Skip to content

Commit dc023c8

Browse files
General improvements 12-02-2025 (#40)
1 parent 6c71114 commit dc023c8

File tree

17 files changed

+220
-213
lines changed

17 files changed

+220
-213
lines changed

src/ByteSync.Client/DependencyInjection/Modules/SingletonsModule.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ protected override void Load(ContainerBuilder builder)
3232
builder.RegisterType<FileDownloaderCache>().SingleInstance().AsImplementedInterfaces();
3333
builder.RegisterType<CommandLineModeHandler>().SingleInstance().AsImplementedInterfaces();
3434
builder.RegisterType<SynchronizationStarter>().SingleInstance().AsImplementedInterfaces();
35+
builder.RegisterType<SynchronizationActionServerInformer>().SingleInstance().AsImplementedInterfaces();
3536
}
3637
}

src/ByteSync.Client/Interfaces/Controls/Inventories/IPathItemsService.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
using System.Threading.Tasks;
2-
using ByteSync.Business.PathItems;
1+
using ByteSync.Business.PathItems;
32
using ByteSync.Common.Business.Inventories;
43

54
namespace ByteSync.Interfaces.Controls.Inventories;
65

76
public interface IPathItemsService
87
{
9-
// public IObservableCache<PathItem, string> AllPathItems { get; }
10-
11-
// public IObservableCache<PathItem, string> CurrentMemberPathItems { get; }
12-
138
Task AddPathItem(PathItem pathItem);
149

1510
Task CreateAndAddPathItem(string path, FileSystemTypes fileSystemType);

src/ByteSync.Client/Interfaces/Services/Sessions/ISessionService.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,10 @@ public interface ISessionService
4848

4949
void ClearCloudSession();
5050

51-
Task SetCloudSession(CloudSession cloudSession, RunCloudSessionProfileInfo? runCloudSessionProfileInfo, SessionSettings sessionSettings);
51+
Task SetCloudSession(CloudSession cloudSession, RunCloudSessionProfileInfo? runCloudSessionProfileInfo, SessionSettings sessionSettings, string password);
5252

5353
Task SetLocalSession(LocalSession localSession, RunLocalSessionProfileInfo? runLocalSessionProfileInfo, SessionSettings sessionSettings);
5454

55-
void SetPassword(string password);
56-
5755
Task SetSessionSettings(SessionSettings sessionSettings);
5856

5957
Task SetSessionStatus(SessionStatus sessionStatus);

src/ByteSync.Client/Services/Inventories/InventoryBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ public InventoryBuilder(string inventoryLetter, SessionSettings sessionSettings,
3939

4040
Indexer = new InventoryIndexer();
4141

42-
Inventory = InstanciateInventory();
42+
Inventory = InstantiateInventory();
4343
}
4444

45-
private Inventory InstanciateInventory()
45+
private Inventory InstantiateInventory()
4646
{
4747
var id = $"IID_{Guid.NewGuid()}";
4848
var inventory = new Inventory();
@@ -312,7 +312,7 @@ private void DoAnalyze(InventoryPart inventoryPart, DirectoryInfo directoryInfo,
312312
// - Windows: New-Item -ItemType SymbolicLink -Path C:\Users\paulf\Desktop\testVide\SL -Target C:\Users\paulf\Desktop\testA_
313313
if (fileInfo.Attributes.HasFlag(FileAttributes.ReparsePoint))
314314
{
315-
Log.Warning("File {File} is ignored because it has flag 'ReparsePoint'", fileInfo.FullName);
315+
Log.Warning("File {File} is ignored because it has flag 'ReparsePoint'. It might be a symolic link", fileInfo.FullName);
316316
return;
317317
}
318318

src/ByteSync.Client/Services/Sessions/Connecting/AfterJoinSessionService.cs

Lines changed: 115 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using System.Text;
2+
using ByteSync.Business.Arguments;
23
using ByteSync.Business.Sessions.Connecting;
4+
using ByteSync.Common.Business.Inventories;
5+
using ByteSync.Common.Business.Sessions.Cloud;
36
using ByteSync.Interfaces.Controls.Applications;
47
using ByteSync.Interfaces.Controls.Communications;
58
using ByteSync.Interfaces.Controls.Communications.Http;
@@ -23,8 +26,9 @@ public class AfterJoinSessionService : IAfterJoinSessionService
2326
private readonly IDigitalSignaturesRepository _digitalSignaturesRepository;
2427
private readonly IEnvironmentService _environmentService;
2528
private readonly ICloudSessionConnectionService _cloudSessionConnectionService;
26-
private readonly ILogger<AfterJoinSessionService> _logger;
2729
private readonly IQuitSessionService _quitSessionService;
30+
private readonly IPathItemRepository _pathItemRepository;
31+
private readonly ILogger<AfterJoinSessionService> _logger;
2832

2933
public AfterJoinSessionService(
3034
ICloudSessionApiClient cloudSessionApiClient,
@@ -38,6 +42,7 @@ public AfterJoinSessionService(
3842
IEnvironmentService environmentService,
3943
ICloudSessionConnectionService cloudSessionConnectionService,
4044
IQuitSessionService quitSessionService,
45+
IPathItemRepository pathItemRepository,
4146
ILogger<AfterJoinSessionService> logger)
4247
{
4348
_cloudSessionApiClient = cloudSessionApiClient;
@@ -51,14 +56,28 @@ public AfterJoinSessionService(
5156
_environmentService = environmentService;
5257
_cloudSessionConnectionService = cloudSessionConnectionService;
5358
_quitSessionService = quitSessionService;
59+
_pathItemRepository = pathItemRepository;
5460
_logger = logger;
5561
}
5662

5763
public async Task Process(AfterJoinSessionRequest request)
5864
{
5965
var sessionMemberInfoDtos = await _cloudSessionApiClient.GetMembers(request.CloudSessionResult.SessionId);
6066

61-
// On contrôle que chacun des autres membres est Auth-Checked
67+
await CheckOtherMembersAreTrustedAndChecked(request, sessionMemberInfoDtos);
68+
69+
var sessionSettings = _dataEncrypter.DecryptSessionSettings(request.CloudSessionResult.SessionSettings);
70+
71+
var password = await GetPassword(request);
72+
await _sessionService.SetCloudSession(request.CloudSessionResult.CloudSession, request.RunCloudSessionProfileInfo, sessionSettings, password);
73+
74+
_sessionMemberService.AddOrUpdate(sessionMemberInfoDtos);
75+
76+
await FillPathItems(request, sessionMemberInfoDtos);
77+
}
78+
79+
private async Task CheckOtherMembersAreTrustedAndChecked(AfterJoinSessionRequest request, List<SessionMemberInfoDTO> sessionMemberInfoDtos)
80+
{
6281
var areAllMemberAuthOK = true;
6382
foreach (var sessionMemberInfo in sessionMemberInfoDtos)
6483
{
@@ -82,10 +101,10 @@ public async Task Process(AfterJoinSessionRequest request)
82101

83102
throw new Exception("Auth check failed, quitting session");
84103
}
85-
86-
var sessionSettings = _dataEncrypter.DecryptSessionSettings(request.CloudSessionResult.SessionSettings);
104+
}
87105

88-
await _sessionService.SetCloudSession(request.CloudSessionResult.CloudSession, request.RunCloudSessionProfileInfo, sessionSettings);
106+
private async Task<string> GetPassword(AfterJoinSessionRequest request)
107+
{
89108
string password;
90109
if (request.IsCreator)
91110
{
@@ -95,31 +114,20 @@ public async Task Process(AfterJoinSessionRequest request)
95114
{
96115
password = (await _cloudSessionConnectionRepository.GetTempSessionPassword(request.CloudSessionResult.SessionId))!;
97116
}
98-
_sessionService.SetPassword(password.ToUpper());
99117

100-
101-
102-
_sessionMemberService.AddOrUpdate(sessionMemberInfoDtos);
103-
118+
return password;
119+
}
120+
121+
private async Task FillPathItems(AfterJoinSessionRequest request, List<SessionMemberInfoDTO> sessionMemberInfoDtos)
122+
{
104123
if (request.RunCloudSessionProfileInfo != null)
105124
{
106125
var myPathItems = request.RunCloudSessionProfileInfo.GetMyPathItems();
107-
108-
// var pathItemsViewModels = _pathItemsService.GetMyPathItems()!;
126+
109127
foreach (var pathItem in myPathItems)
110128
{
111129
await _pathItemsService.CreateAndAddPathItem(pathItem.Path, pathItem.Type);
112-
113-
// pathItemsViewModels.Add(new PathItemViewModel(pathItem));
114-
115-
// var encryptedPathItem = dataEncrypter.EncryptPathItem(pathItem);
116-
//
117-
// // PathItemEncrypter pathItemEncrypter = _sessionObjectsFactory.BuildPathItemEncrypter();
118-
// // var sharedPathItem = pathItemEncrypter.Encrypt(pathItem);
119-
// await _connectionManager.HubWrapper.SetPathItemAdded(cloudSessionResult.SessionId, encryptedPathItem);
120130
}
121-
122-
// await _connectionManager.
123131
}
124132

125133
foreach (var sessionMemberInfo in sessionMemberInfoDtos)
@@ -138,8 +146,93 @@ public async Task Process(AfterJoinSessionRequest request)
138146
}
139147
}
140148
}
149+
150+
AddDebugPathItems();
151+
}
152+
153+
private void AddDebugPathItems()
154+
{
155+
if (Environment.GetCommandLineArgs().Contains(DebugArguments.ADD_PATHITEM_TESTA))
156+
{
157+
DebugAddDesktopPathItem("testA");
158+
}
159+
160+
if (Environment.GetCommandLineArgs().Contains(DebugArguments.ADD_PATHITEM_TESTA1))
161+
{
162+
DebugAddDesktopPathItem("testA1");
163+
}
164+
165+
if (Environment.GetCommandLineArgs().Contains(DebugArguments.ADD_PATHITEM_TESTB))
166+
{
167+
DebugAddDesktopPathItem("testB");
168+
}
169+
170+
if (Environment.GetCommandLineArgs().Contains(DebugArguments.ADD_PATHITEM_TESTB1))
171+
{
172+
DebugAddDesktopPathItem("testB1");
173+
}
174+
175+
if (Environment.GetCommandLineArgs().Contains(DebugArguments.ADD_PATHITEM_TESTC))
176+
{
177+
DebugAddDesktopPathItem("testC");
178+
}
179+
180+
if (Environment.GetCommandLineArgs().Contains(DebugArguments.ADD_PATHITEM_TESTC1))
181+
{
182+
DebugAddDesktopPathItem("testC1");
183+
}
184+
185+
if (Environment.GetCommandLineArgs().Contains(DebugArguments.ADD_PATHITEM_TESTD))
186+
{
187+
DebugAddDesktopPathItem("testD");
188+
}
189+
190+
if (Environment.GetCommandLineArgs().Contains(DebugArguments.ADD_PATHITEM_TESTD1))
191+
{
192+
DebugAddDesktopPathItem("testD1");
193+
}
194+
195+
if (Environment.GetCommandLineArgs().Contains(DebugArguments.ADD_PATHITEM_TESTE))
196+
{
197+
DebugAddDesktopPathItem("testE");
198+
}
199+
200+
if (Environment.GetCommandLineArgs().Contains(DebugArguments.ADD_PATHITEM_TESTE1))
201+
{
202+
DebugAddDesktopPathItem("testE1");
203+
}
204+
205+
if (Environment.GetCommandLineArgs().Contains(DebugArguments.ADD_PATHITEM_TESTTMP))
206+
{
207+
DebugAddDesktopPathItem("testTmp");
208+
}
209+
210+
if (Environment.GetCommandLineArgs().Contains(DebugArguments.ADD_PATHITEM_MYDATA))
211+
{
212+
_pathItemsService.CreateAndAddPathItem(@"D:\MyData", FileSystemTypes.Directory);
213+
}
214+
215+
if (Environment.GetCommandLineArgs().Contains(DebugArguments.ADD_PATHITEM_SAMPLEDATA))
216+
{
217+
_pathItemsService.CreateAndAddPathItem(@"E:\SampleData", FileSystemTypes.Directory);
218+
}
141219
}
142220

221+
private void DebugAddDesktopPathItem(string folderName)
222+
{
223+
var myPathItems = _pathItemRepository.Elements.Where(pi => pi.ClientInstanceId == _environmentService.ClientInstanceId).ToList();
224+
225+
if (myPathItems.Any(pi => pi.Path.Equals(IOUtils.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), folderName),
226+
StringComparison.InvariantCultureIgnoreCase)))
227+
{
228+
return;
229+
}
230+
231+
_pathItemsService.CreateAndAddPathItem(
232+
IOUtils.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), folderName),
233+
FileSystemTypes.Directory);
234+
}
235+
143236
private string GeneratePassword()
144237
{
145238
var sb = new StringBuilder();

src/ByteSync.Client/Services/Sessions/SessionService.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public void ClearCloudSession()
129129
}
130130

131131
public Task SetCloudSession(CloudSession cloudSession, RunCloudSessionProfileInfo? runCloudSessionProfileInfo,
132-
SessionSettings sessionSettings)
132+
SessionSettings sessionSettings, string password)
133133
{
134134
return Task.Run(() =>
135135
{
@@ -142,6 +142,8 @@ public Task SetCloudSession(CloudSession cloudSession, RunCloudSessionProfileInf
142142
_sessionStatus.OnNext(SessionStatus.Preparation);
143143

144144
_hasSessionBeenReset.OnNext(false);
145+
146+
CloudSessionPassword = password;
145147
});
146148
}
147149

@@ -162,11 +164,6 @@ public Task SetLocalSession(LocalSession localSession, RunLocalSessionProfileInf
162164
});
163165
}
164166

165-
public void SetPassword(string password)
166-
{
167-
CloudSessionPassword = password;
168-
}
169-
170167
public async Task SetSessionSettings(SessionSettings sessionSettings)
171168
{
172169
var currentSession = CurrentSession;

src/ByteSync.Client/Services/Synchronizations/SynchronizationActionHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ public class SynchronizationActionHandler : ISynchronizationActionHandler
2424
private readonly IFileDatesSetter _fileDatesSetter;
2525
private readonly ILogger<SynchronizationActionHandler> _logger;
2626

27-
public SynchronizationActionHandler(ISessionService sessionDataHolder, IConnectionService connectionService, IDeltaManager deltaManager,
27+
public SynchronizationActionHandler(ISessionService sessionService, IConnectionService connectionService, IDeltaManager deltaManager,
2828
ISynchronizationActionServerInformer synchronizationActionServerInformer, ISynchronizationActionRemoteUploader synchronizationActionRemoteUploader,
2929
ISynchronizationService synchronizationService, ISynchronizationApiClient synchronizationApiClient, IFileDatesSetter fileDatesSetter,
3030
ILogger<SynchronizationActionHandler> logger)
3131
{
32-
_sessionService = sessionDataHolder;
32+
_sessionService = sessionService;
3333
_connectionService = connectionService;
3434
_deltaManager = deltaManager;
3535
_synchronizationActionServerInformer = synchronizationActionServerInformer;

0 commit comments

Comments
 (0)