private void AutoButton_Click(object sender, EventArgs e)
 {
     try
     {
         var client = new HttpClient()
         {
             Timeout = TimeSpan.FromSeconds(5)
         };
         var res = client.GetAsync("https://raw.githubusercontent.com/caishuai163/tips/master/ss/conf.json").Result;
         if (!res.IsSuccessStatusCode)
         {
             return;
         }
         var data = res.Content.ReadAsStringAsync().Result;
         Dictionary <string, string> json = JsonConvert.DeserializeObject <Dictionary <string, string> >(data);
         Server s = new Server()
         {
             server      = json["ip"],
             server_port = int.Parse(json["port"]),
             password    = json["pwd"],
             method      = json["method"]
         };
         var isExist = _modifiedConfiguration.configs.Exists(f => f.server.Equals(s.server) && f.server_port == s.server_port);
         if (!isExist)
         {
             Configuration.AddDefaultServerOrServer(_modifiedConfiguration, s);
             LoadServerNameListToUI(_modifiedConfiguration);
             UpdateIndexToEnd();
         }
     }
     catch (Exception ex) {
         Console.WriteLine("我的日志:" + ex.ToString());
     }
 }
示例#2
0
 private void AddButton_Click(object sender, EventArgs e)
 {
     if (ValidateAndSaveSelectedServerDetails(isSave: true))
     {
         Configuration.AddDefaultServerOrServer(_modifiedConfiguration);
         LoadServerNameListToUI(_modifiedConfiguration);
         _lastSelectedIndex = (ServersListBox.SelectedIndex = _modifiedConfiguration.configs.Count - 1);
     }
 }
示例#3
0
 private void AddButton_Click(object sender, EventArgs e)
 {
     if (ValidateAndSaveSelectedServerDetails(isSave: true))
     {
         Configuration.AddDefaultServerOrServer(_modifiedConfiguration);
         LoadServerNameListToUI(_modifiedConfiguration);
         UpdateIndexToEnd();
     }
 }
示例#4
0
 private void DuplicateButton_Click(object sender, EventArgs e)
 {
     if (ValidateAndSaveSelectedServerDetails(isCopy: true))
     {
         Server currServer = _modifiedConfiguration.configs[_lastSelectedIndex];
         Configuration.AddDefaultServerOrServer(_modifiedConfiguration, currServer, _lastSelectedIndex + 1);
         LoadServerNameListToUI(_modifiedConfiguration);
         _lastSelectedIndex = (ServersListBox.SelectedIndex = (_lastSelectedIndex + 1));
     }
 }
示例#5
0
 private void AddButton_Click(object sender, EventArgs e)
 {
     if (!ValidateAndSaveSelectedServerDetails())
     {
         return;
     }
     Configuration.AddDefaultServerOrServer(_modifiedConfiguration);
     LoadServerNameListToUI(_modifiedConfiguration);
     ServersListBox.SelectedIndex = _modifiedConfiguration.configs.Count - 1;
     _lastSelectedIndex           = ServersListBox.SelectedIndex;
 }
示例#6
0
        private void DeleteButton_Click(object sender, EventArgs e)
        {
            _modifiedConfiguration.configs.RemoveAt(_lastSelectedIndex);

            if (_modifiedConfiguration.configs.Count == 0)
            {
                Configuration.AddDefaultServerOrServer(_modifiedConfiguration);
            }

            LoadServerNameListToUI(_modifiedConfiguration);
            UpdateIndexToEnd();
            LoadSelectedServerDetails();

            UpdateButtons();
        }
示例#7
0
        private void DeleteButton_Click(object sender, EventArgs e)
        {
            _modifiedConfiguration.configs.RemoveAt(_lastSelectedIndex);

            if (_modifiedConfiguration.configs.Count == 0)
            {
                Configuration.AddDefaultServerOrServer(_modifiedConfiguration);
            }

            LoadServerNameListToUI(_modifiedConfiguration);
            ServersListBox.SelectedIndexChanged -= ServersListBox_SelectedIndexChanged;

            _lastSelectedIndex = (ServersListBox.SelectedIndex = (_lastSelectedIndex >= _modifiedConfiguration.configs.Count ? (_modifiedConfiguration.configs.Count - 1) : _lastSelectedIndex));

            ServersListBox.SelectedIndexChanged += ServersListBox_SelectedIndexChanged;
            LoadSelectedServerDetails();

            UpdateButtons();
        }
示例#8
0
        private void DeleteButton_Click(object sender, EventArgs e)
        {
            _lastSelectedIndex = ServersListBox.SelectedIndex;
            if (_lastSelectedIndex >= 0 && _lastSelectedIndex < _modifiedConfiguration.configs.Count)
            {
                _modifiedConfiguration.configs.RemoveAt(_lastSelectedIndex);
            }
            if (_modifiedConfiguration.configs.Count == 0)
            {
                Configuration.AddDefaultServerOrServer(_modifiedConfiguration);
            }
            if (_lastSelectedIndex >= _modifiedConfiguration.configs.Count)
            {
                // can be -1
                _lastSelectedIndex = _modifiedConfiguration.configs.Count - 1;
            }
            ServersListBox.SelectedIndex = _lastSelectedIndex;
            LoadServerNameListToUI(_modifiedConfiguration);
            ServersListBox.SelectedIndex = _lastSelectedIndex;
            LoadSelectedServerDetails();

            UpdateButtons();
        }