Exemplo n.º 1
0
        // Projection request
        /// <summary>
        /// Request a projection to be performed
        /// </summary>
        /// <param name="domainName">
        /// The domain name of the entity over which the classification is to run
        /// </param>
        /// <param name="entityTypeName">
        /// The entity type over which to run the classification
        /// </param>
        /// <param name="instanceKey">
        /// The specific instance over which to run the classification
        /// </param>
        /// <param name="classifierTypeName">
        /// The specific type of classification process to run over the event stream
        /// </param>
        /// <param name="asOfDate">
        /// (Optional) The date up to which to run the classification
        /// </param>
        public async Task RequestProjection(string domainName,
                                            string entityTypeName,
                                            string instanceKey,
                                            string projectionTypeName,
                                            Nullable <DateTime> asOfDate)
        {
            Guid correlationId = Guid.NewGuid();

            EventStream esQry = new EventStream(new EventStreamAttribute(
                                                    MakeDomainQueryName(DomainName),
                                                    QueryName,
                                                    UniqueIdentifier),
                                                context: _queryContext);

            ProjectionRequested evPrj = new ProjectionRequested()
            {
                CorrelationIdentifier = correlationId.ToString(),
                DomainName            = domainName,
                EntityTypeName        = entityTypeName,
                InstanceKey           = instanceKey,
                ProjectionTypeName    = projectionTypeName,
                AsOfDate   = asOfDate,
                DateLogged = DateTime.UtcNow
            };

            await esQry.AppendEvent(evPrj);
        }
Exemplo n.º 2
0
        //ProjectionRequested
        public void HandleEvent(ProjectionRequested eventHandled)
        {
            #region Logging
            if (null != log)
            {
                log.LogDebug($"HandleEvent( ProjectionRequested ) in {nameof(Query_Summary_Projection)}");
            }
            #endregion

            if (null != eventHandled)
            {
                // Set the status as "In error" if this was a fatal parameter error
                base.AddOrUpdateValue <QueryState>(nameof(CurrentState), 0, QueryState.InProgress);
                #region Logging
                if (null != log)
                {
                    log.LogDebug($"Projection requested {eventHandled.ProjectionTypeName} for {eventHandled.AggregateType}-{eventHandled.AggregateInstanceKey } in {nameof(Query_Summary_Projection)}");
                }
                #endregion
            }
            else
            {
                #region Logging
                if (null != log)
                {
                    log.LogWarning($"HandleEvent( QueryParameterValidationErrorOccured ) - parameter was null in {nameof(Query_Summary_Projection)}");
                }
                #endregion
            }
        }
        // Projection request
        /// <summary>
        /// Request a projection to be performed
        /// </summary>
        /// <param name="domainName">
        /// The domain name of the entity over which the classification is to run
        /// </param>
        /// <param name="entityTypeName">
        /// The entity type over which to run the classification
        /// </param>
        /// <param name="instanceKey">
        /// The specific instance over which to run the classification
        /// </param>
        /// <param name="projectionTypeName">
        /// The specific type of projection process to run over the event stream
        /// </param>
        /// <param name="asOfDate">
        /// (Optional) The date up to which to run the classification
        /// </param>
        public async Task RequestProjection(string domainName,
                                            string entityTypeName,
                                            string instanceKey,
                                            string projectionTypeName,
                                            Nullable <DateTime> asOfDate = null)
        {
            Guid correlationId = Guid.NewGuid();

            EventStream esQry = new EventStream(new EventStreamAttribute(
                                                    MakeDomainQueryName(DomainName),
                                                    QueryName,
                                                    UniqueIdentifier,
                                                    notificationDispatcherName: _queryDispatcherName),
                                                context: _queryContext);

            ProjectionRequested evPrj = new ProjectionRequested()
            {
                CorrelationIdentifier    = correlationId.ToString(),
                ProjectionDomainName     = domainName,
                ProjectionEntityTypeName = entityTypeName,
                ProjectionInstanceKey    = instanceKey,
                ProjectionTypeName       = projectionTypeName,
                AsOfDate   = asOfDate,
                DateLogged = DateTime.UtcNow
            };

            await esQry.AppendEvent(evPrj);

            if (_queryListener != null)
            {
                // TODO : Use the listener / executor to run the projection
            }
        }
        // Projection request
        /// <summary>
        /// Request a projection to be performed
        /// </summary>
        /// <param name="domainName">
        /// The domain name of the entity over which the classification is to run
        /// </param>
        /// <param name="entityTypeName">
        /// The entity type over which to run the classification
        /// </param>
        /// <param name="instanceKey">
        /// The specific instance over which to run the classification
        /// </param>
        /// <param name="classifierTypeName">
        /// The specific type of classification process to run over the event stream
        /// </param>
        /// <param name="asOfDate">
        /// (Optional) The date up to which to run the classification
        /// </param>
        public async Task RequestProjection(string domainName,
                                            string entityTypeName,
                                            string instanceKey,
                                            string projectionTypeName,
                                            Nullable <DateTime> asOfDate)
        {
            Guid correlationId = Guid.NewGuid();

            EventStream esCmd = new EventStream(new EventStreamAttribute(
                                                    MakeDomainCommandName(DomainName),
                                                    CommandName,
                                                    UniqueIdentifier,
                                                    notificationDispatcherName: _commandDispatcherName),
                                                context: _commandContext);

            ProjectionRequested evPrj = new ProjectionRequested()
            {
                CorrelationIdentifier    = correlationId.ToString(),
                ProjectionDomainName     = domainName,
                ProjectionEntityTypeName = entityTypeName,
                ProjectionInstanceKey    = instanceKey,
                ProjectionTypeName       = projectionTypeName,
                AsOfDate   = asOfDate,
                DateLogged = DateTime.UtcNow
            };

            await esCmd.AppendEvent(evPrj);
        }
Exemplo n.º 5
0
        public void FromQueueMessage_Valid_TestMethod()
        {
            string testMessage = "E|Projection Requested|AAAA-BBBB-CDEF012345|2|null||Bank|Account|A-123456-BB|Balance|null|";

            var testObj = ProjectionRequested.FromQueuedMessage(testMessage);

            Assert.IsNotNull(testObj);
        }
Exemplo n.º 6
0
        public void FromQueueMessage_Blank_TestMethod()
        {
            string testMessage = "";

            var testObj = ProjectionRequested.FromQueuedMessage(testMessage);

            Assert.IsNull(testObj);
        }
Exemplo n.º 7
0
        public void ToQueueMessage_TestMethod()
        {
            string expected = "|Bank|Account|A-123456-BB|Balance|null|";
            string actual   = "";

            ProjectionRequested testObj = new ProjectionRequested()
            {
                ProjectionDomainName     = "Bank",
                ProjectionEntityTypeName = "Account",
                ProjectionInstanceKey    = "A-123456-BB",
                ProjectionTypeName       = "Balance"
            };

            actual = ProjectionRequested.ToQueueMessage(testObj);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 8
0
        public void FromQueueMessage_Valid_AsOfDate_TestMethod()
        {
            DateTime expected = new DateTime(2020, 12, 19);
            DateTime actual   = new DateTime(1984, 3, 15);

            IEventStreamIdentity cmdTest = new Common.Binding.EventStreamAttribute("Bank", "Apply Interest", "A-123456-BB");

            string testMessage = QueueNotificationDispatcher.MakeMessageString(cmdTest,
                                                                               QueueNotificationDispatcher.NOTIFICATION_NEW_EVENT,
                                                                               "Projection Requested",
                                                                               3);

            testMessage += $"|Bank|Account|A-123456-BB|Balance|2020-12-19|123456789-ab";

            var testObj = ProjectionRequested.FromQueuedMessage(testMessage);

            actual = testObj.AsOfDate.GetValueOrDefault();

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 9
0
        public void FromQueueMessage_Valid_Correlation_TestMethod()
        {
            string expected = "123456789-ab";
            string actual   = "not set";

            IEventStreamIdentity cmdTest = new Common.Binding.EventStreamAttribute("Bank", "Apply Interest", "A-123456-BB");

            string testMessage = QueueNotificationDispatcher.MakeMessageString(cmdTest,
                                                                               QueueNotificationDispatcher.NOTIFICATION_NEW_EVENT,
                                                                               "Projection Requested",
                                                                               3);

            testMessage += $"|Bank|Account|A-123456-BB|Balance|null|123456789-ab";

            var testObj = ProjectionRequested.FromQueuedMessage(testMessage);

            actual = testObj.CorrelationIdentifier;

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 10
0
        public async Task NewEventAppended(IEventStreamIdentity targetEntity,
                                           string eventType,
                                           int sequenceNumber,
                                           string commentary     = "",
                                           object eventPayload   = null,
                                           IWriteContext context = null)
        {
            string messageToSend = MakeMessageString(targetEntity,
                                                     NOTIFICATION_NEW_EVENT,
                                                     eventType,
                                                     sequenceNumber);

            string queueName = string.Empty;

            // special case - if it is a Command or Query requesting a Classification or Projection..
            if (eventType == EventNameAttribute.GetEventName(typeof(ProjectionRequested)))
            {
                // Is it a command or query...
                if (targetEntity.DomainName.Contains("Command"))
                {
                    queueName = QUEUE_COMMAND_PROJECTIONS;
                }
                if (targetEntity.DomainName.Contains("Query"))
                {
                    queueName = QUEUE_QUERY_PROJECTIONS;
                }
                // Add the extra details to the message text to indicate what projection was requested
                ProjectionRequested evtPayload = eventPayload as ProjectionRequested;
                if (evtPayload != null)
                {
                    messageToSend += ProjectionRequested.ToQueueMessage(evtPayload);
                }
            }
            else
            {
                if (eventType == EventNameAttribute.GetEventName(typeof(ClassifierRequested)))
                {
                    // Is it a command or query...
                    if (targetEntity.DomainName.Contains("Command"))
                    {
                        queueName = QUEUE_COMMAND_CLASSIFICATIONS;
                    }
                    if (targetEntity.DomainName.Contains("Query"))
                    {
                        queueName = QUEUE_QUERY_CLASSIFICATIONS;
                    }
                    // Add the extra details to the message text to indicate what classification was requested
                    ClassifierRequested evtPayload = eventPayload as ClassifierRequested;
                    if (evtPayload != null)
                    {
                        messageToSend += $"|{evtPayload.DomainName}|{evtPayload.EntityTypeName}|{evtPayload.InstanceKey}|{evtPayload.ClassifierTypeName}|{evtPayload.AsOfDate}|{evtPayload.CorrelationIdentifier}";
                    }
                }
                else
                {
                    queueName = MakeQueueName(targetEntity);
                }
            }

            string connectionStringName = _eventStreamSettings.GetConnectionStringName(targetEntity);

            if (!string.IsNullOrWhiteSpace(queueName))
            {
                await SendQueueMessage(connectionStringName, queueName, messageToSend);
            }
        }