public static CrmConnections LoadFromFile(string filePath) { var crmConnections = new CrmConnections("Default"); if (!Uri.IsWellFormedUriString(filePath, UriKind.Absolute) && !File.Exists(filePath)) { return(crmConnections); } using (var fStream = OpenStream(filePath)) { return((CrmConnections)XmlSerializerHelper.Deserialize(fStream, typeof(CrmConnections), typeof(ConnectionDetail))); } }
/// <summary> /// Restore Crm connections list from the file /// </summary> /// <returns>List of Crm connections</returns> public CrmConnections LoadConnectionsList() { CrmConnections crmConnections; try { if (File.Exists(ConfigFileName)) { using (var configReader = new StreamReader(ConfigFileName)) { crmConnections = (CrmConnections)XmlSerializerHelper.Deserialize(configReader.ReadToEnd(), typeof(CrmConnections)); } if (!string.IsNullOrEmpty(crmConnections.Password)) { crmConnections.Password = CryptoManager.Decrypt(crmConnections.Password, CryptoPassPhrase, CryptoSaltValue, CryptoHashAlgorythm, CryptoPasswordIterations, CryptoInitVector, CryptoKeySize); } foreach (var detail in crmConnections.Connections) { if (!string.IsNullOrEmpty(detail.UserPassword)) { detail.UserPassword = CryptoManager.Decrypt(detail.UserPassword, CryptoPassPhrase, CryptoSaltValue, CryptoHashAlgorythm, CryptoPasswordIterations, CryptoInitVector, CryptoKeySize); } // Fix for new connection code if (string.IsNullOrEmpty(detail.OrganizationUrlName)) { if (detail.UseIfd || detail.UseOnline || detail.UseOsdp) { var uri = new Uri(detail.OrganizationServiceUrl); detail.OrganizationUrlName = uri.Host.Split('.')[0]; } else { detail.OrganizationUrlName = detail.Organization; } } } } else { crmConnections = new CrmConnections { Connections = new List <ConnectionDetail>() }; } return(crmConnections); } catch (Exception error) { throw new Exception("Error while deserializing configuration file. Details: " + error.Message); } }