Beispiel #1
0
        public void RegistConsumerByTopic(bool durable, string exchange, string routingKey,
                                          EventHandler <BasicDeliverEventArgs> eventHandler)
        {
            try
            {
                if (_channel.IsClosed)
                {
                    Connect();
                }

                lock (_lockObj)
                {
                    _channel.ExchangeDeclare(exchange, ExchangeType.Topic, durable);
                    var queueName = _channel.QueueDeclare().QueueName;
                    _channel.QueueBind(queueName, exchange, routingKey);

                    var consumer = new EventingBasicConsumer(_channel);
                    consumer.Received += eventHandler;
                    _channel.BasicConsume(queueName, true, consumer);
                    _topic.Add(new MqEnevt
                    {
                        Durable      = durable,
                        Exchange     = exchange,
                        RoutingKey   = routingKey,
                        EventHandler = eventHandler
                    });
                }
            }
            catch (Exception e)
            {
                Nami.Delay(5).Seconds()
                .Do(() => { RegistConsumerByTopic(durable, exchange, routingKey, eventHandler); });
            }
        }
Beispiel #2
0
        public ActionResult CustomRun(int customTime, string matchIdList)
        {
            ResponesJson jsonResp = new ResponesJson();

            try
            {
                var matches = InitMatchList();

                //指定賽事資料
                string[]    matchArray = matchIdList.Split(',');
                List <long> checklist  = new List <long>();
                foreach (var id in matchArray)
                {
                    checklist.Add(long.Parse(id));
                }

                //checklist.Add(13854605);
                //checklist.Add(13649001);

                List <long> mlist = new List <long>();



                foreach (var matchid in checklist)
                {
                    if (matches.Contains(matchid))
                    {
                        mlist.Add(matchid);
                    }
                }

                if (mlist.Count == 0)
                {
                    Log.Info($"無賽事走地與賠率資料");
                    jsonResp.Success    = false;
                    jsonResp.ResultData = "無賽事走地與賠率資料";
                    return(Content(JsonConvert.SerializeObject(jsonResp)));
                }
                Nami.Delay(1).Seconds().Do(() =>
                {
                    foreach (var matchid in mlist)
                    {
                        if (!CacheTool.ThreadExist(matchid) && CacheTool.MatchList.Count < 5)
                        {
                            Log.Info($"即將重播 {matchid} 場的賽事走地與賠率資料");
                            new MatchV1(matchid, customTime).BetRadarStart();
                        }
                    }
                });

                jsonResp.Success    = true;
                jsonResp.ResultData = RefreshList();
            }
            catch (Exception ex)
            {
                jsonResp.ResultData = ex.Message;
                jsonResp.Success    = false;
            }
            return(Content(JsonConvert.SerializeObject(jsonResp)));
        }
Beispiel #3
0
        private static void Loop(int index, int count)
        {
            Log.Info($"{index} loop {count} now {DateTime.Now:HH:mm:ss.fff}");

            var ss = index;

            Nami.Delay(2000).Do(() => { Loop(ss, ++count); });
        }
Beispiel #4
0
        public void Connect()
        {
            //連線到 RabbitMQ
            if (_mqConnection != null)
            {
                if (_mqConnection.IsOpen)
                {
                    Log.Info($"{HostName} _mqConnection.IsOpen=>{_mqConnection.IsOpen} return;");
                    return;
                }

                _mqConnection.ConnectionShutdown -= MqConnectionShutdown;
                _mqConnection.Close();
                _mqConnection.Dispose();
                _mqConnection = null;
            }

            Log.Info($"try to connect {HostName}");
            var rebind = _topic.ToArray();

            _topic.Clear();
            try
            {
                lock (_lockObj)
                {
                    _factory = new ConnectionFactory
                    {
                        HostName = HostName,
                        Port     = Port,
                        UserName = UserName,
                        Password = Password
                    };

                    _mqConnection = _factory.CreateConnection();
                    _mqConnection.ConnectionShutdown += MqConnectionShutdown;
                    _channel = _mqConnection.CreateModel();

                    foreach (var mqEnevt in rebind)
                    {
                        RegistConsumerByTopic(mqEnevt.Durable, mqEnevt.Exchange, mqEnevt.RoutingKey,
                                              mqEnevt.EventHandler);
                    }
                }

                Log.Info($"RabbitMQ Connection to {HostName} is open => {_mqConnection.IsOpen}");
            }
            catch (Exception e)
            {
                _topic.Clear();
                _topic.AddRange(rebind);
                Log.Error($"{HostName} {e.StackTrace ?? "No StackTrace Info"}\n{e.Message ?? "No Message Info"}\n");
                Nami.Delay(5).Seconds().Do(Connect);
            }
        }
Beispiel #5
0
 private void RunTask(object param)
 {
     lock (locker)
     {
         var jobParam = (JobParam)param;
         Nami.Delay(1).Seconds().Do(() =>
         {
             Log.Info($"即將重播 {jobParam.MatchID} 場的賽事走地與賠率資料");
             new Match(jobParam.MatchID, jobParam.Time).RiskmanStart();
         });
     }
 }
Beispiel #6
0
        private void PushOddstToSportServer(int index)
        {
            try
            {
                if (index + 1 > Odds.Length)
                {
                    Log.Info($"賽事編號:{MatchId},第{index + 1}次賠率資料送完");
                    DataSave.SwitchOddsActive(MatchId);
                    CacheTool.MatchRemove(MatchId);
                    return;
                }

                Odds[index].Status = 1;
                var ot = new OperationRequest
                {
                    OperationCode = (int)OperationCode.MainService,
                    ActionCode    = (int)MainServiceActionCode.BroadcastOdds,
                    Parameters    = new Dictionary <byte, object> {
                        { 1, Odds[index] }
                    }
                };
                var lodData = JsonConvert.SerializeObject(Odds[index]);
                Log.Info($"賽事編號:{MatchId},第{index + 1}次發送賠率資料:{lodData}");

                var pevMsgNr = (index == 0) ? 0 : Odds[index - 1].MsgNr;
                if (Odds[index].MsgNr > pevMsgNr || pevMsgNr == 0)
                {
                    DataSave.SwitchOddsActive(Odds[index].MatchId, /*Odds[index].OddsId,*/ Odds[index].MsgNr);
                    DataSave.UpdateMatchCurrentPeriodStart(Odds[index].MatchId);
                }

                int timer = 0;
                if (index <= Odds.Length - 1)
                {
                    timer = avgTimeForOdds;
                }
                else
                {
                    timer = modTimeForOdds;
                }

                Nami.Delay(timer).Do(() =>
                {
                    PushOddstToSportServer(index + 1);
                });
            }
            catch (Exception ex)
            {
                var lodData = JsonConvert.SerializeObject(Odds[index]);
                Log.Info($"賽事編號:{MatchId},第{index + 1}次失敗,失敗原因:{ex.Message},失敗原因:{ex.StackTrace}");
            }
        }
Beispiel #7
0
        public void Connect()
        {
            //連線到 RabbitMQ
            if (_mqConnection != null)
            {
                if (_mqConnection.IsOpen)
                {
                    return;
                }

                _mqConnection.ConnectionShutdown -= MqConnectionShutdown;
                _mqConnection.Close();
                _mqConnection.Dispose();
                _mqConnection = null;
            }

            var rebind = _topic.ToArray();

            _topic.Clear();
            try
            {
                lock (_lockObj)
                {
                    _factory = new ConnectionFactory
                    {
                        HostName = HostName,
                        Port     = Port,
                        UserName = UserName,
                        Password = Password
                    };

                    _mqConnection = _factory.CreateConnection();
                    _mqConnection.ConnectionShutdown += MqConnectionShutdown;
                    _channel = _mqConnection.CreateModel();

                    foreach (var mqEnevt in rebind)
                    {
                        RegistConsumerByTopic(mqEnevt.Durable, mqEnevt.Exchange, mqEnevt.RoutingKey,
                                              mqEnevt.EventHandler);
                    }
                }
            }
            catch (Exception e)
            {
                _topic.Clear();
                _topic.AddRange(rebind);
                Nami.Delay(5).Seconds().Do(Connect);
            }
        }
Beispiel #8
0
        public static void DoOddsBatch(string message, string JsonData, int excuteTimes = 0)
        {
            try
            {
                var url     = $"{ServerSite}/integration/batch-odd-change/";
                var request = (HttpWebRequest)WebRequest.Create(url);
                request.Method      = "POST"; // 方法
                request.KeepAlive   = true;   //是否保持連線
                request.ContentType = "application/json; charset=utf-8";
                var sb = new StringBuilder();
                sb.Append($"{JsonData}");
                var param = sb.ToString();
                var bs    = Encoding.UTF8.GetBytes(param);

                Log.Debug($"SendOddsBatchToRiskMan => message:{message}\n apiurl:{url}\n parame:{sb}\n");

                using (var reqStream = request.GetRequestStream())
                {
                    reqStream.Write(bs, 0, bs.Length);
                }

                using (var response = (HttpWebResponse)request.GetResponse())
                {
                    using (var sr = new StreamReader(response.GetResponseStream()))
                    {
                        var result = sr.ReadToEnd();
                        sr.Close();
                        Log.Debug($"SendOddsBatchToRiskMan => message:{message}\n apiurl:{url}\n parame:{sb}\n result:{(int)response.StatusCode}");
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, $"SendOddsBatchToRiskMan => message:{message}\n {ex.StackTrace}\n{ex.Message}\n");
                Nami.Delay(1).Seconds().Do(() =>
                {
                    DoOddsBatch(JsonData, excuteTimes++);
                });
            }

            if (excuteTimes >= 10)
            {
                Log.Error($"SendOddsBatchToRiskManData=> message:{message}\n {JsonData}\n");
            }
        }
Beispiel #9
0
        public void Connect()
        {
            //連線到 RabbitMQ
            if (_mqConnection != null)
            {
                if (_mqConnection.IsOpen)
                {
                    Log.Info($"{HostName} _mqConnection.IsOpen=>{_mqConnection.IsOpen} return;");
                    return;
                }

                _mqConnection.ConnectionShutdown -= MqConnectionShutdown;
                _mqConnection.Close();
                _mqConnection.Dispose();
                _mqConnection = null;
            }

            Log.Info($"try to connect {HostName}");

            _factory = new ConnectionFactory
            {
                HostName = HostName,
                Port     = Port,
                UserName = UserName,
                Password = Password
            };

            try
            {
                lock (_lockObj)
                {
                    _mqConnection = _factory.CreateConnection();
                    _mqConnection.ConnectionShutdown += MqConnectionShutdown;
                    _channel = _mqConnection.CreateModel();
                }

                Log.Info($"RabbitMQ Connection to {HostName} is open => {_mqConnection.IsOpen}");
            }
            catch (Exception e)
            {
                Log.Error(e, $"{HostName} Connect Exception:{e.StackTrace} {e.Message}");
                Nami.Delay(5).Seconds().Do(Connect);
            }
        }
Beispiel #10
0
        private void PushOddsToRiskMan(int index)
        {
            try
            {
                if (index + 1 > RiskOddsDataList.Count)
                {
                    Log.Info($"賽事編號:{MatchId},第{index + 1}次賠率資料送完");
                    //賠率送完即結算
                    DataSave.DoSettle(MatchId, 1); //全場
                    DataSave.DoSettle(MatchId, 2); //半場
                    //DataSave.SwitchOddsActive(MatchId);
                    CacheTool.MatchRemove(MatchId);
                    return;
                }
                var message = $"賽事編號:{MatchId},第{index + 1}次賠率資料傳送";
                SendRisk.DoOddsBatch(message, JsonConvert.SerializeObject(RiskOddsDataList[index]));

                Log.Info(message + $", Data => {JsonConvert.SerializeObject(RiskOddsDataList[index])}");

                int timer = 0;
                if (index <= RiskOddsDataList.Count - 1)
                {
                    timer = avgTimeForOddsRisk;
                }
                else
                {
                    timer = modTimeForOddsRisk;
                }

                Nami.Delay(timer).Do(() =>
                {
                    PushOddsToRiskMan(index + 1);
                });
            }
            catch (Exception ex)
            {
                var lodData = JsonConvert.SerializeObject(Odds[index]);
                Log.Info($"賽事編號:{MatchId},第{index + 1}次失敗,失敗原因:{ex.Message},失敗原因:{ex.StackTrace}");
            }
        }
Beispiel #11
0
        public ActionResult RadomRun(int randomTime, int randomCnt)
        {
            ResponesJson jsonResp = new ResponesJson();

            try
            {
                List <long> mlist    = new List <long>();
                var         matches  = InitMatchList();
                Random      rand     = new Random(Guid.NewGuid().GetHashCode());
                List <int>  listLinq = new List <int>(Enumerable.Range(0, matches.Count() - 1));
                listLinq = listLinq.OrderBy(num => rand.Next()).ToList <int>();

                for (int i = 0; i < randomCnt; i++)
                {
                    mlist.Add(matches[listLinq[i]]);
                }

                Nami.Delay(1).Seconds().Do(() =>
                {
                    foreach (var matchid in mlist)
                    {
                        if (!CacheTool.ThreadExist(matchid) && CacheTool.MatchList.Count < 5)
                        {
                            Log.Info($"即將重播 {matchid} 場的賽事走地與賠率資料");
                            new Match(matchid, randomTime).BetRadarStart();
                        }
                    }
                });
                jsonResp.Success    = true;
                jsonResp.ResultData = RefreshList();
            }
            catch (Exception ex)
            {
                jsonResp.ResultData = ex.Message;
                jsonResp.Success    = false;
            }
            return(Content(JsonConvert.SerializeObject(jsonResp)));
        }
Beispiel #12
0
        public void RegistConsumerByTopic(bool durable, string exchange, string routingKey,
                                          EventHandler <BasicDeliverEventArgs> eventHandler)
        {
            try
            {
                if (_channel.IsClosed)
                {
                    Connect();
                }

                lock (_lockObj)
                {
                    _channel.ExchangeDeclare(exchange, ExchangeType.Topic, durable);
                    var queueName = _channel.QueueDeclare().QueueName;
                    _channel.QueueBind(queueName, exchange, routingKey);

                    var consumer = new EventingBasicConsumer(_channel);
                    consumer.Received += eventHandler;
                    _channel.BasicConsume(queueName, true, consumer);
                    _topic.Add(new MqEnevt
                    {
                        Durable      = durable,
                        Exchange     = exchange,
                        RoutingKey   = routingKey,
                        EventHandler = eventHandler
                    });
                }

                Log.Info($"{HostName} RegistConsumerByTopic exchange:{exchange} routingKey:{routingKey} success");
            }
            catch (Exception e)
            {
                Log.Error($"{HostName} {e.StackTrace ?? "No StackTrace Info"}\n{e.Message ?? "No Message Info"}\n");
                Nami.Delay(5).Seconds()
                .Do(() => { RegistConsumerByTopic(durable, exchange, routingKey, eventHandler); });
            }
        }
Beispiel #13
0
        private void PushOddsToIntegration(int index)
        {
            try
            {
                if (index + 1 > OddsDt.Rows.Count)
                {
                    Log.Info($"賽事編號:{MatchId},第{index + 1}次賠率資料送完");
                    CacheTool.MatchRemove(MatchId);
                    return;
                }

                var lodData = OddsDt.Rows[index]["JsonData"].ToString();

                ToMq("odds", "odds.replaylive", EntityTool.Serialize(lodData));
                Log.Info($"賽事編號:{MatchId},第{index + 1}次發送賠率資料:{lodData}");

                int timer = 0;
                if (index <= Odds.Length - 1)
                {
                    timer = avgTimeForOdds;
                }
                else
                {
                    timer = modTimeForOdds;
                }

                Nami.Delay(timer).Do(() =>
                {
                    PushOddstToSportServer(index + 1);
                });
            }
            catch (Exception ex)
            {
                var lodData = JsonConvert.SerializeObject(Odds[index]);
                Log.Info($"賽事編號:{MatchId},第{index + 1}次失敗,失敗原因:{ex.Message},失敗原因:{ex.StackTrace}");
            }
        }
Beispiel #14
0
        private static void Main(string[] args)
        {
            var now = DateTime.Now;

            Log.Info($"Start at {now:HH:mm:ss}");

            /*Nami.Delay(20000).Do(() =>
             * {
             *  foreach (var s in new[] {1, 2, 3})
             *  {
             *      var ss = s;
             *      Nami.Delay(2000).Do(() =>
             *      {
             *          Loop(ss, 0);
             *      });
             *  }
             * });*/
            Nami.Every(450).Milliseconds().Times(2).Do(() => { PrintData("Every 450 Milliseconds", DateTime.Now); });
            Nami.Every(1).Seconds().Times(3).Do(() => { PrintData("Every 1 Seconds Times 3", DateTime.Now); });
            Nami.Every(10).Minutes().Do(() => { PrintData("Every 10 Minutes", DateTime.Now); });
            Nami.Every(10).Minutes().AfterExecuteTask().Do(() =>
            {
                PrintData("Every 10 Minutes and AfterExecuteTask(didn't work)", DateTime.Now);
                Thread.Sleep(4 * 60 * 1000);
            });
            Nami.Every(600).Seconds().AfterExecuteTask().Do(() =>
            {
                PrintData("Every 600 Seconds and sleep 4 Minutes", DateTime.Now);
                Thread.Sleep(4 * 60 * 1000);
            });
            Nami.Delay(4000).Times(4).Do(() => { PrintData("Delay 4000 ms Times 4", DateTime.Now); });

            now = now.AddSeconds(17).AddMilliseconds(100);
            Nami.EveryMonday().At(now.Hour, now.Minute, now.Second).Do(() => { PrintData("Monday", DateTime.Now); });
            Nami.EveryTuesday().At(now.Hour, now.Minute, now.Second).Do(() => { PrintData("Tuesday", DateTime.Now); });
            Nami.EveryWednesday().At(now.Hour, now.Minute, now.Second)
            .Do(() => { PrintData("Wednesday", DateTime.Now); });
            Nami.EveryThursday().At(now.Hour, now.Minute, now.Second)
            .Do(() => { PrintData("Thursday", DateTime.Now); });
            Nami.EveryFriday().At(now.Hour, now.Minute, now.Second).Do(() => { PrintData("Friday", DateTime.Now); });
            Nami.EverySaturday().At(now.Hour, now.Minute, now.Second)
            .Do(() => { PrintData("Saturday", DateTime.Now); });
            Nami.EverySunday().At(now.Hour, now.Minute, now.Second).Do(() => { PrintData("Sunday", DateTime.Now); });

            now = now.AddSeconds(1);
            Nami.Every(1).Hours().At(now.Hour, now.Minute, now.Second).Do(() =>
            {
                PrintData("Every 1 Hours", DateTime.Now);
            });

            now = now.AddSeconds(1);
            Nami.Every(1).Days().At(now.Hour, now.Minute, now.Second)
            .Do(() => { PrintData("Every 1 Days", DateTime.Now); });

            now = now.AddSeconds(1);
            Nami.Everyday().At(now.Hour, now.Minute, now.Second).Do(() => { PrintData("Everyday", DateTime.Now); });

            Console.ReadKey();

            Nami.EverySunday().At(6, 0, 0).Do(() => { PrintData("EverySunday().Days().At(6,0,0)   ", DateTime.Now); });
            Nami.EveryMonday().At(6, 0, 0).Do(() => { PrintData("EveryMonday().Days().At(6,0,0)   ", DateTime.Now); });
            Nami.EveryMonday().At(12, 0, 0).Do(() =>
            {
                PrintData("EveryMonday().Days().At(12,0,0)   ", DateTime.Now);
            });

            Nami.EveryTuesday().At(6, 0, 0).Do(() => { PrintData("EveryMonday().Days().At(6,0,0)   ", DateTime.Now); });
            Nami.EveryTuesday().At(12, 0, 0)
            .Do(() => { PrintData("EveryMonday().Days().At(12,0,0)   ", DateTime.Now); });

            Nami.Everyday().At(6, 0, 0).Do(() => { PrintData("Everyday().At(6,0,0)   ", DateTime.Now); });

            Nami.Every(1).Days().Do(() => { PrintData("Every(1).Days()   ", DateTime.Now); });
            Nami.Every(1).Days().At(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second + 2).Do(() =>
            {
                PrintData("Every(1).Days().At   ", DateTime.Now);
            });
            Nami.Every(2).Days().At(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second + 2).Do(() =>
            {
                PrintData("Every(2).Days().At   ", DateTime.Now);
            });

            Nami.Every(1).Hours().At(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second + 2).Do(() =>
            {
                PrintData("Every Hours   ", DateTime.Now);
            });
            Nami.Every(2).Hours().At(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second + 2).Do(() =>
            {
                PrintData("Every 2 Hours   ", DateTime.Now);
            });
            Nami.Every(1).Minutes().Do(() => { PrintData("Every(1).Minutes()", DateTime.Now); });
            Nami.Every(2).Minutes().Do(() => { PrintData("Every(2).Minutes()", DateTime.Now); });

            Nami.Delay(1).Seconds().Times(5).Do(() =>
            {
                Log.Info($"Nami.Delay(1).Seconds() {DateTime.Now:HH:mm:ss}");
            });
            var d = Nami.Delay(1).Seconds().Times(5).Do(() => { PrintData(" Dispose ", DateTime.Now); });

            d.Dispose();
            Nami.Delay(30).Seconds().Times(5).Do(() => { PrintData("Delay(30) 5 times", DateTime.Now); });
            Nami.RightNow().Times(3).Do(() => { PrintData("RightNow 3 times", DateTime.Now); });
            Nami.RightNow().Do(() => { PrintData("Just RightNow   ", DateTime.Now); });
            Nami.Delay(1000).Milliseconds().Do(() =>
            {
                PrintData($"Just Delay(1000) execute:{DateTime.Now:HH:mm:ss.fff}", DateTime.Now);
            });
            Nami.Every(60000).Milliseconds().Do(() =>
            {
                PrintData("Just Every(60000).Milliseconds()   ", DateTime.Now);
            });
            Nami.Everyday().At(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second + 5)
            .Do(() => { PrintData("Everyday   ", DateTime.Now); });

            Console.ReadKey();
            IFiber pool   = new PoolFiber();
            IFiber thread = new ThreadFiber();

            pool.Start();
            thread.Start();

            pool.ScheduleOnInterval(() => { PrintData("pool  ", DateTime.Now); }, 0, 150000);
            var td = thread.ScheduleOnInterval(() => { PrintData("thread", DateTime.Now); }, 0, 100000);

            thread.ScheduleOnInterval(() => { PrintData("thread ten second", DateTime.Now); }, 0, 100000);
            for (var i = 0; i < 100; i++)
            {
                var i1 = i;
                thread.Enqueue(() => { PrintData($"thread  {i1}", DateTime.Now); });
            }

            pool.Schedule(() =>
            {
                Console.WriteLine($"td Dispose");
                td.Dispose();
                for (var i = 0; i < 10; i++)
                {
                    thread.Enqueue(() => { PrintData("Schedule start thread  ", DateTime.Now); });
                }
            }, 20000);
            Nami.Every(10).Seconds().AfterExecuteTask().Do(() => { RunSleepCron("Af", 10, 600); });
            Nami.Every(10).Seconds().AfterExecuteTask().Do(() => { RunSleepCron("Af", 10, 600); });
            Nami.Every(10).Seconds().BeforeExecuteTask().Do(() => { RunSleepCron("Be", 10, 0); });
            Nami.Every(10).Seconds().BeforeExecuteTask().Do(() => { RunSleepCron("Be", 10, 0); });



            Nami.Every(100).Seconds().Do(() =>
            {
                thread.Enqueue(() => { PrintData(" Nami.Every(1).Seconds().Do  ", DateTime.Now); });
            });

            Nami.Every(150).Seconds().Do(() => { PrintData("Nami  ", DateTime.Now); });
            Nami.Every(1).Hours().At(0, 02, 0).Do(() => { PrintData("Hours  2", DateTime.Now); });
            Nami.Delay(1500).Do(() => { PrintData("Delay  ", DateTime.Now); });
            Nami.EveryTuesday().At(14, 13, 40).Do(() =>
            {
                PrintData("Nami.EveryTuesday().At(n, n, n)  ", DateTime.Now);
            });

            Nami.Every(1).Minutes().Do(() => { PrintData("Nami.Every(1).Minutes()", DateTime.Now); });
            Nami.Every(2).Minutes().At(0, 0, 15).Do(() =>
            {
                PrintData("Nami.Every(2).Minutes().At(0,0,15)", DateTime.Now);
            });

            Nami.Delay(1000).Do(() => { PrintData("Delay  ", DateTime.Now); });
            Nami.Delay(2500).Do(() => { PrintData("Delay  ", DateTime.Now); });
            Nami.Delay(3500).Do(() => { PrintData("Delay  ", DateTime.Now); });
            Nami.Delay(4500).Do(() => { PrintData("Delay  ", DateTime.Now); });
            //thread.Dispose();
            Console.ReadKey();
        }
Beispiel #15
0
        private void PushScoutToMq(int index)
        {
            try
            {
                if (index + 1 > Scout.Length)
                {
                    Log.Info($"賽事編號:{MatchId} 第{index + 1}次走地資料送完");
                    return;
                }

                Scout[index].Type = Scout[index].TypeId;

                if (Scout[index].Type == 1013 && (Scout[index].ExtraInfo == 6 ||
                                                  Scout[index].ExtraInfo == 7 ||
                                                  Scout[index].ExtraInfo == 31 ||
                                                  Scout[index].ExtraInfo == 100))
                {
                    DataSave.UpdateMatchCurrentPeriodStart(MatchId);
                    DataSave.UpdateMatchStatus(MatchId, Scout[index].ExtraInfo);
                }

                if (index > 1 && Scout[index].MatchScore != Scout[index - 1].MatchScore)
                {
                    DataSave.UpdateMatcScore(MatchId, Scout[index].MatchScore);
                }

                var tj = new TransJson
                {
                    Success = true,
                    Code    = "1.0",
                    Message = null,
                    Key     = "RMQ_LiveCompetition",
                    Result  = Scout[index]
                };
                //走地動畫
                ToMq("livescout", Scout[index].MatchId.ToString(), JsonConvert.SerializeObject(tj));
                //通知 Clinet 狀態
                var tSportServer = JsonConvert.SerializeObject(Scout[index]);
                ToMq("livescout", "sport.server", tSportServer);

                Log.Info($"賽事編號:{MatchId} 第{index + 1}次走地動畫&通知推送 {tSportServer}");

                int timer = 0;
                if (index <= Odds.Length - 1)
                {
                    timer = avgTimeForScout;
                }
                else
                {
                    timer = modTimeForScout;
                }

                Nami.Delay(timer).Do(() =>
                {
                    PushScoutToMq(index + 1);
                });
            }
            catch (Exception ex)
            {
                var tSportServer = JsonConvert.SerializeObject(Scout[index]);
                Log.Info($"賽事編號:{MatchId},第{index + 1}次失敗,失敗原因:{ex.Message}, 失敗原因:{ex.StackTrace}");
            }
        }