示例#1
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);
                    }
                }
            }
        }
示例#2
0
 public void Save()
 {
     XmlSerializerHelper.SerializeToFile(instance, Path.Combine(new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName, "MscrmTools.ConnectionsList.xml"));
 }