Ejemplo n.º 1
0
        /*
        static void LineT78AllSectionTravelCalc()
        {
            Line line = matrix.getLine("T78");

            ConsoleServer.WriteLine("=========Line T78 Section W TravelTime ==========");

            foreach (Section sec in line.getAllSectionEnum("W"))
            {
                try
                {
                    ConsoleServer.WriteLine(sec.sectionName + ":" + sec.getTravelTime() + "s");
                }
                catch (Exception ex)
                {
                    ConsoleServer.WriteLine(ex.Message + ex.StackTrace);
                }
            }

                 ConsoleServer.WriteLine("=========Line T78 Section E TravelTime ==========");

            foreach (Section sec in line.getAllSectionEnum("E"))
            {
                try
                {
                    ConsoleServer.WriteLine(sec.sectionName + ":" + sec.getTravelTime() + "s");
                }
                catch (Exception ex)
                {
                    ConsoleServer.WriteLine(ex.Message + ex.StackTrace);
                }
            }

        }
         *
         * */
        /*
        static void LineT78AllUnitTravelCalc()
        {
            int totalsec = 0;

            bool bisInvalid = false;
            // throw new Exception("The method or operation is not implemented.");
            Line line = matrix.getLine("T78");

            for (int i = line.startmileage / 1000; i <= (line.endmileage-1 )/ 1000; i++)
            {
                try
                {
                    int sec = 0;
                    sec = line["W", i].getTravelTime();
                    if (sec >= 0)
                    {
                        if (i == line.startmileage / 1000)
                            sec = (int)(sec * (((i + 1) * 1000.0 - line.startmileage) / 1000.0));
                        else if (i == line.endmileage / 1000)
                            sec = (int)(sec * (-(i * 1000.0 - line.endmileage) / 1000.0));
                    }
                    else
                    {
                        bisInvalid = true;
                        //continue;
                    }
                    totalsec += sec;
                    ConsoleServer.WriteLine(line["W", i].unitid + ":" + sec + "sec ");
                }
                catch (Exception ex)
                {
                    ConsoleServer.WriteLine(ex.Message + ex.StackTrace);
                }
            }

            ConsoleServer.WriteLine("==================================");
            ConsoleServer.WriteLine((bisInvalid) ? "total:-1 min" : "total:" + totalsec / 60 + "min");
            bisInvalid = false;
            totalsec = 0;
            //    Line line = matrix.getLine("T78");
            for (int i = line.startmileage / 1000; i <= (line.endmileage-1) / 1000; i++)
            {
                try
                {

                    int sec = 0;
                    sec = line["E", i].getTravelTime();
                    if (sec >= 0)
                    {
                        if (i == line.startmileage / 1000)
                            sec = (int)(sec * (((i + 1) * 1000.0 - line.startmileage) / 1000.0));
                        else if (i == line.endmileage / 1000)
                            sec = (int)(sec * (-(i * 1000.0 - line.endmileage) / 1000.0));
                    }
                    else
                        bisInvalid = true;
                    totalsec += sec;
                    ConsoleServer.WriteLine(line["E", i].unitid + ":" + sec + "sec ");
                }
                catch (Exception ex)
                {
                    ConsoleServer.WriteLine(ex.Message + ex.StackTrace);
                }
            }

            ConsoleServer.WriteLine("==================================");
            ConsoleServer.WriteLine((bisInvalid) ? "total:-1 min" : "total:" + totalsec / 60 + "min");

        }
         * */
        static void travelModule_OnNewTravelData(RGS_TravelDisplayData[] displayData)
        {
            foreach (RGS_TravelDisplayData data in displayData)
            {
                try
                {
                    TC.RGSDeviceWrapper rgs = (TC.RGSDeviceWrapper)matrix.getDeviceWrapper(data.devname);
                    if (data.icons != null)
                        rgs.SetTravelDisplay(data.icons, data.msgs, data.colors);
                    else
                        rgs.SetOutput(new OutputQueueData(rgs.deviceName,OutputModeEnum.TravelMode, OutputQueueData.TRAVEL_RULE_ID, OutputQueueData.TRAVEL_PRIORITY, null));
                }
                catch (Exception ex)
                {
                    ConsoleServer.WriteLine(ex.Message + ex.StackTrace);
                }

            }
        }
Ejemplo n.º 2
0
        public void section_data_1min_task()
        {
            ConsoleServer.WriteLine("section_data_1min_task started!");

               while (true)
               {
               try
               {
                   System.Net.WebRequest req = System.Net.HttpWebRequest.Create("http://192.168.4.4/section_traffic_data.xml");

                   System.IO.Stream stream = req.GetResponse().GetResponseStream();
                   System.IO.TextReader rd = new System.IO.StreamReader(stream);
                   System.IO.TextWriter wr = new System.IO.StreamWriter(Util.CPath(AppDomain.CurrentDomain.BaseDirectory + "tmp.xml"));
                   wr.Write(rd.ReadToEnd());
                   wr.Flush();
                   wr.Close();
                   rd.Close();
                   stream.Close();
                   wr.Dispose();
                   rd.Dispose();
                   stream.Dispose();

                   Ds ds = five_min_section_parser(Util.CPath(AppDomain.CurrentDomain.BaseDirectory + "tmp.xml"));
                   // Curr5minSecDs.Dispose();
                   Curr5minSecDs = ds;

                   string dest;
                   if ((dest = getSaveDirFileName(ds.tblFileAttr[0].time)) != "")   // new 5 min data
                   {
                      ConsoleServer.WriteLine("section_data_1min_task: new section data->" + ds.tblFileAttr[0][0].ToString());

                       System.IO.File.Copy(Util.CPath(AppDomain.CurrentDomain.BaseDirectory + "tmp.xml"), dest);
                       //if (OnNewTravelData != null)
                       //{

                           calcuate_travel_time();

                           RGS_TravelDisplayData[] displayDatas = new RGS_TravelDisplayData[RGSConfDs.tblRGSMain.Rows.Count];
                           for (int i = 0; i < RGSConfDs.tblRGSMain.Rows.Count; i++)
                           {
                               displayDatas[i] = getRgsDisplay(RGSConfDs.tblRGSMain[i]);
                           }

                          if(OnNewTravelData!=null)
                              OnNewTravelData(displayDatas);
                           //try
                           //{
                           //    NotifyDisplayTask();
                           //}
                           //catch (Exception ex)
                           //{
                           //    Console.WriteLine("section_data_1min_task:" + ex.Message);
                           //}
                       //}

                   }

               }
               catch (Exception ex)
               {
                   ConsoleServer.WriteLine("section_data_1min_task:" + ex.Message + ex.StackTrace);

                   try
                   {
                       if (Curr5minSecDs == null || System.Math.Abs(((TimeSpan)(System.DateTime.Now - Curr5minSecDs.tblFileAttr[0].time)).TotalMinutes) >= 20)
                       {
                           lock (RGSConfDs.tblRGSMain)
                           {

                               RGS_TravelDisplayData[] displayDatas = new RGS_TravelDisplayData[RGSConfDs.tblRGSMain.Rows.Count];
                               for (int i = 0; i < RGSConfDs.tblRGSMain.Rows.Count; i++)
                               {
                                   displayDatas[i] =new RGS_TravelDisplayData(RGSConfDs.tblRGSMain[0].rgs_name,null,null,null);
                               }

                               if (OnNewTravelData != null)
                                   OnNewTravelData(displayDatas);
                               //foreach (Ds.tblRGS_ConfigRow r in RGSConfDs.tblRGS_Config.Rows)
                               //{
                               //    r.RowError = "Timcc 連線資料異常!";
                               //    r.mode = 1; //手動
                               //    Console.WriteLine("寫入 RowErr");

                               //}
                               //if (OnNewTravelData != null)
                               //{

                               //    try
                               //    {
                               //        DataSet ds1 = new DataSet();

                               //        ds1.Tables.Add(Util.getPureDataTable(RGSConfDs.tblRGS_Config));
                               //        OnNewTravelData(ds1);
                               //        NotifyDisplayTask();
                               //    }
                               //    catch (Exception ex1)
                               //    {
                               //        Console.WriteLine("section_data_1min_task:" + ex1.StackTrace);
                               //    }
                               //}
                           }
                           ConsoleServer.WriteLine("Timcc 連線異常!");
                       }
                   }
                   catch (Exception ex1)
                   {
                       ConsoleServer.WriteLine(ex1.Message);
                   }

               }

             //   Util.GC();

               System.Threading.Thread.Sleep(60 * 1000);
               }
        }