예제 #1
0
        public void Connect()
        {
            try
            {
                string ServiceBusConnectionString = String.Format(@"Endpoint=sb://{0}.servicebus.windows.net/;SharedAccessKeyName={1};SharedAccessKey={2};",
                                                                  sbConfig.ServiceBusNamespace, sbConfig.SasKeyName, sbConfig.SasKey);

                MessagingFactory factory = MessagingFactory.CreateFromConnectionString(ServiceBusConnectionString);
                this.subscriptionClient = SubscriptionClient.CreateFromConnectionString(ServiceBusConnectionString, sbConfig.ServiceBusTopic,
                                                                                        sbConfig.ServiceBusSubscription, ReceiveMode.ReceiveAndDelete);

                this.subscriptionClient.OnMessage(this.OnNewMessage);

                if (OnServiceBusConnected != null)
                {
                    OnServiceBusConnected.Invoke(this.subscriptionClient.Name, this.subscriptionClient.TopicPath);
                    this.LogEvent(EventTypeConsts.Info, "Binding done", "Servicebus handler listining for messages.");
                }
                else
                {
                    this.LogEvent(EventTypeConsts.Error, "Error", "OnServiceBusConnected handlers not set");
                }
            }
            catch (Exception ex)
            {
                this.LogEvent(EventTypeConsts.Error, "subscription init error", ex.Message);
            }
        }
        public async void InitSubscription()
        {
            try
            {
                HttpHelper = new HttpClientHelper(this);

                var dispatcher = DispatcherHelper.GetDispatcher;;

                await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    if (OnServiceBusConnected != null)
                    {
                        OnServiceBusConnected.Invoke(this.UrlAddress, this.UrlAddress);
                        this.LogEvent(EventTypeConsts.Info, "Binding done", "Web service handler listining for messages.");
                    }
                    else
                    {
                        this.LogEvent(EventTypeConsts.Error, "Error", "WebService handler not set");
                    }
                });
            }
            catch (Exception ex)
            {
                this.LogEvent(EventTypeConsts.Error, "Webservice request error", ex.Message + " " + ex.StackTrace);
            }finally
            {
                // Log view mode to collect data for Kiosks
                this.LogEvent(EventTypeConsts.Info, "View mode", String.Format("View IsMain: {0}, view count: {1} ", CoreApplication.GetCurrentView().IsMain, CoreApplication.Views.Count));
            }
        }
예제 #3
0
        public void InitSubscription(string TopicName, string SubscriptionName, int eventsExpiration)
        {
            this.eventsExpiration = eventsExpiration;

            try
            {
                MessagingFactory factory = MessagingFactory.CreateFromConnectionString(this.ServiceBusConnectionString);
                this.subscriptionClient = SubscriptionClient.CreateFromConnectionString(this.ServiceBusConnectionString, TopicName, SubscriptionName, ReceiveMode.ReceiveAndDelete);

                this.subscriptionClient.OnMessage(this.onNewMessage);

                if (OnServiceBusConnected != null)
                {
                    OnServiceBusConnected.Invoke(this.subscriptionClient.Name, this.subscriptionClient.TopicPath);
                    this.LogEvent(EventTypeConsts.Info, "Binding done", "Servicebus handler listining for messages.");
                }
                else
                {
                    this.LogEvent(EventTypeConsts.Error, "Error", "OnServiceBusConnected handlers not set");
                }
            }
            catch (Exception ex)
            {
                this.LogEvent(EventTypeConsts.Error, "subscription init error", ex.Message);
            }
        }
예제 #4
0
        public async void InitSubscription()
        {
            ReaderMutex.WaitOne(MutexWaitTime); // Wait one minute for mutex
            // Query topic.
            try
            {
                byte[] queryTopicResponse = await HttpHelper.GetEntity(this.topicAddress);

                if (queryTopicResponse == null)
                {
                    return;
                }

                this.LogEvent(EventTypeConsts.Info, "Topic exists", this.topicAddress);


                // Query subscription.
                while (checkSubscription() == null)
                {
                    this.LogEvent(EventTypeConsts.Error, "Error reading subscription", this.subscriptionAddress);
                    await Task.Delay(TimeSpan.FromSeconds(60));
                }

                // Create a timer-initiated ThreadPool task to renew SAS token regularly
                SASTokenRenewTimer = ThreadPoolTimer.CreatePeriodicTimer(RenewSASToken, TimeSpan.FromMinutes(15));

                var dispatcher = DispatcherHelper.GetDispatcher;
                await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    Task.Delay(TimeSpan.FromSeconds(5));
                    if (OnServiceBusConnected != null)
                    {
                        OnServiceBusConnected.Invoke(this.subscriptionAddress, this.subscriptionAddress);
                        this.LogEvent(EventTypeConsts.Info, "Binding done", "Servicebus handler listining for messages.");
                    }
                    else
                    {
                        this.LogEvent(EventTypeConsts.Error, "Error", "OnServiceBusConnected handlers not set");
                    }
                });
            }
            finally
            {
                ReaderMutex.ReleaseMutex();
                // Log view mode to collect data for Kiosks
                this.LogEvent(EventTypeConsts.Info, "View mode", String.Format("View IsMain: {0}, view count: {1} ", CoreApplication.GetCurrentView().IsMain, CoreApplication.Views.Count));
            }
        }
예제 #5
0
        public async void InitSubscription()
        {
            try
            {
                ServiceBusConnectionStringBuilder builder = new ServiceBusConnectionStringBuilder(String.Format("Endpoint=sb://{0}.servicebus.windows.net/;", ServiceBusNamespace));
                builder.SharedAccessKeyName = this.SasKeyName;
                builder.SharedAccessKey     = this.SasKey;
                builder.TransportType       = TransportType.Amqp;

                MessagingFactory factory = MessagingFactory.CreateFromConnectionString(builder.ToString());

                this.subscriptionClient = factory.CreateSubscriptionClient(TopicName, SubscriptionName);


                this.subscriptionClient.OnMessage(this.OnMessageAction, new OnMessageOptions {
                    AutoComplete = true
                });


                var dispatcher = DispatcherHelper.GetDispatcher;

                await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    Task.Delay(TimeSpan.FromSeconds(5));
                    if (OnServiceBusConnected != null)
                    {
                        OnServiceBusConnected.Invoke(this.SubscriptionName, this.TopicName);
                        this.LogEvent(EventTypeConsts.Info, "Binding done", "Servicebus handler listining for messages.");
                    }
                });
            }
            catch (Exception ex)
            { ///System.ObjectDisposedException ?
                this.LogEvent(EventTypeConsts.Error, ex.Message, ex.StackTrace);
            }
        }