Example #1
0
        private string GetWeatherValue(string fieldReference, Tim_hub.Weather.API.Weather weather)
        {
            string[] propnames = fieldReference.Split('.');

            Type   lastObj    = weather.GetType();
            object fieldValue = null;

            foreach (var propname in propnames)
            {
                bool isArray    = propname.Split('[').Length >= 2;
                int  arrayIndex = isArray ? int.Parse(propname.Split('[')[1].Replace("]", "")) : 0;
                var  field      = lastObj.GetField(isArray ? propname.Replace("[" + arrayIndex + "]", "") : propname);
                lastObj = field.FieldType;


                if (isArray)
                {
                    lastObj    = ((dynamic[])field.GetValue(fieldValue ?? weather))[arrayIndex].GetType();
                    fieldValue = ((dynamic[])field.GetValue(fieldValue ?? weather))[arrayIndex];
                }
                else
                {
                    fieldValue = field.GetValue(fieldValue ?? weather);
                }
            }

            return(fieldValue.ToString());
        }
Example #2
0
        public string GetWallpaper(Tim_hub.Weather.API.Weather weather)
        {
            StreamReader reader = new StreamReader(DirectoryPath + "/config.json");
            string       config = reader.ReadToEnd();

            reader.Close();
            List <WeatherWallpaper> wallpapers = JsonConvert.DeserializeObject <List <WeatherWallpaper> >(config);

            foreach (var wallp in wallpapers)
            {
                var value = GetWeatherValue(wallp.Condition.PropertyReference, weather);
                Console.WriteLine($"{value}   {wallp.Condition.Operator}    {wallp.Condition.Value}      is {wallp.Condition.Suitable(value)}");
                if (wallp.Condition.Suitable(value))
                {
                    return(DirectoryPath + "\\" + wallp.WallpaperFilename);
                }
            }
            throw new Exception("Wallpaper pack don't valid");
        }
        private void UpdateWeather(Tim_hub.Weather.API.Weather arg)
        {
            if (User.Location != null)
            {
                Console.WriteLine("UPDATE");
                string exePath         = this.GetType().Assembly.Location;
                var    locationPaths   = exePath.Split('\\').ToList();
                string programLocation = exePath.Replace(locationPaths[locationPaths.Count - 1], "");
                var    pack            = new WeatherDesktop.Packs.WeatherPack(programLocation + @"\Assets\WeatherPacks\WeatherDefault");

                var iconID = Weather.Current.Condition[0].IconID;
                SetWeatherFontColor(iconID[iconID.Length - 1] == 'd' ? Brushes.Black : Brushes.White);

                string iconPath = ProgramCache.FilesPath + iconID + ".png";
                if (!System.IO.File.Exists(iconPath))
                {
                    var icon = Tim_hub.Weather.API.DownloadIcon(iconID);
                    icon.Save(iconPath);
                }

                UpdateImageSource(WeatherIcon, iconPath);


                WeatherHumidity.Text = Weather.Current.Measurements.Humidity + " %";
                WeatherPressure.Text = Weather.Current.Measurements.Pressure + " hPa";
                WeatherWind.Text     = Weather.Current.Wind.Speed + " m/s";
                var temper = Weather.Current.Measurements.Temperatur;
                WeatherTemperature.Text  = temper > 0 ? $"+{temper}" : temper.ToString();
                WeatherTemperature.Text += "°C";
                WeatherDeskription.Text  = Weather.Current.Condition[0].Description;
                CityNameWeather.Text     = Weather.Current.CityName;

                var weatherBack = pack.GetWallpaper(Weather.Current);
                UpdateImageSource(WeatherBack, weatherBack);
                DisplayPicture(weatherBack.Replace(@"\\", @"\").Replace(@"\\\", @"\".Replace(@"\\\\", @"\")));
                //just don't ask...
            }
            else
            {
                MainTabContol.SelectedIndex = 2;
            }
        }