Esempio n. 1
0
        private async Task ForwardCommandMessageToThing(BrokeredMessage bm, Thing thing)
        {
            TopicClient forwardClient    = null;
            var         partition        = thing.Partition;
            var         topicName        = string.Format(PARTITION_COMMAND_TOPIC, thing.RelativeId);
            var         connectionString = ServiceBusConnection.FromIssuer(partition.Namespace, partition.Owner, partition.OwnerSecret);
            var         controlMessage   = bm.GetBody <ControlMessage>();
            var         commandMessage   = new CommandMessage {
                Command = controlMessage.Command, Parameters = controlMessage.Parameters
            };

            try
            {
                forwardClient = TopicClient.CreateFromConnectionString(connectionString, topicName);

                using (var forwardMessage = new BrokeredMessage(commandMessage)
                {
                    ContentType = CommandMessage.CONTENT_TYPE
                })
                {
                    forwardMessage.To      = bm.To;
                    forwardMessage.ReplyTo = bm.ReplyTo;

                    await _messagingPolicy.ExecuteAsync(() => forwardClient.SendAsync(forwardMessage));
                }
            }
            finally
            {
                if (forwardClient != null)
                {
                    _catchAllPolicy.Execute(() => { forwardClient.Close(); });
                }
            }
        }
Esempio n. 2
0
        private async Task BroadcastCommandMessageToPartition(BrokeredMessage bm, Partition partition, int[] relativeIds)
        {
            TopicClient forwardClient    = null;
            var         connectionString = ServiceBusConnection.FromIssuer(partition.Namespace, partition.Owner, partition.OwnerSecret);
            var         controlMessage   = bm.GetBody <ControlMessage>();
            var         commandMessage   = new CommandMessage {
                Command = controlMessage.Command, Parameters = controlMessage.Parameters
            };

            foreach (var topicName in relativeIds.Select(id => string.Format(PARTITION_COMMAND_TOPIC, id)))
            {
                try
                {
                    forwardClient = TopicClient.CreateFromConnectionString(connectionString, topicName);

                    using (var forwardMessage = new BrokeredMessage(commandMessage)
                    {
                        ContentType = CommandMessage.CONTENT_TYPE
                    })
                    {
                        forwardMessage.Properties[MessageProperty.BROADCAST] = 0;
                        forwardMessage.ReplyTo = bm.ReplyTo;

                        await _messagingPolicy.ExecuteAsync(() => forwardClient.SendAsync(forwardMessage));
                    }
                }
                finally
                {
                    if (forwardClient != null)
                    {
                        _catchAllPolicy.Execute(() => { forwardClient.Close(); });
                    }
                }
            }
        }
Esempio n. 3
0
 public ThingsAccess(Guid from, int commandTopic, string ns, string issuer, string secret)
 {
     AssertConstruction(from, commandTopic, ns, issuer, secret);
     InitializeObjectMembers(from, commandTopic, ServiceBusConnection.FromIssuer(ns, issuer, secret));
 }
Esempio n. 4
0
        private string CreateThingConnectionString(Guid id, string secret)
        {
            var thing = _thingRepository.GetThingById(id);

            return(ServiceBusConnection.FromIssuer(thing.Partition.Namespace, id.ToString(), secret));
        }
Esempio n. 5
0
 public ThingsWorker(string cloudStorage, string ns, string issuer, string secret)
 {
     AssertConstruction(cloudStorage, ns, issuer, secret);
     InitializeObjectMembers(cloudStorage, ServiceBusConnection.FromIssuer(ns, issuer, secret));
 }