///<summary> /// A method that returns an XML formatted <c>String</c> representing /// the serialized <c>Object</c>. The format used is: /// /// <code> /// <AstronomicalTimes date="1969-02-08" type="net.sourceforge.zmanim.AstronomicalCalendar algorithm="US Naval Almanac Algorithm" location="Lakewood, NJ" latitude="40.095965" longitude="-74.22213" elevation="25.4" timeZoneName="Eastern Standard Time" timeZoneID="America/New_York" timeZoneOffset="-5"> /// <Sunrise>2007-02-18T06:45:27-05:00</Sunrise> /// <TemporalHour>PT54M17.529S</TemporalHour> /// ... /// </AstronomicalTimes> /// </code> /// /// Note that the output uses the <a href = "http://www.w3.org/TR/xmlschema11-2/#Date">xsd:Date</a> /// format for times such as sunrise, and <a href = "http://www.w3.org/TR/xmlschema11-2/#duration">xsd:duration</a> /// format for times that are a duration such as the length of a /// <see cref = "AstronomicalCalendar.GetTemporalHour()">temporal hour</see>. /// The output of this method is returned by the <see cref = "AstronomicalCalendar.ToString" /> }. ///</summary> ///<returns> The XML formatted <c>String</c>. The format will be: /// /// <code> /// <AstronomicalTimes date="1969-02-08" type="net.sourceforge.zmanim.AstronomicalCalendar algorithm="US Naval Almanac Algorithm" location="Lakewood, NJ" latitude="40.095965" longitude="-74.22213" elevation="25.4" timeZoneName="Eastern Standard Time" timeZoneID="America/New_York" timeZoneOffset="-5"> /// <Sunrise>2007-02-18T06:45:27-05:00</Sunrise> /// <TemporalHour>PT54M17.529S</TemporalHour> /// ... /// </AstronomicalTimes> /// </code> ///</returns> public static string ToXml(AstronomicalCalendar ac) { var formatter = new ZmanimFormatter(XSD_DURATION_FORMAT, "yyyy-MM-dd'T'HH:mm:ss"); string df = "yyyy-MM-dd"; var output = new StringBuilder("<"); if (ac.GetType().Name.EndsWith("AstronomicalCalendar")) { output.Append("AstronomicalTimes"); } else if (ac.GetType().Name.EndsWith("ZmanimCalendar")) { output.Append("Zmanim"); } output.Append(" date=\"" + ac.DateWithLocation.Date.ToString(df) + "\""); output.Append(" type=\"" + ac.GetType().Name + "\""); output.Append(" algorithm=\"" + ac.AstronomicalCalculator.CalculatorName + "\""); output.Append(" location=\"" + ac.DateWithLocation.Location.LocationName + "\""); output.Append(" latitude=\"" + ac.DateWithLocation.Location.Latitude + "\""); output.Append(" longitude=\"" + ac.DateWithLocation.Location.Longitude + "\""); output.Append(" elevation=\"" + ac.DateWithLocation.Location.Elevation + "\""); output.Append(" timeZoneName=\"" + ac.DateWithLocation.Location.TimeZone.GetDisplayName() + "\""); output.Append(" timeZoneID=\"" + ac.DateWithLocation.Location.TimeZone.GetId() + "\""); output.Append(" timeZoneOffset=\"" + (ac.DateWithLocation.Location.TimeZone.GetOffset(ac.DateWithLocation.Date.ToFileTime()) / ((double)HOUR_MILLIS)) + "\""); output.Append(">\n"); MethodInfo[] theMethods = ac.GetType().GetMethods(); string tagName = ""; object @value = null; IList <Zman> dateList = new List <Zman>(); IList <Zman> durationList = new List <Zman>(); IList <string> otherList = new List <string>(); for (int i = 0; i < theMethods.Length; i++) { if (IncludeMethod(theMethods[i])) { tagName = theMethods[i].Name.Substring(3); //String returnType = theMethods[i].getReturnType().getName(); try { @value = theMethods[i].Invoke(ac, null); if (@value == null) //FIXME: use reflection to determine what the return type is, not the value { otherList.Add("<" + tagName + ">N/A</" + tagName + ">"); } else if (@value is DateTime) { dateList.Add(new Zman((DateTime)@value, tagName)); } // shaah zmanis else if (@value is long?) { durationList.Add(new Zman((int)((long?)@value), tagName)); } // will probably never enter this block, but is else { // present to be future proof otherList.Add("<" + tagName + ">" + @value + "</" + tagName + ">"); } } catch (Exception e) { output.Append(e.StackTrace); throw; } } } foreach (Zman zman in dateList.OrderBy(x => x.ZmanTime)) { output.Append("\t<" + zman.ZmanLabel); output.Append(">"); output.Append(formatter.FormatDate(zman.ZmanTime, ac.DateWithLocation) + "</" + zman.ZmanLabel + ">\n"); } foreach (Zman zman in durationList.OrderBy(x => x.Duration)) { output.Append("\t<" + zman.ZmanLabel); output.Append(">"); output.Append(formatter.Format((int)zman.Duration) + "</" + zman.ZmanLabel + ">\n"); } foreach (string t in otherList) { // will probably never enter this block output.Append("\t" + t + "\n"); } if (ac.GetType().Name.EndsWith("AstronomicalCalendar")) { output.Append("</AstronomicalTimes>"); } else if (ac.GetType().Name.EndsWith("ZmanimCalendar")) { output.Append("</Zmanim>"); } return(output.ToString()); }
///<summary> /// A method that returns an XML formatted <c>String</c> representing /// the serialized <c>Object</c>. The format used is: /// /// <code> /// <AstronomicalTimes date="1969-02-08" type="net.sourceforge.zmanim.AstronomicalCalendar algorithm="US Naval Almanac Algorithm" location="Lakewood, NJ" latitude="40.095965" longitude="-74.22213" elevation="25.4" timeZoneName="Eastern Standard Time" timeZoneID="America/New_York" timeZoneOffset="-5"> /// <Sunrise>2007-02-18T06:45:27-05:00</Sunrise> /// <TemporalHour>PT54M17.529S</TemporalHour> /// ... /// </AstronomicalTimes> /// </code> /// /// Note that the output uses the <a href = "http://www.w3.org/TR/xmlschema11-2/#Date">xsd:Date</a> /// format for times such as sunrise, and <a href = "http://www.w3.org/TR/xmlschema11-2/#duration">xsd:duration</a> /// format for times that are a duration such as the length of a /// <see cref = "AstronomicalCalendar.GetTemporalHour()">temporal hour</see>. /// The output of this method is returned by the <see cref = "AstronomicalCalendar.ToString" /> }. ///</summary> ///<returns> The XML formatted <c>String</c>. The format will be: /// /// <code> /// <AstronomicalTimes date="1969-02-08" type="net.sourceforge.zmanim.AstronomicalCalendar algorithm="US Naval Almanac Algorithm" location="Lakewood, NJ" latitude="40.095965" longitude="-74.22213" elevation="25.4" timeZoneName="Eastern Standard Time" timeZoneID="America/New_York" timeZoneOffset="-5"> /// <Sunrise>2007-02-18T06:45:27-05:00</Sunrise> /// <TemporalHour>PT54M17.529S</TemporalHour> /// ... /// </AstronomicalTimes> /// </code> ///</returns> public static string ToXml(AstronomicalCalendar ac) { var formatter = new ZmanimFormatter(XSD_DURATION_FORMAT, "yyyy-MM-dd'T'HH:mm:ss"); string df = "yyyy-MM-dd"; var output = new StringBuilder("<"); if (ac.GetType().Name.EndsWith("AstronomicalCalendar")) { output.Append("AstronomicalTimes"); } else if (ac.GetType().Name.EndsWith("ZmanimCalendar")) { output.Append("Zmanim"); } output.Append(" date=\"" + ac.DateWithLocation.Date.ToString(df) + "\""); output.Append(" type=\"" + ac.GetType().Name + "\""); output.Append(" algorithm=\"" + ac.AstronomicalCalculator.CalculatorName + "\""); output.Append(" location=\"" + ac.DateWithLocation.Location.LocationName + "\""); output.Append(" latitude=\"" + ac.DateWithLocation.Location.Latitude + "\""); output.Append(" longitude=\"" + ac.DateWithLocation.Location.Longitude + "\""); output.Append(" elevation=\"" + ac.DateWithLocation.Location.Elevation + "\""); output.Append(" timeZoneName=\"" + ac.DateWithLocation.Location.TimeZone.GetDisplayName() + "\""); output.Append(" timeZoneID=\"" + ac.DateWithLocation.Location.TimeZone.GetId() + "\""); output.Append(" timeZoneOffset=\"" + (ac.DateWithLocation.Location.TimeZone.GetOffset(ac.DateWithLocation.Date.ToFileTime()) / ((double)HOUR_MILLIS)) + "\""); output.Append(">\n"); MethodInfo[] theMethods = ac.GetType().GetMethods(); string tagName = ""; object @value = null; IList<Zman> dateList = new List<Zman>(); IList<Zman> durationList = new List<Zman>(); IList<string> otherList = new List<string>(); for (int i = 0; i < theMethods.Length; i++) { if (IncludeMethod(theMethods[i])) { tagName = theMethods[i].Name.Substring(3); //String returnType = theMethods[i].getReturnType().getName(); try { @value = theMethods[i].Invoke(ac, null); if (@value == null) //FIXME: use reflection to determine what the return type is, not the value { otherList.Add("<" + tagName + ">N/A</" + tagName + ">"); } else if (@value is DateTime) { dateList.Add(new Zman((DateTime)@value, tagName)); } // shaah zmanis else if (@value is long?) { durationList.Add(new Zman((int)((long?)@value), tagName)); } // will probably never enter this block, but is else { // present to be future proof otherList.Add("<" + tagName + ">" + @value + "</" + tagName + ">"); } } catch (Exception e) { output.Append(e.StackTrace); throw; } } } foreach (Zman zman in dateList.OrderBy(x => x.ZmanTime)) { output.Append("\t<" + zman.ZmanLabel); output.Append(">"); output.Append(formatter.FormatDate(zman.ZmanTime, ac.DateWithLocation) + "</" + zman.ZmanLabel + ">\n"); } foreach (Zman zman in durationList.OrderBy(x => x.Duration)) { output.Append("\t<" + zman.ZmanLabel); output.Append(">"); output.Append(formatter.Format((int)zman.Duration) + "</" + zman.ZmanLabel + ">\n"); } foreach (string t in otherList) { // will probably never enter this block output.Append("\t" + t + "\n"); } if (ac.GetType().Name.EndsWith("AstronomicalCalendar")) { output.Append("</AstronomicalTimes>"); } else if (ac.GetType().Name.EndsWith("ZmanimCalendar")) { output.Append("</Zmanim>"); } return output.ToString(); }