public void ImageAsync(int id, ResizeMode? type, int? size)
        {
            AsyncManager.OutstandingOperations.Increment();
            Task.Factory.StartNew(() =>
            {
                using (var service = new PhotosService())
                {
                    var photo = service.GetPhoto(id);
                    if (photo == null)
                        return;

                    // 此処から始まる処理が概ねファイルアクセスで競合エラー起きる
                    // originalとoptimizeへのアクセスがサムネイルとプレビューで同時に発生するから
                    // ファイルアクセスが追いついてないみたい。
                    // なので、この2ファイルに関してはちょっと早めに処理するか、排他制御出来るように
                    // 制御しましょう。
                    Stream image;
                    //try
                    {
                        image = service.GetImage(photo, type ?? ResizeMode.Optimize, size ?? 0);
                    }
                    //catch{}
                    AsyncManager.Parameters["image"] = image;
                    AsyncManager.Parameters["contentType"] = photo.ContentType;
                    AsyncManager.OutstandingOperations.Decrement();
                }
            });
        }
Exemple #2
0
        public ActionResult Index(string id, int size = 100)
        {
            using (var service = new PhotosService())
            {
                var model = new Paging<Tag>
                                {
                                    Items =
                                        service.RecentTags(size)
                                        .Select(t => new Tag(t)),
                                    Total = -1
                                };

                return View(model);
            }
        }
        public ActionResult Create(Photo photo)
        {
            var enable = bool.Parse(ConfigurationManager.AppSettings["Enable.Upload"] ?? "false");
            if (!enable)
                return new HttpStatusCodeResult(406);

            using (var service = new PhotosService())
            {
                var model = photo.ToModel();
                if (ModelState.IsValid)
                {
                    var path = StorageSettings.BasePath("Storage.Uploading");
                    model.ImportTags(MvcPhotos.Models.Tag.ToTags(photo.InputTags.Split(' ')));
                    service.Append(model, path, photo.File);

                    // 保存
                    TempData[CreateMessage] = "登録しました";
                    return Redirect(Url.UaRouteUrl("Default", new {action = "Create"}));
                }
            }
            return View();
        }
 public ActionResult Index(int last = 0, int size = 100)
 {
     using (var service = new PhotosService())
     {
         var model = new Paging<Photo>
                         {
                             Items = service.RecentPhotos(last, size).Select(m => new Photo(m)),
                             Total = -1
                         };
         return View(model);
     }
 }
        public ActionResult Tags(string id, int last = 0, int size = 100)
        {
            using (var service = new PhotosService())
            {
                var model = new Paging<Photo>
                                {
                                    Items = service.TagPhotos(id, last, size).Select(m => new Photo(m)),
                                    Total = -1
                                };

                return View("Index", model);
            }
        }