Beispiel #1
0
        public void Check_GetAlosHashachar()
        {
            var zman = calendar.GetAlosHashachar().RemoveMilliseconds();

            Assert.That(zman, Is.EqualTo(
                            new DateTime(2010, 4, 2, 5, 17, 14)
                            ));
        }
        public void Check_GetAlosHashachar()
        {
            var zman = calendar.GetAlosHashachar();

            Assert.That(zman, Is.EqualTo(
                            new DateTime(2010, 4, 2, 5, 17, 14, 493)
                            ));
        }
        public async Task <JsonResult> Post([FromBody] GoogleJsonRequest value)
        {
            //Create request
            try
            {
                HttpContext.Request.Body.Position = 0;
                StreamReader read = new StreamReader(HttpContext.Request.Body, true);
                //log the inconming request body just to be able to view them on heroku
                Console.WriteLine(await read.ReadToEndAsync());
                WebRequest request = WebRequest.Create("http://freegeoip.net/json/" + Request.Headers["x-forwarded-for"].ToString());
                request.Method = "GET";
                //Get the response
                WebResponse wr = await request.GetResponseAsync();

                Stream       receiveStream = wr.GetResponseStream();
                StreamReader reader        = new StreamReader(receiveStream);
                string       content       = reader.ReadToEnd();
                JObject      obj           = JObject.Parse(content);
                String       city          = (String)obj["city"];
                double       lat           = (Double)obj["latitude"];
                double       lon           = (Double)obj["longitude"];
                String       timeZone      = (String)obj["time_zone"];
                //generate the zmanim
                ITimeZone   zmanimTimeZone = new WindowsTimeZone(timeZone);
                GeoLocation location       = new GeoLocation("Random", lat, lon,
                                                             0, zmanimTimeZone);
                ComplexZmanimCalendar czc = new ComplexZmanimCalendar(location);
                //if zmanim_names is null then return the full zmanim, otherwise return that specific zman
                if (value is null || value.Result is null || value.Result.Parameters is null || value.Result.Parameters.ZmanimNames is null)
                {
                    String Speech = "Here are your jewish times for " + city + ". Dawn is at " + czc.GetAlosHashachar().formatDate() + ". Sunrise is at " + czc.GetSunrise().formatDate()
                                    + ". The Latest Shema is at " + czc.GetSofZmanShmaMGA().formatDate() + " According to the magein avraham, and at "
                                    + czc.GetSofZmanShmaGRA().formatDate() + " according to the grah." + " The latest time for morning prayers is at "
                                    + czc.GetSofZmanTfilaGRA().formatDate() + " According to the grah and at "
                                    + czc.GetSofZmanShmaMGA().formatDate() + " according to the magein avraham. "
                                    + "Midday is at " + czc.GetChatzos().formatDate() + ". The earliest time for afternoon services is at " + czc.GetMinchaGedola().formatDate()
                                    + ". Sunset is at" + czc.GetSunset().formatDate()
                                    + ". Nightfall is at " + czc.GetTzais().formatDate();

                    String display =
                        "Jewish times for " + city + "\nDawn-" + czc.GetAlosHashachar().formatDate() + "\nSunrise-" + czc.GetSunrise().formatDate()
                        + "\n Latest Shema MGA-" + czc.GetSofZmanShmaMGA().formatDate() + "\n Latest Shema Gra-"
                        + czc.GetSofZmanShmaGRA().formatDate() + "\nLatest morning prayers Gra-"
                        + czc.GetSofZmanTfilaGRA().formatDate() + "\nLatest morning prayers Mga-"
                        + czc.GetSofZmanShmaMGA().formatDate()
                        + "\nMidday-" + czc.GetChatzos().formatDate() + "\nEarliest afternoon prayers-" + czc.GetMinchaGedola().formatDate()
                        + "\nSunset-" + czc.GetSunset().formatDate()
                        + "\nNightfall-" + czc.GetTzais().formatDate();

                    ResponseJson response = new ResponseJson();
                    response.DisplayText = display;
                    response.Source      = "Zmanim.net";
                    response.Speech      = Speech;
                    Console.WriteLine("Processed post method");
                    return(Json(response));
                }
                else
                {
                    String speech  = "";
                    String display = "";
                    switch (value.Result.Parameters.ZmanimNames)
                    {
                    case "shkia":
                        speech  = "Sunset is at " + czc.GetSunset().formatDate();
                        display = speech;
                        break;

                    case "sofeshema":
                        speech  = "Latest shema is at " + czc.GetSofZmanShmaGRA().formatDate() + " according to the grah, and at " + czc.GetSofZmanShmaMGA().formatDate() + " according to the magein avraham";
                        display = "Latest Shema Gra: " + czc.GetSofZmanShmaGRA().formatDate() + ". Latest Shema Magein Avraham: " + czc.GetSofZmanShmaMGA().formatDate();
                        break;

                    case "sofeteffilah":
                        speech  = "The latest time for morning prayers is at " + czc.GetSofZmanTfilaGRA().formatDate() + " according to the grah, and at " + czc.GetSofZmanTfilaMGA().formatDate() + " according to the magein avraham";
                        display = "Latest morning prayers Gra: " + czc.GetSofZmanTfilaGRA().formatDate() + ". Latest morning prayers Magein Avraham: " + czc.GetSofZmanTfilaMGA().formatDate();
                        break;

                    case "chatzos":
                        speech  = "Midday is at " + czc.GetChatzos().formatDate();
                        display = speech;
                        break;

                    case "minchagedolah":
                        speech  = "The earliest time for afternoon prayer is at " + czc.GetMinchaGedola().formatDate();
                        display = speech;
                        break;

                    case "minchaketana":
                        speech  = "Mincha Ketana is at " + czc.GetMinchaKetana().formatDate();
                        display = speech;
                        break;

                    case "neitz":
                        speech  = "Sunrise is at " + czc.GetSunrise().formatDate();
                        display = speech;
                        break;

                    case "alos":
                        speech  = "Dawn is at " + czc.GetAlosHashachar().formatDate();
                        display = speech;
                        break;

                    case "tzaishakochavim":
                        speech  = "Nightfall is at " + czc.GetTzais().formatDate();
                        display = speech;
                        break;

                    default:
                        speech  = "The zman you requested could not be calculated";
                        display = speech;
                        break;
                    }
                    ResponseJson response = new ResponseJson();
                    response.DisplayText = display + " in " + city;
                    response.Source      = "Zmanim.net";
                    response.Speech      = speech + " in " + city;
                    Console.WriteLine("Processed post method");
                    return(Json(response));
                }
            }
Beispiel #4
0
        /// <summary>
        /// show Times Based of Geo location
        /// </summary>
        public void LocationTimes()
        {
            string      locationName;
            double      latitude;
            double      longitude;
            double      elevation;
            XmlDocument xmlDoc = new XmlDocument();

            if (!File.Exists("GeoLocation.xml"))
            {
                GeoLocationTimes glt = new GeoLocationTimes();
                glt.CreateFirstGeoLocationXML();
                //glt.SetGeoLocation();
            }
            else
            {
                xmlDoc.Load("GeoLocation.xml");
                XmlNodeList nodeList = xmlDoc.DocumentElement.SelectNodes("/Table/Geo");
                string      GeoID = "", GeoLocationName = "", Geolatitude = "", Geolongitude = "", Geoelevation = "";
                foreach (XmlNode node in nodeList)
                {
                    GeoID           = node.SelectSingleNode("Geo_Id").InnerText;
                    GeoLocationName = node.SelectSingleNode("Geo_Location_Name").InnerText;
                    Geolatitude     = node.SelectSingleNode("Latitude").InnerText;
                    Geolongitude    = node.SelectSingleNode("Longitude").InnerText;
                    Geoelevation    = node.SelectSingleNode("Elevation").InnerText;
                }
                locationName = GeoLocationName;
                latitude     = Convert.ToDouble(Geolatitude);
                longitude    = Convert.ToDouble(Geolongitude);
                elevation    = Convert.ToDouble(Geoelevation);

                //ITimeZone timeZone = new OlsonTimeZone(PublicDomain.TzTimeZone.CurrentTimeZone);
                ITimeZone             timeZone = new OlsonTimeZone("Asia/Jerusalem");
                GeoLocation           location = new GeoLocation(locationName, latitude, longitude, elevation, timeZone);
                ComplexZmanimCalendar zc = new ComplexZmanimCalendar(DateTime.Now, location);
                string   TimeFormat = "HH:mm:ss";
                DateTime d1, d2, d3, d4, d5, d6, d7, d8, d9;
                {
                    lblTi1.Text = (locationName);
                    d1          = (zc.GetAlosHashachar().Value);
                    d2          = (zc.GetBeginNauticalTwilight().Value);
                    d3          = (zc.GetSunrise().Value);
                    d4          = (zc.GetSofZmanShmaMGA().Value);
                    d5          = (zc.GetSofZmanShmaGRA().Value);
                    d6          = (zc.GetMinchaGedola72Minutes().Value);
                    d7          = (zc.GetSeaLevelSunset().Value);
                    d8          = (zc.GetTzaisGeonim4Point37Degrees().Value);
                    d9          = (zc.GetCandleLighting().Value);
                    lblTi2.Text = d1.ToString(TimeFormat);
                    lblTi3.Text = d2.ToString(TimeFormat);
                    lblTi4.Text = d3.ToString(TimeFormat);
                    lblTi5.Text = d4.ToString(TimeFormat);
                    lblTi6.Text = d5.ToString(TimeFormat);
                    lblTi7.Text = d6.ToString(TimeFormat);
                    lblTi8.Text = d7.ToString(TimeFormat);
                    //lblTi9.Text = (zc.GetTzaisGeonim8Point5Degrees().ToString());
                    //lblTi9.Text = (zc.GetTzaisGeonim3Point65Degrees().ToString());
                    lblTi9.Text     = d8.ToString(TimeFormat);
                    lblCandles.Text = d9.ToString(TimeFormat);
                }
            }
        }