private void RegisterMobileControlTagPrefix()
        {
            // Try to load the Mobile assembly if not already done
            if (!_fTriedToLoadMobileAssembly)
            {
                _mobileAssembly = LoadAssembly(AssemblyRef.SystemWebMobile, false /*throwOnFail*/);

                if (_mobileAssembly != null)
                {
                    _mobilePageType = _mobileAssembly.GetType("System.Web.UI.MobileControls.MobilePage");
                    Debug.Assert(_mobilePageType != null);
                    _mobileUserControlType = _mobileAssembly.GetType("System.Web.UI.MobileControls.MobileUserControl");
                    Debug.Assert(_mobileUserControlType != null);
                }

                _fTriedToLoadMobileAssembly = true;
            }

            if (_mobileAssembly == null)
            {
                return;
            }

            RootBuilder.RegisterTagPrefix("Mobile", "System.Web.UI.MobileControls", _mobileAssembly);
        }
示例#2
0
		public void Ctor1_Deny_Unrestricted ()
		{
			RootBuilder rb = new RootBuilder (new PageParser ());
			try {
				rb.GetChildControlType (null, null);
			}
			catch (ArgumentNullException) {
				// mono and ms 1.x
			}
			catch (NullReferenceException) {
				// ms 2.0 - more likely parameters don't change this result
			}
			Assert.IsNotNull (rb.BuiltObjects, "BuiltObjects");
		}
示例#3
0
        void AddChild(object child)
        {
            if (children == null)
            {
                children = new ArrayList();
            }

            children.Add(child);
            ControlBuilder cb = child as ControlBuilder;

            if (cb != null && cb is TemplateBuilder)
            {
                if (templateChildren == null)
                {
                    templateChildren = new ArrayList();
                }
                templateChildren.Add(child);
            }

            if (parser == null)
            {
                return;
            }

            string tag = cb != null ? cb.TagName : null;

            if (String.IsNullOrEmpty(tag))
            {
                return;
            }

            RootBuilder         rb      = Root;
            AspComponentFoundry foundry = rb != null ? rb.Foundry : null;

            if (foundry == null)
            {
                return;
            }
            AspComponent component = foundry.GetComponent(tag);

            if (component == null || !component.FromConfig)
            {
                return;
            }

            parser.AddImport(component.Namespace);
            parser.AddDependency(component.Source);
        }
示例#4
0
        private void EnsureMasterPageFileFromConfigApplied()
        {
            // Skip if it's already applied.
            if (_mainDirectiveMasterPageSet)
            {
                return;
            }

            // If the masterPageFile is defined in the config
            if (_configMasterPageFile != null)
            {
                // Readjust the lineNumber to the location of maindirective
                int prevLineNumber = _lineNumber;
                _lineNumber = _mainDirectiveLineNumber;
                try {
                    if (_configMasterPageFile.Length > 0)
                    {
                        Type type = GetReferencedType(_configMasterPageFile);

                        // Make sure it has the correct base type
                        if (!typeof(MasterPage).IsAssignableFrom(type))
                        {
                            ProcessError(SR.GetString(SR.Invalid_master_base, _configMasterPageFile));
                        }
                    }

                    if (((FileLevelPageControlBuilder)RootBuilder).ContentBuilderEntries != null)
                    {
                        RootBuilder.SetControlType(BaseType);
                        RootBuilder.PreprocessAttribute(String.Empty /*filter*/, "MasterPageFile", _configMasterPageFile, true /*mainDirectiveMode*/);
                    }
                }
                finally {
                    _lineNumber = prevLineNumber;
                }
            }

            _mainDirectiveMasterPageSet = true;
        }
        internal override void ProcessUnknownMainDirectiveAttribute(string filter, string attribName, string value)
        {
            // Don't allow the id to be specified on the directive, even though it is
            // a public member of the control class (VSWhidbey 85384)
            if (attribName == "id")
            {
                base.ProcessUnknownMainDirectiveAttribute(filter, attribName, value);
                return;
            }

            // Process unknown attributes as regular control attribute, hence allowing
            // arbitrary properties of the base class to be set.
            // But turn off IAttributeAccessor support, otherwise any bad string on a
            // user control's directive won't be caught.

            try {
                RootBuilder.PreprocessAttribute(filter, attribName, value, true /*mainDirectiveMode*/);
            }
            catch (Exception e) {
                ProcessError(SR.GetString(SR.Attrib_parse_error, attribName, e.Message));
            }
        }
示例#6
0
    private void EnsureRootBuilderCreated() {

        // Create it on demand
        if (_rootBuilder != null)
            return;

        if (BaseType == DefaultBaseType) {
            // If the base type is the default, no need to look up the attribute
            _rootBuilder = CreateDefaultFileLevelBuilder();
        }
        else {
            // Look for a custom attribute
            Type fileLevelBuilderType = GetFileLevelControlBuilderType();

            if (fileLevelBuilderType == null) {
                // No custom type: use the default
                _rootBuilder = CreateDefaultFileLevelBuilder();
            }
            else {
                // Create the custom file level builder
                _rootBuilder = (RootBuilder) HttpRuntime.CreateNonPublicInstance(
                    fileLevelBuilderType);
            }
        }

        _rootBuilder.Line = 1;
        _rootBuilder.Init(this, null, null, null, null, null);
        _rootBuilder.SetTypeMapper(TypeMapper);

        _rootBuilder.VirtualPath = CurrentVirtualPath;

        // Create and seed the stack of builders.
        _builderStack = new Stack();
        _builderStack.Push(new BuilderStackEntry(RootBuilder, null, null, 0, null, 0));
    }
示例#7
0
		void CreateRootBuilder (Stream inputStream, string filename)
		{
			if (rootBuilder != null)
				return;
			
			Type rootBuilderType = GetRootBuilderType (inputStream, filename);
			rootBuilder = Activator.CreateInstance (rootBuilderType) as RootBuilder;
			if (rootBuilder == null)
				throw new HttpException ("Cannot create an instance of file-level control builder.");
			rootBuilder.Init (tparser, null, null, null, null, null);
			if (componentFoundry != null)
				rootBuilder.Foundry = componentFoundry;
			
			stack.Push (rootBuilder, null);
			tparser.RootBuilder = rootBuilder;
		}
 internal BuildResultNoCompileTemplateControl(Type baseType, TemplateParser parser)
 {
     this._baseType = baseType;
     this._rootBuilder = parser.RootBuilder;
     this._rootBuilder.PrepareNoCompilePageSupport();
 }
        internal override void ProcessDirective(string directiveName, IDictionary directive)
        {
            if (string.Compare(directiveName, "outputcache", true, CultureInfo.InvariantCulture) == 0)
            {
                // Make sure the outputcache directive was not already specified
                if (_outputCacheDirective != null)
                {
                    throw new HttpException(
                              HttpRuntime.FormatResourceString(SR.Only_one_directive_allowed, directiveName));
                }

                ProcessOutputCacheDirective(directiveName, directive);

                _outputCacheDirective = directive;
            }
            else if (string.Compare(directiveName, "register", true, CultureInfo.InvariantCulture) == 0)
            {
                // Register directive

                // Optionally, allow an assembly, which is used by the designer
                string   assemblyName = Util.GetAndRemoveNonEmptyAttribute(directive, "assembly");
                Assembly assembly     = null;
                if (assemblyName != null)
                {
                    assembly = AddAssemblyDependency(assemblyName);

                    if (assembly == null)
                    {
                        // It should never be null at runtime, since it throws
                        Debug.Assert(FInDesigner, "FInDesigner");

                        // Just ignore the directive (ASURT 100454)
                        return;
                    }
                }

                // Get the tagprefix, which is required
                string prefix = Util.GetAndRemoveNonEmptyIdentifierAttribute(directive, "tagprefix");
                if (prefix == null)
                {
                    throw new HttpException(HttpRuntime.FormatResourceString(
                                                SR.Missing_attr, "tagprefix"));
                }

                string tagName = Util.GetAndRemoveNonEmptyIdentifierAttribute(directive, "tagname");
                string src     = Util.GetAndRemoveNonEmptyAttribute(directive, "src");
                string ns      = Util.GetAndRemoveNonEmptyNoSpaceAttribute(directive, "namespace");

                if (tagName != null)
                {
                    // If tagname was specified, 'src' is required
                    if (src == null)
                    {
                        throw new HttpException(HttpRuntime.FormatResourceString(SR.Missing_attr, "src"));
                    }

                    EnsureNullAttribute("namespace", ns);
                }
                else
                {
                    // If tagname was NOT specified, 'namespace' is required
                    if (ns == null)
                    {
                        throw new HttpException(HttpRuntime.FormatResourceString(SR.Missing_attr, "namespace"));
                    }

                    // Assembly is also required (ASURT 61326)
                    if (assembly == null)
                    {
                        throw new HttpException(HttpRuntime.FormatResourceString(SR.Missing_attr, "assembly"));
                    }

                    EnsureNullAttribute("src", src);
                }

                // If there are some attributes left, fail
                Util.CheckUnknownDirectiveAttributes(directiveName, directive);

                // Is it a single tag to .aspx file mapping?
                if (tagName != null)
                {
                    // Compile it into a Type
                    Type type = GetUserControlType(src);

                    // Register the new tag, including its prefix
                    RootBuilder.RegisterTag(prefix + ":" + tagName, type);

                    return;
                }

                AddImportEntry(ns);

                // If there is a prefix, register the namespace to allow tags with
                // that prefix to be created.
                RootBuilder.RegisterTagPrefix(prefix, ns, assembly);
            }
            else if (string.Compare(directiveName, "reference", true, CultureInfo.InvariantCulture) == 0)
            {
                string page    = Util.GetAndRemoveNonEmptyNoSpaceAttribute(directive, "page");
                string control = Util.GetAndRemoveNonEmptyNoSpaceAttribute(directive, "control");

                // If neither or both are specified, fail
                if ((page == null) == (control == null))
                {
                    throw new HttpException(HttpRuntime.FormatResourceString(SR.Invalid_reference_directive));
                }

                if (page != null)
                {
                    GetReferencedPageType(page);
                }

                if (control != null)
                {
                    GetUserControlType(control);
                }

                // If there are some attributes left, fail
                Util.CheckUnknownDirectiveAttributes(directiveName, directive);
            }
            else
            {
                base.ProcessDirective(directiveName, directive);
            }
        }
示例#10
0
    internal BuildResultNoCompileTemplateControl(Type baseType, TemplateParser parser) {
        _baseType = baseType;
        _rootBuilder = parser.RootBuilder;

        // Cleanup anything that's no longer needed in the ControlBuilder
        _rootBuilder.PrepareNoCompilePageSupport();
    }
示例#11
0
		public void Ctor0_Deny_Unrestricted ()
		{
			RootBuilder rb = new RootBuilder ();
			Assert.IsNotNull (rb.BuiltObjects, "BuiltObjects");
		}
		public AspGenerator (TemplateParser tparser)
		{
			this.tparser = tparser;
			text = new StringBuilder ();
			stack = new BuilderLocationStack ();
			rootBuilder = new RootBuilder (tparser);
			stack.Push (rootBuilder, null);
			tparser.RootBuilder = rootBuilder;
			pstack = new ParserStack ();
		}