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)); }
/// <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)); }
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)); }
/// <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 }
public FileIdentity(FileIdentity fid) : this(fid.Name, fid.Modified, fid.Uploaded, fid.Type, fid.Size, fid.Hash) { //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 FileContents(FileIdentity identity, string contents = null) : base(identity) { this.contents = contents; }