private async Task<ActivityPropertyProviders> CreatePropertyProviders(ICompositeActivityDefinition compositeActivityDefinition, CancellationToken cancellationToken) { var propertyProviders = new ActivityPropertyProviders(); var activityDefinitions = compositeActivityDefinition.Activities; foreach (var activityDefinition in activityDefinitions) { var activityType = await _activityTypeService.GetActivityTypeAsync(activityDefinition.Type, cancellationToken); var activityDescriptor = await activityType.DescribeAsync(); var propertyDescriptors = activityDescriptor.InputProperties; foreach (var property in activityDefinition.Properties) { var propertyDescriptor = propertyDescriptors.FirstOrDefault(x => x.Name == property.Name); if (propertyDescriptor == null) { _logger.LogWarning("Could not find the specified property '{PropertyName}' for activity type {ActivityTypeName}", property.Name, activityType.TypeName); continue; } var syntax = property.Syntax ?? propertyDescriptor.DefaultSyntax ?? SyntaxNames.Literal; var expression = property.GetExpression(syntax); var provider = new ExpressionActivityPropertyValueProvider(expression, syntax, propertyDescriptor.Type); propertyProviders.AddProvider(activityDefinition.ActivityId, property.Name, provider); } } return propertyProviders; }
private async Task AddActivityOutputAsync(Engine engine, ActivityExecutionContext activityExecutionContext, CancellationToken cancellationToken) { var workflowExecutionContext = activityExecutionContext.WorkflowExecutionContext; var workflowInstance = activityExecutionContext.WorkflowInstance; var workflowBlueprint = workflowExecutionContext.WorkflowBlueprint; var activities = new Dictionary <string, object>(); foreach (var activity in workflowBlueprint.Activities.Where(x => !string.IsNullOrWhiteSpace(x.Name))) { var activityType = await _activityTypeService.GetActivityTypeAsync(activity.Type, cancellationToken); var activityDescriptor = await _activityTypeService.DescribeActivityType(activityType, cancellationToken); var outputProperties = activityDescriptor.OutputProperties; var storageProviderLookup = activity.PropertyStorageProviders; var activityModel = new Dictionary <string, object?>(); var storageContext = new WorkflowStorageContext(workflowInstance, activity.Id); foreach (var property in outputProperties) { var propertyName = property.Name; var storageProviderName = storageProviderLookup.GetItem(propertyName) ?? property.DefaultWorkflowStorageProvider; activityModel[propertyName] = (Func <object?>)(() => _workflowStorageService.LoadAsync(storageProviderName, storageContext, propertyName, cancellationToken).Result); } activities[activity.Name !] = activityModel;
private async ValueTask <(Variables InputProperties, Variables OutputProperties)> GetActivityPropertiesAsync(IWorkflowBlueprintWrapper workflowBlueprintWrapper, IActivityBlueprintWrapper activityBlueprintWrapper, CancellationToken cancellationToken) { var activityBlueprint = activityBlueprintWrapper.ActivityBlueprint; var activityType = await _activityTypeService.GetActivityTypeAsync(activityBlueprint.Type, cancellationToken); var activityDescriptor = await _activityTypeService.DescribeActivityType(activityType, cancellationToken); var activityId = activityBlueprint.Id; var activityWrapper = workflowBlueprintWrapper.GetActivity(activityId) !; var inputProperties = new Variables(); var outputProperties = new Variables(); foreach (var property in activityDescriptor.InputProperties) { var value = await GetPropertyValueAsync(workflowBlueprintWrapper.WorkflowBlueprint, activityWrapper, property, cancellationToken); inputProperties.Set(property.Name, value); } foreach (var property in activityDescriptor.OutputProperties) { // Declare output properties to have at least a complete schema. outputProperties.Set(property.Name, null); } return(inputProperties, outputProperties); }
private Task AddDeclaredTypes(RenderingTypeScriptDefinitions notification, ActivityDefinition activity, ICollection <string> declaredTypes, CancellationToken cancellationToken) { var typeName = activity.Type; var schema = GetActivitySchema(activity); var targetType = GetActivityTargetType(activity); if (!string.IsNullOrWhiteSpace(schema)) { declaredTypes.Add($"{activity.Name}: {typeName}<{schema}>"); } else if (!string.IsNullOrWhiteSpace(targetType)) { declaredTypes.Add($"{activity.Name}: {typeName}<{targetType}>"); } declaredTypes.Add($"declare interface {typeName}<T>"); var activityType = _activityTypeService.GetActivityTypeAsync(typeName, cancellationToken).Result; var descriptor = activityType.DescribeAsync().Result; var inputProperties = descriptor.InputProperties; var outputProperties = descriptor.OutputProperties; foreach (var property in inputProperties) { RenderActivityProperty(notification, declaredTypes, typeName, property.Name, property.Type); } foreach (var property in outputProperties) { RenderActivityProperty(notification, declaredTypes, typeName, property.Name, property.Type); } return(Task.CompletedTask); }
public async Task Handle(RenderingTypeScriptDefinitions notification, CancellationToken cancellationToken) { var output = notification.Output; output.AppendLine("declare function guid(): string"); output.AppendLine("declare function parseGuid(text: string): Guid"); output.AppendLine("declare function setVariable(name: string, value?: any): void;"); output.AppendLine("declare function getVariable(name: string): any;"); output.AppendLine("declare function getConfig(section: string): any;"); output.AppendLine("declare function isNullOrWhiteSpace(text: string): boolean;"); output.AppendLine("declare function isNullOrEmpty(text: string): boolean;"); output.AppendLine("declare function getWorkflowDefinitionIdByName(name: string): string;"); output.AppendLine("declare function getWorkflowDefinitionIdByTag(tag: string): string;"); output.AppendLine("declare function getActivity(idOrName: string): any;"); output.AppendLine("declare function getActivityProperty(activityIdOrName: string, propertyName: string): any;"); output.AppendLine("declare const activityExecutionContext: ActivityExecutionContext;"); output.AppendLine("declare const workflowExecutionContext: WorkflowExecutionContext;"); output.AppendLine("declare const workflowInstance: WorkflowInstance;"); output.AppendLine("declare const workflowInstanceId: string;"); output.AppendLine("declare const workflowDefinitionId: string;"); output.AppendLine("declare const workflowDefinitionVersion: number;"); output.AppendLine("declare const correlationId: string;"); output.AppendLine("declare const currentCulture: CultureInfo;"); output.AppendLine("declare const input: any;"); var workflowDefinition = notification.WorkflowDefinition; if (workflowDefinition != null) { // Workflow Context var contextType = workflowDefinition.ContextOptions?.ContextType; if (contextType != null) { var workflowContextTypeScriptType = notification.GetTypeScriptType(contextType); output.AppendLine($"declare const workflowContext: {workflowContextTypeScriptType}"); } // Workflow Variables. foreach (var variable in workflowDefinition.Variables !.Data) { var variableType = variable.Value?.GetType() ?? typeof(object); var typeScriptType = notification.GetTypeScriptType(variableType); output.AppendLine($"declare const {variable.Key}: {typeScriptType}"); } // Named Activities. var namedActivities = workflowDefinition.Activities.Where(x => !string.IsNullOrWhiteSpace(x.Name)).ToList(); var activityTypeNames = namedActivities.Select(x => x.Type).Distinct().ToList(); var activityTypes = await Task.WhenAll(activityTypeNames.Select(async activityTypeName => (activityTypeName, await _activityTypeService.GetActivityTypeAsync(activityTypeName, cancellationToken)))); var activityTypeDictionary = activityTypes.ToDictionary(x => x.activityTypeName, x => x.Item2); foreach (var activityType in activityTypeDictionary.Values) { RenderActivityTypeDeclaration(activityType, output); } output.AppendLine("declare interface Activities {"); foreach (var activity in namedActivities) { var activityType = activityTypeDictionary[activity.Type]; var typeScriptType = activityType.TypeName; output.AppendLine($"{activity.Name}: {typeScriptType};"); } output.AppendLine("}"); output.AppendLine("declare const activities: Activities"); } void RenderActivityTypeDeclaration(ActivityType type, StringBuilder writer) { var typeName = type.TypeName; var descriptor = type.Describe(); var inputProperties = descriptor.InputProperties; var outputProperties = descriptor.OutputProperties; writer.AppendLine($"declare interface {typeName} {{"); foreach (var property in inputProperties) { RenderActivityProperty(writer, property.Name, property.Type); } foreach (var property in outputProperties) { RenderActivityProperty(writer, property.Name, property.Type); } writer.AppendLine("}"); } void RenderActivityProperty(StringBuilder writer, string propertyName, Type propertyType) { var typeScriptType = notification.GetTypeScriptType(propertyType); writer.AppendLine($"{propertyName}(): {typeScriptType};"); } }