Beispiel #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);
            }
        }
Beispiel #2
0
    private void Start()
    {
        var flightBehaviour = GetComponent <FlightBehaviour>();

        if (flightBehaviour != null)
        {
            HasWind   = false;
            WindSpeed = Vector3.zero;

            var properties = transform.GetComponent <BulletProperties>();
            if (properties != null)
            {
                absolutePressure = PressureConverter.MmHgToPascal(properties.AbsolutePressureAir);

                temperature = TemeperatureConverter.CelsiusToKelvin(properties.TemperatureAir);
                temperature = temperature != 0 ? temperature : BulletProperties.DefaultTemperature;

                gasConstant = properties.GasConstant != 0 ? properties.GasConstant : BulletProperties.DefaultGasConstant;

                formResistanceCoeficient = properties.BulletFrontFormResistanceCoeficient;
                square = properties.BulletSquare;

                mass = properties.BulletMass != 0 ? properties.BulletMass : BulletProperties.DefaultBulletMass;

                flightBehaviour.Accelerations.Add(CalculateWindAcceleration);
            }
        }
    }
 protected override void Calculate()
 {
     if (textBox_FromUnit.Text != string.Empty)
     {
         var pressureConverter = new PressureConverter(decimal.Parse(textBox_FromUnit.Text), comboBox_FromUnit.Text, comboBox_ToUnit.Text);
         textBox_ToUnit.Text = pressureConverter.ConvertUnit().ToString(".######");
     }
 }
Beispiel #4
0
        public void pa_pa()
        {
            converter = new PressureConverter("pa", "pa");
            double valL = 1;
            double valR = 1;

            Assert.AreEqual(valR, converter.LeftToRight(valL));
            Assert.AreEqual(valL, converter.RightToLeft(valR));
        }
Beispiel #5
0
        public void pa_mbar()
        {
            converter = new PressureConverter("pa", "mbar");
            double valL = 1;
            double valR = 0.010000000000;

            Assert.AreEqual(valR, converter.LeftToRight(valL));
            Assert.AreEqual(valL, converter.RightToLeft(valR));
        }
Beispiel #6
0
        public void pa___kg_cm2()
        {
            converter = new PressureConverter("pa", "kg/cm2");
            double valL = 1;
            double valR = 0.0000101971621298;

            Assert.AreEqual(valR, converter.LeftToRight(valL));
            Assert.AreEqual(valL, converter.RightToLeft(valR));
        }
Beispiel #7
0
        public void pa___short_ton_in2()
        {
            converter = new PressureConverter("pa", "short ton/in2");
            double valL = 1;
            double valR = 0.000000072519;

            Assert.AreEqual(valR, converter.LeftToRight(valL));
            Assert.AreEqual(valL, converter.RightToLeft(valR));
        }
Beispiel #8
0
        public void pa_atm()
        {
            converter = new PressureConverter("pa", "atm");
            double valL = 1;
            double valR = 0.000009869233;

            Assert.AreEqual(valR, converter.LeftToRight(valL));
            Assert.AreEqual(valL, converter.RightToLeft(valR));
        }
Beispiel #9
0
        public void pa___long_ton_in2()
        {
            converter = new PressureConverter("pa", "long ton/in2");
            double valL = 1;
            double valR = 0.000000064749;

            Assert.AreEqual(valR, converter.LeftToRight(valL));
            Assert.AreEqual(valL, converter.RightToLeft(valR));
        }
Beispiel #10
0
        public void pa___lb_ft2()
        {
            converter = new PressureConverter("pa", "lb/ft2");
            double valL = 1;
            double valR = 0.020885434233;

            Assert.AreEqual(valR, converter.LeftToRight(valL));
            Assert.AreEqual(valL, converter.RightToLeft(valR));
        }
Beispiel #11
0
        public void pa___lb_in2()
        {
            converter = new PressureConverter("pa", "lb/in2");
            double valL = 1;
            double valR = 0.000145037738;

            Assert.AreEqual(valR, converter.LeftToRight(valL));
            Assert.AreEqual(valL, converter.RightToLeft(valR));
        }
Beispiel #12
0
        public void UpdateUnitSystem(UnitSystem unitSystem)
        {
            this.unitSystem = unitSystem;
            this.TextBox.Clear();
            if (unitSystem != null)
            {
                string temperature        = "Temperature: \t\t" + TemperatureConverter.GetUnitAsString(unitSystem.TemperatureUnit);
                string pressure           = "Pressure: \t\t\t" + PressureConverter.GetUnitAsString(unitSystem.PressureUnit);
                string massFlowRate       = "Mass Flow Rate: \t\t" + MassFlowRateConverter.GetUnitAsString(unitSystem.MassFlowRateUnit);
                string volumeFlowRate     = "Volume Flow Rate: \t\t" + VolumeFlowRateConverter.GetUnitAsString(unitSystem.VolumeFlowRateUnit);
                string moistureContent    = "Moisture Content: \t\t" + MoistureContentConverter.GetUnitAsString(unitSystem.MoistureContentUnit);
                string relativeHumidity   = "Fraction: \t\t\t" + FractionConverter.GetUnitAsString(unitSystem.FractionUnit);
                string enthalpy           = "Specific Energy: \t\t" + SpecificEnergyConverter.GetUnitAsString(unitSystem.SpecificEnergyUnit);
                string specificHeat       = "Specific Heat: \t\t" + SpecificHeatConverter.GetUnitAsString(unitSystem.SpecificHeatUnit);
                string energy             = "Energy: \t\t\t" + EnergyConverter.GetUnitAsString(unitSystem.EnergyUnit);
                string power              = "Power: \t\t\t" + PowerConverter.GetUnitAsString(unitSystem.PowerUnit);
                string density            = "Density: \t\t\t" + DensityConverter.GetUnitAsString(unitSystem.DensityUnit);
                string dynamicViscosity   = "Dynamic Viscosity: \t\t" + DynamicViscosityConverter.GetUnitAsString(unitSystem.DynamicViscosityUnit);
                string kinematicViscosity = "Kinematic Viscosity: \t" + KinematicViscosityConverter.GetUnitAsString(unitSystem.KinematicViscosityUnit);
                string conductivity       = "Thermal Conductivity: \t" + ThermalConductivityConverter.GetUnitAsString(unitSystem.ThermalConductivityUnit);
                string diffusivity        = "Diffusivity: \t\t" + DiffusivityConverter.GetUnitAsString(unitSystem.DiffusivityUnit);
                string mass   = "Mass: \t\t\t" + MassConverter.GetUnitAsString(unitSystem.MassUnit);
                string length = "Length: \t\t\t" + LengthConverter.GetUnitAsString(unitSystem.LengthUnit);
                string area   = "Area: \t\t\t" + AreaConverter.GetUnitAsString(unitSystem.AreaUnit);
                string volume = "Volume: \t\t\t" + VolumeConverter.GetUnitAsString(unitSystem.VolumeUnit);
                string time   = "Time: \t\t\t" + TimeConverter.GetUnitAsString(unitSystem.TimeUnit);

                this.TextBox.AppendText(temperature + "\r\n");
                this.TextBox.AppendText(pressure + "\r\n");
                this.TextBox.AppendText(massFlowRate + "\r\n");
                this.TextBox.AppendText(volumeFlowRate + "\r\n");
                this.TextBox.AppendText(moistureContent + "\r\n");
                this.TextBox.AppendText(relativeHumidity + "\r\n");
                this.TextBox.AppendText(enthalpy + "\r\n");
                this.TextBox.AppendText(specificHeat + "\r\n");
                this.TextBox.AppendText(energy + "\r\n");
                this.TextBox.AppendText(power + "\r\n");
                this.TextBox.AppendText(density + "\r\n");
                this.TextBox.AppendText(dynamicViscosity + "\r\n");
                this.TextBox.AppendText(kinematicViscosity + "\r\n");
                this.TextBox.AppendText(conductivity + "\r\n");
                this.TextBox.AppendText(diffusivity + "\r\n");
                this.TextBox.AppendText(mass + "\r\n");
                this.TextBox.AppendText(length + "\r\n");
                this.TextBox.AppendText(area + "\r\n");
                this.TextBox.AppendText(volume + "\r\n");
                this.TextBox.AppendText(time);
            }
        }
Beispiel #13
0
        private void InitialConverterParameter(SettingsModel settings)
        {
            TemperatureDecoratorConverter.ChangeParameter(settings.Preferences.TemperatureParameter);
            DateTimeConverter.ChangeParameter(settings.Preferences.GetForecastFormat());
            var p = settings.Preferences.GetHourlyFormat();

            HourMinuteConverter.ChangeParameter(p);
            UpdateTimeConverter.ChangeParameter(p);
            RefreshCompleteConverter.ChangeParameter(p);
            WindSpeedConverter.ChangeParameter(settings.Preferences.WindParameter, settings.Preferences.SpeedParameter);
            PressureConverter.ChangeParameter(settings.Preferences.PressureParameter);
            VisibilityConverter.ChangeParameter(settings.Preferences.LengthParameter);
            ImmersiveHourConverter.ChangeParameter(settings.Preferences.GetImmersiveHourFormat());
            ImmersiveMinConverter.ChangeParameter(settings.Preferences.GetImmersiveMinFormat());
        }
Beispiel #14
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;
            }
            }
        }
Beispiel #15
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();
        }
Beispiel #16
0
 public void Setup()
 {
     converter = new PressureConverter();
 }
Beispiel #17
0
 public void Cleanup()
 {
     converter = null;
 }