Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 972ac4c

Browse files
committed
1. extended filesync interface definition and slightly change how gui uses the service
2. added 'null' and 'false' handling in gui Signed-off-by: Mateusz Bysiek <mb@mbdev.pl>
1 parent d9bc81c commit 972ac4c

File tree

8 files changed

+134
-65
lines changed

8 files changed

+134
-65
lines changed

FileSyncGui/FileSyncConnection.cs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public bool AddUser(UserContents u) {
3636
return result;
3737
} catch (Exception ex) {
3838
cl.Abort();
39-
throw new ActionException("Unable to create new user account.",
39+
throw new ActionException("Unable to create new user account.",
4040
ActionType.User, ex);
4141
}
4242
}
@@ -62,6 +62,8 @@ public UserIdentity GetUser(Credentials c) {
6262
UserIdentity u = null;
6363
u = cl.GetUser(c);
6464
cl.Close();
65+
if (u == null)
66+
throw new ActionException("Received a null object.", ActionType.User);
6567
return u;
6668
} catch (Exception ex) {
6769
cl.Abort();
@@ -76,6 +78,8 @@ public UserContents GetUserWithMachines(Credentials c) {
7678
UserContents u = null;
7779
u = cl.GetUserWithMachines(c);
7880
cl.Close();
81+
if (u == null)
82+
throw new ActionException("Received a null object.", ActionType.User);
7983
return u;
8084
} catch (Exception ex) {
8185
cl.Abort();
@@ -93,7 +97,7 @@ public bool DelUser(Credentials c) {
9397
return result;
9498
} catch (Exception ex) {
9599
cl.Abort();
96-
throw new ActionException("Unable to delete the user account.",
100+
throw new ActionException("Unable to delete the user account.",
97101
ActionType.User, ex);
98102
}
99103
}
@@ -151,10 +155,11 @@ public MachineContents GetMachineWithDirs(Credentials c, MachineIdentity mid) {
151155
if (mid == null)
152156
throw new ArgumentNullException("mid", "machine identity was null");
153157

154-
155158
MachineContents newM = new MachineContents(mid);
156159
newM.Directories = cl.GetDirList(c, newM);
157160
cl.Close();
161+
if (newM == null)
162+
throw new ActionException("Received a null object.", ActionType.User);
158163
return newM;
159164

160165
//MachineContents m = null;
@@ -197,10 +202,19 @@ public DirectoryContents GetDirectoryWithFiles(Credentials c, MachineContents m,
197202
DirectoryIdentity did) {
198203
var cl = new Ref.FileSyncModelClient();
199204
try {
200-
DirectoryContents d = null;
201-
d = cl.GetDirectoryWithFiles(c, m, did);
205+
206+
DirectoryContents newD = new DirectoryContents(did);
207+
newD.Files = cl.GetFileList(c, m, newD);
202208
cl.Close();
203-
return d;
209+
if (newD == null)
210+
throw new ActionException("Received a null object.", ActionType.User);
211+
return newD;
212+
213+
//DirectoryContents d = null;
214+
//d = cl.GetDirectoryWithFiles(c, m, did);
215+
//cl.Close();
216+
//return d;
217+
204218
} catch (ActionException ex) {
205219
cl.Abort();
206220
throw new ActionException("Unable to download directory contents.",
@@ -244,6 +258,8 @@ public FileContents GetFileWithContent(Credentials c, MachineContents m,
244258
FileContents f = null;
245259
f = cl.GetFileWithContent(c, m, d, f);
246260
cl.Close();
261+
if (f == null)
262+
throw new ActionException("Received a null object.", ActionType.User);
247263
return f;
248264
} catch (Exception ex) {
249265
cl.Abort();
@@ -266,5 +282,10 @@ public bool DelFile(Credentials c, MachineIdentity mid, DirectoryIdentity did,
266282
public System.Collections.Generic.List<DirectoryContents> GetDirList(Credentials c, MachineContents m) {
267283
throw new NotImplementedException();
268284
}
285+
286+
287+
public System.Collections.Generic.List<FileContents> GetFileList(Credentials c, MachineContents m, DirectoryContents d) {
288+
throw new NotImplementedException();
289+
}
269290
}
270291
}

FileSyncGui/LoginWindow.xaml.cs

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,13 @@ private void buttonLogin_Click(object sender, RoutedEventArgs e) {
154154
Credentials c = getCredentials();
155155

156156
try {
157-
connection.Login(c);
158-
159-
parentWindow.credentials = c;
160-
//MessageBox.Show("User logged in.");
161-
this.DialogResult = true;
162-
this.Close();
157+
if (connection.Login(c)) {
158+
parentWindow.credentials = c;
159+
//MessageBox.Show("User logged in.");
160+
this.DialogResult = true;
161+
this.Close();
162+
} else
163+
new SystemMessage("FileSync", "Sorry..", "Login attempt failed.").ShowDialog();
163164
} catch (ActionException ex) {
164165
new SystemMessage(ex).ShowDialog();
165166
}
@@ -168,8 +169,9 @@ private void buttonLogin_Click(object sender, RoutedEventArgs e) {
168169
private void buttonReset_Click(object sender, RoutedEventArgs e) {
169170
try {
170171
if (connection.TestWCF())
171-
new SystemMessage(null, "WCF test", "WCF connection test passed",
172+
new SystemMessage(null, "WCF test", "WCF connection test passed",
172173
MemeType.FuckYea).ShowDialog();
174+
else throw new Exception("test returned false");
173175
} catch (Exception ex) {
174176
var ae = new ActionException("WCF test failed", ActionType.User, null, ex);
175177
new SystemMessage(ae).ShowDialog();
@@ -179,6 +181,7 @@ private void buttonReset_Click(object sender, RoutedEventArgs e) {
179181
if (connection.TestEF())
180182
new SystemMessage(null, "EF test", "Enitity Framework connection test passed",
181183
MemeType.FuckYea).ShowDialog();
184+
else throw new Exception("test returned false");
182185
} catch (Exception ex) {
183186
var ae = new ActionException("EF test failed", ActionType.User, null, ex);
184187
new SystemMessage(ae).ShowDialog();
@@ -194,22 +197,23 @@ private void buttonCreateSubmit_Click(object sender, RoutedEventArgs e) {
194197
MachineContents m = this.getMachine();
195198

196199
try {
197-
connection.AddUser(this.getUser());
198-
199-
this.DialogResult = true;
200-
//MessageBox.Show("User was created!");
201-
202-
connection.Login(c);
203-
connection.AddMachine(c, m);
204-
205-
parentWindow.credentials = c;
206-
m = connection.GetMachineWithDirs(c, m);
207-
//parentWindow.machine = new MachineContents(c, id, false, false, true);
208-
m = local.ReadMachineContents(m);
209-
//MachineActions.GetContets(c, id);
210-
211-
//MessageBox.Show("Machine was created!");
212-
this.Close();
200+
if (connection.AddUser(this.getUser())) {
201+
this.DialogResult = true;
202+
//MessageBox.Show("User was created!");
203+
204+
connection.Login(c);
205+
connection.AddMachine(c, m);
206+
207+
parentWindow.credentials = c;
208+
m = connection.GetMachineWithDirs(c, m);
209+
//parentWindow.machine = new MachineContents(c, id, false, false, true);
210+
m = local.ReadMachineContents(m);
211+
//MachineActions.GetContets(c, id);
212+
213+
//MessageBox.Show("Machine was created!");
214+
this.Close();
215+
} else
216+
new SystemMessage(new ActionException("Sorry, an error.", ActionType.User)).ShowDialog();
213217
} catch (ActionException ex) {
214218
new SystemMessage(ex).ShowDialog();
215219
} catch (Exception ex) {

FileSyncGui/MainWindow.xaml.cs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -340,22 +340,14 @@ private void buttonSaveChanges_Click(object sender, RoutedEventArgs e) {
340340

341341
var newMachine = new MachineContents(MachineName, MachineDesc);
342342

343-
connection.ChangeMachineDetails(credentials, newMachine, machine);
343+
if (connection.ChangeMachineDetails(credentials, newMachine, machine)) {
344+
machine.Name = MachineName;
345+
machine.Description = MachineDesc;
346+
new SystemMessage("FileSync", "Changes saved",
347+
"Machine metadata was successfully updated.", MemeType.FuckYea).ShowDialog();
348+
} else
349+
new SystemMessage("FileSync", "Error", "bool WCF function returned false").ShowDialog();
344350

345-
machine.Name = MachineName;
346-
machine.Description = MachineDesc;
347-
348-
//if (machine.UpdateInDatabase(credentials,
349-
// newMachine).WasSuccessful
350-
// //MachineActions.Modify(credentials, machine.Identity,
351-
// //new MachineIdentity(MachineName, MachineDesc)).IsSuccess()
352-
// ) {
353-
// //nothing here now
354-
//}
355-
new SystemMessage("FileSync", "Changes saved",
356-
"Machine metadata was successfully updated.", MemeType.FuckYea).ShowDialog();
357-
//MessageBox.Show("Changes saved.", "FileSync",
358-
// MessageBoxButton.OK, MessageBoxImage.Information);
359351
} catch (ActionException ex) {
360352
MessageBox.Show(ex.Message, ex.Title);
361353
}
@@ -411,7 +403,7 @@ private void optionDownloadMachine_Click(object sender, RoutedEventArgs e) {
411403
"All directories defined in this machine were downloaded and restored.",
412404
MemeType.FuckYea).ShowDialog();
413405
else new SystemMessage("FileSync", "This is embarassing.",
414-
"The machine was not downloaded successfully.");
406+
"The machine was not downloaded successfully.").ShowDialog();
415407

416408
//foreach (DirIdentity did in machine.Directories) {
417409
// var files = DirActions.Download(credentials, machine.Identity, did);
@@ -526,7 +518,8 @@ private void optionUploadFile_Click(object sender, RoutedEventArgs e) {
526518
var dc = machine.Directories[dirIndex];
527519
var fc = Directories[dirIndex].Files[fileIndex];
528520

529-
connection.AddFile(credentials, machine, dc, fc);
521+
if (!connection.AddFile(credentials, machine, dc, fc))
522+
new SystemMessage("FileSync", "Error", "bool WCF function returned false").ShowDialog();
530523

531524
//fc.Upload(credentials, machine, dc);
532525
//FileActions.Upload(credentials, machine.Identity, did, fid,

FileSyncGui/Service References/Ref/FileSyncService.wsdl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@
8585
<wsdl:message name="IFileSyncModel_AddDirectory_OutputMessage">
8686
<wsdl:part name="parameters" element="tns:AddDirectoryResponse" />
8787
</wsdl:message>
88+
<wsdl:message name="IFileSyncModel_GetFileList_InputMessage">
89+
<wsdl:part name="parameters" element="tns:GetFileList" />
90+
</wsdl:message>
91+
<wsdl:message name="IFileSyncModel_GetFileList_OutputMessage">
92+
<wsdl:part name="parameters" element="tns:GetFileListResponse" />
93+
</wsdl:message>
8894
<wsdl:message name="IFileSyncModel_GetDirectoryWithFiles_InputMessage">
8995
<wsdl:part name="parameters" element="tns:GetDirectoryWithFiles" />
9096
</wsdl:message>
@@ -168,6 +174,10 @@
168174
<wsdl:input wsaw:Action="http://tempuri.org/IFileSyncModel/AddDirectory" message="tns:IFileSyncModel_AddDirectory_InputMessage" />
169175
<wsdl:output wsaw:Action="http://tempuri.org/IFileSyncModel/AddDirectoryResponse" message="tns:IFileSyncModel_AddDirectory_OutputMessage" />
170176
</wsdl:operation>
177+
<wsdl:operation name="GetFileList">
178+
<wsdl:input wsaw:Action="http://tempuri.org/IFileSyncModel/GetFileList" message="tns:IFileSyncModel_GetFileList_InputMessage" />
179+
<wsdl:output wsaw:Action="http://tempuri.org/IFileSyncModel/GetFileListResponse" message="tns:IFileSyncModel_GetFileList_OutputMessage" />
180+
</wsdl:operation>
171181
<wsdl:operation name="GetDirectoryWithFiles">
172182
<wsdl:input wsaw:Action="http://tempuri.org/IFileSyncModel/GetDirectoryWithFiles" message="tns:IFileSyncModel_GetDirectoryWithFiles_InputMessage" />
173183
<wsdl:output wsaw:Action="http://tempuri.org/IFileSyncModel/GetDirectoryWithFilesResponse" message="tns:IFileSyncModel_GetDirectoryWithFiles_OutputMessage" />
@@ -308,6 +318,15 @@
308318
<soap:body use="literal" />
309319
</wsdl:output>
310320
</wsdl:operation>
321+
<wsdl:operation name="GetFileList">
322+
<soap:operation soapAction="http://tempuri.org/IFileSyncModel/GetFileList" style="document" />
323+
<wsdl:input>
324+
<soap:body use="literal" />
325+
</wsdl:input>
326+
<wsdl:output>
327+
<soap:body use="literal" />
328+
</wsdl:output>
329+
</wsdl:operation>
311330
<wsdl:operation name="GetDirectoryWithFiles">
312331
<soap:operation soapAction="http://tempuri.org/IFileSyncModel/GetDirectoryWithFiles" style="document" />
313332
<wsdl:input>

FileSyncGui/Service References/Ref/FileSyncService2.xsd

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -187,28 +187,44 @@
187187
</xs:sequence>
188188
</xs:complexType>
189189
</xs:element>
190-
<xs:element name="GetDirectoryWithFiles">
190+
<xs:element name="GetFileList">
191191
<xs:complexType>
192192
<xs:sequence>
193193
<xs:element xmlns:q24="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="c" nillable="true" type="q24:Credentials" />
194194
<xs:element xmlns:q25="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="m" nillable="true" type="q25:MachineContents" />
195-
<xs:element xmlns:q26="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="d" nillable="true" type="q26:DirectoryIdentity" />
195+
<xs:element xmlns:q26="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="d" nillable="true" type="q26:DirectoryContents" />
196+
</xs:sequence>
197+
</xs:complexType>
198+
</xs:element>
199+
<xs:element name="GetFileListResponse">
200+
<xs:complexType>
201+
<xs:sequence>
202+
<xs:element xmlns:q27="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="GetFileListResult" nillable="true" type="q27:ArrayOfFileContents" />
203+
</xs:sequence>
204+
</xs:complexType>
205+
</xs:element>
206+
<xs:element name="GetDirectoryWithFiles">
207+
<xs:complexType>
208+
<xs:sequence>
209+
<xs:element xmlns:q28="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="c" nillable="true" type="q28:Credentials" />
210+
<xs:element xmlns:q29="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="m" nillable="true" type="q29:MachineContents" />
211+
<xs:element xmlns:q30="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="d" nillable="true" type="q30:DirectoryIdentity" />
196212
</xs:sequence>
197213
</xs:complexType>
198214
</xs:element>
199215
<xs:element name="GetDirectoryWithFilesResponse">
200216
<xs:complexType>
201217
<xs:sequence>
202-
<xs:element xmlns:q27="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="GetDirectoryWithFilesResult" nillable="true" type="q27:DirectoryContents" />
218+
<xs:element xmlns:q31="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="GetDirectoryWithFilesResult" nillable="true" type="q31:DirectoryContents" />
203219
</xs:sequence>
204220
</xs:complexType>
205221
</xs:element>
206222
<xs:element name="DelDirectory">
207223
<xs:complexType>
208224
<xs:sequence>
209-
<xs:element xmlns:q28="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="c" nillable="true" type="q28:Credentials" />
210-
<xs:element xmlns:q29="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="mid" nillable="true" type="q29:MachineIdentity" />
211-
<xs:element xmlns:q30="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="did" nillable="true" type="q30:DirectoryIdentity" />
225+
<xs:element xmlns:q32="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="c" nillable="true" type="q32:Credentials" />
226+
<xs:element xmlns:q33="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="mid" nillable="true" type="q33:MachineIdentity" />
227+
<xs:element xmlns:q34="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="did" nillable="true" type="q34:DirectoryIdentity" />
212228
</xs:sequence>
213229
</xs:complexType>
214230
</xs:element>
@@ -222,10 +238,10 @@
222238
<xs:element name="AddFile">
223239
<xs:complexType>
224240
<xs:sequence>
225-
<xs:element xmlns:q31="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="c" nillable="true" type="q31:Credentials" />
226-
<xs:element xmlns:q32="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="m" nillable="true" type="q32:MachineContents" />
227-
<xs:element xmlns:q33="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="d" nillable="true" type="q33:DirectoryContents" />
228-
<xs:element xmlns:q34="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="f" nillable="true" type="q34:FileContents" />
241+
<xs:element xmlns:q35="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="c" nillable="true" type="q35:Credentials" />
242+
<xs:element xmlns:q36="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="m" nillable="true" type="q36:MachineContents" />
243+
<xs:element xmlns:q37="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="d" nillable="true" type="q37:DirectoryContents" />
244+
<xs:element xmlns:q38="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="f" nillable="true" type="q38:FileContents" />
229245
</xs:sequence>
230246
</xs:complexType>
231247
</xs:element>
@@ -239,27 +255,27 @@
239255
<xs:element name="GetFileWithContent">
240256
<xs:complexType>
241257
<xs:sequence>
242-
<xs:element xmlns:q35="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="c" nillable="true" type="q35:Credentials" />
243-
<xs:element xmlns:q36="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="m" nillable="true" type="q36:MachineContents" />
244-
<xs:element xmlns:q37="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="d" nillable="true" type="q37:DirectoryContents" />
245-
<xs:element xmlns:q38="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="f" nillable="true" type="q38:FileIdentity" />
258+
<xs:element xmlns:q39="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="c" nillable="true" type="q39:Credentials" />
259+
<xs:element xmlns:q40="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="m" nillable="true" type="q40:MachineContents" />
260+
<xs:element xmlns:q41="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="d" nillable="true" type="q41:DirectoryContents" />
261+
<xs:element xmlns:q42="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="f" nillable="true" type="q42:FileIdentity" />
246262
</xs:sequence>
247263
</xs:complexType>
248264
</xs:element>
249265
<xs:element name="GetFileWithContentResponse">
250266
<xs:complexType>
251267
<xs:sequence>
252-
<xs:element xmlns:q39="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="GetFileWithContentResult" nillable="true" type="q39:FileContents" />
268+
<xs:element xmlns:q43="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="GetFileWithContentResult" nillable="true" type="q43:FileContents" />
253269
</xs:sequence>
254270
</xs:complexType>
255271
</xs:element>
256272
<xs:element name="DelFile">
257273
<xs:complexType>
258274
<xs:sequence>
259-
<xs:element xmlns:q40="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="c" nillable="true" type="q40:Credentials" />
260-
<xs:element xmlns:q41="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="mid" nillable="true" type="q41:MachineIdentity" />
261-
<xs:element xmlns:q42="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="did" nillable="true" type="q42:DirectoryIdentity" />
262-
<xs:element xmlns:q43="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="f" nillable="true" type="q43:FileIdentity" />
275+
<xs:element xmlns:q44="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="c" nillable="true" type="q44:Credentials" />
276+
<xs:element xmlns:q45="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="mid" nillable="true" type="q45:MachineIdentity" />
277+
<xs:element xmlns:q46="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="did" nillable="true" type="q46:DirectoryIdentity" />
278+
<xs:element xmlns:q47="http://schemas.datacontract.org/2004/07/FileSyncObjects" minOccurs="0" name="f" nillable="true" type="q47:FileIdentity" />
263279
</xs:sequence>
264280
</xs:complexType>
265281
</xs:element>

0 commit comments

Comments
 (0)