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)); }
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)); }
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 bool SaveToDisk() { if (Files == null || Files.Count == 0) { return(true); } DirIdentity did = (DirIdentity)this; foreach (FileContents fc in Files) { fc.SaveToDisk(did); } return(true); //throw new ActionException("PREVENTED HDD DATA MODIFICATION:" // + "\n\nCurrent directory contents: " + new DirContents(this.Identity, true).ToString() // + "\n\nContents downloaded: " + this.ToString(), ActionType.Directory); }
public DirContents(Credentials cr, MachineIdentity mid, DirIdentity did, bool downloadFilesContents = false, bool addRealFiles = false) : this(FromDatabase(cr, mid, did, downloadFilesContents), addRealFiles) { //nothing needed here }
/// <summary> /// Creates a directory that /// </summary> /// <param name="did">identity of the directory</param> /// <param name="files">initial files that the directory will contain</param> /// <param name="addRealFiles">files stored under the real path are added</param> public DirContents(DirIdentity did, List <FileContents> files = null, bool addRealFiles = false) : this(did.Name, did.LocalPath, did.Description, files, addRealFiles) { //nothing needed here }
private ActionResult UpdateInDatabase(Credentials cr, MachineIdentity mid, DirIdentity newDid) { throw new ActionException("Directory modification is not properly handled.", ActionType.Directory); }
public DirIdentity(DirIdentity did) : this(did.Name, did.LocalPath, did.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 bool SaveToDisk(DirIdentity did) { return(WriteTo(did.LocalPath + "\\" + this.Name)); }
public ActionResult DeleteFromDatabase(Credentials cr, MachineIdentity mid, DirIdentity did) { throw new ActionException("File deletion is not properly handled.", ActionType.File); }