コード例 #1
0
ファイル: MainForm.cs プロジェクト: gookee/bing-wallpaper
        private async System.Threading.Tasks.Task UpdateWallpaper()
        {
            if (CurrentWallpaper != null)
            {
                try
                {
                    var img = await CurrentWallpaper.getImage();

                    Wallpaper.Set(img, Wallpaper.Style.Stretched);
                }
                catch { }
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: w8w8w8/bing-wallpaper
        /// <summary>
        /// 随机壁纸
        /// </summary>
        public async void SetRandomWallpaper()
        {
            try
            {
                var bingImg = HistoryImageProvider.getRandom();
                var img     = await bingImg.getImage();

                Wallpaper.Set(img, Wallpaper.Style.Stretched);
                _currentWallpaper = bingImg;
                ShowSetWallpaperNotification();
            }
            catch (Exception ex)
            {
                ShowErrorNotification();
            }
        }
コード例 #3
0
        /// <summary>
        /// SetWallpaper fetches the wallpaper from Bing and sets it
        /// </summary>
        public async void SetWallpaper()
        {
            try
            {
                var bingImg = await _provider.GetImage();

                Wallpaper.Set(bingImg.Img, Wallpaper.Style.Stretched);
                _currentWallpaper = bingImg.Img;
                SetCopyrightTrayLabel(bingImg.Copyright, bingImg.CopyrightLink);

                ShowSetWallpaperNotification();
            }
            catch
            {
                ShowErrorNotification();
            }
        }
コード例 #4
0
        static void Main(string[] args)
        {
            Wallpaper wallpaper = new Wallpaper();

            Console.WriteLine("检测是否已经下载过壁纸……");
            if (!wallpaper.Exists)
            {
                Console.WriteLine("正在下载壁纸……");
                wallpaper.Download("HPImageArchive.aspx?format=js&idx=0&n=1");
                Console.WriteLine("壁纸下载成功,正在更改壁纸……");
                wallpaper.SetWindowsWallpaper();
            }
            else
            {
                Console.WriteLine("今日壁纸已经下载过了");
            }
        }
コード例 #5
0
ファイル: MainForm.cs プロジェクト: w8w8w8/bing-wallpaper
        /// <summary>
        /// 获取最新壁纸
        /// </summary>
        public async void SetWallpaper()
        {
            try
            {
                var bingImg = await _provider.GetLatestImage();

                var img = await bingImg.getImage();

                Wallpaper.Set(img, Wallpaper.Style.Stretched);
                _currentWallpaper = bingImg;
                ShowSetWallpaperNotification();

                // 保存到历史记录
                HistoryImageProvider.AddImage(bingImg);
            }
            catch
            {
                ShowErrorNotification();
            }
        }
コード例 #6
0
        private static void Main(string[] args)
        {
            var systemTray = new SystemTray("BingWallpaper");

            var index = Rnd.Next(0, 8);

            systemTray.ShowBalloon($"Set {index} of 8");
            var file = GetImage(index);

            Logger.Info($"Current: {Wallpaper.GetBackgroud()}");
            Wallpaper.SetBackgroud(file);

            if (systemTray.TrayIcon != null)
            {
                systemTray.TrayIcon.Visible = false;
                systemTray.TrayIcon.Dispose();
            }

            Application.Exit();
        }
コード例 #7
0
        //Config End

        private void Run()
        {
            ReadConfig();
            _bingApi.Time     = _time;
            _bingApi.Location = _location;
            try
            {
                _bingApi.Init();
                String localImagePath = DownloadImage();
                Console.WriteLine("开始设置壁纸:" + localImagePath);
                Wallpaper.Set(localImagePath, Wallpaper.Style.Stretched);
                Console.WriteLine("设置壁纸成功");
            }
            catch (WebException e)
            {
                Console.WriteLine("网络连接失败,请连接网络后重试。");
            }
            catch (Exception e)
            {
                Console.WriteLine("程序运行发生异常:" + e.Message);
            }
        }
コード例 #8
0
ファイル: FormMain.cs プロジェクト: jamie-mh/BingWallpaper
        private async Task SetWallpaper(int index, bool silent = false)
        {
            var image = _bingClient.Images[index];
            var path  = Path.Combine(Path.GetTempPath(), "wallpaper.jpg");

            try
            {
                await _bingClient.DownloadImage(image, path);
            }
            catch
            {
                if (!silent)
                {
                    ShowNetworkError(() => buttonSetWallpaper_Click(), () => {
                        buttonSetWallpaper.Enabled = true;
                    });
                }

                return;
            }

            Wallpaper.SetStyle(Wallpaper.Style.Fill);
            Wallpaper.SetPath(path);
        }