Esempio n. 1
0
 private static void SaveWarningInfo()
 {
     while (true)
     {
         if (WarningHistory.Count == 0)
         {
             Thread.Sleep(2000);
         }
         else
         {
             try
             {
                 Model.WarningEntity we    = null;
                 Queue <string>      queue = new Queue <string>();
                 for (int i = WarningHistory.Count; i > -1; i--)
                 {
                     if (WarningHistory.Count > 0 && WarningHistory.TryDequeue(out we))
                     {
                         var s = string.Format("{0} {1}, {2}", DateTime.Today.ToShortDateString(), we.DataTime, we.WarningDescription);
                         queue.Enqueue(s);
                     }
                 }
                 File.AppendAllLines(WarningFilePath, queue, Encoding.UTF8);
             }
             catch (Exception ex)
             {
                 Program.logger.LogRunning("预警记录出错!", ex.Message);
             }
         }
     }
 }
Esempio n. 2
0
        private void TimerEvent(object sender, EventArgs e)
        {
            try
            {
                int index = listViewNFWarning.Items.Count - 1;
                Model.WarningEntity warning = null;

                if (!Program.Warnings.ContainsKey(this.Formula.ID) || Program.Warnings[this.Formula.ID].Count == 0)
                {
                    return;
                }

                var queue = Program.Warnings[this.Formula.ID];
                for (int i = 0; i < 20; i++)
                {
                    if (queue.Count > 0 && queue.TryDequeue(out warning))
                    {
                        if (index > -1)
                        {
                            this.listViewNFWarning.Items.RemoveAt(index);
                        }

                        WarningHistory.Enqueue(warning);

                        ListViewItem listViewItemAdded = new ListViewItem(new string[] { "1", warning.Code, warning.DataTime, Math.Round((decimal)warning.Match / 10000, 2).ToString("#0.00"), warning.SubValue.ToString("#0.000"), warning.SubType, warning.WarningCount.ToString(), warning.LargeVolume, warning.LargeVolumnCost, warning.LargeVolumnFlag });
                        listViewItemAdded.BackColor = warning.Background;
                        listViewItemAdded.Tag       = warning;


                        this.listViewNFWarning.Items.Insert(0, listViewItemAdded);
                        foreach (ListViewItem item in this.listViewNFWarning.Items)
                        {
                            if (item.Tag != null)
                            {
                                item.SubItems[0].Text = (item.Index + 1).ToString();
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Program.logger.LogRunning("预警功能定时出错:{0}\r\n  StackTrace:{1} ", ex.Message, ex.StackTrace);
            }
        }