public ServiceDescription BuildServiceDescription(out IDictionary<string, ContractDescription> implementedContracts, out IList<Type> reflectedContracts) { ServiceDescriptionContext context = new ServiceDescriptionContext(); ServiceDescription description = new ServiceDescription(); ApplyBehaviors(description); context.ServiceDescription = description; Walker walker = new Walker(true); walker.FoundActivity += delegate(Walker w, WalkerEventArgs args) { IServiceDescriptionBuilder activity = args.CurrentActivity as IServiceDescriptionBuilder; if (activity == null) { return; } activity.BuildServiceDescription(context); }; walker.Walk(this.workflowDefinitionContext.GetWorkflowDefinition()); if (context.Contracts == null || context.Contracts.Count == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.NoContract))); } implementedContracts = context.Contracts; reflectedContracts = context.ReflectedContracts; return description; }
internal static bool HasCodeWithin(Activity rootActivity) { bool hasCodeWithin = false; Walker walker = new Walker(); walker.FoundActivity += delegate (Walker walker, WalkerEventArgs e) { Activity currentActivity = e.CurrentActivity; if (!currentActivity.Enabled) { e.Action = WalkerAction.Skip; } else { CodeTypeMemberCollection members = currentActivity.GetValue(WorkflowMarkupSerializer.XCodeProperty) as CodeTypeMemberCollection; if ((members != null) && (members.Count != 0)) { hasCodeWithin = true; e.Action = WalkerAction.Abort; } } }; walker.Walk(rootActivity); return hasCodeWithin; }
private void OnRefreshTypes(object sender, EventArgs e) { ITypeProvider typeProvider; if (this.refreshTypesHandler != null) { WorkflowView view = this.serviceProvider.GetService(typeof(WorkflowView)) as WorkflowView; if (view != null) { view.Idle -= this.refreshTypesHandler; } this.refreshTypesHandler = null; } IDesignerHost host = this.serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost; Activity seedActivity = (host != null) ? (host.RootComponent as Activity) : null; if (seedActivity != null) { typeProvider = this.serviceProvider.GetService(typeof(ITypeProvider)) as ITypeProvider; if (typeProvider != null) { Walker walker = new Walker(); walker.FoundProperty += delegate (Walker w, WalkerEventArgs args) { if (((args.CurrentValue != null) && (args.CurrentProperty != null)) && ((args.CurrentProperty.PropertyType == typeof(Type)) && (args.CurrentValue is Type))) { Type type = typeProvider.GetType(((Type) args.CurrentValue).FullName); if (type != null) { args.CurrentProperty.SetValue(args.CurrentPropertyOwner, type, null); if (args.CurrentActivity != null) { TypeDescriptor.Refresh(args.CurrentActivity); } } } else if (((args.CurrentProperty == null) && (args.CurrentValue is DependencyObject)) && !(args.CurrentValue is Activity)) { walker.WalkProperties(args.CurrentActivity, args.CurrentValue); } }; walker.FoundActivity += delegate (Walker w, WalkerEventArgs args) { if (args.CurrentActivity != null) { TypeDescriptor.Refresh(args.CurrentActivity); ActivityDesigner designer = ActivityDesigner.GetDesigner(args.CurrentActivity); if (designer != null) { designer.RefreshDesignerActions(); } InvokeWorkflowDesigner designer2 = designer as InvokeWorkflowDesigner; if (designer2 != null) { designer2.RefreshTargetWorkflowType(); } } }; walker.Walk(seedActivity); } IPropertyValueUIService service = this.serviceProvider.GetService(typeof(IPropertyValueUIService)) as IPropertyValueUIService; if (service != null) { service.NotifyPropertyValueUIItemsChanged(); } this.RefreshTasks(); this.RefreshDesignerActions(); } }
private static ValidationErrorCollection ValidateIdentifiers(IServiceProvider serviceProvider, Activity activity) { ValidationErrorCollection validationErrors = new ValidationErrorCollection(); Dictionary<string, int> names = new Dictionary<string, int>(); Walker walker = new Walker(); walker.FoundActivity += delegate (Walker walker2, WalkerEventArgs e) { Activity currentActivity = e.CurrentActivity; if (!currentActivity.Enabled) { e.Action = WalkerAction.Skip; } else { ValidationError item = null; if (names.ContainsKey(currentActivity.QualifiedName)) { if (names[currentActivity.QualifiedName] != 1) { item = new ValidationError(SR.GetString("Error_DuplicatedActivityID", new object[] { currentActivity.QualifiedName }), 0x602, false, "Name"); item.UserData[typeof(Activity)] = currentActivity; validationErrors.Add(item); names[currentActivity.QualifiedName] = 1; } } else if (!string.IsNullOrEmpty(currentActivity.Name)) { names[currentActivity.Name] = 0; item = ValidationHelpers.ValidateIdentifier("Name", serviceProvider, currentActivity.Name); if (item != null) { item.UserData[typeof(Activity)] = currentActivity; validationErrors.Add(item); } } } }; walker.Walk(activity); return validationErrors; }
public virtual void MoveActivities(System.Workflow.ComponentModel.Design.HitTestInfo moveLocation, ReadOnlyCollection<Activity> activitiesToMove) { WalkerEventHandler handler = null; if (moveLocation == null) { throw new ArgumentNullException("moveLocation"); } if (activitiesToMove == null) { throw new ArgumentNullException("activitiesToMove"); } CompositeActivity parentActivity = base.Activity as CompositeActivity; if (parentActivity == null) { throw new Exception(SR.GetString("Error_DragDropInvalid")); } IIdentifierCreationService service = base.GetService(typeof(IIdentifierCreationService)) as IIdentifierCreationService; if (service == null) { throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(IIdentifierCreationService).FullName })); } if (!(base.GetService(typeof(IDesignerHost)) is IDesignerHost)) { throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(IDesignerHost).FullName })); } int num = moveLocation.MapToIndex(); foreach (Activity activity2 in activitiesToMove) { ActivityDesigner designer = ActivityDesigner.GetDesigner(activity2); if ((designer != null) && (designer.ParentDesigner == this)) { int num2 = parentActivity.Activities.IndexOf(activity2); if (num > num2) { num--; } } CompositeActivity parent = activity2.Parent; int index = parent.Activities.IndexOf(activity2); activity2.Parent.Activities.Remove(activity2); service.EnsureUniqueIdentifiers(parentActivity, new Activity[] { activity2 }); DesignerHelpers.UpdateSiteName(activity2, "_activityonthemove_"); CompositeActivity compositeActivity = activity2 as CompositeActivity; if (compositeActivity != null) { int num4 = 1; foreach (Activity activity5 in Helpers.GetNestedActivities(compositeActivity)) { DesignerHelpers.UpdateSiteName(activity5, "_activityonthemove_" + num4.ToString(CultureInfo.InvariantCulture)); num4++; } } try { parentActivity.Activities.Insert(num++, activity2); } catch (Exception exception) { parent.Activities.Insert(index, activity2); throw exception; } DesignerHelpers.UpdateSiteName(activity2, activity2.Name); if (compositeActivity != null) { foreach (Activity activity6 in Helpers.GetNestedActivities(compositeActivity)) { DesignerHelpers.UpdateSiteName(activity6, activity6.Name); } } } foreach (Activity activity7 in activitiesToMove) { Walker walker = new Walker(); if (handler == null) { handler = delegate (Walker w, WalkerEventArgs walkerEventArgs) { ExtenderHelpers.FilterDependencyProperties(base.Activity.Site, walkerEventArgs.CurrentActivity); TypeDescriptor.Refresh(walkerEventArgs.CurrentActivity); }; } walker.FoundActivity += handler; walker.Walk(activity7); } }
public virtual void InsertActivities(System.Workflow.ComponentModel.Design.HitTestInfo insertLocation, ReadOnlyCollection<Activity> activitiesToInsert) { WalkerEventHandler handler = null; if (insertLocation == null) { throw new ArgumentNullException("insertLocation"); } if (activitiesToInsert == null) { throw new ArgumentNullException("activitiesToInsert"); } CompositeActivity parentActivity = base.Activity as CompositeActivity; if (parentActivity == null) { throw new Exception(SR.GetString("Error_DragDropInvalid")); } int num = insertLocation.MapToIndex(); IIdentifierCreationService service = base.GetService(typeof(IIdentifierCreationService)) as IIdentifierCreationService; if (service == null) { throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(IIdentifierCreationService).FullName })); } service.EnsureUniqueIdentifiers(parentActivity, activitiesToInsert); foreach (Activity activity2 in activitiesToInsert) { if (activity2 == null) { throw new ArgumentException("activitiesToInsert", SR.GetString("Error_CollectionHasNullEntry")); } if (activity2.Parent == null) { parentActivity.Activities.Insert(num++, activity2); WorkflowDesignerLoader.AddActivityToDesigner(base.Activity.Site, activity2); } } foreach (Activity activity3 in activitiesToInsert) { Walker walker = new Walker(); if (handler == null) { handler = (w, walkerEventArgs) => ExtenderHelpers.FilterDependencyProperties(base.Activity.Site, walkerEventArgs.CurrentActivity); } walker.FoundActivity += handler; walker.Walk(activity3); } }
public static bool TryPickOperation(IServiceProvider serviceProvider, Activity activity, OperationInfoBase currentOperation, out OperationInfoBase selectedOperation) { selectedOperation = null; bool isReceiveActivity = activity is ReceiveActivity; try { using (OperationPickerDialog operationPicker = new OperationPickerDialog(serviceProvider, isReceiveActivity)) { Walker activityTreeWalker = new Walker(); Type allowedActivityType = null; if (isReceiveActivity) { allowedActivityType = typeof(ReceiveActivity); } else { allowedActivityType = typeof(SendActivity); } activityTreeWalker.FoundActivity += delegate(Walker walker, WalkerEventArgs eventArgs) { Activity foundActivity = eventArgs.CurrentActivity; if (!(allowedActivityType.IsAssignableFrom(foundActivity.GetType()))) { return; } if (!foundActivity.Enabled) { return; } if (foundActivity is ReceiveActivity) { ReceiveActivity reciveActivity = foundActivity as ReceiveActivity; if (reciveActivity.ServiceOperationInfo != null) { operationPicker.AddServiceOperation(reciveActivity.ServiceOperationInfo, reciveActivity); } } if (foundActivity is SendActivity) { SendActivity sendActivity = foundActivity as SendActivity; if (sendActivity.ServiceOperationInfo != null) { operationPicker.AddServiceOperation(sendActivity.ServiceOperationInfo, sendActivity); } } }; activityTreeWalker.Walk(activity.RootActivity); OperationInfoBase currentServiceOperationInfo = currentOperation as OperationInfoBase; if (currentServiceOperationInfo != null) { operationPicker.SelectedOperation = currentServiceOperationInfo; } DialogResult dialogResult = operationPicker.ShowDialog(); if ((operationPicker.SelectedOperation != null) && (dialogResult == DialogResult.OK) && !operationPicker.SelectedOperation.Equals(currentServiceOperationInfo)) { selectedOperation = operationPicker.SelectedOperation.Clone(); return true; } } } catch (Exception e) { DesignerHelpers.ShowMessage(serviceProvider, e.Message, DR.GetString(DR.WorkflowDesignerTitle), MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); throw; } return false; }
static Dictionary<string, ContractType> BuildContractTypes(Activity contextActivity) { if (contextActivity == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contextActivity"); } Dictionary<string, ContractType> types = new Dictionary<string, ContractType>(); Walker walker = new Walker(true); walker.FoundActivity += delegate(Walker w, WalkerEventArgs args) { ReceiveActivity currentActivity = args.CurrentActivity as ReceiveActivity; if (currentActivity == null) { return; } OperationInfo operationInfo = currentActivity.ServiceOperationInfo as OperationInfo; if (operationInfo == null) { return; } if (string.IsNullOrEmpty(operationInfo.ContractName) || string.IsNullOrEmpty(operationInfo.Name)) { return; } if (!types.ContainsKey(operationInfo.ContractName)) { types.Add(operationInfo.ContractName, new ContractType(operationInfo.ContractName)); } bool hasReturnValue = false; bool duplicatedPositions = false; int maxPosition = -1; List<int> parameterIndexs = new List<int>(); foreach (OperationParameterInfo operationParameterInfo in operationInfo.Parameters) { if (operationParameterInfo.Position == -1) { hasReturnValue = true; } else { maxPosition = (maxPosition < operationParameterInfo.Position) ? operationParameterInfo.Position : maxPosition; } if (parameterIndexs.Contains(operationParameterInfo.Position)) { duplicatedPositions = true; break; } else { parameterIndexs.Add(operationParameterInfo.Position); } } if (duplicatedPositions || maxPosition > (operationInfo.Parameters.Count - (hasReturnValue ? 2 : 1))) { return; } ContractType contract = types[operationInfo.ContractName]; ContractMethodInfo methodInfo = new ContractMethodInfo(contract, operationInfo); }; walker.Walk(contextActivity); return types; }