Document IDocumentFactory.CreateDocument(DocumentProjectItem projectItem, bool readOnly, DocumentMode mode, DocumentViewType initialView, out DocumentWindow documentWindow, out DesignerHost designerHost)
 {
     if (projectItem == null)
     {
         throw new ArgumentNullException("projectItem");
     }
     Document document = new AshxDocument(projectItem);
     designerHost = new DesignerHost(document);
     document.Load(readOnly);
     documentWindow = new AshxDocumentWindow(designerHost, document);
     return document;
 }
 Document IDocumentFactory.CreateDocument(DocumentProjectItem projectItem, bool readOnly, DocumentMode mode, DocumentViewType initialView, out DocumentWindow documentWindow, out DesignerHost designerHost)
 {
     if (projectItem == null)
     {
         throw new ArgumentNullException("projectItem");
     }
     TableDocument document = new TableDocument(projectItem);
     designerHost = new DesignerHost(document);
     document.Load(readOnly);
     if (initialView == DocumentViewType.Default)
     {
         initialView = (document.Table.GetRowCount() == 0) ? DocumentViewType.Design : DocumentViewType.Source;
     }
     documentWindow = new TableDocumentWindow(designerHost, document, initialView);
     return document;
 }
 Document IDocumentFactory.CreateDocument(DocumentProjectItem projectItem, bool readOnly, DocumentMode mode, DocumentViewType initialView, out DocumentWindow documentWindow, out DesignerHost designerHost)
 {
     if (projectItem == null)
     {
         throw new ArgumentNullException("projectItem");
     }
     if (initialView == DocumentViewType.Default)
     {
         initialView = WebPackage.Instance.WebDefaultView;
         if (initialView == DocumentViewType.Source)
         {
             initialView = DocumentViewType.Composite;
         }
     }
     documentWindow = null;
     AscxDocument document = new AscxDocument(projectItem);
     designerHost = new WebFormsDesignerHost(document);
     document.Load(readOnly);
     Page page = null;
     UserControl child = null;
     if (document.DocumentDirective.Inherits.ToLower().IndexOf("mobile") < 0)
     {
         page = new Page();
         child = new UserControl();
         child.ID = "Page";
         documentWindow = new AscxDocumentWindow(designerHost, document, initialView);
         page.Site = new AscxPageSite(designerHost, page);
         page.DesignerInitialize();
         page.Controls.Add(child);
     }
     else
     {
         if (!_mobileAssemblyLoadFailed)
         {
             if (_mobileAssembly == null)
             {
                 _mobileAssembly = Assembly.LoadWithPartialName(_mobileAssemblyName);
             }
             if (_mobileAssembly != null)
             {
                 document.Dispose();
                 document = new AscxDocument(projectItem);
                 Type type = _mobileAssembly.GetType("System.Web.UI.MobileControls.MobilePage");
                 Type type2 = _mobileAssembly.GetType("System.Web.UI.MobileControls.MobileUserControl");
                 Type type3 = _mobileAssembly.GetType("System.Web.UI.MobileControls.Form");
                 page = (Page) Activator.CreateInstance(type);
                 child = (UserControl) Activator.CreateInstance(type2);
                 Control control2 = (Control) Activator.CreateInstance(type3);
                 Type type4 = Type.GetType("Microsoft.Matrix.Packages.Web.Mobile.MobileDesignerHost, Microsoft.Matrix.Packages.Web.Mobile");
                 designerHost = (DesignerHost) Activator.CreateInstance(type4, new object[] { document });
                 document.Load(readOnly);
                 Type type5 = Type.GetType("Microsoft.Matrix.Packages.Web.Mobile.MobileWebFormsDocumentWindow, Microsoft.Matrix.Packages.Web.Mobile");
                 documentWindow = (DocumentWindow) Activator.CreateInstance(type5, new object[] { designerHost, document, initialView });
                 page.Site = new AscxPageSite(designerHost, page);
                 page.DesignerInitialize();
                 page.Controls.Add(control2);
                 control2.Controls.Add(child);
             }
             else
             {
                 _mobileAssemblyLoadFailed = true;
             }
         }
         if (_mobileAssemblyLoadFailed)
         {
             document.Dispose();
             Document document2 = new TextDocument(projectItem);
             designerHost = new DesignerHost(document2);
             ((IMxUIService) designerHost.GetService(typeof(IMxUIService))).ReportError("Microsoft Mobile Internet Toolkit is required for design-time editing of mobile user controls.\r\nPlease visit 'http://www.asp.net/mobile/default.aspx' for more information.\r\nThe user control will be opened in the text editor instead.", "Mobile User Controls are not enabled.", true);
             document2.Load(readOnly);
             documentWindow = new TextDocumentWindow(designerHost, document2);
             return document2;
         }
     }
     IDesignerHost host = designerHost;
     host.Container.Add(child, "UserControl");
     child.DesignerInitialize();
     return document;
 }
 Document IDocumentFactory.CreateDocument(DocumentProjectItem projectItem, bool readOnly, DocumentMode mode, DocumentViewType initialView, out DocumentWindow documentWindow, out DesignerHost designerHost)
 {
     throw new NotSupportedException("Invalid use of CodeDocumentFactory. This class only exists to represent a arbitrary code file.");
 }
 Document IDocumentFactory.CreateDocument(DocumentProjectItem projectItem, bool readOnly, DocumentMode mode, DocumentViewType initialView, out DocumentWindow documentWindow, out DesignerHost designerHost)
 {
     if (projectItem == null)
     {
         throw new ArgumentNullException("projectItem");
     }
     Document document = new HtmlDocument(projectItem);
     designerHost = new DesignerHost(document);
     document.Load(readOnly);
     if (initialView == DocumentViewType.Default)
     {
         initialView = WebPackage.Instance.WebDefaultView;
     }
     documentWindow = new HtmlDocumentWindow(designerHost, document, initialView);
     return document;
 }