Esempio n. 1
0
 public static void WriteToFile(TemplateMap map, string path)
 {
     try
     {
         Directory.CreateDirectory(Path.GetDirectoryName(path));
         using (var fileStream = File.OpenWrite(path))
         {
             var serizlier = new DataContractJsonSerializer(
                 typeof(TemplateMap),
                 new DataContractJsonSerializerSettings()
             {
                 UseSimpleDictionaryFormat = true
             });
             serizlier.WriteObject(fileStream, map);
         }
     }
     catch (System.Exception e)
     {
         AddAnyFilePackage.LogToOutputPane(string.Concat(
                                               "Could not save the mapping file to: ",
                                               path,
                                               "\r\n",
                                               e.Message));
     }
 }
Esempio n. 2
0
 public static TemplateMap LoadFromFile(string path)
 {
     if (File.Exists(path))
     {
         try
         {
             using (var fileStream = File.OpenRead(path))
             {
                 var deserializer = new DataContractJsonSerializer(typeof(TemplateMap));
                 return(deserializer.ReadObject(fileStream) as TemplateMap);
             }
         }
         catch (Exception e)
         {
             AddAnyFilePackage.LogToOutputPane(string.Concat(
                                                   "There was error loading the mappings from: ",
                                                   path,
                                                   "\r\n",
                                                   e.Message));
         }
     }
     return(null);
 }