示例#1
0
        static void Main(string[] args)
        {
            //Log.Get().Info("Hi~~");

            BingImageManager imageManager = new BingImageManager("cn.bing.com", "China");

            Console.WriteLine(imageManager.ContainsTodayBingImage());
            Console.ReadLine();
            Console.WriteLine(imageManager.SaveTodayBingImage());
            //UIBingImage image = imageManager.GetLastBingImage();
            //Console.WriteLine(image.ImageName);
            //using (FileStream fs = new FileStream("D:\\" + image.ImageName + ".jpg", FileMode.Create))
            //{
            //    fs.Write(image.ImageData, 0, image.ImageData.Length);
            //}
        }
示例#2
0
        protected override void OnStart(string[] args)
        {
            BingImageManager bingManager = new BingImageManager("cn.bing.com", "China");

            timer = new Timer(stateInfo =>
            {
                BingImageManager manager = (BingImageManager)stateInfo;
                bool result = false;
                try
                {
                    Log.Get().Info("开始检查bing图片下载情况!");
                    if (!bingManager.ContainsTodayBingImage())
                    {
                        Log.Get().Info("开始下载!");
                        result = bingManager.SaveTodayBingImage();
                    }
                }
                catch (Exception exception)
                {
                    Log.Get().Error("下载bing图片出现错误!", exception);
                }
                finally
                {
                    DateTime after;
                    if (result)
                    {
                        after = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 00:05:00")).AddDays(1);
                    }
                    else
                    {
                        after = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:00:00")).AddHours(1);
                    }
                    TimeSpan time = after - DateTime.Now;
                    timer.Change(time, TimeSpan.Zero);
                }
            }, bingManager, TimeSpan.Zero, TimeSpan.Zero);
        }