Ejemplo n.º 1
0
        private void btnSave_Click(object sender, System.EventArgs e)
        {
            var curSettings = GetterSettings();

            if (!curSettings.Equals(orgCoreServSettings))
            {
                coreServ.UpdateCoreSettings(curSettings);
                servers.UpdateMarkList();
            }
            Close();
        }
        void ModifyServersSetting(
            List <VgcApis.Interfaces.ICoreServCtrl> list,
            int newMode, string newIP, int newPort, bool isPortAutoIncrease,
            string newMark, int newAutorun, int newImport, int newSkipCN)
        {
            Action <int, Action> worker = (index, next) =>
            {
                var portNumber = isPortAutoIncrease ? newPort + index : newPort;

                var server = list[index];
                if (!server.GetCoreCtrl().IsCoreRunning())
                {
                    ModifyServerSetting(
                        ref server,
                        newMode, newIP, portNumber,
                        newMark, newAutorun, newImport, newSkipCN);
                    server.InvokeEventOnPropertyChange();
                    next();
                    return;
                }

                server.GetCoreCtrl().StopCoreThen(() =>
                {
                    ModifyServerSetting(
                        ref server,
                        newMode, newIP, portNumber,
                        newMark, newAutorun, newImport, newSkipCN);
                    server.GetCoreCtrl().RestartCoreThen();
                    next();
                });
            };

            var    that = this;
            Action done = () =>
            {
                servers.UpdateMarkList();
                VgcApis.Misc.UI.RunInUiThread(btnModify, () =>
                {
                    that.Close();
                });
            };

            Misc.Utils.ChainActionHelperAsync(list.Count, worker, done);
        }