Example #1
0
        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));
        }
Example #2
0
 /// <summary>
 /// Downloads the content from database and puts it into the object.
 /// </summary>
 /// <param name="cr">credentials needed to download the data</param>
 /// <returns></returns>
 private static UserIdentity FromDatabase(Credentials cr)
 {
     try {
         UserModel u = UserManipulator.GetUser(cr.ToLib());
         return(new UserIdentity(cr, u.Fullname, u.Email));
     } catch (Exception ex) {
         throw new ActionException("Unable to get user details for the given credentials.",
                                   ActionType.User, MemeType.Fuuuuu, ex);
     }
 }
Example #3
0
        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));
        }
Example #4
0
        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));
        }
Example #5
0
        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));
        }
Example #6
0
        public ActionResult AddToDatabase(Credentials cr)
        {
            try {
                if (cr == null)
                {
                    throw new ArgumentNullException("cr", "user credentials must be provided");
                }

                MachManipulator.AddMachine(cr.ToLib(), this.ToLib());
            } catch (Exception ex) {
                throw new ActionException("Failed to create a new machine.", ActionType.Machine,
                                          MemeType.Fuuuuu, ex);
            }

            return(new ActionResult("Machine created.",
                                    "Your new machine was added to the database.", ActionType.Machine));
        }
Example #7
0
        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));
        }
Example #8
0
        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));
        }
Example #9
0
 private static UserContents FromDatabase(Credentials cr)
 {
     try {
         UserModel u = UserManipulator.GetUser(cr.ToLib());
         MachManipulator.GetMachineList(u);
         List <MachineContents> machines = null;
         if (u.Machines.Count > 0)
         {
             machines = new List <MachineContents>();
             foreach (MachineModel m in u.Machines)
             {
                 machines.Add(new MachineContents(m));
             }
         }
         return(new UserContents(new UserIdentity(u), machines));
     } catch (Exception ex) {
         throw new ActionException("Unable to get list of machines for the user "
                                   + "with the given credentials.", ActionType.User, MemeType.Fuuuuu, ex);
     }
 }