Exemplo n.º 1
0
 void BindEventsTo(Controllers.CoreServerCtrl server)
 {
     server.OnCoreClosing     += InvokeEventOnCoreClosingIgnoreError;
     server.OnCoreStart       += OnTrackCoreStartHandler;
     server.OnCoreStop        += OnTrackCoreStopHandler;
     server.OnPropertyChanged += InvokeEventOnServerPropertyChange;
 }
Exemplo n.º 2
0
        void ReleaseEventsFrom(Controllers.CoreServerCtrl server)
        {
            server.OnCoreClosing -= InvokeEventOnCoreClosingIgnoreError;
            server.OnCoreStart   -= OnTrackCoreStartHandler;
            server.OnCoreStop    -= OnTrackCoreStopHandler;

            server.OnPropertyChanged -= InvokeEventOnServerPropertyChange;
        }
Exemplo n.º 3
0
        public bool AddServer(string config, string mark, bool quiet = false)
        {
            // first check
            if (IsServerExist(config))
            {
                return(false);
            }

            var coreInfo = new VgcApis.Models.Datas.CoreInfo
            {
                isInjectImport     = setting.CustomDefImportGlobalImport,
                isInjectSkipCNSite = setting.CustomDefImportBypassCnSite,
                customInbType      = setting.CustomDefImportMode,
                inbIp      = setting.CustomDefImportIp,
                inbPort    = setting.CustomDefImportPort,
                config     = config,
                customMark = mark,
            };

            var newServer = new Controllers.CoreServerCtrl(coreInfo);

            newServer.Run(cache, setting, configMgr, this);

            bool duplicated = true;

            lock (serverListWriteLock)
            {
                // double check
                if (!IsServerExist(config))
                {
                    coreServList.Add(newServer);
                    var idx = coreServList.Count();
                    newServer.GetCoreStates().SetIndexQuiet(idx);
                    AddNewMark(mark);
                    duplicated = false;
                }
            }

            if (duplicated)
            {
                newServer.Dispose();
                return(false);
            }

            BindEventsTo(newServer);
            if (!quiet)
            {
                newServer.GetConfiger().UpdateSummaryThen(() =>
                {
                    // UpdateSummaryThen will invoke OnServerPropertyChange.
                    InvokeEventOnServerCountChange(this, EventArgs.Empty);
                    RequireFormMainUpdate();
                });
            }
            setting.LazyGC();
            serverSaver.DoItLater();
            return(true);
        }
Exemplo n.º 4
0
        void DisposeCoreServThen(Controllers.CoreServerCtrl coreServ, Action next = null)
        {
            var copy = coreServ;

            VgcApis.Misc.Utils.RunInBackground(() =>
            {
                ReleaseEventsFrom(copy);
                copy.Dispose();
                next?.Invoke();
            });
        }
Exemplo n.º 5
0
        void ServerTrackingUpdateWorker(
            Controllers.CoreServerCtrl coreServCtrl,
            bool isStart)
        {
            var config = coreServCtrl?.GetConfiger()?.GetConfig();

            var curTrackerSetting =
                configMgr.GenCurTrackerSetting(
                    coreServList.AsReadOnly(),
                    config ?? string.Empty,
                    isStart);

            setting.SaveServerTrackerSetting(curTrackerSetting);
            return;
        }
Exemplo n.º 6
0
        void InitServerCtrlList()
        {
            lock (serverListWriteLock)
            {
                var coreInfoList = setting.LoadCoreInfoList();
                foreach (var coreInfo in coreInfoList)
                {
                    var server = new Controllers.CoreServerCtrl(coreInfo);
                    coreServList.Add(server);
                }
            }

            foreach (var server in coreServList)
            {
                server.Run(cache, setting, configMgr, this);
                BindEventsTo(server);
            }
        }