Exemplo n.º 1
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.
 }
Exemplo n.º 2
0
 private static FileContent Decode(string input)
 {
     try
     {
         return(new FileContent(PersistenceUtilities.DecodeBase64ToBinary(input)));
     }
     catch // if there is an exception of any kind decoding, fall back to standard decoding
     {
         string decodedString = PersistenceUtilities.DecodeLine(input);
         return(new FileContent(decodedString));
     }
 }
Exemplo n.º 3
0
 private static FileContent Decode(string input)
 {
     try
     {
         return(new FileContent(PersistenceUtilities.DecodeBase64ToBinary(input)));
     }
     catch (FormatException)
     {
         // standard encoding
         string decodedString = PersistenceUtilities.DecodeLine(input);
         return(new FileContent(decodedString));
     }
 }