public void SaveDataSet() { string FileName = Get_Dir_By_ACID_AND_IFPLID(ACID, IFPLID); string Settings_Data = ""; ////////////////////////////////////////////////////////////////////////////////////// // Do not chanage the order of calls Settings_Data = "ADEP " + ADEP + Environment.NewLine; Settings_Data = Settings_Data + "ADES " + ADES + Environment.NewLine; Settings_Data = Settings_Data + "EOBT " + EOBT + Environment.NewLine; Settings_Data = Settings_Data + "EOBD " + EOBD + Environment.NewLine; ////////////////////////////////////////////////////////////////////////////////////// // create a writer and open the file TextWriter tw = new StreamWriter(FileName); try { // write a line of text to the file tw.Write(Settings_Data); } catch { CBS_Main.WriteToLogFile("Exception in EFD_Msg.cs, Saving " + FileName); // close the stream tw.Close(); tw.Dispose(); } // close the stream tw.Close(); tw.Dispose(); }
public static void Initialise() { // Now start heart beat timer. System_Status_Timer = new System.Timers.Timer(1); // Set up the timer for 1sec System_Status_Timer.Elapsed += new ElapsedEventHandler(System_Status_Periodic_Update); System_Status_Timer.Enabled = true; CBS_Main.WriteToLogFile("Starting 1sec timer to check for incomming EFD messages"); }
///var/cbs/prediction/flights/ACID_IFPLID_DATETIME/status/EFD_{Status}_{DATETIME}.kml //<?xml version="1.0" encoding="UTF-8"?> //<kml xmlns="http://www.opengis.net/kml/2.2"> //<Document> //<Placemark> // <name>EFD Status {Inflight}</name> // <TimeStamp> <!-- required TimeStamp or TimeSpan block --> // <when>2013-02-20T00:05:20Z</when> // </TimeStamp> // <ExtendedData> // <Data name="markerType"> // <value> timelineItem</value> // </Data> // <Data name="dataSourceName"> // <value>EFD</value> // </Data> // </ExtendedData> //</Placemark> //</Document> //</kml> public static void Generate_Output(EFD_Msg Message_Data) { string TIME_AS_YYYYMMDDHHMMSS = CBS_Main.GetDate_Time_AS_YYYYMMDDHHMMSS(DateTime.UtcNow); string Time_Stamp = KML_Common.Get_KML_Time_Stamp(); string KML_File_Content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + Environment.NewLine + "<kml xmlns=\"http://www.opengis.net/kml/2.2\">" + Environment.NewLine + "<Document>" + Environment.NewLine + "<Placemark>" + Environment.NewLine + "<name>EFD Status " + Message_Data.FL_STATUS + "</name>" + Environment.NewLine + "<TimeStamp> <!-- required TimeStamp or TimeSpan block -->" + Environment.NewLine + "<when>" + Time_Stamp + "</when>" + Environment.NewLine + "</TimeStamp>" + Environment.NewLine + "<ExtendedData>" + Environment.NewLine + "<Data name=\"markerType\">" + Environment.NewLine + "<value> timelineItem</value>" + Environment.NewLine + "</Data>" + Environment.NewLine + "<Data name=\"dataSourceName\">" + Environment.NewLine + "<value>EFD</value>" + Environment.NewLine + "</Data>" + Environment.NewLine + "</ExtendedData>" + Environment.NewLine + "</Placemark>" + Environment.NewLine + "</Document>" + Environment.NewLine + "</kml>"; // Get the final data path string File_Path = Get_Dir_By_ACID_AND_IFPLID(Message_Data.ACID, Message_Data.IFPLID); File_Path = Path.Combine(File_Path, ("EFD_" + Message_Data.FL_STATUS + '_' + TIME_AS_YYYYMMDDHHMMSS + ".kml")); // Save data in the tmp directory first string Tmp = Path.Combine(CBS_Main.Get_Temp_Dir(), ("EFD_" + Message_Data.FL_STATUS + '_' + TIME_AS_YYYYMMDDHHMMSS + ".kml")); // create a writer and open the file TextWriter tw = new StreamWriter(Tmp); try { // write a line of text to the file tw.Write(KML_File_Content); CBS_Main.WriteToLogFile("Generating: " + File_Path); } catch { CBS_Main.WriteToLogFile("Exception in EFD_Status.cs, Saving " + File_Path); } // close the stream tw.Close(); // Now move it to the final destination File.Move(Tmp, File_Path); }
private static string Get_Dir_By_ACID_AND_IFPLID(string ACID, string IFPLID) { string DIR = ""; // First check if directory already exists string IFPLID_DIR_NAME = ACID + "_" + IFPLID + "_*"; string[] DestDirectory = Directory.GetDirectories(CBS_Main.Get_Destination_Dir(), IFPLID_DIR_NAME); if (DestDirectory.Length == 1) { DIR = DestDirectory[0]; DIR = Path.Combine(DIR, ".dataset"); } return(DIR); }
//<FPL_data> // <CLS>BAW905U</CLS> // <ADEP>EDDF</ADEP> // <ADES>EGLL</ADES> // <EOBT>HHMM</EOBT> // <EOBD>YYMMDD</EOBD> // <IFPLID>AA92346961</IFPLID> //</FPL_data> public static void Generate_Output(EFD_Msg Message_Data) { XmlDocument XDoc = new XmlDocument(); // Create root node. XmlElement XElemRoot = XDoc.CreateElement("FPL_Data"); //Add the node to the document. XDoc.AppendChild(XElemRoot); ////////////////////////////////////////////////// // Create Nodes // XmlElement XTemp = XDoc.CreateElement("CLS"); XTemp.InnerText = Message_Data.ACID; XElemRoot.AppendChild(XTemp); XTemp = XDoc.CreateElement("ADEP"); XTemp.InnerText = Message_Data.ADEP; XElemRoot.AppendChild(XTemp); XTemp = XDoc.CreateElement("ADES"); XTemp.InnerText = Message_Data.ADES; XElemRoot.AppendChild(XTemp); XTemp = XDoc.CreateElement("EOBT"); XTemp.InnerText = Message_Data.EOBT; XElemRoot.AppendChild(XTemp); XTemp = XDoc.CreateElement("EOBD"); XTemp.InnerText = Message_Data.EOBD; XElemRoot.AppendChild(XTemp); XTemp = XDoc.CreateElement("IFPLID"); XTemp.InnerText = Message_Data.IFPLID; XElemRoot.AppendChild(XTemp); string TIME_AS_YYYYMMDDHHMMSS = CBS_Main.GetDate_Time_AS_YYYYMMDDHHMMSS(DateTime.UtcNow); string File_Path = Get_Dir_By_ACID_AND_IFPLID(Message_Data.ACID, Message_Data.IFPLID); File_Path = Path.Combine(File_Path, ("Flight_Data_EFD_" + TIME_AS_YYYYMMDDHHMMSS + ".xml")); string Tmp = Path.Combine(CBS_Main.Get_Temp_Dir(), ("Flight_Data_EFD_" + TIME_AS_YYYYMMDDHHMMSS + ".xml")); XDoc.Save(Tmp); File.Move(Tmp, File_Path); }
public static void Generate(bool No_EFD_DATA_Flag) { if ((No_EFD_DATA_Flag == true) && (No_EFD_DATA_Flag_Last_Cycle == false)) { XmlDocument XDoc = new XmlDocument(); // Create root node. XmlElement XElemRoot = XDoc.CreateElement("EFDStatus"); //Add the node to the document. XDoc.AppendChild(XElemRoot); ////////////////////////////////////////////////// // Create Nodes // XmlElement XTemp = XDoc.CreateElement("Status"); XTemp.InnerText = "ERROR"; XElemRoot.AppendChild(XTemp); XTemp = XDoc.CreateElement("Message"); XTemp.InnerText = "No Incoming EFD Data"; XElemRoot.AppendChild(XTemp); XTemp = XDoc.CreateElement("TimeStamp"); XTemp.InnerText = CBS_Main.GetDate_Time_AS_YYYYMMDDHHMMSS(DateTime.Now); XElemRoot.AppendChild(XTemp); string File_Path = Path.Combine(CBS_Main.Get_System_Status_Dir(), ("EFD_Status.xml")); string Tmp = Path.Combine(CBS_Main.Get_Temp_Dir(), ("EFD_Status.xml")); XDoc.Save(Tmp); File.Move(Tmp, File_Path); } else if (No_EFD_DATA_Flag == false) { string File_Path = Path.Combine(CBS_Main.Get_System_Status_Dir(), ("EFD_Status.xml")); if (File.Exists(File_Path)) { File.Delete(File_Path); } FileStream fs = File.Create(File_Path); fs.Close(); fs.Dispose(); } No_EFD_DATA_Flag_Last_Cycle = No_EFD_DATA_Flag; }
public static FIXPOINT_TYPE Get_LATLNG(string FIX) { FIXPOINT_TYPE Return_FIX = new FIXPOINT_TYPE(); string FIXPOINT_Data; string FileName = Path.Combine(CBS_Main.Get_AIRAC_Dir(), "fixpoints"); char[] delimiterChars = { ';' }; StreamReader MyStreamReader; if (File.Exists(FileName)) { // Lets read in settings from the file MyStreamReader = System.IO.File.OpenText(FileName); while (MyStreamReader.Peek() >= 0) { FIXPOINT_Data = MyStreamReader.ReadLine(); string[] words = FIXPOINT_Data.Split(delimiterChars); if (words[0] == FIX) { Return_FIX.Is_Found = true; Return_FIX.Name = FIX; string sLAT = words[4]; if (words[4][0] == '.') { sLAT = '0' + words[4]; } string sLON = words[5]; if (words[5][0] == '.') { sLON = '0' + words[5]; } double LAT = double.Parse(sLAT); double LNG = double.Parse(sLON); Return_FIX.SetPosition(LAT, LNG); break; } } } return(Return_FIX); }
public static void Initialise() { // Set the connection string connString = "server=" + MySQLConnetionString.server_name + ";User Id=" + MySQLConnetionString.login_name + ";database=" + MySQLConnetionString.database; // Open up the connection MySQLconn = new MySqlConnection(connString); try { MySQLconn.Open(); CBS_Main.WriteToLogFile("Opened up MySQL connection " + connString); } catch (Exception e) { CBS_Main.WriteToLogFile("My SQL Error: " + e.Message); } }
// This method writes one line message to the Log file // Log file is written in the following format // <APP_START_DATE_TIME>_EFD_LOG.log public static void WriteToLogFile(string Log_Message) { if (debug_on == "TRUE") { // Debug_Log_File try { // App_Settings_Path string FileName = Path.Combine(App_Settings_Path, Debug_Log_File); using (StreamWriter w = File.AppendText(FileName)) { Log(Log_Message, w); } } catch (Exception e) { CBS_Main.WriteToLogFile("Error in WriteToLogFile " + e.Message); } } }
public static void Generate(EFD_Msg Message_Data) { // First check if directory already exists string IFPLID_DIR_NAME = Message_Data.ACID + "_" + Message_Data.IFPLID + "_*"; string[] DestDirectory = Directory.GetDirectories(CBS_Main.Get_Destination_Dir(), IFPLID_DIR_NAME); // This is first time the data for this particular flight has arrived, so lets just // create the directory structure and create set of files. if (DestDirectory.Length == 0) { // This must be a new flight, so lets create applicable directory IFPLID_DIR_NAME = Message_Data.ACID + "_" + Message_Data.IFPLID + "_"; IFPLID_DIR_NAME = IFPLID_DIR_NAME + CBS_Main.GetDate_Time_AS_YYYYMMDDHHMMSS(DateTime.UtcNow); Directory.CreateDirectory(CBS_Main.Get_Destination_Dir() + IFPLID_DIR_NAME); // Now when it is created, lets get it again so it can be used DestDirectory = Directory.GetDirectories(CBS_Main.Get_Destination_Dir(), IFPLID_DIR_NAME); // Now create subdirectories within new directory Directory.CreateDirectory(Path.Combine(DestDirectory[0], "common")); Directory.CreateDirectory(Path.Combine(DestDirectory[0], "EFD")); Directory.CreateDirectory(Path.Combine(DestDirectory[0], "status")); CBS_Main.WriteToLogFile("Generate Output: Creating dir structure for: " + IFPLID_DIR_NAME); GenerateOutput(Message_Data); Message_Data.SaveDataSet(); } else { // Check if this is a new data set // If true generate a new set of files // and then save the new data set. if (Message_Data.Is_New_Data_Set() == true) { GenerateOutput(Message_Data); Message_Data.SaveDataSet(); } } }
//// This method is to be called once Sector and Trajectory //// lists are populated (upon comleting EFD message extraction) //public void CalculateSectorEntry_Exit_Times(ref List<Sector> Sector_List) //{ // // Loop through the sector list and calculate // // entry/exit levels // for (int i = 0; i < Sector_List.Count; i++) // { // // First take care of the sector entry FL // int Start_Index = 0; // int End_Index = 0; // bool Start_End_WPT_Search_Status = false; // int Start_FL; // int End_FL; // int FL_DIFFERENCE; // TimeSpan Start_To_Sector; // TimeSpan Start_To_End; // double Time_Factor; // double Sector_Crossing_FL; // // Get indexes of WPT before and after sector crossing border // Get_Start_End_WPT_Index(Sector_List[i].SECTOR_ENTRY_TIME, out Start_Index, out End_Index, out Start_End_WPT_Search_Status); // if (Start_End_WPT_Search_Status == true) // { // Start_FL = int.Parse(TrajectoryPoints[Start_Index].Flight_Level); // End_FL = int.Parse(TrajectoryPoints[End_Index].Flight_Level); // FL_DIFFERENCE = End_FL - Start_FL; // Start_To_Sector = Sector_List[i].SECTOR_ENTRY_TIME - CBS_Main.GetDate_Time_From_YYYYMMDDHHMMSS("20" + TrajectoryPoints[Start_Index].ETO); // Start_To_End = CBS_Main.GetDate_Time_From_YYYYMMDDHHMMSS("20" + TrajectoryPoints[End_Index].ETO) - CBS_Main.GetDate_Time_From_YYYYMMDDHHMMSS("20" + TrajectoryPoints[Start_Index].ETO); // Time_Factor = Start_To_Sector.TotalSeconds / Start_To_End.TotalSeconds; // Sector_Crossing_FL = Start_FL + (FL_DIFFERENCE * Time_Factor); // Sector_List[i].EFL = Math.Round(Sector_Crossing_FL).ToString(); // } // // Now calculate sector exit FL // // Get indexes of WPT before and after sector crossing border // Get_Start_End_WPT_Index(Sector_List[i].SECTOR_EXIT_TIME, out Start_Index, out End_Index, out Start_End_WPT_Search_Status); // if (Start_End_WPT_Search_Status == true) // { // Start_FL = int.Parse(TrajectoryPoints[Start_Index].Flight_Level); // End_FL = int.Parse(TrajectoryPoints[End_Index].Flight_Level); // FL_DIFFERENCE = End_FL - Start_FL; // Start_To_Sector = Sector_List[i].SECTOR_EXIT_TIME - CBS_Main.GetDate_Time_From_YYYYMMDDHHMMSS("20" + TrajectoryPoints[Start_Index].ETO); // Start_To_End = CBS_Main.GetDate_Time_From_YYYYMMDDHHMMSS("20" + TrajectoryPoints[End_Index].ETO) - CBS_Main.GetDate_Time_From_YYYYMMDDHHMMSS("20" + TrajectoryPoints[Start_Index].ETO); // Time_Factor = Start_To_Sector.TotalSeconds / Start_To_End.TotalSeconds; // Sector_Crossing_FL = Start_FL + (FL_DIFFERENCE * Time_Factor); // Sector_List[i].XFL = Math.Round(Sector_Crossing_FL).ToString(); // } // } //} // This method returns the indexes of the two WPT points (before and after) given time. // Intended use is to obtain points before and after expected sector crossing. The points // have expected FL and times and based on that it is possible to calculate sector crossing FL private void Get_Start_End_WPT_Index(DateTime TimeAtPoint, out int Start, out int End, out bool Succefull) { Start = 0; End = 0; Succefull = false; for (int i = 0; i < TrajectoryPoints.Count; i++) { TimeSpan Time = CBS_Main.GetDate_Time_From_YYYYMMDDHHMMSS("20" + TrajectoryPoints[i].ETO) - TimeAtPoint; if (Time.TotalSeconds > 0) { Start = i - 1; End = i; // Check for the special case when the first points in the // list is also sector entry point. if (Start < 0) { Start = 0; } Succefull = true; break; } } }
public static void Initialize() { ///////////////////////////////////////////////////////////////// // First check where we are running and prepare app // if (Get_Host_OS() == Host_OS.LINUX) { // Linux Source_Path = "/var/EFD/"; flights_Path = "/var/cbs/prediction/flights/"; System_Status_Path = "/var/cbs/prediction/systemStatus/"; Main_Status_Path = "/var/cbs/prediction/status/"; App_Settings_Path = "/var/cbs/settings/EFD/"; AIRAC_Data_Path = "/var/cbs/settings/AIRAC/"; Tmp_Directory = "/tmp/"; } // Now make sure that proper directory structure // is set up on the host machine if (Directory.Exists(App_Settings_Path) == false) { Directory.CreateDirectory(App_Settings_Path); WriteToLogFile("Creating " + App_Settings_Path); } if (Directory.Exists(Source_Path) == false) { Directory.CreateDirectory(Source_Path); WriteToLogFile("Creating " + Source_Path); } if (Directory.Exists(flights_Path) == false) { Directory.CreateDirectory(flights_Path); WriteToLogFile("Creating " + flights_Path); } if (Directory.Exists(System_Status_Path) == false) { Directory.CreateDirectory(System_Status_Path); WriteToLogFile("Creating " + System_Status_Path); } if (Directory.Exists(Main_Status_Path) == false) { Directory.CreateDirectory(Main_Status_Path); WriteToLogFile("Creating " + Main_Status_Path); } if (Directory.Exists(AIRAC_Data_Path) == false) { Directory.CreateDirectory(AIRAC_Data_Path); WriteToLogFile("Creating " + AIRAC_Data_Path); } if (Directory.Exists(Tmp_Directory) == false) { Directory.CreateDirectory(Tmp_Directory); WriteToLogFile("Creating " + Tmp_Directory); } // Check if cbs_config.txt exists, if so load settings // data saved from the previous session string Settings_Data; string FileName = Path.Combine(App_Settings_Path, "cbs_config.txt"); char[] delimiterChars = { ' ' }; StreamReader MyStreamReader; if (File.Exists(FileName)) { WriteToLogFile("Processing " + FileName); // Lets read in settings from the file MyStreamReader = System.IO.File.OpenText(FileName); while (MyStreamReader.Peek() >= 0) { Settings_Data = MyStreamReader.ReadLine(); if (Settings_Data[0] != '#') { string[] words = Settings_Data.Split(delimiterChars); switch (words[0]) { case "SOURCE_DIR": Source_Path = words[1]; break; case "FLIGHTS_DIR": flights_Path = words[1]; break; case "SYSTEM_STATUS_DIR": System_Status_Path = words[1]; break; case "MAIN_STATUS_DIR": Main_Status_Path = words[1]; break; case "HEART_BEAT": HEART_BEAT = words[1]; break; case "COLD_POWER_UP": Cold_Start_Timeout_Min = int.Parse(words[1]); break; case "SYS_STATUS_UPDATE_RATE": System_Status_Update_Rate_Sec = int.Parse(words[1]); break; case "NO_EFD_DATA_TIMEOUT": No_EFD_Data_Timout = int.Parse(words[1]); break; case "AIRAC_DATA_SOURCE": AIRAC_Data_Path = words[1]; break; case "MYSQL_SERVER": MySqlWriter.MySQLConnetionString.server_name = words[1]; break; case "MYSQL_USER": MySqlWriter.MySQLConnetionString.login_name = words[1]; break; case "MYSQL_DATABASE": MySqlWriter.MySQLConnetionString.database = words[1]; break; case "MYSQL_TABLE": MySqlWriter.MySQLConnetionString.table_name = words[1]; break; case "DEBUG": debug_on = words[1]; break; default: break; } } } MyStreamReader.Close(); MyStreamReader.Dispose(); // Here check if there has been more than parameter since // application has been down TimeSpan TenMin = new TimeSpan(0, Cold_Start_Timeout_Min, 0); TimeSpan AppDown = DateTime.UtcNow - Get_Power_OFF_Time(); // Now check if the application has been down for more than // 10 minutes. If so then clear the directory if (AppDown > TenMin) { ClearSourceDirectory(); WriteToLogFile("APP down for more then 10min, clearing " + Source_Path); } else { // Call routine to process all files that might have // arrived in the last 10 minutes or less. } // Lets save once so HART BEAT gets saved right away SaveSettings(); } else { // Lets then create one with default setting SaveSettings(); // Since we had no idea when the application was last powered off // we assume it has been more than timuout parameter, sop lets delete all files ClearSourceDirectory(); WriteToLogFile("APP down time unknown, clearing " + Source_Path); } // Now start heart beat timer. Cold_Start_Timer = new System.Timers.Timer(10000); // Set up the timer for 1minute Cold_Start_Timer.Elapsed += new ElapsedEventHandler(_HEART_BEAT_timer_Elapsed); Cold_Start_Timer.Enabled = true; // Start input data monitor EFD_File_Handler.Initialise(); // Open up connection to the MySQL database MySqlWriter.Initialise(); ////////////////////////////////////////////////////// // Start periodic timer that will drive system status // update logic // Now start heart beat timer. System_Status_Timer = new System.Timers.Timer((System_Status_Update_Rate_Sec * 100)); // Set up the timer for 1minute System_Status_Timer.Elapsed += new ElapsedEventHandler(System_Status_Periodic_Update); System_Status_Timer.Enabled = true; CBS_Main.WriteToLogFile("Started system status heart beat timer"); }
// /var/cbs/prediction/flights/ACID_IFPLID_DATETIME/EFD/EFD_AOI_Entry_DATETIME.kml //<?xml version="1.0" encoding="UTF-8"?> //<kml xmlns="http://www.opengis.net/kml/2.2"> //<Document> // <Placemark> // <name>EFD AOI Entry</name> // <TimeStamp> // <when>2013-02-20T00:05:20Z</when> // </TimeStamp> // <ExtendedData> // <Data name="dataSourceName"> // <value>EFD</value> // </Data> // <Data name="markerType"> // <value>customMarker</value> // </Data> // <Data name="customIcon"> // <value>imageGoogleYellow.png</value> // </Data> // <Data name="popupLine1"> // <value>Time:{TIME}</value> // </Data> // <Data name="popupLine2"> // <value>Point:{LON,LAT}</value> // </Data> // <Data name="popupLine3"> // <value>Altitude:{Altitude}</value> // </Data> // <Data name="fileLocation"> // <value>flights/ACID_IFPLID_DATETIME/EFD/EFD_AOI_Entry_DATETIME.kml</value> // </Data> // </ExtendedData> // <Point> // <coordinates>12.09607,51.41915,1201,20130305003900</coordinates> // </Point> // </Placemark> //</Document> //</kml> public static void Generate_Output(EFD_Msg Message_Data) { string TIME_AS_YYYYMMDDHHMMSS = CBS_Main.GetDate_Time_AS_YYYYMMDDHHMMSS(DateTime.UtcNow); string Time_Stamp = KML_Common.Get_KML_Time_Stamp(); string Entry_LON_DEGMINSEC; string Entry_LAT_DEGMINSEC; Message_Data.ENTRY_AOI_POINT.GetDegMinSecStringFormat(out Entry_LAT_DEGMINSEC, out Entry_LON_DEGMINSEC); string KML_File_Content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + Environment.NewLine + "<kml xmlns=\"http://www.opengis.net/kml/2.2\">" + Environment.NewLine + "<Document>" + Environment.NewLine + "<Placemark>" + Environment.NewLine + "<name>EFD AOI Entry</name>" + Environment.NewLine + "<TimeStamp>" + Environment.NewLine + "<when>" + Time_Stamp + "</when>" + Environment.NewLine + "</TimeStamp>" + Environment.NewLine + "<ExtendedData>" + Environment.NewLine + "<Data name=\"dataSourceName\">" + Environment.NewLine + "<value>EFD</value>" + Environment.NewLine + "</Data>" + Environment.NewLine + "<Data name=\"markerType\">" + Environment.NewLine + "<value>customMarker</value>" + Environment.NewLine + "</Data>" + Environment.NewLine + "<Data name=\"customIcon\">" + Environment.NewLine + "<value>imageGoogleYellow.png</value>" + Environment.NewLine + "</Data>" + Environment.NewLine + "<Data name=\"popupLine1\">" + Environment.NewLine + "<value>Time:" + Message_Data.AOI_ENTRY_TIME.ToShortDateString() + "/" + Message_Data.AOI_ENTRY_TIME.ToShortTimeString() + "</value>" + Environment.NewLine + "</Data>" + Environment.NewLine + "<Data name=\"popupLine2\">" + Environment.NewLine + "<value>Point:" + Entry_LON_DEGMINSEC + "'" + Entry_LAT_DEGMINSEC + "</value>" + Environment.NewLine + "</Data>" + Environment.NewLine + "<Data name=\"popupLine3\">" + Environment.NewLine + "<value>Altitude:" + Message_Data.AOI_ENTRY_FL + "</value>" + Environment.NewLine + "</Data>" + Environment.NewLine + "<Data name=\"fileLocation\">" + Environment.NewLine + "<value>flights/ACID_IFPLID_DATETIME/EFD/EFD_AOI_Entry_" + TIME_AS_YYYYMMDDHHMMSS + ".kml</value>" + Environment.NewLine + "</Data>" + Environment.NewLine + "</ExtendedData>" + Environment.NewLine + "<Point>" + Environment.NewLine + "<coordinates>" + string.Format("{0:0.0000}", Message_Data.ENTRY_AOI_POINT.GetLatLongDecimal().LongitudeDecimal) + "," + string.Format("{0:0.0000}", Message_Data.ENTRY_AOI_POINT.GetLatLongDecimal().LatitudeDecimal) + "," + Message_Data.AOI_ENTRY_FL + "," + Message_Data.AOI_ENTRY_TIME_YYMMDDHHMMSS + "</coordinates>" + Environment.NewLine + "</Point>" + Environment.NewLine + "</Placemark>" + Environment.NewLine + "</Document>" + Environment.NewLine + "</kml>"; // Get the final data path string File_Path = Get_Dir_By_ACID_AND_IFPLID(Message_Data.ACID, Message_Data.IFPLID); File_Path = Path.Combine(File_Path, ("EFD_AOI_Entry_" + TIME_AS_YYYYMMDDHHMMSS + ".kml")); // Save data in the tmp directory first string Tmp = Path.Combine(CBS_Main.Get_Temp_Dir(), ("EFD_AOI_Entry_" + TIME_AS_YYYYMMDDHHMMSS + ".kml")); // create a writer and open the file TextWriter tw = new StreamWriter(Tmp); try { // write a line of text to the file tw.Write(KML_File_Content); CBS_Main.WriteToLogFile("Generating: " + File_Path); } catch { CBS_Main.WriteToLogFile("Exception in EFD_AOI_Entry.cs, Saving " + File_Path); } // close the stream tw.Close(); // Now move it to the final destination File.Move(Tmp, File_Path); }
public bool Is_New_Data_Set() { bool New_Data_Set = false; string FileName = Get_Dir_By_ACID_AND_IFPLID(ACID, IFPLID); char[] delimiterChars = { ' ' }; StreamReader MyStreamReader = null; string Data_Set; try { // Lets read in settings from the file MyStreamReader = System.IO.File.OpenText(FileName); while (MyStreamReader.Peek() >= 0) { Data_Set = MyStreamReader.ReadLine(); if (Data_Set[0] != '#') { string[] words = Data_Set.Split(delimiterChars); switch (words[0]) { case "ADEP": if (ADEP != words[1]) { New_Data_Set = true; } break; case "ADES": if (ADES != words[1]) { New_Data_Set = true; } break; case "EOBT": if (EOBT != words[1]) { New_Data_Set = true; } break; case "EOBD": if (EOBD != words[1]) { New_Data_Set = true; } break; default: break; } } } } catch (Exception e) { CBS_Main.WriteToLogFile("Error in EFD Message " + e.Message); MyStreamReader.Close(); MyStreamReader.Dispose(); } MyStreamReader.Close(); MyStreamReader.Dispose(); return(New_Data_Set); }
public EFD_Msg(StreamReader Reader) { string OneLine; char[] delimiterChars = { ' ' }; // Parse the file and extract all data needed by EFD while (Reader.Peek() >= 0) { OneLine = Reader.ReadLine(); string[] Words = OneLine.Split(delimiterChars); Waypoint WPT = new Waypoint(); try { switch (Words[0]) { case "-IFPLID": IFPLID = Words[1]; break; case "-ARCID": ACID = Words[1]; break; case "-FLTSTATE": FLTSTATE = Words[1]; break; case "-ARCTYP": ARCTYP = Words[1]; break; case "-ADEP": ADEP = Words[1]; break; case "-ADES": ADES = Words[1]; break; case "-EOBT": EOBT = Words[1]; break; case "-EOBD": EOBD = Words[1]; break; case "-GEO": try { string LAT = Words[4]; string LON = Words[6]; // -LATTD 550302N -LONGTD 1070037W int LAT_DEG = int.Parse(LAT.Substring(0, 2)); int LAT_MIN = int.Parse(LAT.Substring(2, 2)); int LAT_SEC = int.Parse(LAT.Substring(4, 2)); GeoCordSystemDegMinSecUtilities.LatLongPrefix LAT_Prefix = GeoCordSystemDegMinSecUtilities.LatLongPrefix.Not_Valid; if (LAT[6] == 'N') { LAT_Prefix = GeoCordSystemDegMinSecUtilities.LatLongPrefix.N; } else { LAT_Prefix = GeoCordSystemDegMinSecUtilities.LatLongPrefix.S; } int LON_DEG = int.Parse(LON.Substring(0, 3)); int LON_MIN = int.Parse(LON.Substring(3, 2)); int LON_SEC = int.Parse(LON.Substring(5, 2)); GeoCordSystemDegMinSecUtilities.LatLongPrefix LON_Prefix = GeoCordSystemDegMinSecUtilities.LatLongPrefix.Not_Valid; if (LON[7] == 'W') { LON_Prefix = GeoCordSystemDegMinSecUtilities.LatLongPrefix.W; } else { LON_Prefix = GeoCordSystemDegMinSecUtilities.LatLongPrefix.E; } WPT.Name = Words[2]; WPT.Position = new GeoCordSystemDegMinSecUtilities.LatLongClass(LAT_DEG, LAT_MIN, LAT_SEC, LAT_Prefix, LON_DEG, LON_MIN, LON_SEC, LON_Prefix); WPT.Position_Determined = true; GEO_Artifical_List.Add(WPT); } catch (Exception e) { CBS_Main.WriteToLogFile("Exception in EFD_Msg.cs, -GEP Parsing: " + e.Message); } break; case "-BEGIN": if (Words[1] == "RTEPTS") { } else if (Words[1] == "ASPLIST") { } else { } break; // Maastricht UAC Entry and Exit Times // -ASP -AIRSPDES EDYYAOI -ETI 130404091206 -XTI 130404095840 case "": if ((Words.Length == 8) && (Words[1] == "-ASP")) { // Always extract UAC Entry and Exit Times if ((Words[2] == "-AIRSPDES") && (Words[3] == "EDYYAOI")) { AOI_ENTRY_TIME = CBS_Main.GetDate_Time_From_YYYYMMDDHHMMSS("20" + Words[5]); AOI_ENTRY_TIME_YYMMDDHHMMSS = "20" + Words[5]; AOI_EXIT_TIME = CBS_Main.GetDate_Time_From_YYYYMMDDHHMMSS("20" + Words[7]); AOI_EXIT_TIME_YYMMDDHHMMSS = "20" + Words[7]; } //// Now extract all MUAC sectors and sector entry/exit times //// Always extract UAC Entry and Exit Times //if ((Words[2] == "-AIRSPDES") && (Words[3].Substring(0, 4) == "EDYY")) //{ // string Sector_ID = Words[3].Substring(4, (Words[3].Length - 4)); // // FOX,FOX1,FOX2,UAC,UACX,AOI // if (Sector_ID != "FOX" && Sector_ID != "FOX1" && Sector_ID != "FOX2" && // Sector_ID != "UAC" && Sector_ID != "UACX" && Sector_ID != "AOI") // { // Sector Sector = new Sector(); // Sector.ID = Sector_ID; // Sector.SECTOR_ENTRY_TIME = CBS_Main.GetDate_Time_From_YYYYMMDDHHMMSS("20" + Words[5]); // Sector.SECTOR_EXIT_TIME = CBS_Main.GetDate_Time_From_YYYYMMDDHHMMSS("20" + Words[7]); // Sector_List.Add(Sector); // } //} } else if (Words.Length > 1) { if (Words[1] == "-AD" || Words[1] == "-VEC" || Words[1] == "-PT") { FIX_TO_LATLNG.FIXPOINT_TYPE FIX = new FIX_TO_LATLNG.FIXPOINT_TYPE(); switch (Words[1]) { // -AD -ADID OMDB -ETO 130404033500 -PTRTE DCT case "-AD": break; // -VEC -RELDIST 01 -FL F010 -ETO 130404034715 case "-VEC": // Extract data from -PT line WPT.Name = "-VEC" + Words[3]; WPT.Flight_Level = Words[5].Substring(1); // Remove F at the beggining. WPT.ETO = Words[7]; if (TrajectoryPoints.Count > 0) { // Add a new point to the list // Only add position that are known // as defined in the fixpoint table. TrajectoryPoints.Add(WPT); } break; // -PT -PTID GEO01 -FL F300 -ETO 130404041754 case "-PT": // Extract data from -PT line WPT.Name = Words[4]; WPT.Flight_Level = Words[6].Substring(1); // Remove F at the beggining. WPT.ETO = Words[8]; FIX = FIX_TO_LATLNG.Get_LATLNG(WPT.Name); if (FIX.Is_Found == true) { WPT.Position = FIX.Position; WPT.Position_Determined = true; // Add a new point to the list // Only add position that are known // as defined in the fixpoint table. TrajectoryPoints.Add(WPT); } else { // Lets check if the point is in the artifical EFD message // provided list. If so extract the position and assign it to // the main trajectory WPT list foreach (Waypoint GEO_WPT in GEO_Artifical_List) { if (WPT.Name == GEO_WPT.Name) { WPT.Position = new GeoCordSystemDegMinSecUtilities.LatLongClass(GEO_WPT.Position.GetLatLongDecimal().LatitudeDecimal, GEO_WPT.Position.GetLatLongDecimal().LongitudeDecimal); WPT.Position_Determined = true; TrajectoryPoints.Add(WPT); break; } } } break; default: break; } } } break; default: break; } } catch (Exception e) { CBS_Main.WriteToLogFile("Exception in EFD_Msg.cs, Instantiation: " + e.Message); } } ///////////////////////////////////////////////////////////////////////// // DO NOT CHANGE THE ORDER OF THE FOLLOWING CALLS ///////////////////////////////////////////////////////////////////////// // Here parse the list and // 1. Remove all "-VEC points from the end of the list // 2. Determine Lon/Lat of each -VEC point ParseTrajectoryList(ref TrajectoryPoints); // Iterate through the sector lists and // calculate sector entry/exit levels based on the // extrapolation data calculated from the main trajectory // WPT list // CalculateSectorEntry_Exit_Times(ref Sector_List); ///////////////////////////////// // Now set AOI Entry/Exit Points CalculateAOI_Entry_Exit_Times(); Reader.Close(); Reader.Dispose(); /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// }
// 1. Remove all "-VEC points from the end of the list // 2. Determine Lon/Lat of each -VEC point public void ParseTrajectoryList(ref List <Waypoint> T_List) { //////////////////////////////////////////////////////////////////////////////////////// // 1. Remove all "-VEC points from the end of the list //////////////////////////////////////////////////////////////////////////////////////// int LastKnownPointIndex = -1; for (int i = 0; i < T_List.Count; i++) { if (T_List[i].Name.Length == 6 && T_List[i].Name.Substring(0, 4) == "-VEC") { } else { LastKnownPointIndex = i; } } if (LastKnownPointIndex < (T_List.Count - 1)) { try { T_List.RemoveRange(LastKnownPointIndex + 1, T_List.Count - (LastKnownPointIndex + 1)); } catch (Exception e) { CBS_Main.WriteToLogFile("Exception removing VEC range: " + e.Message); } } //////////////////////////////////////////////////////////////////////////////////////////// // 2. Determine Lon/Lat of each -VEC point //////////////////////////////////////////////////////////////////////////////////////////// for (int i = 0; i < T_List.Count; i++) { // Check if this is a -VEC point if (T_List[i].Name.Length == 6 && T_List[i].Name.Substring(0, 4) == "-VEC") { // 1. YES, then LastKnownPointIndex is the index of the previous last known point // 2. Now determine the next known point int next_known_point = GetNextKnownPointIndex(i + 1, ref T_List); // Now we have two known points, so lets compute a new position representing // the percentage of the distance between two known points specifed in the -VEC // point. int percentage = int.Parse(T_List[i].Name.Substring(4, 2)); // select a reference elllipsoid Ellipsoid reference = Ellipsoid.WGS84; // instantiate the calculator GeodeticCalculator geoCalc = new GeodeticCalculator(); GlobalPosition Start_Pos = new GlobalPosition(new GlobalCoordinates(T_List[LastKnownPointIndex].Position.GetLatLongDecimal().LatitudeDecimal, T_List[LastKnownPointIndex].Position.GetLatLongDecimal().LongitudeDecimal)); GlobalPosition End_Pos = new GlobalPosition(new GlobalCoordinates(T_List[next_known_point].Position.GetLatLongDecimal().LatitudeDecimal, T_List[next_known_point].Position.GetLatLongDecimal().LongitudeDecimal)); // Get the distance and conver it to NM double distance = geoCalc.CalculateGeodeticMeasurement(reference, Start_Pos, End_Pos).PointToPointDistance; distance = (distance / 100.0) * (double)percentage; distance = 0.00053996 * distance; //////////////////////////////////////////////////////////// // Calculate the azimuth between two known points Angle Azimuth = geoCalc.CalculateGeodeticMeasurement(reference, Start_Pos, End_Pos).Azimuth; // Calculate new position GeoCordSystemDegMinSecUtilities.LatLongClass New_Position = GeoCordSystemDegMinSecUtilities.CalculateNewPosition(new GeoCordSystemDegMinSecUtilities.LatLongClass(Start_Pos.Latitude.Degrees, Start_Pos.Longitude.Degrees), distance, Azimuth.Degrees); // Assign new position to the -VEC point T_List[i].Position = new GeoCordSystemDegMinSecUtilities.LatLongClass(New_Position.GetLatLongDecimal().LatitudeDecimal, New_Position.GetLatLongDecimal().LongitudeDecimal); } else { LastKnownPointIndex = i; } } }
// EFD_Trajetory_DATETIME.kml //<?xml version="1.0" encoding="UTF-8"?> //<kml xmlns="http://www.opengis.net/kml/2.2"> //<Document> //<Placemark> // <name>DLH2394 Trajectory</name> //<TimeStamp> // <when>2013-02-20T00:05:20Z</when> //</TimeStamp> //<ExtendedData> // <Data name="dataSourceName"> // <value>EFD</value> // </Data> // <Data name="markerType"> // <value>polyline</value> // </Data> // <Data name="lineColor"> // <value>ffff00</value> // </Data> // <Data name="popupLine1"> // <value>Callsign,ADEP,ADES</value> // </Data> // <Data name="popupLine2"> // <value>EOBD, EOBT</value> // </Data> // <Data name="popupLine3"> // <value>IFPLID</value> // </Data> // <Data name="fileLocation"> // <value>flights/ACID_IFPLID_DATETIME/EFD/EFD_Trajectory_DATETIME.kml</value> // </Data> //</ExtendedData> // <LineString> // <coordinates> // 12.17152,51.41049,646,20130305003800 // 12.09607,51.41915,1201,20130305003900 // 12.05830,51.48931,1762,20130305004000 // </coordinates> // </LineString> // </Placemark> //</Document> //</kml> public static void Generate_Output(EFD_Msg Message_Data) { string TIME_AS_YYYYMMDDHHMMSS = CBS_Main.GetDate_Time_AS_YYYYMMDDHHMMSS(DateTime.UtcNow); string Time_Stamp = KML_Common.Get_KML_Time_Stamp(); // Here build the trajectory string // "12.17152,51.41049,646,20130305003800" + Environment.NewLine + // "12.09607,51.41915,1201,20130305003900" + Environment.NewLine + string Trajectory_String = ""; foreach (EFD_Msg.Waypoint WPT in Message_Data.TrajectoryPoints) { Trajectory_String = Trajectory_String + string.Format("{0:0.0000}", WPT.Position.GetLatLongDecimal().LongitudeDecimal) + "," + string.Format("{0:0.0000}", WPT.Position.GetLatLongDecimal().LatitudeDecimal) + "," + WPT.Flight_Level + "," + WPT.ETO + Environment.NewLine; } string KML_File_Content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + Environment.NewLine + "<kml xmlns=\"http://www.opengis.net/kml/2.2\">" + Environment.NewLine + "<Document>" + Environment.NewLine + "<Placemark>" + Environment.NewLine + "<name>" + Message_Data.ACID + " Trajectory" + "</name>" + Environment.NewLine + "<TimeStamp>" + Environment.NewLine + "<when>" + Time_Stamp + "</when>" + Environment.NewLine + "</TimeStamp>" + Environment.NewLine + "<ExtendedData>" + Environment.NewLine + "<Data name=\"dataSourceName\">" + Environment.NewLine + "<value>EFD</value>" + Environment.NewLine + "</Data>" + Environment.NewLine + "<Data name=\"markerType\">" + Environment.NewLine + " <value>polyline</value>" + Environment.NewLine + "</Data>" + Environment.NewLine + "<Data name=\"lineColor\">" + Environment.NewLine + "<value>ffff00</value>" + Environment.NewLine + "</Data>" + Environment.NewLine + "<Data name=\"popupLine1\">" + Environment.NewLine + "<value>" + Message_Data.ACID + ',' + Message_Data.ADEP + ',' + Message_Data.ADES + "</value>" + Environment.NewLine + "</Data>" + Environment.NewLine + "<Data name=\"popupLine2\">" + Environment.NewLine + "<value>" + Message_Data.EOBT + ',' + Message_Data.EOBD + "</value>" + Environment.NewLine + "</Data>" + Environment.NewLine + "<Data name=\"popupLine3\">" + Environment.NewLine + "<value>" + Message_Data.IFPLID + "</value>" + Environment.NewLine + "</Data>" + Environment.NewLine + "<Data name=\"fileLocation\">" + Environment.NewLine + "<value>flights/ACID_IFPLID_DATETIME/EFD/EFD_Trajectory_" + TIME_AS_YYYYMMDDHHMMSS + ".kml</value>" + Environment.NewLine + "</Data>" + Environment.NewLine + "</ExtendedData>" + Environment.NewLine + "<LineString>" + Environment.NewLine + "<coordinates>" + Environment.NewLine + Trajectory_String + "</coordinates>" + Environment.NewLine + "</LineString>" + Environment.NewLine + "</Placemark>" + Environment.NewLine + "</Document>" + Environment.NewLine + "</kml>"; // Get the final data path string File_Path = Get_Dir_By_ACID_AND_IFPLID(Message_Data.ACID, Message_Data.IFPLID); File_Path = Path.Combine(File_Path, ("EFD_Trajectory_" + TIME_AS_YYYYMMDDHHMMSS + ".kml")); // Save data in the tmp directory first string Tmp = Path.Combine(CBS_Main.Get_Temp_Dir(), ("EFD_Trajectory_" + TIME_AS_YYYYMMDDHHMMSS + ".kml")); // create a writer and open the file TextWriter tw = new StreamWriter(Tmp); try { // write a line of text to the file tw.Write(KML_File_Content); CBS_Main.WriteToLogFile("Generating: " + File_Path); } catch { CBS_Main.WriteToLogFile("Exception in EFD_Trajectory.cs, Saving " + File_Path); } // close the stream tw.Close(); // Now move it to the final destination File.Move(Tmp, File_Path); }
public static void Handle_New_File() { string[] filePaths = Directory.GetFiles(CBS_Main.Get_Source_Data_Path(), "*.log*", SearchOption.AllDirectories); foreach (string Path in filePaths) { try { using (MyStreamReader = System.IO.File.OpenText(Path)) { if (MyStreamReader != null) { //// Pass in stream reader and initialise new //// EFD message. EFD_Msg EDF_MESSAGE = new EFD_Msg(MyStreamReader); MyStreamReader.Close(); MyStreamReader.Dispose(); try { //// Generate output Generate_Output.Generate(EDF_MESSAGE); } catch (Exception e1) { CBS_Main.WriteToLogFile("Error in Generate_Output.Generate " + e1.Message); } try { // Write data to the MySqlDatabase MySqlWriter.Write_One_Message(EDF_MESSAGE); } catch (Exception e2) { CBS_Main.WriteToLogFile("Error in MySqlWriter.Write_One_Message " + e2.Message); } // Let the status handler know that the // message has arrived... try { CBS_Main.Notify_EFD_Message_Recived(); } catch (Exception e3) { CBS_Main.WriteToLogFile("Error in CBS_Main.Notify_EFD_Message_Recived " + e3.Message); } //// Once done with the file, //// lets delete it as we do not //// needed it any more try { System.IO.File.Delete(Path); } catch { CBS_Main.WriteToLogFile("Error in EFD_File_Handler, can't delete file " + Path); } break; } } } catch (Exception ex) { CBS_Main.WriteToLogFile("Exception EFD_Handler: " + ex.Message); } } }
// ARCID // IFPLID // FLTSTATE // ADEP // ADES // ARCTYP // ETI // XTI // LASTUPD // TSTARTTIME // TENDTIME // TPOINTS // POINTS public static void Write_One_Message(EFD_Msg Message) { // Lets build SEQMUAC string // FORMAT: // //RH1,1515,1522//RH2,1515,1522 string SEQMUAC = ""; foreach (EFD_Msg.Sector Msg in Message.Sector_List) { SEQMUAC = SEQMUAC + "//" + Msg.ID + ',' + GetTimeAS_HHMM(Msg.SECTOR_ENTRY_TIME) + ',' + GetTimeAS_HHMM(Msg.SECTOR_EXIT_TIME) + ',' + Msg.EFL + ',' + Msg.XFL; } // Lets build TPOINTS string //tpoints (LON,LAT,FL,broj sekundi u odnosu na tstarttime) u formatu: //51.28083,6.75722,0,0;51.59056,6.69417,11900,431 string TPOINTS = ""; int Index = 0; TimeSpan TS = new TimeSpan(0); foreach (EFD_Msg.Waypoint WPT in Message.TrajectoryPoints) { if (Index > 0) { TS = CBS_Main.GetDate_Time_From_YYMMDDHHMMSS(WPT.ETO) - CBS_Main.GetDate_Time_From_YYMMDDHHMMSS(Message.TrajectoryPoints[0].ETO); } TPOINTS = TPOINTS + string.Format("{0:0.0000}", WPT.Position.GetLatLongDecimal().LatitudeDecimal) + ',' + string.Format("{0:0.0000}", WPT.Position.GetLatLongDecimal().LongitudeDecimal) + ',' + WPT.Flight_Level + ',' + TS.TotalSeconds.ToString() + ";"; Index++; } // LASTUPD DateTime T_Now = DateTime.UtcNow; string LASTUPD = T_Now.Year.ToString("0000") + T_Now.Month.ToString("00") + T_Now.Day.ToString("00") + T_Now.Hour.ToString("00") + T_Now.Minute.ToString("00") + T_Now.Second.ToString("00"); string TSTARTTIME = ConvertToUNIXTimestamp(CBS_Main.GetDate_Time_From_YYMMDDHHMMSS(Message.TrajectoryPoints[0].ETO)).ToString(); string TENDTIME = ConvertToUNIXTimestamp(CBS_Main.GetDate_Time_From_YYMMDDHHMMSS(Message.TrajectoryPoints[Message.TrajectoryPoints.Count - 1].ETO)).ToString(); string query = "INSERT INTO " + MySQLConnetionString.table_name + " (IFPLID, ARCID, FLTSTATE, ADEP, ADES, ARCTYP, ETI, XTI, LASTUPD, TSTARTTIME, TENDTIME, TPOINTS, ENTRIES) " + " VALUES (" + Get_With_Quitation(Message.IFPLID) + "," + Get_With_Quitation(Message.ACID) + "," + Get_With_Quitation(Message.FLTSTATE) + "," + Get_With_Quitation(Message.ADEP) + "," + Get_With_Quitation(Message.ADES) + "," + Get_With_Quitation(Message.ARCTYP) + "," + Get_With_Quitation(CBS_Main.GetDate_Time_AS_YYYYMMDDHHMMSS(Message.AOI_ENTRY_TIME)) + "," + Get_With_Quitation(CBS_Main.GetDate_Time_AS_YYYYMMDDHHMMSS(Message.AOI_EXIT_TIME)) + "," + Get_With_Quitation(LASTUPD) + "," + Get_With_Quitation(TSTARTTIME) + "," + Get_With_Quitation(TENDTIME) + "," + Get_With_Quitation(TPOINTS) + "," + Get_With_Quitation(SEQMUAC) + ")"; // First delete the data for the flight (if already exists) string delete_query = "DELETE FROM " + MySQLConnetionString.table_name + " WHERE IFPLID= " + Get_With_Quitation(Message.IFPLID) + "AND ARCID= " + Get_With_Quitation(Message.ACID); //create command and assign the query and connection from the constructor MySqlCommand cmd = new MySqlCommand(delete_query, MySQLconn); try { //Execute command cmd.ExecuteNonQuery(); } catch (Exception e) { Console.WriteLine(e.Message); } //create command and assign the query and connection from the constructor cmd = new MySqlCommand(query, MySQLconn); try { //Execute command cmd.ExecuteNonQuery(); } catch (Exception e) { Console.WriteLine(e.Message); } }
// This method is to be called once TrajectoryPoints // list has been populated and parsed so only known // points are left in the list (The route has been extracted) private void CalculateAOI_Entry_Exit_Times() { // First take care of the sector entry FL int Start_Index = 0; int End_Index = 0; bool Start_End_WPT_Search_Status = false; // FL int Start_FL; int End_FL; int FL_DIFFERENCE; TimeSpan Start_To_Sector; TimeSpan Start_To_End; double Time_Factor; double Sector_Crossing_FL; // select a reference elllipsoid Ellipsoid reference = Ellipsoid.WGS84; // instantiate the calculator GeodeticCalculator geoCalc = new GeodeticCalculator(); // Get indexes of WPT before and after AOI ENTRY crossing crossing border Get_Start_End_WPT_Index(AOI_ENTRY_TIME, out Start_Index, out End_Index, out Start_End_WPT_Search_Status); if (Start_End_WPT_Search_Status == true) { // First take care of the FL Start_FL = int.Parse(TrajectoryPoints[Start_Index].Flight_Level); End_FL = int.Parse(TrajectoryPoints[End_Index].Flight_Level); FL_DIFFERENCE = End_FL - Start_FL; if (Start_Index != End_Index) { Start_To_Sector = AOI_ENTRY_TIME - CBS_Main.GetDate_Time_From_YYYYMMDDHHMMSS("20" + TrajectoryPoints[Start_Index].ETO); Start_To_End = CBS_Main.GetDate_Time_From_YYYYMMDDHHMMSS("20" + TrajectoryPoints[End_Index].ETO) - CBS_Main.GetDate_Time_From_YYYYMMDDHHMMSS("20" + TrajectoryPoints[Start_Index].ETO); Time_Factor = Start_To_Sector.TotalSeconds / Start_To_End.TotalSeconds; Sector_Crossing_FL = Start_FL + (FL_DIFFERENCE * Time_Factor); } else { Sector_Crossing_FL = Start_FL; Time_Factor = 0.0; } AOI_ENTRY_FL = Math.Round(Sector_Crossing_FL).ToString(); GlobalPosition Start_Pos = new GlobalPosition(new GlobalCoordinates(TrajectoryPoints[Start_Index].Position.GetLatLongDecimal().LatitudeDecimal, TrajectoryPoints[Start_Index].Position.GetLatLongDecimal().LongitudeDecimal)); GlobalPosition End_Pos = new GlobalPosition(new GlobalCoordinates(TrajectoryPoints[End_Index].Position.GetLatLongDecimal().LatitudeDecimal, TrajectoryPoints[End_Index].Position.GetLatLongDecimal().LongitudeDecimal)); // Get the distance and conver it to NM double distance = geoCalc.CalculateGeodeticMeasurement(reference, Start_Pos, End_Pos).PointToPointDistance; if (distance > 0) { distance = (distance / 100.0) * (double)Time_Factor; distance = 0.00053996 * distance; //////////////////////////////////////////////////////////// // Calculate the azimuth between two known points Angle Azimuth = geoCalc.CalculateGeodeticMeasurement(reference, Start_Pos, End_Pos).Azimuth; // Calculate new position GeoCordSystemDegMinSecUtilities.LatLongClass New_Position = GeoCordSystemDegMinSecUtilities.CalculateNewPosition(new GeoCordSystemDegMinSecUtilities.LatLongClass(Start_Pos.Latitude.Degrees, Start_Pos.Longitude.Degrees), distance, Azimuth.Degrees); ENTRY_AOI_POINT = new GeoCordSystemDegMinSecUtilities.LatLongClass(New_Position.GetLatLongDecimal().LatitudeDecimal, New_Position.GetLatLongDecimal().LongitudeDecimal); } else { ENTRY_AOI_POINT = new GeoCordSystemDegMinSecUtilities.LatLongClass(Start_Pos.Latitude.Radians, Start_Pos.Longitude.Radians); } } // Get indexes of WPT before and after AOI EXIT crossing crossing border Get_Start_End_WPT_Index(AOI_EXIT_TIME, out Start_Index, out End_Index, out Start_End_WPT_Search_Status); if (Start_End_WPT_Search_Status == true) { // First take care of the FL Start_FL = int.Parse(TrajectoryPoints[Start_Index].Flight_Level); End_FL = int.Parse(TrajectoryPoints[End_Index].Flight_Level); FL_DIFFERENCE = End_FL - Start_FL; Start_To_Sector = AOI_EXIT_TIME - CBS_Main.GetDate_Time_From_YYYYMMDDHHMMSS("20" + TrajectoryPoints[Start_Index].ETO); Start_To_End = CBS_Main.GetDate_Time_From_YYYYMMDDHHMMSS("20" + TrajectoryPoints[End_Index].ETO) - CBS_Main.GetDate_Time_From_YYYYMMDDHHMMSS("20" + TrajectoryPoints[Start_Index].ETO); Time_Factor = Start_To_Sector.TotalSeconds / Start_To_End.TotalSeconds; Sector_Crossing_FL = Start_FL + (FL_DIFFERENCE * Time_Factor); AOI_EXIT_FL = Math.Round(Sector_Crossing_FL).ToString(); GlobalPosition Start_Pos = new GlobalPosition(new GlobalCoordinates(TrajectoryPoints[Start_Index].Position.GetLatLongDecimal().LatitudeDecimal, TrajectoryPoints[Start_Index].Position.GetLatLongDecimal().LongitudeDecimal)); GlobalPosition End_Pos = new GlobalPosition(new GlobalCoordinates(TrajectoryPoints[End_Index].Position.GetLatLongDecimal().LatitudeDecimal, TrajectoryPoints[End_Index].Position.GetLatLongDecimal().LongitudeDecimal)); // Get the distance and conver it to NM double distance = geoCalc.CalculateGeodeticMeasurement(reference, Start_Pos, End_Pos).PointToPointDistance; distance = (distance / 100.0) * (double)Time_Factor; distance = 0.00053996 * distance; //////////////////////////////////////////////////////////// // Calculate the azimuth between two known points Angle Azimuth = geoCalc.CalculateGeodeticMeasurement(reference, Start_Pos, End_Pos).Azimuth; // Calculate new position GeoCordSystemDegMinSecUtilities.LatLongClass New_Position = GeoCordSystemDegMinSecUtilities.CalculateNewPosition(new GeoCordSystemDegMinSecUtilities.LatLongClass(Start_Pos.Latitude.Degrees, Start_Pos.Longitude.Degrees), distance, Azimuth.Degrees); EXIT_AOI_POINT = new GeoCordSystemDegMinSecUtilities.LatLongClass(New_Position.GetLatLongDecimal().LatitudeDecimal, New_Position.GetLatLongDecimal().LongitudeDecimal); } }