Ejemplo n.º 1
0
        public IMessage CreateMessage(ICommandMessage command)
        {
            if (command == null)
            {
                return(null);
            }

            IMessage message = Factory.GetInstance <IMessage>();
            DataContractSerializer serializer = new DataContractSerializer(command.GetType());
            StringBuilder          output     = new StringBuilder();

            using (XmlWriter writer = XmlWriter.Create(output, this.xmlWriterSettings))
            {
                serializer.WriteObject(writer, command);
                writer.Flush();
                message.Text            = output.ToString();
                message.ExtraProperties = command.GetProperties();
                message.TtlInMinutes    = command.TtlInMinutes;
            }

            /*using (MemoryStream memoryStream = new MemoryStream())
             * {
             *  serializer.WriteObject(memoryStream, command);
             *  memoryStream.Position = 0;
             *
             *  using (StreamReader reader = new StreamReader(memoryStream))
             *  {
             *      message.Text = reader.ReadToEnd();
             *  }
             * }*/

            message.Type     = command.CommandName;
            message.SentDate = command.SendingDate;
            return(message);
        }
Ejemplo n.º 2
0
        public void Dispatch(ICommandMessage command)
        {
            var cmdType       = command.GetType();
            var handler       = Activator.CreateInstance(handlers[cmdType]);
            var genericMethod = dispatchCommand.MakeGenericMethod(cmdType);

            genericMethod.Invoke(this, new object[] { handler, command });
        }
Ejemplo n.º 3
0
        public void Handle(ICommandMessage command)
        {
            var type = command.GetType();

            foreach (var kvp in _handlers)
            {
                Console.WriteLine(kvp.Key);
            }

            if (!_handlers.ContainsKey(type))
            {
                return;
            }

            var handler = _handlers[type];

            handler(command);
        }
Ejemplo n.º 4
0
        public async Task Send(ICommandMessage message)
        {
            var queueClient = QueueClient.CreateFromConnectionString(_connectionString, message.GetType().FullName);

            await queueClient.SendAsync(BuildBrokeredMessage(message));
        }