Example #1
0
 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;
 }
 private string GenerateDesignTimeHtml(DocumentProjectItem projectItem)
 {
     string str = null;
     WebFormsDesignerHost designerHost = null;
     try
     {
         AscxDocument document = new AscxDocument(projectItem);
         designerHost = new WebFormsDesignerHost(document);
         document.Load(true);
         str = string.Empty;
         string html = document.Html;
         string directives = document.RegisterDirectives.ToString();
         string controlText = "<asp:PlaceHolder runat=\"server\">" + html + "</asp:PlaceHolder>";
         Control control = ControlParser.ParseControl(designerHost, controlText, directives);
         if ((control == null) || !control.HasControls())
         {
             return str;
         }
         IDesignerHost host2 = designerHost;
         IContainer container = host2.Container;
         StringBuilder builder = new StringBuilder(0x400);
         bool flag = false;
         foreach (Control control2 in control.Controls)
         {
             if (!(control2 is LiteralControl))
             {
                 if (!flag)
                 {
                     flag = true;
                     Page component = new Page();
                     component.ID = "Page";
                     container.Add(component, "Page");
                     component.DesignerInitialize();
                 }
                 container.Add(control2);
             }
         }
         foreach (Control control4 in control.Controls)
         {
             LiteralControl control5 = control4 as LiteralControl;
             if (control5 != null)
             {
                 builder.Append(control5.Text);
             }
             else
             {
                 ControlDesigner designer = (ControlDesigner) host2.GetDesigner(control4);
                 try
                 {
                     string designTimeHtml = designer.GetDesignTimeHtml();
                     builder.Append(designTimeHtml);
                     continue;
                 }
                 catch
                 {
                     continue;
                 }
             }
         }
         str = builder.ToString();
     }
     catch (Exception)
     {
     }
     finally
     {
         if (designerHost != null)
         {
             ((IDisposable) designerHost).Dispose();
             designerHost = null;
         }
     }
     return str;
 }