public IDev2Activity Parse(DynamicActivity dynamicActivity, List<IDev2Activity> seenActivities)
        {
            try
            {
                var chart = WorkflowInspectionServices.GetActivities(dynamicActivity).FirstOrDefault() as Flowchart;
                if (chart != null)
                {
                    if (chart.StartNode == null)
                    {
                        return null;
                    }
                    var start = chart.StartNode as FlowStep;

                    if (start != null)
                    {
                        var tool = ParseTools(start, seenActivities);
                        return tool.FirstOrDefault();
                    }
                    var flowstart = chart.StartNode as FlowSwitch<string>;
                    if (flowstart != null)
                    {
                        return ParseSwitch(flowstart, seenActivities).FirstOrDefault();
                    }
                    var flowdec = chart.StartNode as FlowDecision;
                    return ParseDecision(flowdec, seenActivities).FirstOrDefault();
                }
                return null;
            }
            catch (InvalidWorkflowException e)
            {

                Dev2Logger.Log.Error(e);
                throw;
            }
        }
Exemplo n.º 2
0
            private void GetVariables(DynamicActivity act)
            {
                Variables = new List<string>();
                InspectActivity(act);


            }
      public IDev2Activity Parse(DynamicActivity activity,Guid resourceIdGuid,bool failOnException=false)
      {
          if(HasActivityInCache(resourceIdGuid))
          {
              return GetActivity(resourceIdGuid);
          }
          var dynamicActivity = activity;
          if (dynamicActivity != null)
          {
              try
              {
                  IDev2Activity act = _activityParser.Parse(dynamicActivity);
                  if (_cache.TryAdd(resourceIdGuid, act))
                  {
                      return act;
                  }
              }
                  // ReSharper disable EmptyGeneralCatchClause
              catch(Exception err) //errors caught inside
                  // ReSharper restore EmptyGeneralCatchClause
              {
                  Dev2Logger.Log.Error(err);
                  if(failOnException)
                  throw;
              }
 
          }
          return null;
      }
Exemplo n.º 4
0
        private List<string> GetArgumentsNames(DynamicActivity act)
        {
            List<string> names = new List<string>();
                if (act != null)
                {
                    act.Properties.Where(p => typeof(Argument).IsAssignableFrom(p.Type)).ToList().ForEach(dp =>
                    {
                        names.Add(dp.Name);
                    });

                }

                return names;
        }
Exemplo n.º 5
0
 public static WFRuleEngine Compile(RuleSet ruleSet)
 {
     if (ruleSet.IsValid())
     {
         var activity = new DynamicActivity();
         CompileInputs(activity, ruleSet);
         var implementation = CompileRules(ruleSet);
         activity.Implementation = () => implementation;
         return new WFRuleEngine(activity);
     }
     else
     {
         throw new Exception("RuleSet cannot be compiled.");
     }
 }
 public IDev2Activity Parse(DynamicActivity activity,Guid resourceIdGuid)
 {
     if(HasActivityInCache(resourceIdGuid))
     {
         return GetActivity(resourceIdGuid);
     }
     var dynamicActivity = activity;
     if (dynamicActivity != null)
     {
         IDev2Activity act = _activityParser.Parse(dynamicActivity);
         if (_cache.TryAdd(resourceIdGuid, act))
         {
             return act;
         }
     }
     return null;
 }
        internal static void ConvertActivityBuilderToDynamicActivity(ActivityBuilder activityBuilder, DynamicActivity bodyPlaceholder)
        {
            bodyPlaceholder.Name = activityBuilder.Name;
            bodyPlaceholder.Implementation = () => activityBuilder.Implementation;

            if (activityBuilder.Implementation != null)
            {
                VisualBasic.SetSettings(bodyPlaceholder, VisualBasic.GetSettings(activityBuilder));
            }

            bodyPlaceholder.Attributes.Clear();
            foreach (Attribute attribute in activityBuilder.Attributes)
            {
                bodyPlaceholder.Attributes.Add(attribute);
            }

            bodyPlaceholder.Properties.Clear();
            foreach (DynamicActivityProperty property in activityBuilder.Properties)
            {
                bodyPlaceholder.Properties.Add(property);
            }
        }
Exemplo n.º 8
0
		private void SortStartParameters(DynamicActivity dynamicActivity, CommandParameterCollection parameters)
		{
			uint num = 0;
			bool flag;
			bool flag1;
			string str;
			object baseObject;
			if (dynamicActivity == null)
			{
				flag = false;
			}
			else
			{
				flag = dynamicActivity.Properties.Contains("PSComputerName");
			}
			bool flag2 = flag;
			if (dynamicActivity == null)
			{
				flag1 = false;
			}
			else
			{
				flag1 = dynamicActivity.Properties.Contains("PSPrivateMetadata");
			}
			bool flag3 = flag1;
			this._jobMetadata.Add("WorkflowTakesPrivateMetadata", flag3);
			if (parameters != null)
			{
				foreach (CommandParameter parameter in parameters)
				{
					PowerShellTraceSource powerShellTraceSource = this._tracer;
					string str1 = "PSWorkflowJob";
					string str2 = "SortStartParameters";
					Guid workflowGuidForTraces = this.WorkflowGuidForTraces;
					PSWorkflowJob pSWorkflowJob = this;
					string str3 = "Found parameter; {0}; {1}";
					string[] name = new string[2];
					name[0] = parameter.Name;
					string[] strArrays = name;
					int num1 = 1;
					if (parameter.Value == null)
					{
						str = null;
					}
					else
					{
						str = parameter.Value.ToString();
					}
					strArrays[num1] = str;
					powerShellTraceSource.WriteMessage(str1, str2, workflowGuidForTraces, pSWorkflowJob, str3, name);
					string name1 = parameter.Name;
					string str4 = name1;
					if (name1 != null)
					{
						if (str4 == "PSComputerName")
						{
							if (!flag2)
							{
								string value = parameter.Value as string;
								this._location = value;
								string[] strArrays1 = LanguagePrimitives.ConvertTo<string[]>(parameter.Value);
								this._psWorkflowCommonParameters[parameter.Name] = strArrays1;
								PSSQMAPI.NoteWorkflowCommonParametersValues(parameter.Name, (int)strArrays1.Length);
								continue;
							}
							else
							{
								this._location = "localhost";
								this._workflowParameters[parameter.Name] = LanguagePrimitives.ConvertTo<string[]>(parameter.Value);
								continue;
							}
						}
						else if (str4 == "PSPrivateMetadata")
						{
							Hashtable hashtables = parameter.Value as Hashtable;
							if (hashtables == null)
							{
								continue;
							}
							IDictionaryEnumerator enumerator = hashtables.GetEnumerator();
							while (enumerator.MoveNext())
							{
								this._privateMetadata.Add(enumerator.Key.ToString(), enumerator.Value);
							}
							if (flag3)
							{
								this._workflowParameters.Add(parameter.Name, parameter.Value);
							}
							PSSQMAPI.NoteWorkflowCommonParametersValues(parameter.Name, hashtables.Count);
							continue;
						}
						else if (str4 == "PSInputCollection")
						{
							if (parameter.Value as PSObject != null)
							{
								baseObject = ((PSObject)parameter.Value).BaseObject;
							}
							else
							{
								baseObject = parameter.Value;
							}
							object obj = baseObject;
							if (obj as PSDataCollection<PSObject> == null)
							{
								PSDataCollection<PSObject> pSObjects = new PSDataCollection<PSObject>();
								IEnumerator enumerator1 = LanguagePrimitives.GetEnumerator(obj);
								if (enumerator1 == null)
								{
									pSObjects.Add(PSObject.AsPSObject(parameter.Value));
								}
								else
								{
									while (enumerator1.MoveNext())
									{
										pSObjects.Add(PSObject.AsPSObject(enumerator1.Current));
									}
								}
								this._inputCollection = pSObjects;
								continue;
							}
							else
							{
								this._inputCollection = obj as PSDataCollection<PSObject>;
								continue;
							}
						}
						else if (str4 == "PSParameterCollection")
						{
							continue;
						}
						else if (str4 == "PSRunningTimeoutSec" || str4 == "PSElapsedTimeoutSec" || str4 == "PSConnectionRetryCount" || str4 == "PSActionRetryCount" || str4 == "PSConnectionRetryIntervalSec" || str4 == "PSActionRetryIntervalSec")
						{
							this._psWorkflowCommonParameters.Add(parameter.Name, parameter.Value);
							if (!LanguagePrimitives.TryConvertTo<uint>(parameter.Value, out num))
							{
								continue;
							}
							PSSQMAPI.NoteWorkflowCommonParametersValues(parameter.Name, num);
							continue;
						}
						else if (str4 == "PSPersist" || str4 == "PSCredential" || str4 == "PSPort" || str4 == "PSUseSSL" || str4 == "PSConfigurationName" || str4 == "PSApplicationName" || str4 == "PSConnectionURI" || str4 == "PSSessionOption" || str4 == "PSAuthentication" || str4 == "PSAuthenticationLevel" || str4 == "PSCertificateThumbprint" || str4 == "PSAllowRedirection" || str4 == "Verbose" || str4 == "Debug" || str4 == "ErrorAction" || str4 == "WarningAction" || str4 == "PSWorkflowErrorAction")
						{
							this._psWorkflowCommonParameters.Add(parameter.Name, parameter.Value);
							PSSQMAPI.IncrementWorkflowCommonParameterPresent(parameter.Name);
							continue;
						}
						else if (str4 == "PSSenderInfo" || str4 == "PSWorkflowRoot" || str4 == "PSCurrentDirectory")
						{
							this._psWorkflowCommonParameters.Add(parameter.Name, parameter.Value);
							continue;
						}
					}
					this._workflowParameters.Add(parameter.Name, parameter.Value);
					if (parameter.Value == null)
					{
						continue;
					}
					PSSQMAPI.IncrementWorkflowSpecificParameterType(parameter.Value.GetType());
				}
			}
			this._psWorkflowCommonParameters.Add("WorkflowCommandName", this._definition.Command);
		}
Exemplo n.º 9
0
        private static void CompileInputs(DynamicActivity activity, RuleSet ruleSet)
        {
            var settings = new VisualBasicSettings();
            foreach (var input in ruleSet.Inputs)
            {
                var inProperty = new DynamicActivityProperty
                {
                    Name = input.Key,
                    Type = typeof(InArgument<>).MakeGenericType(input.Value)
                };
                activity.Properties.Add(inProperty);

                settings.ImportReferences.Add(new VisualBasicImportReference
                    {
                        Assembly = input.Value.Assembly.GetName().Name,
                        Import = input.Value.Namespace
                    });
            }
            VisualBasic.SetSettings(activity, settings);
        }
Exemplo n.º 10
0
 private WFRuleEngine(DynamicActivity activity)
 {
     _activity = activity;
 }
        public void WorkflowHelperCompileExpressionsWithActivityExpectedCompilesExpressionsAddsToCacheThenInvalidate()
        {
            const string ExpressionParams = "(\"\",AmbientDataList)";

            var fsa = new DsfFlowSwitchActivity
            {
                ExpressionText = GlobalConstants.InjectedSwitchDataFetchOld + ExpressionParams
            };
            var fda = new DsfFlowDecisionActivity
            {
                ExpressionText = GlobalConstants.InjectedDecisionHandlerOld + ExpressionParams
            };

            var startNode = new FlowStep { Action = new CommentActivityForTest() };
            var chart = new Flowchart { StartNode = startNode };
            chart.Nodes.Add(startNode);
            chart.Nodes.Add(new FlowDecision(fda));
            chart.Nodes.Add(new FlowSwitch<string> { Expression = fsa });


            var workflow = new DynamicActivity
            {
                Implementation = () => chart
            };
            var guid = Guid.NewGuid();
            new WorkflowHelper().CompileExpressions(workflow, guid);

            // No exception thrown means compilation worked

            var compiledExpressionRoot = CompiledExpressionInvoker.GetCompiledExpressionRootForImplementation(workflow) as ICompiledExpressionRoot;
            Assert.AreEqual(GlobalConstants.Resultscache.Count, 1);
            GlobalConstants.InvalidateCache(guid);
            Assert.AreEqual(GlobalConstants.Resultscache.Count, 0);
            Assert.IsNotNull(compiledExpressionRoot);
        }
        public void WorkflowHelperCompileExpressionsWithActivityNoNamespacesExpectedThrowsCompilerException()
        {
            var workflow = new DynamicActivity
            {
                Implementation = () => new WriteLine
                {
                    // ExpressionText MUST be use a class that is not been referenced!
                    Text = new CSharpValue<string>("Dev2.Runtime.Utilities.GenerateString(new Random(), 6)")
                }
            };

            new WorkflowHelper().CompileExpressions(workflow,Guid.NewGuid());
        }
        static DynamicActivity GetDynamicActivity(ActivityBuilder activityDefinition)
        {
            DynamicActivity result = new DynamicActivity
            {
                Name = activityDefinition.Name
            };
            foreach (DynamicActivityProperty property in activityDefinition.Properties)
            {
                result.Properties.Add(property);
            }
            foreach (Attribute attrib in activityDefinition.Attributes)
            {
                result.Attributes.Add(attrib);
            }
            foreach (Constraint constraint in activityDefinition.Constraints)
            {
                result.Constraints.Add(constraint);
            }
            result.Implementation = () => activityDefinition.Implementation;

            VisualBasicSettings vbsettings = VisualBasic.GetSettings(activityDefinition);
            if (vbsettings != null)
            {
                VisualBasic.SetSettings(result, vbsettings);
            }

            IList<string> namespacesForImplementation = TextExpression.GetNamespacesForImplementation(activityDefinition);
            if (namespacesForImplementation.Count > 0)
            {
                TextExpression.SetNamespacesForImplementation(result, namespacesForImplementation);
            }

            IList<AssemblyReference> referencesForImplementation = TextExpression.GetReferencesForImplementation(activityDefinition);
            if (referencesForImplementation.Count > 0)
            {
                TextExpression.SetReferencesForImplementation(result, referencesForImplementation);
            }

            return result;
        }
        public void WorkflowHelperCompileExpressionsWithActivityExpectedSetsNamespaces()
        {
            var activity = new DynamicActivity();
            new WorkflowHelper().CompileExpressions(activity,Guid.NewGuid());

            var impl = new AttachableMemberIdentifier(typeof(TextExpression), "NamespacesForImplementation");

            object property;
            AttachablePropertyServices.TryGetProperty(activity, impl, out property);

            var namespaces = property as List<string>;
            if(namespaces != null)
            {
                Assert.IsTrue(namespaces.SequenceEqual(ExpectedNamespaces));
            }
            else
            {
                Assert.Fail();
            }
        }
Exemplo n.º 15
0
        public static Activity getRuntimeActivityByDynamicActivity(DynamicActivity dynamicActivity)
        {
            IEnumerator<Activity> list = WorkflowInspectionServices.GetActivities(dynamicActivity).GetEnumerator();

            list.MoveNext();

            Activity runtimeActivity = list.Current;

            return runtimeActivity;
        }
        public void Eval(DynamicActivity flowchartProcess, Guid resourceID, IDSFDataObject dsfDataObject)
        {
            IDev2Activity resource = new ActivityParser().Parse(flowchartProcess);

            resource.Execute(dsfDataObject);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Create necessary dictionaries for WorkflowManager consumption based on StartParameters.
        /// </summary>
        private void SortStartParameters(DynamicActivity dynamicActivity, CommandParameterCollection parameters)
        {
            bool selfRemoting = dynamicActivity != null && dynamicActivity.Properties.Any(x => x.Name.Equals(Constants.ComputerName, StringComparison.CurrentCultureIgnoreCase));
            bool takesPSPrivateMetadata = dynamicActivity != null && dynamicActivity.Properties.Contains(Constants.PrivateMetadata);
            _jobMetadata.Add(Constants.WorkflowTakesPrivateMetadata, takesPSPrivateMetadata);

            if (parameters != null)
            {
                foreach (var parameter in parameters)
                {
                    _tracer.WriteMessage(ClassNameTrace, "SortStartParameters", WorkflowGuidForTraces, this, "Found parameter; {0}; {1}", parameter.Name,
                        parameter.Value == null ? null : parameter.Value.ToString());
                    switch (parameter.Name)
                    {
                        case Constants.ComputerName:
                            if (selfRemoting)
                            {
                                // If we're self-remoting, location becomes the default computer
                                // and the PSComputerNames is passed in as an argument instead
                                // of going to the ubiquitous parameters
                                _location = Constants.DefaultComputerName;
                                string parameterName = dynamicActivity.Properties.First(x => x.Name.Equals(Constants.ComputerName, StringComparison.CurrentCultureIgnoreCase)).Name;
                                _workflowParameters[parameterName] = LanguagePrimitives.ConvertTo<string[]>(parameter.Value);
                            }
                            else
                            {
                                // Set _location before adding parameter.
                                var computer = parameter.Value as string;
                                _location = computer;
                                string[] computerNames = LanguagePrimitives.ConvertTo<string[]>(parameter.Value);
                                _psWorkflowCommonParameters[parameter.Name] = computerNames;
                            }
                            break;
                        case Constants.PrivateMetadata:
                            Hashtable privateData = parameter.Value as Hashtable;
                            if (privateData != null)
                            {
                                IDictionaryEnumerator enumerator = privateData.GetEnumerator();
                                while (enumerator.MoveNext())
                                {
                                    _privateMetadata.Add(enumerator.Key.ToString(), enumerator.Value);
                                }

                                // Make the combined object available within the workflow as well...
                                if (takesPSPrivateMetadata)
                                {
                                    _workflowParameters.Add(parameter.Name, parameter.Value);
                                }
                            }
                            break;

                        case Constants.PSInputCollection:
                            {
                                // Remove the input collection so we can properly pass it to the workflow job
                                object baseObject = parameter.Value is PSObject
                                                        ? ((PSObject)parameter.Value).BaseObject
                                                        : parameter.Value;

                                if (baseObject is PSDataCollection<PSObject>)
                                {
                                    _inputCollection = baseObject as PSDataCollection<PSObject>;
                                }
                                else
                                {
                                    var inputCollection = new PSDataCollection<PSObject>();
                                    var e = LanguagePrimitives.GetEnumerator(baseObject);
                                    if (e != null)
                                    {
                                        while (e.MoveNext())
                                        {
                                            inputCollection.Add(PSObject.AsPSObject(e.Current));
                                        }
                                    }
                                    else
                                    {
                                        inputCollection.Add(PSObject.AsPSObject(parameter.Value));
                                    }
                                    _inputCollection = inputCollection;
                                }
                            }
                            break;

                        case Constants.PSParameterCollection:
                            // Remove this one from the parameter collection...
                            break;
                        case Constants.PSRunningTime:
                        case Constants.PSElapsedTime:
                        case Constants.ConnectionRetryCount:
                        case Constants.ActionRetryCount:
                        case Constants.ConnectionRetryIntervalSec:
                        case Constants.ActionRetryIntervalSec:
                            _psWorkflowCommonParameters.Add(parameter.Name, parameter.Value);
                            break;

                        case Constants.Persist:
                        case Constants.Credential:
                        case Constants.Port:
                        case Constants.UseSSL:
                        case Constants.ConfigurationName:
                        case Constants.ApplicationName:
                        case Constants.ConnectionURI:
                        case Constants.SessionOption:
                        case Constants.Authentication:
                        case Constants.AuthenticationLevel:
                        case Constants.CertificateThumbprint:
                        case Constants.AllowRedirection:
                        case Constants.Verbose:
                        case Constants.Debug:
                        case Constants.ErrorAction:
                        case Constants.WarningAction:
                        case Constants.InformationAction:
                        case Constants.PSWorkflowErrorAction:
                        case Constants.PSSuspendOnError:
                        case Constants.PSSenderInfo:
                        case Constants.ModulePath:
                        case Constants.PSCurrentDirectory:
                            // Note: We don't add ErrorVariable, WarningVariable, OutVariable, or OutBuffer
                            // here because they are interpreted by PowerShell in the function generated over
                            // the workflow definition.
                            _psWorkflowCommonParameters.Add(parameter.Name, parameter.Value);
                            break;
                        default:
                            _workflowParameters.Add(parameter.Name, parameter.Value);
                            break;
                    }
                }
            }

            // Add in the workflow command name...
            _psWorkflowCommonParameters.Add("WorkflowCommandName", _definition.Command);
        }
Exemplo n.º 18
0
 //得到[DynamicActivity]的Implementation
 public static Activity getImplementation(DynamicActivity dynamicActivity)
 {
     return dynamicActivity.Implementation();
 }
 internal static DynamicActivity ConvertToDynamicActivity(this ActivityBuilder activityBuilder)
 {
     DynamicActivity result = new DynamicActivity();
     ActivityBuilderExtensions.ConvertActivityBuilderToDynamicActivity(activityBuilder, result);
     return result;
 }
Exemplo n.º 20
0
        public void Eval(DynamicActivity flowchartProcess, IDSFDataObject dsfDataObject,int update)
        {
            IDev2Activity resource = new ActivityParser().Parse(flowchartProcess);

            EvalInner(dsfDataObject, resource, update);
        }
Exemplo n.º 21
0
 public IDev2Activity Parse(DynamicActivity dynamicActivity)
 {
     return Parse(dynamicActivity, new List<IDev2Activity>());
 }