private static MachineContents FromDatabase(Credentials cr, MachineIdentity mid, bool downloadDirsFilesMetadata = false, bool downloadDirsFilesContents = false, bool addRealDirsContents = false) { List <DirContents> dirs; try { if (cr == null) { throw new ArgumentNullException("cr", "user credentials must be provided"); } if (mid == null) { throw new ArgumentNullException("mid", "machine identity must be provided"); } CredentialsLib c = cr.ToLib(); MachineModel m = mid.ToLib(); DirManipulator.GetDirList(/*c, */ m); dirs = new List <DirContents>(); foreach (DirModel d in m.Directories) { var did = new DirIdentity(d); dirs.Add(new DirContents(cr, mid, did, downloadDirsFilesContents, addRealDirsContents)); //if (downloadDirsFilesMetadata) { // FileManipulator.GetFileList(c, m, d); // if (downloadDirsFilesContents) { // foreach (FileModel f in d.Files) // FileManipulator.GetFileContent(c, m, d, f); // } //} //dirs.Add(new DirContents(d, addRealDirsContents, downloadDirsFilesMetadata)); } } catch (Exception ex) { throw new ActionException("Unable to get list of directories belonging " + "to the machine.", ActionType.Machine, MemeType.Fuuuuu, ex); } new ActionResult("Machine directories read.", "Got list of directories for your machine from database.", ActionType.Machine); return(new MachineContents(mid, dirs)); }
public ActionResult Upload(Credentials cr, MachineIdentity mid) { CredentialsLib c = cr.ToLib(); MachineModel m = mid.ToLib(); DirModel d = this.ToLib(); try { DirManipulator.AddDirectory(c, m, d); } catch (Exception ex) { throw new ActionException("Failed to create a remote directory for the files.", ActionType.Directory, MemeType.Fuuuuu, ex); } foreach (FileContents fc in Files) { FileContents fcUp = null; try { if (fc.Size == 0) { fcUp = new FileContents(this.LocalPath + "\\" + fc.Name); } else { fcUp = fc; } //if (!fid.Equals((FileIdentity)fc)) // throw new ActionException("Tried to upload a file that had " // + "different identity than the contents generate.", ActionType.File); ActionResult fileSync = fcUp.Upload(cr, mid, this); if (!fileSync.WasSuccessful) { return(fileSync); } } catch (ActionException ex) { throw new ActionException("Couldn't upload the directory contents.\n\n" + ex.Message, ActionType.Directory, MemeType.Fuuuuu, ex); } catch (Exception ex) { throw new ActionException("Error while uploading a directory.", ActionType.Directory, MemeType.AreYouFuckingKiddingMe, ex); } } return(new ActionResult("Directory was uploaded.", "The selected dir was successfully put into database.", ActionType.Directory)); }
private Credentials(CredentialsLib c) : this(c.Login, c.Pass) { //nothing needed here }