예제 #1
0
        public static int FileComparison(FileContents x, FileContents y)
        {
            int nameComparison = x.Name.CompareTo(y.Name);

            if (nameComparison != 0)
            {
                return(nameComparison);
            }

            int modifiedComparison = x.Modified.CompareTo(y.Modified);

            if (modifiedComparison != 0)
            {
                return(modifiedComparison);
            }

            int sizeComparison = x.Size.CompareTo(y.Size);

            if (sizeComparison != 0)
            {
                return(sizeComparison * (-1));
            }

            int hashComparison = x.Hash.CompareTo(y.Hash);

            if (hashComparison != 0)
            {
                return(hashComparison);
            }

            return(0);
        }
예제 #2
0
        /// <summary>
        /// This function assumes that the files list is initialized. It also performs no cleanup
        /// of duplicates in case of incorrect of consequtive use.
        /// </summary>
        private void AddRealFiles()
        {
            if (LocalPath == null || LocalPath.Equals(EmptyLocalPath))
            {
                return;
            }

            string[] filePaths = Directory.GetFiles(LocalPath);

            if (filePaths == null || filePaths.Length == 0)
            {
                return;
            }

            if (Files == null)
            {
                files = new List <FileContents>();
            }

            foreach (string path in filePaths)
            {
                FileContents fc = new FileContents(path);
                Files.Add(fc);
            }
        }
예제 #3
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));
        }
예제 #4
0
 /// <summary>
 /// Creates file contents from a file in a specified local path, and creates its identity,
 /// which is based on the contents and meta-data of that real file.
 /// </summary>
 /// <param name="filePath"></param>
 public FileContents(string filePath)
     : this(FileContents.FromFile(filePath))
 {
     //nothing needed here
 }
예제 #5
0
 public FileContents(FileContents fc)
     : this(fc.Name, fc.Modified, fc.Contents, fc.Uploaded, fc.Type, fc.Size, fc.Hash)
 {
     //nothing needed here
 }