public ValidationResults ValidateWorkflow(Activity workflow, string runtimeAssembly) { PSWorkflowValidationResults pSWorkflowValidationResult = new PSWorkflowValidationResults(); this.ValidateWorkflowInternal(workflow, runtimeAssembly, pSWorkflowValidationResult); return(pSWorkflowValidationResult.Results); }
/// <summary> /// Validate the workflow, if it is using the allowed activities. /// </summary> /// <param name="workflow">The workflow, which needs to be validated.</param> /// <param name="runtimeAssembly">The additional runtime assembly, which is needed in validation process.</param> public ValidationResults ValidateWorkflow(Activity workflow, string runtimeAssembly) { PSWorkflowValidationResults validationResults = new PSWorkflowValidationResults(); ValidateWorkflowInternal(workflow, runtimeAssembly, validationResults); return(validationResults.Results); }
internal PSWorkflowValidationResults ValidateWorkflow(Guid referenceId, Activity workflow, string runtimeAssembly) { PSWorkflowValidationResults pSWorkflowValidationResult = null; if (!this._validationCache.ContainsKey(referenceId)) { pSWorkflowValidationResult = new PSWorkflowValidationResults(); this.ValidateWorkflowInternal(workflow, runtimeAssembly, pSWorkflowValidationResult); if (this._validationCache.Keys.Count == this.Configuration.ValidationCacheLimit) { this._validationCache.Clear(); } this._validationCache.TryAdd(referenceId, pSWorkflowValidationResult); } else { this._validationCache.TryGetValue(referenceId, out pSWorkflowValidationResult); } return(pSWorkflowValidationResult); }
private Constraint ValidateActivitiesConstraint(string runtimeAssembly, PSWorkflowValidationResults validationResults) { var activityToValidate = new DelegateInArgument <Activity>(); DelegateInArgument <ValidationContext> delegateInArgument1 = new DelegateInArgument <ValidationContext>(); Constraint <Activity> constraint = new Constraint <Activity>(); ActivityAction <Activity, ValidationContext> activityAction = new ActivityAction <Activity, ValidationContext>(); activityAction.Argument1 = activityToValidate; activityAction.Argument2 = delegateInArgument1; AssertValidation assertValidation = new AssertValidation(); assertValidation.IsWarning = false; ParameterExpression parameterExpression = Expression.Parameter(typeof(ActivityContext), "env"); Expression[] expressionArray = new Expression[3]; Expression[] expressionArray1 = new Expression[1]; expressionArray1[0] = parameterExpression; expressionArray[0] = Expression.Call(Expression.Field(Expression.Constant(this), FieldInfo.GetFieldFromHandle(activityToValidate)), (MethodInfo)MethodBase.GetMethodFromHandle(Get, DelegateInArgument <Activity>), expressionArray1); expressionArray[1] = Expression.Field(Expression.Constant(this), FieldInfo.GetFieldFromHandle(runtimeAssembly)); expressionArray[2] = Expression.Field(Expression.Constant(this), FieldInfo.GetFieldFromHandle(validationResults)); ParameterExpression[] parameterExpressionArray = new ParameterExpression[1]; parameterExpressionArray[0] = parameterExpression; assertValidation.Assertion = new InArgument <bool>(Expression.Lambda <Func <ActivityContext, bool> >(Expression.Call(Expression.Constant(this, typeof(PSWorkflowValidator)), (MethodInfo)MethodBase.GetMethodFromHandle(ValidateActivity), expressionArray), parameterExpressionArray)); ParameterExpression parameterExpression1 = Expression.Parameter(typeof(ActivityContext), "env"); Expression[] expressionArray2 = new Expression[3]; expressionArray2[0] = Expression.Property(null, typeof(CultureInfo).GetProperty("CurrentCulture", BindingFlags.Static)); //TODO: REIVEW: (MethodInfo)MethodBase.GetMethodFromHandle(CultureInfo.get_CurrentCulture)); expressionArray2[1] = Expression.Property(null, typeof(Resources).GetProperty("InvalidActivity", BindingFlags.Static)); //TODO: REVIEW: (MethodInfo)MethodBase.GetMethodFromHandle(Resources.get_InvalidActivity)); Expression[] expressionArray3 = new Expression[1]; Expression[] expressionArray4 = new Expression[1]; expressionArray4[0] = parameterExpression1; expressionArray3[0] = Expression.Property(Expression.Call(Expression.Call(Expression.Field(Expression.Constant(this), FieldInfo.GetFieldFromHandle(PSWorkflowValidator.PSWorkflowValidator.activityToValidate)), (MethodInfo)MethodBase.GetMethodFromHandle(Get, DelegateInArgument <Activity>), expressionArray4), (MethodInfo)MethodBase.GetMethodFromHandle(GetType), new Expression[0]), (MethodInfo)MethodBase.GetMethodFromHandle(get_FullName)); expressionArray2[2] = Expression.NewArrayInit(typeof(object), expressionArray3); ParameterExpression[] parameterExpressionArray1 = new ParameterExpression[1]; parameterExpressionArray1[0] = parameterExpression1; assertValidation.Message = new InArgument <string>(Expression.Lambda <Func <ActivityContext, string> >(Expression.Call(null, (MethodInfo)MethodBase.GetMethodFromHandle(string.Format), expressionArray2), parameterExpressionArray1)); activityAction.Handler = assertValidation; constraint.Body = activityAction; return(constraint); }
private Constraint ValidateActivitiesConstraint(string runtimeAssembly, PSWorkflowValidationResults validationResults) { DelegateInArgument <Activity> activityToValidate = new DelegateInArgument <Activity>(); DelegateInArgument <ValidationContext> validationContext = new DelegateInArgument <ValidationContext>(); return(new Constraint <Activity> { Body = new ActivityAction <Activity, ValidationContext> { Argument1 = activityToValidate, Argument2 = validationContext, Handler = new AssertValidation { IsWarning = false, Assertion = new InArgument <bool>( env => ValidateActivity(activityToValidate.Get(env), runtimeAssembly, validationResults)), Message = new InArgument <string>( env => string.Format(CultureInfo.CurrentCulture, Resources.InvalidActivity, activityToValidate.Get(env).GetType().FullName)) } } }); }
internal PSWorkflowValidationResults ValidateWorkflow(Guid referenceId, Activity workflow, string runtimeAssembly) { PSWorkflowValidationResults validationResults = null; if (_validationCache.ContainsKey(referenceId)) { _validationCache.TryGetValue(referenceId, out validationResults); } else { validationResults = new PSWorkflowValidationResults(); this.ValidateWorkflowInternal(workflow, runtimeAssembly, validationResults); // sanity check to ensure cache isn't growing unbounded if (_validationCache.Keys.Count == Configuration.ValidationCacheLimit) { _validationCache.Clear(); } _validationCache.TryAdd(referenceId, validationResults); } return(validationResults); }
internal PSWorkflowValidationResults ValidateWorkflow(Guid referenceId, Activity workflow, string runtimeAssembly) { PSWorkflowValidationResults validationResults = null; if (_validationCache.ContainsKey(referenceId)) { _validationCache.TryGetValue(referenceId, out validationResults); } else { validationResults = new PSWorkflowValidationResults(); this.ValidateWorkflowInternal(workflow, runtimeAssembly, validationResults); // sanity check to ensure cache isn't growing unbounded if (_validationCache.Keys.Count == Configuration.ValidationCacheLimit) { _validationCache.Clear(); } _validationCache.TryAdd(referenceId, validationResults); } return validationResults; }
/// <summary> /// Validate the workflow, if it is using the allowed activities. /// </summary> /// <param name="workflow">The workflow, which needs to be validated.</param> /// <param name="runtimeAssembly">The additional runtime assembly, which is needed in validation process.</param> public ValidationResults ValidateWorkflow(Activity workflow, string runtimeAssembly) { PSWorkflowValidationResults validationResults = new PSWorkflowValidationResults(); ValidateWorkflowInternal(workflow, runtimeAssembly, validationResults); return validationResults.Results; }
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; }
private Constraint ValidateActivitiesConstraint(string runtimeAssembly, PSWorkflowValidationResults validationResults) { DelegateInArgument<Activity> activityToValidate = new DelegateInArgument<Activity>(); DelegateInArgument<ValidationContext> validationContext = new DelegateInArgument<ValidationContext>(); return new Constraint<Activity> { Body = new ActivityAction<Activity, ValidationContext> { Argument1 = activityToValidate, Argument2 = validationContext, Handler = new AssertValidation { IsWarning = false, Assertion = new InArgument<bool>( env => ValidateActivity(activityToValidate.Get(env), runtimeAssembly, validationResults)), Message = new InArgument<string>( env => string.Format(CultureInfo.CurrentCulture, Resources.InvalidActivity, activityToValidate.Get(env).GetType().FullName)) } } }; }
private void ValidateWorkflowInternal(Activity workflow, string runtimeAssembly, PSWorkflowValidationResults validationResults) { PSWorkflowValidator.Tracer.WriteMessage(string.Concat(PSWorkflowValidator.Facility, "Validating a workflow.")); PSWorkflowValidator._structuredTracer.WorkflowValidationStarted(Guid.Empty); ValidationSettings validationSetting = new ValidationSettings(); List <Constraint> constraints = new List <Constraint>(); constraints.Add(this.ValidateActivitiesConstraint(runtimeAssembly, validationResults)); validationSetting.AdditionalConstraints.Add(typeof(Activity), constraints); ValidationSettings validationSetting1 = validationSetting; try { validationResults.Results = ActivityValidationServices.Validate(workflow, validationSetting1); } catch (Exception exception1) { Exception exception = exception1; PSWorkflowValidator.Tracer.TraceException(exception); new ValidationException(Resources.ErrorWhileValidatingWorkflow, exception); throw exception; } PSWorkflowValidator._structuredTracer.WorkflowValidationFinished(Guid.Empty); }
internal PSWorkflowValidationResults ValidateWorkflow(Guid referenceId, Activity workflow, string runtimeAssembly) { PSWorkflowValidationResults pSWorkflowValidationResult = null; if (!this._validationCache.ContainsKey(referenceId)) { pSWorkflowValidationResult = new PSWorkflowValidationResults(); this.ValidateWorkflowInternal(workflow, runtimeAssembly, pSWorkflowValidationResult); if (this._validationCache.Keys.Count == this.Configuration.ValidationCacheLimit) { this._validationCache.Clear(); } this._validationCache.TryAdd(referenceId, pSWorkflowValidationResult); } else { this._validationCache.TryGetValue(referenceId, out pSWorkflowValidationResult); } return pSWorkflowValidationResult; }
public ValidationResults ValidateWorkflow(Activity workflow, string runtimeAssembly) { PSWorkflowValidationResults pSWorkflowValidationResult = new PSWorkflowValidationResults(); this.ValidateWorkflowInternal(workflow, runtimeAssembly, pSWorkflowValidationResult); return pSWorkflowValidationResult.Results; }
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; }
private Constraint ValidateActivitiesConstraint(string runtimeAssembly, PSWorkflowValidationResults validationResults) { var activityToValidate = new DelegateInArgument<Activity>(); DelegateInArgument<ValidationContext> delegateInArgument1 = new DelegateInArgument<ValidationContext>(); Constraint<Activity> constraint = new Constraint<Activity>(); ActivityAction<Activity, ValidationContext> activityAction = new ActivityAction<Activity, ValidationContext>(); activityAction.Argument1 = activityToValidate; activityAction.Argument2 = delegateInArgument1; AssertValidation assertValidation = new AssertValidation(); assertValidation.IsWarning = false; ParameterExpression parameterExpression = Expression.Parameter(typeof(ActivityContext), "env"); Expression[] expressionArray = new Expression[3]; Expression[] expressionArray1 = new Expression[1]; expressionArray1[0] = parameterExpression; expressionArray[0] = Expression.Call(Expression.Field(Expression.Constant(this), FieldInfo.GetFieldFromHandle(activityToValidate)), (MethodInfo)MethodBase.GetMethodFromHandle(Get, DelegateInArgument<Activity>), expressionArray1); expressionArray[1] = Expression.Field(Expression.Constant(this), FieldInfo.GetFieldFromHandle(runtimeAssembly)); expressionArray[2] = Expression.Field(Expression.Constant(this), FieldInfo.GetFieldFromHandle(validationResults)); ParameterExpression[] parameterExpressionArray = new ParameterExpression[1]; parameterExpressionArray[0] = parameterExpression; assertValidation.Assertion = new InArgument<bool>(Expression.Lambda<Func<ActivityContext, bool>>(Expression.Call(Expression.Constant(this, typeof(PSWorkflowValidator)), (MethodInfo)MethodBase.GetMethodFromHandle(ValidateActivity), expressionArray), parameterExpressionArray)); ParameterExpression parameterExpression1 = Expression.Parameter(typeof(ActivityContext), "env"); Expression[] expressionArray2 = new Expression[3]; expressionArray2[0] = Expression.Property(null, typeof(CultureInfo).GetProperty ("CurrentCulture", BindingFlags.Static)); //TODO: REIVEW: (MethodInfo)MethodBase.GetMethodFromHandle(CultureInfo.get_CurrentCulture)); expressionArray2[1] = Expression.Property(null, typeof(Resources).GetProperty ("InvalidActivity", BindingFlags.Static)); //TODO: REVIEW: (MethodInfo)MethodBase.GetMethodFromHandle(Resources.get_InvalidActivity)); Expression[] expressionArray3 = new Expression[1]; Expression[] expressionArray4 = new Expression[1]; expressionArray4[0] = parameterExpression1; expressionArray3[0] = Expression.Property(Expression.Call(Expression.Call(Expression.Field(Expression.Constant(this), FieldInfo.GetFieldFromHandle(PSWorkflowValidator.PSWorkflowValidator.activityToValidate)), (MethodInfo)MethodBase.GetMethodFromHandle(Get, DelegateInArgument<Activity>), expressionArray4), (MethodInfo)MethodBase.GetMethodFromHandle(GetType), new Expression[0]), (MethodInfo)MethodBase.GetMethodFromHandle(get_FullName)); expressionArray2[2] = Expression.NewArrayInit(typeof(object), expressionArray3); ParameterExpression[] parameterExpressionArray1 = new ParameterExpression[1]; parameterExpressionArray1[0] = parameterExpression1; assertValidation.Message = new InArgument<string>(Expression.Lambda<Func<ActivityContext, string>>(Expression.Call(null, (MethodInfo)MethodBase.GetMethodFromHandle(string.Format), expressionArray2), parameterExpressionArray1)); activityAction.Handler = assertValidation; constraint.Body = activityAction; return constraint; }
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); }
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); }
private void ValidateWorkflowInternal(Activity workflow, string runtimeAssembly, PSWorkflowValidationResults validationResults) { PSWorkflowValidator.Tracer.WriteMessage(string.Concat(PSWorkflowValidator.Facility, "Validating a workflow.")); PSWorkflowValidator._structuredTracer.WorkflowValidationStarted(Guid.Empty); ValidationSettings validationSetting = new ValidationSettings(); List<Constraint> constraints = new List<Constraint>(); constraints.Add(this.ValidateActivitiesConstraint(runtimeAssembly, validationResults)); validationSetting.AdditionalConstraints.Add(typeof(Activity), constraints); ValidationSettings validationSetting1 = validationSetting; try { validationResults.Results = ActivityValidationServices.Validate(workflow, validationSetting1); } catch (Exception exception1) { Exception exception = exception1; PSWorkflowValidator.Tracer.TraceException(exception); new ValidationException(Resources.ErrorWhileValidatingWorkflow, exception); throw exception; } PSWorkflowValidator._structuredTracer.WorkflowValidationFinished(Guid.Empty); }
private Activity ValidateWorkflow(JobInvocationInfo invocationInfo, Activity activity, ref bool?isSuspendable) { bool flag = false; PSWorkflowRuntime instance = PSWorkflowRuntime.Instance; JobDefinition definition = invocationInfo.Definition; WorkflowJobDefinition workflowJobDefinition = WorkflowJobDefinition.AsWorkflowJobDefinition(definition); bool flag1 = true; if (activity == null) { activity = DefinitionCache.Instance.GetActivityFromCache(workflowJobDefinition, out flag); if (activity != null) { flag1 = false; if (flag) { return(activity); } } else { throw new InvalidOperationException(); } } if (instance.Configuration.EnableValidation) { if (!flag1 || DefinitionCache.Instance.AllowExternalActivity) { PSWorkflowValidationResults pSWorkflowValidationResult = this.GetWorkflowValidator().ValidateWorkflow(definition.InstanceId, activity, DefinitionCache.Instance.GetRuntimeAssemblyName(workflowJobDefinition)); if (pSWorkflowValidationResult.Results != null) { this.GetWorkflowValidator().ProcessValidationResults(pSWorkflowValidationResult.Results); } isSuspendable = new bool?(pSWorkflowValidationResult.IsWorkflowSuspendable); return(activity); } else { if (Validation.CustomHandler != null) { if (!Validation.CustomHandler(activity)) { string displayName = activity.DisplayName; if (string.IsNullOrEmpty(displayName)) { displayName = base.GetType().Name; } object[] objArray = new object[1]; objArray[0] = displayName; string str = string.Format(CultureInfo.CurrentCulture, Resources.InvalidActivity, objArray); throw new ValidationException(str); } else { return(activity); } } else { throw new InvalidOperationException(); } } } else { return(activity); } }
private void ValidateWorkflowInternal(Activity workflow, string runtimeAssembly, PSWorkflowValidationResults validationResults) { Tracer.WriteMessage(Facility + "Validating a workflow."); _structuredTracer.WorkflowValidationStarted(Guid.Empty); ValidationSettings validationSettings = new ValidationSettings { AdditionalConstraints = { { typeof(Activity), new List<Constraint> { ValidateActivitiesConstraint(runtimeAssembly, validationResults)} } } }; try { validationResults.Results = ActivityValidationServices.Validate(workflow, validationSettings); } catch (Exception e) { Tracer.TraceException(e); ValidationException exception = new ValidationException(Resources.ErrorWhileValidatingWorkflow, e); throw exception; } _structuredTracer.WorkflowValidationFinished(Guid.Empty); }
private Activity ValidateWorkflow(JobInvocationInfo invocationInfo, Activity activity, ref bool?isSuspendable) { PSWorkflowRuntime runtime = PSWorkflowRuntime.Instance; JobDefinition definition = invocationInfo.Definition; WorkflowJobDefinition workflowJobDefinition = WorkflowJobDefinition.AsWorkflowJobDefinition(definition); bool externalActivity = true; if (activity == null) { bool windowsWorkflow; activity = DefinitionCache.Instance.GetActivityFromCache(workflowJobDefinition, out windowsWorkflow); // Debug.Assert(activity != null, "WorkflowManager failed validation for a null activity"); if (activity == null) { throw new InvalidOperationException(); } externalActivity = false; // skip validation if it is a windows workflow if (windowsWorkflow) { return(activity); } } // If validation is disabled, just return the activity as is... if (!runtime.Configuration.EnableValidation) { return(activity); } if (externalActivity && !DefinitionCache.Instance.AllowExternalActivity) { // If there is a custom validator activity, then call it. If it returns true // then just return the activity. if (Validation.CustomHandler == null) { throw new InvalidOperationException(); } if (Validation.CustomHandler.Invoke(activity)) { return(activity); } string displayName = activity.DisplayName; if (string.IsNullOrEmpty(displayName)) { displayName = this.GetType().Name; } string message = string.Format(CultureInfo.CurrentCulture, Resources.InvalidActivity, displayName); throw new ValidationException(message); } PSWorkflowValidationResults validationResults = GetWorkflowValidator().ValidateWorkflow( definition.InstanceId, activity, DefinitionCache.Instance.GetRuntimeAssemblyName(workflowJobDefinition)); if (validationResults.Results != null) { GetWorkflowValidator().ProcessValidationResults(validationResults.Results); } isSuspendable = validationResults.IsWorkflowSuspendable; return(activity); }
private void ValidateWorkflowInternal(Activity workflow, string runtimeAssembly, PSWorkflowValidationResults validationResults) { Tracer.WriteMessage(Facility + "Validating a workflow."); _structuredTracer.WorkflowValidationStarted(Guid.Empty); ValidationSettings validationSettings = new ValidationSettings { AdditionalConstraints = { { typeof(Activity), new List <Constraint> { ValidateActivitiesConstraint(runtimeAssembly, validationResults) } } } }; try { validationResults.Results = ActivityValidationServices.Validate(workflow, validationSettings); } catch (Exception e) { Tracer.TraceException(e); ValidationException exception = new ValidationException(Resources.ErrorWhileValidatingWorkflow, e); throw exception; } _structuredTracer.WorkflowValidationFinished(Guid.Empty); }