/// <summary> /// Désérialisation d'une définition de thème /// </summary> public Task <NatalChartDefinition> Deserialize(Stream stream) { if (stream == null) { throw new ArgumentNullException("stream"); } return(Task.Factory.StartNew <NatalChartDefinition>(() => { var result = new NatalChartDefinition(); result.Planets.Clear(); XmlReaderSettings settings = new XmlReaderSettings { CloseInput = false, IgnoreComments = true, IgnoreProcessingInstructions = true, IgnoreWhitespace = true }; using (var reader = XmlReader.Create(stream, settings)) { while (reader.Read()) { while (reader.IsStartElement()) { switch (reader.Name) { case "name": result.Name = reader.ReadElementContentAsString(); break; case "gender": Gender gender; if (Enum.TryParse <Gender>(reader.ReadElementContentAsString(), true, out gender)) { result.Gender = gender; } break; case "birth-date": using (var sTree = reader.ReadSubtree()) Deserialize(result.BirthDate, sTree); break; case "birth-place-name": result.BirthPlaceName = reader.ReadElementContentAsString(); break; case "birth-place-position": using (var sTree = reader.ReadSubtree()) result.BirthPlacePosition = DeserializeGeoPosition(sTree); break; case "position-center": PositionCenter posCent; if (Enum.TryParse <PositionCenter>(reader.ReadElementContentAsString(), true, out posCent)) { result.PositionCenter = posCent; } break; case "house-system": HouseSystem hSys; if (Enum.TryParse <HouseSystem>(reader.ReadElementContentAsString(), true, out hSys)) { result.HouseSystem = hSys; } break; case "planets": result.Planets.Clear(); using (var sTree = reader.ReadSubtree()) Deserialize(result.Planets, sTree); break; default: reader.Read(); break; } } } } return result; })); }
/// <summary> /// Sérialisation d'une définition de thème /// </summary> public Task Serialize(NatalChartDefinition definition, Stream stream) { if (definition == null) { throw new ArgumentNullException("definition"); } if (stream == null) { throw new ArgumentNullException("stream"); } return(Task.Factory.StartNew(() => { XmlWriterSettings settings = new XmlWriterSettings { CloseOutput = false, Encoding = Encoding.UTF8, Indent = true, IndentChars = " ", OmitXmlDeclaration = false }; using (XmlWriter writer = XmlWriter.Create(stream, settings)) { writer.WriteStartDocument(); //writer.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'"); writer.WriteStartElement("natal-chart"); writer.WriteElementString("name", definition.Name); writer.WriteElementString("gender", definition.Gender.ToString()); writer.WriteStartElement("birth-date"); writer.WriteElementString("date", String.Format("{0:D4}-{1:D2}-{2:D2}", definition.BirthDate.Year, definition.BirthDate.Month, definition.BirthDate.Day)); writer.WriteElementString("time", String.Format("{0:D2}:{1:D2}:{2:D2}.{3:D3}", definition.BirthDate.Hour, definition.BirthDate.Minute, definition.BirthDate.Second, definition.BirthDate.MilliSecond)); writer.WriteElementString("timezone", definition.BirthDate.TimeZone != null ? definition.BirthDate.TimeZone.StandardName : String.Empty); writer.WriteElementString("utc-offset", (definition.BirthDate.TimeZone != null ? definition.BirthDate.TimeZone.BaseUtcOffset : definition.BirthDate.UtcOffset).TotalHours.ToString(System.Globalization.CultureInfo.InvariantCulture)); writer.WriteElementString("daylight", definition.BirthDate.DayLight.ToString()); writer.WriteEndElement(); writer.WriteElementString("birth-place-name", definition.BirthPlaceName); if (definition.BirthPlacePosition != null) { writer.WriteStartElement("birth-place-position"); writer.WriteElementString("longitude", definition.BirthPlacePosition.Longitude.ToString()); writer.WriteElementString("latitude", definition.BirthPlacePosition.Latitude.ToString()); writer.WriteElementString("altitude", definition.BirthPlacePosition.Altitude.ToString()); writer.WriteEndElement(); } writer.WriteElementString("position-center", definition.PositionCenter.ToString()); writer.WriteElementString("house-system", definition.HouseSystem.ToString()); writer.WriteStartElement("planets"); foreach (var planet in definition.Planets) { writer.WriteStartElement("planet"); writer.WriteAttributeString("id", planet.Id.ToString()); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); } })); }
/// <summary> /// Calcul un thème natal /// </summary> public NatalChart CalculateNatalChart(NatalChartDefinition definition) { if (definition == null) { throw new ArgumentNullException(); } // Préparation du résultat NatalChart result = new NatalChart { Definition = definition }; // Initialisation du provider pour le calcul EphemerisProvider.SetTopographic(definition.PositionCenter, definition.BirthPlacePosition); EphemerisProvider.HouseSystem = definition.HouseSystem; // Calcul des dates et des temps result.DateUTC = definition.BirthDate.ToDateTimeOffset().ToUniversalTime(); result.JulianDay = EphemerisProvider.ToJulianDay(definition.BirthDate); result.UniversalTime = EphemerisProvider.ToUniversalTime(result.JulianDay); result.EphemerisTime = EphemerisProvider.ToEphemerisTime(result.JulianDay); result.SideralTime = EphemerisProvider.ToSideralTime(result.JulianDay, definition.BirthPlacePosition.Longitude); // Calculs var enValues = EphemerisProvider.CalcEclipticNutation(result.EphemerisTime); result.TrueEclipticObliquity = enValues.TrueEclipticObliquity; result.MeanEclipticObliquity = enValues.MeanEclipticObliquity; result.NutationLongitude = enValues.NutationLongitude; result.NutationObliquity = enValues.NutationObliquity; // Planets foreach (var planet in definition.Planets) { if (planet == Planet.EclipticNutation) { continue; } if (planet == Planet.Earth && (definition.PositionCenter == PositionCenter.Geocentric || definition.PositionCenter == PositionCenter.Topocentric)) { continue; // Exclude Earth if geo or topo } var pi = EphemerisProvider.CalcPlanet(planet, result.EphemerisTime, result.ARMC, definition.BirthPlacePosition.Longitude, result.TrueEclipticObliquity); result.Planets.Add(pi); } ///* // //* equator position * / // if (fmt.IndexOfAny("aADdQ".ToCharArray()) >= 0) { // iflag2 = iflag | SwissEph.SEFLG_EQUATORIAL; // if (ipl == SwissEph.SE_FIXSTAR) // iflgret = sweph.swe_fixstar(star, tjd_et, iflag2, xequ, ref serr); // else // iflgret = sweph.swe_calc(tjd_et, ipl, iflag2, xequ, ref serr); // } // //* ecliptic cartesian position * / // if (fmt.IndexOfAny("XU".ToCharArray()) >= 0) { // iflag2 = iflag | SwissEph.SEFLG_XYZ; // if (ipl == SwissEph.SE_FIXSTAR) // iflgret = sweph.swe_fixstar(star, tjd_et, iflag2, xcart, ref serr); // else // iflgret = sweph.swe_calc(tjd_et, ipl, iflag2, xcart, ref serr); // } // //* equator cartesian position * / // if (fmt.IndexOfAny("xu".ToCharArray()) >= 0) { // iflag2 = iflag | SwissEph.SEFLG_XYZ | SwissEph.SEFLG_EQUATORIAL; // if (ipl == SwissEph.SE_FIXSTAR) // iflgret = sweph.swe_fixstar(star, tjd_et, iflag2, xcartq, ref serr); // else // iflgret = sweph.swe_calc(tjd_et, ipl, iflag2, xcartq, ref serr); // } // spnam = se_pname; // */ // Houses var houses = EphemerisProvider.CalcHouses(result.JulianDay, definition.BirthPlacePosition.Latitude, definition.BirthPlacePosition.Longitude, result.AscMcs); result.Houses.AddRange(houses); return(result); }