Пример #1
0
        public async Task <IActionResult> PostSubmission(
            [HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = "submission/{user}")] HttpRequest httpRequest,
            string user,
            [SignalR(HubName = "SubmissionHub")] IAsyncCollector <SignalRMessage> signalRMessages,
            ILogger log)
        {
            log.LogInformation($"Request Submitted for '{user}'.");
            if (string.IsNullOrWhiteSpace(user))
            {
                throw new ArgumentException("Cannot be null or empty.", nameof(user));
            }

            var request  = new SubmitForApproval(user);
            var response = await mediator.Send(request);

            var message = new SignalRMessage
            {
                Target    = $"broadcastMessage",
                Arguments = new[] { request.UserId, "submitted" }
            };

            await signalRMessages.AddAsync(message);

            return(new OkObjectResult(response));
        }
Пример #2
0
        public void Setup()
        {
            Test.Initialize();


            _now = DateTime.Now;

            _submitForApprovalMessage = new SubmitForApproval
            {
                ApprovedBy       = "GH13579",
                ApprovedOn       = _now,
                DataCollectionId = 1
            };

            _submitForSecondaryApprovalMessage = new SubmitForSecondaryApproval
            {
                DataCollectionId = 1,
                ApprovedBy       = "FH13545",
                ApprovedOn       = _submitForApprovalMessage.ApprovedOn.AddDays(1)
            };

            _submitForFinalApprovalMessage = new SubmitForFinalApproval
            {
                DataCollectionId = 1,
                ApprovedBy       = "787878r",
                ApprovedOn       = _submitForSecondaryApprovalMessage.ApprovedOn.AddDays(1)
            };

            _submitForSecondaryReApprovalMessage = new SubmitForSecondaryReApproval
            {
                DataCollectionId = 1,
                ApprovedBy       = "454545k",
                ApprovedOn       = _submitForFinalApprovalMessage.ApprovedOn.AddDays(1)
            };


            _publishDataCollectionMessage = new PublishDataCollection
            {
                DataCollectionId = 1,
                ApprovedBy       = "321312w",
                ApprovedOn       = _submitForFinalApprovalMessage.ApprovedOn.AddDays(2)
            };

            _exportToVivoResponse = new ExportToVivoResponse
            {
                DataCollectionId = 1
            };
        }
        /// <summary>
        /// Handles the SubmitForApproval message.
        /// </summary>
        /// <param name="message">SubmitForApproval message.</param>
        public void Handle(SubmitForApproval message)
        {
            Log.InfoFormat("[URDMS] Received SubmitForApproval message id:{0}, approvedBy:{1}, approvedOn:{2}.", message.DataCollectionId, message.ApprovedBy, message.ApprovedOn);


            if (Data.DataCollectionId != 0)
            {
                // An instance already exists for this DataCollection. There cannot be more than one.
                Log.Warn("[URDMS] Saga Instance already exists for this Data Collection. Saga will not continue processing this message.");
                Bus.DoNotContinueDispatchingCurrentMessageToHandlers();
            }
            else
            {
                // Save state
                Data.DataCollectionId = message.DataCollectionId;
                Data.ApprovalState    = DataCollectionApprovalState.Submitted;
                Data.CollectionOwner  = message.ApprovedBy;
                Data.StateChangedOn   = message.ApprovedOn;
                Data.Approver         = message.ApprovedBy;

                Log.InfoFormat("[URDMS] Publishing ApprovalStateChanged for id:{0}", message.DataCollectionId);

                // Change the approvalState of the DataCollection
                Bus.Publish <ApprovalStateChanged>(m =>
                {
                    m.DataCollectionId = message.DataCollectionId;
                    m.ApprovalState    = DataCollectionApprovalState.Submitted;
                    m.StateChangedOn   = message.ApprovedOn;
                    m.Approver         = message.ApprovedBy;
                });

                Bus.Send <NotifyApprovalStateChanged>(m =>
                {
                    m.DataCollectionId = message.DataCollectionId;
                    m.ApprovalState    = DataCollectionApprovalState.Submitted.ToString();
                    m.Approver         = message.ApprovedBy;
                });
            }
        }