Ejemplo n.º 1
0
 internal virtual void RemoveAssemblyAndRelatedFiles(string assemblyName)
 {
     if (assemblyName.StartsWith("App_Web_", StringComparison.Ordinal))
     {
         string str     = assemblyName.Substring("App_Web_".Length);
         bool   gotLock = false;
         try
         {
             CompilationLock.GetLock(ref gotLock);
             DirectoryInfo info = new DirectoryInfo(this._cacheDir);
             foreach (FileInfo info2 in info.GetFiles("*" + str + ".*"))
             {
                 if (info2.Extension == ".dll")
                 {
                     string assemblyCacheKey = BuildResultCache.GetAssemblyCacheKey(info2.FullName);
                     HttpRuntime.CacheInternal.Remove(assemblyCacheKey);
                     RemoveAssembly(info2);
                     StandardDiskBuildResultCache.RemoveSatelliteAssemblies(assemblyName);
                 }
                 else if (info2.Extension == ".delete")
                 {
                     CheckAndRemoveDotDeleteFile(info2);
                 }
                 else
                 {
                     TryDeleteFile(info2);
                 }
             }
         }
         finally
         {
             if (gotLock)
             {
                 CompilationLock.ReleaseLock();
             }
             ShutDownAppDomainIfRequired();
         }
     }
 }
Ejemplo n.º 2
0
        /*
         * Delete an assembly and all its related files.  The assembly is typically named
         * something like ASPNET.jnw_y10n.dll, while related files are simply jnw_y10n.*.
         */
        internal virtual void RemoveAssemblyAndRelatedFiles(string assemblyName)
        {
            Debug.Trace("DiskBuildResultCache", "RemoveAssemblyAndRelatedFiles(" + assemblyName + ")");

            // If the name doesn't start with the prefix, the cleanup code doesn't apply
            if (!assemblyName.StartsWith(BuildManager.WebAssemblyNamePrefix, StringComparison.Ordinal))
            {
                return;
            }

            // Get rid of the prefix, since related files don't have it
            string baseName = assemblyName.Substring(BuildManager.WebAssemblyNamePrefix.Length);

            bool gotLock = false;

            try {
                // Grab the compilation mutex, since we will remove generated assembly
                CompilationLock.GetLock(ref gotLock);

                DirectoryInfo directory = new DirectoryInfo(_cacheDir);

                // Find all the files that contain the base name
                FileInfo[] files = directory.GetFiles("*" + baseName + ".*");
                foreach (FileInfo f in files)
                {
                    if (f.Extension == ".dll")
                    {
                        // Notify existing buildresults that result assembly will be removed.
                        // This is required otherwise new components can be compiled
                        // with obsolete build results whose assembly has been removed.
                        string assemblyKey = GetAssemblyCacheKey(f.FullName);
                        HttpRuntime.CacheInternal.Remove(assemblyKey);

                        // Remove the assembly
                        RemoveAssembly(f);

                        // Also, remove satellite assemblies that may be associated with it
                        StandardDiskBuildResultCache.RemoveSatelliteAssemblies(assemblyName);
                    }
                    else if (f.Extension == dotDelete)
                    {
                        CheckAndRemoveDotDeleteFile(f);
                    }
                    else
                    {
                        // Remove the file, or if not possible, rename it, so it'll get
                        // cleaned up next time by RemoveOldTempFiles()

                        TryDeleteFile(f);
                    }
                }
            }
            finally {
                // Always release the mutex if we had taken it
                if (gotLock)
                {
                    CompilationLock.ReleaseLock();
                }
                DiskBuildResultCache.ShutDownAppDomainIfRequired();
            }
        }
Ejemplo n.º 3
0
        /*
         * Init code used when we are precompiling an app
         */
        private void PrecompilationModeInitialize() {

            // We are precompiling an app

            // Always try the memory cache first
            _memoryCache = new MemoryBuildResultCache(HttpRuntime.CacheInternal);

            // Create a regular disk cache, to take advantage of the fact that the app
            // may already have been compiled (and to cause it to be if it wasn't)
            _codeGenCache = new StandardDiskBuildResultCache(HttpRuntime.CodegenDirInternal);

            // Create a special disk cache in the target's bin directory.  Use a slightly different
            // implementation for the updatable case.
            string targetBinDir = Path.Combine(_precompTargetPhysicalDir, HttpRuntime.BinDirectoryName);
            BuildResultCache preCompilationCache;
            if (PrecompilingForUpdatableDeployment) {
                preCompilationCache = new UpdatablePrecompilerDiskBuildResultCache(targetBinDir);
            }
            else {
                preCompilationCache = new PrecompilerDiskBuildResultCache(targetBinDir);
            }

            _caches = new BuildResultCache[] { _memoryCache, preCompilationCache, _codeGenCache };
        }
Ejemplo n.º 4
0
        /*
         * Init code used when we are running a precompiled app
         */
        private void PrecompiledAppRuntimeModeInitialize() {

            //
            // Initialize the caches
            //

            // Always try the memory cache first
            _memoryCache = new MemoryBuildResultCache(HttpRuntime.CacheInternal);

            // Used the precomp cache for precompiled apps
            BuildResultCache preCompCache = new PrecompiledSiteDiskBuildResultCache(
                HttpRuntime.BinDirectoryInternal);

            // Also create a regular disk cache so that we can compile and cache additional things.
            // This is useful even in non-updatable precomp, to cache DefaultWsdlHelpGenerator.aspx.

            _codeGenCache = new StandardDiskBuildResultCache(HttpRuntime.CodegenDirInternal);

            _caches = new BuildResultCache[] { _memoryCache, preCompCache, _codeGenCache };
        }
Ejemplo n.º 5
0
        /*
         * Init code used when we are running a non-precompiled app
         */
        private void RegularAppRuntimeModeInitialize() {

            //
            // Initialize the caches
            //

            // Always try the memory cache first
            _memoryCache = new MemoryBuildResultCache(HttpRuntime.CacheInternal);

            // Use the standard disk cache for regular apps
            _codeGenCache = new StandardDiskBuildResultCache(HttpRuntime.CodegenDirInternal);

            _caches = new BuildResultCache[] { _memoryCache, _codeGenCache };
        }
Ejemplo n.º 6
0
        private void ProcessBuildProviders()
        {
            CompilerType  compilerType = null;
            BuildProvider firstLanguageBuildProvider = null;

            // First, delete all the existing satellite assemblies of the assembly
            // we're about to build (VSWhidbey 87022) (only if it has a fixed name)
            if (OutputAssemblyName != null)
            {
                Debug.Assert(!CbmGenerateOnlyMode);
                StandardDiskBuildResultCache.RemoveSatelliteAssemblies(OutputAssemblyName);
            }

            // List of BuildProvider's that don't ask for a specific language
            ArrayList languageFreeBuildProviders = null;

            foreach (BuildProvider buildProvider in _buildProviders)
            {
                // If it's an InternalBuildProvider, give it the assembly references early on
                buildProvider.SetReferencedAssemblies(_referencedAssemblies);

                // Instruct the internal build providers to continue processing for more parse errors.
                if (!BuildManager.ThrowOnFirstParseError)
                {
                    InternalBuildProvider provider = buildProvider as InternalBuildProvider;
                    if (provider != null)
                    {
                        provider.ThrowOnFirstParseError = false;
                    }
                }

                // Get the language and culture
                CompilerType ctwp = BuildProvider.GetCompilerTypeFromBuildProvider(buildProvider);

                // Only look for a culture if we're supposed to (basically, in the resources directories)
                string cultureName = null;
                if (_supportLocalization)
                {
                    cultureName = buildProvider.GetCultureName();
                }

                // Is it asking for a specific language?
                if (ctwp != null)
                {
                    // If it specifies a language, it can't also have a culture
                    if (cultureName != null)
                    {
                        throw new HttpException(SR.GetString(SR.Both_culture_and_language, BuildProvider.GetDisplayName(buildProvider)));
                    }

                    // Do we already know the language we'll be using
                    if (compilerType != null)
                    {
                        // If it's different from the current one, fail
                        if (!ctwp.Equals(compilerType))
                        {
                            throw new HttpException(SR.GetString(SR.Inconsistent_language,
                                                                 BuildProvider.GetDisplayName(buildProvider),
                                                                 BuildProvider.GetDisplayName(firstLanguageBuildProvider)));
                        }
                    }
                    else
                    {
                        // Keep track of the build provider of error handling purpose
                        firstLanguageBuildProvider = buildProvider;

                        // Keep track of the language
                        compilerType     = ctwp;
                        _assemblyBuilder = compilerType.CreateAssemblyBuilder(
                            CompConfig, _referencedAssemblies, _generatedFilesDir, OutputAssemblyName);
                    }
                }
                else
                {
                    if (cultureName != null)
                    {
                        // Ignore the culture files in generate-only mode
                        if (CbmGenerateOnlyMode)
                        {
                            continue;
                        }

                        if (_satelliteAssemblyBuilders == null)
                        {
                            _satelliteAssemblyBuilders = new Hashtable(
                                StringComparer.OrdinalIgnoreCase);
                        }

                        // Check if we already have an assembly builder for this culture
                        AssemblyBuilder satelliteAssemblyBuilder =
                            (AssemblyBuilder)_satelliteAssemblyBuilders[cultureName];

                        // If not, create one and store it in the hashtable
                        if (satelliteAssemblyBuilder == null)
                        {
                            satelliteAssemblyBuilder = CompilerType.GetDefaultAssemblyBuilder(
                                CompConfig, _referencedAssemblies, _configPath, OutputAssemblyName);
                            satelliteAssemblyBuilder.CultureName    = cultureName;
                            _satelliteAssemblyBuilders[cultureName] = satelliteAssemblyBuilder;
                        }

                        satelliteAssemblyBuilder.AddBuildProvider(buildProvider);
                        continue;
                    }

                    if (_assemblyBuilder == null)
                    {
                        // If this provider doesn't need a specific language, and we don't know
                        // the language yet, just keep track of it
                        if (languageFreeBuildProviders == null)
                        {
                            languageFreeBuildProviders = new ArrayList();
                        }
                        languageFreeBuildProviders.Add(buildProvider);
                        continue;
                    }
                }

                _assemblyBuilder.AddBuildProvider(buildProvider);
            }

            // If we didn't get an AssemblyBuilder, use a default
            if (_assemblyBuilder == null && languageFreeBuildProviders != null)
            {
                _assemblyBuilder = CompilerType.GetDefaultAssemblyBuilder(
                    CompConfig, _referencedAssemblies, _configPath,
                    _generatedFilesDir, OutputAssemblyName);
            }

            // Add all the language free providers (if any) to the AssemblyBuilder
            if (_assemblyBuilder != null && languageFreeBuildProviders != null)
            {
                foreach (BuildProvider languageFreeBuildProvider in languageFreeBuildProviders)
                {
                    _assemblyBuilder.AddBuildProvider(languageFreeBuildProvider);
                }
            }
        }
        private void ProcessBuildProviders()
        {
            CompilerType type = null;

            System.Web.Compilation.BuildProvider buildProvider = null;
            if (this.OutputAssemblyName != null)
            {
                StandardDiskBuildResultCache.RemoveSatelliteAssemblies(this.OutputAssemblyName);
            }
            ArrayList list = null;

            foreach (System.Web.Compilation.BuildProvider provider2 in this._buildProviders)
            {
                provider2.SetReferencedAssemblies(this._referencedAssemblies);
                if (!BuildManager.ThrowOnFirstParseError)
                {
                    InternalBuildProvider provider3 = provider2 as InternalBuildProvider;
                    if (provider3 != null)
                    {
                        provider3.ThrowOnFirstParseError = false;
                    }
                }
                CompilerType compilerTypeFromBuildProvider = System.Web.Compilation.BuildProvider.GetCompilerTypeFromBuildProvider(provider2);
                string       cultureName = null;
                if (this._supportLocalization)
                {
                    cultureName = provider2.GetCultureName();
                }
                if (compilerTypeFromBuildProvider != null)
                {
                    if (cultureName != null)
                    {
                        throw new HttpException(System.Web.SR.GetString("Both_culture_and_language", new object[] { System.Web.Compilation.BuildProvider.GetDisplayName(provider2) }));
                    }
                    if (type != null)
                    {
                        if (!compilerTypeFromBuildProvider.Equals(type))
                        {
                            throw new HttpException(System.Web.SR.GetString("Inconsistent_language", new object[] { System.Web.Compilation.BuildProvider.GetDisplayName(provider2), System.Web.Compilation.BuildProvider.GetDisplayName(buildProvider) }));
                        }
                    }
                    else
                    {
                        buildProvider         = provider2;
                        this._assemblyBuilder = compilerTypeFromBuildProvider.CreateAssemblyBuilder(this.CompConfig, this._referencedAssemblies, this._generatedFilesDir, this.OutputAssemblyName);
                    }
                }
                else
                {
                    if (cultureName != null)
                    {
                        if (!this.CbmGenerateOnlyMode)
                        {
                            if (this._satelliteAssemblyBuilders == null)
                            {
                                this._satelliteAssemblyBuilders = new Hashtable(StringComparer.OrdinalIgnoreCase);
                            }
                            AssemblyBuilder builder = (AssemblyBuilder)this._satelliteAssemblyBuilders[cultureName];
                            if (builder == null)
                            {
                                builder             = CompilerType.GetDefaultAssemblyBuilder(this.CompConfig, this._referencedAssemblies, this._configPath, this.OutputAssemblyName);
                                builder.CultureName = cultureName;
                                this._satelliteAssemblyBuilders[cultureName] = builder;
                            }
                            builder.AddBuildProvider(provider2);
                        }
                        continue;
                    }
                    if (this._assemblyBuilder == null)
                    {
                        if (list == null)
                        {
                            list = new ArrayList();
                        }
                        list.Add(provider2);
                        continue;
                    }
                }
                this._assemblyBuilder.AddBuildProvider(provider2);
            }
            if ((this._assemblyBuilder == null) && (list != null))
            {
                this._assemblyBuilder = CompilerType.GetDefaultAssemblyBuilder(this.CompConfig, this._referencedAssemblies, this._configPath, this._generatedFilesDir, this.OutputAssemblyName);
            }
            if ((this._assemblyBuilder != null) && (list != null))
            {
                foreach (System.Web.Compilation.BuildProvider provider4 in list)
                {
                    this._assemblyBuilder.AddBuildProvider(provider4);
                }
            }
        }