/// <summary>
        /// An application is selected, update textboxes with selected application.
        /// </summary>
        private void ListViewApps_ItemClick(object sender, ItemClickEventArgs e)
        {
            AppReportedState appReportedState = (AppReportedState)e.ClickedItem;

            if (appReportedState.PackageFamilyName != null)
            {
                PackageFamilyInput1.Text = appReportedState.PackageFamilyName;
                PackageFamilyInput2.Text = appReportedState.PackageFamilyName;
                VersionInput.Text        = "not installed";
                StartupInput.Text        = appReportedState.StartUp;
            }
        }
        /// <summary>
        /// Uninstall an application via device twin.
        /// </summary>
        private async void UninstallAppButton_ClickAsync(object sender, RoutedEventArgs e)
        {
            if (PackageFamilyInput2.Text.Length == 0)
            {
                _mainPage.ShowDialogAsync("Invaid Input", "Please enter all fields to Uninstall application");
                return;
            }
            string refreshingValue = "\"refreshing\"";

            AppReportedState[] appArray = (AppReportedState[])AppsListView.ItemsSource;
            if (appArray != null && appArray.Length > 0)
            {
                AppReportedState appSelected = Array.Find(appArray, a => a.PackageFamilyName == PackageFamilyInput2.Text);
                string           finalValue  = "{ \"apps\" : { \"" + appSelected.PackageFamilyName.Replace('.', '_') + "\": {\"pkgFamilyName\": \"" + appSelected.PackageFamilyName + "\", \"version\": \"" + VersionInput.Text + "\", \"startup\": \"" + StartupInput.Text + "\", \"installDate\": \"" + appSelected.InstallDate + "\" } } }";
                await _mainPage.UpdateTwinData(refreshingValue, finalValue);
            }
        }
        /// <summary>
        /// Update Applications list view with json parameter.
        /// </summary>
        /// <param name="token">The json object that describes the application list.</param>
        private void AppsStatusJsonToUI(JToken token)
        {
            if (!(token is JObject))
            {
                _mainPage.ShowDialogAsync("Read Application Twin Error", "Invalid apps node json format!");
                return;
            }

            List <AppReportedState> data = new List <AppReportedState>();

            JObject root = (JObject)token;

            foreach (JToken p in root.Children())
            {
                if (!(p is JProperty))
                {
                    continue;
                }
                JProperty property            = (JProperty)p;
                string    packageFamilyJsonId = property.Name;
                if (property.Value == null)
                {
                    data.Add(new AppReportedState(packageFamilyJsonId, null, null, null, null));
                }
                else if (property.Value is JObject)
                {
                    AppReportedState appStatusData           = new AppReportedState();
                    JObject          packageFamilyProperties = (JObject)property.Value;
                    foreach (JToken p1 in packageFamilyProperties.Children())
                    {
                        if (!(p1 is JProperty))
                        {
                            continue;
                        }
                        JProperty childProperty = (JProperty)p1;
                        if (childProperty.Name == "pkgFamilyName")
                        {
                            appStatusData.PackageFamilyName = childProperty.Value.ToString();
                        }
                        else if (childProperty.Name == "version")
                        {
                            appStatusData.Version = childProperty.Value.ToString();
                        }
                        else if (childProperty.Name == "installDate")
                        {
                            appStatusData.InstallDate = childProperty.Value.ToString();
                        }
                        else if (childProperty.Name == "startUp")
                        {
                            appStatusData.StartUp = childProperty.Value.ToString();
                        }
                        else if (childProperty.Name == "error")
                        {
                            appStatusData.Error = childProperty.Value.ToString();
                        }
                    }
                    if (appStatusData.PackageFamilyName != null && appStatusData.PackageFamilyName.Length > 0)
                    {
                        data.Add(appStatusData);
                    }
                }
            }
            AppsListView.ItemsSource = data.ToArray();
        }