11using System . Text ;
2+ using ByteSync . Business . Arguments ;
23using ByteSync . Business . Sessions . Connecting ;
4+ using ByteSync . Common . Business . Inventories ;
5+ using ByteSync . Common . Business . Sessions . Cloud ;
36using ByteSync . Interfaces . Controls . Applications ;
47using ByteSync . Interfaces . Controls . Communications ;
58using 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 ( ) ;
0 commit comments