public void FromQueueMessage_Blank_TestMethod()
        {
            string testMessage = "";

            var testObj = ClassifierRequested.FromQueuedMessage(testMessage);

            Assert.IsNull(testObj);
        }
        // Validations

        // Classification request
        /// <summary>
        /// Request a classification to be performed as part of this query
        /// </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>
        /// <param name="classificationParameters">
        /// (Optional) Any additional parameters to use in the classification process
        /// </param>
        public async Task RequestClassification(string domainName,
                                                string entityTypeName,
                                                string instanceKey,
                                                string classifierTypeName,
                                                Nullable <DateTime> asOfDate,
                                                IEnumerable <KeyValuePair <string, object> > classificationParameters)
        {
            // Correlation to link the parameters to the classification
            Guid correlationId = Guid.NewGuid();

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

            if (null != classificationParameters)
            {
                // add a classification request parameter for each...
                foreach (KeyValuePair <string, object> parameter in classificationParameters)
                {
                    ClassifierRequestParameterSet evParam = new ClassifierRequestParameterSet()
                    {
                        CorrelationIdentifier = correlationId.ToString(),
                        ParameterName         = parameter.Key,
                        ParameterValue        = parameter.Value
                    };

                    await esQry.AppendEvent(evParam);
                }
            }

            // add the classification request
            ClassifierRequested evRequest = new ClassifierRequested()
            {
                CorrelationIdentifier = correlationId.ToString(),
                DomainName            = domainName,
                EntityTypeName        = entityTypeName,
                InstanceKey           = instanceKey,
                ClassifierTypeName    = classifierTypeName,
                AsOfDate = asOfDate
            };

            await esQry.AppendEvent(evRequest);

            if (_queryListener != null)
            {
                // TODO : Use the listener / executor to run the classification
            }
        }
        public void ToQueueMessage_TestMethod()
        {
            string expected = "|Bank|Account|A-123456-BB|Is Overdrawn|null|";
            string actual   = "";

            ClassifierRequested testObj = new ClassifierRequested()
            {
                DomainName         = "Bank",
                EntityTypeName     = "Account",
                InstanceKey        = "A-123456-BB",
                ClassifierTypeName = "Is Overdrawn"
            };

            actual = ClassifierRequested.ToQueueMessage(testObj);

            Assert.AreEqual(expected, actual);
        }
        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,
                                                                               "Classification Requested",
                                                                               8);

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

            var testObj = ClassifierRequested.FromQueuedMessage(testMessage);

            actual = testObj.CorrelationIdentifier;

            Assert.AreEqual(expected, actual);
        }
Beispiel #5
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);
            }
        }