Skip to content

Commit d7b3958

Browse files
committed
refactor: move AddDebugPathItems to AfterJoinSessionService
refactor: cleanup
1 parent 0476bd3 commit d7b3958

File tree

6 files changed

+120
-125
lines changed

6 files changed

+120
-125
lines changed

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/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/ViewModels/Sessions/Comparisons/Results/ContentIdentityViewModel.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using System.Collections.ObjectModel;
22
using ByteSync.Business.Sessions;
33
using ByteSync.Common.Business.Inventories;
4-
using ByteSync.Common.Helpers;
5-
using ByteSync.Interfaces.Factories;
64
using ByteSync.Interfaces.Factories.ViewModels;
75
using ByteSync.Interfaces.Services.Sessions;
86
using ByteSync.Models.Comparisons.Result;

src/ByteSync.Client/ViewModels/Sessions/Members/SessionMachineViewModel.cs

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
using ByteSync.Interfaces.Factories.Proxies;
2020
using ByteSync.Interfaces.Repositories;
2121
using ByteSync.Interfaces.Services.Sessions;
22-
using ByteSync.Services.Sessions;
2322
using DynamicData;
2423
using DynamicData.Binding;
2524
using ReactiveUI;
@@ -129,91 +128,6 @@ public SessionMachineViewModel(SessionMemberInfo sessionMemberInfo, ISessionServ
129128
});
130129

131130
UpdateMachineDescription();
132-
133-
#if DEBUG
134-
if (IsLocalMachine && _sessionService.CurrentRunSessionProfileInfo == null)
135-
{
136-
void DebugAddDesktopPathItem(string folderName)
137-
{
138-
var allPathItems = _pathItemRepository.Elements.Where(pi => pi.BelongsTo(SessionMemberInfo)).ToList();
139-
140-
if (allPathItems.Any(pi => pi.Path.Equals(IOUtils.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), folderName),
141-
StringComparison.InvariantCultureIgnoreCase)))
142-
{
143-
return;
144-
}
145-
146-
_pathItemsService.CreateAndAddPathItem(
147-
IOUtils.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), folderName),
148-
FileSystemTypes.Directory);
149-
}
150-
151-
if (Environment.GetCommandLineArgs().Contains(DebugArguments.ADD_PATHITEM_TESTA))
152-
{
153-
DebugAddDesktopPathItem("testA");
154-
}
155-
156-
if (Environment.GetCommandLineArgs().Contains(DebugArguments.ADD_PATHITEM_TESTA1))
157-
{
158-
DebugAddDesktopPathItem("testA1");
159-
}
160-
161-
if (Environment.GetCommandLineArgs().Contains(DebugArguments.ADD_PATHITEM_TESTB))
162-
{
163-
DebugAddDesktopPathItem("testB");
164-
}
165-
166-
if (Environment.GetCommandLineArgs().Contains(DebugArguments.ADD_PATHITEM_TESTB1))
167-
{
168-
DebugAddDesktopPathItem("testB1");
169-
}
170-
171-
if (Environment.GetCommandLineArgs().Contains(DebugArguments.ADD_PATHITEM_TESTC))
172-
{
173-
DebugAddDesktopPathItem("testC");
174-
}
175-
176-
if (Environment.GetCommandLineArgs().Contains(DebugArguments.ADD_PATHITEM_TESTC1))
177-
{
178-
DebugAddDesktopPathItem("testC1");
179-
}
180-
181-
if (Environment.GetCommandLineArgs().Contains(DebugArguments.ADD_PATHITEM_TESTD))
182-
{
183-
DebugAddDesktopPathItem("testD");
184-
}
185-
186-
if (Environment.GetCommandLineArgs().Contains(DebugArguments.ADD_PATHITEM_TESTD1))
187-
{
188-
DebugAddDesktopPathItem("testD1");
189-
}
190-
191-
if (Environment.GetCommandLineArgs().Contains(DebugArguments.ADD_PATHITEM_TESTE))
192-
{
193-
DebugAddDesktopPathItem("testE");
194-
}
195-
196-
if (Environment.GetCommandLineArgs().Contains(DebugArguments.ADD_PATHITEM_TESTE1))
197-
{
198-
DebugAddDesktopPathItem("testE1");
199-
}
200-
201-
if (Environment.GetCommandLineArgs().Contains(DebugArguments.ADD_PATHITEM_TESTTMP))
202-
{
203-
DebugAddDesktopPathItem("testTmp");
204-
}
205-
206-
if (Environment.GetCommandLineArgs().Contains(DebugArguments.ADD_PATHITEM_MYDATA))
207-
{
208-
_pathItemsService.CreateAndAddPathItem(@"D:\MyData", FileSystemTypes.Directory);
209-
}
210-
211-
if (Environment.GetCommandLineArgs().Contains(DebugArguments.ADD_PATHITEM_SAMPLEDATA))
212-
{
213-
_pathItemsService.CreateAndAddPathItem(@"E:\SampleData", FileSystemTypes.Directory);
214-
}
215-
}
216-
#endif
217131
}
218132

219133
private void OnLocaleChanged(PropertyChangedEventArgs objEventArgs)

0 commit comments

Comments
 (0)