Esempio n. 1
0
 public void Write(PlanExportData data, string filePath)
 {
     using (var file = new StreamWriter(filePath, false, Encoding.UTF8))
     {
         file.WriteLine($"Date={data.Date.Value:yyyy-MM-dd}, From={data.Begin.Value}, To={data.End.Value}");
         foreach (var item in data.Ephemerides)
         {
             CelestialObject body = item.CelestialObject;
             string          name = body.CommonName.PadRight(32);
             double          ra   = item.GetValue <double>("Equatorial.Alpha");
             double          dec  = item.GetValue <double>("Equatorial.Delta");
             if (double.IsNaN(ra))
             {
                 ra = 0;
             }
             if (double.IsNaN(dec))
             {
                 dec = 0;
             }
             string strRa  = ra.ToString("0.00000", CultureInfo.InvariantCulture).PadRight(10);
             string strDec = dec.ToString("0.00000", CultureInfo.InvariantCulture).PadRight(10);
             file.WriteLine($"{name}{strRa}{strDec}{name}");
         }
     }
 }
        public void Write(PlanExportData data, string filePath)
        {
            var plan = new Plan();

            plan.Date    = DateTime.SpecifyKind(data.Date.Value.Date, DateTimeKind.Unspecified);
            plan.Begin   = data.Begin.Value;
            plan.End     = data.End.Value;
            plan.Objects = data.Ephemerides.Select(x => new PlanItem(x.CelestialObject)).ToList();
            File.WriteAllText(filePath, JsonConvert.SerializeObject(plan, Formatting.Indented, jsonSerializerSettings), Encoding.UTF8);
        }
        public void Write(PlanExportData data, string filePath)
        {
            using (var file = new StreamWriter(filePath, false, Encoding.UTF8))
            {
                file.WriteLine(FILE_HEADER);
                foreach (var item in data.Ephemerides)
                {
                    file.WriteLine(BEGIN_OBJECT);

                    CelestialObject body = item.CelestialObject;
                    string          type = item.CelestialObject.Type;
                    if (type.StartsWith("DeepSky."))
                    {
                        type = "DeepSky";
                    }

                    switch (type)
                    {
                    case "Star":
                    {
                        file.WriteLine($"\tObjectID=2,-1,-1");
                        foreach (string name in body.Names)
                        {
                            file.WriteLine($"\tCatalogNumber={name}");
                        }
                        break;
                    }

                    case "Sun":
                    case "Moon":
                    case "Planet":
                    case "PlanetMoon":
                    {
                        file.WriteLine($"\tObjectID=1,-1,-1");
                        file.WriteLine($"\tCommonName={body.CommonName}");
                        break;
                    }

                    case "Asteroid":
                    {
                        file.WriteLine($"\tObjectID=1,-1,-1");
                        Regex  pattern = new Regex(@"\((?<number>\d+)\)\s*(?<name>.+)");
                        Match  match   = pattern.Match(body.CommonName);
                        string number  = match.Groups["number"].Value;
                        string name    = match.Groups["name"].Value;
                        if (match.Success)
                        {
                            file.WriteLine($"\tCommonName={name}");
                            file.WriteLine($"\tCatalogNumber={number}");
                        }
                        else
                        {
                            file.WriteLine($"\tCommonName={body.CommonName}");
                        }
                        break;
                    }

                    case "Comet":
                    {
                        file.WriteLine($"\tObjectID=1,-1,-1");
                        Regex  pattern = new Regex(@"(?<name2>.+)\s*\((?<name1>\w+\s*)\)");
                        Match  match   = pattern.Match(body.CommonName);
                        string name1   = match.Groups["name1"].Value.Trim();
                        string name2   = match.Groups["name2"].Value.Trim();
                        if (match.Success)
                        {
                            file.WriteLine($"\tCommonName={name1}");
                            file.WriteLine($"\tCommonName={name2}");
                        }
                        else
                        {
                            file.WriteLine($"\tCommonName={body.CommonName}");
                        }
                        break;
                    }

                    case "DeepSky":
                    {
                        file.WriteLine($"\tObjectID=4,-1,-1");
                        foreach (string name in body.Names)
                        {
                            file.WriteLine($"\tCatalogNumber={name}");
                        }
                        break;
                    }

                    default:
                        // UNKNOWN TYPE, SKIP
                        break;
                    }

                    file.WriteLine(END_OBJECT);
                }
            }
        }