private static DirContents FromDatabase(Credentials cr, MachineIdentity mid, DirIdentity did, bool downloadFilesContents = false) { List <FileContents> files = new List <FileContents>(); var c = cr.ToLib(); var m = mid.ToLib(); DirModel d = did.ToLib(); try { FileManipulator.GetFileList(c, m, d); foreach (FileModel f in d.Files) { if (downloadFilesContents) { //adding contents to 'f' FileManipulator.GetFileContent(c, m, d, f); } //adding new gui object to list files.Add(new FileContents(f)); } } catch (ActionException ex) { throw new ActionException("Unable to download directory contents.\n\n" + ex.Message + ".", ActionType.Directory, MemeType.Fuuuuu, ex); } catch (Exception ex) { throw new ActionException("Error while downloading directory contents.", ActionType.Directory, MemeType.Fuuuuu, ex); } //does not add local files, because this is supposed to happen in the constructor that // launches this static private method return(new DirContents(did, files, false)); }
/// <summary> /// Accesses the database, and downloads the content. Amount of data downloaded /// can be adjusted with use of optional boolean arguments. /// </summary> /// <param name="cr"></param> /// <param name="mid"></param> /// <param name="downloadDirsFilesMetadata"></param> /// <param name="downloadDirsFilesContents"></param> /// <param name="addRealDirsContents"></param> public MachineContents(Credentials cr, MachineIdentity mid, bool downloadDirsFilesMetadata = false, bool downloadDirsFilesContents = false, bool addRealDirsContents = false) : this(FromDatabase(cr, mid, downloadDirsFilesMetadata, downloadDirsFilesContents, addRealDirsContents)) { //nothing needed here }
public ActionResult Upload(Credentials cr, MachineIdentity mid, DirIdentity did) { try { FileManipulator.AddFile(cr.ToLib(), mid.ToLib(), did.ToLib(), this.ToLib()); } catch (Exception ex) { throw new ActionException("Error occurred while file was uploaded.", ActionType.File, MemeType.Fuuuuu, ex); } return(new ActionResult("File uploaded.", "File was put into the database.", ActionType.File)); }
private static FileContents FromDatabase(Credentials cr, MachineIdentity mid, DirIdentity did, FileIdentity fid) { FileModel f = null; try { f = fid.ToLib(); FileManipulator.GetFileContent(cr.ToLib(), mid.ToLib(), did.ToLib(), f); } catch (Exception ex) { throw new ActionException("Error while downloading file contents from database.", ActionType.File, MemeType.Fuuuuu, ex); } return(new FileContents(f)); }
public ActionResult UpdateInDatabase(Credentials cr, MachineIdentity newMid) { try { if (cr == null) { throw new ArgumentNullException("cr", "user credentials must be provided"); } MachManipulator.ChangeMachineDetails(cr.ToLib(), newMid.ToLib(), this.ToLib()); } catch (Exception ex) { throw new ActionException("Error while updating machine details.", ActionType.Machine, MemeType.Fuuuuu, ex); } return(new ActionResult("Machine updated.", "Current machine details were saved in the database.", ActionType.Machine)); }
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 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 DirContents(Credentials cr, MachineIdentity mid, DirIdentity did, bool downloadFilesContents = false, bool addRealFiles = false) : this(FromDatabase(cr, mid, did, downloadFilesContents), addRealFiles) { //nothing needed here }
public ActionResult DeleteFromDatabase(Credentials cr, MachineIdentity mid) { throw new ActionException("Directory deletion is not properly handled.", ActionType.Directory); }
private ActionResult UpdateInDatabase(Credentials cr, MachineIdentity mid, DirIdentity newDid) { throw new ActionException("Directory modification is not properly handled.", ActionType.Directory); }
/// <summary> /// Creates new contents of the machine. /// </summary> /// <param name="mid">ientity of the machine</param> /// <param name="directories">list of directories of the machine</param> public MachineContents(MachineIdentity mid, List <DirContents> directories = null) : this(mid.Name, mid.Description, directories) { //nothing needed here }
public MachineIdentity(MachineIdentity mid) : this(mid.Name, mid.Description) { //nothing needed here }
public ActionResult UpdateInDatabase(Credentials cr, MachineIdentity mid, DirIdentity did, FileIdentity newFid) { throw new ActionException("File modification is not properly handled.", ActionType.File); }
public ActionResult DeleteFromDatabase(Credentials cr, MachineIdentity mid, DirIdentity did) { throw new ActionException("File deletion is not properly handled.", ActionType.File); }