示例#1
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                // Prepare parameters
                UploadParameters parameters = GetParametersFromRequest(context);
                if (!VerifyTicket(parameters.RequestToken, parameters.Ticket))
                {
                    throw new Exception("No valid ticket for this request was found.");
                }

                // Check request content length and actual stream length
                // If they're not equal, it means the client canceled the uploading
                bool lengthsMatched = context.Request.ContentLength == context.Request.InputStream.Length;
                if (!lengthsMatched)
                {
                    return;
                }

                var    storage     = SharpBoxSupport.OpenDropBoxStorage();
                var    newFileName = ObjectId.GenerateNewId() + parameters.FileExtension;
                string downloadURI = UploadDownlaodable(context, storage, newFileName, parameters.AlbumId);
                string photoURI    = UploadPhoto(context, storage, newFileName, parameters.AlbumId);
                string thumbURI    = UploadThumbnail(context, storage, newFileName, parameters.AlbumId);
                storage.Close();

                string[] coverURIs = AlbumRepository.UpdateCover(parameters.AlbumId, thumbURI);
                Photo    photo     = new Photo()
                {
                    PhotoURI    = photoURI,
                    ThumbURI    = thumbURI,
                    DownloadURI = downloadURI,
                    AlbumId     = parameters.AlbumId,
                    CreatedBy   = parameters.User
                };
                PhotoRepository.CreatePhoto(photo);
                context.Response.Write(string.Join(";", coverURIs));
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
                context.Request.InputStream.Close();
                context.Response.Write("error");
            }
        }
示例#2
0
        public void CreateAlbum(Album album)
        {
            ServiceSupport.AuthorizeAndExecute(() =>
            {
                album.CreatedBy = HttpContext.Current.User.Identity.Name;
                var albumId     = AlbumRepository.SaveAlbum(album);

                // We just try to create folders. Sometimes this may fail
                // but we don't need to tell users anything wrong because
                // these folders will be created (if necessary) when users upload photos.
                try
                {
                    var storage = SharpBoxSupport.OpenDropBoxStorage();
                    storage.CreateFoldersForAlbum(albumId);
                    storage.Close();
                }
                catch (Exception ex)
                {
                    Logger.Error(ex.ToString());
                }
            });
        }