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); }
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(); } } }
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; } } }
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"); }
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); } } }
// /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); }
// 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); }