public static bool SaveMapTable(List <CrmCmConnection> mapTable) { string fileDirectory = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); fileDirectory = Path.Combine(fileDirectory, "SyncCRM_CM"); string fileName = "MapTable"; if ((fileDirectory == null) || (fileName == null)) { throw new Exception("There is no file directory or file name"); } string filePath = Path.Combine(fileDirectory, fileName); try { if (Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } if (!File.Exists(filePath)) { FileStream fileStream = File.Create(filePath); fileStream.Close(); } using (StreamWriter writer = new StreamWriter(filePath)) { string json = JsonConvert.SerializeObject(mapTable); writer.Write(ManageMapTable.Encrypt(json)); } } catch (Exception e) { throw new Exception(e.Message.ToString()); } return(true); }
public static List <CrmCmConnection> LoadMapTable() { string fileDirectory = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); fileDirectory = Path.Combine(fileDirectory, "SyncCRM_CM"); string fileName = "MapTable"; if ((fileDirectory == null) || (fileName == null)) { throw new Exception("There is no file directory or file name"); } string filePath = Path.Combine(fileDirectory, fileName); try { if (!Directory.Exists(fileDirectory)) { Directory.CreateDirectory(fileDirectory); } if (!File.Exists(filePath)) { FileStream fileStream = File.Create(filePath); fileStream.Close(); } using (StreamReader reader = new StreamReader(filePath)) { string json = reader.ReadToEnd(); List <CrmCmConnection> cmCrmConnectio = JsonConvert.DeserializeObject <List <CrmCmConnection> >(ManageMapTable.Decrypt(json)); return(cmCrmConnectio == null ? new List <CrmCmConnection>() { } : cmCrmConnectio); } } catch (Exception e) { throw new Exception(e.Message.ToString()); } }