コード例 #1
0
 /// <summary>
 ///     系统关闭时调用
 /// </summary>
 internal static void OnZeroEnd()
 {
     RaiseEvent(ZeroNetEventType.AppStop);
     using (OnceScope.CreateScope(ZeroObjects))
     {
         ZeroTrace.WriteLine("[OnZeroEnd>>");
         SystemManager.Instance.HeartLeft();
         ApplicationState = StationState.Closing;
         if (HaseActiveObject)
         {
             Parallel.ForEach(ActiveObjects.ToArray(), obj =>
             {
                 try
                 {
                     ZeroTrace.WriteInfo(obj.Name, "*Close");
                     obj.OnZeroEnd();
                 }
                 catch (Exception e)
                 {
                     ZeroTrace.WriteException(obj.Name, e, "*Close");
                 }
             });
             WaitAllObjectSemaphore();
         }
         GC.Collect();
         ApplicationState = StationState.Closed;
         ZeroTrace.WriteLine("<<OnZeroEnd]");
     }
 }
コード例 #2
0
 /// <summary>
 ///     进入系统侦听
 /// </summary>
 internal static void Monitor()
 {
     using (OnceScope.CreateScope(ZeroApplication.Config))
     {
     }
     using (var poll = ZmqPool.CreateZmqPool())
     {
         poll.Prepare(new[] { ZSocket.CreateSubscriberSocket(ZeroApplication.Config.ZeroMonitorAddress) }, ZPollEvent.In);
         ZeroTrace.WriteLine("Zero center in monitor...");
         TaskEndSem.Release();
         while (ZeroApplication.IsAlive)
         {
             if (!poll.Poll() || !poll.CheckIn(0, out var message))
             {
                 continue;
             }
             if (!message.Unpack(out var item))
             {
                 continue;
             }
             OnMessagePush(item.ZeroEvent, item.SubTitle, item.Content);
         }
     }
     TaskEndSem.Release();
 }
コード例 #3
0
        /// <summary>
        ///     注销时调用
        /// </summary>
        internal static void OnZeroDestory()
        {
            if (!Monitor.TryEnter(ZeroObjects))
            {
                return;
            }
            ZeroTrace.WriteLine("[OnZeroDestory>>");
            RaiseEvent(ZeroNetEventType.AppEnd);
            using (OnceScope.CreateScope(ZeroObjects))
            {
                var array = ZeroObjects.Values.ToArray();
                ZeroObjects.Clear();
                Parallel.ForEach(array, obj =>
                {
                    try
                    {
                        ZeroTrace.WriteInfo(obj.Name, "*Destory");
                        obj.OnZeroDestory();
                    }
                    catch (Exception e)
                    {
                        ZeroTrace.WriteException(obj.Name, e, "*Destory");
                    }
                });

                GC.Collect();
                ZeroTrace.WriteLine("<<OnZeroDestory]");

                ZeroTrace.WriteLine("[OnZeroDispose>>");
                Parallel.ForEach(array, obj =>
                {
                    try
                    {
                        ZeroTrace.WriteInfo(obj.Name, "*Dispose");
                        obj.Dispose();
                    }
                    catch (Exception e)
                    {
                        ZeroTrace.WriteException(obj.Name, e, "*Dispose");
                    }
                });
                ZeroTrace.WriteLine("<<OnZeroDispose]");
            }
        }
コード例 #4
0
 /// <summary>
 ///     系统启动时调用
 /// </summary>
 internal static void OnStationStateChanged(StationConfig config)
 {
     using (OnceScope.CreateScope(ZeroObjects))
     {
         ZeroTrace.WriteLine("[OnStationStateChanged>>");
         Parallel.ForEach(ActiveObjects.ToArray(), obj =>
         {
             try
             {
                 obj.OnStationStateChanged(config);
             }
             catch (Exception e)
             {
                 ZeroTrace.WriteException(obj.Name, e, "OnStationStateChanged");
             }
         });
         ZeroTrace.WriteLine("<<OnStationStateChanged]");
     }
 }
コード例 #5
0
        /// <summary>
        ///     命令行方式管理
        /// </summary>
        public static void CommandConsole()
        {
            while (true)
            {
                var cmd = Console.ReadLine();
                if (String.IsNullOrWhiteSpace(cmd))
                {
                    continue;
                }
                switch (cmd.Trim().ToLower())
                {
                case "quit":
                case "exit":
                    Shutdown();
                    return;

                case "start":
                    Start();
                    continue;
                }

                var words = cmd.Split(' ', '\t', '\r', '\n');
                if (words.Length == 0)
                {
                    ZeroTrace.WriteLine("请输入正确命令");
                    continue;
                }

                var result = SystemManager.Instance.CallCommand(words);
                if (result.InteractiveSuccess)
                {
                    ZeroTrace.WriteInfo("Console", result.TryGetValue(ZeroFrameType.Status, out var value)
                        ? value
                        : result.State.Text());
                }
                else
                {
                    ZeroTrace.WriteError("Console", result.TryGetValue(ZeroFrameType.Status, out var value)
                        ? value
                        : result.State.Text());
                }
            }
        }
コード例 #6
0
 /// <summary>
 ///     系统启动时调用
 /// </summary>
 internal static void OnZeroInitialize()
 {
     using (OnceScope.CreateScope(ZeroObjects))
     {
         ZeroTrace.WriteLine("[OnZeroInitialize>>");
         Parallel.ForEach(ZeroObjects.Values.ToArray(), obj =>
         {
             try
             {
                 obj.OnZeroInitialize();
                 ZeroTrace.WriteInfo(obj.Name, "Initialize");
             }
             catch (Exception e)
             {
                 ZeroTrace.WriteException(obj.Name, e, "*Initialize");
             }
         });
         ZeroTrace.WriteLine("<<OnZeroInitialize]");
     }
 }
コード例 #7
0
        /// <summary>
        ///     系统启动时调用
        /// </summary>
        internal static void OnZeroStart()
        {
            Debug.Assert(!HaseActiveObject);
            using (OnceScope.CreateScope(ZeroObjects, ResetObjectActive))
            {
                ZeroTrace.WriteLine("[OnZeroStart>>");
#if DEBUG
                foreach (var obj in ZeroObjects.Values.ToArray())
                {
                    try
                    {
                        ZeroTrace.WriteInfo(obj.Name, "*Start");
                        obj.OnZeroStart();
                    }
                    catch (Exception e)
                    {
                        ZeroTrace.WriteException(obj.Name, e, "*Start");
                    }
                }
#else
                Parallel.ForEach(ZeroObjects.Values.ToArray(), obj =>
                {
                    try
                    {
                        ZeroTrace.WriteInfo(obj.Name, "*Start");
                        obj.OnZeroStart();
                    }
                    catch (Exception e)
                    {
                        ZeroTrace.WriteException(obj.Name, e, "*Start");
                    }
                });
#endif
                WaitAllObjectSemaphore();
            }
            SystemManager.Instance.HeartReady();
            ApplicationState = StationState.Run;
            RaiseEvent(ZeroNetEventType.AppRun);
            ZeroTrace.WriteLine("<<OnZeroStart]");
        }