public async Task <OpenApiResult> CreateNotificationsAsync(
            IOpenApiContext context,
            CreateNotificationsRequest body)
        {
            // We can guarantee tenant Id is available because it's part of the Uri.
            ITenant tenant = await this.marainServicesTenancy.GetRequestingTenantAsync(context.CurrentTenantId !).ConfigureAwait(false);

            string delegatedTenantId = await this.marainServicesTenancy.GetDelegatedTenantIdForRequestingTenantAsync(tenant.Id).ConfigureAwait(false);

            var operationId = Guid.NewGuid();
            CreateOperationHeaders response = await this.operationsControlClient.CreateOperationAsync(
                delegatedTenantId,
                operationId).ConfigureAwait(false);

            // Create a new CreateNotificationForDeliveryChannelsRequest Object which supports the communication types and delivery channels
            var createNotificationForDeliveryChannelsRequestObject = new CreateNotificationForDeliveryChannelsRequest(
                body.NotificationType,
                body.UserIds,
                body.Timestamp,
                body.Properties,
                body.CorrelationIds);

            IDurableOrchestrationClient orchestrationClient = context.AsDurableFunctionsOpenApiContext().OrchestrationClient
                                                              ?? throw new OpenApiServiceMismatchException($"Operation {CreateNotificationsOperationId} has been invoked, but no Durable Orchestration Client is available on the OpenApi context.");

            await orchestrationClient.StartNewAsync(
                nameof(CreateAndDispatchNotificationsOrchestration),
                new TenantedFunctionData <CreateNotificationForDeliveryChannelsRequest>(context.CurrentTenantId !, createNotificationForDeliveryChannelsRequestObject, operationId)).ConfigureAwait(false);

            return(this.AcceptedResult(response.Location));
        }
Exemple #2
0
        public async Task <OpenApiResult> HandleTrigger(IOpenApiContext context, IWorkflowTrigger body)
        {
            ITenant tenant = await this.marainServicesTenancy.GetRequestingTenantAsync(context.CurrentTenantId).ConfigureAwait(false);

            string delegatedTenantId = await this.marainServicesTenancy.GetDelegatedTenantIdForRequestingTenantAsync(tenant.Id).ConfigureAwait(false);

            var operationId = Guid.NewGuid();
            CreateOperationHeaders operationHeaders =
                await this.operationsControl.CreateOperationAsync(delegatedTenantId, operationId).ConfigureAwait(false);

            var envelope = new WorkflowMessageEnvelope(this.propertyBagFactory.Create(PropertyBagValues.Empty))
            {
                Trigger     = body,
                OperationId = operationId,
                TenantId    = context.CurrentTenantId,
            };

            var durableFunctionsOpenApiContext = (DurableFunctionsOpenApiContext)context;

            await durableFunctionsOpenApiContext.OrchestrationClient.StartNewWithCustomSerializationSettingsAsync(
                nameof(TriggerExecutionOrchestrator),
                operationId.ToString(),
                envelope,
                this.serializerSettingsProvider.Instance).ConfigureAwait(false);

            return(this.AcceptedResult(operationHeaders.Location));
        }
        public async Task WhenIUseTheOperationsControlClientToCreateAnOperation(Table table)
        {
            string idName           = table.Rows[0]["IdName"];
            Guid   id               = this.ScenarioContext.Get <Guid>(idName);
            string resourceLocation = table.Rows[0]["ResourceLocation"];
            long   expireAfter      = long.Parse(table.Rows[0]["ExpireAfter"]);
            string body             = table.Rows[0]["Body"];

            IServiceProvider         serviceProvider = ContainerBindings.GetServiceProvider(this.FeatureContext);
            IMarainOperationsControl client          = serviceProvider.GetRequiredService <IMarainOperationsControl>();
            var transientTenantManager = TransientTenantManager.GetInstance(this.FeatureContext);

            await Exceptions.ExecuteAndStoreExceptionAsync(
                this.ScenarioContext,
                async() =>
            {
                CreateOperationHeaders result = await client.CreateOperationAsync(
                    transientTenantManager.PrimaryTransientClient.Id,
                    id,
                    resourceLocation,
                    expireAfter,
                    body).ConfigureAwait(false);

                this.ScenarioContext.Set(result);
            }).ConfigureAwait(false);
        }
        public void ThenTheCreateOperationResponseContainsTheLocationInTheOperationsStatusApiForTheOperationWithTheIdCalled(string operationIdName)
        {
            var  transientTenantManager = TransientTenantManager.GetInstance(this.FeatureContext);
            Guid operationId            = this.ScenarioContext.Get <Guid>(operationIdName);

            CreateOperationHeaders response = this.ScenarioContext.Get <CreateOperationHeaders>();
            var actualUri   = new Uri(response.Location);
            var expectedUri = new Uri(new Uri(ApiBindings.StatusApiBaseUrl), $"/{transientTenantManager.PrimaryTransientClient.Id}/api/operations/{operationId}");

            Assert.AreEqual(expectedUri, actualUri);
        }
        public async Task WhenIUseTheOperationsControlClientToCreateAnOperationWithTheIdCalled(string operationIdName)
        {
            Guid operationId = this.ScenarioContext.Get <Guid>(operationIdName);

            IServiceProvider         serviceProvider = ContainerBindings.GetServiceProvider(this.FeatureContext);
            IMarainOperationsControl client          = serviceProvider.GetRequiredService <IMarainOperationsControl>();
            var transientTenantManager = TransientTenantManager.GetInstance(this.FeatureContext);

            await Exceptions.ExecuteAndStoreExceptionAsync(
                this.ScenarioContext,
                async() =>
            {
                CreateOperationHeaders result = await client.CreateOperationAsync(
                    transientTenantManager.PrimaryTransientClient.Id,
                    operationId).ConfigureAwait(false);

                this.ScenarioContext.Set(result);
            }).ConfigureAwait(false);
        }
        public async Task <OpenApiResult> UpdateReadStatusesAsync(
            IOpenApiContext context,
            BatchReadStatusUpdateRequestItem[] body)
        {
            // We can guarantee tenant Id is available because it's part of the Uri.
            ITenant tenant = await this.marainServicesTenancy.GetRequestingTenantAsync(context.CurrentTenantId !).ConfigureAwait(false);

            string delegatedTenantId = await this.marainServicesTenancy.GetDelegatedTenantIdForRequestingTenantAsync(tenant.Id).ConfigureAwait(false);

            var operationId = Guid.NewGuid();
            CreateOperationHeaders response = await this.operationsControlClient.CreateOperationAsync(
                delegatedTenantId,
                operationId).ConfigureAwait(false);

            IDurableOrchestrationClient orchestrationClient = context.AsDurableFunctionsOpenApiContext().OrchestrationClient
                                                              ?? throw new OpenApiServiceMismatchException($"Operation {BatchReadStatusUpdateOperationId} has been invoked, but no Durable Orchestration Client is available on the OpenApi context.");

            await orchestrationClient.StartNewAsync(
                nameof(UpdateNotificationReadStatusesOrchestration),
                new TenantedFunctionData <BatchReadStatusUpdateRequestItem[]>(context.CurrentTenantId !, body, operationId)).ConfigureAwait(false);

            return(this.AcceptedResult(response.Location));
        }