Ejemplo n.º 1
0
        public object Convert(ConverterType type, object value)
        {
            switch (type)
            {
            case ConverterType.Temperature:
                _logger.Debug("Temperature converter started");
                return(TemperatureConverter.Convert(value));

            case ConverterType.Speed:
                _logger.Debug("Speed converter started");
                return(SpeedConverter.Convert(value));

            case ConverterType.DegreeToDirection:
                _logger.Debug("Degree to direction converter started");
                return(DegreeToDirectionConverter.Convert(value));

            case ConverterType.Pressure:
                _logger.Debug("Pressure converter started");
                return(PressureConverter.Convert(value));

            default:
                _logger.Error("Unknown converter type");
                return(null);
            }
        }
Ejemplo n.º 2
0
        private void Convert(double value)
        {
            switch (SelectedOp)
            {
            case "Length":
            {
                LengthunitConverter unit = new LengthunitConverter();
                Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString();
                break;
            }

            case "Mass and Weight":
            {
                MassConverter unit = new MassConverter();
                Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString();
                break;
            }

            case "Power":
            {
                PowerConverter unit = new PowerConverter();
                Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString();
                break;
            }

            case "Pressure":
            {
                PressureConverter unit = new PressureConverter();
                Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString();
                break;
            }

            case "Energy":
            {
                EnergyConveter unit = new EnergyConveter();
                Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString();
                break;
            }

            case "Temperature":
            {
                TemperatureConverter unit = new TemperatureConverter();
                Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString();
                break;
            }

            case "Volume":
            {
                VolumeConverter unit = new VolumeConverter();
                Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString();
                break;
            }

            case "Angle":
            {
                AngleConverter unit = new AngleConverter();
                Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString();
                break;
            }

            case "Area":
            {
                AreaConverter unit = new AreaConverter();
                Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString();
                break;
            }

            case "Speed":
            {
                SpeedConverter unit = new SpeedConverter();
                Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString();
                break;
            }

            case "Time":
            {
                TimeunitsConverter unit = new TimeunitsConverter();
                Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString();
                break;
            }
            }
        }
Ejemplo n.º 3
0
        private async Task InitialViewModel()
        {
            CurrentTime = DateTime.Now;
            UpdateTime  = fetchresult.Location.UpdateTime;
            utcOffset   = UpdateTime - fetchresult.Location.UtcTime;
            RefreshCurrentTime();
            CurrentTimeRefreshTask();
            todayIndex = Array.FindIndex(fetchresult.DailyForecast, x =>
            {
                return(x.Date.Date == CurrentTime.Date);
            });
            nowHourIndex = Array.FindIndex(fetchresult.HourlyForecast, x =>
            {
                return((x.DateTime - CurrentTime).TotalSeconds > 0);
            });
            if (CurrentTime.Hour <= sunRise.Hours)
            {
                todayIndex--;
            }
            if (todayIndex < 0)
            {
                todayIndex = 0;
            }
            if (nowHourIndex < 0)
            {
                nowHourIndex = 0;
            }
            if (fetchresult.DailyForecast[todayIndex].SunRise == default(TimeSpan) || fetchresult.DailyForecast[todayIndex].SunSet == default(TimeSpan))
            {
                sunRise = Core.LunarCalendar.SunRiseSet.GetRise(new Models.Location(currentCityModel.Latitude, currentCityModel.Longitude), CurrentTime);
                sunSet  = Core.LunarCalendar.SunRiseSet.GetSet(new Models.Location(currentCityModel.Latitude, currentCityModel.Longitude), CurrentTime);
            }
            else
            {
                sunRise = fetchresult.DailyForecast[todayIndex].SunRise;
                sunSet  = fetchresult.DailyForecast[todayIndex].SunSet;
            }
            City        = currentCityModel.City;
            isNight     = WeatherModel.CalculateIsNight(CurrentTime, sunRise, sunSet);
            this.Glance = Models.Glance.GenerateGlanceDescription(fetchresult, isNight, TemperatureDecoratorConverter.Parameter, DateTime.Now);
            CityGlance  = (City + "  " + Glance);
            Date        = CurrentTime.ToString(settings.Preferences.GetDateFormat());

            var calendar = new CalendarInfo(CurrentTime);
            var loader   = new ResourceLoader();


            LunarCalendar = settings.Preferences.UseLunarCalendarPrimary ? (("农历 " + calendar.LunarYearSexagenary + "年" + calendar.LunarMonthText + "月" + calendar.LunarDayText + "    " + calendar.SolarTermStr).Trim()) : string.Empty;
            Hum           = ": " + fetchresult.HourlyForecast[nowHourIndex].Humidity + "%";
            Pop           = ": " + fetchresult.HourlyForecast[nowHourIndex].Pop + "%";
            Pcpn          = ": " + fetchresult.NowWeather.Precipitation + " mm";
            var v = new VisibilityConverter();

            Vis = ": " + (fetchresult.NowWeather.Visibility == null ? "N/A" : v.Convert(fetchresult.NowWeather.Visibility, null, null, null));
            var w = new WindSpeedConverter();

            Scale = ": " + (fetchresult.NowWeather.Wind == null ? "N/A" : w.Convert(fetchresult.NowWeather.Wind, null, null, null));
            var d = new WindDirectionConverter();

            Dir = ": " + (fetchresult.NowWeather.Wind == null ? "N/A" : d.Convert(fetchresult.NowWeather.Wind, null, null, null));
            var p = new PressureConverter();

            Pressure = ": " + (fetchresult.NowWeather.Pressure == null ? "N/A" : p.Convert(fetchresult.NowWeather.Pressure, null, null, null));

            var t = new TimeSpanConverter();

            SunRise       = ": " + (string)t.Convert(sunRise, null, null, null);
            SunSet        = ": " + (string)t.Convert(sunSet, null, null, null);
            this.Location = ": " + new Models.Location(currentCityModel.Latitude, currentCityModel.Longitude).ToString();
            var off = utcOffset.Hours;

            Offset = ": UTC" + (off >= 0 ? " +" : " -") + t.Convert(utcOffset, null, null, null);

            var uri = await settings.Immersive.GetCurrentBackgroundAsync(fetchresult.NowWeather.Now.Condition, isNight);

            if (uri != null)
            {
                try
                {
                    CurrentBG = new BitmapImage(uri);
                }
                catch (Exception)
                {
                }
            }
            List <KeyValuePair <int, double> > doubles0 = new List <KeyValuePair <int, double> >();
            List <KeyValuePair <int, double> > doubles1 = new List <KeyValuePair <int, double> >();
            List <KeyValuePair <int, double> > doubles2 = new List <KeyValuePair <int, double> >();
            List <KeyValuePair <int, double> > doubles3 = new List <KeyValuePair <int, double> >();
            List <KeyValuePair <int, double> > doubles5 = new List <KeyValuePair <int, double> >();
            List <KeyValuePair <int, double> > doubles4 = new List <KeyValuePair <int, double> >();

            if (!fetchresult.HourlyForecast.IsNullorEmpty())
            {
                for (int i = nowHourIndex + 1; i < fetchresult.HourlyForecast.Length; i++)
                {
                    if (fetchresult.HourlyForecast[i].Temprature != null)
                    {
                        doubles0.Add(new KeyValuePair <int, double>(i, fetchresult.HourlyForecast[i].Temprature.ActualDouble(TemperatureDecoratorConverter.Parameter)));
                    }
                    if (fetchresult.HourlyForecast[i].Pop != default(uint))
                    {
                        doubles1.Add(new KeyValuePair <int, double>(i, fetchresult.HourlyForecast[i].Pop));
                    }
                    if (fetchresult.HourlyForecast[i].Wind != null)
                    {
                        doubles4.Add(new KeyValuePair <int, double>(i, fetchresult.HourlyForecast[i].Wind.Speed.ActualDouble(WindSpeedConverter.SpeedParameter)));
                    }
                }
                var sb = new StringBuilder();
                if (doubles0 != null && doubles0.Count > 1)
                {
                    GetHourlyXText(doubles0, sb);
                    Forecasts.Add(new GraphViewModel(doubles0, null, new SolidColorBrush(Palette.GetRandom()), new SolidColorBrush(Palette.Cyan), string.Format(loader.GetString("HourlyDetailsTemperature"), doubles0.Count), Temperature.GetFormat(TemperatureDecoratorConverter.Parameter), -280, 9999, sb.ToString()));
                }
                if (doubles1 != null && doubles1.Count > 1)
                {
                    GetHourlyXText(doubles1, sb);
                    Forecasts.Add(new GraphViewModel(doubles1, null, new SolidColorBrush(Palette.GetRandom()), new SolidColorBrush(Colors.Transparent), string.Format(loader.GetString("HourlyDetailsPop"), doubles1.Count), "%", 0, 100, sb.ToString()));
                }
                if (doubles4 != null && doubles4.Count > 1)
                {
                    GetHourlyXText(doubles4, sb);
                    Forecasts.Add(new GraphViewModel(doubles4, null, new SolidColorBrush(Palette.GetRandom()), new SolidColorBrush(Colors.Transparent), string.Format(loader.GetString("HourlyDetailsWind"), doubles4.Count), Wind.GetSpeedFormat(WindSpeedConverter.SpeedParameter), 0, 1000, sb.ToString()));
                }
            }

            doubles0.Clear();
            doubles1.Clear();
            doubles2.Clear();
            doubles3.Clear();
            doubles4.Clear();
            doubles5.Clear();

            if (!fetchresult.DailyForecast.IsNullorEmpty())
            {
                for (int i = todayIndex + 1; i < fetchresult.DailyForecast.Length; i++)
                {
                    if (fetchresult.DailyForecast[i].HighTemp != null && fetchresult.DailyForecast[i].LowTemp != null)
                    {
                        doubles0.Add(new KeyValuePair <int, double>(i, fetchresult.DailyForecast[i].HighTemp.ActualDouble(TemperatureDecoratorConverter.Parameter)));
                        doubles1.Add(new KeyValuePair <int, double>(i, fetchresult.DailyForecast[i].LowTemp.ActualDouble(TemperatureDecoratorConverter.Parameter)));
                    }
                    if (fetchresult.DailyForecast[i].Pop != default(uint))
                    {
                        doubles2.Add(new KeyValuePair <int, double>(i, fetchresult.DailyForecast[i].Pop));
                    }
                    if (fetchresult.DailyForecast[i].Precipitation != default(float))
                    {
                        doubles3.Add(new KeyValuePair <int, double>(i, fetchresult.DailyForecast[i].Precipitation));
                    }
                    if (fetchresult.DailyForecast[i].Visibility != null)
                    {
                        doubles5.Add(new KeyValuePair <int, double>(i, fetchresult.DailyForecast[i].Visibility.ActualDouble(VisibilityConverter.LengthParameter)));
                    }
                    if (fetchresult.DailyForecast[i].Wind != null)
                    {
                        doubles4.Add(new KeyValuePair <int, double>(i, fetchresult.DailyForecast[i].Wind.Speed.ActualDouble(WindSpeedConverter.SpeedParameter)));
                    }
                }
                var sb = new StringBuilder();
                if (!doubles0.IsNullorEmpty() && !doubles1.IsNullorEmpty())
                {
                    GetDailyXText(doubles0, sb);
                    Forecasts.Add(new GraphViewModel(doubles0, doubles1, new SolidColorBrush(Palette.Orange), new SolidColorBrush(Palette.Cyan), string.Format(loader.GetString("DailyDetailsTemp"), doubles0.Count), Temperature.GetFormat(TemperatureDecoratorConverter.Parameter), -280, 9999, sb.ToString()));
                }
                if (doubles2 != null && doubles2.Count > 1)
                {
                    GetDailyXText(doubles2, sb);
                    Forecasts.Add(new GraphViewModel(doubles2, null, new SolidColorBrush(Palette.GetRandom()), new SolidColorBrush(Colors.Transparent), string.Format(loader.GetString("DailyDetailsPop"), doubles2.Count), "%", 0, 100, sb.ToString()));
                }
                if (doubles3 != null && doubles3.Count > 1)
                {
                    GetDailyXText(doubles3, sb);
                    Forecasts.Add(new GraphViewModel(doubles3, null, new SolidColorBrush(Palette.GetRandom()), new SolidColorBrush(Colors.Transparent), string.Format(loader.GetString("DailyDetailsPrep"), doubles3.Count), "mm", 0, 100, sb.ToString()));
                }
                if (doubles5 != null && doubles5.Count > 1)
                {
                    GetDailyXText(doubles5, sb);
                    Forecasts.Add(new GraphViewModel(doubles5, null, new SolidColorBrush(Palette.GetRandom()), new SolidColorBrush(Colors.Transparent), string.Format(loader.GetString("DailyDetailsVis"), doubles5.Count), Length.GetFormat(VisibilityConverter.LengthParameter), 0, 1000, sb.ToString()));
                }
                if (doubles4 != null && doubles4.Count > 1)
                {
                    GetDailyXText(doubles4, sb);
                    Forecasts.Add(new GraphViewModel(doubles4, null, new SolidColorBrush(Palette.GetRandom()), new SolidColorBrush(Colors.Transparent), string.Format(loader.GetString("DailyDetailsWind"), doubles4.Count), Wind.GetSpeedFormat(WindSpeedConverter.SpeedParameter), 0, 1000, sb.ToString()));
                }
            }

            OnFetchDataComplete();
        }
Ejemplo n.º 4
0
 public void InvalidCurrentUnit()
 {
     converter.Convert("bar", 5, "pascals");
 }