コード例 #1
0
 public static result Save(Dictionary <int, byte[]> items, string path)
 {
     try
     {
         Proto.ProtoBinaryData protoBinary = new Proto.ProtoBinaryData();
         byte[] fileBytes = protoBinary.protoSerialize(items);
         if (File.Exists(path))
         {
             File.Delete(path);
         }
         using (Stream file = File.OpenWrite(path))
         {
             file.Write(fileBytes, 0, fileBytes.Length);
         }
         return(null);
     }
     catch (Exception ex) { return(new result(null, ex)); }
 }
コード例 #2
0
 private static result LoadFileData(string path)
 {
     try
     {
         if (File.Exists(path))
         {
             Proto.ProtoBinaryData binaryData = new Proto.ProtoBinaryData();
             byte[] fileBytes = File.ReadAllBytes(path);
             if (fileBytes == null)
             {
                 return(new result(null, new Exception("Ошибка открытия файла")));
             }
             return(new result(fileBytes, null));
         }
         else
         {
             return(new result(null, new Exception($"Файл {path} не найден!")));
         }
     }
     catch (Exception ex) { return(new result(null, ex)); }
 }
コード例 #3
0
 private static result LoadBinaryData(string path)
 {
     try
     {
         if (File.Exists(path))
         {
             Proto.ProtoBinaryData    binaryData = new Proto.ProtoBinaryData();
             Dictionary <int, byte[]> items;
             byte[] fileBytes = File.ReadAllBytes(path);
             items = binaryData.protoDeserialize(fileBytes);
             if (items == null)
             {
                 return(new result(null, new Exception("Ошибка сериализации!")));
             }
             return(new result(items, null));
         }
         else
         {
             return(new result(null, new Exception($"Файл {path} не найден!")));
         }
     }
     catch (Exception ex) { return(new result(null, ex)); }
 }