private void GenerateMembers() { IMemberCreationService memeberCreationService = workflowControl.GetService(typeof(IMemberCreationService)) as IMemberCreationService; memeberCreationService.CreateProperty(WorkflowTypeFactory.GetWorkflowClassFullName(Workflow), "Session", sessionType, null, false, false, false, null, true); memeberCreationService.CreateProperty(WorkflowTypeFactory.GetWorkflowClassFullName(Workflow), "Request", requestType, null, false, false, false, null, true); }
private void OnViewCode(object sender, EventArgs e) { IDesignerHost host = this.serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost; IComponent component = (host != null) ? host.RootComponent : null; if (component != null) { IMemberCreationService service = component.Site.GetService(typeof(IMemberCreationService)) as IMemberCreationService; if (service != null) { service.ShowCode(); } } }
private static void RemoveDeletedProperties(List <CustomProperty> propCollection, Type customActivityType, IServiceProvider serviceProvider) { // IMemberCreationService memberCreationService = serviceProvider.GetService(typeof(IMemberCreationService)) as IMemberCreationService; if (memberCreationService == null) { throw new Exception(SR.GetString(SR.General_MissingService, typeof(IMemberCreationService).FullName)); } PropertyInfo[] properties = customActivityType.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance); foreach (PropertyInfo property in properties) { bool found = false; foreach (CustomProperty customProperty in propCollection) { if (property.Name == customProperty.oldPropertyName && property.PropertyType.FullName == customProperty.oldPropertyType) { found = true; break; } } if (!found) { memberCreationService.RemoveProperty(customActivityType.FullName, property.Name, property.PropertyType); } } EventInfo[] events = customActivityType.GetEvents(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance); foreach (EventInfo evtInfo in events) { bool found = false; foreach (CustomProperty customProperty in propCollection) { if (evtInfo.Name == customProperty.oldPropertyName && evtInfo.EventHandlerType.FullName == customProperty.oldPropertyType) { found = true; break; } } if (!found && evtInfo.Name != null && evtInfo.EventHandlerType != null) { memberCreationService.RemoveEvent(customActivityType.FullName, evtInfo.Name, evtInfo.EventHandlerType); } } }
public override void SetValue(object component, object value) { Activity activity = component as Activity; if (activity != null) { IIdentifierCreationService service = activity.Site.GetService(typeof(IIdentifierCreationService)) as IIdentifierCreationService; if (service == null) { throw new Exception(SR.GetString("General_MissingService", new object[] { typeof(IIdentifierCreationService).FullName })); } string identifier = value as string; service.ValidateIdentifier(activity, identifier); bool ignoreCase = CompilerHelpers.GetSupportedLanguage(activity.Site) == SupportedLanguages.VB; Type dataSourceClass = Helpers.GetDataSourceClass(Helpers.GetRootActivity(activity), activity.Site); if ((dataSourceClass != null) && (ActivityBindPropertyDescriptor.FindMatchingMember(identifier, dataSourceClass, ignoreCase) != null)) { throw new ArgumentException(SR.GetString("Error_ActivityNameExist", new object[] { identifier })); } IMemberCreationService service2 = activity.Site.GetService(typeof(IMemberCreationService)) as IMemberCreationService; if (service2 == null) { throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(IMemberCreationService).FullName })); } IDesignerHost host = activity.Site.GetService(typeof(IDesignerHost)) as IDesignerHost; if (host == null) { throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(IDesignerHost).FullName })); } string newClassName = identifier; int num = host.RootComponentClassName.LastIndexOf('.'); if (num > 0) { newClassName = host.RootComponentClassName.Substring(0, num + 1) + identifier; } service2.UpdateTypeName(((Activity)host.RootComponent).GetValue(WorkflowMarkupSerializer.XClassProperty) as string, newClassName); ((Activity)host.RootComponent).SetValue(WorkflowMarkupSerializer.XClassProperty, newClassName); base.SetValue(component, value); DesignerHelpers.UpdateSiteName((Activity)host.RootComponent, identifier); } }
private static void RemoveDeletedProperties(List <CustomProperty> propCollection, System.Type customActivityType, IServiceProvider serviceProvider) { IMemberCreationService service = serviceProvider.GetService(typeof(IMemberCreationService)) as IMemberCreationService; if (service == null) { throw new Exception(SR.GetString("General_MissingService", new object[] { typeof(IMemberCreationService).FullName })); } foreach (PropertyInfo info in customActivityType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)) { bool flag = false; foreach (CustomProperty property in propCollection) { if ((info.Name == property.oldPropertyName) && (info.PropertyType.FullName == property.oldPropertyType)) { flag = true; break; } } if (!flag) { service.RemoveProperty(customActivityType.FullName, info.Name, info.PropertyType); } } foreach (EventInfo info2 in customActivityType.GetEvents(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)) { bool flag2 = false; foreach (CustomProperty property2 in propCollection) { if ((info2.Name == property2.oldPropertyName) && (info2.EventHandlerType.FullName == property2.oldPropertyType)) { flag2 = true; break; } } if ((!flag2 && (info2.Name != null)) && (info2.EventHandlerType != null)) { service.RemoveEvent(customActivityType.FullName, info2.Name, info2.EventHandlerType); } } }
internal static bool CreateField(ITypeDescriptorContext context, ActivityBind activityBind, bool throwOnError) { if (!string.IsNullOrEmpty(activityBind.Path)) { Type toType = PropertyDescriptorUtils.GetBaseType(context.PropertyDescriptor, context.Instance, context); Activity component = PropertyDescriptorUtils.GetComponent(context) as Activity; if ((component != null) && (toType != null)) { component = Helpers.ParseActivityForBind(component, activityBind.Name); if (component == Helpers.GetRootActivity(component)) { bool ignoreCase = CompilerHelpers.GetSupportedLanguage(context) == SupportedLanguages.VB; Type dataSourceClass = Helpers.GetDataSourceClass(component, context); if (dataSourceClass != null) { string path = activityBind.Path; int length = path.IndexOfAny(new char[] { '.', '/', '[' }); if (length != -1) { path = path.Substring(0, length); } MemberInfo info = FindMatchingMember(path, dataSourceClass, ignoreCase); if (info != null) { Type fromType = null; bool isPrivate = false; if (info is FieldInfo) { isPrivate = ((FieldInfo) info).IsPrivate; fromType = ((FieldInfo) info).FieldType; } else if (info is PropertyInfo) { MethodInfo getMethod = ((PropertyInfo) info).GetGetMethod(); MethodInfo setMethod = ((PropertyInfo) info).GetSetMethod(); isPrivate = ((getMethod != null) && getMethod.IsPrivate) || ((setMethod != null) && setMethod.IsPrivate); } else if (info is MethodInfo) { isPrivate = ((MethodInfo) info).IsPrivate; } if (length != -1) { PathWalker walker = new PathWalker(); PathMemberInfoEventArgs finalEventArgs = null; walker.MemberFound = (EventHandler<PathMemberInfoEventArgs>) Delegate.Combine(walker.MemberFound, delegate (object sender, PathMemberInfoEventArgs eventArgs) { finalEventArgs = eventArgs; }); if (!walker.TryWalkPropertyPath(dataSourceClass, activityBind.Path)) { if (throwOnError) { throw new InvalidOperationException(SR.GetString("Error_MemberWithSameNameExists", new object[] { activityBind.Path, dataSourceClass.FullName })); } return false; } fromType = BindHelpers.GetMemberType(finalEventArgs.MemberInfo); } if (((info.DeclaringType == dataSourceClass) || !isPrivate) && ((info is FieldInfo) && TypeProvider.IsAssignable(toType, fromType))) { return true; } if (throwOnError) { throw new InvalidOperationException(SR.GetString("Error_MemberWithSameNameExists", new object[] { activityBind.Path, dataSourceClass.FullName })); } return false; } Activity activity2 = null; if (string.Compare(component.Name, path, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) == 0) { activity2 = component; } else if ((component is CompositeActivity) && (component is CompositeActivity)) { foreach (Activity activity3 in Helpers.GetAllNestedActivities(component as CompositeActivity)) { if (string.Compare(activity3.Name, path, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) == 0) { activity2 = activity3; } } } if (activity2 != null) { if (TypeProvider.IsAssignable(toType, activity2.GetType())) { return true; } if (throwOnError) { throw new InvalidOperationException(SR.GetString("Error_MemberWithSameNameExists", new object[] { activityBind.Path, dataSourceClass.FullName })); } return false; } IMemberCreationService service = context.GetService(typeof(IMemberCreationService)) as IMemberCreationService; if (service != null) { IDesignerHost host = context.GetService(typeof(IDesignerHost)) as IDesignerHost; if (host != null) { service.CreateField(host.RootComponentClassName, activityBind.Path, toType, null, MemberAttributes.Public, null, false); return true; } if (throwOnError) { throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(IDesignerHost).FullName })); } } else if (throwOnError) { throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(IMemberCreationService).FullName })); } } } } else { if ((component == null) && throwOnError) { throw new InvalidOperationException(SR.GetString("Error_InvalidActivityIdentifier", new object[] { activityBind.Name })); } if ((toType == null) && throwOnError) { throw new InvalidOperationException(SR.GetString("Error_PropertyTypeNotDefined", new object[] { context.PropertyDescriptor.Name, typeof(ActivityBind).Name, typeof(IDynamicPropertyTypeProvider).Name })); } } } return false; }
internal WorkflowDesignSurface(IMemberCreationService memberCreationService) { this.ServiceContainer.AddService(typeof(ITypeProvider), new TypeProvider(this.ServiceContainer), true); this.ServiceContainer.AddService(typeof(IMemberCreationService), memberCreationService); this.ServiceContainer.AddService(typeof(IMenuCommandService), new MenuCommandService(this.ServiceContainer)); }
private static void AddNewProperties(List <CustomProperty> propCollection, Type customActivityType, IServiceProvider serviceProvider, List <CustomProperty> existingProps) { IMemberCreationService memberCreationService = serviceProvider.GetService(typeof(IMemberCreationService)) as IMemberCreationService; if (memberCreationService == null) { throw new Exception(SR.GetString(SR.General_MissingService, typeof(IMemberCreationService).FullName)); } ITypeProvider typeProvider = serviceProvider.GetService(typeof(ITypeProvider)) as ITypeProvider; if (typeProvider == null) { throw new Exception(SR.GetString(SR.General_MissingService, typeof(ITypeProvider).FullName)); } try { // foreach (CustomProperty property in propCollection) { bool createNew = (property.oldPropertyName == null || property.oldPropertyType == null); if (!createNew) { if (!property.IsEvent) { createNew = (customActivityType.GetProperty(property.oldPropertyName, typeProvider.GetType(property.oldPropertyType)) == null); } else { createNew = (customActivityType.GetEvent(property.oldPropertyName) == null); } } if (createNew) { AttributeInfo[] attributes = CreateCustomPropertyAttributeArray(property, serviceProvider); if (property.IsEvent) { memberCreationService.CreateEvent(customActivityType.FullName, property.Name, typeProvider.GetType(property.Type), attributes, property.GenerateDependencyProperty); } else { memberCreationService.CreateProperty(customActivityType.FullName, property.Name, typeProvider.GetType(property.Type), attributes, property.GenerateDependencyProperty, false, false, null, false); } } else { // CustomProperty oldProperty = null; foreach (CustomProperty existingProperty in existingProps) { if (existingProperty.Name == property.oldPropertyName && existingProperty.Type == property.oldPropertyType) { oldProperty = existingProperty; } } if (oldProperty == null || ArePropertiesDifferent(property, oldProperty)) { AttributeInfo[] attributes = CreateCustomPropertyAttributeArray(property, serviceProvider); AttributeInfo[] oldAttributes = CreateCustomPropertyAttributeArray(oldProperty, serviceProvider); Type propertyType = typeProvider.GetType(property.Type, false); Type oldPropertyType = typeProvider.GetType(property.oldPropertyType, false); if (propertyType != null) { if (property.IsEvent) { memberCreationService.UpdateEvent(customActivityType.FullName, property.oldPropertyName, oldPropertyType, property.Name, propertyType, attributes, property.GenerateDependencyProperty, false); } else { memberCreationService.UpdateProperty(customActivityType.FullName, property.oldPropertyName, oldPropertyType, property.Name, propertyType, attributes, property.GenerateDependencyProperty, false); } } } } } } finally { // } }
public static void SetBaseTypeName(string typeName, IServiceProvider serviceProvider) { if (string.IsNullOrEmpty(typeName)) { throw new ArgumentNullException("typeName"); } IDesignerHost host = serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost; if (host == null) { throw new InvalidOperationException(SR.GetString(SR.General_MissingService, typeof(IDesignerHost).FullName)); } IMemberCreationService memberCreationService = serviceProvider.GetService(typeof(IMemberCreationService)) as IMemberCreationService; if (memberCreationService == null) { throw new InvalidOperationException(SR.GetString("General_MissingService", typeof(IMemberCreationService).FullName)); } // Validate the base type (this will throw an exception if the type name isn't valid Type newBaseType = ValidateBaseType(typeName, serviceProvider); //Warn the user of the change Type oldBaseType = host.RootComponent.GetType(); if (oldBaseType == newBaseType) { return; } // If we're switch to a base type that is not derived from CompositeActivity, make sure // we dont's support events or exceptions if (!TypeProvider.IsAssignable(typeof(CompositeActivity), newBaseType)) { PropertyDescriptor supportsEventsPropDesc = TypeDescriptor.GetProperties(host.RootComponent)["SupportsEvents"]; if (supportsEventsPropDesc != null && ((bool)supportsEventsPropDesc.GetValue(host.RootComponent)) == true) { supportsEventsPropDesc.SetValue(host.RootComponent, false); } PropertyDescriptor supportsExceptionsPropDesc = TypeDescriptor.GetProperties(host.RootComponent)["SupportsExceptions"]; if (supportsExceptionsPropDesc != null && ((bool)supportsExceptionsPropDesc.GetValue(host.RootComponent)) == true) { supportsExceptionsPropDesc.SetValue(host.RootComponent, false); } } PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(host.RootComponent); if (host.RootComponent is CompositeActivity && ((CompositeActivity)host.RootComponent).Activities.Count > 0) { // Warn user first if there are any children that can not be re-parented to the new root. IUIService uiService = serviceProvider.GetService(typeof(IUIService)) as IUIService; if (uiService != null) { if (DialogResult.OK != uiService.ShowMessage(SR.GetString(SR.NoChildActivities_Message), SR.GetString(SR.NoChildActivities_Caption), MessageBoxButtons.OKCancel)) { return; } } // Remove the children first. This would cause the component removed event to be fired, // thus remove the generated field from the designer.cs file. List <Activity> activitiesToRemove = new List <Activity>(((CompositeActivity)host.RootComponent).Activities); CompositeActivityDesigner rootDesigner = host.GetDesigner(host.RootComponent) as CompositeActivityDesigner; if (rootDesigner != null) { rootDesigner.RemoveActivities(activitiesToRemove.AsReadOnly()); } } //Also, clear all properties of original base. That will allow undo to set old values back. foreach (PropertyDescriptor propertyDescriptor in properties) { if (!propertyDescriptor.Name.Equals("BaseActivityType", StringComparison.Ordinal) && !propertyDescriptor.Name.Equals("Name", StringComparison.Ordinal) && propertyDescriptor.CanResetValue(host.RootComponent)) { propertyDescriptor.ResetValue(host.RootComponent); } } PropertyDescriptor realBaseActivityTypePropertyDescriptor = properties["BaseActivityType"]; PropertyDescriptor baseActivityTypePropertyDescriptor = TypeDescriptor.CreateProperty(realBaseActivityTypePropertyDescriptor.ComponentType, realBaseActivityTypePropertyDescriptor, DesignerSerializationVisibilityAttribute.Visible); IComponentChangeService changeService = serviceProvider.GetService(typeof(IComponentChangeService)) as IComponentChangeService; if (changeService != null) { changeService.OnComponentChanging(host.RootComponent, baseActivityTypePropertyDescriptor); } ((Activity)host.RootComponent).UserData[UserDataKeys.NewBaseType] = newBaseType; memberCreationService.UpdateBaseType(host.RootComponentClassName, newBaseType); if (changeService != null) { changeService.OnComponentChanged(host.RootComponent, baseActivityTypePropertyDescriptor, baseActivityTypePropertyDescriptor.GetValue(host.RootComponent), typeName); } //Work around: Force update of the host by raising idle.This is to ensure undo events work on updated host. Application.RaiseIdle(new EventArgs()); }
public static void SetBaseTypeName(string typeName, IServiceProvider serviceProvider) { if (string.IsNullOrEmpty(typeName)) { throw new ArgumentNullException("typeName"); } IDesignerHost host = serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost; if (host == null) { throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(IDesignerHost).FullName })); } IMemberCreationService service = serviceProvider.GetService(typeof(IMemberCreationService)) as IMemberCreationService; if (service == null) { throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(IMemberCreationService).FullName })); } System.Type fromType = ValidateBaseType(typeName, serviceProvider); if (host.RootComponent.GetType() != fromType) { if (!TypeProvider.IsAssignable(typeof(CompositeActivity), fromType)) { PropertyDescriptor descriptor = TypeDescriptor.GetProperties(host.RootComponent)["SupportsEvents"]; if ((descriptor != null) && ((bool)descriptor.GetValue(host.RootComponent))) { descriptor.SetValue(host.RootComponent, false); } PropertyDescriptor descriptor2 = TypeDescriptor.GetProperties(host.RootComponent)["SupportsExceptions"]; if ((descriptor2 != null) && ((bool)descriptor2.GetValue(host.RootComponent))) { descriptor2.SetValue(host.RootComponent, false); } } PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(host.RootComponent); if ((host.RootComponent is CompositeActivity) && (((CompositeActivity)host.RootComponent).Activities.Count > 0)) { IUIService service2 = serviceProvider.GetService(typeof(IUIService)) as IUIService; if ((service2 != null) && (DialogResult.OK != service2.ShowMessage(SR.GetString("NoChildActivities_Message"), SR.GetString("NoChildActivities_Caption"), MessageBoxButtons.OKCancel))) { return; } List <Activity> list = new List <Activity>(((CompositeActivity)host.RootComponent).Activities); CompositeActivityDesigner designer = host.GetDesigner(host.RootComponent) as CompositeActivityDesigner; if (designer != null) { designer.RemoveActivities(list.AsReadOnly()); } } foreach (PropertyDescriptor descriptor3 in properties) { if ((!descriptor3.Name.Equals("BaseActivityType", StringComparison.Ordinal) && !descriptor3.Name.Equals("Name", StringComparison.Ordinal)) && descriptor3.CanResetValue(host.RootComponent)) { descriptor3.ResetValue(host.RootComponent); } } PropertyDescriptor oldPropertyDescriptor = properties["BaseActivityType"]; PropertyDescriptor member = TypeDescriptor.CreateProperty(oldPropertyDescriptor.ComponentType, oldPropertyDescriptor, new Attribute[] { DesignerSerializationVisibilityAttribute.Visible }); IComponentChangeService service3 = serviceProvider.GetService(typeof(IComponentChangeService)) as IComponentChangeService; if (service3 != null) { service3.OnComponentChanging(host.RootComponent, member); } ((Activity)host.RootComponent).UserData[UserDataKeys.NewBaseType] = fromType; service.UpdateBaseType(host.RootComponentClassName, fromType); if (service3 != null) { service3.OnComponentChanged(host.RootComponent, member, member.GetValue(host.RootComponent), typeName); } Application.RaiseIdle(new EventArgs()); } }
private static void AddNewProperties(List <CustomProperty> propCollection, System.Type customActivityType, IServiceProvider serviceProvider, List <CustomProperty> existingProps) { IMemberCreationService service = serviceProvider.GetService(typeof(IMemberCreationService)) as IMemberCreationService; if (service == null) { throw new Exception(SR.GetString("General_MissingService", new object[] { typeof(IMemberCreationService).FullName })); } ITypeProvider provider = serviceProvider.GetService(typeof(ITypeProvider)) as ITypeProvider; if (provider == null) { throw new Exception(SR.GetString("General_MissingService", new object[] { typeof(ITypeProvider).FullName })); } foreach (CustomProperty property in propCollection) { bool flag = (property.oldPropertyName == null) || (property.oldPropertyType == null); if (!flag) { if (!property.IsEvent) { flag = customActivityType.GetProperty(property.oldPropertyName, provider.GetType(property.oldPropertyType)) == null; } else { flag = customActivityType.GetEvent(property.oldPropertyName) == null; } } if (flag) { AttributeInfo[] attributes = CreateCustomPropertyAttributeArray(property, serviceProvider); if (property.IsEvent) { service.CreateEvent(customActivityType.FullName, property.Name, provider.GetType(property.Type), attributes, property.GenerateDependencyProperty); } else { service.CreateProperty(customActivityType.FullName, property.Name, provider.GetType(property.Type), attributes, property.GenerateDependencyProperty, false, false, null, false); } } else { CustomProperty oldProperty = null; foreach (CustomProperty property3 in existingProps) { if ((property3.Name == property.oldPropertyName) && (property3.Type == property.oldPropertyType)) { oldProperty = property3; } } if ((oldProperty == null) || ArePropertiesDifferent(property, oldProperty)) { AttributeInfo[] infoArray2 = CreateCustomPropertyAttributeArray(property, serviceProvider); CreateCustomPropertyAttributeArray(oldProperty, serviceProvider); System.Type newEventType = provider.GetType(property.Type, false); System.Type type = provider.GetType(property.oldPropertyType, false); if (newEventType != null) { if (property.IsEvent) { service.UpdateEvent(customActivityType.FullName, property.oldPropertyName, type, property.Name, newEventType, infoArray2, property.GenerateDependencyProperty, false); } else { service.UpdateProperty(customActivityType.FullName, property.oldPropertyName, type, property.Name, newEventType, infoArray2, property.GenerateDependencyProperty, false); } } } } } }
internal WorkflowDesignSurface(IMemberCreationService memberCreationService) { //this.ServiceContainer.AddService(typeof(ITypeProvider), new TypeProvider(this.ServiceContainer), true); this.ServiceContainer.AddService(typeof(IMemberCreationService), memberCreationService); this.ServiceContainer.AddService(typeof(IMenuCommandService), new MenuCommandService(this.ServiceContainer)); }
public override void SetValue(object component, object value) { Activity activity = component as Activity; if (activity != null) { // validate the identifier IIdentifierCreationService identifierCreationService = activity.Site.GetService(typeof(IIdentifierCreationService)) as IIdentifierCreationService; if (identifierCreationService == null) { throw new Exception(SR.GetString(SR.General_MissingService, typeof(IIdentifierCreationService).FullName)); } string name = value as string; identifierCreationService.ValidateIdentifier(activity, name); bool isVB = (CompilerHelpers.GetSupportedLanguage(activity.Site) == SupportedLanguages.VB); Type designedType = Helpers.GetDataSourceClass(Helpers.GetRootActivity(activity), activity.Site); if (designedType != null) { MemberInfo matchingMember = ActivityBindPropertyDescriptor.FindMatchingMember(name, designedType, isVB); if (matchingMember != null) { throw new ArgumentException(SR.GetString(SR.Error_ActivityNameExist, name)); } } IMemberCreationService memberCreationService = activity.Site.GetService(typeof(IMemberCreationService)) as IMemberCreationService; if (memberCreationService == null) { throw new InvalidOperationException(SR.GetString(SR.General_MissingService, typeof(IMemberCreationService).FullName)); } IDesignerHost host = activity.Site.GetService(typeof(IDesignerHost)) as IDesignerHost; if (host == null) { throw new InvalidOperationException(SR.GetString(SR.General_MissingService, typeof(IDesignerHost).FullName)); } // We need to update the activityType's name before trying to update the type because // updating the type causes a flush, which access the custom activity's properties, and // doing so requires the new type name string newClassName = name; int indexOfDot = host.RootComponentClassName.LastIndexOf('.'); if (indexOfDot > 0) { newClassName = host.RootComponentClassName.Substring(0, indexOfDot + 1) + name; } // IMPORTANT: You must update the class name in code before renaming the site, since // VS's OnComponentRename updates the RootComponentClassName, so the flush code called // in our OnComponentRename tries to access the new class for information. memberCreationService.UpdateTypeName(((Activity)host.RootComponent).GetValue(WorkflowMarkupSerializer.XClassProperty) as string, newClassName); //((Activity)host.RootComponent).Name = name; ((Activity)host.RootComponent).SetValue(WorkflowMarkupSerializer.XClassProperty, newClassName); base.SetValue(component, value); // Update the site name so the component name shows up correctly in the designer DesignerHelpers.UpdateSiteName((Activity)host.RootComponent, name); } }
internal static bool CreateField(ITypeDescriptorContext context, ActivityBind activityBind, bool throwOnError) { //Check if the activity is root activity and has valid design time type if (!String.IsNullOrEmpty(activityBind.Path)) { Type boundType = PropertyDescriptorUtils.GetBaseType(context.PropertyDescriptor, context.Instance, context); Activity activity = PropertyDescriptorUtils.GetComponent(context) as Activity; if (activity != null && boundType != null) { activity = Helpers.ParseActivityForBind(activity, activityBind.Name); if (activity == Helpers.GetRootActivity(activity)) { bool isVB = (CompilerHelpers.GetSupportedLanguage(context) == SupportedLanguages.VB); Type designedType = Helpers.GetDataSourceClass(activity, context); if (designedType != null) { //field path could be nested too. //need to find field only with the name up to the first dot (CimplexTypeField in the example below) //and the right type (that would be tricky if the field doesnt exist yet) //example: CimplexTypeField.myIDictionary_int_string[10].someOtherGood2 string fieldName = activityBind.Path; int indexOfDot = fieldName.IndexOfAny(new char[] { '.', '/', '[' }); if (indexOfDot != -1) { fieldName = fieldName.Substring(0, indexOfDot); //path is a nested field access } MemberInfo matchingMember = ActivityBindPropertyDescriptor.FindMatchingMember(fieldName, designedType, isVB); if (matchingMember != null) { Type memberType = null; bool isPrivate = false; if (matchingMember is FieldInfo) { isPrivate = ((FieldInfo)matchingMember).IsPrivate; memberType = ((FieldInfo)matchingMember).FieldType; } else if (matchingMember is PropertyInfo) { MethodInfo getMethod = ((PropertyInfo)matchingMember).GetGetMethod(); MethodInfo setMethod = ((PropertyInfo)matchingMember).GetSetMethod(); isPrivate = ((getMethod != null && getMethod.IsPrivate) || (setMethod != null && setMethod.IsPrivate)); } else if (matchingMember is MethodInfo) { isPrivate = ((MethodInfo)matchingMember).IsPrivate; } if (indexOfDot != -1) { //need to find the type of the member the path references (and if the path is valid at all) PathWalker pathWalker = new PathWalker(); PathMemberInfoEventArgs finalEventArgs = null; pathWalker.MemberFound += delegate(object sender, PathMemberInfoEventArgs eventArgs) { finalEventArgs = eventArgs; }; if (pathWalker.TryWalkPropertyPath(designedType, activityBind.Path)) { //successfully walked the entire path memberType = BindHelpers.GetMemberType(finalEventArgs.MemberInfo); } else { //the path is invalid if (throwOnError) { throw new InvalidOperationException(SR.GetString(SR.Error_MemberWithSameNameExists, activityBind.Path, designedType.FullName)); } return(false); } } if ((matchingMember.DeclaringType == designedType || !isPrivate) && matchingMember is FieldInfo && TypeProvider.IsAssignable(boundType, memberType)) { return(true); } else { if (throwOnError) { throw new InvalidOperationException(SR.GetString(SR.Error_MemberWithSameNameExists, activityBind.Path, designedType.FullName)); } return(false); } } else { // Find out if the name conflicts with an existing activity that has not be flushed in to the // code beside. An activity bind can bind to this field only if the type of the property // is the assignable from the activity type. Activity matchingActivity = null; if (string.Compare(activity.Name, fieldName, isVB ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) == 0) { matchingActivity = activity; } else if (activity is CompositeActivity) { if (activity is CompositeActivity) { foreach (Activity existingActivity in Helpers.GetAllNestedActivities(activity as CompositeActivity)) { if (string.Compare(existingActivity.Name, fieldName, isVB ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) == 0) { matchingActivity = existingActivity; } } } } if (matchingActivity != null) { if (TypeProvider.IsAssignable(boundType, matchingActivity.GetType())) { return(true); } else { if (throwOnError) { throw new InvalidOperationException(SR.GetString(SR.Error_MemberWithSameNameExists, activityBind.Path, designedType.FullName)); } return(false); } } } IMemberCreationService memberCreationService = context.GetService(typeof(IMemberCreationService)) as IMemberCreationService; if (memberCreationService == null) { if (throwOnError) { throw new InvalidOperationException(SR.GetString(SR.General_MissingService, typeof(IMemberCreationService).FullName)); } } else { IDesignerHost designerHost = context.GetService(typeof(IDesignerHost)) as IDesignerHost; if (designerHost == null) { if (throwOnError) { throw new InvalidOperationException(SR.GetString("General_MissingService", typeof(IDesignerHost).FullName)); } } else { memberCreationService.CreateField(designerHost.RootComponentClassName, activityBind.Path, boundType, null, MemberAttributes.Public, null, false); return(true); } } } } } else { if (activity == null && throwOnError) { throw new InvalidOperationException(SR.GetString(SR.Error_InvalidActivityIdentifier, activityBind.Name)); } if (boundType == null && throwOnError) { throw new InvalidOperationException(SR.GetString(SR.Error_PropertyTypeNotDefined, context.PropertyDescriptor.Name, typeof(ActivityBind).Name, typeof(IDynamicPropertyTypeProvider).Name)); } } } return(false); }