/// <remarks>
        /// This is meant to test an obsolete method. Don't use this!
        /// </remarks>
        internal static Version GetObsoleteVersionInternal(
            string path,
            NameValueCollection configuration,
            IFileSystem fileSystem
            )
        {
            if (String.IsNullOrEmpty(path))
            {
                throw new ArgumentException(
                          CommonResources.Argument_Cannot_Be_Null_Or_Empty,
                          "path"
                          );
            }

            var binDirectory = GetBinDirectory(path);
            var binVersion   = AssemblyUtils.GetVersionFromBin(binDirectory, _fileSystem);
            var version      = GetVersionInternal(configuration, binVersion, defaultVersion: null);

            if (version != null)
            {
                // If a webpages version is available in config or bin, return it.
                return(version);
            }
            else if (AppRootContainsWebPagesFile(fileSystem, path))
            {
                // If the path points to a WebPages site, return v1 as a fixed version.
                return(AssemblyUtils.WebPagesV1Version);
            }
            return(null);
        }
Exemple #2
0
        // Adds Parameter for unit tests
        internal static bool StartCore(IFileSystem fileSystem, string appDomainAppPath, string binDirectory, NameValueCollection appSettings, IEnumerable <AssemblyName> loadedAssemblies,
                                       IBuildManager buildManager, Action <Version> loadWebPages, Action registerForChangeNotification, Func <string, AssemblyName> getAssemblyNameThunk = null)
        {
            if (WebPagesDeployment.IsExplicitlyDisabled(appSettings))
            {
                // If WebPages is explicitly disabled, exit.
                Debug.WriteLine("WebPages Bootstrapper v{0}: not loading WebPages since it is disabled", AssemblyUtils.ThisAssemblyName.Version);
                return(false);
            }

            Version maxWebPagesVersion = AssemblyUtils.GetMaxWebPagesVersion(loadedAssemblies);

            Debug.Assert(maxWebPagesVersion != null, "Function must return some max value.");
            if (AssemblyUtils.ThisAssemblyName.Version != maxWebPagesVersion)
            {
                // Always let the highest version determine what needs to be done. This would make future proofing simpler.
                Debug.WriteLine("WebPages Bootstrapper v{0}: Higher version v{1} is available.", AssemblyUtils.ThisAssemblyName.Version, maxWebPagesVersion);
                return(false);
            }

            var     webPagesEnabled = WebPagesDeployment.IsEnabled(fileSystem, appDomainAppPath, appSettings);
            Version binVersion      = AssemblyUtils.GetVersionFromBin(binDirectory, fileSystem, getAssemblyNameThunk);
            Version version         = WebPagesDeployment.GetVersionInternal(appSettings, binVersion, defaultVersion: maxWebPagesVersion);

            // Asserts to ensure unit tests are set up correctly. So essentially, we're unit testing the unit tests.
            Debug.Assert(version != null, "GetVersion always returns a version");
            Debug.Assert(binVersion == null || binVersion <= maxWebPagesVersion, "binVersion cannot be higher than max version");

            if ((binVersion != null) && (binVersion != version))
            {
                // Determine if there's a version conflict. A conflict could occur if there's a version specified in the bin which is different from the version specified in the
                // config that is different.
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, ConfigurationResources.WebPagesVersionConflict, version, binVersion));
            }
            else if (binVersion != null)
            {
                // The rest of the code is only meant to be executed if we are executing from the GAC.
                // If a version is bin deployed, we don't need to do anything special to bootstrap.
                return(false);
            }
            else if (!webPagesEnabled)
            {
                Debug.WriteLine("WebPages Bootstrapper v{0}: WebPages not enabled, registering for change notifications", AssemblyUtils.ThisAssemblyName.Version);
                // Register for change notifications under the application root
                registerForChangeNotification();
                return(false);
            }
            else if (!AssemblyUtils.IsVersionAvailable(loadedAssemblies, version))
            {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, ConfigurationResources.WebPagesVersionNotFound, version, AssemblyUtils.ThisAssemblyName.Version));
            }

            Debug.WriteLine("WebPages Bootstrapper v{0}: loading version {1}, loading WebPages", AssemblyUtils.ThisAssemblyName.Version, version);
            // If the version the application was compiled earlier was different, invalidate compilation results by adding a file to the bin.
            InvalidateCompilationResultsIfVersionChanged(buildManager, fileSystem, binDirectory, version);
            loadWebPages(version);
            return(true);
        }
        private static Version GetVersionWithoutEnabledCheckInternal(string path, Version defaultVersion)
        {
            if (String.IsNullOrEmpty(path))
            {
                throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "path");
            }

            var binDirectory = GetBinDirectory(path);
            var binVersion   = AssemblyUtils.GetVersionFromBin(binDirectory, _fileSystem);

            return(GetVersionInternal(GetAppSettings(path), binVersion, defaultVersion));
        }
Exemple #4
0
        private static Version GetVersionWithoutEnabledCheckInternal(string path, Version defaultVersion)
        {
            if (String.IsNullOrEmpty(path))
            {
                throw ExceptionHelper.CreateArgumentNullOrEmptyException("path");
            }

            var binDirectory = GetBinDirectory(path);
            var binVersion   = AssemblyUtils.GetVersionFromBin(binDirectory, _fileSystem);

            return(GetVersionInternal(GetAppSettings(path), binVersion, defaultVersion));
        }
        /// <remarks>
        /// This is meant to test an obsolete method. Don't use this!
        /// </remarks>
        internal static Version GetObsoleteVersionInternal(string path, NameValueCollection configuration, IFileSystem fileSystem, Func <Version> getMaxWebPagesVersion)
        {
            if (String.IsNullOrEmpty(path))
            {
                throw ExceptionHelper.CreateArgumentNullOrEmptyException("path");
            }

            var binDirectory = GetBinDirectory(path);
            var binVersion   = AssemblyUtils.GetVersionFromBin(binDirectory, _fileSystem);
            var version      = GetVersionInternal(configuration, binVersion, defaultVersion: null);

            if (version != null)
            {
                // If a webpages version is available in config or bin, return it.
                return(version);
            }
            else if (AppRootContainsWebPagesFile(fileSystem, path))
            {
                // If the path points to a WebPages site, return the highest version.
                return(getMaxWebPagesVersion());
            }
            return(null);
        }