Ejemplo n.º 1
0
        private async void OnTapped(object sender, ItemTappedEventArgs e)
        {
            var         item          = e.Item as SubscriptionView;
            ContentPage detailSubPage = new DetailSubscriptionPage(client, item.SubscriptionID);

            detailSubPage.Title = "Subscription Details";
            await Navigation.PushAsync(detailSubPage);
        }
Ejemplo n.º 2
0
        private async void OnCreateSubscription(object sender, EventArgs e)
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                UserDialogs.Instance.ShowLoading();
            });

            Double reqPubInterval;
            uint   reqLifeTimeCount;
            uint   reqMaxKeepAliveCount;
            uint   maxNotPerPublish;
            byte   priority;

            try
            {
                if (string.IsNullOrWhiteSpace(RequestedPublishingInterval.Text))
                {
                    throw new EmptyEntryException("Empty Requested Publish Interval Entry!");
                }
                try
                {
                    reqPubInterval = Convert.ToDouble(RequestedPublishingInterval.Text);
                }
                catch (FormatException p)
                {
                    throw new FormatException("Request Publish Format not valid!", p);
                }

                if (string.IsNullOrWhiteSpace(RequestedLifetimeCount.Text))
                {
                    throw new EmptyEntryException("Empty Request Lifetime Count Empty!");
                }
                try
                {
                    reqLifeTimeCount = Convert.ToUInt32(RequestedLifetimeCount.Text);
                }
                catch (FormatException p)
                {
                    throw new FormatException("Request Lifetime Count Format not valid!", p);
                }

                if (string.IsNullOrWhiteSpace(RequestedMaxKeepAliveCount.Text))
                {
                    throw new EmptyEntryException("Empty Request Max Keep Alive Count Entry!");
                }
                try
                {
                    reqMaxKeepAliveCount = Convert.ToUInt32(RequestedMaxKeepAliveCount.Text);
                }
                catch (FormatException p)
                {
                    throw new FormatException("Request Max Keep Alive Count Format non valid!", p);
                }

                if (string.IsNullOrWhiteSpace(MaxNotificationPerPublish.Text))
                {
                    throw new EmptyEntryException("Empty Max Notification Per Publish Entry !");
                }
                try {
                    maxNotPerPublish = Convert.ToUInt32(MaxNotificationPerPublish.Text);
                }
                catch (FormatException p)
                {
                    throw new FormatException("Max Notification Per Publish Format not valid!", p);
                }

                if (string.IsNullOrWhiteSpace(Priority.Text))
                {
                    throw new EmptyEntryException("Empty Priority Entry!");
                }
                try
                {
                    priority = Convert.ToByte(Priority.Text);
                }
                catch (FormatException p)
                {
                    throw new FormatException("Priority Format not valid!", p);
                }

                SubscriptionView subView = await Task.Run(() => client.CreateSub(reqPubInterval, reqLifeTimeCount, reqMaxKeepAliveCount, maxNotPerPublish, true, priority));

                Device.BeginInvokeOnMainThread(() =>
                {
                    UserDialogs.Instance.HideLoading();
                });

                if (subView.PublishingInterval != reqPubInterval || subView.KeepAliveCount != reqMaxKeepAliveCount || subView.LifeTimeCount != reqLifeTimeCount)
                {
                    await DisplayAlert("Info", "Subscription created successfully with revised parameters.", "ok");
                }
                else
                {
                    await DisplayAlert("Info", "Subscription created successfully with requested parameters.", "ok");
                }

                ContentPage detailSubPage = new DetailSubscriptionPage(client, subView.SubscriptionID);
                detailSubPage.Title = "Subscription Details";

                await Navigation.PushAsync(detailSubPage);

                Navigation.RemovePage(this);
            }
            catch (EmptyEntryException p)
            {
                await DisplayAlert("Error", p.Message, "Ok");
            }
            catch (FormatException p)
            {
                await DisplayAlert("Error", p.Message, "Ok");
            }
        }
Ejemplo n.º 3
0
        private async void OnCreateMonitoredItem(object sender, EventArgs e)
        {
            int    typeID;
            ushort namespaceIndex;
            string identifierNode    = null;
            uint   identifierNodeInt = 0;
            int    samplingInterval;
            bool   discardOldest;
            uint   queueSize;
            int    monitoringMode;
            int    filterTrigger;
            uint   deadbandType;
            double deadbandValue;

            try
            {
                typeID = TypeNodeIdPicker.SelectedIndex;
                if (string.IsNullOrEmpty(NodeID.Text))
                {
                    throw new EmptyEntryException("Empty Node ID Entry!");
                }
                if (typeID == 0)
                {
                    try
                    {
                        identifierNodeInt = Convert.ToUInt32(NodeID.Text);
                    }
                    catch (FormatException p)
                    {
                        throw new FormatException("Node ID Format not valid!", p);
                    }
                }
                else
                {
                    identifierNode = NodeID.Text;
                }
                if (string.IsNullOrEmpty(NodeNamespace.Text))
                {
                    throw new EmptyEntryException("Empty Node Namespace Entry!");
                }
                try {
                    namespaceIndex = Convert.ToUInt16(NodeNamespace.Text);
                }
                catch (FormatException p)
                {
                    throw new FormatException("Node Namespace not valid!", p);
                }

                if (string.IsNullOrEmpty(RequestedSamplingInterval.Text))
                {
                    throw new EmptyEntryException("Requested Sampling Interval Empty!");
                }
                try {
                    samplingInterval = Convert.ToInt32(RequestedSamplingInterval.Text);
                }
                catch (FormatException p) {
                    throw new FormatException("Requested Sampling Interval format not valid!", p);
                }
                discardOldest = DiscardOldest.IsToggled;
                if (string.IsNullOrEmpty(QueueSize.Text))
                {
                    throw new EmptyEntryException("Empty Queue Size Entry!");
                }
                try
                {
                    queueSize = Convert.ToUInt32(QueueSize.Text);
                }
                catch (FormatException p)
                {
                    throw new FormatException("Queue Size format non valid!", p);
                }
                monitoringMode = MonitoringModePicker.SelectedIndex;
                filterTrigger  = TriggerPicker.SelectedIndex;

                deadbandType = Convert.ToUInt32(DeadbandTypePicker.SelectedIndex);
                if (string.IsNullOrEmpty(DeadbandValue.Text))
                {
                    throw new EmptyEntryException("Empty Deadband Value Entry!");
                }
                try {
                    deadbandValue = Convert.ToDouble(DeadbandValue.Text);
                    if ((deadbandType == 2) && (deadbandValue < 0 || deadbandValue > 1))
                    {
                        throw new FormatException("Deadband value is not between 0 and 1!");
                    }
                }
                catch (FormatException p)
                {
                    throw new FormatException("Deadband Value Format is not valid!", p);
                }

                Device.BeginInvokeOnMainThread(() =>
                {
                    UserDialogs.Instance.ShowLoading();
                });
                if (typeID == 0)
                {
                    await Task.Run(() => client.CreateMonitoredItem(subscriptionId, namespaceIndex, identifierNodeInt, samplingInterval, discardOldest, queueSize, monitoringMode, filterTrigger, deadbandType, deadbandValue));
                }
                else
                {
                    await Task.Run(() => client.CreateMonitoredItem(subscriptionId, namespaceIndex, identifierNode, samplingInterval, discardOldest, queueSize, monitoringMode, filterTrigger, deadbandType, deadbandValue));
                }
                Device.BeginInvokeOnMainThread(() =>
                {
                    UserDialogs.Instance.HideLoading();
                });
                await DisplayAlert("Info", "Monitored Item Created Successfully", "Ok");

                ContentPage detailSubPage1 = new DetailSubscriptionPage(client, subscriptionId);
                detailSubPage1.Title = "Subscription Details";
                Navigation.RemovePage(Navigation.NavigationStack[this.Navigation.NavigationStack.Count - 2]);
                await Navigation.PushAsync(detailSubPage1);

                Navigation.RemovePage(this);
            }
            catch (FormatException p)
            {
                await DisplayAlert("Error", p.Message, "Ok");
            }
            catch (EmptyEntryException p)
            {
                await DisplayAlert("Error", p.Message, "Ok");
            }
            catch (NoNodeToReadException p)
            {
                await DisplayAlert("Error", p.Message, "Ok");
            }
        }