示例#1
0
        LoginImage GetLoginImage()
        {
            LoginImage image = HttpContext.Cache[ImageCacheName] as LoginImage;

            if (image == null)
            {
                lock (ImageCacheName)
                {
                    if (image == null)
                    {
                        LoginImageManager manager = new LoginImageManager();
                        image = manager.GetLastLoginImage();
                        if (image != null)
                        {
                            DateTime overdueTime;
                            if (image.EndDate.HasValue && image.EndDate.Value.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd"))
                            {
                                overdueTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 01:00:00")).AddDays(1);
                            }
                            else
                            {
                                overdueTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:00:00")).AddHours(1);
                            }
                            HttpContext.Cache.Insert(ImageCacheName, image, null, overdueTime, Cache.NoSlidingExpiration);
                        }
                    }
                }
            }
            return(image);
        }
示例#2
0
        public ActionResult BGImage()
        {
            LoginImage image = HttpContext.Cache[ImageCacheName] as LoginImage;

            if (image != null)
            {
                return(File(image.ImageData, "image/jpeg"));
            }
            else
            {
                return(File("~/Content/images/bingImage.jpg", "image/jpeg"));
            }
        }
示例#3
0
        public ActionResult SaveImage(LoginImage image)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }

            if (!String.IsNullOrEmpty(image.ImageUrl))
            {
                string imagePath = HostingEnvironment.ApplicationPhysicalPath + Path.Combine(image.ImageUrl.Split('/'));
                image.ImageUrl = null;
                if (System.IO.File.Exists(imagePath))
                {
                    using (Image tempImage = Image.FromFile(imagePath))
                    {
                        using (Bitmap bitmap = new Bitmap(tempImage, new Size(1366, 768)))
                        {
                            using (MemoryStream mem = new MemoryStream())
                            {
                                bitmap.Save(mem, ImageFormat.Jpeg);
                                image.ImageData = mem.ToArray();
                            }
                        }
                    }
                    System.IO.File.Delete(imagePath);
                }
            }

            bool flag             = image.BingImageId == Guid.Empty;
            LoginImageManager lim = new LoginImageManager();
            var result            = lim.SaveLoginImage(image);

            if (flag && result)
            {
                AccountController.RemoveLoginImageCache(HttpContext);
            }

            string jsonData = Newtonsoft.Json.JsonConvert.SerializeObject(
                new { Result = result, Data = image });

            return(Content(jsonData, "application/json"));
        }