Exemplo n.º 1
0
        private void ConfigureControlsFirstTime()
        {
            //this.OkButtonIsVisible = false; // Instead, we'll use our own buttons inside the tab control.
            //this.CancelButtonIsVisible = false;
            this.OkButtonText   = Resources.GalleryServerPro.Task_Add_Objects_OK_Btn_Text;
            this.TaskHeaderText = Resources.GalleryServerPro.Task_Add_Objects_Header_Text;
            this.TaskBodyText   = Resources.GalleryServerPro.Task_Add_Objects_Body_Text;

            this.PageTitle = Resources.GalleryServerPro.Task_Add_Objects_Page_Title;

            ConfigureTabStrip();

            if (!HelperFunctions.IsFileAuthorizedForAddingToGallery("dummy.zip", GalleryId))
            {
                chkDoNotExtractZipFile.Enabled  = false;
                chkDoNotExtractZipFile.CssClass = "gsp_disabledtext";
            }

            if (GallerySettings.DiscardOriginalImageDuringImport)
            {
                chkDiscardOriginal.Checked  = true;
                chkDiscardOriginal.Enabled  = false;
                chkDiscardOriginal.CssClass = "gsp_disabledtext";
            }

            HttpContext.Current.Session.Remove(GlobalConstants.SkippedFilesDuringUploadSessionKey);
            MediaObjectHashKeys.Clear();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds the uploaded files to the gallery. This method is called when the application is operating under full trust. In this case,
        /// the ComponentArt Upload control is used. The logic is nearly identical to that in AddUploadedFilesLessThanFullTrust - the only
        /// differences are syntax differences arising from the different file upload control.
        /// </summary>
        /// <param name="files">The files to add to the gallery.</param>
        private void AddUploadedFilesForFullTrust(UploadedFileInfoCollection files)
        {
            // Clear the list of hash keys so we're starting with a fresh load from the data store.
            try
            {
                MediaObjectHashKeys.Clear();

                string albumPhysicalPath = this.GetAlbum().FullPhysicalPathOnDisk;

                HelperFunctions.BeginTransaction();

                UploadedFileInfo[] fileInfos = new UploadedFileInfo[files.Count];
                files.CopyTo(fileInfos, 0);
                Array.Reverse(fileInfos);

                foreach (UploadedFileInfo file in fileInfos)
                {
                    if (String.IsNullOrEmpty(file.FileName))
                    {
                        continue;
                    }

                    if ((System.IO.Path.GetExtension(file.FileName).Equals(".zip", StringComparison.OrdinalIgnoreCase)) && (!chkDoNotExtractZipFile.Checked))
                    {
                        #region Extract the files from the zipped file.

                        lock (file)
                        {
                            if (File.Exists(file.TempFileName))
                            {
                                using (ZipUtility zip = new ZipUtility(Util.UserName, RoleController.GetGalleryServerRolesForUser()))
                                {
                                    this._skippedFiles.AddRange(zip.ExtractZipFile(file.GetStream(), this.GetAlbum(), chkDiscardOriginalImage.Checked));
                                }
                            }
                            else
                            {
                                // When one of the files causes an OutOfMemoryException, this can cause the other files to disappear from the
                                // temp upload directory. This seems to be an issue with the ComponentArt Upload control, since this does not
                                // seem to happen with the ASP.NET FileUpload control. If the file doesn't exist, make a note of it and move on
                                // to the next one.
                                this._skippedFiles.Add(new KeyValuePair <string, string>(file.FileName, Resources.GalleryServerPro.Task_Add_Objects_Uploaded_File_Does_Not_Exist_Msg));
                                continue;                                 // Skip to the next file.
                            }
                        }

                        #endregion
                    }
                    else
                    {
                        #region Add the file

                        string filename = HelperFunctions.ValidateFileName(albumPhysicalPath, file.FileName);
                        string filepath = Path.Combine(albumPhysicalPath, filename);

#if DEBUG
                        TechInfoSystems.TracingTools.Tools.MarkSpot(string.Format(CultureInfo.CurrentCulture, "Attempting to move file {0} to {1}...", file.FileName, filepath));
#endif
                        lock (file)
                        {
                            if (File.Exists(file.TempFileName))
                            {
                                file.SaveAs(filepath);
                            }
                            else
                            {
                                // When one of the files causes an OutOfMemoryException, this can cause the other files to disappear from the
                                // temp upload directory. This seems to be an issue with the ComponentArt Upload control, since this does not
                                // seem to happen with the ASP.NET FileUpload control. If the file doesn't exist, make a note of it and move on
                                // to the next one.
                                this._skippedFiles.Add(new KeyValuePair <string, string>(file.FileName, Resources.GalleryServerPro.Task_Add_Objects_Uploaded_File_Does_Not_Exist_Msg));
                                continue;                                 // Skip to the next file.
                            }
                        }

                        try
                        {
                            IGalleryObject go = Factory.CreateMediaObjectInstance(filepath, this.GetAlbum());
                            GalleryObjectController.SaveGalleryObject(go);

                            if ((chkDiscardOriginalImage.Checked) && (go is Business.Image))
                            {
                                ((Business.Image)go).DeleteHiResImage();
                                GalleryObjectController.SaveGalleryObject(go);
                            }
                        }
                        catch (UnsupportedMediaObjectTypeException ex)
                        {
                            try
                            {
                                File.Delete(filepath);
                            }
                            catch (UnauthorizedAccessException) { }                             // Ignore an error; the file will end up getting deleted during cleanup maintenance

                            this._skippedFiles.Add(new KeyValuePair <string, string>(filename, ex.Message));
                        }

                        #endregion
                    }
                }

                HelperFunctions.CommitTransaction();
            }
            catch
            {
                HelperFunctions.RollbackTransaction();
                throw;
            }
            finally
            {
                // Delete the uploaded temporary files, as by this time they have been saved to the destination directory.
                foreach (UploadedFileInfo file in files)
                {
                    try
                    {
                        System.IO.File.Delete(file.TempFileName);
                    }
                    catch (UnauthorizedAccessException) { }                     // Ignore an error; the file will end up getting deleted during cleanup maintenance
                }

                // Clear the list of hash keys to free up memory.
                MediaObjectHashKeys.Clear();

                HelperFunctions.PurgeCache();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds the uploaded files to the gallery. This method is called when the application is operating at lesss than full trust. In this case,
        /// the ASP.NET FileUpload control is used. The logic is nearly identical to that in AddUploadedFilesForFullTrust - the only
        /// differences are syntax differences arising from the different file upload control.
        /// </summary>
        private void AddUploadedFilesLessThanFullTrust()
        {
            // Clear the list of hash keys so we're starting with a fresh load from the data store.
            try
            {
                MediaObjectHashKeys.Clear();

                string albumPhysicalPath = this.GetAlbum().FullPhysicalPathOnDisk;

                HelperFunctions.BeginTransaction();

                for (int i = 0; i < 5; i++)
                {
                    FileUpload file = (FileUpload)phUpload.FindControl("fuUpload" + i);

                    if (!file.HasFile)
                    {
                        continue;
                    }

                    if ((System.IO.Path.GetExtension(file.FileName).Equals(".zip", StringComparison.OrdinalIgnoreCase)) && (!chkDoNotExtractZipFile.Checked))
                    {
                        #region Extract the files from the zipped file.

                        // Extract the files from the zipped file.
                        using (ZipUtility zip = new ZipUtility(Util.UserName, RoleController.GetGalleryServerRolesForUser()))
                        {
                            this._skippedFiles.AddRange(zip.ExtractZipFile(file.FileContent, this.GetAlbum(), chkDiscardOriginalImage.Checked));
                        }

                        #endregion
                    }
                    else
                    {
                        #region Add the file

                        string filename = HelperFunctions.ValidateFileName(albumPhysicalPath, file.FileName);
                        string filepath = Path.Combine(albumPhysicalPath, filename);

#if DEBUG
                        TechInfoSystems.TracingTools.Tools.MarkSpot(string.Format(CultureInfo.CurrentCulture, "Attempting to move file {0} to {1}...", file.FileName, filepath));
#endif
                        file.SaveAs(filepath);

                        try
                        {
                            IGalleryObject go = Factory.CreateMediaObjectInstance(filepath, this.GetAlbum());
                            GalleryObjectController.SaveGalleryObject(go);

                            if ((chkDiscardOriginalImage.Checked) && (go is Business.Image))
                            {
                                ((Business.Image)go).DeleteHiResImage();
                                GalleryObjectController.SaveGalleryObject(go);
                            }
                        }
                        catch (UnsupportedMediaObjectTypeException ex)
                        {
                            try
                            {
                                File.Delete(filepath);
                            }
                            catch (UnauthorizedAccessException) { }                             // Ignore an error; the file will end up getting deleted during cleanup maintenance

                            this._skippedFiles.Add(new KeyValuePair <string, string>(filename, ex.Message));
                        }

                        #endregion
                    }
                }

                HelperFunctions.CommitTransaction();
            }
            catch
            {
                HelperFunctions.RollbackTransaction();
                throw;
            }
            finally
            {
                // Clear the list of hash keys to free up memory.
                MediaObjectHashKeys.Clear();

                HelperFunctions.PurgeCache();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Adds the uploaded files to the gallery. This method is called when the application is operating under full trust. In this case,
        /// the ComponentArt Upload control is used. The logic is nearly identical to that in AddUploadedFilesLessThanFullTrust - the only
        /// differences are syntax differences arising from the different file upload control.
        /// </summary>
        /// <param name="files">The files to add to the gallery.</param>
        private void AddUploadedFilesForFullTrust(UploadedFileInfoCollection files)
        {
            // Clear the list of hash keys so we're starting with a fresh load from the data store.
            try
            {
                MediaObjectHashKeys.Clear();

                string albumPhysicalPath = this.GetAlbum().FullPhysicalPathOnDisk;

                HelperFunctions.BeginTransaction();

                UploadedFileInfo[] fileInfos = new UploadedFileInfo[files.Count];
                files.CopyTo(fileInfos, 0);
                Array.Reverse(fileInfos);

                foreach (UploadedFileInfo file in fileInfos)
                {
                    if (String.IsNullOrEmpty(file.FileName))
                    {
                        continue;
                    }

                    if ((System.IO.Path.GetExtension(file.FileName).Equals(".zip", StringComparison.OrdinalIgnoreCase)) && (!chkDoNotExtractZipFile.Checked))
                    {
                        #region Extract the files from the zipped file.

                        lock (file)
                        {
                            if (File.Exists(file.TempFileName))
                            {
                                using (ZipUtility zip = new ZipUtility(Util.UserName, GetGalleryServerRolesForUser()))
                                {
                                    this._skippedFiles.AddRange(zip.ExtractZipFile(file.GetStream(), this.GetAlbum(), chkDiscardOriginalImage.Checked));
                                }
                            }
                            else
                            {
                                // When one of the files causes an OutOfMemoryException, this can cause the other files to disappear from the
                                // temp upload directory. This seems to be an issue with the ComponentArt Upload control, since this does not
                                // seem to happen with the ASP.NET FileUpload control. If the file doesn't exist, make a note of it and move on
                                // to the next one.
                                this._skippedFiles.Add(new KeyValuePair <string, string>(file.FileName, Resources.GalleryServerPro.Task_Add_Objects_Uploaded_File_Does_Not_Exist_Msg));
                                continue;                                 // Skip to the next file.
                            }
                        }

                        // Sueetie Modified - Add contents of ZIP file - All

                        List <SueetieMediaObject> sueetieMediaObjects = SueetieMedia.GetSueetieMediaUpdateList(this.GetAlbumId());
                        int i = 0;
                        foreach (SueetieMediaObject _sueetieMediaObject in sueetieMediaObjects)
                        {
                            int            _moid          = _sueetieMediaObject.MediaObjectID;
                            IGalleryObject mo             = Factory.LoadMediaObjectInstance(_moid);
                            SueetieContent sueetieContent = new SueetieContent
                            {
                                SourceID        = _sueetieMediaObject.MediaObjectID,
                                ContentTypeID   = MediaHelper.ConvertContentType(mo.MimeType.TypeCategory),
                                ApplicationID   = (int)SueetieApplications.Current.ApplicationID,
                                UserID          = _sueetieMediaObject.SueetieUserID,
                                DateTimeCreated = mo.DateAdded,
                                IsRestricted    = mo.IsPrivate,
                                Permalink       = MediaHelper.SueetieMediaObjectUrl(_moid, this.GalleryId)
                            };

                            // Add Sueetie-specific data to Sueetie_gs_MediaObject
                            _sueetieMediaObject.ContentTypeID    = MediaHelper.ConvertContentType(mo.MimeType.TypeCategory);
                            _sueetieMediaObject.AlbumID          = this.GetAlbum().Id;
                            _sueetieMediaObject.InDownloadReport = false;
                            SueetieMedia.CreateSueetieMediaObject(_sueetieMediaObject);
                            SueetieCommon.AddSueetieContent(sueetieContent);
                            i++;
                        }


                        #endregion
                    }
                    else
                    {
                        #region Add the file

                        string filename = HelperFunctions.ValidateFileName(albumPhysicalPath, file.FileName);
                        string filepath = Path.Combine(albumPhysicalPath, filename);

                        lock (file)
                        {
                            if (File.Exists(file.TempFileName))
                            {
                                file.SaveAs(filepath);
                            }
                            else
                            {
                                // When one of the files causes an OutOfMemoryException, this can cause the other files to disappear from the
                                // temp upload directory. This seems to be an issue with the ComponentArt Upload control, since this does not
                                // seem to happen with the ASP.NET FileUpload control. If the file doesn't exist, make a note of it and move on
                                // to the next one.
                                this._skippedFiles.Add(new KeyValuePair <string, string>(file.FileName, Resources.GalleryServerPro.Task_Add_Objects_Uploaded_File_Does_Not_Exist_Msg));
                                continue;                                 // Skip to the next file.
                            }
                        }

                        try
                        {
                            IGalleryObject go = Factory.CreateMediaObjectInstance(filepath, this.GetAlbum());
                            GalleryObjectController.SaveGalleryObject(go);

                            if ((chkDiscardOriginalImage.Checked) && (go is Business.Image))
                            {
                                ((Business.Image)go).DeleteHiResImage();
                                GalleryObjectController.SaveGalleryObject(go);
                            }


                            // Sueetie Modified - Add mediaobject to Sueetie_Content - Single File

                            SueetieContent sueetieContent = new SueetieContent
                            {
                                SourceID      = go.Id,
                                ContentTypeID = MediaHelper.ConvertContentType(go.MimeType.TypeCategory),
                                ApplicationID = (int)SueetieApplications.Current.ApplicationID,
                                UserID        = CurrentSueetieUserID,
                                IsRestricted  = this.GetAlbum().IsPrivate,
                                Permalink     = MediaHelper.SueetieMediaObjectUrl(go.Id, this.GalleryId)
                            };
                            SueetieCommon.AddSueetieContent(sueetieContent);

                            // Add Sueetie-specific data to Sueetie_gs_MediaObject

                            SueetieMediaObject _sueetieMediaObject = new SueetieMediaObject();
                            _sueetieMediaObject.MediaObjectID    = go.Id;
                            _sueetieMediaObject.ContentTypeID    = MediaHelper.ConvertContentType(go.MimeType.TypeCategory);
                            _sueetieMediaObject.AlbumID          = this.GetAlbum().Id;
                            _sueetieMediaObject.InDownloadReport = false;
                            SueetieMedia.CreateSueetieMediaObject(_sueetieMediaObject);

                            SueetieMediaAlbum sueetieAlbum = SueetieMedia.GetSueetieMediaAlbum(this.GetAlbum().Id);
                            if (CurrentSueetieGallery.IsLogged)
                            {
                                SueetieLogs.LogUserEntry((UserLogCategoryType)sueetieAlbum.AlbumMediaCategoryID, sueetieAlbum.ContentID, CurrentSueetieUserID);
                            }
                        }
                        catch (UnsupportedMediaObjectTypeException ex)
                        {
                            try
                            {
                                File.Delete(filepath);
                            }
                            catch (UnauthorizedAccessException) { }                             // Ignore an error; the file will end up getting deleted during cleanup maintenance

                            this._skippedFiles.Add(new KeyValuePair <string, string>(filename, ex.Message));
                        }

                        #endregion
                    }
                }

                SueetieMedia.ClearMediaPhotoListCache(0);
                SueetieMedia.ClearSueetieMediaObjectListCache(this.CurrentSueetieGalleryID);

                HelperFunctions.CommitTransaction();
            }
            catch
            {
                HelperFunctions.RollbackTransaction();
                throw;
            }
            finally
            {
                // Delete the uploaded temporary files, as by this time they have been saved to the destination directory.
                foreach (UploadedFileInfo file in files)
                {
                    try
                    {
                        System.IO.File.Delete(file.TempFileName);
                    }
                    catch (UnauthorizedAccessException) { }                     // Ignore an error; the file will end up getting deleted during cleanup maintenance
                }

                // Clear the list of hash keys to free up memory.
                MediaObjectHashKeys.Clear();

                HelperFunctions.PurgeCache();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Adds the uploaded files to the gallery. This method is called when the application is operating at lesss than full trust. In this case,
        /// the ASP.NET FileUpload control is used. The logic is nearly identical to that in AddUploadedFilesForFullTrust - the only
        /// differences are syntax differences arising from the different file upload control.
        /// </summary>
        private void AddUploadedFilesLessThanFullTrust()
        {
            // Clear the list of hash keys so we're starting with a fresh load from the data store.
            try
            {
                MediaObjectHashKeys.Clear();

                string albumPhysicalPath = this.GetAlbum().FullPhysicalPathOnDisk;

                HelperFunctions.BeginTransaction();

                for (int i = 0; i < 5; i++)
                {
                    FileUpload file = (FileUpload)phUpload.FindControl("fuUpload" + i);

                    if (!file.HasFile)
                    {
                        continue;
                    }

                    if ((System.IO.Path.GetExtension(file.FileName).Equals(".zip", StringComparison.OrdinalIgnoreCase)) && (!chkDoNotExtractZipFile.Checked))
                    {
                        #region Extract the files from the zipped file.

                        // Extract the files from the zipped file.
                        using (ZipUtility zip = new ZipUtility(Util.UserName, GetGalleryServerRolesForUser()))
                        {
                            this._skippedFiles.AddRange(zip.ExtractZipFile(file.FileContent, this.GetAlbum(), chkDiscardOriginalImage.Checked));
                        }

                        #endregion
                    }
                    else
                    {
                        #region Add the file

                        string filename = HelperFunctions.ValidateFileName(albumPhysicalPath, file.FileName);
                        string filepath = Path.Combine(albumPhysicalPath, filename);

                        file.SaveAs(filepath);

                        try
                        {
                            IGalleryObject go = Factory.CreateMediaObjectInstance(filepath, this.GetAlbum());

                            // Sueetie Modified - Fix Blank Title on individual uploads
                            if (go.Title.Trim().Length == 0)
                            {
                                go.Title = go.Original.FileName;
                            }

                            GalleryObjectController.SaveGalleryObject(go);

                            if ((chkDiscardOriginalImage.Checked) && (go is Business.Image))
                            {
                                ((Business.Image)go).DeleteHiResImage();
                                GalleryObjectController.SaveGalleryObject(go);
                            }

                            // Sueetie Modified - Add mediaobject to Sueetie_Content - Single File

                            SueetieContent sueetieContent = new SueetieContent
                            {
                                SourceID      = go.Id,
                                ContentTypeID = MediaHelper.ConvertContentType(go.MimeType.TypeCategory),
                                ApplicationID = (int)SueetieApplications.Current.ApplicationID,
                                UserID        = CurrentSueetieUserID,
                                IsRestricted  = this.GetAlbum().IsPrivate,
                                Permalink     = MediaHelper.SueetieMediaObjectUrl(go.Id, this.GalleryId)
                            };
                            SueetieCommon.AddSueetieContent(sueetieContent);

                            // Add Sueetie-specific data to Sueetie_gs_MediaObject

                            SueetieMediaObject _sueetieMediaObject = new SueetieMediaObject();
                            _sueetieMediaObject.MediaObjectID    = go.Id;
                            _sueetieMediaObject.ContentTypeID    = MediaHelper.ConvertContentType(go.MimeType.TypeCategory);
                            _sueetieMediaObject.AlbumID          = this.GetAlbum().Id;
                            _sueetieMediaObject.InDownloadReport = false;
                            SueetieMedia.CreateSueetieMediaObject(_sueetieMediaObject);

                            SueetieMediaAlbum sueetieAlbum = SueetieMedia.GetSueetieMediaAlbum(this.GetAlbum().Id);
                            if (CurrentSueetieGallery.IsLogged)
                            {
                                SueetieLogs.LogUserEntry((UserLogCategoryType)sueetieAlbum.AlbumMediaCategoryID, sueetieAlbum.ContentID, CurrentSueetieUserID);
                            }
                            SueetieMedia.ClearMediaPhotoListCache(0);
                            SueetieMedia.ClearSueetieMediaObjectListCache(this.CurrentSueetieGalleryID);
                        }
                        catch (UnsupportedMediaObjectTypeException ex)
                        {
                            try
                            {
                                File.Delete(filepath);
                            }
                            catch (UnauthorizedAccessException) { }                             // Ignore an error; the file will end up getting deleted during cleanup maintenance

                            this._skippedFiles.Add(new KeyValuePair <string, string>(filename, ex.Message));
                        }

                        #endregion
                    }
                }

                HelperFunctions.CommitTransaction();
            }
            catch
            {
                HelperFunctions.RollbackTransaction();
                throw;
            }
            finally
            {
                // Clear the list of hash keys to free up memory.
                MediaObjectHashKeys.Clear();

                HelperFunctions.PurgeCache();
            }
        }