private static HarddiskDirectory ToHarddiskDirectory(this ConfigNode configNode, Harddisk harddisk, VolumePath path)
        {
            HarddiskDirectory directory = new HarddiskDirectory(harddisk, path);

            foreach (ConfigNode fileNode in configNode.GetNodes("file"))
            {
                directory.CreateFile(fileNode.GetValue(FilenameValueString), fileNode.ToHarddiskFile(harddisk, directory));
            }

            foreach (ConfigNode dirNode in configNode.GetNodes("directory"))
            {
                string dirName = dirNode.GetValue(DirnameValueString);

                directory.CreateDirectory(dirName, dirNode.ToHarddiskDirectory(harddisk, VolumePath.FromString(dirName, path)));
            }

            return(directory);
        }
        public static ConfigNode ToConfigNode(this HarddiskDirectory directory, string nodeName)
        {
            ConfigNode node = new ConfigNode(nodeName);

            node.AddValue(DirnameValueString, directory.Name);

            foreach (VolumeItem item in directory)
            {
                if (item is HarddiskDirectory)
                {
                    HarddiskDirectory dir = item as HarddiskDirectory;
                    node.AddNode(dir.ToConfigNode("directory"));
                }

                if (item is HarddiskFile)
                {
                    HarddiskFile file = item as HarddiskFile;
                    node.AddNode(file.ToConfigNode("file"));
                }
            }

            return(node);
        }
 public static FileContent ToHarddiskFile(this ConfigNode configNode, Harddisk harddisk, HarddiskDirectory directory)
 {
     return(Decode(configNode.GetValue("line")));
 }
Example #4
0
        private static HarddiskDirectory ToHarddiskDirectory(this ConfigNode configNode, Harddisk harddisk, VolumePath path)
        {
            HarddiskDirectory directory = new HarddiskDirectory(harddisk, path);

            foreach (ConfigNode fileNode in configNode.GetNodes("file"))
            {
                directory.CreateFile(fileNode.GetValue(FilenameValueString), fileNode.ToHarddiskFile(harddisk, directory));
            }

            foreach (ConfigNode dirNode in configNode.GetNodes("directory"))
            {
                string dirName = dirNode.GetValue(DirnameValueString);

                directory.CreateDirectory(dirName, dirNode.ToHarddiskDirectory(harddisk, VolumePath.FromString(dirName, path)));
            }

            return directory;
        }
Example #5
0
 public static FileContent ToHarddiskFile(this ConfigNode configNode, Harddisk harddisk, HarddiskDirectory directory)
 {
     try
     {
         string content = null;
         if (configNode.TryGetValue("ascii", ref content)) // ASCII files just get decoded from the ConfigNode safe representation
         {
             return new FileContent(PersistenceUtilities.DecodeLine(content));
         }
         if (configNode.TryGetValue("binary", ref content)) // binary files get decoded from Base64 and gzip
         {
             return new FileContent(PersistenceUtilities.DecodeBase64ToBinary(content));
         }
         if (configNode.TryGetValue("line", ref content)) // fall back to legacy logic
         {
             return Decode(content);
         }
     }
     catch (Exception ex)
     {
         SafeHouse.Logger.LogError(string.Format("Exception caught loading file information: {0}\n\nStack Trace:\n{1}", ex.Message, ex.StackTrace));
     }
     SafeHouse.Logger.LogError(string.Format("Error loading file information from ConfigNode at path {0} on hard disk {1}", directory.Path, harddisk.Name));
     return new FileContent("");  // if there was an error, just return a blank file.
 }
Example #6
0
 public Harddisk(int size)
 {
     Capacity = size;
     RootHarddiskDirectory = new HarddiskDirectory(this, VolumePath.EMPTY);
 }
Example #7
0
 public HarddiskFile(HarddiskDirectory harddiskDirectory, string name)
     : base(harddiskDirectory.Volume as Harddisk,
     VolumePath.FromString(name, harddiskDirectory.Path))
 {
     this.hardiskDirectory = harddiskDirectory;
 }
Example #8
0
 public static FileContent ToHarddiskFile(this ConfigNode configNode, Harddisk harddisk, HarddiskDirectory directory)
 {
     try
     {
         string content = null;
         if (configNode.TryGetValue("ascii", ref content)) // ASCII files just get decoded from the ConfigNode safe representation
         {
             return(new FileContent(PersistenceUtilities.DecodeLine(content)));
         }
         if (configNode.TryGetValue("binary", ref content)) // binary files get decoded from Base64 and gzip
         {
             return(new FileContent(PersistenceUtilities.DecodeBase64ToBinary(content)));
         }
         if (configNode.TryGetValue("line", ref content)) // fall back to legacy logic
         {
             return(Decode(content));
         }
     }
     catch (Exception ex)
     {
         SafeHouse.Logger.LogError(string.Format("Exception caught loading file information: {0}\n\nStack Trace:\n{1}", ex.Message, ex.StackTrace));
     }
     SafeHouse.Logger.LogError(string.Format("Error loading file information from ConfigNode at path {0} on hard disk {1}", directory.Path, harddisk.Name));
     return(new FileContent(""));  // if there was an error, just return a blank file.
 }
Example #9
0
 public HarddiskFile(HarddiskDirectory harddiskDirectory, string name) : base(harddiskDirectory.Volume as Harddisk,
                                                                              VolumePath.FromString(name, harddiskDirectory.Path))
 {
     this.hardiskDirectory = harddiskDirectory;
 }