private void CheckElementValue(XmlElement ElementSource, string AttributeName, ref float OutValue) { if (!ElementSource.HasAttribute(AttributeName)) { return; } OutValue = MM_Converter.ToSingle(ElementSource.Attributes[AttributeName].Value); }
/// <summary> /// Initialize a new weather station /// </summary> /// <param name="xE">The XML Element containing the station's ID and lat/long</param> public MM_WeatherStation(XmlElement xE) { if (xE["icao"] != null) { this.StationID = xE["icao"].InnerText; } if (xE["lon"] != null && xE["lat"] != null) { this.LngLat = new PointF(ConvertToSingle(xE["lon"].InnerText), ConvertToSingle(xE["lat"].InnerText)); } if (xE.HasAttribute("StationID")) { this.StationID = xE.Attributes["StationID"].Value; } if (xE.HasAttribute("Description")) { this.Description = (xE.Attributes["Description"].Value); } if (xE.HasAttribute("Coordinates")) { this.LngLat = new PointF(MM_Converter.ToSingle(xE.Attributes["Coordinates"].Value.Split(',')[0]), MM_Converter.ToSingle(xE.Attributes["Coordinates"].Value.Split(',')[1])); } if (xE.HasAttribute("Elevation")) { this.Elevation = MM_Converter.ToSingle(xE.Attributes["Elevation"].Value); } if (xE.HasAttribute("Temperature")) { this.Temperature = MM_Converter.ToSingle(xE.Attributes["Temperature"].Value); } if (xE.HasAttribute("Humidity")) { this.Humidity = MM_Converter.ToSingle(xE.Attributes["Humidity"].Value); } if (xE.HasAttribute("WindDirection")) { this.WindDirection = xE.Attributes["WindDirection"].Value; } if (xE.HasAttribute("WindSpeed")) { this.WindSpeed = MM_Converter.ToSingle(xE.Attributes["WindSpeed"].Value); } if (xE.HasAttribute("Pressure")) { this.Pressure = MM_Converter.ToSingle(xE.Attributes["Pressure"].Value); } if (xE.HasAttribute("Dewpoint")) { this.Dewpoint = MM_Converter.ToSingle(xE.Attributes["Dewpoint"].Value); } if (xE.HasAttribute("Summary")) { this.Summary = (xE.Attributes["Summary"].Value); } }
/// <summary> /// Check an element for its value, and add it in. /// </summary> /// <param name="ElementSource"></param> /// <param name="AttributeName"></param> /// <param name="OutValues"></param> private void CheckElementValue(XmlElement ElementSource, string AttributeName, ref float[] OutValues) { if (!ElementSource.HasAttribute(AttributeName)) { return; } String[] splStr = ElementSource.Attributes[AttributeName].Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); for (int a = 0; a < OutValues.Length; a++) { OutValues[a] = MM_Converter.ToSingle(splStr[a]); } }
/// <summary> /// Convert a string to a single-precision number /// </summary> /// <param name="Value"></param> /// <returns></returns> private float ConvertToSingle(String Value) { StringBuilder ToReadStr = new StringBuilder(); foreach (Char c in Value.ToCharArray()) { if (Char.IsNumber(c) || (c == '.')) { ToReadStr.Append(c); } } if (ToReadStr.Length == 0) { return(0f); } else { return(MM_Converter.ToSingle(ToReadStr.ToString())); } }
/// <summary> /// Create a new IROL/CSC limit /// </summary> /// <param name="dr"></param> public MM_Limit(DataRow dr) { this.Name = MM_Repository.TitleCase((string)dr["ID"]); this.Current = MM_Converter.ToSingle(dr["RTOTMW"]); this.Max = MM_Converter.ToSingle(dr["LTOTMW"]); }
/* * /// <summary> * /// Create a new boundary (from an XML element) * /// </summary> * /// <param name="xE">The element containing boundary information</param> * public MM_Boundary(XmlElement xE) * { * this.Name = xE.Attributes["Name"].Value; * this.Max = new PointF(MM_Converter.ToSingle(xE.Attributes["Max_X"].Value), MM_Converter.ToSingle(xE.Attributes["Max_Y"].Value)); * this.Min = new PointF(MM_Converter.ToSingle(xE.Attributes["Min_X"].Value), MM_Converter.ToSingle(xE.Attributes["Min_Y"].Value)); * this.Centroid = new PointF(MM_Converter.ToSingle(xE.Attributes["Centroid_X"].Value), MM_Converter.ToSingle(xE.Attributes["Centroid_Y"].Value)); * if (xE.HasAttribute("Boundary_Website")) * this.Website = xE.Attributes["Boundary_Website"].Value; * * String[] splCoords; * if (xE["Coordinates"] == null) * splCoords = xE.InnerText.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); * else * splCoords = xE["Coordinates"].InnerText.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); * Coordinates = new PointF[splCoords.Length / 2]; * List<PointF> ConvertedPoints = new List<PointF>(Coordinates.Length); * #if LimitedCoordinates * List<PointF> NewPoints = new List<PointF>(); * int NumDecPlaces = 3; * for (int a = 0; a < splCoords.Length; a += 2) * { * PointF ThisPoint = RoundedPoint(splCoords[a], splCoords[a + 1], NumDecPlaces); * if (NewPoints.Count == 0 || ThisPoint.X != NewPoints[NewPoints.Count - 1].X || ThisPoint.Y != NewPoints[NewPoints.Count - 1].Y) * { * NewPoints.Add(ThisPoint); * ConvertedPoints.Add(new PointF(ThisPoint.X * 1000f, ThisPoint.Y * 1000f)); * } * } * Coordinates = NewPoints.ToArray(); * #else * for (int a = 0; a < Coordinates.Length; a++) * { * Coordinates[a] = new PointF(MM_Converter.ToSingle(splCoords[a * 2]), MM_Converter.ToSingle(splCoords[(a * 2) + 1])); * ConvertedPoints.Add(new PointF(Coordinates[a].X * 1000f, Coordinates[a].Y * 1000f)); * } #endif * HitTestPath.AddLines(ConvertedPoints.ToArray()); * ConvertedPoints.Clear(); * * WeatherAlerts = new List<string>(xE.SelectNodes("WeatherAlert").Count); * WeatherForecast = new Dictionary<string, string>(xE.SelectNodes("WeatherForecast").Count); * WeatherStations = new List<MM_WeatherStation>(xE.SelectNodes("WeatherStation").Count); * * foreach (XmlNode xE2 in xE.ChildNodes) * if (xE2 is XmlElement == false) * { } * else if (xE2.Name == "WeatherAlert") * WeatherAlerts.Add((xE2.Attributes["Value"].Value)); * else if (xE2.Name == "WeatherForecast") * WeatherForecast.Add((xE2.Attributes["Name"].Value), (xE2.Attributes["Value"].Value)); * else if (xE2.Name == "WeatherStation") * this.WeatherStations.Add(new MM_WeatherStation(xE2 as XmlElement)); * * * * }*/ /// <summary> /// Convert a string to a rounded decimal point /// </summary> /// <param name="X">The X coordinate</param> /// <param name="Y">The Y coordinate</param> /// <param name="NumDecPlaces">The number of decimal places</param> /// <returns></returns> private PointF RoundedPoint(string X, string Y, int NumDecPlaces) { return(new PointF((float)Math.Round(MM_Converter.ToSingle(X), NumDecPlaces), (float)Math.Round(MM_Converter.ToSingle(Y), NumDecPlaces))); }
/// <summary> /// Initialize a new boundary /// </summary> /// <param name="xE"></param> /// <param name="AddIfNew">Whether to add any new elements that may be created</param> public MM_Boundary(XmlElement xE, bool AddIfNew) : base(xE, AddIfNew) { //Because of an issue where some boundaries contain multiple substations of the same TEID, fix it here. Dictionary <Int32, MM_Substation> Subs = new Dictionary <Int32, MM_Substation>(Substations.Count); foreach (MM_Substation Sub in this.Substations) { if (!Subs.ContainsKey(Sub.TEID)) { Subs.Add(Sub.TEID, Sub); } } Substations.Clear(); Substations.AddRange(Subs.Values); if (xE.HasAttribute("Max_X")) { this.Max = new PointF(MM_Converter.ToSingle(xE.Attributes["Max_X"].Value), MM_Converter.ToSingle(xE.Attributes["Max_Y"].Value)); this.Min = new PointF(MM_Converter.ToSingle(xE.Attributes["Min_X"].Value), MM_Converter.ToSingle(xE.Attributes["Min_Y"].Value)); this.Centroid = new PointF(MM_Converter.ToSingle(xE.Attributes["Centroid_X"].Value), MM_Converter.ToSingle(xE.Attributes["Centroid_Y"].Value)); } if (xE.HasAttribute("Boundary_Website")) { this.Website = xE.Attributes["Boundary_Website"].Value; } if (xE.HasAttribute("Coordinates") || xE["Coordinates"] != null) { String[] Coords = null; if (xE["Coordinates"] != null) { Coords = xE["Coordinates"].InnerText.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); } else { Coords = xE.Attributes["Coordinates"].InnerText.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); } List <PointF> OutCoordinates = new List <PointF>(); List <PointF> OutConvertedCoordinates = new List <PointF>(); for (int a = 0; a < Coords.Length; a += 2) { PointF OutPt = new PointF(MM_Converter.ToSingle(Coords[a]), MM_Converter.ToSingle(Coords[a + 1])); OutCoordinates.Add(OutPt); OutConvertedCoordinates.Add(new PointF(OutPt.X * 1000f, OutPt.Y * 1000f)); } //Now make sure the last coordiante closes it out. if (OutCoordinates[OutCoordinates.Count - 1].Equals(OutCoordinates[0]) == false) { OutCoordinates.Add(OutCoordinates[0]); OutConvertedCoordinates.Add(OutConvertedCoordinates[0]); } Coordinates = OutCoordinates; HitTestPath.AddLines(OutConvertedCoordinates.ToArray()); } else { List <PointF> OutConvertedCoordinates = new List <PointF>(); foreach (PointF OutPt in Coordinates) { OutConvertedCoordinates.Add(new PointF(OutPt.X * 1000f, OutPt.Y * 1000f)); } try { HitTestPath.AddLines(OutConvertedCoordinates.ToArray()); } catch (Exception ex) { MM_System_Interfaces.LogError(ex); } } }