Beispiel #1
0
        private List<string> CreateImagesInfoBySimple()
        {
            var info = new List<string>();
            var store = Data.Storage.StorageFactory.GetStorage(TenantProvider.CurrentTenantID.ToString(), "photo");
            var storage = StorageFactory.GetStorage();

            var uid = SecurityContext.CurrentAccount.ID.ToString();
            var eventID = Request["events_selector"];

            var albums = storage.GetAlbums(Convert.ToInt64(eventID), uid);

            var currentAlbum = 0 < albums.Count ? albums[0] : null;

            if (currentAlbum == null)
            {
                var Event = storage.GetEvent(Convert.ToInt64(eventID));

                currentAlbum = new Album {Event = Event, UserID = uid};

                storage.SaveAlbum(currentAlbum);
            }
            var fileNamePath = PhotoConst.ImagesPath + uid + "/" + currentAlbum.Id + "/";

            var listFiles = store.ListFilesRelative("", fileNamePath, "*.*", false);

            for (var j = 0; j < Request.Files.Count; j++)
            {
                var file = Request.Files[j];

                if (file.ContentLength > SetupInfo.MaxUploadSize)
                    continue;

                if (string.IsNullOrEmpty(file.FileName))
                    continue;

                var currentImageInfo = new ImageInfo();

                var fileExtension = FileUtility.GetFileExtension(file.FileName);
                var fileNameWithOutExtension = FileUtility.GetFileName(file.FileName);
                var addSuffix = string.Empty;

                var i = 1;

                while (CheckFile(listFiles, fileNameWithOutExtension + addSuffix + PhotoConst.THUMB_SUFFIX + fileExtension))
                {
                    addSuffix = "(" + i.ToString() + ")";
                    i++;
                }

                var fileNameThumb = fileNamePath + fileNameWithOutExtension + addSuffix + PhotoConst.THUMB_SUFFIX + "." + PhotoConst.jpeg_extension;
                var fileNamePreview = fileNamePath + fileNameWithOutExtension + addSuffix + PhotoConst.PREVIEW_SUFFIX + "." + PhotoConst.jpeg_extension;


                currentImageInfo.Name = fileNameWithOutExtension;
                currentImageInfo.PreviewPath = fileNamePreview;
                currentImageInfo.ThumbnailPath = fileNameThumb;
                var fs = file.InputStream;

                try
                {
                    var reader = new EXIFReader(fs);
                    currentImageInfo.ActionDate = (string) reader[PropertyTagId.DateTime];
                }
                catch
                {
                }

                ImageHelper.GenerateThumbnail(fs, fileNameThumb, ref currentImageInfo, store);
                ImageHelper.GeneratePreview(fs, fileNamePreview, ref currentImageInfo, store);

                fs.Dispose();

                var image = new AlbumItem(currentAlbum)
                                {
                                    Name = currentImageInfo.Name,
                                    Timestamp = ASC.Core.Tenants.TenantUtil.DateTimeNow(),
                                    UserID = uid,
                                    Location = currentImageInfo.Name,
                                    PreviewSize = new Size(currentImageInfo.PreviewWidth, currentImageInfo.PreviewHeight),
                                    ThumbnailSize = new Size(currentImageInfo.ThumbnailWidth, currentImageInfo.ThumbnailHeight)
                                };

                storage.SaveAlbumItem(image);

                currentAlbum.FaceItem = image;

                storage.SaveAlbum(currentAlbum);

                info.Add(image.Id.ToString());
            }

            return info;
        }
Beispiel #2
0
        public override FileUploadResult ProcessUpload(HttpContext context)
        {
            if (!ASC.Core.SecurityContext.AuthenticateMe(CookiesManager.GetCookies(CookiesType.AuthKey)))
            {
                return new FileUploadResult
                           {
                               Success = false,
                               Message = "Permission denied"
                           };
            }

            var result = "";

            try
            {
                if (ProgressFileUploader.HasFilesToUpload(context))
                {
                    var postedFile = new ProgressFileUploader.FileToUpload(context);
                    var fileName = postedFile.FileName;
                    var inputStream = postedFile.InputStream;


                    var store = Data.Storage.StorageFactory.GetStorage(TenantProvider.CurrentTenantID.ToString(), "photo");
                    var storage = StorageFactory.GetStorage();

                    var uid = context.Request["uid"];
                    var eventID = context.Request["eventID"];

                    var albums = storage.GetAlbums(Convert.ToInt64(eventID), uid);

                    var currentAlbum = 0 < albums.Count ? albums[0] : null;

                    if (currentAlbum == null)
                    {
                        var Event = storage.GetEvent(Convert.ToInt64(eventID));

                        currentAlbum = new Album
                                           {
                                               Event = Event,
                                               UserID = uid
                                           };

                        storage.SaveAlbum(currentAlbum);
                    }

                    if (context.Session["photo_albumid"] != null)
                    {
                        context.Session["photo_albumid"] = currentAlbum.Id;
                    }

                    var fileNamePath = PhotoConst.ImagesPath + uid + "/" + currentAlbum.Id + "/";

                    var currentImageInfo = new ImageInfo();

                    var listFiles = store.ListFilesRelative("", fileNamePath, "*.*", false);
                    context.Session["photo_listFiles"] = listFiles;

                    var fileExtension = FileUtility.GetFileExtension(fileName);
                    var fileNameWithOutExtension = GetFileName(fileName);
                    var addSuffix = string.Empty;

                    //if file already exists
                    var i = 1;

                    while (CheckFile(listFiles, fileNameWithOutExtension + addSuffix + PhotoConst.THUMB_SUFFIX + fileExtension))
                    {
                        addSuffix = "(" + i.ToString() + ")";
                        i++;
                    }

                    var fileNameThumb = fileNamePath + fileNameWithOutExtension + addSuffix + PhotoConst.THUMB_SUFFIX + "." + PhotoConst.jpeg_extension;
                    var fileNamePreview = fileNamePath + fileNameWithOutExtension + addSuffix + PhotoConst.PREVIEW_SUFFIX + "." + PhotoConst.jpeg_extension;

                    currentImageInfo.Name = fileNameWithOutExtension;
                    currentImageInfo.PreviewPath = fileNamePreview;
                    currentImageInfo.ThumbnailPath = fileNameThumb;

                    var fs = inputStream;

                    try
                    {
                        var reader = new EXIFReader(fs);
                        currentImageInfo.ActionDate = (string) reader[PropertyTagId.DateTime];
                    }
                    catch
                    {
                    }

                    ImageHelper.GenerateThumbnail(fs, fileNameThumb, ref currentImageInfo, store);
                    ImageHelper.GeneratePreview(fs, fileNamePreview, ref currentImageInfo, store);

                    fs.Dispose();

                    var image = new AlbumItem(currentAlbum)
                                    {
                                        Name = currentImageInfo.Name,
                                        Timestamp = ASC.Core.Tenants.TenantUtil.DateTimeNow(),
                                        UserID = uid,
                                        Location = currentImageInfo.Name,
                                        PreviewSize = new Size(currentImageInfo.PreviewWidth, currentImageInfo.PreviewHeight),
                                        ThumbnailSize = new Size(currentImageInfo.ThumbnailWidth, currentImageInfo.ThumbnailHeight)
                                    };

                    storage.SaveAlbumItem(image);

                    currentAlbum.FaceItem = image;
                    storage.SaveAlbum(currentAlbum);

                    var response = image.Id.ToString();

                    var byteArray = System.Text.Encoding.UTF8.GetBytes(response);
                    result = Convert.ToBase64String(byteArray);
                }

            }
            catch (Exception ex)
            {
                return new FileUploadResult
                           {
                               Success = false,
                               Message = ex.Message,
                           };
            }

            return new FileUploadResult
                       {
                           Success = true,
                           Data = "",
                           Message = result
                       };
        }
Beispiel #3
0
        protected void Page_Load(object sender, EventArgs e)
        {            
            try
            {
                // Get the data
                HttpPostedFile jpeg_image_upload = Request.Files["Filedata"];
                IDataStore store = StorageFactory.GetStorage(TenantProvider.CurrentTenantID.ToString(), "photo");
                var storage = ASC.PhotoManager.Model.StorageFactory.GetStorage();
                   
                string uid = Request["uid"];
                string eventID = Request["eventID"];
                
                bool clearSession = false;

                Album currentAlbum = null;
                
                var albums = storage.GetAlbums(Convert.ToInt64(eventID), uid);
                    clearSession = true;

                    currentAlbum = 0 < albums.Count ? albums[0] : null;

                    if (currentAlbum == null)
                    {
                        Event Event = storage.GetEvent(Convert.ToInt64(eventID));

                        currentAlbum = new Album();
                        currentAlbum.Event = Event;
                        currentAlbum.UserID = uid;

                        storage.SaveAlbum(currentAlbum);
                    }

                    if (Session["photo_albumid"] != null)
                    {
                        if (currentAlbum.Id != (long)Session["photo_albumid"])
                            clearSession = true;
                        Session["photo_albumid"] = currentAlbum.Id;
                    }
                    else
                        clearSession = true;

                string fileNamePath = Resources.PhotoManagerResource.ImagesPath + uid + "/" + currentAlbum.Id + "/";

                ImageInfo currentImageInfo = new ImageInfo();
                string[] listFiles;

                if (Session["photo_listFiles"] != null && !clearSession)
                    listFiles = (string[])Session["photo_listFiles"];
                else
                {
                    listFiles = store.ListFilesRelative("", fileNamePath, "*.*", false);
                    Session["photo_listFiles"] = listFiles;
                }

                string fileExtension = GetFileExtension(jpeg_image_upload.FileName);
                string fileNameWithOutExtension = GetFileName(jpeg_image_upload.FileName);
                string addSuffix = string.Empty;

                
                //if file already exists
                int i = 1;

                while (CheckFile(listFiles, fileNameWithOutExtension + addSuffix + Constants.THUMB_SUFFIX + fileExtension))
                {
                    addSuffix = "(" + i.ToString() + ")";
                    i++;
                }

                string fileNameThumb = fileNamePath + fileNameWithOutExtension + addSuffix + Constants.THUMB_SUFFIX + "." + Constants.jpeg_extension;
                string fileNamePreview = fileNamePath + fileNameWithOutExtension + addSuffix + Constants.PREVIEW_SUFFIX + "." + Constants.jpeg_extension;
                                

                currentImageInfo.Name = fileNameWithOutExtension;
                currentImageInfo.PreviewPath = fileNamePreview;
                currentImageInfo.ThumbnailPath = fileNameThumb;


                Stream fs = jpeg_image_upload.InputStream;
                
                try
                {
                    EXIFReader reader = new EXIFReader(fs);
                    currentImageInfo.ActionDate = (string)reader[PropertyTagId.DateTime];
                }
                catch { }

                ImageHelper.GenerateThumbnail(fs, fileNameThumb, ref currentImageInfo, store);
                ImageHelper.GeneratePreview(fs, fileNamePreview, ref currentImageInfo, store);

                fs.Dispose();

                AlbumItem image = new AlbumItem(currentAlbum);
                image.Name = currentImageInfo.Name;
                image.Timestamp = ASC.Core.Tenants.TenantUtil.DateTimeNow();
                image.UserID = uid;

                image.Location = currentImageInfo.Name;
                

                image.PreviewSize = new Size(currentImageInfo.PreviewWidth, currentImageInfo.PreviewHeight);
                image.ThumbnailSize = new Size(currentImageInfo.ThumbnailWidth, currentImageInfo.ThumbnailHeight);

                storage.SaveAlbumItem(image);

                currentAlbum.FaceItem = image;
                storage.SaveAlbum(currentAlbum);

                string response = image.Id.ToString();

                byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(response);
                string encodingResponse = Convert.ToBase64String(byteArray);

                
                Response.StatusCode = 200;
                Response.Write(encodingResponse);
            }
            catch
            {
                // If any kind of error occurs return a 500 Internal Server error
                Response.StatusCode = 500;
                Response.Write("An error occured");
                Response.End();
            }
            finally
            {
                Response.End();
            }
        }