public static string ResolveFileName(string filename, ISite site, bool designMode) { string fileName = null; if (!Path.IsPathRooted(filename)) { // in design mode, resolve url using IUrlResolutionService if (designMode) { IWebApplication app = (IWebApplication) site.GetService(typeof(IWebApplication)); if (app != null) { IProjectItem projectItem = app.GetProjectItemFromUrl(filename); if (projectItem == null) throw new InvalidOperationException("Could not load ProjectItem corresponding to source filename '" + filename + "'."); fileName = projectItem.PhysicalPath; } } else if (HttpContext.Current != null) { fileName = HttpContext.Current.Server.MapPath(filename); } if (fileName == null) throw new InvalidOperationException("Could not resolve source filename."); } else { fileName = filename; } return fileName; }
internal WebConfigManager(ISite site) { Debug.Assert(site != null); _site = site; IWebApplication webApplicationService = (IWebApplication)_site.GetService(typeof(IWebApplication)); if (webApplicationService != null) { IProjectItem dataFileProjectItem = webApplicationService.GetProjectItemFromUrl("~/web.config"); if (dataFileProjectItem != null) { _path = dataFileProjectItem.PhysicalPath; } } /* VSWhidbey 271075, 257678 // the following inspired by: // \VSDesigner\Designer\Microsoft\VisualStudio\Designer\Serialization\BaseDesignerLoader.cs Type projectItemType = Type.GetType("EnvDTE.ProjectItem, " + AssemblyRef.EnvDTE); if (projectItemType != null) { Object currentProjItem = _site.GetService(projectItemType); PropertyInfo containingProjectProp = projectItemType.GetProperty("ContainingProject"); Object dteProject = containingProjectProp.GetValue(currentProjItem, new Object[0]); Type projectType = Type.GetType("EnvDTE.Project, " + AssemblyRef.EnvDTE); PropertyInfo fullNameProperty = projectType.GetProperty("FullName"); String projectPath = (String)fullNameProperty.GetValue(dteProject, new Object[0]); _path = Path.GetDirectoryName(projectPath) + "\\web.config"; } */ }
public CommandSet(ISite site) { this.site = site; this.eventService = (IEventHandlerService) site.GetService(typeof(IEventHandlerService)); this.eventService.EventHandlerChanged += new EventHandler(this.OnEventHandlerChanged); IDesignerHost host = (IDesignerHost) site.GetService(typeof(IDesignerHost)); if (host != null) { host.Activated += new EventHandler(this.UpdateClipboardItems); } this.statusCommandUI = new StatusCommandUI(site); IUIService uiService = site.GetService(typeof(IUIService)) as IUIService; this.commandSet = new CommandSetItem[] { new CommandSetItem(this, new EventHandler(this.OnStatusDelete), new EventHandler(this.OnMenuDelete), StandardCommands.Delete, uiService), new CommandSetItem(this, new EventHandler(this.OnStatusCopy), new EventHandler(this.OnMenuCopy), StandardCommands.Copy, uiService), new CommandSetItem(this, new EventHandler(this.OnStatusCut), new EventHandler(this.OnMenuCut), StandardCommands.Cut, uiService), new ImmediateCommandSetItem(this, new EventHandler(this.OnStatusPaste), new EventHandler(this.OnMenuPaste), StandardCommands.Paste, uiService), new CommandSetItem(this, new EventHandler(this.OnStatusSelectAll), new EventHandler(this.OnMenuSelectAll), StandardCommands.SelectAll, true, uiService), new CommandSetItem(this, new EventHandler(this.OnStatusAlways), new EventHandler(this.OnMenuDesignerProperties), MenuCommands.DesignerProperties, uiService), new CommandSetItem(this, new EventHandler(this.OnStatusAlways), new EventHandler(this.OnKeyCancel), MenuCommands.KeyCancel, uiService), new CommandSetItem(this, new EventHandler(this.OnStatusAlways), new EventHandler(this.OnKeyCancel), MenuCommands.KeyReverseCancel, uiService), new CommandSetItem(this, new EventHandler(this.OnStatusPrimarySelection), new EventHandler(this.OnKeyDefault), MenuCommands.KeyDefaultAction, true, uiService), new CommandSetItem(this, new EventHandler(this.OnStatusAnySelection), new EventHandler(this.OnKeyMove), MenuCommands.KeyMoveUp, true, uiService), new CommandSetItem(this, new EventHandler(this.OnStatusAnySelection), new EventHandler(this.OnKeyMove), MenuCommands.KeyMoveDown, true, uiService), new CommandSetItem(this, new EventHandler(this.OnStatusAnySelection), new EventHandler(this.OnKeyMove), MenuCommands.KeyMoveLeft, true, uiService), new CommandSetItem(this, new EventHandler(this.OnStatusAnySelection), new EventHandler(this.OnKeyMove), MenuCommands.KeyMoveRight, true), new CommandSetItem(this, new EventHandler(this.OnStatusAnySelection), new EventHandler(this.OnKeyMove), MenuCommands.KeyNudgeUp, true, uiService), new CommandSetItem(this, new EventHandler(this.OnStatusAnySelection), new EventHandler(this.OnKeyMove), MenuCommands.KeyNudgeDown, true, uiService), new CommandSetItem(this, new EventHandler(this.OnStatusAnySelection), new EventHandler(this.OnKeyMove), MenuCommands.KeyNudgeLeft, true, uiService), new CommandSetItem(this, new EventHandler(this.OnStatusAnySelection), new EventHandler(this.OnKeyMove), MenuCommands.KeyNudgeRight, true, uiService) }; this.selectionService = (ISelectionService) site.GetService(typeof(ISelectionService)); if (this.selectionService != null) { this.selectionService.SelectionChanged += new EventHandler(this.OnSelectionChanged); } this.menuService = (IMenuCommandService) site.GetService(typeof(IMenuCommandService)); if (this.menuService != null) { for (int i = 0; i < this.commandSet.Length; i++) { this.menuService.AddCommand(this.commandSet[i]); } } IDictionaryService service = site.GetService(typeof(IDictionaryService)) as IDictionaryService; if (service != null) { service.SetValue(typeof(CommandID), new CommandID(new Guid("BA09E2AF-9DF2-4068-B2F0-4C7E5CC19E2F"), 0)); } }
internal static Font GetVS7Font(ISite site) { System.Drawing.Font vsfont = Control.DefaultFont; if (site != null) { IUIService uiService = (IUIService) site.GetService( typeof(IUIService) ); if (uiService != null) { vsfont = (Font) uiService.Styles["DialogFont"]; } } return vsfont; }
private static ConfigSection section; // = ConfigurationManager.GetSection(ConfigSectionName.FineUI) as ConfigSection; /// <summary> /// Refer:http://flimflan.com/blog/AccessingWebconfigAtDesignTimeInNET20.aspx /// </summary> /// <param name="site"></param> /// <returns></returns> public static ConfigSection GetDesignTimeSection(ISite site) { IWebApplication webApp = (IWebApplication)site.GetService(typeof(IWebApplication)); if (webApp != null) { Configuration config = webApp.OpenWebConfiguration(false); if (config != null) { ConfigurationSection section = config.GetSection(ConfigSectionName.FineUI); if (section != null) { return section as ConfigSection; } } } return null; }
internal void AddControl(Control ctl) { // lock (this) { if (containerCache.Contains(ctl)) { throw new ArgumentException(string.Format(SR.AXDuplicateControl, GetNameForControl(ctl)), "ctl"); } containerCache.Add(ctl, ctl); if (assocContainer == null) { ISite site = ctl.Site; if (site != null) { assocContainer = site.Container; IComponentChangeService ccs = (IComponentChangeService)site.GetService(typeof(IComponentChangeService)); if (ccs != null) { ccs.ComponentRemoved += new ComponentEventHandler(OnComponentRemoved); } } } else { #if DEBUG ISite site = ctl.Site; if (site != null && assocContainer != site.Container) { Debug.WriteLineIf(AxHTraceSwitch.TraceVerbose, "mismatch between assoc container & added control"); } #endif } } }
public void SetAction(Component self, TBasicAction value) { TBasicActionLink actionLink = GetActionLink(self); if (actionLink != null && actionLink.Action == value) { return; } if (value == null) { actionLink.Dispose(); lock (compToActionLinks) compToActionLinks.Remove(self); } else { if (actionLink == null) { actionLink = CreateActionLink(self); lock (compToActionLinks) compToActionLinks.Add(self, actionLink); actionLink.Change += (sender, e) => DoActionChange(self, sender, e); } actionLink.Action = value; bool isloading = false; ISite site = value.Site ?? self.Site; if (site != null) { IDesignerHost designHost = site.GetService(typeof(IDesignerHost)) as IDesignerHost; if (designHost != null) { isloading = designHost.Loading; } } ActionChange(self, value, isloading); } }
/// <include file='doc\DesignerExtenders.uex' path='docs/doc[@for="DesignerExtenders.CSharpExtenderProvider.CanExtend"]/*' /> /// <devdoc> /// Determines if ths extender provider can extend the given object. We extend /// all objects, so we always return true. /// </devdoc> public bool CanExtend(object o) { if (!(o is IComponent)) { return(false); } // We don't add modifiers to the base component. // if (baseComponent == null) { ISite site = ((IComponent)o).Site; if (site != null) { IDesignerHost host = (IDesignerHost)site.GetService(typeof(IDesignerHost)); if (host != null) { baseComponent = host.RootComponent; } } } if (o == baseComponent) { return(false); } // Now see if this object is inherited. If so, then we don't want to // extend. // if (!TypeDescriptor.GetAttributes(o)[typeof(InheritanceAttribute)].Equals(InheritanceAttribute.NotInherited)) { return(false); } return(true); }
internal virtual void OnPropertyChanged(DispatchID dispid) { try { ISite site = Host.Site; if (site is not null) { IComponentChangeService changeService = (IComponentChangeService)site.GetService(typeof(IComponentChangeService)); if (changeService is not null) { try { changeService.OnComponentChanging(Host, null); } catch (CheckoutException coEx) { if (coEx == CheckoutException.Canceled) { return; } throw; } // Now notify the change service that the change was successful. // changeService.OnComponentChanged(Host, null, null, null); } } } catch (Exception t) { Debug.Fail(t.ToString()); throw; } }
public override object GetValue(object component) { if (component == null) { throw new ArgumentNullException("component"); } ISite site = null; if (component is IComponent) { site = ((IComponent)component).Site; } if (site == null) { IReferenceService service = this._eventSvc._provider.GetService(typeof(IReferenceService)) as IReferenceService; if (service != null) { IComponent component2 = service.GetComponent(component); if (component2 != null) { site = component2.Site; } } } if (site == null) { return(null); } IDictionaryService service2 = (IDictionaryService)site.GetService(typeof(IDictionaryService)); if (service2 == null) { return(null); } return((string)service2.GetValue(new ReferenceEventClosure(component, this))); }
public static GlobalConfig GetExtNetSection(ISite site) { if (site != null) { IWebApplication app = (IWebApplication)site.GetService(typeof(IWebApplication)); if (app != null) { Configuration config = app.OpenWebConfiguration(false); if (config != null) { ConfigurationSection section = config.GetSection("extnet"); if (section != null) { return(section as GlobalConfig); } } } } return(null); }
private IEventBindingService GetEventPropertyService(object obj, ITypeDescriptorContext context) { IEventBindingService eventPropertySvc = null; if (!sunkEvent) { IDesignerEventService des = (IDesignerEventService)sp.GetService(typeof(IDesignerEventService)); if (des != null) { des.ActiveDesignerChanged += new ActiveDesignerEventHandler(this.OnActiveDesignerChanged); } sunkEvent = true; } if (eventPropertySvc == null && currentHost != null) { eventPropertySvc = (IEventBindingService)currentHost.GetService(typeof(IEventBindingService)); } if (eventPropertySvc == null && obj is IComponent) { ISite site = ((IComponent)obj).Site; if (site != null) { eventPropertySvc = (IEventBindingService)site.GetService(typeof(IEventBindingService)); } } if (eventPropertySvc == null && context != null) { eventPropertySvc = (IEventBindingService)context.GetService(typeof(IEventBindingService)); } return(eventPropertySvc); }
private bool RegisterControl(WebBrowserBase ctl) { ISite site = ctl.Site; if (site != null) { IContainer container = site.Container; if (container != null) { if (this.assocContainer != null) { return(container == this.assocContainer); } this.assocContainer = container; IComponentChangeService service = (IComponentChangeService)site.GetService(typeof(IComponentChangeService)); if (service != null) { service.ComponentRemoved += new ComponentEventHandler(this.OnComponentRemoved); } return(true); } } return(false); }
/// <summary> /// <para> /// Persists a control using the /// specified string writer. /// </para> /// </summary> /// <param name='sw'> /// The string writer to use. /// </param> /// <param name=' control'> /// The control to persist. /// </param> internal static void PersistControl(TextWriter sw, Control control) { if (control is LiteralControl) { PersistLiteralControl(sw, (LiteralControl)control); return; } if (control is DesignerDataBoundLiteralControl) { PersistDataBoundLiteralControl(sw, (DesignerDataBoundLiteralControl)control); return; } ISite site = control.Site; if (site == null) { IComponent baseComponent = (IComponent)control.Page; Debug.Assert(baseComponent != null, "Control does not have its Page set!"); if (baseComponent != null) { site = baseComponent.Site; } } IDesignerHost host = null; if (site != null) { host = (IDesignerHost)site.GetService(typeof(IDesignerHost)); } Debug.Assert(host != null, "Did not get a valid IDesignerHost reference. Expect persistence problems!"); PersistControl(sw, control, host); }
/// <summary> /// This will set value to be the new value of this property on the /// component by invoking the setXXX method on the component. If the /// value specified is invalid, the component should throw an exception /// which will be passed up. The component designer should design the /// property so that getXXX following a setXXX should return the value /// passed in if no exception was thrown in the setXXX call. /// </summary> public override void SetValue(object component, object value) { Debug.WriteLine($"[{Name}]: SetValue({component?.GetType().Name ?? "(null)"}, {value?.GetType().Name ?? "(null)"})"); if (component != null) { ISite site = GetSite(component); object oldValue = null; object invokee = GetInvocationTarget(_componentClass, component); if (!IsReadOnly) { IComponentChangeService changeService = null; // Announce that we are about to change this component if (site != null) { changeService = (IComponentChangeService)site.GetService(typeof(IComponentChangeService)); } // Make sure that it is ok to send the onchange events if (changeService != null) { oldValue = GetMethodValue.Invoke(invokee, null); try { changeService.OnComponentChanging(component, this); } catch (CheckoutException coEx) { if (coEx == CheckoutException.Canceled) { return; } throw; } } try { try { SetMethodValue.Invoke(invokee, new object[] { value }); OnValueChanged(invokee, EventArgs.Empty); } catch (Exception t) { // Give ourselves a chance to unwind properly before rethrowing the exception. // value = oldValue; // If there was a problem setting the controls property then we get: // ArgumentException (from properties set method) // ==> Becomes inner exception of TargetInvocationException // ==> caught here if (t is TargetInvocationException && t.InnerException != null) { // Propagate the original exception up throw t.InnerException; } else { throw; } } } finally { // Now notify the change service that the change was successful. changeService?.OnComponentChanged(component, this, oldValue, value); } } } }
protected virtual Object [] GetValidatableControls(Object instance) { System.Web.UI.MobileControls.BaseValidator thisValidator = null; if (instance is Array) { Array controlList = (Array)instance; Debug.Assert(controlList.Length > 0); thisValidator = (BaseValidator)controlList.GetValue(0); Form firstForm = GetContainingForm(thisValidator); for (int i = 1; i < controlList.Length; i++) { BaseValidator validator = (BaseValidator)controlList.GetValue(i); if (GetContainingForm(validator) != firstForm) { return(null); } } } if (instance is System.Web.UI.MobileControls.BaseValidator) { thisValidator = (System.Web.UI.MobileControls.BaseValidator)instance; } else if (instance is ChoicePropertyFilter) { IDeviceSpecificDesigner designer = ((ChoicePropertyFilter)instance).Designer; thisValidator = designer.UnderlyingObject as System.Web.UI.MobileControls.BaseValidator; } if (thisValidator == null) { Debug.Fail("Unsupported object passed in"); return(null); } ArrayList controlArray = new ArrayList(); if (GetContainingStyleSheet(thisValidator) != null) { ISite site = thisValidator.Site; IContainer container = null; if (site != null) { container = (IContainer)site.GetService(typeof(IContainer)); Debug.Assert(container != null); foreach (IComponent component in container.Components) { Control control = component as Control; if (control != null && CanBeValidated(control)) { controlArray.Add(control.ID); } } } } else { Form parentForm = GetContainingForm(thisValidator); if (parentForm != null) { ExtractValidatableControls(parentForm, controlArray); } else { return(null); } } controlArray.Sort(); return(controlArray.ToArray()); }
/// <summary> /// This adds the delegate value as a listener to when this event is fired /// by the component, invoking the addOnXXX method. /// </summary> public override void AddEventHandler(object component, Delegate value) { FillMethods(); if (component != null) { ISite site = GetSite(component); IComponentChangeService changeService = null; // Announce that we are about to change this component // if (site != null) { changeService = (IComponentChangeService)site.GetService(typeof(IComponentChangeService)); } if (changeService != null) { try { changeService.OnComponentChanging(component, this); } catch (CheckoutException coEx) { if (coEx == CheckoutException.Canceled) { return; } throw coEx; } changeService.OnComponentChanging(component, this); } bool shadowed = false; if (site != null && site.DesignMode) { // Events are final, so just check the class if (EventType != value.GetType()) { throw new ArgumentException(SR.Format(SR.ErrorInvalidEventHandler, Name)); } IDictionaryService dict = (IDictionaryService)site.GetService(typeof(IDictionaryService)); if (dict != null) { Delegate eventdesc = (Delegate)dict.GetValue(this); eventdesc = Delegate.Combine(eventdesc, value); dict.SetValue(this, eventdesc); shadowed = true; } } if (!shadowed) { _addMethod.Invoke(component, new[] { value }); } // Now notify the change service that the change was successful. // if (changeService != null) { changeService.OnComponentChanged(component, this, null, value); } } }
/// <summary> /// Navigates code to the given event. /// </summary> protected bool ViewEvent(object obj, string newHandler, EventDescriptor eventdesc, bool alwaysNavigate) { object value = GetPropertyValueCore(obj); string handler = value as string; if (handler == null && value != null && TypeConverter != null && TypeConverter.CanConvertTo(typeof(string))) { handler = TypeConverter.ConvertToString(value); } if (newHandler == null && !string.IsNullOrEmpty(handler)) { newHandler = handler; } else if (handler == newHandler && !string.IsNullOrEmpty(newHandler)) { return(true); } IComponent component = obj as IComponent; if (component == null && propertyInfo is MergePropertyDescriptor) { // It's possible that multiple objects are selected, and we're trying to create an event for each of them // Array objArray = obj as Array; if (objArray != null && objArray.Length > 0) { component = objArray.GetValue(0) as IComponent; } } if (component == null) { return(false); } if (propertyInfo.IsReadOnly) { return(false); } if (eventdesc == null) { if (eventBindings == null) { eventBindings = (IEventBindingService)GetService(typeof(IEventBindingService)); } if (eventBindings != null) { eventdesc = eventBindings.GetEvent(propertyInfo); } } IDesignerHost host = this.DesignerHost; DesignerTransaction trans = null; try { // This check can cause exceptions if the event has unreferenced dependencies, which we want to cath. // This must be done before the transaction is started or the commit/cancel will also throw. if (eventdesc.EventType == null) { return(false); } if (host != null) { string compName = component.Site != null ? component.Site.Name : component.GetType().Name; trans = DesignerHost.CreateTransaction(string.Format(SR.WindowsFormsSetEvent, compName + "." + this.PropertyName)); } if (eventBindings == null) { ISite site = component.Site; if (site != null) { eventBindings = (IEventBindingService)site.GetService(typeof(IEventBindingService)); } } if (newHandler == null && eventBindings != null) { newHandler = eventBindings.CreateUniqueMethodName(component, eventdesc); } if (newHandler != null) { // now walk through all the matching methods to see if this one exists. // if it doesn't we'll wanna show code. // if (eventBindings != null) { bool methodExists = false; foreach (string methodName in eventBindings.GetCompatibleMethods(eventdesc)) { if (newHandler == methodName) { methodExists = true; break; } } if (!methodExists) { alwaysNavigate = true; } } try { propertyInfo.SetValue(obj, newHandler); } catch (InvalidOperationException ex) { if (trans != null) { trans.Cancel(); trans = null; } if (this.GridEntryHost != null && this.GridEntryHost is PropertyGridView) { PropertyGridView pgv = this.GridEntryHost as PropertyGridView; pgv.ShowInvalidMessage(newHandler, obj, ex); } return(false); } } if (alwaysNavigate && eventBindings != null) { targetBindingService = eventBindings; targetComponent = component; targetEventdesc = eventdesc; Application.Idle += new EventHandler(PropertyDescriptorGridEntry.ShowCodeIdle); } } catch { if (trans != null) { trans.Cancel(); trans = null; } throw; } finally { if (trans != null) { trans.Commit(); } } return(true); }
public static GlobalConfig GetExtNetSection(ISite site) { if (site != null) { IWebApplication app = (IWebApplication)site.GetService(typeof(IWebApplication)); if (app != null) { Configuration config = app.OpenWebConfiguration(false); if (config != null) { ConfigurationSection section = config.GetSection("extnet"); if (section != null) { return section as GlobalConfig; } } } } return null; }
/// <include file='doc\DataFieldConverter.uex' path='docs/doc[@for="DataFieldConverter.GetStandardValues"]/*' /> /// <devdoc> /// <para> /// Gets the fields present within the selected data source if information about them is available. /// </para> /// </devdoc> public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { object[] names = null; String dataMember = null; bool autoGenerateFields = false; bool autoGenerateFieldsSet = false; ObjectList objectList = null; if (context != null) { ArrayList list = new ArrayList(); PropertyDescriptorCollection props = null; IComponent component = context.Instance as IComponent; if (component is IDeviceSpecificChoiceDesigner) { Object owner = ((ChoicePropertyFilter)component).Owner; PropertyDescriptor pd = ((ICustomTypeDescriptor)component).GetProperties()[_dataMemberPropertyName]; Debug.Assert(pd != null, "Cannot get DataMember"); if (owner is ObjectList) { autoGenerateFields = ((ObjectList)owner).AutoGenerateFields; autoGenerateFieldsSet = true; } component = ((IDeviceSpecificChoiceDesigner)component).UnderlyingControl; // See if owner already has a DataMember dataMember = (String)pd.GetValue(owner); Debug.Assert(dataMember != null); if (dataMember == String.Empty) { // Get it from underlying object. dataMember = (String)pd.GetValue(component); Debug.Assert(dataMember != null); } } if (component != null) { objectList = component as ObjectList; if (objectList != null) { foreach (ObjectListField field in objectList.Fields) { list.Add(field.Name); } if (!autoGenerateFieldsSet) { autoGenerateFields = objectList.AutoGenerateFields; } } if (objectList == null || autoGenerateFields) { ISite componentSite = component.Site; if (componentSite != null) { IDesignerHost designerHost = (IDesignerHost)componentSite.GetService(typeof(IDesignerHost)); if (designerHost != null) { IDesigner designer = designerHost.GetDesigner(component); if (designer is IDataSourceProvider) { IEnumerable dataSource = null; if (dataMember != null && dataMember != String.Empty) { DataBindingCollection dataBindings = ((HtmlControlDesigner)designer).DataBindings; DataBinding binding = dataBindings[_dataSourcePropertyName]; if (binding != null) { dataSource = DesignTimeData.GetSelectedDataSource( component, binding.Expression, dataMember); } } else { dataSource = ((IDataSourceProvider)designer).GetResolvedSelectedDataSource(); } if (dataSource != null) { props = DesignTimeData.GetDataFields(dataSource); } } } } } } if (props != null) { foreach (PropertyDescriptor propDesc in props) { list.Add(propDesc.Name); } } names = list.ToArray(); Array.Sort(names); } return(new StandardValuesCollection(names)); }
/// <summary> /// 设计时嵌入资源url地址 /// </summary> /// <param name="site"></param> /// <param name="resourceName"></param> /// <returns></returns> public static string GetWebResourceUrl(ISite site, string resourceName) { string resourceUrl = String.Empty; if (site != null) { IResourceUrlGenerator service = (IResourceUrlGenerator)site.GetService(typeof(IResourceUrlGenerator)); if (service != null) { resourceUrl = service.GetResourceUrl(site.Component.GetType(), resourceName); } } //// 告诉HttpCompress,不要设置ETag,同时设置Expires为一年后的今天 //resourceUrl += "&expires=1"; return resourceUrl; }
public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { object[] objArray1 = null; if (context != null) { IComponent component1 = context.Instance as IComponent; if (component1 != null) { ISite site1 = component1.Site; if (site1 != null) { IDesignerHost host1 = (IDesignerHost)site1.GetService(typeof(IDesignerHost)); if (host1 != null) { IDesigner designer1 = host1.GetDesigner(component1); DesignerDataSourceView view1 = this.GetView(designer1); if (view1 != null) { IDataSourceViewSchema schema1 = null; try { schema1 = view1.Schema; } catch (Exception exception1) { IComponentDesignerDebugService service1 = (IComponentDesignerDebugService)site1.GetService(typeof(IComponentDesignerDebugService)); if (service1 != null) { service1.Fail("DataSource DebugService FailedCall\r\n" + exception1.ToString()); } } if (schema1 != null) { IDataSourceFieldSchema[] schemaArray1 = schema1.GetFields(); if (schemaArray1 != null) { objArray1 = new object[schemaArray1.Length]; for (int num1 = 0; num1 < schemaArray1.Length; num1++) { objArray1[num1] = schemaArray1[num1].Name; } } } } if (((objArray1 == null) && (designer1 != null)) && (designer1 is IDataSourceProvider)) { IDataSourceProvider provider1 = designer1 as IDataSourceProvider; IEnumerable enumerable1 = null; if (provider1 != null) { enumerable1 = provider1.GetResolvedSelectedDataSource(); } if (enumerable1 != null) { PropertyDescriptorCollection collection1 = DesignTimeData.GetDataFields(enumerable1); if (collection1 != null) { ArrayList list1 = new ArrayList(); foreach (PropertyDescriptor descriptor1 in collection1) { list1.Add(descriptor1.Name); } objArray1 = list1.ToArray(); } } } } } } } return(new TypeConverter.StandardValuesCollection(objArray1)); }
public void SetSite(ISite site) { this.site = site; IServiceProvider sp = (IServiceProvider)site; this.resolver = new XmlProxyResolver(sp); this.model = (XmlCache)site.GetService(typeof(XmlCache)); this.model.ModelChanged -= new EventHandler<ModelChangedEventArgs>(OnModelChanged); this.model.ModelChanged += new EventHandler<ModelChangedEventArgs>(OnModelChanged); }
protected virtual void AddInheritedComponents(Type type, IComponent component, IContainer container) { if ((type != null) && typeof(IComponent).IsAssignableFrom(type)) { ISite site = component.Site; IComponentChangeService service = null; INameCreationService service2 = null; if (site != null) { service2 = (INameCreationService)site.GetService(typeof(INameCreationService)); service = (IComponentChangeService)site.GetService(typeof(IComponentChangeService)); if (service != null) { service.ComponentAdding += new ComponentEventHandler(this.OnComponentAdding); } } try { while (type != typeof(object)) { Type reflectionType = TypeDescriptor.GetReflectionType(type); foreach (FieldInfo info in reflectionType.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)) { string name = info.Name; if (typeof(IComponent).IsAssignableFrom(info.FieldType)) { object obj2 = info.GetValue(component); if (obj2 != null) { InheritanceAttribute inheritedReadOnly; MemberInfo member = info; object[] customAttributes = info.GetCustomAttributes(typeof(AccessedThroughPropertyAttribute), false); if ((customAttributes != null) && (customAttributes.Length > 0)) { AccessedThroughPropertyAttribute attribute = (AccessedThroughPropertyAttribute)customAttributes[0]; PropertyInfo property = reflectionType.GetProperty(attribute.PropertyName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); if ((property != null) && (property.PropertyType == info.FieldType)) { if (!property.CanRead) { continue; } member = property.GetGetMethod(true); name = attribute.PropertyName; } } bool flag = this.IgnoreInheritedMember(member, component); bool flag2 = false; if (flag) { flag2 = true; } else if (member is FieldInfo) { FieldInfo info4 = (FieldInfo)member; flag2 = info4.IsPrivate | info4.IsAssembly; } else if (member is MethodInfo) { MethodInfo info5 = (MethodInfo)member; flag2 = info5.IsPrivate | info5.IsAssembly; } if (flag2) { inheritedReadOnly = InheritanceAttribute.InheritedReadOnly; } else { inheritedReadOnly = InheritanceAttribute.Inherited; } bool flag3 = this.inheritedComponents[obj2] == null; this.inheritedComponents[obj2] = inheritedReadOnly; if (!flag && flag3) { try { this.addingComponent = (IComponent)obj2; this.addingAttribute = inheritedReadOnly; if ((service2 == null) || service2.IsValidName(name)) { try { container.Add((IComponent)obj2, name); } catch { } } } finally { this.addingComponent = null; this.addingAttribute = null; } } } } } type = type.BaseType; } } finally { if (service != null) { service.ComponentAdding -= new ComponentEventHandler(this.OnComponentAdding); } } } }
internal static string LoadSystemLanguages(string systemmessagefile, ISite site) { if (systemmessagefile != null && systemmessagefile.StartsWith(HTTPCONST, StringComparison.OrdinalIgnoreCase) == false) { IWebApplication webApp = (IWebApplication) site.GetService(typeof (IWebApplication)); if (webApp != null) { if (webApp.RootProjectItem.PhysicalPath == null) throw new ApplicationException( string.Format("No Phystical path found for web project '{0}'", webApp.RootProjectItem.Name)); if (systemmessagefile.StartsWith("~/")) systemmessagefile = systemmessagefile.Remove(0, 2); systemmessagefile = Path.Combine(webApp.RootProjectItem.PhysicalPath, systemmessagefile); } } return systemmessagefile; }
public void SetSite(ISite site) { // Overriding the Site property directly breaks the WinForms designer. this.Site = site; this.settings = (Settings)site.GetService(typeof(Settings)); if (this.settings != null) { this.settings.Changed += new SettingsEventHandler(settings_Changed); } settings_Changed(this, ""); this.editor.Site = site; XmlCache model = (XmlCache)site.GetService(typeof(XmlCache)); model.ModelChanged += new EventHandler<ModelChangedEventArgs>(OnModelChanged); }
/// <summary> /// <para>Gets the implementer of the <see cref='System.IServiceProvider'/>.</para> /// </summary> public virtual object GetService(Type service) { return(_site?.GetService(service)); }
internal static void CheckConfiguration(ISite site) { if (site == null) { return; } IWebApplication app = (IWebApplication)site.GetService(typeof(IWebApplication)); if (app == null) { return; } Configuration config = app.OpenWebConfiguration(false); HttpHandlersSection handlers = (HttpHandlersSection)config.GetSection("system.web/httpHandlers"); // Does the httpHandlers Secton already exist? if (handlers == null) { // If not, add it... handlers = new HttpHandlersSection(); ConfigurationSectionGroup group = config.GetSectionGroup("system.web"); // Does the system.web Section already exist? if (group == null) { // If not, add it... config.SectionGroups.Add("system.web", new ConfigurationSectionGroup()); group = config.GetSectionGroup("system.web"); } if (group != null) { group.Sections.Add("httpHandlers", handlers); } } HttpHandlerAction action = new HttpHandlerAction("*/ext.axd", "Ext.Net.ResourceHandler", "*", false); // Does the ResourceHandler already exist? if (handlers.Handlers.IndexOf(action) < 0) { // If not, add it... handlers.Handlers.Add(action); config.Save(); } HttpModulesSection modules = (HttpModulesSection)config.GetSection("system.web/httpModules"); // Does the httpModules Secton already exist? if (modules == null) { // If not, add it... modules = new HttpModulesSection(); ConfigurationSectionGroup group = config.GetSectionGroup("system.web"); // Does the system.web Section already exist? if (group == null) { // If not, add it... config.SectionGroups.Add("system.web", new ConfigurationSectionGroup()); group = config.GetSectionGroup("system.web"); } if (group != null) { group.Sections.Add("httpModules", modules); } } //<add name="DirectRequestModule" type="Ext.Net.DirectRequestModule, Ext.Net" /> HttpModuleAction action2 = new HttpModuleAction("DirectRequestModule", "Ext.Net.DirectRequestModule, Ext.Net"); // Does the ResourceHandler already exist? if (modules.Modules.IndexOf(action2) < 0) { // If not, add it... modules.Modules.Add(action2); config.Save(); } }
/// <summary> /// </summary> protected virtual Object [] GetChoices(Object instance) { bool defaultAdded = false; DeviceSpecific deviceSpecific; if (instance is System.Web.UI.MobileControls.StyleSheet) { StyleSheet ss = (StyleSheet)instance; ISite componentSite = ss.Site; Debug.Assert(componentSite != null, "Expected the component to be sited."); IDesignerHost designerHost = (IDesignerHost)componentSite.GetService(typeof(IDesignerHost)); Debug.Assert(designerHost != null, "Expected a designer host."); Object designer = designerHost.GetDesigner(ss); Debug.Assert(designer != null, "Expected a designer for the stylesheet."); Debug.Assert(designer is StyleSheetDesigner, "Expected a StyleSheet designer."); StyleSheetDesigner ssd = (StyleSheetDesigner)designer; Style style = (Style)ssd.CurrentStyle; if (null != style) { deviceSpecific = style.DeviceSpecific; } else { deviceSpecific = null; } } else if (instance is System.Web.UI.MobileControls.DeviceSpecific) { deviceSpecific = (DeviceSpecific)instance; } else if (instance is MobileControl) { MobileControl mc = (MobileControl)instance; deviceSpecific = mc.DeviceSpecific; } else { // Simply return null if the instance is not recognizable. return(null); } ArrayList returnArray = new ArrayList(); // entry that corresponds to null CurrentChoice. returnArray.Add(SR.GetString(SR.DeviceFilter_NoChoice)); if (null == deviceSpecific) { return(returnArray.ToArray()); } Debug.Assert(deviceSpecific.Choices != null); foreach (DeviceSpecificChoice choice in deviceSpecific.Choices) { // Choice must have a Name if (choice.Filter != null && choice.Filter.Length == 0) { if (!defaultAdded) { returnArray.Add(SR.GetString(SR.DeviceFilter_DefaultChoice)); defaultAdded = true; } } else { if (!choice.Filter.Equals(SR.GetString(SR.DeviceFilter_NoChoice))) { returnArray.Add(DesignerUtility.ChoiceToUniqueIdentifier(choice)); } } } returnArray.Sort(); return(returnArray.ToArray()); }
/// <summary> /// Adds inherited components to the <see cref="InheritanceService"/>. /// </summary> protected virtual void AddInheritedComponents(Type type, IComponent component, IContainer container) { // We get out now if this component type is not assignable from IComponent. We only walk down to the component level. if (type is null || !typeof(IComponent).IsAssignableFrom(type)) { return; } Debug.WriteLineIf(s_inheritanceServiceSwitch.TraceVerbose, "Searching for inherited components on '" + type.FullName + "'."); Debug.Indent(); ISite site = component.Site; IComponentChangeService cs = null; INameCreationService ncs = null; if (site is not null) { ncs = (INameCreationService)site.GetService(typeof(INameCreationService)); cs = (IComponentChangeService)site.GetService(typeof(IComponentChangeService)); if (cs is not null) { cs.ComponentAdding += new ComponentEventHandler(OnComponentAdding); } } try { while (type != typeof(object)) { Type reflect = TypeDescriptor.GetReflectionType(type); FieldInfo[] fields = reflect.GetFields(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic); Debug.WriteLineIf(s_inheritanceServiceSwitch.TraceVerbose, "...found " + fields.Length.ToString(CultureInfo.InvariantCulture) + " fields."); for (int i = 0; i < fields.Length; i++) { FieldInfo field = fields[i]; string name = field.Name; // Get out now if this field is not assignable from IComponent. Type reflectionType = GetReflectionTypeFromTypeHelper(field.FieldType); if (!GetReflectionTypeFromTypeHelper(typeof(IComponent)).IsAssignableFrom(reflectionType)) { Debug.WriteLineIf(s_inheritanceServiceSwitch.TraceVerbose, "...skipping " + name + ": Not IComponent"); continue; } // Now check the attributes of the field and get out if it isn't something that can be inherited. Debug.Assert(!field.IsStatic, "Instance binding shouldn't have found this field"); // If the value of the field is null, then don't mess with it. If it wasn't assigned when our base class was created then we can't really use it. object value = field.GetValue(component); if (value is null) { Debug.WriteLineIf(s_inheritanceServiceSwitch.TraceVerbose, "...skipping " + name + ": Contains NULL"); continue; } // We've been fine up to this point looking at the field. Now, however, we must check to see if this field has an AccessedThroughPropertyAttribute on it. If it does, then we must look for the property and use its name and visibility for the remainder of the scan. Should any of this bail we just use the field. MemberInfo member = field; object[] fieldAttrs = field.GetCustomAttributes(typeof(AccessedThroughPropertyAttribute), false); if (fieldAttrs is not null && fieldAttrs.Length > 0) { Debug.Assert(fieldAttrs.Length == 1, "Non-inheritable attribute has more than one copy"); Debug.Assert(fieldAttrs[0] is AccessedThroughPropertyAttribute, "Reflection bug: GetCustomAttributes(type) didn't discriminate by type"); AccessedThroughPropertyAttribute propAttr = (AccessedThroughPropertyAttribute)fieldAttrs[0]; PropertyInfo fieldProp = reflect.GetProperty(propAttr.PropertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); Debug.Assert(fieldProp is not null, "Field declared with AccessedThroughPropertyAttribute has no associated property"); Debug.Assert(fieldProp.PropertyType == field.FieldType, "Field declared with AccessedThroughPropertyAttribute is associated with a property with a different return type."); if (fieldProp is not null && fieldProp.PropertyType == field.FieldType) { // If the property cannot be read, it is useless to us. if (!fieldProp.CanRead) { continue; } // We never access the set for the property, so we can concentrate on just the get method. member = fieldProp.GetGetMethod(true); Debug.Assert(member is not null, "GetGetMethod for property didn't return a method, but CanRead is true"); name = propAttr.PropertyName; } } // Add a user hook to add or remove members. The default hook here ignores all inherited private members. bool ignoreMember = IgnoreInheritedMember(member, component); // We now have an inherited member. Gather some information about it and then add it to our list. We must always add to our list, but we may not want to add it to the container. That is up to the IgnoreInheritedMember method. We add here because there are components in the world that, when sited, add their children to the container too. That's fine, but we want to make sure we account for them in the inheritance service too. Debug.WriteLineIf(s_inheritanceServiceSwitch.TraceVerbose, "...found inherited member '" + name + "'"); Debug.Indent(); Debug.WriteLineIf(s_inheritanceServiceSwitch.TraceVerbose, "Type: " + field.FieldType.FullName); InheritanceAttribute attr; Debug.Assert(value is IComponent, "Value of inherited field is not IComponent. How did this value get into the datatype?"); bool privateInherited = false; if (ignoreMember) { // If we are ignoring this member, then always mark it as private. The designer doesn't want it; we only do this in case some other component adds this guy to the container. privateInherited = true; } else { if (member is FieldInfo fi) { privateInherited = fi.IsPrivate | fi.IsAssembly; } else if (member is MethodInfo mi) { privateInherited = mi.IsPrivate | mi.IsAssembly; } } if (privateInherited) { attr = InheritanceAttribute.InheritedReadOnly; Debug.WriteLineIf(s_inheritanceServiceSwitch.TraceVerbose, "Inheritance: Private"); } else { Debug.WriteLineIf(s_inheritanceServiceSwitch.TraceVerbose, "Inheritance: Public"); attr = InheritanceAttribute.Inherited; } bool notPresent = (_inheritedComponents[value] is null); _inheritedComponents[value] = attr; if (!ignoreMember && notPresent) { Debug.WriteLineIf(s_inheritanceServiceSwitch.TraceVerbose, "Adding " + name + " to container."); try { _addingComponent = (IComponent)value; _addingAttribute = attr; // Lets make sure this is a valid name if (ncs is null || ncs.IsValidName(name)) { try { container.Add((IComponent)value, name); } catch { // We do not always control the base components, and there could be a lot of rogue base components. If there are exceptions when adding them, lets just ignore and continue. } } } finally { _addingComponent = null; _addingAttribute = null; } } Debug.Unindent(); } type = type.BaseType; } } finally { if (cs is not null) { cs.ComponentAdding -= new ComponentEventHandler(OnComponentAdding); } Debug.Unindent(); } }
public override void SetValue(object component, object value) { if (component != null) { ISite site = GetSite(component); IComponentChangeService changeService = null; if (site != null) { changeService = (IComponentChangeService)site.GetService(typeof(IComponentChangeService)); } // Raise the OnComponentChanging event changeService.OnComponentChanging(component, this); // Save the old value object oldValue = GetValue(component); try { WorkflowParameterBindingCollection parameters = GetParameters(component); if (parameters != null) { if (value == null) { // Remove the binding from the ParameterBindings collection parameters.Remove(this.Name); } else { // Add the binding to the ParameterBindings collection WorkflowParameterBinding binding = null; if (parameters.Contains(this.Name)) { binding = parameters[this.Name]; } else { binding = new WorkflowParameterBinding(this.Name); parameters.Add(binding); } // Set the binding value on the ParameterBindings collection correspondent binding item if (value is ActivityBind) { binding.SetBinding(WorkflowParameterBinding.ValueProperty, value as ActivityBind); } else { binding.SetValue(WorkflowParameterBinding.ValueProperty, value); } } } // Raise the OnValueChanged event OnValueChanged(component, EventArgs.Empty); } catch (Exception) { value = oldValue; throw; } finally { if (changeService != null) { // Raise the OnComponentChanged event changeService.OnComponentChanged(component, this, oldValue, value); } } } }
internal static void CheckConfiguration(ISite site) { if (site == null) { return; } IWebApplication app = (IWebApplication)site.GetService(typeof(IWebApplication)); if (app == null) { return; } Configuration config = app.OpenWebConfiguration(false); HttpHandlersSection handlers = (HttpHandlersSection)config.GetSection("system.web/httpHandlers"); // Does the httpHandlers Secton already exist? if (handlers == null) { // If not, add it... handlers = new HttpHandlersSection(); ConfigurationSectionGroup group = config.GetSectionGroup("system.web"); // Does the system.web Section already exist? if (group == null) { // If not, add it... config.SectionGroups.Add("system.web", new ConfigurationSectionGroup()); group = config.GetSectionGroup("system.web"); } if (group != null) { group.Sections.Add("httpHandlers", handlers); } } HttpHandlerAction action = new HttpHandlerAction("*/ext.axd", "Ext.Net.ResourceHandler", "*", false); // Does the ResourceHandler already exist? if (handlers.Handlers.IndexOf(action) < 0) { // If not, add it... handlers.Handlers.Add(action); config.Save(); } HttpModulesSection modules = (HttpModulesSection)config.GetSection("system.web/httpModules"); // Does the httpModules Secton already exist? if (modules == null) { // If not, add it... modules = new HttpModulesSection(); ConfigurationSectionGroup group = config.GetSectionGroup("system.web"); // Does the system.web Section already exist? if (group == null) { // If not, add it... config.SectionGroups.Add("system.web", new ConfigurationSectionGroup()); group = config.GetSectionGroup("system.web"); } if (group != null) { group.Sections.Add("httpModules", modules); } } //<add name="DirectRequestModule" type="Ext.Net.DirectRequestModule, Ext.Net" /> HttpModuleAction action2 = new HttpModuleAction("DirectRequestModule", "Ext.Net.DirectRequestModule, Ext.Net"); // Does the ResourceHandler already exist? if (modules.Modules.IndexOf(action2) < 0) { // If not, add it... modules.Modules.Add(action2); config.Save(); } }
/// <devdoc> /// <para>Gets the implementer of the <see cref='System.IServiceProvider'/>.</para> /// </devdoc> public virtual object GetService(Type service) { return((site == null)? null : site.GetService(service)); }
/// <summary> /// This will remove the delegate value from the event chain so that /// it no longer gets events from this component. /// </summary> public override void RemoveEventHandler(object component, Delegate value) { FillMethods(); if (component != null) { ISite site = GetSite(component); #if FEATURE_ICOMPONENTCHANGESERVICE IComponentChangeService changeService = null; // Announce that we are about to change this component // if (site != null) { changeService = (IComponentChangeService)site.GetService(typeof(IComponentChangeService)); } if (changeService != null) { #if FEATURE_CHECKOUTEXCEPTION try { changeService.OnComponentChanging(component, this); } catch (CheckoutException coEx) { if (coEx == CheckoutException.Canceled) { return; } throw coEx; } #else changeService.OnComponentChanging(component, this); #endif // FEATURE_CHECKOUTEXCEPTION } #endif // FEATURE_ICOMPONENTCHANGESERVICE bool shadowed = false; if (site != null && site.DesignMode) { IDictionaryService dict = (IDictionaryService)site.GetService(typeof(IDictionaryService)); if (dict != null) { Delegate del = (Delegate)dict.GetValue(this); del = Delegate.Remove(del, value); dict.SetValue(this, del); shadowed = true; } } if (!shadowed) { _removeMethod.Invoke(component, new[] { value }); } #if FEATURE_ICOMPONENTCHANGESERVICE // Now notify the change service that the change was successful. // if (changeService != null) { changeService.OnComponentChanged(component, this, null, value); } #endif } }
/// <include file='doc\GlobalDataBindingHandler.uex' path='docs/doc[@for="GlobalDataBindingHandler.OnDataBind"]/*' /> /// <devdoc> /// </devdoc> public static void OnDataBind(object sender, EventArgs e) { Debug.Assert(sender is Control, "DataBindings can only be present on Controls."); Control control = (Control)sender; // check if this control has any data-bindings IDataBindingsAccessor dataBindingsAccessor = (IDataBindingsAccessor)sender; if (dataBindingsAccessor.HasDataBindings == false) { return; } // check if the control type has an associated data-binding handler DataBindingHandlerAttribute handlerAttribute = (DataBindingHandlerAttribute)TypeDescriptor.GetAttributes(sender)[typeof(DataBindingHandlerAttribute)]; if ((handlerAttribute == null) || (handlerAttribute.HandlerTypeName.Length == 0)) { return; } // components in the designer/container do not get handled here; the // designer for that control handles it in its own special way ISite site = control.Site; IDesignerHost designerHost = null; if (site == null) { Page page = control.Page; if (page != null) { site = page.Site; } else { // When the designer is working on a UserControl instead of a Page Control parent = control.Parent; // We shouldn't have to walk up the parent chain a whole lot - maybe a couple // of levels on the average while ((site == null) && (parent != null)) { if (parent.Site != null) { site = parent.Site; } parent = parent.Parent; } } } if (site != null) { designerHost = (IDesignerHost)site.GetService(typeof(IDesignerHost)); } if (designerHost == null) { Debug.Fail("Did not get back an IDesignerHost"); return; } // non-top level components, such as controls within templates do not have designers // these are the only things that need the data-binding handler stuff IDesigner designer = designerHost.GetDesigner(control); if (designer != null) { return; } // get the handler and cache it the first time around DataBindingHandler dataBindingHandler = null; try { string handlerTypeName = handlerAttribute.HandlerTypeName; dataBindingHandler = (DataBindingHandler)DataBindingHandlerTable[handlerTypeName]; if (dataBindingHandler == null) { Type handlerType = Type.GetType(handlerTypeName); if (handlerType != null) { dataBindingHandler = (DataBindingHandler)Activator.CreateInstance(handlerType, BindingFlags.Instance | BindingFlags.Public | BindingFlags.CreateInstance, null, null, null); DataBindingHandlerTable[handlerTypeName] = dataBindingHandler; } } } catch (Exception ex) { Debug.Fail(ex.ToString()); return; } // finally delegate to it to handle this particular control if (dataBindingHandler != null) { dataBindingHandler.DataBindControl(designerHost, control); } }
/// <devdoc> /// Retrieves the set of extender providers providing services for the given component. /// </devdoc> private IExtenderProvider[] GetExtenderProviders(ISite site) { // See if this component's site has an IExtenderListService. If it // does, we get our list of extenders from that, not from the container. // IExtenderListService listService = (IExtenderListService)site.GetService(typeof(IExtenderListService)); if (listService != null) { return listService.GetExtenderProviders(); } else { ComponentCollection comps = site.Container.Components; ArrayList exList = null; foreach(IComponent comp in comps) { if (comp is IExtenderProvider) { if (exList == null) { exList = new ArrayList(2); } exList.Add(comp); } } if (exList == null) { return null; } else { IExtenderProvider[] temp = new IExtenderProvider[exList.Count]; exList.CopyTo(temp, 0); return temp; } } }
public static object GetService(Control control, Type service) { ISite site = GetSite(control); return(site == null ? null : site.GetService(service)); }
/// <include file='doc\Component.uex' path='docs/doc[@for="Component.GetService"]/*' /> /// <devdoc> /// <para> /// Returns an object representing a service provided by /// the <see cref='System.ComponentModel.Component'/> /// . /// </para> /// </devdoc> protected virtual object GetService(Type service) { ISite s = site; return((s == null) ? null : s.GetService(service)); }
HRESULT IPropertyNotifySink.OnChanged(DispatchID dispid) { // Some controls fire OnChanged() notifications when getting values of some properties. // To prevent this kind of recursion, we check to see if we are already inside a OnChanged() call. if (host.NoComponentChangeEvents != 0) { return(HRESULT.S_OK); } host.NoComponentChangeEvents++; try { AxPropertyDescriptor prop = null; Debug.WriteLineIf(AxHTraceSwitch.TraceVerbose, "in OnChanged"); if (dispid != DispatchID.UNKNOWN) { prop = host.GetPropertyDescriptorFromDispid(dispid); if (prop != null) { prop.OnValueChanged(host); if (!prop.SettingValue) { prop.UpdateTypeConverterAndTypeEditor(true); } } } else { // update them all for DISPID_UNKNOWN. PropertyDescriptorCollection props = ((ICustomTypeDescriptor)host).GetProperties(); foreach (PropertyDescriptor p in props) { prop = p as AxPropertyDescriptor; if (prop != null && !prop.SettingValue) { prop.UpdateTypeConverterAndTypeEditor(true); } } } ISite site = host.Site; if (site != null) { IComponentChangeService changeService = (IComponentChangeService)site.GetService(typeof(IComponentChangeService)); if (changeService != null) { try { changeService.OnComponentChanging(host, prop); } catch (CheckoutException coEx) { if (coEx == CheckoutException.Canceled) { return(HRESULT.S_OK); } throw; } // Now notify the change service that the change was successful. // changeService.OnComponentChanged(host, prop, null, (prop?.GetValue(host))); } } } catch (Exception t) { Debug.Fail(t.ToString()); throw; } finally { host.NoComponentChangeEvents--; } return(HRESULT.S_OK); }
/// This will set value to be the new value of this property on the /// component by invoking the setXXX method on the component. If the /// value specified is invalid, the component should throw an exception /// which will be passed up. The component designer should design the /// property so that getXXX following a setXXX should return the value /// passed in if no exception was thrown in the setXXX call. public override void SetValue(object component, object value) { // Argument, state checking. Is it ok to set this event? // if (IsReadOnly) { Exception ex = new InvalidOperationException("Tried to set a read only event."); throw ex; } if (value != null && !(value is string)) { Exception ex = new ArgumentException("Cannot set to value " + value.ToString() + "."); throw ex; } string name = (string)value; if (name != null && name.Length == 0) { name = null; } // Obtain the site for the component. Note that this can be a site // to a parent component if we can get to the reference service. // ISite site = null; if (component is IComponent) { site = ((IComponent)component).Site; } if (site == null) { IReferenceService rs = _eventSvc._provider.GetService(typeof(IReferenceService)) as IReferenceService; if (rs != null) { IComponent baseComponent = rs.GetComponent(component); if (baseComponent != null) { site = baseComponent.Site; } } } if (site == null) { Exception ex = new InvalidOperationException("There is no site for component " + component.ToString() + "."); throw ex; } // The dictionary service is where we store the actual event method name. // IDictionaryService ds = (IDictionaryService)site.GetService(typeof(IDictionaryService)); if (ds == null) { Exception ex = new InvalidOperationException("Cannot find IDictionaryService"); throw ex; } // Get the old method name, ensure that they are different, and then continue. // ReferenceEventClosure key = new ReferenceEventClosure(component, this); string oldName = (string)ds.GetValue(key); if (object.ReferenceEquals(oldName, name)) { return; } if (oldName != null && name != null && oldName.Equals(name)) { return; } // Before we continue our work, ensure that the name is // actually valid. // if (name != null) { _eventSvc.ValidateMethodName(name); } // Ok, the names are different. Fire a changing event to make // sure it's OK to perform the change. // IComponentChangeService change = (IComponentChangeService)site.GetService(typeof(IComponentChangeService)); if (change != null) { try { change.OnComponentChanging(component, this); } catch (CheckoutException coEx) { if (coEx == CheckoutException.Canceled) { return; } throw; } } // Less chance of success of adding a new method name, so // don't release the old name until we verify that adding // the new one actually succeeded. // if (name != null) { _eventSvc.UseMethod(component, _eventDesc, name); } if (oldName != null) { _eventSvc.FreeMethod(component, _eventDesc, oldName); } ds.SetValue(key, name); if (change != null) { change.OnComponentChanged(component, this, oldName, name); } OnValueChanged(component, EventArgs.Empty); }
/// <summary> /// This will set value to be the new value of this property on the /// component by invoking the setXXX method on the component. If the /// value specified is invalid, the component should throw an exception /// which will be passed up. The component designer should design the /// property so that getXXX following a setXXX should return the value /// passed in if no exception was thrown in the setXXX call. /// </summary> public override void SetValue(object component, object value) { // Argument, state checking. Is it ok to set this event? if (IsReadOnly) { Exception ex = new InvalidOperationException(string.Format(SR.EventBindingServiceEventReadOnly, Name)); ex.HelpLink = SR.EventBindingServiceEventReadOnly; throw ex; } if (value != null && !(value is string)) { Exception ex = new ArgumentException(string.Format(SR.EventBindingServiceBadArgType, Name, typeof(string).Name)); ex.HelpLink = SR.EventBindingServiceBadArgType; throw ex; } string name = (string)value; if (name != null && name.Length == 0) { name = null; } // Obtain the site for the component. Note that this can be a site // to a parent component if we can get to the reference service. ISite site = null; if (component is IComponent) { site = ((IComponent)component).Site; } if (site is null && (_eventSvc._provider.GetService(typeof(IReferenceService)) is IReferenceService rs)) { IComponent baseComponent = rs.GetComponent(component); if (baseComponent != null) { site = baseComponent.Site; } } if (site is null) { Exception ex = new InvalidOperationException(SR.EventBindingServiceNoSite); ex.HelpLink = SR.EventBindingServiceNoSite; throw ex; } // The dictionary service is where we store the actual event method name. if (!(site.GetService(typeof(IDictionaryService)) is IDictionaryService ds)) { Exception ex = new InvalidOperationException(string.Format(SR.EventBindingServiceMissingService, typeof(IDictionaryService).Name)); ex.HelpLink = SR.EventBindingServiceMissingService; throw ex; } // Get the old method name, ensure that they are different, and then continue. ReferenceEventClosure key = new ReferenceEventClosure(component, this); string oldName = (string)ds.GetValue(key); if (object.ReferenceEquals(oldName, name)) { return; } if (oldName != null && name != null && oldName.Equals(name)) { return; } // Before we continue our work, ensure that the name is actually valid. if (name != null) { _eventSvc.ValidateMethodName(name); } // If there is a designer host, create a transaction so there is a // nice name for this change. We don't want a name like // "Change property 'Click', because to users, this isn't a property. DesignerTransaction trans = null; if (site.GetService(typeof(IDesignerHost)) is IDesignerHost host) { trans = host.CreateTransaction(string.Format(SR.EventBindingServiceSetValue, site.Name, name)); } try { // Ok, the names are different. Fire a changing event to make // sure it's OK to perform the change. IComponentChangeService change = site.GetService(typeof(IComponentChangeService)) as IComponentChangeService; if (change != null) { try { change.OnComponentChanging(component, this); change.OnComponentChanging(component, Event); } catch (CheckoutException coEx) { if (coEx == CheckoutException.Canceled) { return; } throw; } } // Less chance of success of adding a new method name, so // don't release the old name until we verify that adding // the new one actually succeeded. if (name != null) { _eventSvc.UseMethod((IComponent)component, Event, name); } if (oldName != null) { _eventSvc.FreeMethod((IComponent)component, Event, oldName); } ds.SetValue(key, name); if (change != null) { change.OnComponentChanged(component, Event, null, null); change.OnComponentChanged(component, this, oldName, name); } OnValueChanged(component, EventArgs.Empty); if (trans != null) { trans.Commit(); } } finally { if (trans != null) { ((IDisposable)trans).Dispose(); } } }
public StringCollection GetStandardValues(Component component) { StringCollection fields = new StringCollection(); if (component != null) { ISite site1 = component.Site; if (site1 != null) { IDesignerHost host1 = (IDesignerHost)site1.GetService(typeof(IDesignerHost)); if (host1 != null) { IDesigner designer1 = host1.GetDesigner(component); DesignerDataSourceView view1 = ((DataBoundControlDesigner)designer1).DesignerView; if (view1 != null) { IDataSourceViewSchema schema1 = null; try { schema1 = view1.Schema; } catch (Exception exception1) { IComponentDesignerDebugService service1 = (IComponentDesignerDebugService)site1.GetService(typeof(IComponentDesignerDebugService)); if (service1 != null) { service1.Fail("DataSource DebugService FailedCall\r\n" + exception1.ToString()); } } if (schema1 != null) { IDataSourceFieldSchema[] schemaArray1 = schema1.GetFields(); if (schemaArray1 != null) { for (int num1 = 0; num1 < schemaArray1.Length; num1++) { fields.Add(schemaArray1[num1].Name); } } } } if (((fields.Count == 0) && (designer1 != null)) && (designer1 is IDataSourceProvider)) { IDataSourceProvider provider1 = designer1 as IDataSourceProvider; IEnumerable enumerable1 = null; if (provider1 != null) { enumerable1 = provider1.GetResolvedSelectedDataSource(); } if (enumerable1 != null) { PropertyDescriptorCollection collection1 = DesignTimeData.GetDataFields(enumerable1); if (collection1 != null) { foreach (PropertyDescriptor descriptor1 in collection1) { fields.Add(descriptor1.Name); } } } } } } } return(fields); }