Esempio n. 1
0
        public static GPLocationProvider getMyLocation()
        {
            if (myLocation == null)
            {
                myLocation = new GPLocationProvider();
                bool   bSucc        = false;
                string possibleFile = GPFileHelper.getAppDataFile("mylocation.xml");
                if (File.Exists(possibleFile))
                {
                    try
                    {
                        myLocation.loadXml(possibleFile);
                        bSucc = true;
                    }
                    catch
                    {
                    }
                }

                if (bSucc == false)
                {
                    NumberFormatInfo fmt = new NumberFormatInfo();
                    GPLocation       loc = new GPLocation();
                    loc.setCity(GPUserDefaults.StringForKey("myloc.city", "Mayapur"));
                    loc.setCountryCode(GPUserDefaults.StringForKey("myloc.country", "IN"));
                    loc.setLatitudeNorthPositive(double.Parse(GPUserDefaults.StringForKey("myloc.lat", "23.423413"), fmt));
                    loc.setLongitudeEastPositive(double.Parse(GPUserDefaults.StringForKey("myloc.lon", "88.388079"), fmt));
                    loc.setTimeZoneName(GPUserDefaults.StringForKey("myloc.tzname", "Asia/Calcutta"));
                    myLocation.setDefaultLocation(loc);
                }
            }

            return(myLocation);
        }
Esempio n. 2
0
        public int GetArg_Date(string str, out GPGregorianTime vc)
        {
            vc = new GPGregorianTime(GPLocation.getEmptyLocation());
            string[] parts = str.Replace('/', '-').Split('-');
            if (parts.Length < 3)
            {
                return(1);
            }
            int day, month, year;

            int.TryParse(parts[0], out day);
            if (day == 0)
            {
                day = 1;
            }
            int.TryParse(parts[1], out month);
            if (month == 0)
            {
                month = 1;
            }
            int.TryParse(parts[2], out year);

            vc.setDate(year, month, day);
            return(0);
        }
Esempio n. 3
0
        /// <summary>
        /// Recalculation of sunrise time for given travelling
        /// </summary>
        /// <param name="sun"></param>
        /// <param name="locChange"></param>
        private static void recalculateSunriseTravel(GPSun sun, GPLocationChange locChange)
        {
            GPSun  newSun = new GPSun();
            double drStep = 0.5;
            double dr     = 0.0;
            int    steps  = 0;

            while (steps < 25)
            {
                GPLocation      lp = locChange.getTravellingLocation(dr);
                double          jd = locChange.julianStart + (locChange.julianEnd - locChange.julianStart) * dr;
                GPGregorianTime gt = new GPGregorianTime(lp);
                gt.setJulianGreenwichTime(jd);
                GPLocationProvider lpr = new GPLocationProvider(lp);
                newSun.calculateRise(sun.rise, lpr);
                newSun.updateSunriseTimes(sun.rise, lpr);

                if (gt.getJulianGreenwichTime() > newSun.rise.getJulianGreenwichTime())
                {
                    drStep = drStep / 2;
                    dr    -= drStep;
                }
                else
                {
                    dr += drStep;
                }

                steps++;
            }

            sun.rise                = newSun.rise;
            sun.sunrise_deg         = newSun.sunrise_deg;
            sun.eclipticalLongitude = newSun.eclipticalLongitude;
        }
Esempio n. 4
0
        public bool readXmlNode(XmlElement elem)
        {
            changes = new List <GPLocationChange>();
            bool succ = false;

            foreach (XmlElement e1 in elem.ChildNodes)
            {
                if (e1.Name.Equals("Change"))
                {
                    GPLocationChange chng = new GPLocationChange();
                    chng.loadFromXmlNode(e1);
                    changes.Add(chng);
                }
                else if (e1.Name.Equals("DefaultLocation"))
                {
                    defaultLocation = new GPLocation();
                    defaultLocation.loadFromXmlNode(e1);
                    succ = true;

                    if (e1.HasAttribute("type"))
                    {
                        int i = TYPE_SELECTED;
                        if (int.TryParse(e1.GetAttribute("type"), out i))
                        {
                            this.setType(i);
                        }
                    }
                }
            }

            return(succ);
        }
Esempio n. 5
0
 private void addLocationToList(GPLocation lc, List <GPLocation> list)
 {
     if (list.IndexOf(lc) < 0)
     {
         list.Add(lc);
     }
 }
Esempio n. 6
0
        public int GetArg_Time(string str, out GPGregorianTime vc)
        {
            vc = new GPGregorianTime(GPLocation.getEmptyLocation());
            double l          = 0.0;
            double coma       = 10.0;
            bool   after_coma = false;
            bool   is_deg     = false;

            string s = str;

            foreach (char ch in str)
            {
                switch (ch)
                {
                case '0':
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                    if (after_coma)
                    {
                        if (is_deg)
                        {
                            l += (ch - '0') * 5.0 / (coma * 3.0);
                        }
                        else
                        {
                            l += (ch - '0') / coma;
                        }
                        coma *= 10.0;
                    }
                    else
                    {
                        l = l * 10.0 + (ch - '0');
                    }
                    break;

                case ':':
                    after_coma = true;
                    is_deg     = true;
                    break;

                default:
                    return(SetArgLastError(14));
                }
            }

            vc.setDayHours(l / 24.0);

            return(0);
        }
Esempio n. 7
0
 public GPLocation(GPLocation loc)
 {
     _id  = loc.getId();
     city = loc.city;
     setLatitudeNorthPositive(loc.GetLatitudeNorthPositive());
     setLongitudeEastPositive(loc.GetLongitudeEastPositive());
     countryCode  = loc.countryCode;
     timezoneName = loc.timezoneName;
     timezone     = loc.timezone;
 }
Esempio n. 8
0
        public bool GetNaksatraTimeRange(GPLocation earth, out GPGregorianTime from, out GPGregorianTime to)
        {
            GPGregorianTime start = new GPGregorianTime(date);

            start.setDayHours(astrodata.sun.getSunriseDayHours());

            GPNaksatra.GetNextNaksatra(start, out to);
            GPNaksatra.GetPrevNaksatra(start, out from);

            return(true);
        }
Esempio n. 9
0
 public override void InsertNewObjectFromStrings(string[] parts, FileKey fk)
 {
     if (parts.Length >= 5 && parts[0].Length > 0)
     {
         NumberFormatInfo fmt      = new NumberFormatInfo();
         GPLocation       location = new GPLocation();
         location.setCity(parts[0]);
         location.setLatitudeNorthPositive(double.Parse(parts[1], fmt));
         location.setLongitudeEastPositive(double.Parse(parts[2], fmt));
         location.setCountryCode(parts[3]);
         location.setTimeZoneName(parts[4]);
         locations.Add(location);
     }
 }
Esempio n. 10
0
 /// <summary>
 /// Bias of DST time in seconds (s)
 /// </summary>
 public int getDaylightTimeBias()
 {
     if (!dstValid)
     {
         GPLocation loc = getLocation();
         if (loc != null && loc.getTimeZone() != null)
         {
             p_dst_bias = loc.getTimeZone().BiasSecondsForDate(this);
             p_dst_on   = (p_dst_bias > 0);
         }
         dstValid = true;
     }
     return(p_dst_bias);
 }
Esempio n. 11
0
        /// <summary>
        /// Creates GPLocationProvider object from given data.
        /// </summary>
        /// <param name="city">Any string</param>
        /// <param name="longitude">Unit is degrees. Positive values are to the east, negative values are to the west.</param>
        /// <param name="latitude">Unit is degrees. Positive values are for the north hemisphere, negative values are for south hemisphere.</param>
        /// <param name="timeZoneName">Name of timezone. This is one of the values returned by function GPTimeZoneList.sharedTimeZones().getTimeZones()</param>
        /// <returns></returns>
        public static GPLocationProvider EncapsulateLocation(string city, double longitude, double latitude, string timeZoneName)
        {
            GPLocation loca = new GPLocation();

            loca.setCity(city);
            loca.setLongitudeEastPositive(longitude);
            loca.setLatitudeNorthPositive(latitude);
            loca.setTimeZoneName(timeZoneName);

            GPLocationProvider locProv = new GPLocationProvider();

            locProv.setDefaultLocation(loca);

            return(locProv);
        }
Esempio n. 12
0
 public void setLocationAtIndex(int i, GPLocation loc)
 {
     if (changes.Count == 0)
     {
         setDefaultLocation(loc);
     }
     if (i < changes.Count)
     {
         changes[i].LocationA = loc;
     }
     if (i > 0)
     {
         changes[i - 1].LocationB = loc;
     }
 }
Esempio n. 13
0
 public bool getDaylightTimeON()
 {
     normalizeValues();
     if (!dstValid)
     {
         GPLocation loc = getLocation();
         if (loc != null && loc.getTimeZone() != null)
         {
             p_dst_bias = loc.getTimeZone().BiasSecondsForDate(this);
             p_dst_on   = (p_dst_bias > 0);
         }
         dstValid = true;
     }
     return(p_dst_on);
 }
Esempio n. 14
0
        public double getTimeZoneOffsetHours()
        {
            GPLocation loc = getLocation();

            if (loc == null)
            {
                return(0);
            }
            GPTimeZone tz = loc.getTimeZone();

            if (tz == null)
            {
                return(0);
            }
            return(tz.OffsetSeconds / 3600.0);
        }
Esempio n. 15
0
        private void calculateRiseSetMethodM(double D, GPLocationProvider ed)
        {
            GPLocation obs = ed.getLocation(D);
            double     a1, a2, a3;
            double     d1, d2, d3;
            double     siderealTime = GPAstroEngine.GetSiderealTime(D);
            double     h0           = -0.833333;

            calculateCoordinatesMethodM(D - 1);
            a1 = rightAscession;
            d1 = declination;
            calculateCoordinatesMethodM(D);
            a2 = rightAscession;
            d2 = declination;
            calculateCoordinatesMethodM(D + 1);
            a3 = rightAscession;
            d3 = declination;
            double longitude = -ed.GetLongitudeEastPositive();
            double latitude  = ed.GetLatitudeNorthPositive();
            double cosH0     = (GPMath.sinDeg(h0) - GPMath.sinDeg(latitude) * GPMath.sinDeg(d2))
                               / (GPMath.cosDeg(latitude) * GPMath.cosDeg(d2));
            double H0 = GPMath.arccosDeg(cosH0);

            H0 = GPMath.putIn180(H0);

            double m0     = (a2 + longitude - siderealTime) / 360;
            double m1     = m0 - H0 / 360;
            double m2     = m0 + H0 / 360;
            double deltaM = 0;

            deltaM = getCorrection(D, a1, a2, a3, d1, d2, d3, siderealTime, h0, longitude, latitude, m0, true);
            m0    += deltaM;
            deltaM = getCorrection(D, a1, a2, a3, d1, d2, d3, siderealTime, h0, longitude, latitude, m1, false);
            m1    += deltaM;
            deltaM = getCorrection(D, a1, a2, a3, d1, d2, d3, siderealTime, h0, longitude, latitude, m2, false);
            m2    += deltaM;

            julianDayRise = julianDay + m1;
            julianDayNoon = julianDay + m0;
            julianDaySet  = julianDay + m2;

            sunrise_deg = GPMath.putIn360(m1 * 360);
            noon_deg    = GPMath.putIn360(m0 * 360);
            sunset_deg  = GPMath.putIn360(m2 * 360);
        }
Esempio n. 16
0
        public static void TestMoonEvents()
        {
            TRiseSet     kind;
            GPJulianTime dp = new GPJulianTime();

            dp.setLocalJulianDay(defJulian);
            GPLocation obs = new GPLocation();

            obs.setLatitudeNorthPositive(defLatitude).setLongitudeEastPositive(defLongitude).SetAltitude(0.2);
            GPLocationProvider prov = new GPLocationProvider(obs);

            for (int k = 0; k < 26; k++)
            {
                dp = GPAstroEngine.GetNextMoonEvent(dp, prov, out kind);
                Log("next event = {0}, {1}\n", dp, kind);
                dp.AddHours(1);
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Gets location based on given julian day
        /// </summary>
        /// <param name="julianDay"></param>
        /// <returns></returns>
        public GPLocation getLocation(double julianDay)
        {
            if (changes.Count < 1)
            {
                return(defaultLocation);
            }
            double lastStart = 0;

            foreach (GPLocationChange lch in changes)
            {
                if (lch.julianStart > julianDay)
                {
                    currStart       = lastStart;
                    currEnd         = lch.julianStart;
                    currentLocation = lch.LocationA;
                    currentChange   = null;
                    return(currentLocation);
                }

                if (lch.julianStart <= julianDay && lch.julianEnd >= julianDay)
                {
                    currStart       = lch.julianStart;
                    currEnd         = lch.julianEnd;
                    currentLocation = null;
                    currentChange   = lch;
                    GPLocation lp = currentChange.getLocation(julianDay);
                    return(lp);
                }

                lastStart = lch.julianEnd;
            }

            int last = changes.Count - 1;

            if (changes[last].julianEnd < julianDay)
            {
                currStart       = changes[last].julianEnd;
                currEnd         = currStart + 2000000;
                currentLocation = changes[last].LocationB;
                return(currentLocation);
            }

            return(defaultLocation);
        }
Esempio n. 18
0
        public GPLocation getTravellingLocation(double ratio)
        {
            double lonA, lonB;
            double latA, latB;

            lonA = LocationA.GetLongitudeEastPositive();
            lonB = LocationB.GetLongitudeEastPositive();
            latA = LocationA.GetLatitudeNorthPositive();
            latB = LocationB.GetLatitudeNorthPositive();

            GPLocation newLoc = new GPLocation();

            newLoc.setTimeZone(TimezoneStart ? LocationA.getTimeZone() : LocationB.getTimeZone());
            newLoc.setLongitudeEastPositive(lonA + (lonB - lonA) * ratio);
            newLoc.setLatitudeNorthPositive(latA + (latB - latA) * ratio);
            newLoc.SetAltitude(0);

            return(newLoc);
        }
Esempio n. 19
0
 public void loadFromXmlNode(XmlElement elem)
 {
     foreach (XmlElement e1 in elem.ChildNodes)
     {
         if (e1.Name.Equals("LocationA"))
         {
             LocationA = new GPLocation();
             LocationA.loadFromXmlNode(e1);
         }
         else if (e1.Name.Equals("LocationB"))
         {
             LocationB = new GPLocation();
             LocationB.loadFromXmlNode(e1);
         }
         else if (e1.Name.Equals("Time"))
         {
             bool   b;
             double d;
             if (e1.HasAttribute("TzStart"))
             {
                 b = true;
                 bool.TryParse(e1.GetAttribute("TzStart"), out b);
                 TimezoneStart = b;
             }
             if (e1.HasAttribute("JuStart"))
             {
                 double.TryParse(e1.GetAttribute("JuStart"), out d);
                 julianStart = d;
             }
             if (e1.HasAttribute("JuEnd"))
             {
                 double.TryParse(e1.GetAttribute("JuEnd"), out d);
                 julianEnd = d;
             }
         }
     }
 }
Esempio n. 20
0
        /// <summary>
        /// recalculation of arunodaya time for given travelling
        /// </summary>
        /// <param name="sun"></param>
        /// <param name="locChange"></param>
        private static void recalculateArunodayaTravel(GPSun sun, GPLocationChange locChange)
        {
            GPSun  newSun = new GPSun();
            double drStep = 0.5;
            double dr     = 0.0;
            int    steps  = 0;

            while (steps < 25)
            {
                GPLocation      lp = locChange.getTravellingLocation(dr);
                double          jd = locChange.julianStart + (locChange.julianEnd - locChange.julianStart) * dr;
                GPGregorianTime gt = new GPGregorianTime(lp);
                gt.setJulianGreenwichTime(jd);
                GPLocationProvider lpr = new GPLocationProvider(lp);
                newSun.calculateRise(sun.rise, lpr);
                newSun.updateSunriseTimes(sun.rise, lpr);
                //                    Debugger.Log(0, "", String.Format("ROW: {0} {1}   {2}  {3}\n", lp.getLongitudeString(), lp.getLatitudeString(),
                //                        newSun.rise.getLongTimeString(), gt.getLongTimeString()));

                if (gt.getJulianGreenwichTime() > newSun.arunodaya.getJulianGreenwichTime())
                {
                    drStep = drStep / 2;
                    dr    -= drStep;
                }
                else
                {
                    dr += drStep;
                }

                steps++;
            }

            sun.arunodaya          = newSun.arunodaya;
            sun.arunodaya_deg      = newSun.arunodaya_deg;
            sun.longitude_arun_deg = newSun.longitude_arun_deg;
        }
Esempio n. 21
0
 public GPGregorianTime(GPLocation loc, GPJulianTime julianTime)
 {
     setLocation(loc);
     setJulianGreenwichTime(julianTime);
 }
Esempio n. 22
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. 23
0
        public static int FormatCalendarICAL(GPCalendarResults daybuff, StringBuilder m_text)
        {
            int             k;
            int             initialLength = 0;
            int             lastmasa = -1;
            int             tzoffset = 0, tzoff;
            string          str, str2;
            StringBuilder   dayText = new StringBuilder();
            GPCalendarDay   pvd, prevd, nextd;
            string          SPACE_BEFORE_LINE = " , ";
            GPGregorianTime vc  = new GPGregorianTime(daybuff.m_vcStart);
            GPLocation      loc = daybuff.CurrentLocation.getLocation(0);

            DateTime st = new DateTime();

            m_text.Remove(0, m_text.Length);
            m_text.Append("BEGIN:VCALENDAR\nVERSION:2.0\nX-WR-CALNAME:VAISNAVA\nPRODID:-//GBC Calendar Comitee//GCAL//EN\n");
            m_text.Append("X-WR-RELCALID:");
            str2 = string.Format("{0:00000000}-{1:0000}-{2:0000}-{3:0000}-{4:0000}{5:00000000}", st.Year + st.Millisecond, st.Day, st.Month,
                                 st.Hour, st.Minute + st.Millisecond);
            m_text.Append(str2);
            m_text.Append("\nX-WR-TIMEZONE:");

            m_text.Append(loc.getTimeZoneName());
            m_text.Append("\n");

            m_text.Append("CALSCALE:GREGORIAN\nMETHOD:PUBLISH\n");
            m_text.Append("BEGIN:VTIMEZONE\nTZID:");
            m_text.Append(loc.getTimeZoneName());
            str2 = string.Format("\nLAST-MODIFIED:{0:0000}{1:00}{2:00}T{3:00}{4:00}{5:00}Z", st.Year, st.Month, st.Day, st.Hour, st.Minute, st.Second);
            m_text.Append(str2);

            tzoffset = Convert.ToInt32(loc.getTimeZone().OffsetSeconds / 60);
            tzoff    = Convert.ToInt32(loc.getTimeZone().getMaximumOffsetSeconds() / 60);

            if (loc.getTimeZone().hasDstInYear(st.Year))
            {
                DateTime dta = loc.getTimeZone().StartDateInYear(st.Year);
                str2 = string.Format("\nBEGIN:DAYLIGHT\nDTSTART:{0:0000}{1:00}{2:00}T{3:00}0000", dta.Year, dta.Month, dta.Day, dta.Hour);
                m_text.Append(str2);

                str2 = string.Format("\nTZOFFSETTO:{0}{1:00}{2:00}", (tzoff > 0 ? '+' : '-'), Math.Abs(tzoff) / 60, Math.Abs(tzoff) % 60);
                m_text.Append(str2);

                str2 = string.Format("\nTZOFFSETFROM:{0}{1:00}{2:00}", '+', 0, 0);
                m_text.Append(str2);

                dta = loc.getTimeZone().EndDateInYear(st.Year);
                m_text.Append("\nEND:DAYLIGHT\nBEGIN:STANDARD\nDTSTART:");
                str2 = string.Format("{0:0000}{1:00}{2:00}T{3:00}0000", dta.Year, dta.Month, dta.Day, dta.Hour);
                m_text.Append(str2);

                str2 = string.Format("\nTZOFFSETTO:{0}{1:00}{2:00}", (tzoffset > 0 ? '+' : '-'), Math.Abs(tzoffset) / 60, Math.Abs(tzoffset) % 60);
                m_text.Append(str2);
                str2 = string.Format("\nTZOFFSETFROM:{0}{1:00}{2:00}", (tzoff > 0 ? '+' : '-'), Math.Abs(tzoff) / 60, Math.Abs(tzoff) % 60);
                m_text.Append(str2);
                m_text.Append("\nEND:STANDARD\n");
            }
            else
            {
                m_text.Append("\nBEGIN:STANDARD\nDTSTART:");
                str2 = string.Format("{0:0000}0101T000000", vc.getYear(), vc.getMonth(), vc.getDay(), vc.getHour());
                m_text.Append(str2);

                str2 = string.Format("\nTZOFFSETTO:%+02d{0:00}", Math.Abs(tzoffset) / 60, Math.Abs(tzoffset) % 60);
                m_text.Append(str2);
                str2 = string.Format("\nTZOFFSETFROM:+0000");
                m_text.Append(str2);
                m_text.Append("\nEND:STANDARD\n");
            }

            m_text.Append("END:VTIMEZONE\n");

            for (k = 0; k < daybuff.m_PureCount; k++)
            {
                //		date.shour = 0.0;
                //		date.TimeZone = earth.tzone;

                prevd = daybuff.get(k - 1);
                pvd   = daybuff.get(k);
                nextd = daybuff.get(k + 1);

                if (pvd != null)
                {
                    dayText.Remove(0, dayText.Length);

                    if (pvd.astrodata.nMasa != lastmasa)
                    {
                        str = string.Format("{0} {1}, Gaurabda {2}", GPMasa.GetName(pvd.astrodata.nMasa), getSharedStringHtml(22), pvd.astrodata.nGaurabdaYear);
                        dayText.Append(str);
                        dayText.Append("\n");
                        if ((pvd.astrodata.nMasa == GPMasa.ADHIKA_MASA) && ((lastmasa >= GPMasa.SRIDHARA_MASA) && (lastmasa <= GPMasa.DAMODARA_MASA)))
                        {
                            if (dayText.Length > 0)
                            {
                                dayText.Append(SPACE_BEFORE_LINE);
                            }
                            dayText.Append(getSharedStringHtml(128));
                            dayText.Append("\n");
                        }

                        lastmasa      = pvd.astrodata.nMasa;
                        initialLength = -1;
                    }
                    else
                    {
                        initialLength = 0;
                    }

                    if (dayText.Length > 0)
                    {
                        dayText.Append(SPACE_BEFORE_LINE);
                    }
                    dayText.Append(GPTithi.getName(pvd.astrodata.nTithi));

                    if ((pvd.astrodata.nTithi == 10) || (pvd.astrodata.nTithi == 25) || (pvd.astrodata.nTithi == 11) || (pvd.astrodata.nTithi == 26))
                    {
                        if (pvd.hasEkadasiParana() == false)
                        {
                            dayText.Append(" ");
                            if (pvd.nMahadvadasiType == GPConstants.EV_NULL)
                            {
                                dayText.Append(getSharedStringHtml(58));
                            }
                            else
                            {
                                dayText.Append(getSharedStringHtml(59));
                            }
                        }
                    }
                    dayText.Append("\n");
                    initialLength += dayText.Length;

                    if (pvd.astrodata.sun.eclipticalLongitude < 0.0)
                    {
                        goto _resolve_text;
                    }

                    //			if (0 != GetShowSetVal(17) == 1)
                    {
                        //				double h1, m1;
                        if (pvd.hasEkadasiParana())
                        {
                            str = pvd.getEkadasiParanaString();

                            dayText.Append(SPACE_BEFORE_LINE);
                            dayText.Append(str);
                            dayText.Append("\n");
                        }
                    }

                    //			if (0 != GetShowSetVal(6) == 1)
                    {
                        foreach (GPCalendarDay.Festival fest in pvd.Festivals)
                        {
                            if (GPUserDefaults.BoolForKey(fest.ShowSettingItem, true))
                            {
                                dayText.Append(SPACE_BEFORE_LINE);
                                dayText.Append(fest.Text);
                                dayText.Append("\n");
                            }
                        }
                    }

                    if (/*GetShowSetVal(16) == 1 &&*/ pvd.sankranti_zodiac >= 0)
                    {
                        str = string.Format(" {0} {1}", GPSankranti.getName(pvd.sankranti_zodiac), getSharedStringHtml(56));
                        dayText.Append(SPACE_BEFORE_LINE);
                        dayText.Append(str);
                        dayText.Append("\n");
                    }



                    //"Sunrise Time",//2
                    //"Sunset Time",//3
                    if (GPDisplays.Calendar.TimeSunriseVisible())
                    {
                        str = string.Format("{0} {1}", getSharedStringHtml(51), pvd.astrodata.sun.rise.getShortTimeString());
                        dayText.Append(SPACE_BEFORE_LINE);
                        dayText.Append(str);
                        dayText.Append("\n");
                    }
                    if (GPDisplays.Calendar.TimeSunsetVisible())
                    {
                        str = string.Format("{0} {1}", getSharedStringHtml(52), pvd.astrodata.sun.set.getShortTimeString());
                        dayText.Append(SPACE_BEFORE_LINE);
                        dayText.Append(str);
                        dayText.Append("\n");
                    }

                    {
                        if (prevd != null)
                        {
                            if (prevd.astrodata.nMasa != pvd.astrodata.nMasa)
                            {
                                str = string.Format("{0} {1} {2}", getSharedStringHtml(780), GPMasa.GetName(pvd.astrodata.nMasa), getSharedStringHtml(22));
                                dayText.Append(SPACE_BEFORE_LINE);
                                dayText.Append(str);
                                dayText.Append("\n");
                            }
                        }
                        if (nextd != null)
                        {
                            if (nextd.astrodata.nMasa != pvd.astrodata.nMasa)
                            {
                                str = string.Format("{0} {1} {2}", getSharedStringHtml(781), GPMasa.GetName(pvd.astrodata.nMasa), getSharedStringHtml(22));
                                dayText.Append(SPACE_BEFORE_LINE);
                                dayText.Append(str);
                                dayText.Append("\n");
                            }
                        }
                    }

_resolve_text:
                    if (dayText.Length > initialLength)
                    {
                        m_text.Append("BEGIN:VEVENT\n");
                        str2 = string.Format("DTSTART;VALUE=DATE:{0:0000}{1:00}{2:00}\n", pvd.date.getYear(), pvd.date.getMonth(), pvd.date.getDay());
                        m_text.Append(str2);

                        /*str2 = string.Format("DTEND;VALUE=DATE:{0:0000}{0:00}{0:00}T{0:00}{0:00}{0:00}\n", pvd.date.year, pvd.date.month, pvd.date.day,
                         *  pvd.astrodata.sun.set.hour, pvd.astrodata.sun.set.min, pvd.astrodata.sun.set.sec);
                         * m_text.Append(str2);*/
                        str2 = string.Format("LOCATION:{0}\n", loc.getFullName());
                        str2.Replace(",", "\\,");
                        m_text.Append(str2);
                        m_text.Append("SUMMARY:");
                        dayText.Replace(",", "\\,");
                        m_text.Append(dayText.ToString().TrimStart());
                        str2 = string.Format("UID:{0:00000000}-{1:0000}-{2:0000}-{3:0000}-{4:00000000}{5:0000}\n", st.Year, st.Month * 30 + st.Day, st.Hour * 60 + st.Minute, st.Second, st.Millisecond, k);
                        m_text.Append(str2);
                        m_text.Append("DURATION:P1D\nSEQUENCE:1\nEND:VEVENT\n");
                    }
                }
            }

            m_text.Append("END:VCALENDAR\n");
            return(1);
        }
Esempio n. 24
0
 public GPLocationProvider(GPLocation loc)
 {
     defaultLocation = loc;
 }
Esempio n. 25
0
 public void setLocation(GPLocation value)
 {
     p_locationProvider = new GPLocationProvider();
     p_locationProvider.setDefaultLocation(value);
 }
Esempio n. 26
0
        /// <summary>
        /// Main function of this class
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public bool ParseCommandArguments(string[] args)
        {
            GPLocationProvider loc = new GPLocationProvider();
            GPLocation         loc1 = new GPLocation();
            GPGregorianTime    vcStart = new GPGregorianTime(loc), vcEnd = new GPGregorianTime(loc);
            GPVedicTime        vaStart = new GPVedicTime(), vaEnd = new GPVedicTime();
            int    nCount;
            int    nReq = 0;
            string strFileOut = "";

            try
            {
                loc1.setLatitudeNorthPositive(0.0);
                loc1.setLongitudeEastPositive(0.0);
                loc1.setTimeZoneName("");
                loc.setDefaultLocation(loc1);
                vcStart.Clear();
                vcEnd         = vcStart;
                vaStart.tithi = vaStart.masa = vaStart.gyear = 0;
                vaEnd         = vaStart;
                nCount        = -1;

                int argc = args.Length;
                for (int i = 0; i < argc; i++)
                {
                    //TRACE2("arg %d = %s\n", i, args[i]);
                    if (args[i] == "-L")
                    {
                        if (argc >= i + 2)
                        {
                            loc1.setLongitudeString(args[i + 1]);
                            double lat   = 0.0;
                            double longi = 0.0;
                            GetArg_EarthPos(args[i + 1], ref lat, ref longi);
                            loc1.setLongitudeEastPositive(longi);
                            loc1.setLatitudeNorthPositive(lat);
                            //TRACE2("-L latitude=%f longitude=%f\n", loc.m_fLatitude, loc.m_fLongitude);
                        }
                        i++;
                    }
                    else if (args[i] == "-N")
                    {
                        if (argc >= i + 2)
                        {
                            loc1.setCity(args[i + 1]);
                            //TRACE1("-N name=%s\n", loc.m_strName);
                        }
                        i++;
                    }
                    else if (args[i] == "-SV")
                    {
                        if (argc >= i + 2)
                        {
                            GetArg_VaisnDate(args[i + 1], out vaStart);
                        }
                        i++;
                    }
                    else if (args[i] == "-SG")
                    {
                        if (argc >= i + 2)
                        {
                            GetArg_Date(args[i + 1], out vcStart);
                        }
                        i++;
                    }
                    else if (args[i] == "-ST")
                    {
                        if (argc >= i + 2)
                        {
                            GetArg_Time(args[i + 1], out vcStart);
                        }
                        i++;
                    }
                    else if (args[i] == "-EG")
                    {
                        if (argc >= i + 2)
                        {
                            GetArg_Date(args[i + 1], out vcEnd);
                            //AfxTrace("-EG day=%d month=%d year=%d\n", vcEnd.day, vcEnd.month, vcEnd.year);
                        }
                        i++;
                    }
                    else if (args[i] == "-EV")
                    {
                        if (argc >= i + 2)
                        {
                            GetArg_VaisnDate(args[i + 1], out vaEnd);
                            //AfxTrace("-EV tithi=%d masa=%d gyear=%d\n", vaEnd.tithi, vaEnd.masa, vaEnd.gyear);
                        }
                        i++;
                    }
                    else if (args[i] == "-EC")
                    {
                        if (argc >= i + 2)
                        {
                            int.TryParse(args[i + 1], out nCount);
                        }
                        i++;
                    }
                    else if (args[i] == "-TZ")
                    {
                        if (argc >= i + 2)
                        {
                            loc1.setTimeZoneName(args[i + 1]);
                        }
                        i++;
                    }
                    else if (args[i] == "-O")
                    {
                        if (argc >= i + 2)
                        {
                            strFileOut = args[i + 1];
                        }
                        i++;
                    }
                    else if (args[i] == "-R")
                    {
                        if (argc >= i + 2)
                        {
                            if (args[i + 1] == "calendar")
                            {
                                nReq = 10;
                            }
                            else if (args[i + 1] == "appday")
                            {
                                nReq = 11;
                            }
                            else if (args[i + 1] == "tithi")
                            {
                                nReq = 12;
                            }
                            else if (args[i + 1] == "sankranti")
                            {
                                nReq = 13;
                            }
                            else if (args[i + 1] == "naksatra")
                            {
                                nReq = 14;
                            }
                            else if (args[i + 1] == "firstday")
                            {
                                nReq = 15;
                            }
                            else if (args[i + 1] == "gcalendar")
                            {
                                nReq = 16;
                            }
                            else if (args[i + 1] == "gtithi")
                            {
                                nReq = 17;
                            }
                            else if (args[i + 1] == "next")
                            {
                                nReq = 18;
                            }
                            else if (args[i + 1] == "help")
                            {
                                nReq = 60;
                            }

                            /*else if (args[i+1] == "")
                             * {
                             * } else if (args[i+1] == "")
                             * {
                             * } else if (args[i+1] == "")
                             * {
                             * } else if (args[i+1] == "")
                             * {
                             * }*/
                        }
                        i++;
                    }
                }

                vcStart.setLocationProvider(loc);
                vcEnd.setLocationProvider(loc);

                switch (nReq)
                {
                case 10:
                case 13:
                case 14:
                    if (vcStart.getYear() == 0 && vaStart.gyear != 0)
                    {
                        GPEngine.VATIMEtoVCTIME(vaStart, out vcStart, loc);
                    }
                    if (vcEnd.getYear() == 0 && vaEnd.gyear != 0)
                    {
                        GPEngine.VATIMEtoVCTIME(vaEnd, out vcEnd, loc);
                    }
                    break;

                default:
                    break;
                }

                if (vcStart.getYear() != 0 && vcEnd.getYear() != 0 && nCount < 0)
                {
                    nCount = Convert.ToInt32(vcEnd.getJulianLocalNoon() - vcStart.getJulianLocalNoon());
                }

                if (nCount < 0)
                {
                    nCount = 30;
                }

                GPAppDayResults   appday   = new GPAppDayResults();
                GPCalendarResults calendar = new GPCalendarResults();
                //AfxTrace("Count === %d\n", nCount);

                StringBuilder fout = new StringBuilder();
                switch (nReq)
                {
                case 10:
                    // -R -O -LAT -LON -SG -C [-DST -NAME]
                    vcStart.NextDay();
                    vcStart.PreviousDay();
                    calendar.CalculateCalendar(vcStart, nCount);
                    FormaterXml.WriteXml(FormaterXml.GetCalendarXmlDocument(calendar), fout);
                    break;

                case 11:
                    // -R -O -LAT -LON -SG -ST [-NAME]
                    appday.calculateAppearanceDayData(loc, vcStart);
                    FormaterXml.FormatAppDayXML(appday, fout);
                    break;

                case 12:
                    FormaterXml.WriteXML_Tithi(fout, loc, vcStart);
                    break;

                case 13:
                    if (vcEnd.getYear() == 0)
                    {
                        vcEnd = vcStart;
                        vcEnd.AddDays(nCount);
                    }
                    FormaterXml.WriteXml(FormaterXml.GetSankrantiXml(loc, vcStart, vcEnd), fout);
                    break;

                case 14:
                    FormaterXml.WriteXML_Naksatra(fout, loc, vcStart, nCount);
                    break;

                case 15:
                    FormaterXml.WriteXML_FirstDay_Year(fout, vcStart);
                    break;

                case 16:
                    vcStart = GPGaurabdaYear.getFirstDayOfYear(loc, vcStart.getYear());
                    vcEnd   = GPGaurabdaYear.getFirstDayOfYear(loc, vcStart.getYear() + 1);
                    nCount  = Convert.ToInt32(vcEnd.getJulianLocalNoon() - vcStart.getJulianLocalNoon());
                    calendar.CalculateCalendar(vcStart, nCount);
                    FormaterXml.WriteXml(FormaterXml.GetCalendarXmlDocument(calendar), fout);
                    break;

                case 17:
                    FormaterXml.WriteXML_GaurabdaTithi(fout, loc, vaStart, vaEnd);
                    break;

                case 18:
                    FormaterXml.WriteXML_GaurabdaNextTithi(fout, loc, vcStart, vaStart);
                    break;
                }
                // application should be windowless
                // since some parameters are present

                File.WriteAllText(strFileOut, fout.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception during execution: " + ex.Message);
            }

            return(true);
        }
Esempio n. 27
0
 public GPGregorianTime(GPLocation loc)
 {
     setLocation(loc);
     Today();
     setDayHours(0.0);
 }
Esempio n. 28
0
 public void setDefaultLocation(GPLocation def)
 {
     defaultLocation = def;
 }
Esempio n. 29
0
 public bool Equals(GPLocation loc)
 {
     return(loc.getCity().Equals(getCity()) &&
            Math.Abs(loc.GetLatitudeNorthPositive() - GetLatitudeNorthPositive()) < 0.01 &&
            Math.Abs(loc.GetLongitudeEastPositive() - GetLongitudeEastPositive()) < 0.01);
 }