Ejemplo n.º 1
0
        public override async Task <ServiceMessageEventArgs> HandleMessage(ISSSBService sender, ServiceMessageEventArgs serviceMessageArgs)
        {
            MessageAtributes messageAtributes = null;

            try
            {
                serviceMessageArgs.Token.ThrowIfCancellationRequested();
                XElement xml = serviceMessageArgs.Message.GetMessageXML();
                messageAtributes = xml.GetMessageAttributes();
            }
            catch (OperationCanceledException)
            {
                serviceMessageArgs.TaskCompletionSource.TrySetCanceled(serviceMessageArgs.Token);
                return(serviceMessageArgs);
            }
            catch (PPSException ex)
            {
                serviceMessageArgs.TaskCompletionSource.TrySetException(ex);
                return(serviceMessageArgs);
            }
            catch (Exception ex)
            {
                this.Logger.LogError(ErrorHelper.GetFullMessage(ex));
                serviceMessageArgs.TaskCompletionSource.TrySetException(new PPSException(ex));
                return(serviceMessageArgs);
            }

            OnDemandTaskManager taskManager = serviceMessageArgs.Services.GetRequiredService <OnDemandTaskManager>();

            try
            {
                serviceMessageArgs.Token.ThrowIfCancellationRequested();
                var task = await taskManager.GetTaskInfo(messageAtributes.TaskID.Value);

                serviceMessageArgs.TaskID = messageAtributes.TaskID.Value;
                var executorArgs = new ExecutorArgs(taskManager, task, serviceMessageArgs.Message, messageAtributes);
                await ExecuteTask(executorArgs, serviceMessageArgs);
            }
            catch (OperationCanceledException)
            {
                serviceMessageArgs.TaskCompletionSource.TrySetCanceled(serviceMessageArgs.Token);
            }
            catch (PPSException ex)
            {
                serviceMessageArgs.TaskCompletionSource.TrySetException(ex);
            }
            catch (Exception ex)
            {
                Logger.LogCritical(ErrorHelper.GetFullMessage(ex));
                serviceMessageArgs.TaskCompletionSource.TrySetException(new PPSException(ex));
            }

            return(serviceMessageArgs);
        }
Ejemplo n.º 2
0
        public override async Task <ServiceMessageEventArgs> HandleMessage(ISSSBService sender, ServiceMessageEventArgs serviceMessageArgs)
        {
            MessageAtributes messageAtributes = null;
            SSSBMessage      originalMessage  = null;

            try
            {
                serviceMessageArgs.Token.ThrowIfCancellationRequested();
                XElement envelopeXml         = serviceMessageArgs.Message.GetMessageXML();
                byte[]   originalMessageBody = Convert.FromBase64String(envelopeXml.Element("body").Value);
                XElement originalMessageXml  = originalMessageBody.GetMessageXML();
                messageAtributes               = originalMessageXml.GetMessageAttributes();
                messageAtributes.isDefered     = true;
                messageAtributes.attemptNumber = (int)envelopeXml.Attribute("attemptNumber");
                string messageType    = (string)envelopeXml.Attribute("messageType");
                string serviceName    = (string)envelopeXml.Attribute("serviceName");
                string contractName   = (string)envelopeXml.Attribute("contractName");
                long   sequenceNumber = (long)envelopeXml.Attribute("sequenceNumber");
                MessageValidationType validationType = (MessageValidationType)Enum.Parse(typeof(MessageValidationType), envelopeXml.Attribute("validationType").Value);
                Guid conversationHandle  = Guid.Parse(envelopeXml.Attribute("conversationHandle").Value);
                Guid conversationGroupID = Guid.Parse(envelopeXml.Attribute("conversationGroupID").Value);

                originalMessage = new SSSBMessage(conversationHandle, conversationGroupID, validationType, contractName);
                originalMessage.SequenceNumber = sequenceNumber;
                originalMessage.ServiceName    = serviceName;
                originalMessage.Body           = originalMessageBody;
            }
            catch (OperationCanceledException)
            {
                serviceMessageArgs.TaskCompletionSource.TrySetCanceled(serviceMessageArgs.Token);
                return(serviceMessageArgs);
            }
            catch (PPSException ex)
            {
                serviceMessageArgs.TaskCompletionSource.TrySetException(ex);
                return(serviceMessageArgs);
            }
            catch (Exception ex)
            {
                this.Logger.LogError(ErrorHelper.GetFullMessage(ex));
                serviceMessageArgs.TaskCompletionSource.TrySetException(new PPSException(ex));
                return(serviceMessageArgs);
            }

            OnDemandTaskManager taskManager = serviceMessageArgs.Services.GetRequiredService <OnDemandTaskManager>();

            try
            {
                serviceMessageArgs.Token.ThrowIfCancellationRequested();
                var task = await taskManager.GetTaskInfo(messageAtributes.TaskID.Value);

                serviceMessageArgs.TaskID = messageAtributes.TaskID.Value;
                var executorArgs = new ExecutorArgs(taskManager, task, originalMessage, messageAtributes);
                await ExecuteTask(executorArgs, serviceMessageArgs);
            }
            catch (OperationCanceledException)
            {
                serviceMessageArgs.TaskCompletionSource.TrySetCanceled(serviceMessageArgs.Token);
            }
            catch (PPSException ex)
            {
                serviceMessageArgs.TaskCompletionSource.TrySetException(ex);
            }
            catch (Exception ex)
            {
                Logger.LogCritical(ErrorHelper.GetFullMessage(ex));
                serviceMessageArgs.TaskCompletionSource.TrySetException(new PPSException(ex));
            }

            return(serviceMessageArgs);
        }
Ejemplo n.º 3
0
 public ExecutorArgs(OnDemandTaskManager tasksManager, TaskInfo taskInfo, SSSBMessage message, MessageAtributes messageAtributes)
 {
     this.TasksManager = tasksManager;
     this.TaskInfo     = taskInfo;
     this.Message      = message;
     this.Atributes    = messageAtributes;
 }