Beispiel #1
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();
            }
        }
        /// <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(Utils.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.
                            }
                        }

                        #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
                        {
                            using (IGalleryObject go = Factory.CreateMediaObjectInstance(filepath, this.GetAlbum()))
                            {
                                GalleryObjectController.SaveGalleryObject(go);
                                Business.Image img = go as Business.Image;
                                bool isImage = (img != null);

                                if ((chkDiscardOriginalImage.Checked) && isImage)
                                {
                                    img.DeleteHiResImage();
                                    GalleryObjectController.SaveGalleryObject(img);
                                }
                            }
                        }
                        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();
            }
        }
Beispiel #3
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).ToUpperInvariant() == ".ZIP") && (!chkDoNotExtractZipFile.Checked))
					{
						#region Extract the files from the zipped file.

						lock (file)
						{
							if (File.Exists(file.TempFileName))
							{
								string userName = (String.IsNullOrEmpty(User.Identity.Name) ? "Anonymous" : User.Identity.Name);
								using (ZipUtility zip = new ZipUtility(userName, WebsiteController.GetRolesForUser(), User.Identity.IsAuthenticated))
								{
									this._skippedFiles.AddRange(zip.ExtractZipFile(file.GetStream(), this.GetAlbum()));
								}
							}
							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());
							WebsiteController.SaveGalleryObject(go);
						}
						catch (UnsupportedMediaObjectTypeException ex)
						{
							File.Delete(filepath);
							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)
				{
					System.IO.File.Delete(file.TempFileName);
				}

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

				HelperFunctions.PurgeCache();
			}
		}
        /// <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();
            }
        }