public static PersistentData GetCurrentSettingsData()
        {
            string path = PathHandling.GetSettingsPath();

            if (PathHandling.CheckIfFileExists(path))
            {
                string jsonString = File.ReadAllText(path);
                data = JsonSerializer.Deserialize <PersistentData>(jsonString);
                return(data);
            }

            return(null);
        }
Exemple #2
0
        private void BanUseUpdated(object sender, RoutedEventArgs e)
        {
            if (view.imageSelection == null || view.imageSelection == "")
            {
                return;
            }
            PersistentData data = new PersistentData(SettingsLoader.GetCurrentSettingsData());

            for (int i = 0; i < data.imageData.Count; i++)
            {
                if (data.imageData[i].fileName == view.imageSelection)
                {
                    DataStructures.ImageData temp = data.imageData[i];
                    temp.banUse                = view.chkBxBanUse;
                    data.imageData[i]          = temp;
                    SettingsLoader.changedData = data;
                    SettingsLoader.UpdateSettings();
                }
            }
        }
Exemple #3
0
        private void ComboboxUpdated(object sender, SelectionChangedEventArgs args)
        {
            if (view.imageSelection == null || view.imageSelection == "")
            {
                return;
            }
            PersistentData data = new PersistentData(SettingsLoader.GetCurrentSettingsData());

            for (int i = 0; i < data.imageData.Count; i++)
            {
                if (data.imageData[i].fileName == view.imageSelection)
                {
                    DataStructures.ImageData temp = data.imageData[i];
                    temp.targetDaytime         = Helperfunctions.ConvertComboIntToDaytime(view.selectedItemDayTime);
                    temp.targetSeason          = Helperfunctions.ConvertComboIntToSeason(view.selectedItemSeason);
                    temp.targetWeather         = Helperfunctions.ConvertComboIntToWeather(view.selectedItemWeather);
                    data.imageData[i]          = temp;
                    SettingsLoader.changedData = data;
                    SettingsLoader.UpdateSettings();
                }
            }
        }
Exemple #4
0
        private void InitializeApp()
        {
            Scroll.Content = ImageCacheLoader.LoadImages();

            SettingsLoader.LoadSettingsFromDisk();
            PersistentData currentData = SettingsLoader.GetCurrentSettingsData();

            DisplaySettings(currentData);

            //weather data
            weatherHandler = new WeatherHandler(currentData.openWeatherMapAPIKey, currentData.plz);
            DispatcherTimer LiveTime = new DispatcherTimer();

            UpdateDataPeriodic(this, null); //show immediatly after application start, then start thread
            LiveTime.Interval = TimeSpan.FromSeconds(30);
            LiveTime.Tick    += UpdateDataPeriodic;
            LiveTime.Start();

            FillComboboxes();

            ImageChanger.StartImageCycling(weatherHandler);
        }
Exemple #5
0
        public void ImageClicked(Image sender)
        {
            string filePath = sender.Source.ToString();

            view.imageSelection = filePath;
            BitmapImage image = new BitmapImage();

            image.BeginInit();
            image.CacheOption = BitmapCacheOption.OnLoad;
            image.UriSource   = new Uri(filePath);
            image.EndInit();
            SelectedImageBox.Source = image;
            PersistentData data = SettingsLoader.GetCurrentSettingsData();

            for (int i = 0; i < data.imageData.Count(); i++)
            {
                if (data.imageData[i].fileName == filePath)
                {
                    //update displayed imagedata
                    view.selectedItemWeather = Helperfunctions.ConvertWeatherEnumToComboInt(data.imageData[i].targetWeather);
                    view.selectedItemDayTime = Helperfunctions.ConvertDayTimeToComboInt(data.imageData[i].targetDaytime);
                    view.selectedItemSeason  = Helperfunctions.ConvertSeasonToComboInt(data.imageData[i].targetSeason);
                    view.chkBxBanUse         = data.imageData[i].banUse;
                    return;
                }
            }

            //file has no data yet, write entry
            DataStructures.ImageData newEntry = new DataStructures.ImageData();
            newEntry.fileName      = filePath;
            newEntry.targetDaytime = DataStructures.enumDayTime.DAWN;
            newEntry.targetSeason  = DataStructures.enumSeason.SPRING;
            newEntry.targetWeather = DataStructures.enumWeather.CLEAR_SKY;
            newEntry.banUse        = false;
            data.imageData.Add(newEntry);
            SettingsLoader.changedData.imageData = data.imageData;
            SettingsLoader.UpdateSettings();
            ImageClicked(sender);
        }
        private static void ThreadRun()
        {
            try
            {
                while (true)
                {
                    WeatherData    currentWeather  = weatherHandler.GetCurrentWeatherData();
                    DateTime       now             = DateTime.Now;
                    PersistentData currentSettings = SettingsLoader.GetCurrentSettingsData();

                    //check if transition allowed
                    if ((bool)currentSettings.changeInBackground)
                    {
                        if (!AppFocus.OtherAppIsInFullScreen())
                        {
                            Wait();
                            continue;
                        }
                    }

                    DataStructures.ImageData[] images = currentSettings.imageData.ToArray();

                    DataStructures.enumDayTime targetDayTime = Helperfunctions.ConvertTimeToDayTime(now, currentWeather);
                    DataStructures.enumSeason  targetSeason  = Helperfunctions.ConvertDateToEnumSeason(now);
                    DataStructures.enumWeather targetWeather = Helperfunctions.ConvertOWMDescrToWeather(currentWeather.data.weather[0].description);

                    //filter images to new list after priority
                    //importance desc: season, daytime, weather
                    List <DataStructures.ImageData> filteredImages = new List <DataStructures.ImageData>();
                    for (int ignorance = 0; ignorance <= 3; ignorance++)
                    {
                        for (int i = 0; i < images.Length; i++)
                        {
                            if (images[i].targetSeason == targetSeason)
                            {
                                if (images[i].targetDaytime == targetDayTime)
                                {
                                    if (images[i].targetWeather == targetWeather)
                                    {
                                        if (!images[i].banUse)
                                        {
                                            filteredImages.Add(images[i]);
                                        }
                                    }
                                    else if (ignorance > 0)
                                    {
                                        filteredImages.Add(images[i]);
                                    }
                                }
                                else if (ignorance > 1)
                                {
                                    filteredImages.Add(images[i]);
                                }
                            }
                            else if (ignorance > 2)
                            {
                                filteredImages.Add(images[i]);
                            }
                        }
                        if (filteredImages.Count > 0)
                        {
                            break;
                        }
                    }

                    if (filteredImages.Count == 0)
                    {
                        Wait();
                        continue;
                    }

                    //select random from filtered list
                    Random rnd      = new Random();
                    int    selected = rnd.Next(0, filteredImages.Count);

                    //change background
                    Uri wallFile = new Uri(filteredImages[selected].fileName);
                    Wallpaper.Set(wallFile, Wallpaper.Style.Stretched);

                    Wait();
                }
            } catch
            {
                return;
            }
        }