public static DesiredProperties FromJsonObject(JObject appsNode)
            {
                List <AppDesiredState> appDesiredStates = new List <AppxManagementDataContract.AppDesiredState>();
                AppListQuery           appListQuery     = new AppListQuery();

                foreach (JProperty property in appsNode.Children())
                {
                    // Logger.Log("Property Name = " + property.Name, LoggingLevel.Verbose);
                    if (String.IsNullOrEmpty(property.Name))
                    {
                        continue;
                    }

                    if (property.Name == JsonQueryApps)
                    {
                        appListQuery = AppListQuery.FromJsonObject((JObject)property.Value);
                    }
                    else
                    {
                        appDesiredStates.Add(AppDesiredState.FromJsonObject(property.Name, property.Value));
                    }
                }

                return(new DesiredProperties(appDesiredStates, appListQuery));
            }
            public static AppDesiredState FromJsonObject(string packageFamilyId, JToken jToken)
            {
                AppDesiredState desiredState = new AppDesiredState(packageFamilyId);

                if (jToken is JObject)
                {
                    JObject appPropertiesObject = (JObject)jToken;

                    foreach (JProperty appProperty in appPropertiesObject.Properties())
                    {
                        // We expect non-null non-object values.
                        if (appProperty == null || appProperty.Value == null || !(appProperty.Value is JValue))
                        {
                            continue;
                        }

                        if (appProperty.Name == JsonPkgFamilyName)
                        {
                            desiredState.packageFamilyName = appProperty.Value.ToString();
                        }
                        else if (appProperty.Name == JsonStartUp)
                        {
                            desiredState.startUp = AppxManagementDataContract.StartUpTypeFromString(appProperty.Value.ToString());
                        }
                        else if (appProperty.Name == JsonVersion)
                        {
                            string value = appProperty.Value.ToString();
                            if (value == JsonQueryApps)
                            {
                                desiredState.action = AppDesiredAction.Query;
                            }
                            else if (value == AppxManagementDataContract.VersionNotInstalled)
                            {
                                desiredState.action = AppDesiredAction.Uninstall;
                            }
                            else
                            {
                                Version result = null;
                                if (Version.TryParse(value, out result))
                                {
                                    desiredState.action  = AppDesiredAction.Install;
                                    desiredState.version = result;
                                }
                                else
                                {
                                    desiredState.action       = AppDesiredAction.Undefined;
                                    desiredState.errorCode    = ErrorCodes.INVALID_DESIRED_VERSION;
                                    desiredState.errorMessage = "Invalid desired version format!";
                                }
                            }
                        }
                        else if (appProperty.Name == JsonAppxSource)
                        {
                            desiredState.appxSource = appProperty.Value.ToString();
                        }
                        else if (appProperty.Name == JsonDepsSources)
                        {
                            desiredState.depsSources = appProperty.Value.ToString();
                        }
                        else if (appProperty.Name == JsonCertSource)
                        {
                            desiredState.certSource = appProperty.Value.ToString();
                        }
                        else if (appProperty.Name == JsonCertStore)
                        {
                            desiredState.certStore = appProperty.Value.ToString();
                        }
                    }
                }
                else
                {
                    JValue value = (JValue)jToken;
                    if (value == null || value.Value == null)
                    {
                        desiredState.action = AppDesiredAction.Unreport;
                    }
                    else
                    {
                        desiredState.action       = AppDesiredAction.Undefined;
                        desiredState.errorCode    = ErrorCodes.INVALID_DESIRED_PKG_FAMILY_ID;
                        desiredState.errorMessage = "Invalid desired package family id value!";
                    }
                }

                return(desiredState);
            }