Beispiel #1
0
        protected override void OnLoading(ElsaContext dbContext, WorkflowInstance entity)
        {
            var data = new
            {
                entity.Input,
                entity.Output,
                entity.Variables,
                entity.ActivityData,
                entity.Metadata,
                entity.BlockingActivities,
                entity.ScheduledActivities,
                entity.Scopes,
                entity.Fault,
                entity.CurrentActivity
            };

            var json = (string)dbContext.Entry(entity).Property("Data").CurrentValue;

            if (!string.IsNullOrWhiteSpace(json))
            {
                data = JsonConvert.DeserializeAnonymousType(json, data, DefaultContentSerializer.CreateDefaultJsonSerializationSettings()) !;
            }

            entity.Input               = data.Input;
            entity.Output              = data.Output;
            entity.Variables           = data.Variables;
            entity.ActivityData        = data.ActivityData;
            entity.Metadata            = data.Metadata;
            entity.BlockingActivities  = data.BlockingActivities;
            entity.ScheduledActivities = data.ScheduledActivities;
            entity.Scopes              = data.Scopes;
            entity.Fault               = data.Fault;
            entity.CurrentActivity     = data.CurrentActivity;
        }
        public IBus ConfigureServiceBus(IEnumerable <Type> messageTypes, string queueName)
        {
            queueName = ServiceBusOptions.FormatQueueName(queueName);
            var prefixedQueueName = PrefixQueueName(queueName);
            var messageTypeList   = messageTypes.ToList();
            var configurer        = Configure.With(_handlerActivator);
            var map = messageTypeList.ToDictionary(x => x, _ => prefixedQueueName);
            var configureContext = new ServiceBusEndpointConfigurationContext(configurer, prefixedQueueName, map, _serviceProvider);

            // Default options.
            configurer
            .Serialization(serializer => serializer.UseNewtonsoftJson(DefaultContentSerializer.CreateDefaultJsonSerializationSettings()))
            .Logging(l => l.MicrosoftExtensionsLogging(_loggerFactory))
            .Routing(r => r.TypeBased().Map(map))
            .Options(options => options.Apply(_elsaOptions.ServiceBusOptions));

            // Configure transport.
            _elsaOptions.ConfigureServiceBusEndpoint(configureContext);

            var newBus = configurer.Start();

            _serviceBuses.Add(prefixedQueueName, newBus);

            foreach (var messageType in messageTypeList)
            {
                _messageTypeQueueDictionary[messageType] = prefixedQueueName;
            }

            return(newBus);
        }
    protected override Task ExecuteAsync(CancellationToken stoppingToken)
    {
        var handlerActivator = new DependencyInjectionHandlerActivator(_serviceProvider);
        var configurer       = Configure.With(handlerActivator);

        configurer
        .Serialization(serializer => serializer.UseNewtonsoftJson(DefaultContentSerializer.CreateDefaultJsonSerializationSettings()))
        .Transport(transport => transport.UseAzureServiceBus(_configuration.GetConnectionString("AzureServiceBus"), "error"))
        .Routing(r =>
        {
            r.AddTransportMessageForwarder(transportMessage =>
            {
                var returnAddress = transportMessage.Headers[Headers.SourceQueue];

                if (returnAddress.Contains("workflow-management-events"))
                {
                    return(Task.FromResult(ForwardAction.Ignore()));
                }

                return(Task.FromResult(ForwardAction.ForwardTo(returnAddress)));
            });
        });

        var bus = configurer.Start();

        return(Task.CompletedTask);
    }
Beispiel #4
0
    public override void WriteJson(JsonWriter writer, object?value, JsonSerializer serializer)
    {
        var variables = (Variables)(value ?? new Variables());
        var variablesSerializerSettings = DefaultContentSerializer.CreateDefaultJsonSerializationSettings();

        variablesSerializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.None;
        var json = JsonConvert.SerializeObject(variables.Data, Formatting.Indented, variablesSerializerSettings);

        serializer.Serialize(writer, json);
    }
Beispiel #5
0
        public static JsonSerializerSettings GetSettingsForWorkflowDefinition()
        {
            // Here we don't want to use the `PreserveReferencesHandling` setting because the model will be used by the designer "as-is" and will not resolve $id references.
            // Fixes #1605.
            var settings = DefaultContentSerializer.CreateDefaultJsonSerializationSettings();

            settings.PreserveReferencesHandling = PreserveReferencesHandling.None;

            return(settings);
        }
        public override void OnActionExecuted(ActionExecutedContext context)
        {
            if (context.Result is ObjectResult objectResult)
            {
                var services           = context.HttpContext.RequestServices;
                var serializerSettings = DefaultContentSerializer.CreateDefaultJsonSerializationSettings();

                objectResult.Formatters.RemoveType <SystemTextJsonOutputFormatter>();
                objectResult.Formatters.Add(new NewtonsoftJsonOutputFormatter(
                                                serializerSettings,
                                                services.GetRequiredService <ArrayPool <char> >(),
                                                services.GetRequiredService <IOptions <MvcOptions> >().Value));
            }
            else
            {
                base.OnActionExecuted(context);
            }
        }
Beispiel #7
0
        internal ElsaOptions()
        {
            WorkflowDefinitionStoreFactory       = sp => ActivatorUtilities.CreateInstance <InMemoryWorkflowDefinitionStore>(sp);
            WorkflowInstanceStoreFactory         = sp => ActivatorUtilities.CreateInstance <InMemoryWorkflowInstanceStore>(sp);
            WorkflowExecutionLogStoreFactory     = sp => ActivatorUtilities.CreateInstance <InMemoryWorkflowExecutionLogStore>(sp);
            WorkflowTriggerStoreFactory          = sp => ActivatorUtilities.CreateInstance <InMemoryBookmarkStore>(sp);
            WorkflowDefinitionDispatcherFactory  = sp => ActivatorUtilities.CreateInstance <QueuingWorkflowDispatcher>(sp);
            WorkflowInstanceDispatcherFactory    = sp => ActivatorUtilities.CreateInstance <QueuingWorkflowDispatcher>(sp);
            CorrelatingWorkflowDispatcherFactory = sp => ActivatorUtilities.CreateInstance <QueuingWorkflowDispatcher>(sp);
            JsonSerializerConfigurer             = (sp, serializer) => { };
            DefaultWorkflowStorageProviderType   = typeof(WorkflowInstanceWorkflowStorageProvider);
            DistributedLockingOptions            = new DistributedLockingOptions();
            ConfigureServiceBusEndpoint          = ConfigureInMemoryServiceBusEndpoint;

            CreateJsonSerializer = sp =>
            {
                var serializer = DefaultContentSerializer.CreateDefaultJsonSerializer();
                JsonSerializerConfigurer(sp, serializer);
                return(serializer);
            };
        }
        protected override void OnLoading(ElsaContext dbContext, WorkflowDefinition entity)
        {
            var data = new
            {
                entity.Activities,
                entity.Connections,
                entity.Variables,
                entity.ContextOptions,
                entity.CustomAttributes
            };

            var json = (string)dbContext.Entry(entity).Property("Data").CurrentValue;

            data = JsonConvert.DeserializeAnonymousType(json, data, DefaultContentSerializer.CreateDefaultJsonSerializationSettings());

            entity.Activities       = data.Activities;
            entity.Connections      = data.Connections;
            entity.Variables        = data.Variables;
            entity.ContextOptions   = data.ContextOptions;
            entity.CustomAttributes = data.CustomAttributes;
        }
Beispiel #9
0
        private static IInputFormatter[] GetInputFormatters(
            ILoggerFactory loggerFactory,
            ArrayPool <char> charPool,
            ObjectPoolProvider objectPoolProvider,
            IOptions <MvcOptions> mvcOptions,
            IOptions <MvcNewtonsoftJsonOptions> jsonOptions)
        {
            var jsonOptionsValue   = jsonOptions.Value;
            var serializerSettings = DefaultContentSerializer.CreateDefaultJsonSerializationSettings();

            return(new IInputFormatter[]
            {
                new NewtonsoftJsonInputFormatter(
                    loggerFactory.CreateLogger <ElsaJsonBodyModelBinder>(),
                    serializerSettings,
                    charPool,
                    objectPoolProvider,
                    mvcOptions.Value,
                    jsonOptionsValue)
            });
        }
Beispiel #10
0
        private async Task WriteContentAsync(CancellationToken cancellationToken)
        {
            var httpContext = _httpContextAccessor.HttpContext ?? new DefaultHttpContext();
            var response    = httpContext.Response;

            var content = Content;

            if (content == null)
            {
                return;
            }

            if (content is string stringContent)
            {
                if (!string.IsNullOrWhiteSpace(stringContent))
                {
                    await response.WriteAsync(stringContent, cancellationToken);
                }

                return;
            }

            if (content is Stream stream)
            {
                content = await stream.ReadBytesToEndAsync(cancellationToken);
            }

            if (content is byte[] buffer)
            {
                await response.Body.WriteAsync(buffer, cancellationToken);

                return;
            }

            var json = JsonConvert.SerializeObject(content, DefaultContentSerializer.CreateDefaultJsonSerializationSettings());
            await response.WriteAsync(json, cancellationToken);
        }
Beispiel #11
0
 public BlobStorageWorkflowStorageProvider(IOptions <BlobStorageWorkflowStorageProviderOptions> options)
 {
     _blobStorage        = options.Value.BlobStorageFactory();
     _serializerSettings = DefaultContentSerializer.CreateDefaultJsonSerializationSettings();
     _serializerSettings.TypeNameHandling = TypeNameHandling.All;
 }
Beispiel #12
0
 public BlobStorageWorkflowStorageProvider(IBlobStorage blobStorage)
 {
     _blobStorage        = blobStorage;
     _serializerSettings = DefaultContentSerializer.CreateDefaultJsonSerializationSettings();
     _serializerSettings.TypeNameHandling = TypeNameHandling.All;
 }