Пример #1
0
        private void LoadImage(object sender, RoutedEventArgs e)
        {
            Image img = sender as Image;

            img.Stretch = Stretch.Fill;
            img.Source  = new BitmapImage(new Uri(BingUtils.LOCAL_IMAGE_FILE_JPG, UriKind.RelativeOrAbsolute));
            img.Stretch = Stretch.UniformToFill;

            BingObject bingObject = BingUtils.ReadConfig();

            if (bingObject.images != null)
            {
                string info = bingObject.images.FirstOrDefault()?.copyright;
                if (info != null)
                {
                    copyright_window.Text = Regex.Match(info, @"\(([^)]*)\)").Groups[1].Value;
                    title_window.Text     = info.Replace(Regex.Match(info, @"\(([^)]*)\)").Groups[0].Value, "");

                    System.Threading.Tasks.Task.Run(async() =>
                    {
                        await BingUtils.SetBingWallpaperAsync();
                    }).Wait();

                    if (bingObject.config != null && bingObject.config.setLockScreen)
                    {
                        System.Threading.Tasks.Task.Run(async() =>
                        {
                            await BingUtils.SetBingWallpaperLockScreenAsync();
                        }).Wait();
                    }
                }
            }
        }
Пример #2
0
        public SettingsPage()
        {
            BingObject bingObject = BingUtils.ReadConfig();

            this.InitializeComponent();
            this.DataContext = this;

            if (bingObject?.config != null)
            {
                defaultLanguage      = bingObject.config.languageOptions.Name;
                defaultPeriod        = bingObject.config.period;
                defaultRunAtStartup  = bingObject.config.runAtStartup;
                defaultSetWallpaper  = bingObject.config.setWallpaper;
                defaultSetLockScreen = bingObject.config.setLockScreen;
            }
            else
            {
                defaultLanguage      = CultureInfo.CurrentCulture.Name;
                defaultPeriod        = "Every Day";
                defaultRunAtStartup  = true;
                defaultSetWallpaper  = true;
                defaultSetLockScreen = true;
            }

            cmbLocation.ItemsSource  = LanguageOptions;
            cmbExecution.ItemsSource = ExecutionPeriods;

            cmbLocation.SelectedIndex  = LanguageOptions.IndexOf(LanguageOptions.Where(p => p.Name == defaultLanguage).ToList().FirstOrDefault());
            cmbExecution.SelectedIndex = executionPeriods.IndexOf(defaultPeriod);

            RunAtStartup_Box.IsChecked  = defaultRunAtStartup;
            SetWallpaper_Box.IsChecked  = defaultSetWallpaper;
            SetLockScreen_Box.IsChecked = defaultSetLockScreen;
        }
Пример #3
0
        private static BingObject DownloadBingConfigFile(string location)
        {
            BingObject newBingObject = null, actualBingObject = null;
            string     json = string.Empty;

            try
            {
                string url = string.Format("{0}{1}", BING_IMG_URL_JSON, location);
                if (Utils.IsInternetAvailable())
                {
                    var myClient  = new HttpClient();
                    var myRequest = new HttpRequestMessage(HttpMethod.Get, url);
                    var response  = myClient.SendAsync(myRequest).Result.Content.ReadAsStringAsync().Result;
                    newBingObject = JsonConvert.DeserializeObject <BingObject>(response);
                    if (File.Exists(LOCAL_CONFIGURATION_FILE_JSON))
                    {
                        string fileJson = File.ReadAllText(LOCAL_CONFIGURATION_FILE_JSON);
                        actualBingObject     = JsonConvert.DeserializeObject <BingObject>(fileJson);
                        newBingObject.config = actualBingObject.config;
                        File.Delete(LOCAL_CONFIGURATION_FILE_JSON);
                    }
                    File.WriteAllText(LOCAL_CONFIGURATION_FILE_JSON, JsonConvert.SerializeObject(newBingObject));
                }
                else
                {
                    throw new WebException("Internet connection is not available");
                }
            }
            catch (Exception ex)
            {
                //Fallo en la red, obtenemos el temporal
                WriteInBingWallpaperLog(ex.Message);
            }
            return(newBingObject);
        }
Пример #4
0
        public static BingObject ReadConfig()
        {
            BingObject result = null;

            if (File.Exists(LOCAL_CONFIGURATION_FILE_JSON))
            {
                string fileJson = File.ReadAllText(LOCAL_CONFIGURATION_FILE_JSON);
                result = JsonConvert.DeserializeObject <BingObject>(fileJson);
            }
            return(result);
        }
Пример #5
0
        public static BingObject GetWallpaperFromBing(string location)
        {
            BingObject result = null;

            try
            {
                result = DownloadBingConfigFile(location);
                if (result != null)
                {
                    DownloadImageFile(string.Format("{0}{1}{2}", BING_URL, result?.images?.FirstOrDefault()?.urlbase, BING_RESOLUTION));
                }
            }
            catch (Exception ex) {
                WriteInBingWallpaperLog(ex.Message);
            }
            return(result);
        }
Пример #6
0
        public MainPage()
        {
            BingObject bingObject = BingUtils.GetWallpaperFromBing("ES-es");

            this.InitializeComponent();

            var coreTitleBar = CoreApplication.GetCurrentView().TitleBar;

            Window.Current.SetTitleBar(AppTitle);
            coreTitleBar.ExtendViewIntoTitleBar = true;

            //remove the solid-colored backgrounds behind the caption controls and system back button
            var viewTitleBar = ApplicationView.GetForCurrentView().TitleBar;

            viewTitleBar.ButtonBackgroundColor         = Colors.Transparent;
            viewTitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
            viewTitleBar.ButtonForegroundColor         = (Color)Resources["SystemBaseHighColor"];

            UpdateAppTitle();
            Window.Current.CoreWindow.SizeChanged += (s, e) => UpdateAppTitle();
            coreTitleBar.LayoutMetricsChanged     += (s, e) => UpdateAppTitle();

            ContentFrame.Navigate(typeof(BingPage));
        }