示例#1
0
        protected new static FileContents FromFile(string filePath)
        {
            string s = ReadFrom(filePath);

            //just to perform basic error checking, to keep the code DRY:
            var i = FileIdentity.FromFile(filePath);

            return(new FileContents(filePath.Substring(filePath.LastIndexOf('\\') + 1),
                                    System.IO.File.GetLastWriteTime(filePath), s, DateTime.Now, FileType.PlainText));
        }
示例#2
0
        /// <summary>
        /// Compares metadata of the identity of the file. Does not compare the actual contents,
        /// and does not check whether the given object contains the contents of the file (or only
        /// its identity).
        /// </summary>
        /// <param name="o">object to compare</param>
        /// <returns>true if: name, size, hash and modification date are all the same
        /// in both objects</returns>
        public override bool Equals(object o)
        {
            if (!o.GetType().Equals(typeof(FileIdentity)) &&
                !o.GetType().Equals(typeof(FileContents)))
            {
                return(false);
            }

            FileIdentity fid = (FileIdentity)o;

            return(fid.Name.Equals(Name) && fid.Size == Size && fid.Hash.Equals(Hash) &&
                   fid.Modified.Equals(Modified));
        }
示例#3
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));
        }
示例#4
0
 /// <summary>
 /// Creates file identity of a real file.
 /// </summary>
 /// <param name="filePath">path to file</param>
 public FileIdentity(string filePath)
     : this(FileIdentity.FromFile(filePath))
 {
     //nothing needed here
 }
示例#5
0
 public FileIdentity(FileIdentity fid)
     : this(fid.Name, fid.Modified, fid.Uploaded, fid.Type, fid.Size, fid.Hash)
 {
     //nothing needed here
 }
示例#6
0
 public ActionResult UpdateInDatabase(Credentials cr, MachineIdentity mid, DirIdentity did,
                                      FileIdentity newFid)
 {
     throw new ActionException("File modification is not properly handled.",
                               ActionType.File);
 }
示例#7
0
 public FileContents(FileIdentity identity, string contents = null)
     : base(identity)
 {
     this.contents = contents;
 }