private async Task HandleGroupMessage(MsmqMessage m)
        {
            try
            {
                var groupMessage = this.protocol.ReadGroupCommand(m.Body);

                var connection = this.connections[groupMessage.ConnectionId];
                if (connection == null)
                {
                    // user not on this server
                    return;
                }

                if (groupMessage.Action == GroupAction.Remove)
                {
                    await this.RemoveGroupAsyncCore(connection, groupMessage.GroupName);
                }

                if (groupMessage.Action == GroupAction.Add)
                {
                    await this.AddGroupAsyncCore(connection, groupMessage.GroupName);
                }

                // Send an ack to the server that sent the original command.
                var ack = this.protocol.WriteAck(groupMessage.Id);
                await this.msmqBus.PublishAsync(this.queues.GroupManagement(groupMessage.ServerName), ack);
            }
            catch (Exception ex)
            {
                MsmqLog.InternalMessageFailed(this.logger, ex);
            }
        }
Exemplo n.º 2
0
        public void ProcessarMensagemRecebida(MsmqMessage <string> mensagemRecebida)
        {
            var corpoDaMensagem = mensagemRecebida.Body;

            Console.WriteLine($"Mensagem: {corpoDaMensagem}");
            Console.WriteLine();
        }
Exemplo n.º 3
0
 public void SubmitPurchaseOrder(MsmqMessage<PurchaseOrder> ordermsg)
 {
     PurchaseOrder po = (PurchaseOrder)ordermsg.Body;
     Random statusIndexer = new Random();
     po.Status = (OrderStates)statusIndexer.Next(3);
     Console.WriteLine("Processing {0} ", po);
 }
Exemplo n.º 4
0
 public void SubmitPurchaseOrder(MsmqMessage<PurchaseOrder> msg)
 {
     PurchaseOrder po = (PurchaseOrder)msg.Body;
     Random statusIndexer = new Random();
     po.Status = (OrderStates)statusIndexer.Next(3);
     Console.WriteLine("Processing {0} ", po);
 }
Exemplo n.º 5
0
        static void Run()
        {
            MsmqIntegrationBinding binding = new MsmqIntegrationBinding();

            binding.Security.Mode = MsmqIntegrationSecurityMode.None;
            EndpointAddress address = new EndpointAddress("msmq.formatname:DIRECT=OS:" + Constants.QUEUE_PATH);

            ChannelFactory <ClassLib.IOrderProcessor> channelFactory = new ChannelFactory <ClassLib.IOrderProcessor>(binding, address);

            try
            {
                ClassLib.IOrderProcessor channel = channelFactory.CreateChannel();

                MyOrder order = new MyOrder();
                order.ID   = DateTime.Now.Ticks.ToString();
                order.Name = "Order_" + order.ID;

                MsmqMessage <MyOrder> ordermsg = new MsmqMessage <MyOrder>(order);
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    channel.SubmitPurchaseOrderInMessage(ordermsg);
                    scope.Complete();
                }

                Console.WriteLine("Order has been submitted:{0}", ordermsg);
            }
            finally
            {
                channelFactory.Close();
            }
        }
Exemplo n.º 6
0
        static void Run()
        {
            MsmqIntegrationBinding binding = new MsmqIntegrationBinding();
            binding.Security.Mode = MsmqIntegrationSecurityMode.None;
            EndpointAddress address = new EndpointAddress("msmq.formatname:DIRECT=OS:" + Constants.QUEUE_PATH);

            ChannelFactory<ClassLib.IOrderProcessor> channelFactory = new ChannelFactory<ClassLib.IOrderProcessor>(binding, address);

            try
            {
                ClassLib.IOrderProcessor channel = channelFactory.CreateChannel();

                MyOrder order = new MyOrder();
                order.ID = DateTime.Now.Ticks.ToString();
                order.Name = "Order_" + order.ID;

                MsmqMessage<MyOrder> ordermsg = new MsmqMessage<MyOrder>(order);
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    channel.SubmitPurchaseOrderInMessage(ordermsg);
                    scope.Complete();
                }

                Console.WriteLine("Order has been submitted:{0}", ordermsg);
            }
            finally
            {
                channelFactory.Close();
            }
        }
        private async Task HandleRegularMessage(MsmqMessage m)
        {
            try
            {
                MsmqLog.ReceivedFromChannel(this.logger, m.ChannelName);

                var invocation = this.protocol.ReadInvocation(m.Body);

                var tasks = new List <Task>(this.connections.Count);

                foreach (var connection in this.connections)
                {
                    if (invocation.ExcludedConnectionIds == null || !invocation.ExcludedConnectionIds.Contains(connection.ConnectionId))
                    {
                        tasks.Add(connection.WriteAsync(invocation.Message).AsTask());
                    }
                }

                await Task.WhenAll(tasks);
            }
            catch (Exception ex)
            {
                MsmqLog.FailedWritingMessage(this.logger, ex);
            }
        }
Exemplo n.º 8
0
 public void SubmitPurchaseOrder(MsmqMessage<PurchaseOrder> ordermsg)
 {
     PurchaseOrder po = (PurchaseOrder)ordermsg.Body;
     Random statusIndexer = new Random();
     po.Status = (OrderStates)statusIndexer.Next(3);
     Console.WriteLine("Processing {0} ", po);
     //Send a response to the client that the order has been received and is pending fullfillment 
     SendResponse(ordermsg);
 }
 public void ProcessIncomingMessage(MsmqMessage<Order> incomingOrderMessage)
 {
     var orderRequest = incomingOrderMessage.Body;
     Console.WriteLine(orderRequest.OrderID);
     Console.WriteLine(orderRequest.ShipToAddress);
     Console.WriteLine(orderRequest.ShipToCity);
     Console.WriteLine(orderRequest.ShipToCountry);
     Console.WriteLine(orderRequest.ShipToZipCode);
     Console.WriteLine(orderRequest.SubmittedOn);
 }
Exemplo n.º 10
0
        public void ProcessIncomingMessage(MsmqMessage <string> mensagem)
        {
            Console.WriteLine("------------------------------------ mensagem recebida ---------------------------------------");

            var body = mensagem.Body;

            mongo.Insert(body);


            Console.WriteLine(body);
            Console.WriteLine();
        }
Exemplo n.º 11
0
        public void ProcessPerson(MsmqMessage <Person> ordermsg)
        {
            Person p = (Person)ordermsg.Body;

            Console.WriteLine("Processing Person ID {0} ", p.PersonID);
            Console.WriteLine("Name: " + p.Name);
            Console.WriteLine("Address: " + p.Address);
            Console.WriteLine("Age: " + p.Age);
            Console.WriteLine("Person processed......");
            Console.WriteLine("----------------------------");
            Console.WriteLine();
        }
Exemplo n.º 12
0
 private void SendResponse(MsmqMessage<PurchaseOrder> ordermsg)
 {
     OrderResponseClient client = new OrderResponseClient("OrderResponseEndpoint");
     
     //Set the correlation ID such that the client can correlate the response to the order
     MsmqMessage<PurchaseOrder> orderResponsemsg = new MsmqMessage<PurchaseOrder>(ordermsg.Body);
     orderResponsemsg.CorrelationId = ordermsg.Id;
     using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
     {
         client.SendOrderResponse(orderResponsemsg);
         scope.Complete();
     }
     client.Close();
 }
        private Task HandleAckMessage(MsmqMessage m)
        {
            try
            {
                var ackId = this.protocol.ReadAck(m.Body);
                this.ackHandler.TriggerAck(ackId);
            }
            catch (Exception ex)
            {
                MsmqLog.InternalMessageFailed(this.logger, ex);
            }

            return(Task.CompletedTask);
        }
Exemplo n.º 14
0
        private void SendResponse(MsmqMessage <PurchaseOrder> ordermsg)
        {
            OrderResponseClient client = new OrderResponseClient("OrderResponseEndpoint");

            //Set the correlation ID such that the client can correlate the response to the order
            MsmqMessage <PurchaseOrder> orderResponsemsg = new MsmqMessage <PurchaseOrder>(ordermsg.Body);

            orderResponsemsg.CorrelationId = ordermsg.Id;
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
            {
                client.SendOrderResponse(orderResponsemsg);
                scope.Complete();
            }
            client.Close();
        }
Exemplo n.º 15
0
        private static void Sample_01_Msmq()
        {
            var msmqTest = new MsmqTester();

            msmqTest.SendMessage(
                new MsmqMessage()
            {
                Amount  = 100,
                DueDate = "2014/11/12 11:30:22",
                Payee   = "Payee1",
                Payor   = "Payer1"
            });

            MsmqMessage msg = msmqTest.ReceiveMessage();

            Console.WriteLine(msg.Payor);
        }
Exemplo n.º 16
0
        public void Receive(MsmqMessage<LogMsmqMessage> message)
        {
            try
            {
                var logMsmqMessage = message.Body;
                var logMessage = BinarySerializationHelper.Deserialize<LogMessage>(logMsmqMessage.SerializedLogMessage);

                ILog log = LogWrapper.Instance.Get(logMessage.Type);

                ThreadContext.Properties["DateTime"] = logMessage.Created.ToString("yyyy-MM-dd HH:mm:ss,fff");
                ThreadContext.Properties["Method"] = logMessage.Method;
                ThreadContext.Properties["Machine"] = logMessage.Machine;
                ThreadContext.Properties["ThreadName"] = logMessage.ThreadName;
                ThreadContext.Properties["Application"] = logMessage.Application;
                ThreadContext.Properties["Type"] = logMessage.Type;

                switch (logMessage.Level)
                {
                    case LogLevel.Debug:
                        log.Debug(logMessage.Message, logMessage.Exception);
                        break;
                    case LogLevel.Info:
                        log.Info(logMessage.Message, logMessage.Exception);
                        break;
                    case LogLevel.Warn:
                        log.Warn(logMessage.Message, logMessage.Exception);
                        break;
                    case LogLevel.Error:
                        log.Error(logMessage.Message, logMessage.Exception);
                        break;
                    case LogLevel.Fatal:
                        log.Fatal(logMessage.Message, logMessage.Exception);
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(string.Format("Exception logging data. {0}", ex));
            }
        }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            // Create the purchase order
            PurchaseOrder po = new PurchaseOrder();
            po.customerId = "somecustomer.com";
            po.poNumber = Guid.NewGuid().ToString();

            PurchaseOrderLineItem lineItem1 = new PurchaseOrderLineItem();
            lineItem1.productId = "Blue Widget";
            lineItem1.quantity = 54;
            lineItem1.unitCost = 29.99F;

            PurchaseOrderLineItem lineItem2 = new PurchaseOrderLineItem();
            lineItem2.productId = "Red Widget";
            lineItem2.quantity = 890;
            lineItem2.unitCost = 45.89F;

            po.orderLineItems = new PurchaseOrderLineItem[2];
            po.orderLineItems[0] = lineItem1;
            po.orderLineItems[1] = lineItem2;

            OrderProcessorClient client = new OrderProcessorClient("OrderResponseEndpoint");

            MsmqMessage<PurchaseOrder> ordermsg = new MsmqMessage<PurchaseOrder>(po);
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
            {
                client.SubmitPurchaseOrder(ordermsg);
                scope.Complete();
            }
            Console.WriteLine("Order has been submitted:{0}", po);

            //Closing the client gracefully closes the connection and cleans up resources
            client.Close();

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
        public void DeliverGreeting(MsmqMessage<Greeting> greetingMessage)
        {
            // Extract the greeting from the MSMQ message
            Greeting greeting = greetingMessage.Body;

            // Set up and do some tracking...
            var trackingId = SetTrackingId();
            WCFUserEventProvider ev = new WCFUserEventProvider();
            ev.WriteInformationEvent(
                "GreetingService.DeliverGreeting",
                XmlSerialization.SerializeToXmlString(greeting));

            // Use the delivery service for each individual message
            var deliveryService = new DeliveryService.DeliveryServiceClient();
            foreach (string recipient in greeting.Recipients)
            {
                deliveryService.DeliverMessage(
                    trackingId,
                    string.Format(
                        "{0} {1}",
                        greeting.GreetingMessage,
                        recipient));
            }
        }
Exemplo n.º 19
0
 public void SubmitNewOrder(MsmqMessage<Contract.NewOrderMessage> newOrder)
 {
     Debugger.Break();
 }
Exemplo n.º 20
0
        public override void Execute(System.ServiceModel.MsmqIntegration.MsmqMessage<Common.Contracts.RoutedMessageContract> value)
        {
            string paramString = string.Empty;

            Task task = new Task(() =>
            {
                try
                {
                    MethodInfo info = HostedContract.GetType()
                        .GetMethod(value.Body.Action);
                    // Strip out parameters from the message contract
                    object val = value.Body.MessageBody;
                    List<ActionParameter> parms = new List<ActionParameter>();
                    XmlSerializer serial = new XmlSerializer(typeof(List<ActionParameter>));
                    using (StringReader sr = new StringReader(value.Body.MessageBody.ToString()))
                    {
                        parms.AddRange((List<ActionParameter>)serial.Deserialize(sr));
                        parms.ForEach(p => paramString += string.Format("{0} ({1}): {2}\r\n", p.Name, p.ParamType, p.Value.ToString() ?? string.Empty));
                    }
                    // Execute the function based on action name
                    object retval = null;
                    object locker = 4;
                    lock (locker)
                    {
                        retval = info.Invoke(HostedContract, parms.Select(x => x.Value).ToArray());
                    };
                    MsmqMessage<RoutedMessageContract> msg = new MsmqMessage<RoutedMessageContract>(
                        new RoutedMessageContract()
                        {
                            StatusCode = TransmissionStatusCodes.EOT_GOOD,
                            MessageBody = retval ?? string.Format("Call to {0}::{1} successful",
                                this.HostedContract.GetType().Name, value.Body.Action),
                            IsFromGateway = true,
                            Action = "",
                            DestinationHub = "",
                            DestinationSpoke = "",
                        });
                    msg.Label = "Success";
                    msg.CorrelationId = value.Id;
                    Route(msg);
                }
                catch (Exception ex)
                {
                    string errOutput = ex.Message + "\r\n" + ex.StackTrace +
                             "\r\n" +
                             string.Format("Function: {0}.{1}",
                             HostedContract.GetType().Name, value.Body.Action) + "\r\n" +
                             "Parameter(s):" + "\r\n" + paramString;
                    Instrument(TransmissionStatusCodes.EOT_ERR, errOutput, InstrumentationSources.Spoke, this.ObjectID, value.Id);
                    MsmqMessage<RoutedMessageContract> msg = new System.ServiceModel.MsmqIntegration.MsmqMessage<Common.Contracts.RoutedMessageContract>(
                        new Common.Contracts.RoutedMessageContract()
                        {
                            StatusCode = TransmissionStatusCodes.EOT_ERR,
                            MessageBody = "An error has occurred. Please consult the application log for more details." ,
                            IsFromGateway = true,
                            Action = value.Body.Action,
                            DestinationHub = value.Body.DestinationHub,
                            DestinationSpoke = value.Body.DestinationSpoke,
                        }) { Label = "Error" };
                    msg.CorrelationId = value.Id;
                    Route(msg);
                }
            });
            task.Start();
        }
Exemplo n.º 21
0
 public override void Route(MsmqMessage<RoutedMessageContract> value)
 {
     value.Body.IsFromGateway = true;
     base.Route(value);
 }
Exemplo n.º 22
0
 public override void Start(MsmqMessage<RoutedMessageContract> value)
 {
     Instrument(Common.TransmissionStatusCodes.SVC_START, "Starting route dispatcher...", Common.InstrumentationSources.Hub, this.ObjectID);
     base.Start(value);
 }
Exemplo n.º 23
0
 public void CancelPurchaseOrder(MsmqMessage<string> msg)
 {
     string ponumber = (string)msg.Body;
     Console.WriteLine("Purchase Order {0} is cancelled ", ponumber);
 }
Exemplo n.º 24
0
 public void SubmitPurchaseOrderInMessage(MsmqMessage<MyOrder> ordermsg)
 {
     MyOrder po = (MyOrder)ordermsg.Body;
     Console.WriteLine("Processing id:{0}, name:{1} ", po.ID, po.Name);
 }
Exemplo n.º 25
0
 public void Show(MsmqMessage<string> msg)
 {
     Console.ForegroundColor = ConsoleColor.Cyan;
     Console.WriteLine("\n*** Queue: Label[{0}], Body[{1}] ***\n", msg.Label, msg.Body);
     Console.ResetColor();
 }
        public void SubmitMessage(MsmqMessage<MentoringMessage> message)
        {
            MentoringMessage msg = (MentoringMessage)message.Body;

            Console.WriteLine(msg.ToString());
        }
Exemplo n.º 27
0
 public void SubmitMessage(MsmqMessage<McrsQueueMessage> message)
 {
     Trace.WriteLine("In SubmitMessage");
     Trace.WriteLine(message.Body.AsString);
 }