Ejemplo n.º 1
0
        /// <summary>
        /// Assign various application-wide properties to be used during the lifetime of the application. This method
        /// should be called once when the application first starts.
        /// </summary>
        /// <param name="trustLevel">The trust level of the current application.</param>
        /// <param name="physicalAppPath">The physical path of the currently executing application. For web applications
        /// this will be equal to the Request.PhysicalApplicationPath property.</param>
        /// <param name="appName">The name of the currently running application.</param>
        /// <param name="galleryResourcesPath">The path, relative to the current application, to
        /// the directory containing the Gallery Server Pro resources such as images, user controls,
        /// scripts, etc. Use the value of the galleryResourcesPath setting in the
        /// galleryServerPro/core section of web.config. Examples: "gs", "GalleryServerPro\resources"</param>
        /// <exception cref="System.InvalidOperationException">Thrown when this method is called more than once during
        /// the application's lifetime.</exception>
        /// <exception cref="System.ArgumentOutOfRangeException">Thrown if the trustLevel parameter has the value
        /// ApplicationTrustLevel.None.</exception>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="physicalAppPath"/> or <paramref name="appName"/>
        /// is null.</exception>
        /// <exception cref="GalleryServerPro.Events.CustomExceptions.CannotWriteToDirectoryException">
        /// Thrown when Gallery Server Pro is unable to write to, or delete from, a directory. This may be the media objects
        /// directory, thumbnail or optimized directory, the temporary directory (defined in
        /// <see cref="GlobalConstants.TempUploadDirectory"/>), or the App_Data directory.</exception>
        public void Initialize(ApplicationTrustLevel trustLevel, string physicalAppPath, string appName, string galleryResourcesPath)
        {
            #region Validation

            if (this._isInitialized)
            {
                throw new System.InvalidOperationException("The AppSetting instance has already been initialized. It cannot be initialized more than once.");
            }

            if (trustLevel == ApplicationTrustLevel.None)
            {
                throw new System.ComponentModel.InvalidEnumArgumentException("Invalid ApplicationTrustLevel value. ApplicationTrustLevel.None is not valid. Use ApplicationTrustLevel.Unknown if the trust level cannot be calculated.");
            }

            if (String.IsNullOrEmpty(physicalAppPath))
            {
                throw new ArgumentNullException("physicalAppPath");
            }

            if (String.IsNullOrEmpty(appName))
            {
                throw new ArgumentNullException("appName");
            }

            #endregion

            this.AppTrustLevel           = trustLevel;
            this.PhysicalApplicationPath = physicalAppPath;
            this.ApplicationName         = appName;
            this.GalleryResourcesPath    = galleryResourcesPath;

            ConfigureAppDataDirectory(physicalAppPath);

            InitializeDataStore();

            PopulateAppSettingsFromDataStore();

            ConfigureTempDirectory(physicalAppPath);

            this._dotNetFrameworkVersion = GetDotNetFrameworkVersion();

            string ffmpegPath = Path.Combine(physicalAppPath, @"bin\ffmpeg.exe");
            this._ffmpegPath = (File.Exists(ffmpegPath) ? ffmpegPath : String.Empty);

            string imageMagickConvertPath = Path.Combine(physicalAppPath, @"bin\convert.exe");
            this._imageMagickConvertPath = (File.Exists(imageMagickConvertPath) ? imageMagickConvertPath : String.Empty);

            this._isInitialized = true;

            // Validate the application and gallery settings. This must come after setting _isInitialized to true because the function
            // accesses properties of the AppSetting singleton, which will throw a ApplicationNotInitializedException when a property is
            // accessed before initialization is complete.
            Validate();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Set up the business layer with information about this web application, such as its trust level and a few settings
        /// from the configuration file.
        /// </summary>
        /// <exception cref="GalleryServerPro.ErrorHandler.CustomExceptions.CannotWriteToDirectoryException">
        /// Thrown when Gallery Server Pro is unable to write to, or delete from, the media objects directory.</exception>
        private static void InitializeBusinessLayer()
        {
            // Determine the trust level this web application is running in and set to a global variable. This will be used
            // throughout the application to gracefully degrade when we are not at Full trust.
            ApplicationTrustLevel trustLevel = Util.GetCurrentTrustLevel();

            // Get the application path so that the business layer (and any dependent layers) has access to it. Don't use
            // HttpContext.Current.Request.PhysicalApplicationPath because in some cases HttpContext.Current won't be available
            // (for example, when the DotNetNuke search engine indexer causes this code to trigger).
            string physicalApplicationPath = AppDomain.CurrentDomain.BaseDirectory.Substring(0, AppDomain.CurrentDomain.BaseDirectory.Length - 1);

            physicalApplicationPath = physicalApplicationPath.Replace("/", "\\");

            // Pass these values to our global app settings instance, where the values can be used throughout the application.
            AppSetting.Instance.Initialize(trustLevel, physicalApplicationPath, Constants.APP_NAME);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Assign various application-wide properties to be used during the lifetime of the application. This method
        /// should be called once when the application first starts.
        /// </summary>
        /// <param name="trustLevel">The trust level of the current application.</param>
        /// <param name="physicalAppPath">The physical path of the currently executing application. For web applications
        /// this will be equal to the Request.PhysicalApplicationPath property.</param>
        /// <param name="appName">The name of the currently running application.</param>
        /// <param name="galleryResourcesPath">The path, relative to the current application, to
        /// the directory containing the Gallery Server resources such as images, user controls,
        /// scripts, etc. Examples: "gs", "GalleryServer\resources"</param>
        /// <exception cref="System.InvalidOperationException">Thrown when this method is called more than once during
        /// the application's lifetime.</exception>
        /// <exception cref="System.ArgumentOutOfRangeException">Thrown if the trustLevel parameter has the value
        /// ApplicationTrustLevel.None.</exception>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="physicalAppPath"/> or <paramref name="appName"/>
        /// is null.</exception>
        /// <exception cref="CannotWriteToDirectoryException">
        /// Thrown when Gallery Server is unable to write to, or delete from, a directory. This may be the media objects
        /// directory, thumbnail or optimized directory, the temporary directory (defined in
        /// <see cref="GlobalConstants.TempUploadDirectory"/>), or the App_Data directory.</exception>
        public void Initialize(ApplicationTrustLevel trustLevel, string physicalAppPath, string appName, string galleryResourcesPath)
        {
            #region Validation

            if (this._isInitialized)
            {
                throw new System.InvalidOperationException("The AppSetting instance has already been initialized. It cannot be initialized more than once.");
            }

            if (trustLevel == ApplicationTrustLevel.None)
            {
                throw new System.ComponentModel.InvalidEnumArgumentException("Invalid ApplicationTrustLevel value. ApplicationTrustLevel.None is not valid. Use ApplicationTrustLevel.Unknown if the trust level cannot be calculated.");
            }

            if (String.IsNullOrEmpty(physicalAppPath))
            {
                throw new ArgumentNullException("physicalAppPath");
            }

            if (String.IsNullOrEmpty(appName))
            {
                throw new ArgumentNullException("appName");
            }

            #endregion

            this.AppTrustLevel           = trustLevel;
            this.PhysicalApplicationPath = physicalAppPath;
            this.ApplicationName         = appName;
            this.GalleryResourcesPath    = galleryResourcesPath;

            ConfigureAppDataDirectory(physicalAppPath);

            InitializeDataStore();

            PopulateAppSettingsFromDataStore();

            ConfigureTempDirectory(physicalAppPath);

            this._dotNetFrameworkVersion = GetDotNetFrameworkVersion();


            string ffmpegPath = Path.Combine(physicalAppPath, @"bin\ffmpeg.exe");
            this._ffmpegPath = (File.Exists(ffmpegPath) ? ffmpegPath : String.Empty);

            this._isInitialized = true;
        }
Ejemplo n.º 4
0
		/// <summary>
		/// Assign various application-wide properties to be used during the lifetime of the application. This method
		/// should be called once when the application first starts.
		/// </summary>
		/// <param name="trustLevel">The trust level of the current application.</param>
		/// <param name="physicalAppPath">The physical path of the currently executing application. For web applications
		/// this will be equal to the Request.PhysicalApplicationPath property.</param>
		/// <param name="appName">The name of the currently running application.</param>
		/// <exception cref="System.InvalidOperationException">Thrown when this method is called more than once during 
		/// the application's lifetime.</exception>
		/// <exception cref="System.ArgumentOutOfRangeException">Thrown if the trustLevel parameter has the value
		/// ApplicationTrustLevel.None.</exception>
		/// <exception cref="System.ArgumentNullException">Thrown if any parameters are null or empty.</exception>
		/// <exception cref="GalleryServerPro.ErrorHandler.CustomExceptions.CannotWriteToDirectoryException">
		/// Thrown when Gallery Server Pro is unable to write to, or delete from, a directory. This may be the media objects
		/// directory, thumbnail or optimized directory, the temporary directory (defined in 
		/// <see cref="GlobalConstants.TempUploadDirectory"/>), or the App_Data directory.</exception>
		public void Initialize(ApplicationTrustLevel trustLevel, string physicalAppPath, string appName)
		{
			#region Validation

			if (this._isInitialized)
			{
				throw new System.InvalidOperationException("The AppSetting instance has already been initialized. It cannot be initialized more than once.");
			}

			if (trustLevel == ApplicationTrustLevel.None)
			{
				throw new System.ComponentModel.InvalidEnumArgumentException("Invalid ApplicationTrustLevel value. ApplicationTrustLevel.None is not valid. Use ApplicationTrustLevel.Unknown if the trust level cannot be calculated.");
			}

			if (String.IsNullOrEmpty(physicalAppPath)) throw new ArgumentNullException("physicalAppPath");

			if (String.IsNullOrEmpty(appName)) throw new ArgumentNullException("appName");

			#endregion

			this.AppTrustLevel = trustLevel;
			this.PhysicalApplicationPath = physicalAppPath;
			this.ApplicationName = appName;

			Core core = ConfigManager.GetGalleryServerProConfigSection().Core;

			string mediaObjectPath = core.MediaObjectPath;
			string thumbnailPath = (String.IsNullOrEmpty(core.ThumbnailPath) ? mediaObjectPath : core.ThumbnailPath);
			string optimizedPath = (String.IsNullOrEmpty(core.OptimizedPath) ? mediaObjectPath : core.OptimizedPath);

			if (core.MediaObjectPathIsReadOnly)
				ValidateReadOnlyGallery(mediaObjectPath, thumbnailPath, optimizedPath);

			// Setting the MediaObjectPhysicalPath property will throw an exception if the directory does not exist or is not writeable.
			this.MediaObjectPhysicalPath = HelperFunctions.CalculateFullPath(physicalAppPath, mediaObjectPath);

			// The property setter for the ThumbnailPath and OptimizedPath propertys will throw an exception if the directory 
			// does not exist or is not writeable.
			this.ThumbnailPath = HelperFunctions.CalculateFullPath(physicalAppPath, thumbnailPath);
			this.OptimizedPath = HelperFunctions.CalculateFullPath(physicalAppPath, optimizedPath);

			ConfigureAppDataDirectory(physicalAppPath);

			ConfigureTempDirectory(physicalAppPath);

			try
			{
				// Verify the database has the minimum default records and the latest data schema.
				Factory.GetDataProvider().InitializeDataStore();
			}
			catch (Exception ex)
			{
				// In certain situations the method ConfigureAppDataDirectory (above) will determine that the App_Data directory is writeable yet SQLite
				// is still unable to use it. It is unclear exactly why this occurs: I observed that the method was able to create and delete the test
				// file even when the Effective Permissions showed there was no Delete permission. To handle this, we'll check the exception and, if 
				// it is the one that is thrown when there are not enough permissions, we'll re-throw it as a CannotWriteToDirectoryException. The
				// global error handler in Gallery.cs will catch this and show a user-friendly error.
				if (ex.Message.StartsWith("Attempt to write a read-only database"))
				{
					throw new GalleryServerPro.ErrorHandler.CustomExceptions.CannotWriteToDirectoryException(Path.Combine(physicalAppPath, GlobalConstants.AppDataDirectory), ex);
				}
				else
				{
					throw;
				}
			}

			this._isDotNet3Installed = DetermineIfDotNet3IsInstalled();

			this._isRegistered = (GalleryServerPro.Configuration.ConfigManager.GetGalleryServerProConfigSection().Core.ProductKey.Equals(GlobalConstants.ProductKey));

			DateTime galleryCreationDate = Factory.GetDataProvider().Gallery_GetCurrentGallery(new Gallery()).CreationDate;
			this._isInTrialPeriod = (galleryCreationDate.AddDays(GlobalConstants.TrialNumberOfDays) > DateTime.Now);
			
			this._isInitialized = true;
		}
Ejemplo n.º 5
0
        /// <summary>
        /// Assign various application-wide properties to be used during the lifetime of the application. This method
        /// should be called once when the application first starts.
        /// </summary>
        /// <param name="trustLevel">The trust level of the current application.</param>
        /// <param name="physicalAppPath">The physical path of the currently executing application. For web applications
        /// this will be equal to the Request.PhysicalApplicationPath property.</param>
        /// <param name="appName">The name of the currently running application.</param>
        /// <param name="galleryResourcesPath">The path, relative to the current application, to 
        /// the directory containing the Gallery Server Pro resources such as images, user controls, 
        /// scripts, etc. Use the value of the galleryResourcesPath setting in the 
        /// galleryServerPro/core section of web.config. Examples: "gs", "GalleryServerPro\resources"</param>
        /// <exception cref="System.InvalidOperationException">Thrown when this method is called more than once during
        /// the application's lifetime.</exception>
        /// <exception cref="System.ArgumentOutOfRangeException">Thrown if the trustLevel parameter has the value
        /// ApplicationTrustLevel.None.</exception>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="physicalAppPath"/> or <paramref name="appName"/>
        /// is null.</exception>
        /// <exception cref="GalleryServerPro.ErrorHandler.CustomExceptions.CannotWriteToDirectoryException">
        /// Thrown when Gallery Server Pro is unable to write to, or delete from, a directory. This may be the media objects
        /// directory, thumbnail or optimized directory, the temporary directory (defined in
        /// <see cref="GlobalConstants.TempUploadDirectory"/>), or the App_Data directory.</exception>
        public void Initialize(ApplicationTrustLevel trustLevel, string physicalAppPath, string appName, string galleryResourcesPath)
        {
            #region Validation

            if (this._isInitialized)
            {
                throw new System.InvalidOperationException("The AppSetting instance has already been initialized. It cannot be initialized more than once.");
            }

            if (trustLevel == ApplicationTrustLevel.None)
            {
                throw new System.ComponentModel.InvalidEnumArgumentException("Invalid ApplicationTrustLevel value. ApplicationTrustLevel.None is not valid. Use ApplicationTrustLevel.Unknown if the trust level cannot be calculated.");
            }

            if (String.IsNullOrEmpty(physicalAppPath))
                throw new ArgumentNullException("physicalAppPath");

            if (String.IsNullOrEmpty(appName))
                throw new ArgumentNullException("appName");

            #endregion

            this.AppTrustLevel = trustLevel;
            this.PhysicalApplicationPath = physicalAppPath;
            this.ApplicationName = appName;
            this.GalleryResourcesPath = galleryResourcesPath;

            ConfigureAppDataDirectory(physicalAppPath);

            ConfigureTempDirectory(physicalAppPath);

            InitializeDataStore(physicalAppPath);

            PopulateAppSettingsFromDataStore();

            this._dotNetFrameworkVersion = GetDotNetFrameworkVersion();

            string ffmpegPath = Path.Combine(physicalAppPath, @"bin\ffmpeg.exe");
            this._ffmpegPath = (File.Exists(ffmpegPath) ? ffmpegPath : String.Empty);

            string imageMagickConvertPath = Path.Combine(physicalAppPath, @"bin\convert.exe");
            this._imageMagickConvertPath = (File.Exists(imageMagickConvertPath) ? imageMagickConvertPath : String.Empty);

            this._isInitialized = true;

            // Validate the application and gallery settings. This must come after setting _isInitialized to true because the function
            // accesses properties of the AppSetting singleton, which will throw a ApplicationNotInitializedException when a property is
            // accessed before initialization is complete.
            Validate();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Assign various application-wide properties to be used during the lifetime of the application. This method
        /// should be called once when the application first starts.
        /// </summary>
        /// <param name="trustLevel">The trust level of the current application.</param>
        /// <param name="physicalAppPath">The physical path of the currently executing application. For web applications
        /// this will be equal to the Request.PhysicalApplicationPath property.</param>
        /// <param name="appName">The name of the currently running application.</param>
        /// <exception cref="System.InvalidOperationException">Thrown when this method is called more than once during
        /// the application's lifetime.</exception>
        /// <exception cref="System.ArgumentOutOfRangeException">Thrown if the trustLevel parameter has the value
        /// ApplicationTrustLevel.None.</exception>
        /// <exception cref="System.ArgumentNullException">Thrown if any parameters are null or empty.</exception>
        /// <exception cref="GalleryServerPro.ErrorHandler.CustomExceptions.CannotWriteToDirectoryException">
        /// Thrown when Gallery Server Pro is unable to write to, or delete from, a directory. This may be the media objects
        /// directory, thumbnail or optimized directory, the temporary directory (defined in
        /// <see cref="GlobalConstants.TempUploadDirectory"/>), or the App_Data directory.</exception>
        public void Initialize(ApplicationTrustLevel trustLevel, string physicalAppPath, string appName)
        {
            #region Validation

            if (this._isInitialized)
            {
                throw new System.InvalidOperationException("The AppSetting instance has already been initialized. It cannot be initialized more than once.");
            }

            if (trustLevel == ApplicationTrustLevel.None)
            {
                throw new System.ComponentModel.InvalidEnumArgumentException("Invalid ApplicationTrustLevel value. ApplicationTrustLevel.None is not valid. Use ApplicationTrustLevel.Unknown if the trust level cannot be calculated.");
            }

            if (String.IsNullOrEmpty(physicalAppPath))
            {
                throw new ArgumentNullException("physicalAppPath");
            }

            if (String.IsNullOrEmpty(appName))
            {
                throw new ArgumentNullException("appName");
            }

            #endregion

            this.AppTrustLevel           = trustLevel;
            this.PhysicalApplicationPath = physicalAppPath;
            this.ApplicationName         = appName;

            Core core = ConfigManager.GetGalleryServerProConfigSection().Core;

            string mediaObjectPath = core.MediaObjectPath;
            string thumbnailPath   = (String.IsNullOrEmpty(core.ThumbnailPath) ? mediaObjectPath : core.ThumbnailPath);
            string optimizedPath   = (String.IsNullOrEmpty(core.OptimizedPath) ? mediaObjectPath : core.OptimizedPath);

            if (core.MediaObjectPathIsReadOnly)
            {
                ValidateReadOnlyGallery(mediaObjectPath, thumbnailPath, optimizedPath);
            }

            // Setting the MediaObjectPhysicalPath property will throw an exception if the directory does not exist or is not writeable.
            this.MediaObjectPhysicalPath = HelperFunctions.CalculateFullPath(physicalAppPath, mediaObjectPath);

            // The property setter for the ThumbnailPath and OptimizedPath propertys will throw an exception if the directory
            // does not exist or is not writeable.
            this.ThumbnailPath = HelperFunctions.CalculateFullPath(physicalAppPath, thumbnailPath);
            this.OptimizedPath = HelperFunctions.CalculateFullPath(physicalAppPath, optimizedPath);

            ConfigureAppDataDirectory(physicalAppPath);

            ConfigureTempDirectory(physicalAppPath);

            try
            {
                // Verify the database has the minimum default records and the latest data schema.
                Factory.GetDataProvider().InitializeDataStore();
            }
            catch (Exception ex)
            {
                // In certain situations the method ConfigureAppDataDirectory (above) will determine that the App_Data directory is writeable yet SQLite
                // is still unable to use it. It is unclear exactly why this occurs: I observed that the method was able to create and delete the test
                // file even when the Effective Permissions showed there was no Delete permission. To handle this, we'll check the exception and, if
                // it is the one that is thrown when there are not enough permissions, we'll re-throw it as a CannotWriteToDirectoryException. The
                // global error handler in Gallery.cs will catch this and show a user-friendly error.
                if (ex.Message.StartsWith("Attempt to write a read-only database"))
                {
                    throw new GalleryServerPro.ErrorHandler.CustomExceptions.CannotWriteToDirectoryException(Path.Combine(physicalAppPath, GlobalConstants.AppDataDirectory), ex);
                }
                else
                {
                    throw;
                }
            }

            this._isDotNet3Installed = DetermineIfDotNet3IsInstalled();

            this._isRegistered = (GalleryServerPro.Configuration.ConfigManager.GetGalleryServerProConfigSection().Core.ProductKey.Equals(GlobalConstants.ProductKey));

            DateTime galleryCreationDate = Factory.GetDataProvider().Gallery_GetCurrentGallery(new Gallery()).CreationDate;
            this._isInTrialPeriod = (galleryCreationDate.AddDays(GlobalConstants.TrialNumberOfDays) > DateTime.Now);

            this._isInitialized = true;
        }