Example #1
0
        static void Main(string[] args)
        {
            BingDownloader   bd     = new BingDownloader("cn.bing.com", 0, 1);
            List <BingImage> images = bd.GetImage(0, 1);

            foreach (BingImage image in images)
            {
                Console.WriteLine(image.Messages[0].Text);
                foreach (Hotspot spot in image.Hotspots)
                {
                    Console.WriteLine(spot.Discription);
                }
                image.Image.Save("c:\\bingImage.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            Console.Read();
        }
Example #2
0
        public bool SaveTodayBingImage()
        {
            List <BingImage> images = null;

            try
            {
                images = downloader.GetImage(1, 1);
                if (images.Count == 0)
                {
                    return(false);
                }
                BingImage   image   = images[0];
                UIBingImage uiImage = BingImageToUIBingImage(image);
                using (DbConnection conn = Connection)
                {
                    conn.Open();
                    DbCommand cmd = conn.CreateCommand();
                    cmd.CommandText = "INSERT INTO [sys_LoginImages] VALUES (@BingImageId, @StartDate, @EndDate, @Copyright, @ImageName, @BingHost, @ImageUrl, @ImageData, @Hotspots, @Messages)";
                    cmd.CommandType = CommandType.Text;

                    DbParameter param = new SqlParameter("@BingImageId", DbType.Guid);
                    param.Value = uiImage.BingImageId;
                    cmd.Parameters.Add(param);
                    param       = new SqlParameter("@StartDate", DbType.DateTime);
                    param.Value = uiImage.StartDate;
                    cmd.Parameters.Add(param);
                    param       = new SqlParameter("@EndDate", DbType.DateTime);
                    param.Value = uiImage.EndDate;
                    cmd.Parameters.Add(param);
                    param       = new SqlParameter("@Copyright", DbType.String);
                    param.Value = uiImage.Copyright;
                    cmd.Parameters.Add(param);
                    param       = new SqlParameter("@ImageName", DbType.String);
                    param.Value = uiImage.ImageName;
                    cmd.Parameters.Add(param);
                    param       = new SqlParameter("@BingHost", DbType.String);
                    param.Value = uiImage.BingHost;
                    cmd.Parameters.Add(param);
                    param       = new SqlParameter("@ImageUrl", DbType.String);
                    param.Value = uiImage.ImageUrl;
                    cmd.Parameters.Add(param);
                    param       = new SqlParameter("@ImageData", DbType.Binary);
                    param.Value = uiImage.ImageData;
                    cmd.Parameters.Add(param);
                    param       = new SqlParameter("@Hotspots", DbType.String);
                    param.Value = uiImage.Hotspots;
                    cmd.Parameters.Add(param);
                    param       = new SqlParameter("@Messages", DbType.String);
                    param.Value = uiImage.Messages;
                    cmd.Parameters.Add(param);

                    int val = cmd.ExecuteNonQuery();
                    return(val == 1);
                }
            }
            catch (Exception e)
            {
                Logging.Log.Get().Current.Error("保存出现错误", e);
                return(false);
            }
        }