public void AllowOperater(object v)
        {
            string id   = string.Empty;
            bool   oper = false;

            if (v is OPENALLOW)
            {
                OPENALLOW value = (OPENALLOW)v;
                id   = value.basic.ID;
                oper = value.ALLOW;
            }
            else
            {
                CLOSEALLOW value = (CLOSEALLOW)v;
                id   = value.basic.ID;
                oper = value.ALLOW;
            }

            if (Workers.Keys.Contains(id))
            {
                Workers[id].bAllow = oper;
            }
        }
        /// <summary>
        /// 策略管理线程工作函数
        /// 任务:
        /// 1. 获取用户请求队列中的指令
        /// 2. 巡检工作组中订阅列表修改
        /// </summary>
        private void ThreadProc()
        {
            while (true)
            {
                if ((DateTime.Now - GlobalHeartBeat.GetGlobalTime()).TotalMinutes > 15)
                {
                    log.LogEvent("系统供血模块无响应,策略管理线程即将停止!");
                    KeyValuePair <string, object> message2 = new KeyValuePair <string, object>("THREAD_STRATEGY_MANAGEMENT", (object)false);
                    queue_system_status.GetQueue().Enqueue((object)message2);
                    //管理策略线程退出前,对正在运行的工作策略执行“绞杀”,并维护数据库记录,这个过程称为 grace broken
                    break;
                }


                while (QCommands.Count > 0)
                {
                    object obj = QCommands.Dequeue();

                    #region 指令类型判断
                    if (obj is OPENCREATE)
                    {
                        RecruitNewWorker(obj);
                    }
                    else if (obj is OPENMODIFY)
                    {
                        UpdateWorker(obj);
                    }
                    else if (obj is OPENALLOW)
                    {
                        OPENALLOW value = (OPENALLOW)obj;
                        AllowOperater((object)obj);
                    }
                    else if (obj is OPENRUN)
                    {
                        OPENRUN value = (OPENRUN)obj;
                        RunOperater((object)value);
                    }
                    else if (obj is OPENDELETE)
                    {
                        DeleteWorker(obj);
                    }
                    else if (obj is CLOSECREATE)
                    {
                        RecruitNewWorker(obj);
                    }
                    else if (obj is CLOSEMODIFY)
                    {
                        UpdateWorker(obj);
                    }
                    else if (obj is CLOSERUN)
                    {
                        CLOSERUN value = (CLOSERUN)obj;
                        RunOperater((object)value);
                    }
                    else if (obj is CLOSEALLOW)
                    {
                        CLOSEALLOW value = (CLOSEALLOW)obj;
                        AllowOperater((object)obj);
                    }
                    else if (obj is CLOSEDELETE)
                    {
                        DeleteWorker(obj);
                    }
                    else
                    {
                        continue;
                    }

                    #endregion
                }


                if (DateTime.Now.Second % 2 == 0)
                {
                    if (_logUpdateTime.Second != DateTime.Now.Second)
                    {
                        _logUpdateTime = DateTime.Now;

                        KeyValuePair <string, object> message1 = new KeyValuePair <string, object>("THREAD_STRATEGY_MANAGEMENT", (object)true);
                        queue_system_status.GetQueue().Enqueue((object)message1);

                        int count_0  = (from item in WorkersStratus where item.Value == 0 select item).Count();
                        int count_12 = (from item in WorkersStratus where item.Value == 1 || item.Value == 2 select item).Count();


                        if (DateTime.Now.Second % 31 == 0 || DateTime.Now.Second % 32 == 0)
                        {
                            log.LogEvent("运行策略: " + (count_0 + count_12).ToString() + "\n问题或结束策略: " + count_0.ToString());
                        }

                        Dictionary <String, StrategyInfo> strategyInfo = new Dictionary <string, StrategyInfo>();
                        foreach (var item in Workers)
                        {
                            WorkersStratus[item.Key] = item.Value.Status;
                            item.Value.Status        = 0;

                            StrategyInfo info = new StrategyInfo()
                            {
                                BelongUser         = item.Value.User,
                                StrType            = item.Value.Type,
                                Contract           = item.Value.CT,
                                Status             = item.Value.Status,
                                StrategyInstanceID = item.Value.StrategyInstanceID,
                                HandNum            = item.Value.HD,
                                SubscribeList      = new List <string>(item.Value.SubscribeList.Count)
                            };

                            strategyInfo.Add(item.Value.StrategyInstanceID, info);

                            foreach (string s in item.Value.SubscribeList)
                            {
                                info.SubscribeList.Add(s);
                            }
                        }

                        int count = Workers.Count;
                        KeyValuePair <string, object> message2 = new KeyValuePair <string, object>("STRATEGY_N", (object)count);
                        queue_system_status.GetQueue().Enqueue((object)message2);

                        Dictionary <string, StrategyInfo> value = new Dictionary <string, StrategyInfo>();
                        foreach (KeyValuePair <string, StrategyWorker> pair in Workers)
                        {
                            StrategyInfo info = new StrategyInfo()
                            {
                                BelongUser         = pair.Value.User,
                                Contract           = pair.Value.CT,
                                HandNum            = pair.Value.HD,
                                Status             = pair.Value.Status,
                                StrategyInstanceID = pair.Value.StrategyInstanceID,
                                StrType            = pair.Value.Type,
                                SubscribeList      = pair.Value.SubscribeList
                            };
                            value.Add(pair.Value.StrategyInstanceID, info);
                        }
                        KeyValuePair <string, object> message3 = new KeyValuePair <string, object>("STRATEGY_P", (object)value);
                        queue_system_status.GetQueue().Enqueue((object)message3);

                        KeyValuePair <string, object> message4 = new KeyValuePair <string, object>("THREAD_STRATEGY_WORKER", (object)WorkersStratus);
                        queue_system_status.GetQueue().Enqueue((object)message4);
                    }
                }

                //巡检工作组订阅内容修改
                try
                {
                    CheckSubscribeUpdate();
                }
                catch (Exception ex) { DBAccessLayer.LogSysInfo("StrategyMonitorClass-ThreadProc", ex.ToString()); ex.ToString(); }

                Thread.Sleep(10);
            }
        }
Beispiel #3
0
        public static void UpdateDatebase(string type, object value)
        {
            switch (type)
            {
            case "A1":
            {
                OPENCREATE data = (OPENCREATE)value;

                break;
            }

            case "A2":
            {
                OPENMODIFY data = (OPENMODIFY)value;
                break;
            }

            case "A3":
            {
                OPENRUN data = (OPENRUN)value;
                break;
            }

            case "A4":
            {
                OPENALLOW data = (OPENALLOW)value;
                break;
            }

            case "A5":
            {
                OPENDELETE data = (OPENDELETE)value;
                break;
            }

            case "B1":
            {
                CLOSECREATE data = (CLOSECREATE)value;
                break;
            }

            case "B2":
            {
                CLOSEMODIFY data = (CLOSEMODIFY)value;
                break;
            }

            case "B3":
            {
                CLOSERUN data = (CLOSERUN)value;
                break;
            }

            case "B4":
            {
                CLOSEALLOW data = (CLOSEALLOW)value;
                break;
            }

            case "B5":
            {
                CLOSEDELETE data = (CLOSEDELETE)value;
                break;
            }

            case "C1":
            {
                MakeOrder data = (MakeOrder)value;
                break;
            }
            }
        }