public void Init()
 {
     lock (serverListLock)
     {
         serverList = new List<ServerInfo>();
         string[] encServerList = Properties.Settings.Default.ServerList ?? new string[0];
         foreach (string encServer in encServerList)
         {
             string decryptCredential = EncryptionUtils.Unprotect(encServer);
             string[] decryptCredentialComps = decryptCredential.Split(SEPARATOR);
             ServerInfo connection = new ServerInfo();
             connection.HostName = decryptCredentialComps[0];
             connection.UserName = decryptCredentialComps[1];
             connection.Password = decryptCredentialComps[2];
             connection.task = null;
             serverList.Add(connection);
         }
     }
 }
Example #2
0
        private string ProtectCredential(ServerInfo connection)
        {
            string Host = connection.HostName ?? string.Empty;
            string username = connection.UserName ?? string.Empty;
            string passwordSecret = connection.Password ?? string.Empty;

            return EncryptionUtils.Protect(String.Join(SEPARATOR.ToString(), new[] { Host, username, passwordSecret }));
        }
Example #3
0
 public bool UpdateServerInfo(ServerInfo server)
 {
     lock (serverListLock)
     {
         foreach (ServerInfo con in serverList)
         {
             if (server.HostName == con.HostName)
             {
                 serverList.Remove(con);
                 serverList.Add(server);
                 updateServerList();
                 return true;
             }
         }
         return false;
     }
 }
Example #4
0
        public void UpdateServerCredential(string credential)
        {
            log.Info("Receive credential update message");

            string decryptCredential = EncryptionUtils.UnprotectForLocalMachine(credential);
            string[] decryptCredentialComps = decryptCredential.Split(SEPARATOR);

            lock (serverListLock)
            {
                if (decryptCredentialComps.Length == 3)
                {//Add credential
                    System.Threading.Tasks.Task originalTask = null;
                    foreach (ServerInfo connection in serverList)
                    {
                        if (connection.HostName == decryptCredentialComps[0])
                        {
                            originalTask = connection.task;
                            serverList.Remove(connection);
                            log.Info("Refresh credential");
                            break;
                        }
                    }
                    ServerInfo newConnection = new ServerInfo();
                    newConnection.HostName = decryptCredentialComps[0];
                    newConnection.UserName = decryptCredentialComps[1];
                    newConnection.Password = decryptCredentialComps[2];
                    newConnection.task = originalTask;
                    serverList.Add(newConnection);
                    log.InfoFormat("Add credential, current credential size is {0}", serverList.Count);
                }
                else if (decryptCredentialComps.Length == 1)
                {//remove credential
                    foreach (ServerInfo connection in serverList)
                    {
                        if (connection.HostName == decryptCredentialComps[0])
                        {
                            serverList.Remove(connection);
                            log.InfoFormat("Remove credential, current credential size is {0}", serverList.Count);
                            break;
                        }
                    }
                }

                updateServerList();
            }
        }
Example #5
0
        public bool UpdateServerCredential(ServerInfo server, string masterName)
        {
            lock (serverListLock)
            {
                bool needRefresh = true;
                foreach (ServerInfo con in serverList)
                {
                    if (masterName == con.HostName)
                    {
                        needRefresh = false;
                        break;
                    }
                }

                serverList.Remove(server);
                if (needRefresh)
                {
                    server.HostName = masterName;
                    serverList.Add(server);
                }

                updateServerList();
                return needRefresh;
            }
        }