private RootDesignerView(IDesignerHost host) : base() { //it's through this that we communicate with JavaScript comm = new CommandManager(this); //we use the host to get services and designers this.host = host as DesignerHost; if (this.host == null) { throw new ArgumentNullException("host"); } //We use this to monitor component changes and update as necessary changeService = host.GetService(typeof(IComponentChangeService)) as IComponentChangeService; if (changeService == null) { throw new Exception("Could not obtain IComponentChangeService from host"); } //We use this to monitor and set selections selectionService = host.GetService(typeof(ISelectionService)) as ISelectionService; if (selectionService == null) { throw new Exception("Could not obtain ISelectionService from host"); } //This is used to add undo/redo, cut/paste etc commands to menu //Also to launch right-click menu menuService = host.GetService(typeof(IMenuCommandService)) as IMenuCommandService; //if (menuService == null) // return; //Now we've got all services, register our events changeService.ComponentChanged += new ComponentChangedEventHandler(changeService_ComponentChanged); selectionService.SelectionChanged += new EventHandler(selectionService_SelectionChanged); //Register incoming calls from JavaScript comm.RegisterJSHandler("Click", new ClrCall(JSClick)); comm.RegisterJSHandler("Activate", new ClrCall(JSActivate)); comm.RegisterJSHandler("ThrowException", new ClrCall(JSException)); comm.RegisterJSHandler("DebugStatement", new ClrCall(JSDebugStatement)); comm.RegisterJSHandler("ResizeControl", new ClrCall(JSResize)); comm.RegisterJSHandler("DocumentReturn", new ClrCall(JSDocumentReturn)); comm.RegisterJSHandler("RemoveControl", new ClrCall(JSRemoveControl)); comm.RegisterJSHandler("DeserializeAndAdd", new ClrCall(JSDeserializeAndAdd)); comm.RegisterJSHandler("Serialize", new ClrCall(JSSerialize)); System.Diagnostics.Trace.WriteLine("RootDesignerView created"); }
private void handleToolboxNode(ItemToolboxNode node) { ToolboxItemToolboxNode tiNode = node as ToolboxItemToolboxNode; if (tiNode != null) { //load the type into this process and get the ToolboxItem tiNode.Type.Load(); System.Drawing.Design.ToolboxItem ti = tiNode.GetToolboxItem(); //web controls have sample HTML that need to be deserialised, in a ToolboxDataAttribute //TODO: Fix WebControlToolboxItem and (mono classlib's use of it) so we don't have to mess around with type lookups and attributes here if (ti.AssemblyName != null && ti.TypeName != null) { //look up and register the type ITypeResolutionService typeRes = (ITypeResolutionService)designerHost.GetService(typeof(ITypeResolutionService)); typeRes.ReferenceAssembly(ti.AssemblyName); Type controlType = typeRes.GetType(ti.TypeName, true); //read the WebControlToolboxItem data from the attribute AttributeCollection atts = TypeDescriptor.GetAttributes(controlType); System.Web.UI.ToolboxDataAttribute tda = (System.Web.UI.ToolboxDataAttribute)atts [typeof(System.Web.UI.ToolboxDataAttribute)]; //if it's present if (tda != null && tda.Data.Length > 0) { //look up the tag's prefix and insert it into the data WebFormReferenceManager webRef = designerHost.GetService(typeof(WebFormReferenceManager)) as WebFormReferenceManager; if (webRef == null) { throw new Exception("Host does not provide an IWebFormReferenceManager"); } string aspText = String.Format(tda.Data, webRef.GetTagPrefix(controlType)); System.Diagnostics.Trace.WriteLine("Toolbox processing ASP.NET item data: " + aspText); //and add it to the document designerHost.RootDocument.InsertFragment(aspText); return; } } //No ToolboxDataAttribute? Get the ToolboxItem to create the components itself ti.CreateComponents(designerHost); } }
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 IWebApplication GetWebApplication() { IWebApplication webApplication = (IWebApplication)DesignerHost.GetService(typeof(IWebApplication)); Assertion.IsNotNull(webApplication, "The 'IServiceProvider' failed to return an 'IWebApplication' service."); return(webApplication); }
//TODO: Some way to reset this when host is reset public WebFormReferenceManager (DesignerHost host) { if (host == null) throw new ArgumentNullException ("host"); this.host = host; this.typeRes = host.GetService (typeof (ITypeResolutionService)) as ITypeResolutionService; if (typeRes == null) throw new Exception ("Could not obtain ITypesResolutionService from host"); }
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 RootDesignerView (IDesignerHost host) : base() { //it's through this that we communicate with JavaScript comm = new CommandManager (this); //we use the host to get services and designers this.host = host as DesignerHost; if (this.host == null) throw new ArgumentNullException ("host"); //We use this to monitor component changes and update as necessary changeService = host.GetService (typeof (IComponentChangeService)) as IComponentChangeService; if (changeService == null) throw new Exception ("Could not obtain IComponentChangeService from host"); //We use this to monitor and set selections selectionService = host.GetService (typeof (ISelectionService)) as ISelectionService; if (selectionService == null) throw new Exception ("Could not obtain ISelectionService from host"); //This is used to add undo/redo, cut/paste etc commands to menu //Also to launch right-click menu menuService = host.GetService (typeof (IMenuCommandService)) as IMenuCommandService; //if (menuService == null) // return; //Now we've got all services, register our events changeService.ComponentChanged += new ComponentChangedEventHandler (changeService_ComponentChanged); selectionService.SelectionChanged += new EventHandler (selectionService_SelectionChanged); //Register incoming calls from JavaScript comm.RegisterJSHandler ("Click", new ClrCall (JSClick)); comm.RegisterJSHandler ("Activate", new ClrCall (JSActivate)); comm.RegisterJSHandler ("ThrowException", new ClrCall (JSException)); comm.RegisterJSHandler ("DebugStatement", new ClrCall (JSDebugStatement)); comm.RegisterJSHandler ("ResizeControl", new ClrCall (JSResize)); comm.RegisterJSHandler ("DocumentReturn", new ClrCall (JSDocumentReturn)); comm.RegisterJSHandler ("RemoveControl", new ClrCall (JSRemoveControl)); comm.RegisterJSHandler ("DeserializeAndAdd", new ClrCall (JSDeserializeAndAdd)); comm.RegisterJSHandler ("Serialize", new ClrCall (JSSerialize)); System.Diagnostics.Trace.WriteLine ("RootDesignerView created"); }
/// <include file='doc\DesignSite.uex' path='docs/doc[@for="DesignSite.GetService"]/*' /> /// <devdoc> /// Retrieves the requested service. /// </devdoc> public object GetService(Type service) { if (service == typeof(IDictionaryService)) { return((IDictionaryService)this); } else if (service == typeof(IExtenderListService)) { return((IExtenderListService)this); } return(host.GetService(service)); }
public object GetDesignTimePropertyValue(string propertyName) { ArgumentUtility.CheckNotNullOrEmpty("propertyName", propertyName); try { //EnvDTE._DTE environment = (EnvDTE._DTE) ((IServiceProvider)site).GetService (typeof (EnvDTE._DTE)); Type _DTEType = TypeUtility.GetType("EnvDTE._DTE, EnvDTE", true); object environment = DesignerHost.GetService(_DTEType); if (environment != null) { //EnvDTE.Project project = environment.ActiveDocument.ProjectItem.ContainingProject; object activeDocument = _DTEType.InvokeMember("ActiveDocument", BindingFlags.GetProperty, null, environment, null); object projectItem = activeDocument.GetType().InvokeMember("ProjectItem", BindingFlags.GetProperty, null, activeDocument, null); object project = projectItem.GetType().InvokeMember("ContainingProject", BindingFlags.GetProperty, null, projectItem, null); ////project.Properties uses a 1-based index //foreach (EnvDTE.Property property in project.Properties) object properties = project.GetType().InvokeMember("Properties", BindingFlags.GetProperty, null, project, null); foreach (object property in (IEnumerable)properties) { //if (property.Name == propertyName) string projectPropertyName = (string)property.GetType().InvokeMember("Name", BindingFlags.GetProperty, null, property, null); if (projectPropertyName == propertyName) { //return property.Value; return(property.GetType().InvokeMember("Value", BindingFlags.GetProperty, null, property, null)); } } } } catch { return(null); } return(null); }
public ServerObjectParsingObject(Type type, Hashtable attributes, string tagid, ParsingObject parent) : base(tagid, parent) { //create the object if (type.GetInterface("System.ComponentModel.IComponent") != null) { //note: this automatically adds to parent's container, as some controls //need to be sited e.g. if they use site dictionaries //TODO: should this action be passed up the tree so controls can intercept? obj = ((AspNetEdit.Editor.ComponentModel.DesignerHost)base.DesignerHost).CreateComponent(type, attributes["ID"] as string, false); } else { obj = Activator.CreateInstance(type); } //and populate it from the attributes pdc = TypeDescriptor.GetProperties(obj); foreach (DictionaryEntry de in attributes) { if (0 == string.Compare((string)de.Key, "runat")) { continue; } if (0 == string.Compare((string)de.Key, "ID")) { continue; } //use the dash subproperty syntax string[] str = ((string)de.Key).Split('-'); PropertyDescriptor pd = pdc.Find(str[0], true); //if property not found, try events if (str.Length == 1 && pd == null && CultureInfo.InvariantCulture.CompareInfo.IsPrefix(str[0].ToLower(), "on")) { IEventBindingService iebs = (IEventBindingService)DesignerHost.GetService(typeof(IEventBindingService)); if (iebs == null) { throw new Exception("Could not obtain IEventBindingService from host"); } EventDescriptorCollection edc = TypeDescriptor.GetEvents(obj); EventDescriptor e = edc.Find(str[0].Remove(0, 2), true); if (e != null) { pd = iebs.GetEventProperty(e); } else { throw new Exception("Could not find event " + str[0].Remove(0, 2)); } } object loopObj = obj; for (int i = 0; i < str.Length; i++) { if (pd == null) { throw new Exception("Could not find property " + (string)de.Key); } if (i == str.Length - 1) { pd.SetValue(obj, pd.Converter.ConvertFromString((string)de.Value)); break; } loopObj = pd.GetValue(loopObj); pd = TypeDescriptor.GetProperties(loopObj).Find(str[0], true); } } parseAtt = TypeDescriptor.GetAttributes(obj)[typeof(ParseChildrenAttribute)] as ParseChildrenAttribute; //FIXME: fix this in MCS classlib if (parseAtt.DefaultProperty.Length == 0) { parseAtt = null; } //work out how we're trying to parse the children if (parseAtt != null) { if (parseAtt.DefaultProperty != null) { PropertyDescriptor pd = pdc[parseAtt.DefaultProperty]; if (pd == null) { throw new Exception("Default property does not exist"); } if (pd.PropertyType.GetInterface("System.Collections.IList") == (typeof(IList))) { mode = ParseChildrenMode.DefaultCollectionProperty; } else { mode = ParseChildrenMode.DefaultProperty; } } else if (parseAtt.ChildrenAsProperties) { mode = ParseChildrenMode.Properties; } else { mode = ParseChildrenMode.Controls; } } else { //FIXME: these are actually persistence hints, but ParseChildrenAttribute doesn't always exist. //FIXME: logic would be dodgy with bad input parseAtt = ParseChildrenAttribute.Default; mode = ParseChildrenMode.Controls; foreach (PropertyDescriptor pd in pdc) { PersistenceModeAttribute modeAttrib = pd.Attributes[typeof(PersistenceModeAttribute)] as PersistenceModeAttribute; if (modeAttrib == null) { return; } switch (modeAttrib.Mode) { case PersistenceMode.Attribute: continue; case PersistenceMode.EncodedInnerDefaultProperty: parseAtt.DefaultProperty = pd.Name; mode = ParseChildrenMode.DefaultEncodedProperty; break; case PersistenceMode.InnerDefaultProperty: parseAtt.DefaultProperty = pd.Name; if (pd.PropertyType.GetInterface("System.Collections.IList") == (typeof(IList))) { mode = ParseChildrenMode.DefaultCollectionProperty; } else { mode = ParseChildrenMode.DefaultProperty; } break; case PersistenceMode.InnerProperty: mode = ParseChildrenMode.Properties; break; } } } }
protected T GetService <T>() where T : class { return(DesignerHost.GetService(typeof(T)) as T); }
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; }