private static void EnsureDefaultChildHierarchy(IDesignerHost designerHost) { //When we are adding the root activity we need to make sure that all the child activities which are required by the parent //activity are looked up in the toolboxitem and added appropriately //If the composite activity already has a some child activities but not all then it //means that user has changed the InitializeComponent and hence we do nothing //This is the simple check to get the designer working in case of selecting composite //root activities CompositeActivity rootActivity = designerHost.RootComponent as CompositeActivity; if (rootActivity != null && rootActivity.Activities.Count == 0) { object[] attribs = rootActivity.GetType().GetCustomAttributes(typeof(ToolboxItemAttribute), false); ToolboxItemAttribute toolboxItemAttrib = (attribs != null && attribs.GetLength(0) > 0) ? attribs[0] as ToolboxItemAttribute : null; if (toolboxItemAttrib != null && toolboxItemAttrib.ToolboxItemType != null) { ToolboxItem item = Activator.CreateInstance(toolboxItemAttrib.ToolboxItemType, new object[] { rootActivity.GetType() }) as ToolboxItem; IComponent[] components = item.CreateComponents(); //I am assuming here that there will be always one top level component created. //If there are multiple then there is a bigger problem as we dont know how //to use those CompositeActivity compositeActivity = null; foreach (IComponent component in components) { if (component.GetType() == rootActivity.GetType()) { compositeActivity = component as CompositeActivity; break; } } //Add the children if (compositeActivity != null && compositeActivity.Activities.Count > 0) { IIdentifierCreationService identifierCreationService = designerHost.GetService(typeof(IIdentifierCreationService)) as IIdentifierCreationService; if (identifierCreationService != null) { //We do not go thru the composite designer here as composite activity //might have simple designer Activity[] activities = compositeActivity.Activities.ToArray(); compositeActivity.Activities.Clear(); identifierCreationService.EnsureUniqueIdentifiers(rootActivity, activities); // Work around : Don't called AddRange because it doesn't send the ListChange notifications // to the activity collection. Use multiple Add calls instaead foreach (Activity newActivity in activities) { rootActivity.Activities.Add(newActivity); } foreach (Activity childActivity in activities) { WorkflowDesignerLoader.AddActivityToDesigner(designerHost, childActivity); } } } } } }
internal static bool IsCustomActivity(CompositeActivity compositeActivity) { if (compositeActivity == null) { throw new ArgumentNullException("compositeActivity"); } if (compositeActivity.UserData.Contains(System.Workflow.Activities.Common.UserDataKeys.CustomActivity)) { return((bool)compositeActivity.UserData[System.Workflow.Activities.Common.UserDataKeys.CustomActivity]); } try { CompositeActivity activity = Activator.CreateInstance(compositeActivity.GetType()) as CompositeActivity; if ((activity != null) && (activity.Activities.Count > 0)) { compositeActivity.UserData[System.Workflow.Activities.Common.UserDataKeys.CustomActivityDefaultName] = activity.Name; compositeActivity.UserData[System.Workflow.Activities.Common.UserDataKeys.CustomActivity] = true; return(true); } } catch { } compositeActivity.UserData[System.Workflow.Activities.Common.UserDataKeys.CustomActivity] = false; return(false); }
internal static bool IsCustomActivity(CompositeActivity compositeActivity) { if (compositeActivity == null) { throw new ArgumentNullException("compositeActivity"); } Guid CustomActivity = new Guid("298CF3E0-E9E0-4d41-A11B-506E9132EB27"); Guid CustomActivityDefaultName = new Guid("8bcd6c40-7bf6-4e60-8eea-bbf40bed92da"); if (compositeActivity.UserData.Contains(new Guid("298CF3E0-E9E0-4d41-A11B-506E9132EB27"))) { return((bool)(compositeActivity.UserData[CustomActivity])); } else { try { CompositeActivity activity = Activator.CreateInstance(compositeActivity.GetType()) as CompositeActivity; if (activity != null && activity.Activities.Count > 0) { compositeActivity.UserData[CustomActivityDefaultName] = activity.Name; compositeActivity.UserData[CustomActivity] = true; return(true); } } catch { } } compositeActivity.UserData[CustomActivity] = false; return(false); }
private static void EnsureDefaultChildHierarchy(IDesignerHost designerHost) { CompositeActivity rootComponent = designerHost.RootComponent as CompositeActivity; if ((rootComponent != null) && (rootComponent.Activities.Count == 0)) { object[] customAttributes = rootComponent.GetType().GetCustomAttributes(typeof(ToolboxItemAttribute), false); ToolboxItemAttribute attribute = ((customAttributes != null) && (customAttributes.GetLength(0) > 0)) ? (customAttributes[0] as ToolboxItemAttribute) : null; if ((attribute != null) && (attribute.ToolboxItemType != null)) { IComponent[] componentArray = (Activator.CreateInstance(attribute.ToolboxItemType, new object[] { rootComponent.GetType() }) as ToolboxItem).CreateComponents(); CompositeActivity activity2 = null; foreach (IComponent component in componentArray) { if (component.GetType() == rootComponent.GetType()) { activity2 = component as CompositeActivity; break; } } if ((activity2 != null) && (activity2.Activities.Count > 0)) { IIdentifierCreationService service = designerHost.GetService(typeof(IIdentifierCreationService)) as IIdentifierCreationService; if (service != null) { Activity[] childActivities = activity2.Activities.ToArray(); activity2.Activities.Clear(); service.EnsureUniqueIdentifiers(rootComponent, childActivities); foreach (Activity activity3 in childActivities) { rootComponent.Activities.Add(activity3); } foreach (Activity activity4 in childActivities) { WorkflowDesignerLoader.AddActivityToDesigner(designerHost, activity4); } } } } } }
internal override void OnBeforeSerializeContents(WorkflowMarkupSerializationManager serializationManager, object obj) { base.OnBeforeSerializeContents(serializationManager, obj); CompositeActivity activity = obj as CompositeActivity; XmlWriter writer = serializationManager.WorkflowMarkupStack[typeof(XmlWriter)] as XmlWriter; if ((activity.Parent == null) && (writer != null)) { Dictionary <string, Activity> dictionary = new Dictionary <string, Activity>(); string prefix = string.Empty; XmlQualifiedName xmlQualifiedName = serializationManager.GetXmlQualifiedName(activity.GetType(), out prefix); dictionary.Add(xmlQualifiedName.Namespace, activity); foreach (Activity activity2 in Helpers.GetNestedActivities(activity)) { prefix = string.Empty; xmlQualifiedName = serializationManager.GetXmlQualifiedName(activity2.GetType(), out prefix); if (!dictionary.ContainsKey(xmlQualifiedName.Namespace)) { writer.WriteAttributeString("xmlns", prefix, null, xmlQualifiedName.Namespace); dictionary.Add(xmlQualifiedName.Namespace, activity2); } } } }
private void OnAddBranch(object sender, EventArgs e) { CompositeActivity branchActivity = OnCreateNewBranch(); CompositeActivity compositeActivity = Activity as CompositeActivity; if (compositeActivity != null && branchActivity != null) { // Record the current number of child activities int designerCount = ContainedDesigners.Count; CompositeActivityDesigner.InsertActivities(this, new ConnectorHitTestInfo(this, HitTestLocations.Designer, compositeActivity.Activities.Count), new List <Activity>(new Activity[] { branchActivity }).AsReadOnly(), DR.GetString(DR.AddingBranch, branchActivity.GetType().Name)); // If the number of child activities has increased, the branch add was successful, so // make sure the highest indexed branch is visible if (ContainedDesigners.Count > designerCount && ContainedDesigners.Count > 0) { ContainedDesigners[ContainedDesigners.Count - 1].EnsureVisible(); } } }
internal override void OnBeforeSerializeContents(WorkflowMarkupSerializationManager serializationManager, object obj) { base.OnBeforeSerializeContents(serializationManager, obj); //For root activity we will go through all the nested activities and put the namespaces at the top level CompositeActivity compositeActivity = obj as CompositeActivity; XmlWriter writer = serializationManager.WorkflowMarkupStack[typeof(XmlWriter)] as XmlWriter; if (compositeActivity.Parent == null && writer != null) { Dictionary <string, Activity> writtenMappings = new Dictionary <string, Activity>(); string prefix = String.Empty; XmlQualifiedName xmlQualifiedName = serializationManager.GetXmlQualifiedName(compositeActivity.GetType(), out prefix); writtenMappings.Add(xmlQualifiedName.Namespace, compositeActivity); foreach (Activity containedActivity in Helpers.GetNestedActivities(compositeActivity)) { prefix = String.Empty; xmlQualifiedName = serializationManager.GetXmlQualifiedName(containedActivity.GetType(), out prefix); if (!writtenMappings.ContainsKey(xmlQualifiedName.Namespace)) { writer.WriteAttributeString("xmlns", prefix, null, xmlQualifiedName.Namespace); writtenMappings.Add(xmlQualifiedName.Namespace, containedActivity); } } } }
private void OnAddBranch(object sender, EventArgs e) { CompositeActivity activity = this.OnCreateNewBranch(); CompositeActivity activity2 = base.Activity as CompositeActivity; if ((activity2 != null) && (activity != null)) { int count = this.ContainedDesigners.Count; CompositeActivityDesigner.InsertActivities(this, new ConnectorHitTestInfo(this, HitTestLocations.Designer, activity2.Activities.Count), new List <Activity>(new Activity[] { activity }).AsReadOnly(), DR.GetString("AddingBranch", new object[] { activity.GetType().Name })); if ((this.ContainedDesigners.Count > count) && (this.ContainedDesigners.Count > 0)) { this.ContainedDesigners[this.ContainedDesigners.Count - 1].EnsureVisible(); } } }
public override ValidationErrorCollection Validate(ValidationManager manager, object obj) { CompositeActivity activity = obj as CompositeActivity; if (activity == null) { throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(CompositeActivity).FullName }), "obj"); } if (Helpers.IsActivityLocked(activity)) { return(new ValidationErrorCollection()); } ValidationErrorCollection errors = base.Validate(manager, obj); int num = 0; int num2 = 0; int num3 = 0; foreach (Activity activity2 in ((ISupportAlternateFlow)activity).AlternateFlowActivities) { num += (activity2 is CancellationHandlerActivity) ? 1 : 0; num2 += (activity2 is FaultHandlersActivity) ? 1 : 0; num3 += (activity2 is CompensationHandlerActivity) ? 1 : 0; } if (num > 1) { errors.Add(new ValidationError(SR.GetString("Error_MoreThanOneCancelHandler", new object[] { activity.GetType().Name }), 0x527)); } if (num2 > 1) { errors.Add(new ValidationError(SR.GetString("Error_MoreThanOneFaultHandlersActivityDecl", new object[] { activity.GetType().Name }), 0x52a)); } if (num3 > 1) { errors.Add(new ValidationError(SR.GetString("Error_MoreThanOneCompensationDecl", new object[] { activity.GetType().Name }), 0x52b)); } if (manager.ValidateChildActivities) { foreach (Activity activity3 in Helpers.GetAllEnabledActivities(activity)) { errors.AddRange(ValidationHelpers.ValidateActivity(manager, activity3)); } } return(errors); }
public override ValidationErrorCollection Validate(ValidationManager manager, object obj) { CompositeActivity compositeActivity = obj as CompositeActivity; if (compositeActivity == null) { throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(CompositeActivity).FullName), "obj"); } if (Helpers.IsActivityLocked(compositeActivity)) { return(new ValidationErrorCollection()); } ValidationErrorCollection validationErrors = base.Validate(manager, obj); // check if more than one cancellation handler or compensation or fault handlers are specified int cancelHandlerCount = 0; int exceptionHandlersCount = 0; int compensationHandlerCount = 0; foreach (Activity activity in ((ISupportAlternateFlow)compositeActivity).AlternateFlowActivities) { cancelHandlerCount += (activity is CancellationHandlerActivity) ? 1 : 0; exceptionHandlersCount += (activity is FaultHandlersActivity) ? 1 : 0; compensationHandlerCount += (activity is CompensationHandlerActivity) ? 1 : 0; } // check cancellation handlers if (cancelHandlerCount > 1) { validationErrors.Add(new ValidationError(SR.GetString(SR.Error_MoreThanOneCancelHandler, compositeActivity.GetType().Name), ErrorNumbers.Error_ScopeMoreThanOneEventHandlersDecl)); } // check exception handlers if (exceptionHandlersCount > 1) { validationErrors.Add(new ValidationError(SR.GetString(SR.Error_MoreThanOneFaultHandlersActivityDecl, compositeActivity.GetType().Name), ErrorNumbers.Error_ScopeMoreThanOneFaultHandlersActivityDecl)); } // check compensation handlers if (compensationHandlerCount > 1) { validationErrors.Add(new ValidationError(SR.GetString(SR.Error_MoreThanOneCompensationDecl, compositeActivity.GetType().Name), ErrorNumbers.Error_ScopeMoreThanOneCompensationDecl)); } if (manager.ValidateChildActivities) { foreach (Activity childActivity in Helpers.GetAllEnabledActivities(compositeActivity)) { validationErrors.AddRange(ValidationHelpers.ValidateActivity(manager, childActivity)); } } return(validationErrors); }