Пример #1
0
 static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
 {
     //SystemMonitor.Error(e.Exception.Message);
     Console.WriteLine(" e " + e.Exception);
     LogUtil.Error(e.Exception.ToString());
     LogUtil.Close();
 }
Пример #2
0
 static void Application_ThreadExit(object sender, EventArgs e)
 {
     LogUtil.Info("Application Exit");
     LogUtil.Close();
 }
Пример #3
0
        public override void Receive(object msg)
        {
            Console.WriteLine(" TimeCheckHandler  Receive ~~~~~~~~~~~ " + msg);
            string[] msgs = (string[])msg;

            Protocol protocol    = AppUtil.ParseProtocol(msgs[1]);
            int      paramAmount = AppUtil.StringToInt(msgs[2]);

            if (protocol != Protocol.UNKNOWN)
            {
                try
                {
                    switch (protocol)
                    {
                    case Protocol.S0002_1:
                        string   strServerTime = msgs[3];
                        DateTime serverTime;
                        serverTime = DateTime.Parse(strServerTime);

                        if (FXPA != null && !FXPA.IsDisposed)
                        {
                            if (!msgs.Contains(NULL))
                            {
                                if (serverTime.CompareTo(AppSetting.END_TIME) > 0)
                                {
                                    errCode = -1;
                                    MethodInvoker mi = new MethodInvoker(ShowErrorMsg);
                                    FXPA.BeginInvoke(mi);

                                    mi = new MethodInvoker(CloseApp);
                                    FXPA.BeginInvoke(mi);
                                }
                            }
                        }

                        int DAY = Convert.ToInt16(serverTime.Day);
                        AppContext.CURRENT_TIME = serverTime;

                        DateTime startTimeOfNormalDay = AppUtil.GetStartTimeOfNormalDay(AppContext.CURRENT_TIME);

                        if (DAY > LogUtil.DAY && serverTime.CompareTo(startTimeOfNormalDay) > 0)
                        {
                            MethodInvoker mi = new MethodInvoker(TimeLabelUpdate);
                            AppContext.TradeExpertControl.BeginInvoke(mi);
                            LogUtil.DAY = DAY;
                            LogUtil.Close();
                            LogUtil.init(true, true, true, true);
                        }
                        else if (DAY > AppContext.DAY)
                        {
                            AppContext.DAY = DAY;
                            DateTime      startTimeOfWeek   = AppUtil.GetStartTimeOfWeek(AppContext.CURRENT_TIME);
                            DateTime      startTimeOfBizDay = AppUtil.GetStartTimeOfBizToday(AppContext.CURRENT_TIME);
                            List <Signal> obsoletes         = new List <Signal>();
                            if (AppSetting.STATUS == AppSetting.TEST_ACCOUNT && serverTime.CompareTo(startTimeOfWeek) > 0)
                            {
                                if (AppContext.SignalDatas.Count > 0)
                                {
                                    lock (AppConst.SignalDatasLocker)
                                    {
                                        foreach (Signal signal in AppContext.SignalDatas)
                                        {
                                            if (signal.ProfitPrice != 0 && signal.ProfitTime.CompareTo(startTimeOfWeek) < 0)
                                            {
                                                obsoletes.Add(signal);
                                            }
                                        }
                                        foreach (Signal signal in obsoletes)
                                        {
                                            AppContext.SignalDatas.Remove(signal);
                                        }
                                    }
                                }
                            }
                            else if (serverTime.CompareTo(startTimeOfBizDay) > 0)
                            {
                                if (AppContext.SignalDatas.Count > 0)
                                {
                                    lock (AppConst.SignalDatasLocker)
                                    {
                                        foreach (Signal signal in AppContext.SignalDatas)
                                        {
                                            if (signal.ProfitPrice != 0 && signal.ProfitTime.CompareTo(startTimeOfBizDay) < 0)
                                            {
                                                obsoletes.Add(signal);
                                            }
                                        }
                                        foreach (Signal signal in obsoletes)
                                        {
                                            AppContext.SignalDatas.Remove(signal);
                                        }
                                    }
                                }
                            }

                            if (obsoletes != null && obsoletes.Count > 0)
                            {
                                MethodInvoker mi = new MethodInvoker(SignalListUpdate);
                                signalListView.BeginInvoke(mi);
                                mi = new MethodInvoker(StatListUpdate);
                                AppContext.StatListView.BeginInvoke(mi);
                                mi = new MethodInvoker(PriceListUpdate);
                                priceListView.BeginInvoke(mi);
                            }

                            obsoletes.Clear();
                            List <PublishInfo> obsoletes2 = new List <PublishInfo>();
                            if (AppContext.PublishInfos.Count > 0)
                            {
                                lock (AppContext.PublishInfos)
                                {
                                    foreach (PublishInfo info in AppContext.PublishInfos)
                                    {
                                        if (AppContext.CURRENT_TIME.Subtract(info.DateTime) > AppConst.AppTimeSpans[Interval.DAY1])
                                        {
                                            obsoletes2.Add(info);
                                        }
                                    }

                                    foreach (PublishInfo info in obsoletes2)
                                    {
                                        AppContext.PublishInfos.Remove(info);
                                    }
                                    if (obsoletes2 != null && obsoletes2.Count > 0)
                                    {
                                        MethodInvoker mi = new MethodInvoker(InfoListUpdate);
                                        infoListView.BeginInvoke(mi);
                                    }
                                }
                            }
                            obsoletes2.Clear();
                        }
                        break;
                    }
                }
                catch (Exception e)
                {
                    LogUtil.Info(" TimeCheckHandler  Receive  Exception~~~~~~~~~~~ " + e.StackTrace);
                }
            }
        }