public override ValidationError ValidateActivityChange(Activity activity, ActivityChangeAction action)
 {
     if (activity == null)
     {
         throw new ArgumentNullException("activity");
     }
     if (action == null)
     {
         throw new ArgumentNullException("action");
     }
     if (((activity.ExecutionStatus != ActivityExecutionStatus.Initialized) && (activity.ExecutionStatus != ActivityExecutionStatus.Executing)) && (activity.ExecutionStatus != ActivityExecutionStatus.Closed))
     {
         return new ValidationError(SR.GetString("Error_DynamicActivity2", new object[] { activity.QualifiedName, activity.ExecutionStatus, activity.GetType().FullName }), 0x50f);
     }
     RemovedActivityAction action2 = action as RemovedActivityAction;
     if (action2 != null)
     {
         StateActivity originalRemovedActivity = action2.OriginalRemovedActivity as StateActivity;
         if (originalRemovedActivity != null)
         {
             return new ValidationError(SR.GetError_CantRemoveState(originalRemovedActivity.QualifiedName), 0x61b);
         }
         if (activity.ExecutionStatus == ActivityExecutionStatus.Executing)
         {
             EventDrivenActivity activity3 = action2.OriginalRemovedActivity as EventDrivenActivity;
             if (activity3 != null)
             {
                 return new ValidationError(SR.GetError_CantRemoveEventDrivenFromExecutingState(activity3.QualifiedName, activity.QualifiedName), 0x620);
             }
         }
     }
     return null;
 }
        protected static TypeProvider CreateTypeProvider(Activity rootActivity)
        {
            TypeProvider typeProvider = new TypeProvider(null);

            Type companionType = rootActivity.GetType();
            typeProvider.SetLocalAssembly(companionType.Assembly);
            typeProvider.AddAssembly(companionType.Assembly);

            foreach (AssemblyName assemblyName in companionType.Assembly.GetReferencedAssemblies())
            {
                Assembly referencedAssembly = null;
                try
                {
                    referencedAssembly = Assembly.Load(assemblyName);
                    if (referencedAssembly != null)
                    {
                        typeProvider.AddAssembly(referencedAssembly);
                    }
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }
                }

                if (referencedAssembly == null && assemblyName.CodeBase != null)
                {
                    typeProvider.AddAssemblyReference(assemblyName.CodeBase);
                }
            }

            return typeProvider;
        }
 public void AddActivityToDesigner(Activity activity)
 {
     if (activity == null)
     {
         throw new ArgumentNullException("activity");
     }
     IDesignerHost service = base.GetService(typeof(IDesignerHost)) as IDesignerHost;
     if (service == null)
     {
         throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(IDesignerHost).FullName }));
     }
     if ((activity.Parent == null) && (service.RootComponent == null))
     {
         string str = activity.GetValue(WorkflowMarkupSerializer.XClassProperty) as string;
         string name = !string.IsNullOrEmpty(str) ? Helpers.GetClassName(str) : Helpers.GetClassName(activity.GetType().FullName);
         service.Container.Add(activity, name);
         this.AddTargetFrameworkProvider(activity);
     }
     else
     {
         service.Container.Add(activity, activity.QualifiedName);
         this.AddTargetFrameworkProvider(activity);
     }
     if (activity is CompositeActivity)
     {
         foreach (Activity activity2 in Helpers.GetNestedActivities(activity as CompositeActivity))
         {
             service.Container.Add(activity2, activity2.QualifiedName);
             this.AddTargetFrameworkProvider(activity2);
         }
     }
 }
		// Methods
		public override bool Evaluate (Activity activity, IServiceProvider provider)
		{

			Activity parent = activity;
			RuleDefinitions definitions = null;

			while (parent != null) {

				definitions = (RuleDefinitions) parent.GetValue (RuleDefinitions.RuleDefinitionsProperty);

				if (definitions != null)
					break;

				parent = parent.Parent;
			}

			if (definitions == null) {
				Console.WriteLine ("No definition");
				return false;
			}

			//Console.WriteLine ("Definition {0} at {1}", definitions, parent);
			RuleValidation validation = new RuleValidation (activity.GetType (), null);
			RuleExecution execution = new RuleExecution (validation, parent);
			RuleCondition condition = definitions.Conditions [ConditionName];
			//Console.WriteLine ("Condition {0}", condition);
			return condition.Evaluate (execution);
		}
 internal static void GetAllMembers(Activity activity, IList<TrackingDataItem> items, TrackingAnnotationCollection annotations)
 {
     Type type = activity.GetType();
     foreach (FieldInfo info in type.GetFields(BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance))
     {
         if (!IsInternalVariable(info.Name))
         {
             TrackingDataItem item = new TrackingDataItem {
                 FieldName = info.Name,
                 Data = GetRuntimeValue(info.GetValue(activity), activity)
             };
             foreach (string str in annotations)
             {
                 item.Annotations.Add(str);
             }
             items.Add(item);
         }
     }
     foreach (PropertyInfo info2 in type.GetProperties(BindingFlags.GetProperty | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance))
     {
         if (!IsInternalVariable(info2.Name) && (info2.GetIndexParameters().Length <= 0))
         {
             TrackingDataItem item2 = new TrackingDataItem {
                 FieldName = info2.Name,
                 Data = GetRuntimeValue(info2.GetValue(activity, null), activity)
             };
             foreach (string str2 in annotations)
             {
                 item2.Annotations.Add(str2);
             }
             items.Add(item2);
         }
     }
 }
        public void AddActivity(Activity input)
        {
            var path = ((Activity)input).GetPrivateMethodValue<string>("get_DottedPath");

            bool isRoot = (input.Parent == null) || (path.Contains(".") == false);

            if (isRoot)
                ActivityTree.Add(new ActivityWrapper(input, path));
            else
                UnresolvedActivities.Add(new ActivityWrapper(input, path));

            #region Populate Base and Declaration List
            lock (this)
            {
                string fullName = input.GetType().FullName;
                if (DeclarationTypes.Contains(fullName) == false)
                {
                    lock (this)
                    {
                        fullName = input.GetType().FullName;

                        if (DeclarationTypes.Contains(fullName) == false)
                        {
                            DeclarationTypes.Add(fullName);
                        }
                    }
                }
            }

            lock (this)
            {
                string baseTypeName = input.GetType().BaseType.FullName;
                if (BaseTypes.Contains(baseTypeName) == false)
                {
                    lock (this)
                    {
                        baseTypeName = input.GetType().BaseType.FullName;

                        if (BaseTypes.Contains(baseTypeName) == false)
                        {
                            BaseTypes.Add(baseTypeName);
                        }
                    }
                }
            }
            #endregion
        }
 private CodeTypeDeclaration CreateOrGetServiceDeclaration(Activity rootActivity, CodeNamespaceCollection codeNamespaceCollection)
 {
     string namespaceName = "";
     CodeNamespace webServiceCodeNamespace = null;
     string fullName = rootActivity.GetType().FullName;
     CodeTypeDeclaration webserviceCodeTypeDeclaration = null;
     if (rootActivity.GetType().FullName.IndexOf(".") != -1)
     {
         namespaceName = rootActivity.GetType().FullName.Substring(0, rootActivity.GetType().FullName.LastIndexOf('.'));
     }
     foreach (CodeNamespace namespace3 in codeNamespaceCollection)
     {
         if (namespace3.Name == namespaceName)
         {
             webServiceCodeNamespace = namespace3;
             break;
         }
     }
     if (webServiceCodeNamespace == null)
     {
         webServiceCodeNamespace = this.GetWebServiceCodeNamespace(namespaceName);
         codeNamespaceCollection.Add(webServiceCodeNamespace);
     }
     string str3 = fullName.Substring(fullName.LastIndexOf('.') + 1) + "_WebService";
     foreach (CodeTypeDeclaration declaration2 in webServiceCodeNamespace.Types)
     {
         if (declaration2.Name == str3)
         {
             webserviceCodeTypeDeclaration = declaration2;
             break;
         }
     }
     if (webserviceCodeTypeDeclaration == null)
     {
         webserviceCodeTypeDeclaration = this.GetWebserviceCodeTypeDeclaration(fullName.Substring(fullName.LastIndexOf('.') + 1));
         webServiceCodeNamespace.Types.Add(webserviceCodeTypeDeclaration);
         webServiceCodeNamespace.Imports.Add(new CodeNamespaceImport("System"));
         webServiceCodeNamespace.Imports.Add(new CodeNamespaceImport("System.Web"));
         webServiceCodeNamespace.Imports.Add(new CodeNamespaceImport("System.Web.Services"));
         webServiceCodeNamespace.Imports.Add(new CodeNamespaceImport("System.Web.Services.Protocols"));
         webServiceCodeNamespace.Imports.Add(new CodeNamespaceImport("System.Workflow.Runtime.Hosting"));
         webServiceCodeNamespace.Imports.Add(new CodeNamespaceImport("System.Workflow.Activities"));
     }
     return webserviceCodeTypeDeclaration;
 }
 private static CorrelationToken GetCorrelationToken(Activity activity)
 {
     DependencyProperty dependencyProperty = DependencyProperty.FromName("CorrelationToken", activity.GetType());
     if (dependencyProperty == null)
     {
         dependencyProperty = DependencyProperty.FromName("CorrelationToken", activity.GetType().BaseType);
     }
     CorrelationToken token = activity.GetValue(dependencyProperty) as CorrelationToken;
     if (token == null)
     {
         throw new InvalidOperationException(SR.GetString("Error_CorrelationTokenMissing", new object[] { activity.Name }));
     }
     CorrelationToken token2 = CorrelationTokenCollection.GetCorrelationToken(activity, token.Name, token.OwnerActivityName);
     if (token2 == null)
     {
         throw new InvalidOperationException(SR.GetString("Error_CorrelationTokenMissing", new object[] { activity.Name }));
     }
     return token2;
 }
 internal static ActivityExecutor[] GetActivityExecutors(Activity activity)
 {
     if (activity == null)
     {
         throw new ArgumentNullException("activity");
     }
     Type type = activity.GetType();
     ActivityExecutor[] executorArray = executors[type] as ActivityExecutor[];
     if (executorArray == null)
     {
         lock (executors.SyncRoot)
         {
             executorArray = executors[type] as ActivityExecutor[];
             if (executorArray != null)
             {
                 return executorArray;
             }
             object[] objArray = null;
             try
             {
                 objArray = ComponentDispenser.CreateActivityExecutors(activity);
             }
             catch (Exception exception)
             {
                 throw new InvalidOperationException(SR.GetString("ExecutorCreationFailedErrorMessage", new object[] { type.FullName }), exception);
             }
             if ((objArray == null) || (objArray.Length == 0))
             {
                 throw new InvalidOperationException(SR.GetString("ExecutorCreationFailedErrorMessage", new object[] { type.FullName }));
             }
             executorArray = new ActivityExecutor[objArray.Length];
             for (int i = 0; i < objArray.Length; i++)
             {
                 if (!typeToExecutorMapping.Contains(objArray[i].GetType()))
                 {
                     lock (typeToExecutorMapping.SyncRoot)
                     {
                         if (!typeToExecutorMapping.Contains(objArray[i].GetType()))
                         {
                             Thread.MemoryBarrier();
                             typeToExecutorMapping[objArray[i].GetType()] = objArray[i];
                         }
                     }
                 }
                 executorArray[i] = (ActivityExecutor) typeToExecutorMapping[objArray[i].GetType()];
             }
             Thread.MemoryBarrier();
             executors[type] = executorArray;
         }
     }
     return executorArray;
 }
Example #10
0
		public object GetRuntimeValue (Activity activity, Type targetType)
		{
			if (activity == null) {
				throw new ArgumentNullException ("activity is a null reference");
			}

			Type activity_type = activity.GetType ();

			PropertyInfo info = activity_type.GetProperty (Path, BindingFlags.FlattenHierarchy  |
				BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.Instance);

			return info.GetValue (activity, null);
		}
 internal void AddChild(Activity child)
 {
     if ((base.Activity is CompositeActivity) && (child != null))
     {
         int count = this.ContainedDesigners.Count;
         System.Workflow.ComponentModel.Design.HitTestInfo insertLocation = new System.Workflow.ComponentModel.Design.HitTestInfo(this, HitTestLocations.Designer);
         CompositeActivityDesigner.InsertActivities(this, insertLocation, new List<Activity>(new Activity[] { child }).AsReadOnly(), string.Format(CultureInfo.InvariantCulture, System.Workflow.Activities.DR.GetString("AddingChild"), new object[] { child.GetType().Name }));
         if ((this.ContainedDesigners.Count > count) && (this.ContainedDesigners.Count > 0))
         {
             this.ContainedDesigners[this.ContainedDesigners.Count - 1].EnsureVisible();
         }
         this.SelectionService.SetSelectedComponents(new object[] { child }, SelectionTypes.Click);
     }
 }
 internal static Type GetActivityType(IServiceProvider serviceProvider, Activity refActivity)
 {
     Type type = null;
     string str = refActivity.GetValue(WorkflowMarkupSerializer.XClassProperty) as string;
     if ((refActivity.Site != null) && !string.IsNullOrEmpty(str))
     {
         ITypeProvider service = serviceProvider.GetService(typeof(ITypeProvider)) as ITypeProvider;
         if ((service != null) && !string.IsNullOrEmpty(str))
         {
             type = service.GetType(str, false);
         }
         return type;
     }
     return refActivity.GetType();
 }
 private static void SetInputParameters(System.Workflow.ComponentModel.Activity definition, System.Workflow.ComponentModel.Activity rootActivity, IDictionary <string, object> inputs, bool hasNameCollision)
 {
     if (inputs != null)
     {
         int length = "In".Length;
         foreach (KeyValuePair <string, object> pair in inputs)
         {
             PropertyInfo property;
             if (hasNameCollision)
             {
                 string name = pair.Key.Substring(0, pair.Key.Length - length);
                 property = definition.GetType().GetProperty(name);
             }
             else
             {
                 property = definition.GetType().GetProperty(pair.Key);
             }
             if ((property != null) && property.CanWrite)
             {
                 property.SetValue(rootActivity, pair.Value, null);
             }
         }
     }
 }
 public override ValidationError ValidateActivityChange(Activity activity, ActivityChangeAction action)
 {
     if (activity == null)
     {
         throw new ArgumentNullException("activity");
     }
     if (action == null)
     {
         throw new ArgumentNullException("action");
     }
     if (((activity.ExecutionStatus != ActivityExecutionStatus.Initialized) && (activity.ExecutionStatus != ActivityExecutionStatus.Executing)) && (activity.ExecutionStatus != ActivityExecutionStatus.Closed))
     {
         return new ValidationError(SR.GetString("Error_DynamicActivity2", new object[] { activity.QualifiedName, Enum.GetName(typeof(ActivityExecutionStatus), activity.ExecutionStatus), activity.GetType().FullName }), 0x50f);
     }
     return null;
 }
Example #15
0
        private static Activity CloneRootActivity(Activity originalRootActivity)
        {
            string           str             = originalRootActivity.GetValue(Activity.WorkflowXamlMarkupProperty) as string;
            string           rulesMarkup     = null;
            Activity         rootActivity    = null;
            IServiceProvider serviceProvider = originalRootActivity.GetValue(Activity.WorkflowRuntimeProperty) as IServiceProvider;

            if (!string.IsNullOrEmpty(str))
            {
                rulesMarkup  = originalRootActivity.GetValue(Activity.WorkflowRulesMarkupProperty) as string;
                rootActivity = Activity.OnResolveActivityDefinition(null, str, rulesMarkup, true, false, serviceProvider);
            }
            else
            {
                rootActivity = Activity.OnResolveActivityDefinition(originalRootActivity.GetType(), null, null, true, false, serviceProvider);
            }
            if (rootActivity == null)
            {
                throw new NullReferenceException(SR.GetString("Error_InvalidRootForWorkflowChanges"));
            }
            ArrayList workflowChanges = (ArrayList)originalRootActivity.GetValue(WorkflowChangeActionsProperty);

            if (workflowChanges != null)
            {
                workflowChanges = CloneWorkflowChangeActions(workflowChanges, originalRootActivity);
                if (workflowChanges == null)
                {
                    return(rootActivity);
                }
                foreach (WorkflowChangeAction action in workflowChanges)
                {
                    action.ApplyTo(rootActivity);
                }
                rootActivity.SetValue(WorkflowChangeActionsProperty, workflowChanges);
            }
            return(rootActivity);
        }
 internal static void ValidateActivity(Activity activity, WorkflowCompilerParameters parameters, WorkflowCompilerResults results)
 {
     ValidationManager manager = new ValidationManager(WorkflowCompilationContext.Current.ServiceProvider);
     foreach (Validator validator in manager.GetValidators(activity.GetType()))
     {
         try
         {
             foreach (ValidationError error in validator.Validate(manager, activity))
             {
                 if (!error.UserData.Contains(typeof(Activity)))
                 {
                     error.UserData[typeof(Activity)] = activity;
                 }
                 results.Errors.Add(CreateXomlCompilerError(error, parameters));
             }
         }
         catch (TargetInvocationException exception)
         {
             Exception exception2 = exception.InnerException ?? exception;
             ValidationError error2 = new ValidationError(SR.GetString("Error_ValidatorThrewException", new object[] { exception2.GetType().FullName, validator.GetType().FullName, activity.Name, exception2.ToString() }), 0x627);
             results.Errors.Add(CreateXomlCompilerError(error2, parameters));
         }
         catch (Exception exception3)
         {
             ValidationError error3 = new ValidationError(SR.GetString("Error_ValidatorThrewException", new object[] { exception3.GetType().FullName, validator.GetType().FullName, activity.Name, exception3.ToString() }), 0x627);
             results.Errors.Add(CreateXomlCompilerError(error3, parameters));
         }
     }
 }
        internal void AddChild(Activity child)
        {
            CompositeActivity compositeActivity = this.Activity as CompositeActivity;
            if (compositeActivity != null && child != null)
            {
                // Record the current number of child activities
                int designerCount = ContainedDesigners.Count;

                HitTestInfo hitTestInfo = new HitTestInfo(this, HitTestLocations.Designer);

                CompositeActivityDesigner.InsertActivities(
                    this,
                    hitTestInfo,
                    new List<Activity>(new Activity[] { child }).AsReadOnly(),
                    string.Format(System.Globalization.CultureInfo.InvariantCulture,
                    DR.GetString(DR.AddingChild),
                    child.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();

                this.SelectionService.SetSelectedComponents(new object[] { child }, SelectionTypes.Primary);
            }
        }
 internal static TypeProvider CreateTypeProvider(Activity rootActivity)
 {
     TypeProvider provider = new TypeProvider(null);
     Type type = rootActivity.GetType();
     provider.SetLocalAssembly(type.Assembly);
     provider.AddAssembly(type.Assembly);
     foreach (AssemblyName name in type.Assembly.GetReferencedAssemblies())
     {
         Assembly assembly = null;
         try
         {
             assembly = Assembly.Load(name);
             if (assembly != null)
             {
                 provider.AddAssembly(assembly);
             }
         }
         catch
         {
         }
         if ((assembly == null) && (name.CodeBase != null))
         {
             provider.AddAssemblyReference(name.CodeBase);
         }
     }
     return provider;
 }
 private static bool CompareWorkflowDefinition(Activity originalWorkflowDefinition, Activity currentWorkflowDefinition)
 {
     if (originalWorkflowDefinition == currentWorkflowDefinition)
     {
         return true;
     }
     if (originalWorkflowDefinition.GetType() != currentWorkflowDefinition.GetType())
     {
         return false;
     }
     Guid guid = (Guid) originalWorkflowDefinition.GetValue(WorkflowChangeVersionProperty);
     Guid guid2 = (Guid) currentWorkflowDefinition.GetValue(WorkflowChangeVersionProperty);
     return (guid == guid2);
 }
 private static Activity CloneRootActivity(Activity originalRootActivity)
 {
     string str = originalRootActivity.GetValue(Activity.WorkflowXamlMarkupProperty) as string;
     string rulesMarkup = null;
     Activity rootActivity = null;
     IServiceProvider serviceProvider = originalRootActivity.GetValue(Activity.WorkflowRuntimeProperty) as IServiceProvider;
     if (!string.IsNullOrEmpty(str))
     {
         rulesMarkup = originalRootActivity.GetValue(Activity.WorkflowRulesMarkupProperty) as string;
         rootActivity = Activity.OnResolveActivityDefinition(null, str, rulesMarkup, true, false, serviceProvider);
     }
     else
     {
         rootActivity = Activity.OnResolveActivityDefinition(originalRootActivity.GetType(), null, null, true, false, serviceProvider);
     }
     if (rootActivity == null)
     {
         throw new NullReferenceException(SR.GetString("Error_InvalidRootForWorkflowChanges"));
     }
     ArrayList workflowChanges = (ArrayList) originalRootActivity.GetValue(WorkflowChangeActionsProperty);
     if (workflowChanges != null)
     {
         workflowChanges = CloneWorkflowChangeActions(workflowChanges, originalRootActivity);
         if (workflowChanges == null)
         {
             return rootActivity;
         }
         foreach (WorkflowChangeAction action in workflowChanges)
         {
             action.ApplyTo(rootActivity);
         }
         rootActivity.SetValue(WorkflowChangeActionsProperty, workflowChanges);
     }
     return rootActivity;
 }
        internal static object ResolveActivityPath(Activity refActivity, string path)
        {
            PathWalker walker;
            if (refActivity == null)
            {
                throw new ArgumentNullException("refActivity");
            }
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }
            if (path.Length == 0)
            {
                throw new ArgumentException(SR.GetString("Error_EmptyPathValue"), "path");
            }
            object value = refActivity;
            BindRecursionContext recursionContext = new BindRecursionContext();
            if (new PathWalker { MemberFound = (EventHandler<PathMemberInfoEventArgs>) Delegate.Combine(walker.MemberFound, delegate (object sender, PathMemberInfoEventArgs eventArgs) {
                if (value == null)
                {
                    eventArgs.Action = PathWalkAction.Cancel;
                }
                else
                {
                    switch (eventArgs.MemberKind)
                    {
                        case PathMemberKind.Field:
                            try
                            {
                                value = (eventArgs.MemberInfo as FieldInfo).GetValue(value);
                            }
                            catch (Exception exception)
                            {
                                value = null;
                                eventArgs.Action = PathWalkAction.Cancel;
                                if (!refActivity.DesignMode)
                                {
                                    TargetInvocationException exception2 = exception as TargetInvocationException;
                                    throw (exception2 != null) ? exception2.InnerException : exception;
                                }
                            }
                            break;

                        case PathMemberKind.Event:
                        {
                            EventInfo memberInfo = eventArgs.MemberInfo as EventInfo;
                            DependencyProperty dependencyProperty = DependencyProperty.FromName(memberInfo.Name, value.GetType());
                            if ((dependencyProperty != null) && (value is DependencyObject))
                            {
                                if ((value as DependencyObject).IsBindingSet(dependencyProperty))
                                {
                                    value = (value as DependencyObject).GetBinding(dependencyProperty);
                                }
                                else
                                {
                                    value = (value as DependencyObject).GetHandler(dependencyProperty);
                                }
                            }
                            break;
                        }
                        case PathMemberKind.Property:
                            if ((eventArgs.MemberInfo as PropertyInfo).CanRead)
                            {
                                DependencyProperty property2 = DependencyProperty.FromName(eventArgs.MemberInfo.Name, value.GetType());
                                if (((property2 != null) && (value is DependencyObject)) && (value as DependencyObject).IsBindingSet(property2))
                                {
                                    value = (value as DependencyObject).GetBinding(property2);
                                }
                                else
                                {
                                    try
                                    {
                                        value = (eventArgs.MemberInfo as PropertyInfo).GetValue(value, null);
                                    }
                                    catch (Exception exception3)
                                    {
                                        value = null;
                                        eventArgs.Action = PathWalkAction.Cancel;
                                        if (!refActivity.DesignMode)
                                        {
                                            TargetInvocationException exception4 = exception3 as TargetInvocationException;
                                            throw (exception4 != null) ? exception4.InnerException : exception3;
                                        }
                                    }
                                }
                                break;
                            }
                            eventArgs.Action = PathWalkAction.Cancel;
                            return;

                        case PathMemberKind.IndexedProperty:
                        case PathMemberKind.Index:
                            try
                            {
                                value = (eventArgs.MemberInfo as PropertyInfo).GetValue(value, BindingFlags.GetProperty, null, eventArgs.IndexParameters, CultureInfo.InvariantCulture);
                            }
                            catch (Exception exception5)
                            {
                                value = null;
                                eventArgs.Action = PathWalkAction.Cancel;
                                if (!refActivity.DesignMode)
                                {
                                    TargetInvocationException exception6 = exception5 as TargetInvocationException;
                                    throw (exception6 != null) ? exception6.InnerException : exception5;
                                }
                            }
                            break;
                    }
                    if (((value is ActivityBind) && !eventArgs.LastMemberInThePath) && (GetMemberType(eventArgs.MemberInfo) != typeof(ActivityBind)))
                    {
                        while (value is ActivityBind)
                        {
                            ActivityBind bind = value as ActivityBind;
                            if (recursionContext.Contains(refActivity, bind))
                            {
                                throw new InvalidOperationException(SR.GetString("Bind_ActivityDataSourceRecursionDetected"));
                            }
                            recursionContext.Add(refActivity, bind);
                            value = bind.GetRuntimeValue(refActivity);
                        }
                    }
                }
            }) }.TryWalkPropertyPath(refActivity.GetType(), path))
            {
                return value;
            }
            return null;
        }
        internal static TypeProvider CreateTypeProvider(Activity rootActivity)
        {
            TypeProvider typeProvider = new TypeProvider(null);

            Type companionType = rootActivity.GetType();
            typeProvider.SetLocalAssembly(companionType.Assembly);
            typeProvider.AddAssembly(companionType.Assembly);

            foreach (AssemblyName assemblyName in companionType.Assembly.GetReferencedAssemblies())
            {
                Assembly referencedAssembly = null;
                try
                {
                    referencedAssembly = Assembly.Load(assemblyName);
                    if (referencedAssembly != null)
                        typeProvider.AddAssembly(referencedAssembly);
                }
                catch
                {
                }

                if (referencedAssembly == null && assemblyName.CodeBase != null)
                    typeProvider.AddAssemblyReference(assemblyName.CodeBase);
            }
            return typeProvider;
        }
        private static Activity CloneRootActivity(Activity originalRootActivity)
        {
            // create new definition root
            string xomlText = originalRootActivity.GetValue(Activity.WorkflowXamlMarkupProperty) as string;
            string rulesText = null;
            Activity clonedRootActivity = null;
            IServiceProvider serviceProvider = originalRootActivity.GetValue(Activity.WorkflowRuntimeProperty) as IServiceProvider;
            Debug.Assert(serviceProvider != null);
            if (!string.IsNullOrEmpty(xomlText))
            {
                rulesText = originalRootActivity.GetValue(Activity.WorkflowRulesMarkupProperty) as string;
                clonedRootActivity = Activity.OnResolveActivityDefinition(null, xomlText, rulesText, true, false, serviceProvider);
            }
            else
                clonedRootActivity = Activity.OnResolveActivityDefinition(originalRootActivity.GetType(), null, null, true, false, serviceProvider);

            if (clonedRootActivity == null)
                throw new NullReferenceException(SR.GetString(SR.Error_InvalidRootForWorkflowChanges));

            // deserialize change history and apply it to new definition tree
            ArrayList workflowChanges = (ArrayList)((Activity)originalRootActivity).GetValue(WorkflowChanges.WorkflowChangeActionsProperty);
            if (workflowChanges != null)
            {
                workflowChanges = CloneWorkflowChangeActions(workflowChanges, originalRootActivity);
                if (workflowChanges != null)
                {
                    // apply changes to the shared schedule Defn to get the instance specific copy
                    foreach (WorkflowChangeAction action in workflowChanges)
                    {
                        bool result = action.ApplyTo((Activity)clonedRootActivity);
                        Debug.Assert(result, "ApplyTo Failed");
                    }
                    ((Activity)clonedRootActivity).SetValue(WorkflowChanges.WorkflowChangeActionsProperty, workflowChanges);
                }
            }
            return clonedRootActivity;
        }
        private static bool CompareWorkflowDefinition(Activity originalWorkflowDefinition, Activity currentWorkflowDefinition)
        {
            if (originalWorkflowDefinition == currentWorkflowDefinition)
                return true;

            if (originalWorkflowDefinition.GetType() != currentWorkflowDefinition.GetType())
                return false;

            Guid originalChangeVersion = (Guid)originalWorkflowDefinition.GetValue(WorkflowChanges.WorkflowChangeVersionProperty);
            Guid currentChangeVersion = (Guid)currentWorkflowDefinition.GetValue(WorkflowChanges.WorkflowChangeVersionProperty);
            return (originalChangeVersion == currentChangeVersion);
        }
Example #25
0
 public void TrackData(System.Workflow.ComponentModel.Activity activity, int eventCounter, string key, object data)
 {
     this.nativeActivityContext.Track(new InteropTrackingRecord(this.Activity.DisplayName, new UserTrackingRecord(activity.GetType(), activity.QualifiedName, activity.ContextGuid, (activity.Parent == null) ? Guid.Empty : activity.Parent.ContextGuid, DateTime.UtcNow, eventCounter, key, data)));
 }
Example #26
0
        private void EnumerateEventHandlersForActivity(Guid scheduleTypeId, Activity activity)
        {
            List<ActivityHandlerDescriptor> handlerMethods = new List<ActivityHandlerDescriptor>();
            MethodInfo getInvocationListMethod = activity.GetType().GetMethod("System.Workflow.ComponentModel.IDependencyObjectAccessor.GetInvocationList", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy);

            foreach (EventInfo eventInfo in activity.GetType().GetEvents(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy))
            {
                DependencyProperty dependencyEvent = DependencyProperty.FromName(eventInfo.Name, activity.GetType());

                if (dependencyEvent != null)
                {
                    try
                    {
                        MethodInfo boundGetInvocationListMethod = getInvocationListMethod.MakeGenericMethod(new Type[] { dependencyEvent.PropertyType });
                        foreach (Delegate handler in (boundGetInvocationListMethod.Invoke(activity, new object[] { dependencyEvent }) as Delegate[]))
                        {
                            MethodInfo handlerMethodInfo = handler.Method;
                            ActivityHandlerDescriptor handlerMethod;
                            handlerMethod.Name = handlerMethodInfo.DeclaringType.FullName + "." + handlerMethodInfo.Name;
                            handlerMethod.Token = handlerMethodInfo.MetadataToken;
                            handlerMethods.Add(handlerMethod);
                        }
                    }
                    catch
                    {
                    }
                }
            }

            this.controllerConduit.UpdateHandlerMethodsForActivity(this.programId, scheduleTypeId, activity.QualifiedName, handlerMethods);
        }
        internal static object ResolveActivityPath(Activity refActivity, string path)
        {
            PathWalker walker;

            if (refActivity == null)
            {
                throw new ArgumentNullException("refActivity");
            }
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }
            if (path.Length == 0)
            {
                throw new ArgumentException(SR.GetString("Error_EmptyPathValue"), "path");
            }
            object value = refActivity;
            BindRecursionContext recursionContext = new BindRecursionContext();

            if (new PathWalker {
                MemberFound = (EventHandler <PathMemberInfoEventArgs>) Delegate.Combine(walker.MemberFound, delegate(object sender, PathMemberInfoEventArgs eventArgs) {
                    if (value == null)
                    {
                        eventArgs.Action = PathWalkAction.Cancel;
                    }
                    else
                    {
                        switch (eventArgs.MemberKind)
                        {
                        case PathMemberKind.Field:
                            try
                            {
                                value = (eventArgs.MemberInfo as FieldInfo).GetValue(value);
                            }
                            catch (Exception exception)
                            {
                                value = null;
                                eventArgs.Action = PathWalkAction.Cancel;
                                if (!refActivity.DesignMode)
                                {
                                    TargetInvocationException exception2 = exception as TargetInvocationException;
                                    throw (exception2 != null) ? exception2.InnerException : exception;
                                }
                            }
                            break;

                        case PathMemberKind.Event:
                            {
                                EventInfo memberInfo = eventArgs.MemberInfo as EventInfo;
                                DependencyProperty dependencyProperty = DependencyProperty.FromName(memberInfo.Name, value.GetType());
                                if ((dependencyProperty != null) && (value is DependencyObject))
                                {
                                    if ((value as DependencyObject).IsBindingSet(dependencyProperty))
                                    {
                                        value = (value as DependencyObject).GetBinding(dependencyProperty);
                                    }
                                    else
                                    {
                                        value = (value as DependencyObject).GetHandler(dependencyProperty);
                                    }
                                }
                                break;
                            }

                        case PathMemberKind.Property:
                            if ((eventArgs.MemberInfo as PropertyInfo).CanRead)
                            {
                                DependencyProperty property2 = DependencyProperty.FromName(eventArgs.MemberInfo.Name, value.GetType());
                                if (((property2 != null) && (value is DependencyObject)) && (value as DependencyObject).IsBindingSet(property2))
                                {
                                    value = (value as DependencyObject).GetBinding(property2);
                                }
                                else
                                {
                                    try
                                    {
                                        value = (eventArgs.MemberInfo as PropertyInfo).GetValue(value, null);
                                    }
                                    catch (Exception exception3)
                                    {
                                        value = null;
                                        eventArgs.Action = PathWalkAction.Cancel;
                                        if (!refActivity.DesignMode)
                                        {
                                            TargetInvocationException exception4 = exception3 as TargetInvocationException;
                                            throw (exception4 != null) ? exception4.InnerException : exception3;
                                        }
                                    }
                                }
                                break;
                            }
                            eventArgs.Action = PathWalkAction.Cancel;
                            return;

                        case PathMemberKind.IndexedProperty:
                        case PathMemberKind.Index:
                            try
                            {
                                value = (eventArgs.MemberInfo as PropertyInfo).GetValue(value, BindingFlags.GetProperty, null, eventArgs.IndexParameters, CultureInfo.InvariantCulture);
                            }
                            catch (Exception exception5)
                            {
                                value = null;
                                eventArgs.Action = PathWalkAction.Cancel;
                                if (!refActivity.DesignMode)
                                {
                                    TargetInvocationException exception6 = exception5 as TargetInvocationException;
                                    throw (exception6 != null) ? exception6.InnerException : exception5;
                                }
                            }
                            break;
                        }
                        if (((value is ActivityBind) && !eventArgs.LastMemberInThePath) && (GetMemberType(eventArgs.MemberInfo) != typeof(ActivityBind)))
                        {
                            while (value is ActivityBind)
                            {
                                ActivityBind bind = value as ActivityBind;
                                if (recursionContext.Contains(refActivity, bind))
                                {
                                    throw new InvalidOperationException(SR.GetString("Bind_ActivityDataSourceRecursionDetected"));
                                }
                                recursionContext.Add(refActivity, bind);
                                value = bind.GetRuntimeValue(refActivity);
                            }
                        }
                    }
                })
            }.TryWalkPropertyPath(refActivity.GetType(), path))
            {
                return(value);
            }
            return(null);
        }
Example #28
0
 protected virtual void OnListChanged(ActivityCollectionChangeEventArgs e)
 {
     if (e == null)
     {
         throw new ArgumentNullException("e");
     }
     if (((e.Action == ActivityCollectionChangeAction.Replace) || (e.Action == ActivityCollectionChangeAction.Remove)) && (e.RemovedItems != null))
     {
         foreach (Activity activity in e.RemovedItems)
         {
             activity.SetParent(null);
         }
     }
     if (((e.Action == ActivityCollectionChangeAction.Replace) || (e.Action == ActivityCollectionChangeAction.Add)) && (e.AddedItems != null))
     {
         foreach (Activity activity2 in e.AddedItems)
         {
             activity2.SetParent(this);
         }
         Queue <Activity> queue = new Queue <Activity>(e.AddedItems);
         while (queue.Count > 0)
         {
             Activity activity3 = queue.Dequeue();
             if ((activity3 != null) && (((activity3.Name == null) || (activity3.Name.Length == 0)) || (activity3.Name == activity3.GetType().Name)))
             {
                 Activity rootActivity = Helpers.GetRootActivity(activity3);
                 string   str          = rootActivity.GetValue(WorkflowMarkupSerializer.XClassProperty) as string;
                 if ((rootActivity.Parent == null) || !string.IsNullOrEmpty(str))
                 {
                     ArrayList list = new ArrayList();
                     list.AddRange(Helpers.GetIdentifiersInCompositeActivity(rootActivity as CompositeActivity));
                     activity3.Name = DesignerHelpers.GenerateUniqueIdentifier(this.Site, Helpers.GetBaseIdentifier(activity3), (string[])list.ToArray(typeof(string)));
                 }
             }
             if (activity3 is CompositeActivity)
             {
                 foreach (Activity activity5 in ((CompositeActivity)activity3).Activities)
                 {
                     queue.Enqueue(activity5);
                 }
             }
         }
     }
     if (this.Site != null)
     {
         IComponentChangeService service = this.Site.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
         if (service != null)
         {
             service.OnComponentChanged(this, null, e, null);
         }
     }
 }
 internal RTTrackingProfile(TrackingProfile profile, Activity root, Type serviceType)
 {
     this._activities = new Dictionary<string, List<ActivityTrackPointCacheItem>>();
     this._activitiesIgnore = new List<string>();
     this._user = new Dictionary<string, List<UserTrackPoint>>();
     this._userIgnore = new List<string>();
     if (profile == null)
     {
         throw new ArgumentNullException("profile");
     }
     if (root == null)
     {
         throw new ArgumentNullException("root");
     }
     if (null == serviceType)
     {
         throw new ArgumentNullException("serviceType");
     }
     this._workflowType = root.GetType();
     this._serviceType = serviceType;
     TrackingProfileSerializer serializer = new TrackingProfileSerializer();
     StringWriter writer = new StringWriter(CultureInfo.InvariantCulture);
     StringReader reader = null;
     TrackingProfile profile2 = null;
     try
     {
         serializer.Serialize(writer, profile);
         reader = new StringReader(writer.ToString());
         profile2 = serializer.Deserialize(reader);
     }
     finally
     {
         if (reader != null)
         {
             reader.Close();
         }
         if (writer != null)
         {
             writer.Close();
         }
     }
     this._profile = profile2;
     this.CheckAllActivities(root);
 }
        private static string ConvertActivity(Activity current, RuleDefinitions ruleDefinitions)
        {
            var builder = new StringBuilder();
            if (current is IfElseActivity)
            {
                //var activity = current as IfElseActivity;
                //if (activity.Activities.Count > 0) // there are branches if..else..activity
                //{
                //    string[] dependents = activity.Activities.Select(x => x.Name).ToArray();

                //    builder.AppendFormat("There are {0} conditions executed in this scenario namely -", activity.Activities.Count)
                //        .AppendLine(dependents.ToCSV())
                //        .AppendLine();
                //}
            }
            else if (current is IfElseBranchActivity)
            {
                var activity = current as IfElseBranchActivity;
                builder.AppendLine(ConvertActivityCondition(activity.Condition, ruleDefinitions));
            }
            else if (current is WhileActivity)
            {
                var activity = current as WhileActivity;
                builder.AppendLine(ConvertActivityCondition(activity.Condition, ruleDefinitions));
            }
            //else if (current is SequenceActivity)
            //{

            //}
            //else if (current is ListenActivity)
            //{

            //}
            //else if (current is StateActivity)
            //{

            //}
            //else if (current is StateInitializationActivity)
            //{

            //}
            else if (current is SetStateActivity)
            {
                var activity = current as SetStateActivity;
                builder.AppendFormat("This activity sets the next state of the workflow to {0}", activity.TargetStateName).AppendLine();
            }
            //else if (current is EventDrivenActivity)
            //{

            //}
            else if (current is PolicyActivity)
            {
                var activity = current as PolicyActivity;
                builder.AppendLine(RuleTranslator.ConvertRuleSetReference(activity.RuleSetReference, ruleDefinitions));
            }
            else
            {
                Log.Debug("Not supported: " + current.GetType());
            }

            return builder.ToString().TrimEnd(Environment.NewLine.ToCharArray());
        }
Example #31
0
        internal static ActivityExecutor[] GetActivityExecutors(Activity activity)
        {
            if (activity == null)
            {
                throw new ArgumentNullException("activity");
            }

            Type activityType = activity.GetType();

            ActivityExecutor[] activityExecutors = executors[activityType] as ActivityExecutor[];
            if (activityExecutors != null)
            {
                return(activityExecutors);
            }

            lock (executors.SyncRoot)
            {
                activityExecutors = executors[activityType] as ActivityExecutor[];
                if (activityExecutors != null)
                {
                    return(activityExecutors);
                }

                object[] activityExecutorsObjects = null;
                try
                {
                    //activityExecutorsObjects = ComponentDispenser.CreateComponents(activityType, typeof(ActivityExecutorAttribute));
                    activityExecutorsObjects = ComponentDispenser.CreateActivityExecutors(activity);
                }
                catch (Exception e)
                {
                    throw new InvalidOperationException(SR.GetString(SR.ExecutorCreationFailedErrorMessage, activityType.FullName), e);
                }

                if (activityExecutorsObjects == null || activityExecutorsObjects.Length == 0)
                {
                    throw new InvalidOperationException(SR.GetString(SR.ExecutorCreationFailedErrorMessage, activityType.FullName));
                }

                activityExecutors = new ActivityExecutor[activityExecutorsObjects.Length];
                for (int index = 0; index < activityExecutorsObjects.Length; index++)
                {
                    if (!typeToExecutorMapping.Contains(activityExecutorsObjects[index].GetType()))
                    {
                        lock (typeToExecutorMapping.SyncRoot)
                        {
                            if (!typeToExecutorMapping.Contains(activityExecutorsObjects[index].GetType()))
                            {
                                System.Threading.Thread.MemoryBarrier();
                                typeToExecutorMapping[activityExecutorsObjects[index].GetType()] = activityExecutorsObjects[index];
                            }
                        }
                    }
                    activityExecutors[index] = (ActivityExecutor)typeToExecutorMapping[activityExecutorsObjects[index].GetType()];
                }

                System.Threading.Thread.MemoryBarrier();
                executors[activityType] = activityExecutors;
            }
            return(activityExecutors);
        }
 private TrackingListener GetListener(Activity sked, WorkflowExecutor skedExec, TrackingListenerBroker broker)
 {
     if ((sked == null) || (skedExec == null))
     {
         WorkflowTrace.Tracking.TraceEvent(TraceEventType.Error, 0, ExecutionStringManager.NullParameters);
         return null;
     }
     if ((this._services != null) && (this._services.Count > 0))
     {
         bool load = null != broker;
         List<TrackingChannelWrapper> channels = this.GetChannels(sked, skedExec, skedExec.InstanceId, sked.GetType(), ref broker);
         if ((channels != null) && (channels.Count != 0))
         {
             return new TrackingListener(this, sked, skedExec, channels, broker, load);
         }
     }
     return null;
 }
Example #33
0
 private static string GetBaseIdentifier(Activity activity)
 {
     string baseIdentifier = activity.GetType().Name;
     StringBuilder b = new StringBuilder(baseIdentifier.Length);
     for (int i = 0; i < baseIdentifier.Length; i++)
     {
         if (Char.IsUpper(baseIdentifier[i]) && (i == 0 || i == baseIdentifier.Length - 1 || Char.IsUpper(baseIdentifier[i + 1])))
         {
             b.Append(Char.ToLower(baseIdentifier[i], CultureInfo.InvariantCulture));
         }
         else
         {
             b.Append(baseIdentifier.Substring(i));
             break;
         }
     }
     return b.ToString();
 }
        /// <summary>
        /// Primary constructor
        /// </summary>
        /// <param name="root"></param>
        /// <param name="workflowType"></param>
        /// <param name="profile"></param>
        internal RTTrackingProfile(TrackingProfile profile, Activity root, Type serviceType)
        {
            if (null == profile)
                throw new ArgumentNullException("profile");
            if (null == root)
                throw new ArgumentNullException("root");
            if (null == serviceType)
                throw new ArgumentNullException("serviceType");

            _workflowType = root.GetType();
            _serviceType = serviceType;
            //
            // "Clone" a private copy in case the tracking service holds a reference to 
            // the profile it gave us and attempts to modify it at a later point
            TrackingProfileSerializer tps = new TrackingProfileSerializer();

            StringWriter writer = new StringWriter(System.Globalization.CultureInfo.InvariantCulture);
            StringReader reader = null;

            TrackingProfile privateProfile = null;

            try
            {
                //
                // Let exceptions bubble back to the tracking service - 
                // the profile must be valid per the schema.
                tps.Serialize(writer, profile);
                reader = new StringReader(writer.ToString());
                privateProfile = tps.Deserialize(reader);
            }
            finally
            {
                if (null != reader)
                    reader.Close();

                if (null != writer)
                    writer.Close();
            }
            _profile = privateProfile;

            CheckAllActivities((Activity)root);
        }
 public string GetBaseActivityType(Activity activity)
 {
     return activity.GetType().FullName;
 }
 private System.Type GetActivityType(Activity activity)
 {
     System.Type type = null;
     IDesignerHost service = this.serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost;
     WorkflowDesignerLoader loader = this.serviceProvider.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
     if (((service != null) && (loader != null)) && (activity.Parent == null))
     {
         ITypeProvider provider = this.serviceProvider.GetService(typeof(ITypeProvider)) as ITypeProvider;
         if (provider != null)
         {
             type = provider.GetType(service.RootComponentClassName, false);
         }
     }
     if (type == null)
     {
         type = activity.GetType();
     }
     return type;
 }
Example #37
0
 public void TrackActivityStatusChange(System.Workflow.ComponentModel.Activity activity, int eventCounter)
 {
     this.nativeActivityContext.Track(new InteropTrackingRecord(this.Activity.DisplayName, new ActivityTrackingRecord(activity.GetType(), activity.QualifiedName, activity.ContextGuid, (activity.Parent == null) ? Guid.Empty : activity.Parent.ContextGuid, activity.ExecutionStatus, DateTime.UtcNow, eventCounter, null)));
 }