예제 #1
0
        static void printActivityTree(Activity activity, string tag)
        {
            Console.WriteLine("{0} DisplayName:{1},type:{2}", tag, activity.DisplayName, activity.GetType());

            System.Collections.Generic.IEnumerator<Activity> list = WorkflowInspectionServices.GetActivities(activity).GetEnumerator();

            while (list.MoveNext())
            {
                printActivityTree(list.Current, "  " + tag);
            }
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChannelActivity" /> class.
        /// </summary>
        /// <param name="activity">The activity.</param>
        /// <param name="level">The level.</param>
        internal ChannelActivity(Activity activity, int level = 0)
        {
            Id = activity.Id;
            DisplayName = activity.DisplayName;
            ActivityType = activity.GetType().Name;
            Level = level;

            Children = WorkflowInspectionServices.GetActivities(activity)
                .Select(child => new ChannelActivity(child, level+1) as IChannelActivity)
                .ToList();
        }
예제 #3
0
        public static Constraint VerifyParentIsObjectContextScope(Activity activity)
        {
            DelegateInArgument<Activity> element = new DelegateInArgument<Activity>();
            DelegateInArgument<ValidationContext> context = new DelegateInArgument<ValidationContext>();
            DelegateInArgument<Activity> child = new DelegateInArgument<Activity>();
            Variable<bool> result = new Variable<bool>();

            return new Constraint<Activity>
            {
                Body = new ActivityAction<Activity, ValidationContext>
                {
                    Argument1 = element,
                    Argument2 = context,
                    Handler = new Sequence
                    {
                        Variables = { result },
                        Activities =
                        {
                            new ForEach<Activity>
                            {
                                Values = new GetParentChain
                                {
                                    ValidationContext = context
                                },
                                Body = new ActivityAction<Activity>
                                {
                                    Argument = child,
                                    Handler = new If
                                    {
                                        Condition = new InArgument<bool>((env) => object.Equals(child.Get(env).GetType(), typeof(ObjectContextScope))),
                                        Then = new Assign<bool>
                                        {
                                            Value = true,
                                            To = result
                                        }
                                    }
                                }
                            },
                            new AssertValidation
                            {
                                Assertion = new InArgument<bool>(env => result.Get(env)),
                                Message = new InArgument<string> (string.Format("{0} can only be added inside an ObjectContextScope activity.", activity.GetType().Name)),
                                PropertyName = new InArgument<string>((env) => element.Get(env).DisplayName)
                            }
                        }
                    }
                }
            };
        }
예제 #4
0
		public virtual bool RunInActivityController(Activity activity)
		{
			if (activity != null)
			{
				string name = activity.GetType().Name;
				if (!this._inProcActivityLookup.ContainsKey(name))
				{
					ActivityRunMode activityRunMode = this._runtime.Configuration.GetActivityRunMode(activity);
					bool flag = activityRunMode == ActivityRunMode.InProcess;
					return this._inProcActivityLookup.GetOrAdd(name, flag);
				}
				else
				{
					return this._inProcActivityLookup[name];
				}
			}
			else
			{
				throw new ArgumentNullException("activity");
			}
		}
예제 #5
0
        private bool CheckIfSuspendable(Activity activity)
        {
            if (string.Equals(activity.GetType().ToString(), "Microsoft.PowerShell.Activities.PSPersist", StringComparison.OrdinalIgnoreCase))
            {
                return true;
            }

            if (string.Equals(activity.GetType().ToString(), "Microsoft.PowerShell.Activities.Suspend", StringComparison.OrdinalIgnoreCase))
            {
                return true;
            }

            PSActivity psactivity = activity as PSActivity;
            if (psactivity != null && psactivity.PSPersist != null && psactivity.PSPersist.Expression != null)
            {
                return true;
            }

            Sequence seqActivity = activity as Sequence;
            if (seqActivity != null && seqActivity.Variables != null && seqActivity.Variables.Count > 0)
            {
                foreach (Variable var in seqActivity.Variables)
                {
                    if (string.Equals(var.Name, WorkflowPreferenceVariables.PSPersistPreference, StringComparison.OrdinalIgnoreCase))
                        return true;
                }
            }
            
            Parallel parActivity = activity as Parallel;
            if (parActivity != null && parActivity.Variables != null && parActivity.Variables.Count > 0)
            {
                foreach (Variable var in parActivity.Variables)
                {
                    if (string.Equals(var.Name, WorkflowPreferenceVariables.PSPersistPreference, StringComparison.OrdinalIgnoreCase))
                        return true;
                }
            }

            return false;
        }
예제 #6
0
        private bool ValidateActivity(Activity activity, string runtimeAssembly, PSWorkflowValidationResults validationResult)
        {
            if (validationResult != null && validationResult.IsWorkflowSuspendable == false)
            {
                validationResult.IsWorkflowSuspendable = CheckIfSuspendable(activity);
            }

            bool allowed = false;
            Type activityType = activity.GetType();

            // If there is a custom validator activity, then call it. If it returns true
            // then just return the activity.
            if (Validation.CustomHandler != null && Validation.CustomHandler.Invoke(activity))
            {
                allowed = true;
            }
            else if (MandatorySystemActivities.Contains(activityType.Name))
            {
                allowed = true;
            }
            else if (string.Equals(activityType.Assembly.FullName, "System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35", StringComparison.OrdinalIgnoreCase))
            {
                allowed = AllowedSystemActivities.Contains(activityType.Name);
            }
            else if (string.Equals(runtimeAssembly, activityType.Assembly.GetName().Name, StringComparison.OrdinalIgnoreCase))
            {
                // Allow the activities which belong to runtime assembly containing dependent Xamls.
                allowed = true;
            }
            else if (Configuration.PSDefaultActivitiesAreAllowed
              && PowerShellActivitiesAssemblies.Contains(activityType.Assembly.GetName().Name.ToLowerInvariant()))
            {
                // Allow any of the activities from our product assemblies provided that product activities were
                // specified as allowed activities
                allowed = true;
            }
            else
            {
                //  Check if the activityId matches any activity in the allowed list
                //  as a full name or as  pattern.
                foreach (string allowedActivity in Configuration.AllowedActivity ?? new string[0])
                {
                    // skipping * because it has already been checked above
                    if (string.Equals(allowedActivity, PSWorkflowConfigurationProvider.PSDefaultActivities, StringComparison.OrdinalIgnoreCase))
                        continue;

                    if (activity is System.Activities.Activity)
                    {
                        if (false
                            || IsMatched(allowedActivity, activityType.Name)
                            || IsMatched(allowedActivity, activityType.FullName)
                            || IsMatched(allowedActivity, activityType.Assembly.GetName().Name + "\\" + activityType.Name)
                            || IsMatched(allowedActivity, activityType.Assembly.GetName().Name + "\\" + activityType.FullName)
                            || IsMatched(allowedActivity, activityType.Assembly.GetName().FullName + "\\" + activityType.Name)
                            || IsMatched(allowedActivity, activityType.Assembly.GetName().FullName + "\\" + activityType.FullName))
                        {
                            allowed = true;
                            break;
                        }
                    }
                }
            }

            string displayName = activity.DisplayName;

            if (string.IsNullOrEmpty(displayName))
                displayName = this.GetType().Name;

            if (allowed)
            {
                _structuredTracer.WorkflowActivityValidated(Guid.Empty, displayName, activityType.FullName);
            }
            else
            {
                _structuredTracer.WorkflowActivityValidationFailed(Guid.Empty, displayName, activityType.FullName);
            }

            return allowed;
        }
 static void AssertIsCodeActivity(Activity activity)
 {
     Type codeActivityOfTType = null;
     ActivityWithResult activityWithResult = activity as ActivityWithResult;
     if (activityWithResult != null)
     {
         codeActivityOfTType = typeof(CodeActivity<>).MakeGenericType(activityWithResult.ResultType);
     }
     Fx.Assert(activity is CodeActivity || (codeActivityOfTType != null && codeActivityOfTType.IsAssignableFrom(activity.GetType())), "Expected CodeActivity or CodeActivity<T>");
 }
예제 #8
0
 private static XName GetWorkflowHostTypeName(System.Activities.Activity workflowDefinition)
 {
     return(XName.Get(workflowDefinition.GetType().FullName, "http://www.baseeam.com/2016/workflow"));
 }
예제 #9
0
		private bool CheckIfSuspendable(Activity activity)
		{
			bool flag;
			if (!string.Equals(activity.GetType().ToString(), "Microsoft.PowerShell.Activities.PSPersist", StringComparison.OrdinalIgnoreCase))
			{
				if (!string.Equals(activity.GetType().ToString(), "Microsoft.PowerShell.Activities.Suspend", StringComparison.OrdinalIgnoreCase))
				{
					PSActivity pSActivity = activity as PSActivity;
					if (pSActivity == null || pSActivity.PSPersist == null || pSActivity.PSPersist.Expression == null)
					{
						Sequence sequence = activity as Sequence;
						if (sequence != null && sequence.Variables != null && sequence.Variables.Count > 0)
						{
							foreach (Variable variable in sequence.Variables)
							{
								if (!string.Equals(variable.Name, "PSPersistPreference", StringComparison.OrdinalIgnoreCase))
								{
									continue;
								}
								flag = true;
								return flag;
							}
						}
						Parallel parallel = activity as Parallel;
						if (parallel != null && parallel.Variables != null && parallel.Variables.Count > 0)
						{
							foreach (Variable variable1 in parallel.Variables)
							{
								if (!string.Equals(variable1.Name, "PSPersistPreference", StringComparison.OrdinalIgnoreCase))
								{
									continue;
								}
								flag = true;
								return flag;
							}
						}
						return false;
					}
					else
					{
						return true;
					}
				}
				else
				{
					return true;
				}
			}
			else
			{
				return true;
			}
		}
예제 #10
0
        public virtual bool RunInActivityController(Activity activity)
        {
            if (activity == null)
            {
                throw new ArgumentNullException("activity");
            }

            String name = activity.GetType().Name;

            if (_inProcActivityLookup.ContainsKey(name)) return _inProcActivityLookup[name];


            ActivityRunMode runMode = _runtime.Configuration.GetActivityRunMode(activity);
            bool runInProc = runMode == ActivityRunMode.InProcess;

            return _inProcActivityLookup.GetOrAdd(name, runInProc);
        }
 internal static Dictionary<object, SourceLocation> GetSourceLocations(Activity rootActivity, out string sourcePath, out bool isTemporaryFile)
 {
     sourcePath = XamlDebuggerXmlReader.GetFileName(rootActivity) as string;
     isTemporaryFile = false;
     Assembly localAssembly = rootActivity.GetType().Assembly;
     if (rootActivity.Parent != null)
     {
         localAssembly = rootActivity.Parent.GetType().Assembly;
     }
     if ((rootActivity.Children != null) && (rootActivity.Children.Count > 0))
     {
         Activity instance = rootActivity.Children[0];
         string fileName = XamlDebuggerXmlReader.GetFileName(instance) as string;
         if (!string.IsNullOrEmpty(fileName))
         {
             rootActivity = instance;
             sourcePath = fileName;
         }
     }
     if (!string.IsNullOrEmpty(sourcePath))
     {
         SourceLocation location;
         Activity workflowRoot;
         if (TryGetSourceLocation(rootActivity, sourcePath, out location))
         {
             workflowRoot = rootActivity;
         }
         else
         {
             FileInfo info = new FileInfo(sourcePath);
             byte[] buffer = new byte[info.Length];
             using (FileStream stream = new FileStream(sourcePath, FileMode.Open, FileAccess.Read))
             {
                 stream.Read(buffer, 0, buffer.Length);
             }
             object obj2 = Deserialize(buffer, localAssembly);
             IDebuggableWorkflowTree tree = obj2 as IDebuggableWorkflowTree;
             if (tree != null)
             {
                 workflowRoot = tree.GetWorkflowRoot();
             }
             else
             {
                 workflowRoot = obj2 as Activity;
             }
         }
         Dictionary<object, SourceLocation> mapping = new Dictionary<object, SourceLocation>();
         if (workflowRoot != null)
         {
             CollectMapping(rootActivity, workflowRoot, mapping, sourcePath);
         }
         return mapping;
     }
     string tempFileName = Path.GetTempFileName();
     sourcePath = Path.ChangeExtension(tempFileName, ".xaml");
     File.Move(tempFileName, sourcePath);
     isTemporaryFile = true;
     return PublishAndCollectMapping(rootActivity, sourcePath);
 }
 private static Dictionary<object, SourceLocation> PublishAndCollectMapping(Activity activity, string path)
 {
     Dictionary<object, SourceLocation> mapping = new Dictionary<object, SourceLocation>();
     using (MemoryStream stream = new MemoryStream())
     {
         Serialize(stream, activity);
         stream.Position = 0L;
         Activity activity2 = Deserialize(stream.GetBuffer(), activity.GetType().Assembly) as Activity;
         using (StreamWriter writer = new StreamWriter(path))
         {
             stream.Position = 0L;
             using (StreamReader reader = new StreamReader(stream))
             {
                 writer.Write(reader.ReadToEnd());
             }
         }
         CollectMapping(activity, activity2, mapping, path);
     }
     return mapping;
 }
예제 #13
0
파일: PSActivity.cs 프로젝트: nickchal/pash
		internal static bool IsActivityInlineScript(Activity activity)
		{
			return string.Equals(activity.GetType().FullName, "Microsoft.PowerShell.Activities.InlineScript", StringComparison.OrdinalIgnoreCase);
		}
예제 #14
0
        /// <summary>
        /// Return activity has argment
        /// </summary>
        public static bool IsArgument(Activity arg)
        {
            Contract.Requires(arg != null);

               return (typeof(ActivityWithResult).IsAssignableFrom(arg.GetType()));
        }
예제 #15
0
		private bool ValidateActivity(Activity activity, string runtimeAssembly, PSWorkflowValidationResults validationResult)
		{
			bool flag;
			if (validationResult != null && !validationResult.IsWorkflowSuspendable)
			{
				validationResult.IsWorkflowSuspendable = this.CheckIfSuspendable(activity);
			}
			Type type = activity.GetType();
			if (Validation.CustomHandler == null || !Validation.CustomHandler(activity))
			{
				if (!string.Equals(type.Assembly.FullName, "System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35", StringComparison.OrdinalIgnoreCase))
				{
					if (!string.Equals(runtimeAssembly, type.Assembly.GetName().Name, StringComparison.OrdinalIgnoreCase))
					{
						if (!this.Configuration.PSDefaultActivitiesAreAllowed || !PSWorkflowValidator.PowerShellActivitiesAssemblies.Contains(type.Assembly.GetName().Name.ToLowerInvariant()))
						{
							IEnumerable<string> allowedActivity = this.Configuration.AllowedActivity;
							IEnumerable<string> strs = allowedActivity;
							if (allowedActivity == null)
							{
								strs = (IEnumerable<string>)(new string[0]);
							}
							foreach (string str in strs)
							{
								if (string.Equals(str, "PSDefaultActivities", StringComparison.OrdinalIgnoreCase) || activity == null || !PSWorkflowValidator.IsMatched(str, type.Name) && !PSWorkflowValidator.IsMatched(str, type.FullName) && !PSWorkflowValidator.IsMatched(str, string.Concat(type.Assembly.GetName().Name, "\\", type.Name)) && !PSWorkflowValidator.IsMatched(str, string.Concat(type.Assembly.GetName().Name, "\\", type.FullName)) && !PSWorkflowValidator.IsMatched(str, string.Concat(type.Assembly.GetName().FullName, "\\", type.Name)) && !PSWorkflowValidator.IsMatched(str, string.Concat(type.Assembly.GetName().FullName, "\\", type.FullName)))
								{
									continue;
								}
								flag = true;
								break;
							}
						}
						else
						{
							flag = true;
						}
					}
					else
					{
						flag = true;
					}
				}
				else
				{
					flag = PSWorkflowValidator.AllowedSystemActivities.Contains(type.Name);
				}
			}
			else
			{
				flag = true;
			}
			string displayName = activity.DisplayName;
			if (string.IsNullOrEmpty(displayName))
			{
				displayName = this.GetType().Name;
			}
			if (!flag)
			{
				PSWorkflowValidator._structuredTracer.WorkflowActivityValidationFailed(Guid.Empty, displayName, type.FullName);
			}
			else
			{
				PSWorkflowValidator._structuredTracer.WorkflowActivityValidated(Guid.Empty, displayName, type.FullName);
			}
			return flag;
		}
        static void AssertIsCodeActivity(Activity activity)
        {
            Type codeActivityOfTType = null;
            ActivityWithResult activityWithResult = activity as ActivityWithResult;

            if (activityWithResult != null)
            {
                codeActivityOfTType = typeof(CodeActivity <>).MakeGenericType(activityWithResult.ResultType);
            }
            Fx.Assert(activity is CodeActivity || (codeActivityOfTType != null && codeActivityOfTType.IsAssignableFrom(activity.GetType())), "Expected CodeActivity or CodeActivity<T>");
        }
 private static bool IsParallelActivity(Activity activity)
 {
     return ((activity is Parallel) || (activity.GetType().IsGenericType && (activity.GetType().GetGenericTypeDefinition() == typeof(ParallelForEach<>))));
 }