/// <summary>
        /// Restore Crm connections list from the file
        /// </summary>
        /// <returns>List of Crm connections</returns>
        public CrmConnections LoadConnectionsList()
        {
            try
            {
                CrmConnections crmConnections;
                if (File.Exists(ConfigurationFile))
                {
                    crmConnections = CrmConnections.LoadFromFile(ConfigurationFile);

                    if (!string.IsNullOrEmpty(crmConnections.Password))
                    {
                        crmConnections.Password = CryptoManager.Decrypt(crmConnections.Password,
                                                                        CryptoPassPhrase,
                                                                        CryptoSaltValue,
                                                                        CryptoHashAlgorythm,
                                                                        CryptoPasswordIterations,
                                                                        CryptoInitVector,
                                                                        CryptoKeySize);
                    }

                    foreach (var detail in crmConnections.Connections)
                    {
                        // 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;
                            }
                        }

                        // Fix old connection for TimeOut
                        if (detail.Timeout == TimeSpan.Zero)
                        {
                            detail.Timeout = new TimeSpan(1200000000);
                        }
                    }
                }
                else
                {
                    crmConnections = new CrmConnections
                    {
                        Connections = new List <ConnectionDetail>()
                    };
                }

                return(crmConnections);
            }
            catch (Exception error)
            {
                throw new Exception("Error while deserializing configuration file. Details: " + error.Message);
            }
        }
示例#2
0
        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)));
            }
        }
示例#3
0
        public static CrmConnections LoadFromFile(string filePath)
        {
            var crmConnections = new CrmConnections();

            if (!File.Exists(filePath))
            {
                return(crmConnections);
            }

            using (var fStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                if (fStream.Length == 0)
                {
                    return(crmConnections);
                }

                var doc = XDocument.Load(fStream);
                var crmConnectionsElt = doc.Element("CrmConnections");
                if (crmConnectionsElt == null)
                {
                    return(crmConnections);
                }

                var connectionsElt = crmConnectionsElt.Element("Connections");
                if (connectionsElt == null)
                {
                    return(crmConnections);
                }

                var useMruDisplayElt = connectionsElt.Element("UseMruDisplay");
                if (useMruDisplayElt != null)
                {
                    crmConnections.UseMruDisplay = useMruDisplayElt.Value == "true";
                }

                var proxyElt = connectionsElt.Element("Proxy");
                if (proxyElt != null)
                {
                    var useCustomProxyElt = proxyElt.Element("UseCustomProxy");
                    if (useCustomProxyElt != null)
                    {
                        crmConnections.UseCustomProxy = useCustomProxyElt.Value == "true";
                    }
                    var useInternetExplorerProxyElt = proxyElt.Element("UseInternetExplorerProxy");
                    if (useInternetExplorerProxyElt != null)
                    {
                        crmConnections.UseInternetExplorerProxy = useInternetExplorerProxyElt.Value == "true";
                    }
                    var addressElt = proxyElt.Element("Address");
                    if (addressElt != null)
                    {
                        crmConnections.ProxyAddress = addressElt.Value;
                    }
                    var usernameElt = proxyElt.Element("Username");
                    if (usernameElt != null)
                    {
                        crmConnections.UserName = usernameElt.Value;
                    }
                    var passwordElt = proxyElt.Element("Password");
                    if (passwordElt != null)
                    {
                        crmConnections.Password = passwordElt.Value;
                    }
                    var byPassProxyOnLocalElt = proxyElt.Element("ByPassProxyOnLocal");
                    if (byPassProxyOnLocalElt != null)
                    {
                        crmConnections.ByPassProxyOnLocal = byPassProxyOnLocalElt.Value == "true";
                    }
                    var useDefaultCredentialsElt = proxyElt.Element("UseDefaultCredentials");
                    if (useDefaultCredentialsElt != null)
                    {
                        crmConnections.UseDefaultCredentials = useDefaultCredentialsElt.Value == "true";
                    }
                }

                foreach (var elt in doc.Descendants("ConnectionDetail"))
                {
                    var cd = new ConnectionDetail();

                    var authElement = elt.Element("AuthType");
                    if (authElement != null)
                    {
                        cd.AuthType =
                            (AuthenticationProviderType)
                            Enum.Parse(typeof(AuthenticationProviderType), authElement.Value);
                    }

                    var connectionIdElement = elt.Element("ConnectionId");
                    cd.ConnectionId = connectionIdElement != null ? new Guid(connectionIdElement.Value) : Guid.NewGuid();

                    var connectionNameElement = elt.Element("ConnectionName");
                    cd.ConnectionName = connectionNameElement != null ? connectionNameElement.Value : null;

                    var homeRealmUrlElement = elt.Element("HomeRealmUrl");
                    cd.HomeRealmUrl = homeRealmUrlElement != null ? homeRealmUrlElement.Value : null;

                    var isCustomAuthElement = elt.Element("IsCustomAuth");
                    cd.IsCustomAuth = isCustomAuthElement != null && isCustomAuthElement.Value == "true";

                    var organizationElement = elt.Element("Organization");
                    if (organizationElement != null)
                    {
                        cd.Organization = organizationElement.Value;
                    }

                    var originalUrlElement = elt.Element("OriginalUrl");
                    if (originalUrlElement != null)
                    {
                        cd.OriginalUrl = originalUrlElement.Value;
                    }

                    var organizationFriendlyNameElement = elt.Element("OrganizationFriendlyName");
                    if (organizationFriendlyNameElement != null)
                    {
                        cd.OrganizationFriendlyName = organizationFriendlyNameElement.Value;
                    }

                    var organizationServiceUrlElement = elt.Element("OrganizationServiceUrl");
                    if (organizationServiceUrlElement != null)
                    {
                        cd.OrganizationServiceUrl = organizationServiceUrlElement.Value;
                    }

                    var organizationDataServiceUrlElement = elt.Element("OrganizationDataServiceUrl");
                    if (organizationDataServiceUrlElement != null)
                    {
                        cd.OrganizationDataServiceUrl = organizationDataServiceUrlElement.Value;
                    }

                    var organizationUrlNameElement = elt.Element("OrganizationUrlName");
                    if (organizationUrlNameElement != null)
                    {
                        cd.OrganizationUrlName = organizationUrlNameElement.Value;
                    }

                    var organizationVersionElement = elt.Element("OrganizationVersion");
                    if (organizationVersionElement != null)
                    {
                        cd.OrganizationVersion = organizationVersionElement.Value;
                    }

                    var savePasswordElement = elt.Element("SavePassword");
                    cd.SavePassword = savePasswordElement != null && savePasswordElement.Value == "true";

                    var serverNameElement = elt.Element("ServerName");
                    if (serverNameElement != null)
                    {
                        cd.ServerName = serverNameElement.Value;
                    }

                    var serverPortElement = elt.Element("ServerPort");
                    if (serverPortElement != null)
                    {
                        int serverPort = string.IsNullOrEmpty(serverPortElement.Value)
                            ? 80
                            : int.Parse(serverPortElement.Value);

                        cd.ServerPort = serverPort;
                    }

                    var timeOutElement = elt.Element("Timeout");
                    if (timeOutElement != null)
                    {
                        long timeoutValue = string.IsNullOrEmpty(timeOutElement.Value)
                           ? 1200000000
                           : long.Parse(timeOutElement.Value);

                        cd.TimeoutTicks = timeoutValue;
                    }

                    var useIfdElement = elt.Element("UseIfd");
                    cd.UseIfd = useIfdElement != null && useIfdElement.Value == "true";
                    var useOnlineElement = elt.Element("UseOnline");
                    cd.UseOnline = useOnlineElement != null && useOnlineElement.Value == "true";
                    var useOsdpElement = elt.Element("UseOsdp");
                    cd.UseOsdp = useOsdpElement != null && useOsdpElement.Value == "true";
                    var useSslElement = elt.Element("UseSsl");
                    cd.UseSsl = useSslElement != null && useSslElement.Value == "true";

                    var userDomainElement = elt.Element("UserDomain");
                    if (timeOutElement != null)
                    {
                        cd.UserDomain = userDomainElement.Value;
                    }

                    var userNameElement = elt.Element("UserName");
                    if (userNameElement != null)
                    {
                        cd.UserName = userNameElement.Value;
                    }

                    var userPasswordElement = elt.Element("UserPassword");
                    if (userPasswordElement != null)
                    {
                        cd.SetPassword(userPasswordElement.Value, true);
                    }

                    var webApplicationUrlElement = elt.Element("WebApplicationUrl");
                    if (webApplicationUrlElement != null)
                    {
                        cd.WebApplicationUrl = webApplicationUrlElement.Value;
                    }

                    var lastUsedOnElt = elt.Element("LastUsedOn");
                    if (lastUsedOnElt != null)
                    {
                        cd.LastUsedOn = DateTime.Parse(lastUsedOnElt.Value, CultureInfo.InvariantCulture.DateTimeFormat);
                    }

                    var customInfo = elt.Element("CustomInformation");
                    if (customInfo != null)
                    {
                        cd.CustomInformation = new Dictionary <string, string>();
                        foreach (var custel in customInfo.Elements())
                        {
                            cd.CustomInformation.Add(custel.Name.LocalName, custel.Value);
                        }
                    }

                    crmConnections.Connections.Add(cd);
                }
            }

            return(crmConnections);
        }
示例#4
0
        /// <summary>
        /// Restore Crm connections list from the file
        /// </summary>
        /// <returns>List of Crm connections</returns>
        public CrmConnections LoadConnectionsList()
        {
            try
            {
                CrmConnections crmConnections;
                if (File.Exists(ConfigurationFile))
                {
                    crmConnections = CrmConnections.LoadFromFile(ConfigurationFile);

                    if (!string.IsNullOrEmpty(crmConnections.Password))
                    {
                        crmConnections.Password = CryptoManager.Decrypt(crmConnections.Password,
                        CryptoPassPhrase,
                        CryptoSaltValue,
                        CryptoHashAlgorythm,
                        CryptoPasswordIterations,
                        CryptoInitVector,
                        CryptoKeySize);
                    }

                    foreach (var detail in crmConnections.Connections)
                    {
                        // 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;
                            }
                        }

                        // Fix old connection for TimeOut
                        if (detail.Timeout == TimeSpan.Zero)
                        {
                            detail.Timeout = new TimeSpan(1200000000);
                        }
                    }
                }
                else
                {
                    crmConnections = new CrmConnections
                    {
                        Connections = new List<ConnectionDetail>()
                    };
                }

                return crmConnections;
            }
            catch (Exception error)
            {
                throw new Exception("Error while deserializing configuration file. Details: " + error.Message);
            }
        }
示例#5
0
        /// <summary>
        /// Saves Crm connections list to file
        /// </summary>
        public void SaveConnectionsFile(CrmConnections connectionsList)
        {
            if (!string.IsNullOrEmpty(connectionsList.Password))
            {
                connectionsList.Password = CryptoManager.Encrypt(connectionsList.Password,
                                                                 CryptoPassPhrase,
                                                                 CryptoSaltValue,
                                                                 CryptoHashAlgorythm,
                                                                 CryptoPasswordIterations,
                                                                 CryptoInitVector,
                                                                 CryptoKeySize);
            }

            var cache = new Dictionary <Guid, string>();

            lock (connectionsList.Connections)
            {
                foreach (var detail in connectionsList.Connections)
                {
                    if (!detail.ConnectionId.HasValue)
                    {
                        continue;
                    }

                    cache.Add(detail.ConnectionId.Value, detail.UserPassword);

                    if (detail.SavePassword)
                    {
                        if (!string.IsNullOrEmpty(detail.UserPassword))
                        {
                            detail.UserPassword = CryptoManager.Encrypt(detail.UserPassword,
                                                                        CryptoPassPhrase,
                                                                        CryptoSaltValue,
                                                                        CryptoHashAlgorythm,
                                                                        CryptoPasswordIterations,
                                                                        CryptoInitVector,
                                                                        CryptoKeySize);
                        }
                    }
                    else
                    {
                        detail.UserPassword = null;
                    }
                }

                XmlSerializerHelper.SerializeToFile(connectionsList, ConfigFileName);

                foreach (var detail in connectionsList.Connections)
                {
                    if (!detail.ConnectionId.HasValue)
                    {
                        continue;
                    }

                    if (detail.UserPassword == null)
                    {
                        detail.UserPassword = cache[detail.ConnectionId.Value];
                        continue;
                    }

                    if (!string.IsNullOrEmpty(detail.UserPassword))
                    {
                        detail.UserPassword = CryptoManager.Decrypt(detail.UserPassword,
                                                                    CryptoPassPhrase,
                                                                    CryptoSaltValue,
                                                                    CryptoHashAlgorythm,
                                                                    CryptoPasswordIterations,
                                                                    CryptoInitVector,
                                                                    CryptoKeySize);
                    }
                }
            }
        }
示例#6
0
        /// <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);
            }
        }
示例#7
0
        private void fsw_Changed(object sender, FileSystemEventArgs e)
        {
            if (e.ChangeType == WatcherChangeTypes.Changed)
            {
                ConnectionsList = LoadConnectionsList();

                ConnectionListUpdated(null, new EventArgs());
            }
        }
 public ConnectionFile(CrmConnections connections)
 {
     Name = connections.Name;
 }
示例#9
0
        public static CrmConnections LoadFromFile(string filePath)
        {
            var crmConnections = new CrmConnections();

            if (!File.Exists(filePath))
            {
                return crmConnections;
            }

            using (var fStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                if (fStream.Length == 0)
                {
                    return crmConnections;
                }

                var doc = XDocument.Load(fStream);
                var crmConnectionsElt = doc.Element("CrmConnections");
                if (crmConnectionsElt == null)
                    return crmConnections;

                var connectionsElt = crmConnectionsElt.Element("Connections");
                if (connectionsElt == null)
                    return crmConnections;

                 var useMruDisplayElt = connectionsElt.Element("UseMruDisplay");
                if (useMruDisplayElt != null)
                {
                    crmConnections.UseMruDisplay = useMruDisplayElt.Value == "true";
                }

                var proxyElt = connectionsElt.Element("Proxy");
                if (proxyElt != null)
                {
                    var useCustomProxyElt = proxyElt.Element("UseCustomProxy");
                    if(useCustomProxyElt != null)
                        crmConnections.UseCustomProxy = useCustomProxyElt.Value == "true";
                    var useInternetExplorerProxyElt = proxyElt.Element("UseInternetExplorerProxy");
                    if (useInternetExplorerProxyElt != null)
                        crmConnections.UseInternetExplorerProxy = useInternetExplorerProxyElt.Value == "true";
                    var addressElt = proxyElt.Element("Address");
                    if (addressElt != null)
                        crmConnections.ProxyAddress = addressElt.Value;
                    var usernameElt = proxyElt.Element("Username");
                    if (usernameElt != null)
                        crmConnections.UserName = usernameElt.Value;
                    var passwordElt = proxyElt.Element("Password");
                    if (passwordElt != null)
                        crmConnections.Password = passwordElt.Value;
                    var byPassProxyOnLocalElt = proxyElt.Element("ByPassProxyOnLocal");
                    if (byPassProxyOnLocalElt != null)
                        crmConnections.ByPassProxyOnLocal = byPassProxyOnLocalElt.Value == "true";
                    var useDefaultCredentialsElt = proxyElt.Element("UseDefaultCredentials");
                    if (useDefaultCredentialsElt != null)
                        crmConnections.UseDefaultCredentials = useDefaultCredentialsElt.Value == "true";
                }

                foreach (var elt in doc.Descendants("ConnectionDetail"))
                {
                    var cd = new ConnectionDetail();

                    var authElement = elt.Element("AuthType");
                    if (authElement != null)
                    {
                        cd.AuthType =
                            (AuthenticationProviderType)
                                Enum.Parse(typeof (AuthenticationProviderType), authElement.Value);
                    }

                    var connectionIdElement = elt.Element("ConnectionId");
                    cd.ConnectionId = connectionIdElement != null ? new Guid(connectionIdElement.Value) : Guid.NewGuid();

                    var connectionNameElement = elt.Element("ConnectionName");
                    cd.ConnectionName = connectionNameElement != null ? connectionNameElement.Value : null;

                    var homeRealmUrlElement = elt.Element("HomeRealmUrl");
                    cd.HomeRealmUrl = homeRealmUrlElement != null ? homeRealmUrlElement.Value : null;

                    var isCustomAuthElement = elt.Element("IsCustomAuth");
                    cd.IsCustomAuth = isCustomAuthElement != null && isCustomAuthElement.Value == "true";

                    var organizationElement = elt.Element("Organization");
                    if (organizationElement != null)
                    {
                        cd.Organization = organizationElement.Value;
                    }

                    var organizationFriendlyNameElement = elt.Element("OrganizationFriendlyName");
                    if (organizationFriendlyNameElement != null)
                    {
                        cd.OrganizationFriendlyName = organizationFriendlyNameElement.Value;
                    }

                    var organizationServiceUrlElement = elt.Element("OrganizationServiceUrl");
                    if (organizationServiceUrlElement != null)
                    {
                        cd.OrganizationServiceUrl = organizationServiceUrlElement.Value;
                    }

                    var organizationUrlNameElement = elt.Element("OrganizationUrlName");
                    if (organizationUrlNameElement != null)
                    {
                        cd.OrganizationUrlName = organizationUrlNameElement.Value;
                    }

                    var organizationVersionElement = elt.Element("OrganizationVersion");
                    if (organizationVersionElement != null)
                    {
                        cd.OrganizationVersion = organizationVersionElement.Value;
                    }

                    var savePasswordElement = elt.Element("SavePassword");
                    cd.SavePassword = savePasswordElement != null && savePasswordElement.Value == "true";

                    var serverNameElement = elt.Element("ServerName");
                    if (serverNameElement != null)
                    {
                        cd.ServerName = serverNameElement.Value;
                    }

                    var serverPortElement = elt.Element("ServerPort");
                    if (serverPortElement != null)
                    {
                        int serverPort = string.IsNullOrEmpty(serverPortElement.Value)
                            ? 80
                            : int.Parse(serverPortElement.Value);

                        cd.ServerPort = serverPort;
                    }

                    var timeOutElement = elt.Element("Timeout");
                    if (timeOutElement != null)
                    {
                         long timeoutValue = string.IsNullOrEmpty(timeOutElement.Value)
                            ? 1200000000
                            : long.Parse(timeOutElement.Value);

                        cd.TimeoutTicks = timeoutValue;
                    }

                    var useIfdElement = elt.Element("UseIfd");
                    cd.UseIfd = useIfdElement != null && useIfdElement.Value == "true";
                    var useOnlineElement = elt.Element("UseOnline");
                    cd.UseOnline = useOnlineElement != null && useOnlineElement.Value == "true";
                    var useOsdpElement = elt.Element("UseOsdp");
                    cd.UseOsdp = useOsdpElement != null && useOsdpElement.Value == "true";
                    var useSslElement = elt.Element("UseSsl");
                    cd.UseSsl = useSslElement != null && useSslElement.Value == "true";

                    var userDomainElement = elt.Element("UserDomain");
                    if (timeOutElement != null)
                    {
                        cd.UserDomain = userDomainElement.Value;
                    }

                    var userNameElement = elt.Element("UserName");
                    if (userNameElement != null)
                    {
                        cd.UserName = userNameElement.Value;
                    }

                    var userPasswordElement = elt.Element("UserPassword");
                    if (userPasswordElement != null)
                    {
                        cd.SetPassword(userPasswordElement.Value, true);
                    }

                    var webApplicationUrlElement = elt.Element("WebApplicationUrl");
                    if (webApplicationUrlElement != null)
                    {
                        cd.WebApplicationUrl = webApplicationUrlElement.Value;
                    }

                    var lastUsedOnElt = elt.Element("LastUsedOn");
                    if (lastUsedOnElt != null)
                    {
                        cd.LastUsedOn = DateTime.Parse(lastUsedOnElt.Value, CultureInfo.InvariantCulture.DateTimeFormat);
                    }

                    crmConnections.Connections.Add(cd);
                }
            }

            return crmConnections;
        }