public override void SetValue(object component, object value) { Activity activity = component as Activity; if (activity != null) { ISite site = PropertyDescriptorUtils.GetSite(ServiceProvider, component); if (site == null) { throw new Exception(SR.GetString(SR.General_MissingService, typeof(ISite).FullName)); } IIdentifierCreationService identifierCreationService = site.GetService(typeof(IIdentifierCreationService)) as IIdentifierCreationService; if (identifierCreationService == null) { throw new Exception(SR.GetString(SR.General_MissingService, typeof(IIdentifierCreationService).FullName)); } string newID = value as string; identifierCreationService.ValidateIdentifier(activity, newID); DesignerHelpers.UpdateSiteName(activity, newID); base.SetValue(component, value); } }
private string GeneratePropertyAssociatedFieldName(string className, string propertyName, Type propertyType, out bool exisitingField) { exisitingField = false; IIdentifierCreationService identCreationService = this.ServiceProvider.GetService(typeof(IIdentifierCreationService)) as IIdentifierCreationService; if (identCreationService == null) { throw new InvalidOperationException(); } string baseFieldName = "_"; if (propertyName.StartsWith("@")) { baseFieldName += propertyName.Substring(1); } else { baseFieldName += propertyName; } bool validIdent = false; int identCount = 1; string fieldName = String.Empty; while (!validIdent && identCount < Int32.MaxValue) { fieldName = baseFieldName + System.Convert.ToString(identCount); try { identCreationService.ValidateIdentifier(RootActivity, fieldName); validIdent = true; //See if the field already exists, and if it's the same type if (DoesFieldExist(className, fieldName, propertyType)) { exisitingField = true; } else if (DoesFieldExist(className, fieldName)) { validIdent = false; } } catch { validIdent = false; } identCount += 1; } return(fieldName); }
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); } }
public override void SetValue(object component, object value) { if (IsReadOnly) { throw new ArgumentException(this.eventDescriptor.Name); } if (value != null && !(value is string)) { throw new ArgumentException(this.eventDescriptor.Name); } if (component is DependencyObject) { string name = value as string; DependencyObject dependencyObject = component as DependencyObject; string oldName = null; if (dependencyObject.GetValue(WorkflowMarkupSerializer.EventsProperty) == null) { dependencyObject.SetValue(WorkflowMarkupSerializer.EventsProperty, new Hashtable()); } Hashtable dynamicEvents = dependencyObject.GetValue(WorkflowMarkupSerializer.EventsProperty) as Hashtable; if (dynamicEvents.ContainsKey(this.eventDescriptor.Name)) { oldName = dynamicEvents[this.eventDescriptor.Name] as string; } if (oldName != null && name != null && oldName.Equals(name, StringComparison.Ordinal)) { foreach (string methodName in this.eventSvc.GetCompatibleMethods(this.eventDescriptor)) { if (methodName.Equals(name, StringComparison.CurrentCulture)) { return; } } } else if (oldName == name) { return; } IDesignerHost host = this.serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost; if (host == null) { throw new InvalidOperationException(typeof(IDesignerHost).FullName); } if (!String.IsNullOrEmpty(name)) { if (name.StartsWith("@")) { throw new InvalidOperationException(name); } Activity rootActivity = host.RootComponent as Activity; if (rootActivity != null) { // make sure the name doesn't conflict with an existing member in the code-beside. MemberInfo matchingMember = null; Type designedType = Helpers.GetDataSourceClass(rootActivity, this.serviceProvider); if (designedType != null) { WorkflowLoader loader = this.serviceProvider.GetService(typeof(WorkflowLoader)) as WorkflowLoader; foreach (MemberInfo memberInfo in designedType.GetMembers(BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) { if (memberInfo.Name.Equals(name, StringComparison.Ordinal)) { matchingMember = memberInfo; break; } } } if (matchingMember != null) { if (!(matchingMember is MethodInfo)) { throw new InvalidOperationException(designedType.FullName); } } else { // make sure the name doesn't conflict with an existing activity. IIdentifierCreationService idService = this.serviceProvider.GetService(typeof(IIdentifierCreationService)) as IIdentifierCreationService; if (idService != null) { idService.ValidateIdentifier(rootActivity, name); } } } } // If there is a designer host, create a transaction. DesignerTransaction trans = null; if (host != null) { trans = host.CreateTransaction(name); } try { IComponentChangeService change = this.serviceProvider.GetService(typeof(IComponentChangeService)) as IComponentChangeService; if (change != null) { try { change.OnComponentChanging(component, this); change.OnComponentChanging(component, this.eventDescriptor); } catch (CheckoutException coEx) { if (coEx == CheckoutException.Canceled) { return; } throw; } } if (name != null) { if (host.RootComponent != null) { if (!this.useMethodCalled && !string.IsNullOrEmpty(oldName)) { eventSvc.UseMethod((IComponent)component, eventDescriptor, oldName); } eventSvc.UseMethod((IComponent)component, eventDescriptor, name); this.useMethodCalled = true; } } if (oldName != null && host.RootComponent != null) { eventSvc.FreeMethod((IComponent)component, eventDescriptor, oldName); } dynamicEvents[this.eventDescriptor.Name] = name; if (change != null) { change.OnComponentChanged(component, this.eventDescriptor, 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 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); } }