private ConnectionInfo GetConnectionInfo(string database)
        {
            ConnectionInfo info = ObjectHelper.CloneObject <ConnectionInfo>(this.connectionInfo);

            info.Database = database;
            return(info);
        }
Ejemplo n.º 2
0
        private T CloneDbObject <T>(T dbObject, string owner) where T : DatabaseObject
        {
            if (dbObject == null)
            {
                return(null);
            }

            T clonedObj = ObjectHelper.CloneObject <T>(dbObject);

            clonedObj.Owner = owner;

            return(clonedObj);
        }
        public static Guid Save(AccountProfileInfo info, bool rememberPassword)
        {
            AccountProfileInfo cloneInfo = ObjectHelper.CloneObject <AccountProfileInfo>(info);

            if (!rememberPassword || info.IntegratedSecurity)
            {
                cloneInfo.Password = "";
            }
            else if (rememberPassword && !string.IsNullOrEmpty(info.Password))
            {
                cloneInfo.Password = AesHelper.Encrypt(info.Password);
            }

            List <AccountProfileInfo> profiles = new List <AccountProfileInfo>();

            if (File.Exists(ProfilePath))
            {
                profiles = (List <AccountProfileInfo>)JsonConvert.DeserializeObject(File.ReadAllText(ProfilePath), typeof(List <AccountProfileInfo>));
            }

            AccountProfileInfo oldProfile = profiles.FirstOrDefault(item => item.Id == info.Id);

            Guid id = info.Id;

            if (oldProfile == null)
            {
                profiles.Add(cloneInfo);
            }
            else
            {
                id = oldProfile.Id;

                ObjectHelper.CopyProperties(info, oldProfile);

                if (rememberPassword && !string.IsNullOrEmpty(info.Password))
                {
                    oldProfile.Password = AesHelper.Encrypt(info.Password);
                }
            }

            File.WriteAllText(ProfilePath, JsonConvert.SerializeObject(profiles, Formatting.Indented));

            return(id);
        }
Ejemplo n.º 4
0
        public static string Save(ConnectionProfileInfo info, bool rememberPassword)
        {
            ConnectionInfo connectionInfo = ObjectHelper.CloneObject <ConnectionInfo>(info.ConnectionInfo);

            info.Database = connectionInfo.Database;

            if (!rememberPassword)
            {
                connectionInfo.Password = "";
            }

            string encrptedPassword = "";

            if (rememberPassword && !string.IsNullOrEmpty(connectionInfo.Password))
            {
                encrptedPassword = AesHelper.Encrypt(connectionInfo.Password);
            }

            string profileName = info.Name;

            if (string.IsNullOrEmpty(profileName))
            {
                profileName = info.ConnectionDescription;
            }

            var accountProfiles = AccountProfileManager.GetProfiles(info.DatabaseType);

            AccountProfileInfo accountProfile = accountProfiles.FirstOrDefault(item => item.Server == connectionInfo.Server &&
                                                                               item.Port == connectionInfo.Port &&
                                                                               item.UserId == connectionInfo.UserId &&
                                                                               item.IntegratedSecurity == connectionInfo.IntegratedSecurity);

            bool changed = false;

            if (accountProfile != null)
            {
                if (!accountProfile.IntegratedSecurity && accountProfile.Password != encrptedPassword)
                {
                    changed = true;
                    accountProfile.Password = connectionInfo.Password;
                }
            }
            else
            {
                changed        = true;
                accountProfile = new AccountProfileInfo()
                {
                    DatabaseType = info.DatabaseType
                };
                ObjectHelper.CopyProperties(connectionInfo, accountProfile);
            }

            if (changed)
            {
                AccountProfileManager.Save(accountProfile, rememberPassword);
            }

            List <ConnectionProfileInfo> profiles = new List <ConnectionProfileInfo>();

            if (File.Exists(ProfilePath))
            {
                profiles = (List <ConnectionProfileInfo>)JsonConvert.DeserializeObject(File.ReadAllText(ProfilePath), typeof(List <ConnectionProfileInfo>));
            }

            ConnectionProfileInfo oldProfile = profiles.FirstOrDefault(item => item.Name == info.Name && item.DatabaseType == info.DatabaseType);

            if (oldProfile == null)
            {
                info.AccountProfileId = accountProfile.Id;
                profiles.Add(info);
            }
            else
            {
                ObjectHelper.CopyProperties(info, oldProfile);
            }

            File.WriteAllText(ProfilePath, JsonConvert.SerializeObject(profiles, Formatting.Indented));

            return(profileName);
        }