Example #1
0
        public static ExpressionEditor GetExpressionEditor(string expressionPrefix, IServiceProvider serviceProvider)
        {
            if (serviceProvider == null)
            {
                return(null);
            }

            IWebApplication webApp = (IWebApplication)serviceProvider.GetService(typeof(IWebApplication));

            if (webApp == null)
            {
                return(null);
            }

            _Configuration config = webApp.OpenWebConfiguration(true);

            if (config == null)
            {
                return(null);
            }

            CompilationSection sec = (CompilationSection)config.GetSection("system.web/compilation");

            System.Web.Configuration.ExpressionBuilder builder = sec.ExpressionBuilders [expressionPrefix];

            if (builder == null)
            {
                return(null);
            }

            return(GetExpressionEditor(Type.GetType(builder.Type), serviceProvider));
        }
Example #2
0
 protected void Page_Init(object sender, EventArgs e)
 {
     config      = WebConfigurationManager.OpenWebConfiguration("/mod9lab");
     compilation =
         (CompilationSection)config.GetSection("system.web/compilation");
     _debugStatus = compilation.Debug;
 }
Example #3
0
        internal static Type GetBuildProviderTypeFromExtension(CompilationSection config, string extension, BuildProviderAppliesTo neededFor, bool failIfUnknown)
        {
            BuildProviderInfo buildProviderInfo = System.Web.Compilation.BuildProvider.GetBuildProviderInfo(config, extension);
            Type c = null;

            if (((buildProviderInfo != null) && (buildProviderInfo.Type != typeof(IgnoreFileBuildProvider))) && (buildProviderInfo.Type != typeof(ForceCopyBuildProvider)))
            {
                c = buildProviderInfo.Type;
            }
            if (((neededFor == BuildProviderAppliesTo.Web) && BuildManager.PrecompilingForUpdatableDeployment) && !typeof(BaseTemplateBuildProvider).IsAssignableFrom(c))
            {
                c = null;
            }
            if (c != null)
            {
                if ((neededFor & buildProviderInfo.AppliesTo) != 0)
                {
                    return(c);
                }
            }
            else if ((neededFor != BuildProviderAppliesTo.Resources) && (config.GetCompilerInfoFromExtension(extension, false) != null))
            {
                return(typeof(SourceFileBuildProvider));
            }
            if (failIfUnknown)
            {
                throw new HttpException(System.Web.SR.GetString("Unknown_buildprovider_extension", new object[] { extension, neededFor.ToString() }));
            }
            return(null);
        }
 internal WebDirectoryBatchCompiler(VirtualDirectory vdir)
 {
     this._vdir                 = vdir;
     this._utcStart             = DateTime.UtcNow;
     this._compConfig           = MTConfigUtil.GetCompilationConfig(this._vdir.VirtualPath);
     this._referencedAssemblies = BuildManager.GetReferencedAssemblies(this._compConfig);
 }
        internal bool AllowVirtualReference(CompilationSection compConfig, System.Web.VirtualPath referenceVirtualPath)
        {
            VirtualReferenceType page;
            string extension = referenceVirtualPath.Extension;
            Type   type      = CompilationUtil.GetBuildProviderTypeFromExtension(compConfig, extension, BuildProviderAppliesTo.Web, false);

            if (type == null)
            {
                return(false);
            }
            if (type == typeof(PageBuildProvider))
            {
                page = VirtualReferenceType.Page;
            }
            else if (type == typeof(UserControlBuildProvider))
            {
                page = VirtualReferenceType.UserControl;
            }
            else if (type == typeof(MasterPageBuildProvider))
            {
                page = VirtualReferenceType.Master;
            }
            else if (type == typeof(SourceFileBuildProvider))
            {
                page = VirtualReferenceType.SourceFile;
            }
            else
            {
                page = VirtualReferenceType.Other;
            }
            return(this.AllowVirtualReference(referenceVirtualPath.VirtualPathString, page));
        }
Example #6
0
        // Add the referenced assemblies into the compileParameters. Notice that buildProviders do not have
        // the correct referenced assemblies and we don't cache them since the assemblies could change
        // between appdomains. (removing assemblies from bin, etc)
        private void FixupReferencedAssemblies(VirtualPath virtualPath, CompilerParameters compilerParameters)
        {
            CompilationSection compConfig = MTConfigUtil.GetCompilationConfig(virtualPath);

            ICollection referencedAssemblies = BuildManager.GetReferencedAssemblies(compConfig);
            Util.AddAssembliesToStringCollection(referencedAssemblies, compilerParameters.ReferencedAssemblies);
        }
Example #7
0
        protected override void ComputeHashCode(HashCodeCombiner hashCodeCombiner)
        {
            base.ComputeHashCode(hashCodeCombiner);
            CompilationSection compilationConfig = MTConfigUtil.GetCompilationConfig(base.VirtualPath);

            hashCodeCombiner.AddObject(compilationConfig.RecompilationHash);
        }
Example #8
0
        static Settings()
        {
            //PagesSection ps = (PagesSection)WebConfigurationManager.GetSection("system.web/pages");
            //List<string> ns = new List<string>(ps.Namespaces.Count);
            //foreach (NamespaceInfo n in ps.Namespaces)
            //    ns.Add(n.Namespace);
            CompilationSection   cs = (CompilationSection)WebConfigurationManager.GetSection("system.web/compilation");
            GlobalizationSection gs = (GlobalizationSection)WebConfigurationManager.GetSection("system.web/globalization");
            SiteSection          ss = SiteSection.GetSection();

            _configSettings          = new Settings();
            _configSettings._rootUrl = HttpContext.Current.Request.ApplicationPath;
            if (!_configSettings._rootUrl.EndsWith("/"))
            {
                _configSettings._rootUrl = string.Concat(_configSettings._rootUrl, "/");
            }
            //_configSettings._controllerNamespaces = ns.ToArray();
            _configSettings._theme            = ss.Theme;
            _configSettings._themePath        = GetTempPath(_configSettings._theme);
            _configSettings._themeUrl         = string.Concat(_configSettings._rootUrl, "themes/", _configSettings._theme, "/");
            _configSettings._debug            = cs.Debug;
            _configSettings._responseEncoding = gs.ResponseEncoding;
            _configSettings._fileEncoding     = gs.FileEncoding;
            _configSettings._urlMode          = ss.UrlMode;
            //_configSettings._urlExt = ss.UrlExt;
            _configSettings._management    = ss.Management;
            _configSettings._wapDomain     = ss.WapDomain;
            _configSettings._subDomain     = ss.SubDomain;
            _configSettings._dataProvider  = ss.DataProvider;
            _configSettings._cacheMode     = ss.CacheMode;
            _configSettings._cacheProvider = ss.CacheProvider;
            _configSettings._resources     = ss.ResourcesUrl;
            _configSettings._passport      = ss.PassportUrl;
            _configSettings._wapPassport   = ss.WapPassportUrl;
        }
Example #9
0
        public static void Configure()
        {
            JsEngineSwitcher.Instance.DefaultEngineName = V8JsEngine.EngineName;

            CompilationSection compilationSection =
                (CompilationSection)ConfigurationManager.GetSection("system.web/compilation");

            if (compilationSection.Debug)
            {
                ReactSiteConfiguration.Configuration
                .SetLoadBabel(false)
                .SetLoadReact(false)
                .SetReuseJavaScriptEngines(false)
                //.DisableServerSideRendering()
                .SetUseDebugReact(true)
                .AddScriptWithoutTransform("~/scripts/server.js");
            }
            else
            {
                ReactSiteConfiguration.Configuration
                .SetLoadBabel(false)
                .SetLoadReact(false)
                .AddScriptWithoutTransform("~/scripts/server.min.js");
            }
        }
        private static bool GetDebugFromConfig()
        {
            CompilationSection section =
                (CompilationSection)WebConfigurationManager.GetWebApplicationSection("system.web/compilation");

            return(section.Debug);
        }
 internal AssemblyBuilder(CompilationSection compConfig, ICollection referencedAssemblies, CompilerType compilerType, string outputAssemblyName)
 {
     this._compConfig                  = compConfig;
     this._outputAssemblyName          = outputAssemblyName;
     this._initialReferencedAssemblies = AssemblySet.Create(referencedAssemblies);
     this._compilerType                = compilerType.Clone();
     if (BuildManager.PrecompilingWithDebugInfo)
     {
         this._compilerType.CompilerParameters.IncludeDebugInformation = true;
     }
     else if (BuildManager.PrecompilingForDeployment)
     {
         this._compilerType.CompilerParameters.IncludeDebugInformation = false;
     }
     else if (DeploymentSection.RetailInternal)
     {
         this._compilerType.CompilerParameters.IncludeDebugInformation = false;
     }
     else if (this._compConfig.AssemblyPostProcessorTypeInternal != null)
     {
         this._compilerType.CompilerParameters.IncludeDebugInformation = true;
     }
     this._tempFiles.KeepFiles       = this._compilerType.CompilerParameters.IncludeDebugInformation;
     this._codeProvider              = CompilationUtil.CreateCodeDomProviderNonPublic(this._compilerType.CodeDomProviderType);
     this._maxBatchSize              = this._compConfig.MaxBatchSize;
     this._maxBatchGeneratedFileSize = this._compConfig.MaxBatchGeneratedFileSize * 0x400;
 }
        private void LoadExpressionEditors()
        {
            this._expressionEditors = new HybridDictionary(true);
            IWebApplication service = (IWebApplication)base.ServiceProvider.GetService(typeof(IWebApplication));

            if (service != null)
            {
                try
                {
                    System.Configuration.Configuration configuration = service.OpenWebConfiguration(true);
                    if (configuration != null)
                    {
                        CompilationSection section = (CompilationSection)configuration.GetSection("system.web/compilation");
                        foreach (ExpressionBuilder builder in section.ExpressionBuilders)
                        {
                            string           expressionPrefix = builder.ExpressionPrefix;
                            ExpressionEditor expressionEditor = ExpressionEditor.GetExpressionEditor(expressionPrefix, base.ServiceProvider);
                            if (expressionEditor != null)
                            {
                                this._expressionEditors[expressionPrefix] = expressionEditor;
                                this._expressionBuilderComboBox.Items.Add(new ExpressionItem(expressionPrefix));
                            }
                        }
                    }
                }
                catch
                {
                }
                this._expressionBuilderComboBox.InvalidateDropDownWidth();
            }
            this._expressionBuilderComboBox.Items.Add(this.NoneItem);
        }
Example #13
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        byte[] arr = new byte[24];
        RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();

        rng.GetBytes(arr);
        System.Text.StringBuilder machineKey = new System.Text.StringBuilder(24);
        for (int i = 0; i < arr.Length; i++)
        {
            machineKey.Append(String.Format("{0:X2}", arr[i]));
        }
        Page.Response.Write(machineKey.ToString());



        Page.Response.Write(WebConfigurationManager.AppSettings["topic"] + "<br />");
        Page.Response.Write(WebConfigurationManager.ConnectionStrings["NorthwindConnection"] + "<br />");
        Page.Response.Write(WebConfigurationManager.GetSection("connectionStrings") + "<br />");
        CompilationSection cs = (CompilationSection)WebConfigurationManager.GetSection("system.web/compilation");

        foreach (AssemblyInfo item in cs.Assemblies)
        {
            Response.Write(item.Assembly + "<br /");
        }
    }
Example #14
0
        public static HtmlString ScriptLinkBundle(this HtmlHelper htmlHelper, IList <string> unbundledfiles, string bundledfile, string cachebusterKey = "")
        {
            string             scripttags    = string.Empty;
            CompilationSection configSection = (CompilationSection)ConfigurationManager.GetSection("system.web/compilation");

            if (configSection.Debug)
            {
                foreach (var file in unbundledfiles)
                {
                    var scripttag = new TagBuilder("script");
                    scripttag.MergeAttribute("type", "text/javascript");
                    scripttag.MergeAttribute("src", file);
                    scripttags += scripttag.ToString();
                }
            }
            else
            {
                var scripttag = new TagBuilder("script");
                scripttag.MergeAttribute("type", "text/javascript");

                if (string.IsNullOrWhiteSpace(cachebusterKey) || ConfigurationManager.AppSettings[cachebusterKey] == null)
                {
                    scripttag.MergeAttribute("src", bundledfile);
                }
                else
                {
                    scripttag.MergeAttribute("src", string.Format("{0}?v={1}", bundledfile, ConfigurationManager.AppSettings[cachebusterKey]));
                }

                scripttags = scripttag.ToString();
            }

            return(new HtmlString(scripttags));
        }
Example #15
0
        internal static CodeDomProvider CreateProvider(HttpContext context, string lang, out CompilerParameters par, out string tempdir)
        {
            CodeDomProvider ret = null;

            par = null;

            CompilationSection config = (CompilationSection)WebConfigurationManager.GetWebApplicationSection("system.web/compilation");
            Compiler           comp   = config.Compilers[lang];

            if (comp == null)
            {
                CompilerInfo info = CodeDomProvider.GetCompilerInfo(lang);
                if (info != null && info.IsCodeDomProviderTypeValid)
                {
                    ret = info.CreateProvider();
                    par = info.CreateDefaultCompilerParameters();
                }
            }
            else
            {
                Type t = HttpApplication.LoadType(comp.Type, true);
                ret = Activator.CreateInstance(t) as CodeDomProvider;

                par = new CompilerParameters();
                par.CompilerOptions = comp.CompilerOptions;
                par.WarningLevel    = comp.WarningLevel;
            }
            tempdir = config.TempDirectory;

            return(ret);
        }
        public void Defaults()
        {
            CompilationSection c = new CompilationSection();

            Assert.IsNotNull(c.Assemblies, "A1");

            Assert.AreEqual("", c.AssemblyPostProcessorType, "A2");
            Assert.IsTrue(c.Batch, "A3");
            Assert.AreEqual(TimeSpan.FromMinutes(15), c.BatchTimeout, "A4");

            Assert.IsNotNull(c.BuildProviders, "A5");
            Assert.IsNotNull(c.CodeSubDirectories, "A6");
            Assert.IsNotNull(c.Compilers, "A7");

            Assert.IsFalse(c.Debug, "A8");
            Assert.AreEqual("vb", c.DefaultLanguage, "A9");
            Assert.IsTrue(c.Explicit, "A10");

            Assert.IsNotNull(c.ExpressionBuilders, "A11");
            Assert.AreEqual(1000, c.MaxBatchSize, "A12");
            Assert.AreEqual(15, c.NumRecompilesBeforeAppRestart, "A13");
            Assert.IsFalse(c.Strict, "A14");
            Assert.AreEqual("", c.TempDirectory, "A15");
            Assert.IsFalse(c.UrlLinePragmas, "A16");
        }
Example #17
0
        // Returns the list of buildProvider types associated to the specified appliesTo
        internal static List <Type> GetFolderLevelBuildProviderTypes(CompilationSection config,
                                                                     FolderLevelBuildProviderAppliesTo appliesTo)
        {
            FolderLevelBuildProviderCollection buildProviders = config.FolderLevelBuildProviders;

            return(buildProviders.GetBuildProviderTypes(appliesTo));
        }
        private bool CheckAuth(HttpContext context)
        {
            CompilationSection ds = (CompilationSection)WebConfigurationManager.GetSection("system.web/compilation");

            if (ds.Debug)
            {
                return(true);
            }

            bool            result       = false;
            string          access_token = context.Request["access_token"];
            List <ApiToken> tokenList    = context.Application["api_token"] as List <ApiToken>;

            if (tokenList == null)
            {
                tokenList = new List <ApiToken>();
            }
            ApiToken token = (from i in tokenList where i.access_token == access_token select i).SingleOrDefault();

            if (token != null)
            {
                if (token.update_time.AddSeconds(7200) <= DateTime.Now)
                {
                    result = true;
                }
            }
            return(result);
        }
 void ProcessRemove(string val, CompilationSection section, SettingsMappingWhatContents how)
 {
     if (val == "assemblies")
     {
         RemoveAssembly(section, how);
     }
 }
Example #20
0
        /*
         * Return a CompilerType that a language maps to.
         */
        internal static CompilerType GetCompilerInfoFromLanguage(VirtualPath configPath, string language)
        {
            // Get the <compilation> config object
            CompilationSection config = MTConfigUtil.GetCompilationConfig(configPath);

            return(config.GetCompilerInfoFromLanguage(language));
        }
Example #21
0
        /*
         * Return a CompilerType that a extension maps to.
         */
        private static CompilerType GetCompilerInfoFromExtension(VirtualPath configPath, string extension)
        {
            // Get the <compilation> config object
            CompilationSection config = MTConfigUtil.GetCompilationConfig(configPath);

            return(config.GetCompilerInfoFromExtension(extension, true /*throwOnFail*/));
        }
        /// <inheritdoc/>
        protected override void OnException(ExceptionContext filterContext)
        {
            CompilationSection compilationSection = (CompilationSection)WebConfigurationManager.GetSection(@"system.web/compilation");

            if (compilationSection.Debug)
            {
                return;
            }

            if (filterContext.ExceptionHandled)
            {
                return;
            }

            // Log the exception.
            LogHelper.Error <ZoombracoController>("Handled Exception: ", filterContext.Exception);

            // Set the correct view.
            HttpException httpException = filterContext.Exception as HttpException;

            if (httpException != null)
            {
                int statusCode = httpException.GetHttpCode();
                filterContext.HttpContext.Response.StatusDescription = httpException.Message;
                filterContext.HttpContext.Response.StatusCode        = statusCode;
            }

            filterContext.Result           = this.View(this.ErrorViewName);
            filterContext.ExceptionHandled = true;
        }
        /*
         * Returns an array of the assemblies defined in the bin and assembly reference config section
         */
        internal String[] GetTopLevelAssemblyReferences(VirtualPath virtualPath)
        {
            // Add a pending call to make sure our thread doesn't get killed
            AddPendingCall();

            List <Assembly> assemblyList = new List <Assembly>();

            try {
                // Treat it as relative to the app root
                virtualPath.CombineWithAppRoot();

                CompilationSection compConfig = MTConfigUtil.GetCompilationConfig(virtualPath);

                // Add all the config assemblies to the list
                foreach (AssemblyInfo assemblyInfo in compConfig.Assemblies)
                {
                    Assembly[] assemblies = assemblyInfo.AssemblyInternal;
                    for (int i = 0; i < assemblies.Length; i++)
                    {
                        if (assemblies[i] != null)
                        {
                            assemblyList.Add(assemblies[i]);
                        }
                    }
                }
            } finally {
                RemovePendingCall();
            }
            StringCollection paths = new StringCollection();

            Util.AddAssembliesToStringCollection(assemblyList, paths);
            string[] references = new string[paths.Count];
            paths.CopyTo(references, 0);
            return(references);
        }
        /// <summary>
        /// Check whether an assembly has dependencies to a framework assembly of a higher version,
        /// report the issue as a warning or error.
        /// </summary>
        private static void CheckOutOfRangeDependencies(string assemblyName)
        {
            string       dependencies = null;
            Assembly     assembly     = Assembly.Load(assemblyName);
            AssemblyName aName        = new AssemblyName(assemblyName);

            // If the loaded assembly has a different version than the specified assembly,
            // then it is likely that there was unification or binding redirect in place.
            // If that is the case, then GetReferenceAssemblies won't be accurate for
            // finding the references of the actual assembly, so we skip checking its references.
            if (assembly.GetName().Version != aName.Version)
            {
                return;
            }

            foreach (AssemblyName name in assembly.GetReferencedAssemblies())
            {
                try {
                    Assembly referenceAssembly = CompilationSection.LoadAndRecordAssembly(name);
                    string   path;
                    ReferenceAssemblyType referenceAssemblyType =
                        GetPathToReferenceAssembly(referenceAssembly, out path, null, null, false /*checkDependencies*/);

                    // We need to check the following 2 conditions:
                    // 1. If the assembly is available in the target framework, we also need to
                    // verify that the version being referenced is no higher than what we have
                    // in the target framework.
                    // 2. If the assembly is only available in a higher version framework.
                    Version resolvedAssemblyVersion = GetAssemblyVersion(path);
                    if (resolvedAssemblyVersion == null)
                    {
                        continue;
                    }

                    if ((referenceAssemblyType == ReferenceAssemblyType.FrameworkAssembly && resolvedAssemblyVersion < name.Version) ||
                        referenceAssemblyType == ReferenceAssemblyType.FrameworkAssemblyOnlyPresentInHigherVersion)
                    {
                        if (dependencies == null)
                        {
                            dependencies = name.FullName;
                        }
                        else
                        {
                            dependencies += "; " + name.FullName;
                        }
                    }
                }
                catch {
                    // Ignore dependencies that are not found, as we are primarily concerned
                    // with framework assemblies that are on the machine.
                }
            }

            if (dependencies != null)
            {
                string message = SR.GetString(SR.Higher_dependencies, assemblyName, dependencies);
                ReportWarningOrError(message);
            }
        }
 internal BuildProvidersCompiler(VirtualPath configPath, bool supportLocalization, string outputAssemblyName)
 {
     this._configPath           = configPath;
     this._supportLocalization  = supportLocalization;
     this._compConfig           = MTConfigUtil.GetCompilationConfig(this._configPath);
     this._referencedAssemblies = BuildManager.GetReferencedAssemblies(this.CompConfig);
     this._outputAssemblyName   = outputAssemblyName;
 }
Example #26
0
        /*
         * Return a file provider Type that an extension maps to.
         */
        internal static Type GetBuildProviderTypeFromExtension(VirtualPath configPath, string extension,
                                                               BuildProviderAppliesTo neededFor, bool failIfUnknown)
        {
            // Get the <compilation> config object
            CompilationSection config = MTConfigUtil.GetCompilationConfig(configPath);

            return(GetBuildProviderTypeFromExtension(config, extension, neededFor, failIfUnknown));
        }
 internal AssemblyBuilder CreateAssemblyBuilder(CompilationSection compConfig, ICollection referencedAssemblies, string generatedFilesDir, string outputAssemblyName)
 {
     if (generatedFilesDir != null)
     {
         return(new CbmCodeGeneratorBuildProviderHost(compConfig, referencedAssemblies, this, generatedFilesDir, outputAssemblyName));
     }
     return(new AssemblyBuilder(compConfig, referencedAssemblies, this, outputAssemblyName));
 }
 internal BuildProvidersCompiler(VirtualPath configPath, bool supportLocalization, string generatedFilesDir, int index)
 {
     this._configPath           = configPath;
     this._supportLocalization  = supportLocalization;
     this._compConfig           = MTConfigUtil.GetCompilationConfig(this._configPath);
     this._referencedAssemblies = BuildManager.GetReferencedAssemblies(this.CompConfig, index);
     this._generatedFilesDir    = generatedFilesDir;
 }
Example #29
0
        internal static AssemblyBuilder GetDefaultAssemblyBuilder(CompilationSection compConfig,
                                                                  ICollection referencedAssemblies, VirtualPath configPath,
                                                                  string generatedFilesDir, string outputAssemblyName)
        {
            CompilerType ctwp = GetDefaultCompilerTypeWithParams(compConfig, configPath);

            return(ctwp.CreateAssemblyBuilder(compConfig, referencedAssemblies,
                                              generatedFilesDir, outputAssemblyName));
        }
Example #30
0
        public static BundleOptions GetBundleOptionByDebugMode()
        {
            CompilationSection compilationSection =
                (CompilationSection)ConfigurationManager.GetSection(@"system.web/compilation");

            return(compilationSection.Debug
                ? BundleOptions.Combined
                : BundleOptions.MinifiedAndCombined);
        }