コード例 #1
0
 /// <summary>
 /// Calculate sunrise and sunset times. Returns false if time zone and longitude are incompatible.
 /// </summary>
 /// <param name="lat">Latitude coordinates.</param>
 /// <param name="lon">Longitude coordinates.</param>
 /// <param name="date">Date for which to calculate.</param>
 /// <param name="riseTime">Sunrise time (output)</param>
 /// <param name="setTime">Sunset time (output)</param>
 /// <param name="isSunrise">Whether or not the sun rises at that day</param>
 /// <param name="isSunset">Whether or not the sun sets at that day</param>
 public bool CalculateSunRiseSetTimes(LatitudeCoords lat, LongitudeCoords lon, DateTime date,
                                      ref DateTime riseTime, ref DateTime setTime,
                                      ref bool isSunrise, ref bool isSunset)
 {
     return(CalculateSunRiseSetTimes(lat.ToDouble(), lon.ToDouble(), date, ref riseTime, ref setTime,
                                     ref isSunrise, ref isSunset));
 }
コード例 #2
0
ファイル: SunTimes.cs プロジェクト: EAbychkov/AlarmApp
        /// <summary>
        /// Calculate sunrise and sunset times. Returns false if time zone and longitude are incompatible.
        /// </summary>
        /// <param name="lat">Latitude coordinates.</param>
        /// <param name="lon">Longitude coordinates.</param>
        /// <param name="date">Date for which to calculate.</param>
        /// <param name="riseTime">Sunrise time (output)</param>
        /// <param name="setTime">Sunset time (output)</param>
        /// <param name="isSunrise">Whether or not the sun rises at that day</param>
        /// <param name="isSunset">Whether or not the sun sets at that day</param>
        public bool CalculateSunRiseSetTimes(LatitudeCoords lat, LongitudeCoords lon, DateTime date,
												ref DateTime riseTime, ref DateTime setTime,
												ref bool isSunrise, ref bool isSunset)
        {
            return CalculateSunRiseSetTimes(lat.ToDouble(), lon.ToDouble(), date, ref riseTime, ref setTime, ref isSunrise, ref isSunset);
        }
コード例 #3
0
 /// <summary>
 ///     Calculate sunrise and sunset times. Returns false if time zone and longitude are incompatible.
 /// </summary>
 /// <param name="lat"> Latitude coordinates. </param>
 /// <param name="lon"> Longitude coordinates. </param>
 /// <param name="date"> Date for which to calculate. </param>
 /// <param name="riseTime"> Sunrise time (output) </param>
 /// <param name="setTime"> Sunset time (output) </param>
 /// <param name="isSunrise"> Whether or not the sun rises at that day </param>
 /// <param name="isSunset"> Whether or not the sun sets at that day </param>
 public void CalculateSunriseSetTimes([NotNull] LatitudeCoords lat, [NotNull] LongitudeCoords lon, DateTime date,
                                      ref DateTime riseTime, ref DateTime setTime, ref bool isSunrise, ref bool isSunset)
 {
     CalculateSunriseSetTimes(lat.ToDouble(), lon.ToDouble(), date, ref riseTime, ref setTime, ref isSunrise,
                              ref isSunset);
 }
コード例 #4
0
        #pragma warning disable 1998
        private static async Task <Module> GetModule(string value)
        #pragma warning restore 1998
        {
            try
            {
                ModuleType      moduleType      = ModuleType.None;
                string          city            = string.Empty;
                string          postal          = string.Empty;
                string          cityCode        = string.Empty;
                string          country         = string.Empty;
                string          language        = string.Empty;
                LatitudeCoords  latitudeCoords  = null;
                LongitudeCoords longitudeCoords = null;
                Categories      categories      = Categories.Business;
                Countries       countries       = Countries.AE;
                Languages       languages       = Languages.AF;

                if (value != string.Empty)
                {
                    if (!value.Contains("news"))
                    {
                        LocationTable locationTable = DataAccess.GetLocationData()?[0];

                        moduleType = (ModuleType)Enum.Parse(typeof(ModuleType), Regex.Replace(value, @"[\d-]", string.Empty).ToUpper());

                        if (locationTable != null)
                        {
                            switch (moduleType)
                            {
                            case ModuleType.None:
                                break;

                            case ModuleType.Time:

                                Coordinates coordinates = await GoogleMapsGeocoding.GetCoordinatesForPostal(locationTable.Postal, locationTable.Country);

                                if (coordinates == null)
                                {
                                    break;
                                }

                                latitudeCoords  = coordinates.Latitude;
                                longitudeCoords = coordinates.Longitude;
                                break;

                            case ModuleType.Weather:

                                city     = locationTable.City;
                                postal   = locationTable.Postal;
                                cityCode = locationTable.CityCode;
                                country  = locationTable.Country;
                                language = locationTable.Language;
                                break;

                            case ModuleType.Weatherforecast:

                                city     = locationTable.City;
                                postal   = locationTable.Postal;
                                cityCode = locationTable.CityCode;
                                country  = locationTable.Country;
                                language = locationTable.Language;
                                break;

                            case ModuleType.News:
                                break;

                            case ModuleType.Quote:
                                break;

                            case ModuleType.Joke:
                                break;
                            }
                        }
                    }
                    else
                    {
                        moduleType = ModuleType.News;

                        value = value.Remove(0, 4);

                        // To UppperCamelCase
                        value = value.First().ToString().ToUpper() + value.Substring(1);

                        categories = (Categories)Enum.Parse(typeof(Categories), Regex.Replace(value, @"[\d-]", string.Empty));

                        LocationTable locationTable = DataAccess.GetLocationData()?[0];

                        // ReSharper disable once InvertIf
                        if (locationTable != null)
                        {
                            countries = (Countries)Enum.Parse(typeof(Countries), locationTable.Country.ToUpper());

                            languages = (Languages)Enum.Parse(typeof(Languages), locationTable.Language.ToUpper());
                        }
                    }
                }

                return(new Module
                {
                    ModuleType = moduleType,
                    City = city,
                    Postal = postal,
                    CityCode = cityCode,
                    Country = country,
                    Language = language,
                    LatitudeCoords = latitudeCoords,
                    LongitudeCoords = longitudeCoords,
                    NewsCategory = categories,
                    NewsCountry = countries,
                    NewsLanguage = languages
                });
            }
            catch (Exception exception)
            {
                Log.Log.WriteException(exception);
                return(new Module());
            }
        }
コード例 #5
0
    } //LongitudeCoords Class

    /// <summary>
    /// Calculate sunrise and sunset times. Returns false if time zone and longitude are incompatible.
    /// </summary>
    /// <param name="lat">Latitude coordinates.</param>
    /// <param name="lon">Longitude coordinates.</param>
    /// <param name="date">Date for which to calculate.</param>
    /// <param name="riseTime">Sunrise time (output)</param>
    /// <param name="setTime">Sunset time (output)</param>
    /// <param name="isSunrise">Whether or not the sun rises at that day</param>
    /// <param name="isSunset">Whether or not the sun sets at that day</param>
    public bool CalculateSunRiseSetTimes(LatitudeCoords lat, LongitudeCoords lon, DateTime date,
                                         out DateTime riseTime, out DateTime setTime,
                                         out bool isSunrise, out bool isSunset)
    {
        return(this.CalculateSunRiseSetTimes(lat.ToDouble(), lon.ToDouble(), date, out riseTime, out setTime, out isSunrise, out isSunset));
    } //CalculateSunRiseSetTimes Function
コード例 #6
0
        #pragma warning disable 1998
        private static async Task <Module> getModule(string value)
        #pragma warning restore 1998
        {
            ModuleType      moduleType      = ModuleType.NONE;
            string          city            = string.Empty;
            string          country         = string.Empty;
            string          language        = string.Empty;
            LatitudeCoords  latitudeCoords  = null;
            LongitudeCoords longitudeCoords = null;
            Categories      categories      = Categories.Business;
            Countries       countries       = Countries.AE;
            Languages       languages       = Languages.AF;

            if (value != string.Empty)
            {
                if (!value.Contains("news"))
                {
                    LocationTable locationTable = DataAccess.GetLocationData()?[0];

                    moduleType = (ModuleType)Enum.Parse(typeof(ModuleType), value.ToUpper());

                    if (locationTable != null)
                    {
                        switch (moduleType)
                        {
                        case ModuleType.NONE:
                            break;

                        case ModuleType.TIME:

                            Coordinates coordinates = await GoogleMapsGeocoding.GetCoordinatesForCity(locationTable.City, locationTable.State, locationTable.Country);

                            latitudeCoords  = coordinates.Latitude;
                            longitudeCoords = coordinates.Longitude;
                            break;

                        case ModuleType.WEATHER:

                            city     = locationTable.City;
                            country  = locationTable.Country;
                            language = locationTable.Language;
                            break;

                        case ModuleType.WEATHERFORECAST:

                            city     = locationTable.City;
                            country  = locationTable.Country;
                            language = locationTable.Language;
                            break;

                        case ModuleType.NEWS:
                            break;

                        case ModuleType.QUOTE:
                            break;

                        case ModuleType.JOKE:
                            break;
                        }
                    }
                }
                else
                {
                    moduleType = ModuleType.NEWS;

                    value = value.Remove(0, 4);

                    // To UppperCamelCase
                    value = value.First().ToString().ToUpper() + value.Substring(1);

                    categories = (Categories)Enum.Parse(typeof(Categories), value);

                    LocationTable locationTable = DataAccess.GetLocationData()?[0];

                    // ReSharper disable once InvertIf
                    if (locationTable != null)
                    {
                        countries = (Countries)Enum.Parse(typeof(Countries), locationTable.Country.ToUpper());

                        languages = (Languages)Enum.Parse(typeof(Languages), locationTable.Language.ToUpper());
                    }
                }
            }

            return(new Module
            {
                ModuleType = moduleType,
                City = city,
                Country = country,
                Language = language,
                LatitudeCoords = latitudeCoords,
                LongitudeCoords = longitudeCoords,
                NewsCategory = categories,
                NewsCountry = countries,
                NewsLanguage = languages
            });
        }
コード例 #7
0
 /// <summary>
 /// Calculate sunrise and sunset times. Returns false if time zone and longitude are incompatible.
 /// </summary>
 /// <param name="lat">Latitude coordinates.</param>
 /// <param name="lon">Longitude coordinates.</param>
 /// <param name="date">Date for which to calculate.</param>
 /// <param name="riseTime">Sunrise time (output)</param>
 /// <param name="setTime">Sunset time (output)</param>
 /// <param name="isSunrise">Whether or not the sun rises at that day</param>
 /// <param name="isSunset">Whether or not the sun sets at that day</param>
 /// <param name="convertSummerTime"></param>
 public bool CalculateSunRiseSetTimes(LatitudeCoords lat, LongitudeCoords lon, DateTime date,
                                      ref DateTime riseTime, ref DateTime setTime,
                                      ref bool isSunrise, ref bool isSunset, bool convertSummerTime = false)
 {
     return(CalculateSunRiseSetTimes(lat.ToDouble(), lon.ToDouble(), date, ref riseTime, ref setTime, ref isSunrise, ref isSunset, convertSummerTime));
 }