protected void assertAreEqual(FileObject file1, FileObject file2) { Assert.AreEqual<DateTime>(file1.Created, file2.Created); Assert.AreEqual<DateTime>(file1.LastEdited, file2.LastEdited); Assert.AreEqual<string>(file1.Hash, file2.Hash); Assert.AreEqual<string>(file1.Name, file2.Name); Assert.AreEqual<string>(file1.Path, file2.Path); Assert.IsFalse(file1.Name.IsNullOrEmpty()); }
public FileObject Clone() { FileObject copy = new FileObject(); //Copy ServiceName values copy.Created = this.Created; copy.Hash = this.Hash; copy.LastEdited = this.LastEdited; copy.LocalPath = this.LocalPath; copy.Name = this.Name; copy.Parent = this.Parent; return copy; }
public FileObject Clone() { FileObject copy = new FileObject(); //Copy ServiceName values copy.Created = this.Created; copy.Hash = this.Hash; copy.LastEdited = this.LastEdited; copy.LocalPath = this.LocalPath; copy.Name = this.Name; copy.Parent = this.Parent; return(copy); }
public void TestFileObjectSerialization() { FileObject file = new FileObject(); file.LocalPath = Directory.GetFiles(".").First(); file.LoadFromDisk(); file.Path = "/" + file.Name; var xml = file.Serialize(); var strResult = xml.ToString(); var roundtrip = new FileObject(); Assert.IsTrue(roundtrip.Validate(xml)); roundtrip.Deserialize(xml); assertAreEqual(file, roundtrip); }
public override void Deserialize(XElement xmlData) { base.Deserialize(xmlData); files = new Dictionary <string, FileObject>(); foreach (XElement item in xmlData.Element(XmlNamesExtended.Files).Elements(XmlNamesExtended.FileObject)) { FileObject newFile = new FileObject(); newFile.Deserialize(item); files.Add(newFile.Name.ToLower(), newFile); } directories = new Dictionary <string, DirectoryObject>(); foreach (XElement item in xmlData.Element(XmlNamesExtended.Directories).Elements(XmlNamesExtended.DirectoryObject)) { DirectoryObject newDir = new DirectoryObject(); newDir.Deserialize(item); directories.Add(newDir.Name.ToLower(), newDir); } }
public CallResult GetFileInfo(string virtualPath) { logger.Info("Getting FileInfo for {0}", virtualPath); if (mountErrorOccurred) { logger.Error("Mount error found"); return new ErrorResult(RemoteErrorCode.MountError); } if (mountErrorOccurred) { logger.Error("Mount error found"); return new ErrorResult(RemoteErrorCode.MountError); } try { if (!checkPermission(virtualPath)) { logger.Error("Permission denied"); return new ErrorResult(RemoteErrorCode.NotAuthorizedError); } var localPath = getLocalPath(virtualPath); if (localPath.IsNullOrEmpty()) throw new FileNotFoundException(); var file = new FileObject(); file.LocalPath = localPath; file.LoadFromDisk(); return new ResponseResult(file); } catch (Exception ex) { if (ex is FileNotFoundException || ex is DirectoryNotFoundException) { logger.Error("Item not found"); return new ErrorResult(RemoteErrorCode.ItemNotFoundError); } else { throw ex; } } }
public virtual void LoadFromDisk(int depth = -1) { logger.Info("Loading Directory {0}", LocalPath); if (!Directory.Exists(this.LocalPath)) { throw new DirectoryNotFoundException(String.Format("Directory '{0}' not found", LocalPath)); } DirectoryInfo info = new DirectoryInfo(LocalPath); this.Name = info.Name; this.Created = info.CreationTimeUtc; this.LastEdited = info.LastWriteTimeUtc; // ## Update files ## try { foreach (string item in Directory.GetFiles(LocalPath)) { string fileName = System.IO.Path.GetFileName(item); if (files.ContainsKey(fileName)) { files[fileName].LoadFromDisk(); } else { FileObject newFile = new FileObject(); newFile.Name = fileName; newFile.LocalPath = item; AddFile(newFile); newFile.LoadFromDisk(); } } } catch (DirectoryNotFoundException) { files = new Dictionary <string, FileObject>(); } //TODO test if this really works! files.Values.Where(x => !File.Exists(LocalPath)).Select(x => files.Remove(x.Name)); // ## Update directories ## try { foreach (string item in Directory.GetDirectories(LocalPath)) { try { string dirName = ExtendedPath.GetDirectoryName(item); if (!directories.ContainsKey(dirName)) { DirectoryObject newDir = new DirectoryObject(); newDir.Name = dirName; newDir.LocalPath = item; if (depth > 1 || depth < 0) { newDir.LoadFromDisk(depth - 1); } AddDirectory(newDir); } } catch (IOException) { } } } catch (DirectoryNotFoundException) { directories = new Dictionary <string, DirectoryObject>(); } directories.Values.Where(x => !Directory.Exists(x.LocalPath)).Select(x => directories.Remove(x.Name)); directories.Values.Select(x => { x.LoadFromDisk(); return(x); }); }
private void printFileObject(FileObject file) { if (file == null) { Program.ErrorLine(this, "FileObject NULL"); } else { Program.OutputLine(this, file.Name.FormatEscape()); //Program.OutputLine(this, "Path: {0}", file.Path); Program.OutputLine(this, "LastEdited: {0}", file.LastEdited); Program.OutputLine(this, "Created: {0}", file.Created); Program.OutputLine(this, "Hash: {0}", file.Hash); } }
public void TestNotSupportedType() { FileObject foo = new FileObject(); testFile.SaveItem(key, foo); }
private static bool compareFileObject(FileObject file1, FileObject file2) { throw new NotImplementedException(); }
private static bool compareFileObject(FileObject file1, FileObject file2) { throw new NotImplementedException(); }
public virtual void LoadFromDisk(int depth = -1) { logger.Info("Loading Directory {0}", LocalPath); if (!Directory.Exists(this.LocalPath)) throw new DirectoryNotFoundException(String.Format("Directory '{0}' not found", LocalPath)); DirectoryInfo info = new DirectoryInfo(LocalPath); this.Name = info.Name; this.Created = info.CreationTimeUtc; this.LastEdited = info.LastWriteTimeUtc; // ## Update files ## try { foreach (string item in Directory.GetFiles(LocalPath)) { string fileName = System.IO.Path.GetFileName(item); if (files.ContainsKey(fileName)) { files[fileName].LoadFromDisk(); } else { FileObject newFile = new FileObject(); newFile.Name = fileName; newFile.LocalPath = item; AddFile(newFile); newFile.LoadFromDisk(); } } } catch (DirectoryNotFoundException) { files = new Dictionary<string, FileObject>(); } //TODO test if this really works! files.Values.Where(x => !File.Exists(LocalPath)).Select(x => files.Remove(x.Name)); // ## Update directories ## try { foreach (string item in Directory.GetDirectories(LocalPath)) { try { string dirName = ExtendedPath.GetDirectoryName(item); if (!directories.ContainsKey(dirName)) { DirectoryObject newDir = new DirectoryObject(); newDir.Name = dirName; newDir.LocalPath = item; if (depth > 1 || depth < 0) { newDir.LoadFromDisk(depth - 1); } AddDirectory(newDir); } } catch (IOException) { } } } catch (DirectoryNotFoundException) { directories = new Dictionary<string, DirectoryObject>(); } directories.Values.Where(x => !Directory.Exists(x.LocalPath)).Select(x => directories.Remove(x.Name)); directories.Values.Select(x => { x.LoadFromDisk(); return x; }); }
public override void Deserialize(XElement xmlData) { base.Deserialize(xmlData); files = new Dictionary<string, FileObject>(); foreach (XElement item in xmlData.Element(XmlNamesExtended.Files).Elements(XmlNamesExtended.FileObject)) { FileObject newFile = new FileObject(); newFile.Deserialize(item); files.Add(newFile.Name.ToLower(), newFile); } directories = new Dictionary<string, DirectoryObject>(); foreach (XElement item in xmlData.Element(XmlNamesExtended.Directories).Elements(XmlNamesExtended.DirectoryObject)) { DirectoryObject newDir = new DirectoryObject(); newDir.Deserialize(item); directories.Add(newDir.Name.ToLower(), newDir); } }
/// <summary> /// Adds a file to the data-structure /// </summary> /// <param name="file"></param> public void AddFile(FileObject file) { if (!files.ContainsKey(file.Name.ToLower()) && !directories.ContainsKey(file.Name.ToLower())) { files.Add(file.Name.ToLower(), file); file.Parent = this; } }