Esempio n. 1
0
        public static void DownloadTodayBingImages()
        {
            if (!NetworkStatus.IsConnectedToInternet())
            {
                "The internet connection was not found.".LogText();
                return;
            }

            var dir = DirUtils.GetImagesDir();

            Enumerable.Range(start: 0, count: 9).AsParallel().ForAll(imageIndex =>
            {
                try
                {
                    var source = $"http://www.bing.com/HPImageArchive.aspx?format=xml&idx={imageIndex}&n=1&mkt=en-US";
                    downloadImage(source, dir, xml =>
                    {
                        var bingImage = xml.FromXmlContent <images>();
                        return(new ImageInfo
                        {
                            Url = $"http://www.bing.com{bingImage.image.url.Replace("_1366x768.jpg", "_1920x1080.jpg")}",
                            Copyright = bingImage.image.copyright
                        });
                    });
                }
                catch (Exception ex)
                {
                    ex.LogException();
                }
            });
        }
Esempio n. 2
0
        public static void SetTodayWallpapaer()
        {
            var dir = DirUtils.GetImagesDir();
            var lastDownalodResult = getImage(dir);
            var imagePath          = lastDownalodResult?.ImageFileName;

            if (string.IsNullOrWhiteSpace(imagePath) || !File.Exists(imagePath))
            {
                Console.WriteLine($"{imagePath} not found.");
                return;
            }

            using (var renderer = new PersianCalendarRenderer(imageFileName: imagePath)
            {
                Holidays = HolidaysReader.GetHolidays(),
                CopyrightText = lastDownalodResult.Copyright,
                TodayColor = Color.DarkRed,
                CopyrightFontName = AppConfig.CopyrightFontName,
                CopyrightFontSize = AppConfig.CopyrightFontSize,
                CalendarFontFileName = AppConfig.CalendarFontFileName,
                CalendarFontSize = AppConfig.CalendarFontSize,
                HolidaysFontSize = AppConfig.HolidaysFontSize,
                ShowPastHolidays = AppConfig.ShowPastHolidays
            })
            {
                using (var bitmap = renderer.DrawThisMonthsCalendar())
                {
                    string wallpaper;
                    if (WindowsVersion.IsWindows8Plus)
                    {
                        const string wallpaperFileName = "_wallpaper.png";
                        wallpaper = Path.Combine(dir, wallpaperFileName);
                        bitmap.Save(wallpaper, ImageFormat.Png);
                    }
                    else
                    {
                        const string wallpaperFileName = "_wallpaper.bmp";
                        wallpaper = Path.Combine(dir, wallpaperFileName);
                        bitmap.Save(wallpaper, ImageFormat.Bmp);
                    }

                    NativeMethods.SetWallpaper(wallpaper);
                    NativeMethods.SetLockScreenImage(wallpaper);
                }
            }
        }