Exemple #1
0
        public void InitializeChannels(SendLinkDescription[] sendLinks)
        {
            InitializeConnectionAndSession();

            foreach(var link in sendLinks)
            {
                // Some sanity checks first
                if (link.Type != LinkType.Send) continue;
                if (!this.partitions.Contains(link.PartitionId.ToString()))
                {
                    throw new Exception(string.Format(
                        "Partition '{0}' does not exist in this event hub and cannot be initialized.",
                        link.PartitionId));
                }

                var amqpLink = new SenderLink(
                    this.amqpSession,
                    "send-link:" + link.Name,
                    string.Format("{0}/Partitions/{1}",
                        this.settings.EventHubName,
                        link.PartitionId));

                this.channels.Add(link.Name, new SendChannel()
                {
                    Connection = amqpConnection,
                    Session = amqpSession,
                    Link = amqpLink,
                    Name = link.Name,
                    PartitionId = link.PartitionId.ToString()
                });
            }
        }
Exemple #2
0
        /// <summary>
        /// Initializes the underlying communication channels.
        /// </summary>
        /// <remarks>
        /// This is a length operation, and should be turned into an async method.
        /// </remarks>
        private bool InitilizeCommunications()
        {
            bool initialized = false;

            this.eventHubSettings = new EventHubSettings()
            {
                ServiceBusName = "lightningbolt",
                EventHubName = "sumobot",
                Policies = new Dictionary<string, string>()
                {
                    { "manage", "Z6KTK+hqBmMiu0WPLchX0oaYDMd+K2nwSRpZKt4RsqA=" },
                    { "device", "syc3awPWUXN1V+KbdAFmpPwx/r0F3chn1SLZJ6smioY=" },
                    { "processor", "8cxDOUPPQLkFIskUxMFCi9JNrBv6xHN8WcIwDz2fYhA=" }
                }
            };

            var sendLinks = new SendLinkDescription[]
            {
                new SendLinkDescription("temperature", "0"),
                new SendLinkDescription("sonar", "1"),
                new SendLinkDescription("ir", "2")
            };

            this.eventSender = new EventSender("PixyBot", this.eventHubSettings, "device");
            try
            {
                this.eventSender.InitializeChannels(sendLinks);
                initialized = true;
            }
            catch (Exception x)
            {
                StatusTxt.Text = "ERROR: " + x.Message;
                initialized = false;
            }

            return initialized;
        }