internal Object Create() { // HACKHACK: for now, let uncreatable types through and error later (for .soap factory) // This design should change - developers will want to know immediately // when they misspell a type if (_type == null) { Type t = Type.GetType(_typename, true); // throw for bad types in deferred case if (!IsTypeHandlerOrFactory(t)) { throw new HttpException(HttpRuntime.FormatResourceString(SR.Type_not_factory_or_handler, _typename)); } if (!HttpRuntime.HasAspNetHostingPermission(AspNetHostingPermissionLevel.Unrestricted)) { if (!IsTypeFromAssemblyWithAPTCA(t) && IsTypeFromAssemblyWithStrongName(t)) { throw new HttpException(HttpRuntime.FormatResourceString(SR.Type_from_untrusted_assembly, _typename)); } } _type = t; } return(HttpRuntime.CreateNonPublicInstance(_type)); }
internal HttpCapabilitiesBase EvaluateFinal(HttpRequest request, bool onlyEvaluateUserAgent) { HttpBrowserCapabilities httpBrowserCapabilities = this.BrowserCapFactory.GetHttpBrowserCapabilities(request); CapabilitiesState state = new CapabilitiesState(request, httpBrowserCapabilities.Capabilities); if (onlyEvaluateUserAgent) { state.EvaluateOnlyUserAgent = true; } if (this._rule != null) { string str = httpBrowserCapabilities["isMobileDevice"]; httpBrowserCapabilities.Capabilities["isMobileDevice"] = null; this._rule.Evaluate(state); string str2 = httpBrowserCapabilities["isMobileDevice"]; if (str2 == null) { httpBrowserCapabilities.Capabilities["isMobileDevice"] = str; } else if (str2.Equals("true")) { httpBrowserCapabilities.DisableOptimizedCacheKey(); } } HttpCapabilitiesBase base2 = (HttpCapabilitiesBase)HttpRuntime.CreateNonPublicInstance(this._resultType); base2.InitInternal(httpBrowserCapabilities); return(base2); }
public IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated) { if (this._handler == null) { this._handler = (IHttpHandler)HttpRuntime.CreateNonPublicInstance(this._handlerType); } return(this._handler); }
internal object Create(string type) { // HACKHACK: for now, let uncreatable types through and error later (for .soap factory) // This design should change - developers will want to know immediately // when they misspell a type return(HttpRuntime.CreateNonPublicInstance(GetHandlerType(type))); }
internal MemCache(CacheCommon cacheCommon) : base(cacheCommon) { // config initialization is done by Init. Assembly asm = Assembly.Load("System.Runtime.Caching, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"); Type t = asm.GetType("System.Runtime.Caching.MemoryCache", true, false); _cacheInternal = HttpRuntime.CreateNonPublicInstance(t, new object[] { "asp_icache", null, true }) as MemoryCache; _cachePublic = HttpRuntime.CreateNonPublicInstance(t, new object[] { "asp_pcache", null, true }) as MemoryCache; }
private static IWebPropertyAccessor GetPropertyAccessor(Type type, string propertyName) { if ((s_accessorGenerator == null) || (s_accessorCache == null)) { lock (s_lockObject) { if ((s_accessorGenerator == null) || (s_accessorCache == null)) { s_accessorGenerator = new FastPropertyAccessor(); s_accessorCache = new Hashtable(); } } } int num = HashCodeCombiner.CombineHashCodes(type.GetHashCode(), propertyName.GetHashCode()); IWebPropertyAccessor accessor = (IWebPropertyAccessor)s_accessorCache[num]; if (accessor == null) { Type type2; FieldInfo fieldInfo = null; PropertyInfo propInfo = null; GetPropertyInfo(type, propertyName, out propInfo, out fieldInfo, out type2); int num2 = 0; if (type2 != type) { num2 = HashCodeCombiner.CombineHashCodes(type2.GetHashCode(), propertyName.GetHashCode()); accessor = (IWebPropertyAccessor)s_accessorCache[num2]; if (accessor != null) { lock (s_accessorCache.SyncRoot) { s_accessorCache[num] = accessor; } return(accessor); } } if (accessor == null) { Type type3; lock (s_accessorGenerator) { type3 = s_accessorGenerator.GetPropertyAccessorTypeWithAssert(type2, propertyName, propInfo, fieldInfo); } accessor = (IWebPropertyAccessor)HttpRuntime.CreateNonPublicInstance(type3); } lock (s_accessorCache.SyncRoot) { s_accessorCache[num] = accessor; if (num2 != 0) { s_accessorCache[num2] = accessor; } } } return(accessor); }
internal static CodeDomProvider CreateCodeDomProviderNonPublic(Type codeDomProviderType) { CodeDomProvider codeDomProvider = CreateCodeDomProviderWithPropertyOptions(codeDomProviderType); if (codeDomProvider != null) { return(codeDomProvider); } return((CodeDomProvider)HttpRuntime.CreateNonPublicInstance(codeDomProviderType)); }
internal PageParserFilter CreateControlTypeFilter() { Type pageParserFilterTypeInternal = this.PageParserFilterTypeInternal; if (pageParserFilterTypeInternal == null) { return(null); } return((PageParserFilter)HttpRuntime.CreateNonPublicInstance(pageParserFilterTypeInternal)); }
internal object Create() { if (this._type == null) { System.Type t = ConfigUtil.GetType(this.Type, "type", this); if (!ConfigUtil.IsTypeHandlerOrFactory(t)) { throw new ConfigurationErrorsException(System.Web.SR.GetString("Type_not_factory_or_handler", new object[] { this.Type }), base.ElementInformation.Source, base.ElementInformation.LineNumber); } this._type = t; } return(HttpRuntime.CreateNonPublicInstance(this._type)); }
internal PageParserFilter CreateControlTypeFilter() { Type pageParserFilterType = PageParserFilterTypeInternal; // If no filter type is registered, return null if (pageParserFilterType == null) { return(null); } // Create an instance of the filter return((PageParserFilter)HttpRuntime.CreateNonPublicInstance(pageParserFilterType)); }
private WebEventProvider GetProviderInstance(string providerName) { object obj2 = this._instances[providerName]; if (obj2 == null) { return(null); } ProviderSettings settings = obj2 as ProviderSettings; if (settings != null) { WebEventProvider provider; Type c = BuildManager.GetType(settings.Type, false); if (typeof(IInternalWebEventProvider).IsAssignableFrom(c)) { provider = (WebEventProvider)HttpRuntime.CreateNonPublicInstance(c); } else { provider = (WebEventProvider)HttpRuntime.CreatePublicInstance(c); } ProcessImpersonationContext context = new ProcessImpersonationContext(); try { provider.Initialize(settings.Name, settings.Parameters); } catch (ConfigurationErrorsException) { throw; } catch (ConfigurationException exception) { throw new ConfigurationErrorsException(exception.Message, settings.ElementInformation.Properties["type"].Source, settings.ElementInformation.Properties["type"].LineNumber); } catch { throw; } finally { if (context != null) { ((IDisposable)context).Dispose(); } } this._instances[providerName] = provider; return(provider); } return(obj2 as WebEventProvider); }
public virtual IHttpHandler GetHandler(HttpContext context, string requestType, string virtualPath, string path) { // Parse and (possibly) compile the file into a type Type t = WebHandlerParser.GetCompiledType(virtualPath, path, context); // Make sure the type has the correct base class (ASURT 123677) Util.CheckAssignableType(typeof(IHttpHandler), t); // Create an instance of the type Object obj = HttpRuntime.CreateNonPublicInstance(t); return((IHttpHandler)obj); }
/* * Create a ControlBuilder for a given tag */ /// <include file='doc\ControlBuilder.uex' path='docs/doc[@for="BaseControlBuilder.CreateBuilderFromType"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public static ControlBuilder CreateBuilderFromType(TemplateParser parser, ControlBuilder parentBuilder, Type type, string tagName, string id, IDictionary attribs, int line, string sourceFileName) { Type builderType = null; // Check whether the control's class exposes a custom builder type ControlBuilderAttribute cba = null; object[] attrs = type.GetCustomAttributes(typeof(ControlBuilderAttribute), /*inherit*/ true); if ((attrs != null) && (attrs.Length == 1)) { Debug.Assert(attrs[0] is ControlBuilderAttribute); cba = (ControlBuilderAttribute)attrs[0]; } if (cba != null) { builderType = cba.BuilderType; } ControlBuilder builder; if (builderType != null) { // Make sure the type has the correct base class (ASURT 123677) Util.CheckAssignableType(typeof(ControlBuilder), builderType); // It does, so use it builder = (ControlBuilder)HttpRuntime.CreateNonPublicInstance(builderType); } else { // It doesn't, so use a generic one builder = new ControlBuilder(); } // REVIEW: I'm not putting this in Init because it seems like // it might not be in the spirit of the method (dbau) builder._line = line; builder._sourceFileName = sourceFileName; // Initialize the builder builder.Init(parser, parentBuilder, type, tagName, id, attribs); return(builder); }
internal virtual HttpCapabilitiesBase EvaluateFinal(HttpRequest request, bool onlyEvaluateUserAgent) { // not in cache: calculate the result Hashtable values = new Hashtable(new CaseInsensitiveHashCodeProvider(CultureInfo.InvariantCulture), new CaseInsensitiveComparer(CultureInfo.InvariantCulture)); CapabilitiesState state = new CapabilitiesState(request, values); if (onlyEvaluateUserAgent) { state.EvaluateOnlyUserAgent = true; } _rule.Evaluate(state); // create the new type // CONSIDER: don't allow non-public cap result types HttpCapabilitiesBase result = (HttpCapabilitiesBase)HttpRuntime.CreateNonPublicInstance(_resultType); result.InitInternal(values); return(result); }
internal Object Create() { // HACKHACK: for now, let uncreatable types through and error later (for .soap factory) // This design should change - developers will want to know immediately // when they misspell a type if (_type == null) { Type t = ConfigUtil.GetType(Type, "type", this); // throw for bad types in deferred case if (!ConfigUtil.IsTypeHandlerOrFactory(t)) { throw new ConfigurationErrorsException( SR.GetString(SR.Type_not_factory_or_handler, Type), ElementInformation.Source, ElementInformation.LineNumber); } _type = t; } return(HttpRuntime.CreateNonPublicInstance(_type)); }
internal HttpCapabilitiesBase EvaluateFinal(HttpRequest request, bool onlyEvaluateUserAgent) { HttpBrowserCapabilities browserCaps = BrowserCapFactory.GetHttpBrowserCapabilities(request); CapabilitiesState state = new CapabilitiesState(request, browserCaps.Capabilities); if (onlyEvaluateUserAgent) { state.EvaluateOnlyUserAgent = true; } if (_rule != null) { string oldIsMobileDevice = browserCaps[_isMobileDeviceCapKey]; browserCaps.Capabilities[_isMobileDeviceCapKey] = null; _rule.Evaluate(state); string newIsMobileDevice = browserCaps[_isMobileDeviceCapKey]; if (newIsMobileDevice == null) { browserCaps.Capabilities[_isMobileDeviceCapKey] = oldIsMobileDevice; } else if (newIsMobileDevice.Equals("true")) { browserCaps.DisableOptimizedCacheKey(); } } // create the new type // HttpCapabilitiesBase result = (HttpCapabilitiesBase)HttpRuntime.CreateNonPublicInstance(_resultType); result.InitInternal(browserCaps); return(result); }
public override void GenerateCode(AssemblyBuilder assemblyBuilder) { // Only attempt to get the Indigo provider once if (!s_triedToGetWebRefType) { s_indigoWebRefProviderType = BuildManager.GetType(IndigoWebRefProviderTypeName, false /*throwOnError*/); s_triedToGetWebRefType = true; } // If we have an Indigo provider, instantiate it and forward the GenerateCode call to it if (s_indigoWebRefProviderType != null) { BuildProvider buildProvider = (BuildProvider)HttpRuntime.CreateNonPublicInstance(s_indigoWebRefProviderType); buildProvider.SetVirtualPath(VirtualPathObject); buildProvider.GenerateCode(assemblyBuilder); } // e.g "/MyApp/Application_WebReferences" VirtualPath rootWebRefDirVirtualPath = HttpRuntime.WebRefDirectoryVirtualPath; // e.g "/MyApp/Application_WebReferences/Foo/Bar" string currentWebRefDirVirtualPath = _vdir.VirtualPath; Debug.Assert(StringUtil.StringStartsWithIgnoreCase( currentWebRefDirVirtualPath, rootWebRefDirVirtualPath.VirtualPathString)); string ns; if (rootWebRefDirVirtualPath.VirtualPathString.Length == currentWebRefDirVirtualPath.Length) { // If it's the root WebReferences dir, use the empty namespace ns = String.Empty; } else { // e.g. "Foo/Bar" Debug.Assert(rootWebRefDirVirtualPath.HasTrailingSlash); currentWebRefDirVirtualPath = UrlPath.RemoveSlashFromPathIfNeeded(currentWebRefDirVirtualPath); currentWebRefDirVirtualPath = currentWebRefDirVirtualPath.Substring( rootWebRefDirVirtualPath.VirtualPathString.Length); // Split it into chunks separated by '/' string[] chunks = currentWebRefDirVirtualPath.Split('/'); // Turn all the relevant chunks into valid namespace chunks for (int i = 0; i < chunks.Length; i++) { chunks[i] = Util.MakeValidTypeNameFromString(chunks[i]); } // Put the relevant chunks back together to form the namespace ns = String.Join(".", chunks); } #if !FEATURE_PAL // FEATURE_PAL does not support System.Web.Services CodeNamespace codeNamespace = new CodeNamespace(ns); // for each discomap file, read all references and add them to the WebReferenceCollection WebReferenceCollection webs = new WebReferenceCollection(); bool hasDiscomap = false; // Go through all the discomap in the directory foreach (VirtualFile child in _vdir.Files) { string extension = UrlPath.GetExtension(child.VirtualPath); extension = extension.ToLower(CultureInfo.InvariantCulture); if (extension == ".discomap") { // NOTE: the WebReferences code requires physical path, so this feature // cannot work with a non-file based VirtualPathProvider string physicalPath = HostingEnvironment.MapPath(child.VirtualPath); DiscoveryClientProtocol client = new DiscoveryClientProtocol(); client.AllowAutoRedirect = true; client.Credentials = CredentialCache.DefaultCredentials; client.ReadAll(physicalPath); WebReference webRefTemp = new WebReference(client.Documents, codeNamespace); // string fileName = System.IO.Path.ChangeExtension(UrlPath.GetFileName(child.VirtualPath), null); string appSetttingUrlKey = ns + "." + fileName; WebReference web = new WebReference(client.Documents, codeNamespace, webRefTemp.ProtocolName, appSetttingUrlKey, null); webs.Add(web); hasDiscomap = true; } } // If we didn't find any discomap files, we have nothing to generate if (!hasDiscomap) { return; } CodeCompileUnit codeCompileUnit = new CodeCompileUnit(); codeCompileUnit.Namespaces.Add(codeNamespace); //public static StringCollection GenerateWebReferences(WebReferenceCollection webReferences, CodeDomProvider codeProvider, CodeCompileUnit codeCompileUnit, WebReferenceOptions options) { WebReferenceOptions options = new WebReferenceOptions(); options.CodeGenerationOptions = CodeGenerationOptions.GenerateProperties | CodeGenerationOptions.GenerateNewAsync | CodeGenerationOptions.GenerateOldAsync; options.Style = ServiceDescriptionImportStyle.Client; options.Verbose = true; StringCollection shareWarnings = ServiceDescriptionImporter.GenerateWebReferences(webs, assemblyBuilder.CodeDomProvider, codeCompileUnit, options); // Add the CodeCompileUnit to the compilation assemblyBuilder.AddCodeCompileUnit(this, codeCompileUnit); #else // !FEATURE_PAL return; #endif // !FEATURE_PAL }
internal IHttpModule Create() { return((IHttpModule)HttpRuntime.CreateNonPublicInstance(this._type)); }
internal object Create(string type) { return(HttpRuntime.CreateNonPublicInstance(this.GetHandlerType(type))); }
internal SRef(object target) { this._sizedRef = HttpRuntime.CreateNonPublicInstance(s_type, new object[] { target }); }
WebEventProvider GetProviderInstance(string providerName) { WebEventProvider provider; object o; o = _instances[providerName]; if (o == null) { return(null); } ProviderSettings providerSettings = o as ProviderSettings; if (providerSettings != null) { // If what we got is still a ProviderSettings, it means we haven't created an instance // of it yet. Type type; string typeName = providerSettings.Type; type = BuildManager.GetType(typeName, false); Debug.Assert(type != null, "type != null"); if (typeof(IInternalWebEventProvider).IsAssignableFrom(type)) { provider = (WebEventProvider)HttpRuntime.CreateNonPublicInstance(type); } else { provider = (WebEventProvider)HttpRuntime.CreatePublicInstance(type); } using (new ProcessImpersonationContext()) { try { provider.Initialize(providerSettings.Name, providerSettings.Parameters); } catch (ConfigurationErrorsException) { throw; } catch (ConfigurationException e) { throw new ConfigurationErrorsException(e.Message, providerSettings.ElementInformation.Properties["type"].Source, providerSettings.ElementInformation.Properties["type"].LineNumber); } catch { throw; } } Debug.Trace("ProviderInstances", "Create a provider instance: " + "name=" + providerSettings.Name + ";type=" + typeName); _instances[providerName] = provider; } else { provider = o as WebEventProvider; Debug.Assert(provider != null, "provider != null"); } return(provider); }
internal /*public*/ IHttpModule Create() { return (IHttpModule)HttpRuntime.CreateNonPublicInstance(_type); }
public override void GenerateCode(AssemblyBuilder assemblyBuilder) { string str2; if (!s_triedToGetWebRefType) { s_indigoWebRefProviderType = BuildManager.GetType("System.Web.Compilation.WCFBuildProvider", false); s_triedToGetWebRefType = true; } if (s_indigoWebRefProviderType != null) { BuildProvider provider = (BuildProvider)HttpRuntime.CreateNonPublicInstance(s_indigoWebRefProviderType); provider.SetVirtualPath(base.VirtualPathObject); provider.GenerateCode(assemblyBuilder); } VirtualPath webRefDirectoryVirtualPath = HttpRuntime.WebRefDirectoryVirtualPath; string virtualPath = this._vdir.VirtualPath; if (webRefDirectoryVirtualPath.VirtualPathString.Length == virtualPath.Length) { str2 = string.Empty; } else { string[] strArray = UrlPath.RemoveSlashFromPathIfNeeded(virtualPath).Substring(webRefDirectoryVirtualPath.VirtualPathString.Length).Split(new char[] { '/' }); for (int i = 0; i < strArray.Length; i++) { strArray[i] = Util.MakeValidTypeNameFromString(strArray[i]); } str2 = string.Join(".", strArray); } CodeNamespace proxyCode = new CodeNamespace(str2); WebReferenceCollection webReferences = new WebReferenceCollection(); bool flag = false; foreach (VirtualFile file in this._vdir.Files) { if (UrlPath.GetExtension(file.VirtualPath).ToLower(CultureInfo.InvariantCulture) == ".discomap") { string topLevelFilename = HostingEnvironment.MapPath(file.VirtualPath); DiscoveryClientProtocol protocol = new DiscoveryClientProtocol { AllowAutoRedirect = true, Credentials = CredentialCache.DefaultCredentials }; protocol.ReadAll(topLevelFilename); WebReference reference = new WebReference(protocol.Documents, proxyCode); string str5 = Path.ChangeExtension(UrlPath.GetFileName(file.VirtualPath), null); string appSettingUrlKey = str2 + "." + str5; WebReference webReference = new WebReference(protocol.Documents, proxyCode, reference.ProtocolName, appSettingUrlKey, null); webReferences.Add(webReference); flag = true; } } if (flag) { CodeCompileUnit codeCompileUnit = new CodeCompileUnit(); codeCompileUnit.Namespaces.Add(proxyCode); WebReferenceOptions options = new WebReferenceOptions { CodeGenerationOptions = CodeGenerationOptions.GenerateOldAsync | CodeGenerationOptions.GenerateNewAsync | CodeGenerationOptions.GenerateProperties, Style = ServiceDescriptionImportStyle.Client, Verbose = true }; ServiceDescriptionImporter.GenerateWebReferences(webReferences, assemblyBuilder.CodeDomProvider, codeCompileUnit, options); assemblyBuilder.AddCodeCompileUnit(this, codeCompileUnit); } }
private static IWebPropertyAccessor GetPropertyAccessor(Type type, string propertyName) { if (s_accessorGenerator == null || s_accessorCache == null) { lock (s_lockObject) { if (s_accessorGenerator == null || s_accessorCache == null) { s_accessorGenerator = new FastPropertyAccessor(); s_accessorCache = new Hashtable(); } } } // First, check if we have it cached // Get a hash key based on the Type and the property name int cacheKey = HashCodeCombiner.CombineHashCodes( type.GetHashCode(), propertyName.GetHashCode()); IWebPropertyAccessor accessor = (IWebPropertyAccessor)s_accessorCache[cacheKey]; // It was cached, so just return it if (accessor != null) { return(accessor); } FieldInfo fieldInfo = null; PropertyInfo propInfo = null; Type declaringType; GetPropertyInfo(type, propertyName, out propInfo, out fieldInfo, out declaringType); // If the Type where the property/field is declared is not the same as the current // Type, check if the declaring Type already has a cached accessor. This limits // the number of different accessors we need to create. e.g. Every control has // an ID property, but we'll end up only create one accessor for all of them. int declaringTypeCacheKey = 0; if (declaringType != type) { // Get a hash key based on the declaring Type and the property name declaringTypeCacheKey = HashCodeCombiner.CombineHashCodes( declaringType.GetHashCode(), propertyName.GetHashCode()); accessor = (IWebPropertyAccessor)s_accessorCache[declaringTypeCacheKey]; // We have a cached accessor for the declaring type, so use it if (accessor != null) { // Cache the declaring type's accessor as ourselves lock (s_accessorCache.SyncRoot) { s_accessorCache[cacheKey] = accessor; } return(accessor); } } if (accessor == null) { Type propertyAccessorType; lock (s_accessorGenerator) { propertyAccessorType = s_accessorGenerator.GetPropertyAccessorTypeWithAssert( declaringType, propertyName, propInfo, fieldInfo); } // Create the type. This is the only place where Activator.CreateInstance is used, // reducing the calls to it from 1 per instance to 1 per type. accessor = (IWebPropertyAccessor)HttpRuntime.CreateNonPublicInstance(propertyAccessorType); } // Cache the accessor lock (s_accessorCache.SyncRoot) { s_accessorCache[cacheKey] = accessor; if (declaringTypeCacheKey != 0) { s_accessorCache[declaringTypeCacheKey] = accessor; } } return(accessor); }