Esempio n. 1
0
        public static void Report(GPLocationProvider loc, string prefix)
        {
            GPGregorianTime start = new GPGregorianTime(loc);
            GPGregorianTime end   = new GPGregorianTime(loc);

            start.setDate(2010, 1, 1);
            end.setDate(2015, 1, 1);

            GPCalendarResults calendar = new GPCalendarResults();

            calendar.CalculateCalendar(start, Convert.ToInt32(end.getJulianLocalNoon() - start.getJulianLocalNoon()));

            GPCoreEventResults coreEvents = new GPCoreEventResults();

            coreEvents.Sort(false);
            coreEvents.CalculateEvents(loc, start, end);

            string path = "d:\\gcal\\reports\\";

            if (Directory.Exists(path))
            {
                File.WriteAllText(Path.Combine(path, prefix + "-cal-" + loc.getCity() + ".txt"),
                                  FormaterInternal.getInternalDalendarData(calendar));
                File.WriteAllText(Path.Combine(path, prefix + "-eve-" + loc.getCity() + ".txt"),
                                  FormaterInternal.getInternalEventsText(coreEvents));
            }
        }
Esempio n. 2
0
        public static string getInternalEventsText(GPCoreEventResults inEvents)
        {
            int i;

            StringBuilder res = new StringBuilder();

            res.AppendFormat(getSharedStringHtml(983), inEvents.m_vcStart, inEvents.m_vcEnd);
            res.AppendLine();
            res.AppendLine();

            res.Append(inEvents.m_location.getFullName());
            res.AppendLine();
            res.AppendLine();

            DateTime prevd = new DateTime(1970, 1, 1);

            for (i = 0; i < inEvents.getCount(); i++)
            {
                GPCoreEvent dnr = inEvents.get(i);

                if (!inEvents.b_sorted)
                {
                    res.Append(dnr.Time.ToString().PadLeft(20));
                }

                res.AppendFormat("   {0}  {1}", dnr.Time.getLongTimeString(), dnr.getEventTitle());
                res.AppendLine();
            }

            res.AppendLine();

            return(res.ToString());
        }
Esempio n. 3
0
        public static int FormatEventsXML(GPCoreEventResults inEvents, StringBuilder strXml)
        {
            int i;

            strXml.AppendFormat("<xml>\r\n<program version=\"{0}\">\r\n<location longitude=\"{1}\" latitude=\"{2}\" timezone=\"{3}\"/>\n"
                                , GPFileHelper.FileVersion, inEvents.m_location.getLocation(0).GetLongitudeEastPositive(),
                                inEvents.m_location.getLocation(0).GetLatitudeNorthPositive()
                                , inEvents.m_location.getLocation(0).getTimeZoneName());
            GPGregorianTime prevd = new GPGregorianTime(inEvents.m_location);

            prevd.setDate(1800, 1, 1);
            for (i = 0; i < inEvents.getCount(); i++)
            {
                GPCoreEvent dnr = inEvents.get(i);

                if (inEvents.b_sorted)
                {
                    if (prevd.getDay() != dnr.Time.getDay() || prevd.getMonth() != dnr.Time.getMonth() || prevd.getYear() != dnr.Time.getYear())
                    {
                        strXml.AppendFormat("\t<day date=\"{0}\" />\n", dnr.Time);
                    }
                    prevd = dnr.Time;
                }

                strXml.AppendFormat("\t<event type=\"{0}\" time=\"{1}\" />\n", dnr.getEventTitle(), dnr.Time.getLongTimeString());
            }

            strXml.Append("</xml>\n");

            return(1);
        }
Esempio n. 4
0
        public static int FormatEventsRtf(GPCoreEventResults inEvents, StringBuilder res)
        {
            int i;

            AppendRtfHeader(res);

            res.AppendFormat("{\\fs{0}\\f2 ", g_Header2Size, g_TextSize);
            res.AppendFormat(getSharedStringRtf(983), inEvents.m_vcStart, inEvents.m_vcEnd);
            res.AppendLine("} \\par");
            List <GPLocation> locList = inEvents.getLocationList();

            foreach (GPLocation loc in locList)
            {
                res.Append(loc.getFullName());
                res.AppendLine("\\par");
            }
            res.AppendLine();

            //res.AppendFormat(inEvents.m_location.getFullName());
            //res.AppendLine("\\par");
            res.AppendLine("\\par");

            DateTime prevd = new DateTime(1970, 1, 1);
            int      prevt = -1;

            for (i = 0; i < inEvents.getCount(); i++)
            {
                GPCoreEvent dnr = inEvents.get(i);

                if (inEvents.b_sorted)
                {
                    DateTime dt = dnr.Time.getLocalTime();
                    if (prevd.Day != dt.Day || prevd.Month != dt.Month || prevd.Year != dt.Year)
                    {
                        res.AppendLine("\\par");
                        res.Append(GPAppHelper.CenterString(dnr.Time.getCompleteLongDateString(), 60, '-'));
                        res.AppendLine("\\par");
                        res.AppendLine("\\par");
                    }
                    prevd = dt;
                }
                else
                {
                    if (prevt != dnr.nType)
                    {
                        string s = " " + dnr.getTypeTitle() + " ";
                        res.AppendLine("\\par");
                        res.Append(GPAppHelper.CenterString(s, 60, '-'));
                        res.AppendLine("\\par");
                        res.AppendLine("\\par");
                    }
                    prevt = dnr.nType;
                }

                if (!inEvents.b_sorted)
                {
                    res.Append(dnr.Time.ToString().PadLeft(20));
                }

                GPLocation loc = dnr.Time.getLocation();
                res.AppendFormat("  {0}  {1} {2} {3} {4}", dnr.Time.getLongTimeString(), dnr.getEventTitle().PadRight(45),
                                 loc.getTimeZoneName().PadRight(32), loc.getLongitudeString().PadLeft(6), loc.getLatitudeString().PadLeft(6));
                res.AppendLine("\\par");
            }

            res.AppendLine("\\par");

            AddNoteRtf(res);

            res.AppendLine("}");


            return(1);
        }
Esempio n. 5
0
        public void CalculateEvents(GPLocationProvider loc, GPGregorianTime vcStart, GPGregorianTime vcEnd)
        {
            GPCoreEventResults inEvents = this;
            GPLocationProvider earth    = loc;
            GPGregorianTime    vc       = new GPGregorianTime(loc);
            GPSun sun = new GPSun();
            //int ndst = 0;
            int nData;

            inEvents.clear();
            inEvents.m_location = loc;
            inEvents.m_vcStart  = vcStart;
            inEvents.m_vcEnd    = vcEnd;

            GPGregorianTime vcAdd  = new GPGregorianTime(loc);
            GPGregorianTime vcTemp = null;
            GPGregorianTime vcNext = new GPGregorianTime(loc);

            vc.Copy(vcStart);

            if (GPDisplays.CoreEvents.Sunrise())
            {
                vcAdd.Copy(vc);
                while (vcAdd.IsBeforeThis(vcEnd))
                {
                    sun.SunCalc(vcAdd, earth);

                    vcTemp = new GPGregorianTime(sun.arunodaya);
                    inEvents.AddEvent(vcTemp, GPConstants.CCTYPE_S_ARUN, 0);

                    //GPJulianTime tr, tt, ts;
                    //GPAstroEngine.CalculateTimeSun(vcTemp, vcTemp.getLocation(), out tr, out tt, out ts);
                    vcTemp = new GPGregorianTime(sun.rise);
                    //vcTemp = new GPGregorianTime(vcTemp.getLocation(), tr);
                    inEvents.AddEvent(vcTemp, GPConstants.CCTYPE_S_RISE, 0);

                    vcTemp = new GPGregorianTime(sun.noon);
                    //vcTemp = new GPGregorianTime(vcTemp.getLocation(), tt);
                    inEvents.AddEvent(vcTemp, GPConstants.CCTYPE_S_NOON, 0);

                    vcTemp = new GPGregorianTime(sun.set);
                    //vcTemp = new GPGregorianTime(vcTemp.getLocation(), ts);
                    inEvents.AddEvent(vcTemp, GPConstants.CCTYPE_S_SET, 0);

                    vcAdd.NextDay();
                }
            }

            if (GPDisplays.CoreEvents.Tithi())
            {
                GPTithi te = new GPTithi();
                te.setStartDate(vc);
                vcAdd = te.getNext();
                while (vcAdd.IsBeforeThis(vcEnd))
                {
                    nData = te.getCurrentPosition();
                    //ndst = loc.getTimeZone().GetDaylightChangeType(vcNext);
                    inEvents.AddEvent(vcAdd, GPConstants.CCTYPE_TITHI, nData);
                    vcAdd = te.getNext();
                }
            }

            if (GPDisplays.CoreEvents.Naksatra())
            {
                GPNaksatra te = new GPNaksatra();
                te.setStartDate(vc);
                vcAdd = te.getNext();
                while (vcAdd.IsBeforeThis(vcEnd))
                {
                    nData = te.getCurrentNaksatra();
                    //ndst = loc.getTimeZone().GetDaylightChangeType(vcNext);
                    inEvents.AddEvent(vcAdd, GPConstants.CCTYPE_NAKS, nData);
                    vcAdd = te.getNext();
                }
            }

            if (GPDisplays.CoreEvents.Sankranti())
            {
                GPSankranti te = new GPSankranti();
                te.setStartDate(vc);
                vcAdd = te.getNext();
                while (vcAdd.IsBeforeThis(vcEnd))
                {
                    nData = te.getCurrentPosition();
                    //ndst = loc.getTimeZone().GetDaylightChangeType(vcNext);
                    inEvents.AddEvent(vcAdd, GPConstants.CCTYPE_SANK, nData);
                    vcAdd = te.getNext();
                }
            }

            if (GPDisplays.CoreEvents.Conjunction())
            {
                double[]      times = null;
                GPConjunction te    = new GPConjunction();
                te.setStartDate(vc);
                vcAdd = te.getNext();
                while (vcAdd.IsBeforeThis(vcEnd))
                {
                    nData = te.getCurrentPosition();
                    //ndst = loc.getTimeZone().GetDaylightChangeType(vcNext);
                    inEvents.AddEvent(vcAdd, GPConstants.CCTYPE_CONJ, nData);

                    if (GPDisplays.CoreEvents.SunEclipse())
                    {
                        GPAstroEngine.CalculateTimesSunEclipse(vcAdd.getJulianGreenwichTime(), vcAdd.getLocation(), out times);
                        if (times != null && times[2] > 0)
                        {
                            for (int i = 0; i < 5; i++)
                            {
                                if (times[i] > 0)
                                {
                                    GPGregorianTime gt = new GPGregorianTime(vcAdd.getLocation());
                                    gt.setJulianGreenwichTime(new GPJulianTime(times[i], 0.0));
                                    inEvents.AddEvent(gt, GPConstants.SUNECLIPSE_CONSTS[i], 0);
                                }
                            }
                        }
                    }

                    vcAdd = te.getNext();
                }
            }


            // moon eclipses
            if (GPDisplays.CoreEvents.MoonEclipse())
            {
                double[]      times = null;
                GPConjunction te    = new GPConjunction();
                te.setOpositeConjunction(true);
                te.setStartDate(vc);
                vcAdd = te.getNext();
                while (vcAdd.IsBeforeThis(vcEnd))
                {
                    GPAstroEngine.CalculateTimesMoonEclipse(vcAdd.getJulianGreenwichTime(), vcAdd.getLocation(), out times);
                    if (times != null && times[4] > 0)
                    {
                        for (int i = 0; i < 9; i++)
                        {
                            if (times[i] > 0 && GPConstants.MOONECLIPSE_CONSTS[i] > 0)
                            {
                                GPGregorianTime gt = new GPGregorianTime(vcAdd.getLocation());
                                gt.setJulianGreenwichTime(new GPJulianTime(times[i], 0.0));
                                inEvents.AddEvent(gt, GPConstants.MOONECLIPSE_CONSTS[i], 0);
                            }
                        }
                    }

                    vcAdd = te.getNext();
                }
            }

            // rise and set of the moon
            if (GPDisplays.CoreEvents.Moonrise())
            {
                GPJulianTime julian    = vc.getJulian();
                GPJulianTime julianEnd = vcEnd.getJulian();
                GPJulianTime nextJulian;
                TRiseSet     kind;

                while (julian.getGreenwichJulianDay() < julianEnd.getGreenwichJulianDay())
                {
                    nextJulian = GPAstroEngine.GetNextMoonEvent(julian, vc.getLocationProvider(), out kind);
                    if (kind == TRiseSet.RISE)
                    {
                        inEvents.AddEvent(new GPGregorianTime(loc, nextJulian), GPConstants.CoreEventMoonRise, 0);
                    }
                    else if (kind == TRiseSet.SET)
                    {
                        inEvents.AddEvent(new GPGregorianTime(loc, nextJulian), GPConstants.CoreEventMoonSet, 0);
                    }
                    julian.setGreenwichJulianDay(nextJulian.getGreenwichJulianDay() + 10.0 / 1440.0);
                }
            }

            // travellings
            {
                GPJulianTime julian = vc.getJulian();
                GPJulianTime julianEnd = vcEnd.getJulian();
                double       start, end;

                start = julian.getGreenwichJulianDay();
                end   = julianEnd.getGreenwichJulianDay();

                for (int i = 0; i < loc.getChangeCount(); i++)
                {
                    GPLocationChange chn = loc.getChangeAtIndex(i);
                    if ((chn.julianStart >= start && chn.julianStart <= end) ||
                        (chn.julianStart >= start && chn.julianEnd <= end))
                    {
                        GPGregorianTime startTime = new GPGregorianTime(chn.LocationA);
                        startTime.setJulianGreenwichTime(new GPJulianTime(chn.julianStart, 0));
                        GPGregorianTime endTime = new GPGregorianTime(chn.LocationB);
                        endTime.setJulianGreenwichTime(new GPJulianTime(chn.julianEnd, 0));
                        inEvents.AddEvent(startTime, GPConstants.CCTYPE_TRAVELLING_START, 0);
                        inEvents.AddEvent(endTime, GPConstants.CCTYPE_TRAVELLING_END, 0);
                    }
                }
            }

            // eventual sorting
            inEvents.Sort(GPDisplays.CoreEvents.Sort());
        }
Esempio n. 6
0
        public static int FormatCalendarPlusCorePlain(GPCalendarPlusEventsResults calev, StringBuilder fout)
        {
            GPCalendarResults  daybuff = calev.theCalendar;
            GPCoreEventResults events  = calev.theEvents;

            //List<string> gstr = GPStrings.getSharedStrings().gstr;
            int             k;
            string          str;
            GPGregorianTime date = new GPGregorianTime(daybuff.CurrentLocation);
            GPCalendarDay   pvd;
            GPCalendarDay   prevd;
            GPCalendarDay   nextd;
            int             nPrevMasa  = -1;
            int             nPrevMonth = -1;

            if (events.b_sorted == false)
            {
                events.Sort(true);
            }

            StringBuilder lineA = new StringBuilder();
            StringBuilder lineB = new StringBuilder();


            for (k = 0; k < daybuff.getCount(); k++)
            {
                prevd = daybuff.get(k - 1);
                pvd   = daybuff.get(k);
                nextd = daybuff.get(k + 1);

                if (pvd != null)
                {
                    bool writeHeaders = false;

                    if (nPrevMasa != pvd.astrodata.nMasa && GPDisplays.Calendar.MasaHeader())
                    {
                        str = string.Format("{0} {1}", pvd.getMasaLongName(), ((nPrevMasa == GPMasa.ADHIKA_MASA) ?  GPStrings.getString(109) : ""));
                        fout.AppendLine(GPAppHelper.CenterString(str, 80));
                        fout.AppendLine(GPAppHelper.CenterString(pvd.getGaurabdaYearLongString(), 80));
                        fout.AppendLine(GPAppHelper.CenterString(pvd.date.getLocation().getFullName(), 80));
                        fout.AppendLine(GPAppHelper.CenterString(string.Format("{0}: {1}", GPStrings.getString(12), pvd.date.getLocation().getTimeZone().getFullName()), 80));
                        fout.AppendLine();

                        nPrevMasa    = pvd.astrodata.nMasa;
                        writeHeaders = true;
                    }
                    else if (nPrevMonth != pvd.date.getMonth() && GPDisplays.Calendar.MonthHeader())
                    {
                        fout.AppendLine(GPAppHelper.CenterString(string.Format("{0} {1}", GPStrings.getString(759 + pvd.date.getMonth()), pvd.date.getYear()), 80));
                        fout.AppendLine(GPAppHelper.CenterString(pvd.date.getLocation().getFullName(), 80));
                        fout.AppendLine(GPAppHelper.CenterString(string.Format("{0}: {1}", GPStrings.getString(12), pvd.date.getLocation().getTimeZone().getFullName()), 80));
                        fout.AppendLine();

                        nPrevMonth   = pvd.date.getMonth();
                        writeHeaders = true;
                    }


                    if (writeHeaders)
                    {
                        int len = fout.Length;

                        fout.Append(" ");
                        fout.Append(GPStrings.getString(985).PadRight(16));
                        fout.Append(GPStrings.getString(986).ToUpper().PadRight(30));
                        if (GPDisplays.Calendar.PaksaInfoVisible())
                        {
                            fout.Append(GPStrings.getString(20).ToUpper().PadRight(6));
                        }
                        else
                        {
                            fout.Append(string.Empty.PadRight(6));
                        }
                        if (GPDisplays.Calendar.YogaVisible())
                        {
                            fout.Append(GPStrings.getString(104).ToUpper().PadRight(10));
                        }
                        if (GPDisplays.Calendar.NaksatraVisible())
                        {
                            fout.Append(GPStrings.getString(15).ToUpper().PadRight(15));
                        }
                        if (GPDisplays.Calendar.FastingFlagVisible())
                        {
                            fout.Append(GPStrings.getString(987).ToUpper().PadRight(5));
                        }
                        if (GPDisplays.Calendar.RasiVisible())
                        {
                            fout.Append(GPStrings.getString(105).ToUpper().PadRight(15));
                        }

                        fout.AppendLine();
                        len = fout.Length - len;
                        fout.AppendLine(string.Empty.PadLeft(len, '-'));
                    }

                    AvcGetOldCalendarDayText(pvd, fout, prevd, nextd);

                    fout.AppendLine();
                    lineA.Remove(0, lineA.Length);
                    lineB.Remove(0, lineB.Length);
                    List <GPStringPair> recs = events.ExtractRecordsForDate(pvd.date);
                    foreach (GPStringPair rec in recs)
                    {
                        lineA.Append(rec.Name);
                        lineB.Append(rec.Value);
                        int tosize = Math.Max(lineA.Length, lineB.Length) + 2;
                        while (lineA.Length < tosize)
                        {
                            lineA.Append(' ');
                        }
                        while (lineB.Length < tosize)
                        {
                            lineB.Append(' ');
                        }
                    }
                    fout.Append(string.Empty.PadLeft(17, ' '));
                    fout.AppendLine(lineA.ToString());
                    fout.Append(string.Empty.PadLeft(17, ' '));
                    fout.AppendLine(lineB.ToString());
                    fout.AppendLine();
                }
                date.setDayHours(0.0);
                date.NextDay();
            }

            return(1);
        }