/// <include file='doc\WebControlPersister.uex' path='docs/doc[@for="ControlPersister.GetDeclarativeType"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Gets the delarative type for the
        ///       specified type.
        ///    </para>
        /// </devdoc>
        private static string GetDeclarativeType(Type type, IDesignerHost host)
        {
            Debug.Assert(host != null, "Need an IDesignerHost to create declarative type names");
            string declarativeType = null;

            if (host != null)
            {
                IWebFormReferenceManager refMgr =
                    (IWebFormReferenceManager)host.GetService(typeof(IWebFormReferenceManager));
                Debug.Assert(refMgr != null, "Did not get back IWebFormReferenceManager service from host.");

                if (refMgr != null)
                {
                    string tagPrefix = refMgr.GetTagPrefix(type);
                    if ((tagPrefix != null) && (tagPrefix.Length != 0))
                    {
                        declarativeType = tagPrefix + ":" + type.Name;
                    }
                }
            }

            if (declarativeType == null)
            {
                declarativeType = type.FullName;
            }

            return(declarativeType);
        }
示例#2
0
 void Interop.IElementNamespaceFactoryCallback.Resolve(string namespaceName, string tagName, string attributes, Interop.IElementNamespace pNamespace)
 {
     namespaceName = namespaceName.ToLower();
     if (this._registeredNamespaces.Contains(namespaceName))
     {
         if (this._referenceManager == null)
         {
             IServiceProvider serviceProvider = this._editor.ServiceProvider;
             this._referenceManager = (IWebFormReferenceManager) serviceProvider.GetService(typeof(IWebFormReferenceManager));
         }
         if (this._referenceManager != null)
         {
             Type objectType = this._referenceManager.GetObjectType(namespaceName, tagName);
             if (objectType != null)
             {
                 int lFlags = 0;
                 PersistChildrenAttribute attribute = (PersistChildrenAttribute) TypeDescriptor.GetAttributes(objectType)[typeof(PersistChildrenAttribute)];
                 if (!attribute.Persist || (objectType == typeof(UserControl)))
                 {
                     lFlags |= 2;
                 }
                 pNamespace.AddTag(tagName, lFlags);
             }
         }
     }
 }
示例#3
0
 void IDisposable.Dispose()
 {
     this._namespaceTable = null;
     this._registeredNamespaces = null;
     this._referenceManager = null;
     this._editor = null;
 }
示例#4
0
		public DesignTimeParser (DesignerHost host, Document document)
		{
			this.host = host;
			this.document = document;
			refMan = host.GetService(typeof(IWebFormReferenceManager)) as IWebFormReferenceManager;
			if (refMan == null)
				throw new Exception ("Could not get IWebFormReferenceManager from host");
		}
示例#5
0
 public RootParsingObject(IDesignerHost host)
     : base("", "", null)
 {
     this.host = host;
     refMan = host.GetService(typeof(IWebFormReferenceManager)) as IWebFormReferenceManager;
     if (refMan == null)
         throw new Exception ("Could not get IWebFormReferenceManager from host");
 }
示例#6
0
 public RootParsingObject(IDesignerHost host)
     : base("", "", null)
 {
     this.host = host;
     refMan    = host.GetService(typeof(IWebFormReferenceManager)) as IWebFormReferenceManager;
     if (refMan == null)
     {
         throw new Exception("Could not get IWebFormReferenceManager from host");
     }
 }
示例#7
0
 public DesignTimeParser(DesignerHost host, Document document)
 {
     this.host     = host;
     this.document = document;
     refMan        = host.GetService(typeof(IWebFormReferenceManager)) as IWebFormReferenceManager;
     if (refMan == null)
     {
         throw new Exception("Could not get IWebFormReferenceManager from host");
     }
 }
        private static string GetDirectives(IDesignerHost designerHost)
        {
            Debug.Assert(designerHost != null);

            string directives = String.Empty;

            IWebFormReferenceManager refMgr =
                (IWebFormReferenceManager)designerHost.GetService(typeof(IWebFormReferenceManager));

            Debug.Assert(refMgr != null, "Expected to be able to get IWebFormReferenceManager");

            if (refMgr != null)
            {
                directives = refMgr.GetRegisterDirectives();
            }

            return(directives);
        }
示例#9
0
        /// <summary>
        ///    <para>
        ///       Gets the delarative type for the
        ///       specified type.
        ///    </para>
        /// </summary>
        /// <param name='type'>
        ///    The type of the declarator.
        /// </param>
        /// <param name='host'>
        ///    The services interface exposed by the webforms designer.
        /// </param>
        private static string GetDeclarativeType(Type type, IDesignerHost host)
        {
            Debug.Assert(host != null, "Need an IDesignerHost to create declarative type names");
            string declarativeType = null;

            if (host != null)
            {
                IWebFormReferenceManager refMgr =
                    (IWebFormReferenceManager)host.GetService(typeof(IWebFormReferenceManager));
                Debug.Assert(refMgr != null, "Did not get back IWebFormReferenceManager service from host.");

                if (refMgr != null)
                {
                    string tagPrefix = refMgr.GetTagPrefix(type);
                    if ((tagPrefix != null) && (tagPrefix.Length != 0))
                    {
                        declarativeType = tagPrefix + ":" + type.Name;
                    }
                }
            }

            if (declarativeType == null)
            {
/* Begin AUI 7201  */
/* Original declarativeType = type.FullName; */
                if (type == typeof(System.Web.UI.MobileControls.Style))
                {
                    declarativeType = type.Name;
                }
                else
                {
                    declarativeType = type.FullName;
                }
/* End AUI 7201 */
            }

            return(declarativeType);
        }
示例#10
0
        private static void PersistObject(HtmlTextWriter writer, object control, IDesignerHost host, bool runAtServer)
        {
            //look up tag prefix from host
            IWebFormReferenceManager refMan = host.GetService(typeof(IWebFormReferenceManager)) as IWebFormReferenceManager;

            if (refMan == null)
            {
                throw new Exception("Could not obtain IWebFormReferenceManager service");
            }
            string prefix = refMan.GetTagPrefix(control.GetType());

            //write tag to HtmlTextWriter
            writer.WriteBeginTag(prefix + ":" + control.GetType().Name);

            //go through all the properties and add attributes if necessary
            PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(control);

            foreach (PropertyDescriptor prop in properties)
            {
                ProcessAttribute(prop, control, writer, string.Empty);
            }

            if (runAtServer)
            {
                writer.WriteAttribute("runat", "server");
            }

            //do the same for events
            IComponent comp = control as IComponent;

            if (comp != null && comp.Site != null)
            {
                IEventBindingService evtBind = (IEventBindingService)comp.Site.GetService(typeof(IEventBindingService));
                if (evtBind != null)
                {
                    foreach (EventDescriptor e in TypeDescriptor.GetEvents(comp))
                    {
                        ProcessEvent(e, comp, writer, evtBind);
                    }
                }
            }


            //ControlDesigner designer = (ControlDesigner) host.GetDesigner(control);
            //TODO: we don't yet support designer.GetPersistInnerHtml() 'cause we don't have the designers...
            if (HasInnerProperties(control))
            {
                writer.Write(HtmlTextWriter.TagRightChar);
                writer.Indent++;
                PersistInnerProperties(writer, control, host);
                writer.Indent--;
                writer.WriteEndTag(prefix + ":" + control.GetType().Name);
            }
            else
            {
                writer.Write(HtmlTextWriter.SelfClosingTagEnd);
            }

            writer.WriteLine();
            writer.Flush();
        }
示例#11
0
        /// <summary>
        ///    dynamically transform DeviceSpecific element to a server control,
        ///    called from OnBehaviorAttached
        /// </summary>
        private void PrefixDeviceSpecificTags()
        {
            IHTMLElement htmlElement = (IHTMLElement)DesignTimeElementInternal;

            Debug.Assert(htmlElement != null,
                         "Invalid HTML element in FormDesigner.OnBehaviorAttached");

            IWebFormReferenceManager refMgr =
                (IWebFormReferenceManager)GetService(typeof(IWebFormReferenceManager));

            Debug.Assert(refMgr != null, "Did not get back IWebFormReferenceManager service.");

            String tagPrefix = refMgr.GetTagPrefix(typeof(DeviceSpecific));

            Debug.Assert(tagPrefix != null && tagPrefix.Length > 0, "TagPrefix is invalid");

            IHTMLElementCollection allChildren = (IHTMLElementCollection)htmlElement.GetChildren();

            if (null != allChildren)
            {
                bool   substitutions     = false;
                int    nestingLevel      = 0;
                String modifiedInnerHTML = String.Empty;
                for (Int32 i = 0; i < allChildren.GetLength(); i++)
                {
                    IHTMLElement htmlChild = (IHTMLElement)allChildren.Item(i, 0);
                    Debug.Assert(null != htmlChild, "htmlChild is null");
                    String childContent      = htmlChild.GetOuterHTML();
                    String childUpperContent = childContent.ToUpper(CultureInfo.InvariantCulture);
                    if (childContent.StartsWith("<", StringComparison.Ordinal) &&
                        !(childContent.StartsWith("</", StringComparison.Ordinal) || (childContent.EndsWith("/>", StringComparison.Ordinal))))
                    {
                        if (!childUpperContent.StartsWith("<" + tagPrefix.ToUpper(CultureInfo.InvariantCulture) + ":", StringComparison.Ordinal))
                        {
                            nestingLevel++;
                        }
                    }
                    else if (childContent.StartsWith("</", StringComparison.Ordinal))
                    {
                        nestingLevel--;
                    }
                    if (1 == nestingLevel &&
                        childUpperContent.StartsWith("<DEVICESPECIFIC", StringComparison.Ordinal) &&
                        childUpperContent.EndsWith(">", StringComparison.Ordinal))
                    {
                        Debug.Assert(substitutions == false, "substitutions is true");
                        modifiedInnerHTML += "<" + tagPrefix + ":DeviceSpecific runat=\"server\">\r\n";
                        substitutions      = true;
                    }
                    else if (1 == nestingLevel &&
                             childUpperContent.StartsWith("<DEVICESPECIFIC", StringComparison.Ordinal) &&
                             childUpperContent.EndsWith("/>", StringComparison.Ordinal))
                    {
                        modifiedInnerHTML += "<" + tagPrefix + ":DeviceSpecific runat=\"server\"></" + tagPrefix + ":DeviceSpecific>\r\n";
                        substitutions      = true;
                    }
                    else if (0 == nestingLevel && 0 == String.Compare(childUpperContent, "</DEVICESPECIFIC>", StringComparison.Ordinal))
                    {
                        Debug.Assert(substitutions == true, "substitutions is false");
                        modifiedInnerHTML += "</" + tagPrefix + ":DeviceSpecific>\r\n";
                    }
                    else
                    {
                        modifiedInnerHTML += childContent + "\r\n";
                    }
                }
                if (substitutions)
                {
                    _shouldDirtyPage = true;
                    htmlElement.SetInnerHTML(modifiedInnerHTML);
                }
            }
        }