//Add feed subscription to collection given name and URI
        private void AddFeedSubscription(string argFeedName, string argFeedURIString)
        {
            ApplicationDataCompositeValue newFeedSubscription = new ApplicationDataCompositeValue();

            newFeedSubscription.Add("FeedName", argFeedName);
            newFeedSubscription.Add("FeedUri", argFeedURIString);
            feedSubscriptionsCollection.Add(newFeedSubscription);
            SaveFeedSubscriptionsSettings();
        }
        //Add entry to FeedSubscription collection given URI
        private async Task AddFeedSubscription(string argFeedURIString)
        {
            ApplicationDataCompositeValue newFeedSubscription = new ApplicationDataCompositeValue();
            //We don't have a name for the feed so we need to fetch it
            Task <string> t = FetchFeedNameAsync(argFeedURIString);
            await         t;

            newFeedSubscription.Add("FeedName", t.Result);
            newFeedSubscription.Add("FeedUri", argFeedURIString);
            feedSubscriptionsCollection.Add(newFeedSubscription);
            SaveFeedSubscriptionsSettings();
        }
        /// <summary>
        /// Saves a group of items by its key in a composite.
        /// This method should be considered for objects that do not exceed 8k bytes during the lifetime of the application
        /// (refers to <see cref="SaveFileAsync{T}(string, T)"/> for complex/large objects) and for groups of settings which
        /// need to be treated in an atomic way.
        /// </summary>
        /// <typeparam name="T">Type of object saved</typeparam>
        /// <param name="compositeKey">Key of the composite (that contains settings)</param>
        /// <param name="values">Objects to save</param>
        public void Save <T>(string compositeKey, IDictionary <string, T> values)
        {
            if (KeyExists(compositeKey))
            {
                ApplicationDataCompositeValue composite = (ApplicationDataCompositeValue)Settings.Values[compositeKey];

                foreach (KeyValuePair <string, T> setting in values)
                {
                    if (composite.ContainsKey(setting.Key))
                    {
                        composite[setting.Key] = JsonConvert.SerializeObject(setting.Value);
                    }
                    else
                    {
                        composite.Add(setting.Key, JsonConvert.SerializeObject(setting.Value));
                    }
                }
            }
            else
            {
                ApplicationDataCompositeValue composite = new ApplicationDataCompositeValue();
                foreach (KeyValuePair <string, T> setting in values)
                {
                    composite.Add(setting.Key, JsonConvert.SerializeObject(setting.Value));
                }

                Settings.Values[compositeKey] = composite;
            }
        }
        /// <inheritdoc />
        public void Save<T>(string compositeKey, IDictionary<string, T> values)
        {
            if (KeyExists(compositeKey))
            {
                ApplicationDataCompositeValue composite = (ApplicationDataCompositeValue)Settings[compositeKey];

                foreach (KeyValuePair<string, T> setting in values)
                {
                    if (composite.ContainsKey(setting.Key))
                    {
                        composite[setting.Key] = _serializer.Serialize(setting.Value);
                    }
                    else
                    {
                        composite.Add(setting.Key, _serializer.Serialize(setting.Value));
                    }
                }

                Settings[compositeKey] = composite;
                Task.Run(() => Set(_extensionId, UserId, compositeKey, composite));
            }
            else
            {
                ApplicationDataCompositeValue composite = new ApplicationDataCompositeValue();
                foreach (KeyValuePair<string, T> setting in values)
                {
                    composite.Add(setting.Key, _serializer.Serialize(setting.Value));
                }

                Settings[compositeKey] = composite;
                Task.Run(() => Set(_extensionId, UserId, compositeKey, composite));
            }
        }
        public void Save <T>(string compositeKey, IDictionary <string, T> values)
        {
            if (this.TryRead(compositeKey, out ApplicationDataCompositeValue? composite) && composite != null)
            {
                foreach (KeyValuePair <string, T> setting in values)
                {
                    if (composite.ContainsKey(setting.Key))
                    {
                        composite[setting.Key] = this.Serializer.Serialize(setting.Value);
                    }
                    else
                    {
                        composite.Add(setting.Key, this.Serializer.Serialize(setting.Value));
                    }
                }
            }
            else
            {
                composite = new ApplicationDataCompositeValue();
                foreach (KeyValuePair <string, T> setting in values)
                {
                    composite.Add(setting.Key, this.Serializer.Serialize(setting.Value));
                }

                this.Settings.Values[compositeKey] = composite;
            }
        }
Exemple #6
0
        /// <summary>
        /// The save group.
        /// </summary>
        /// <param name="group">
        /// The group.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/> to run asynchronously.
        /// </returns>
        public Task SaveGroup(SkrapeGroup group)
        {
            return(Task.Run(
                       () =>
            {
                var compositeValue = new ApplicationDataCompositeValue
                {
                    { IdProperty, @group.Id },
                    { TitleProperty, @group.Title },
                    {
                        DescriptionProperty,
                        @group.Description
                    },
                    {
                        PageCountProperty,
                        @group.Pages.Count()
                    }
                };
                for (var idx = 0; idx < group.Pages.Count(); idx++)
                {
                    compositeValue.Add(PageIndex + idx, group.Pages[idx].Id);
                }

                var container = Roaming.CreateContainer(GroupKey, ApplicationDataCreateDisposition.Always);
                container.Values[group.Id.ToString()] = compositeValue;
            }));
        }
Exemple #7
0
        /// <summary>
        /// The save page.
        /// </summary>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/> for asynchronous saving.
        /// </returns>
        public async Task SavePage(SkrapedPage page)
        {
            // save loaded status locally, so remote machines will load on first use
            LocalSettings.Values["Page" + page.Id] = page.Loaded;

            var compositeValue = new ApplicationDataCompositeValue
            {
                { IdProperty, page.Id },
                { TitleProperty, page.Title },
                { ThumbnailProperty, page.ThumbnailPath.ToString() },
                { UrlProperty, page.Url.ToString() },
                { ImageCountProperty, page.Images.Count() }
            };

            for (var idx = 0; idx < page.Images.Count(); idx++)
            {
                compositeValue.Add(ImageIndex + idx, page.Images[idx].ToString());
            }

            var container = Roaming.CreateContainer(
                PageKey,
                ApplicationDataCreateDisposition.Always);

            container.Values[page.Id.ToString()] = compositeValue;
            await SavePageData(page);
        }
        private async Task BuildWebIdCache()
        {
            Dictionary<StreamsEnum, string> webIds = _sessionContext.UserContext.WebIDs;
            if (webIds == null)
            {
                string webID = await GetServerWebID();
                string nameFilter = string.Format("{0}.MobileData*", _sessionContext.UserContext.Username);

                HttpResponseMessage responseGetPoints = await _piWebClient.GetPoints(webID, nameFilter);

                dynamic valueResult;
                if (responseGetPoints.StatusCode == HttpStatusCode.Ok)
                {
                    using (StreamReader sr = new StreamReader((await responseGetPoints.Content.ReadAsInputStreamAsync()).AsStreamForRead()))
                    {
                        using (JsonTextReader jReader = new JsonTextReader(sr))
                        {
                            valueResult = JObject.ReadFrom(jReader);
                        }
                    }

                    IList<PointDTO> points = valueResult["Items"].ToObject<List<PointDTO>>();

                    ApplicationDataCompositeValue webIdsStored = new ApplicationDataCompositeValue();

                    foreach (var pt in points)
                    {
                        webIdsStored.Add(pt.Name, pt.WebId);
                    }

                    AppSettingsManager.Instance.LocalSettings.Containers["UserSettings"].AddOrUpdateValue("WebIds", webIdsStored);
                }
            
            }
        }
Exemple #9
0
        public void PersistObject(string key, Dictionary <string, object> objectValuesMap)
        {
            var objectValue = new ApplicationDataCompositeValue();

            foreach (var objectValueKvp in objectValuesMap)
            {
                objectValue.Add(objectValueKvp);
            }
            _localSettings.Values[key] = objectValue;
        }
        public static ApplicationDataCompositeValue ToCompositeValue(this InkToolbarPreferences preferences)
        {
            var result = new ApplicationDataCompositeValue();

            foreach (var property in GetProperties(preferences))
            {
                result.Add(new KeyValuePair <string, object>(property.Name, property.GetValue(preferences)));
            }

            return(result);
        }
Exemple #11
0
        public override bool SaveToLocal(string key, string value)
        {
            ApplicationDataCompositeValue composite =
                ApplicationData.Current.LocalSettings.Values[COMPOSITE_SETTING] as ApplicationDataCompositeValue ??
                new ApplicationDataCompositeValue();

            if (composite.Any(p => p.Key == key))
            {
                composite.Remove(key);
            }
            composite.Add(key, value);

            ApplicationData.Current.LocalSettings.Values[COMPOSITE_SETTING] = composite;

            return(true);
        }
        private async Task BuildWebIdCache()
        {
            Dictionary <StreamsEnum, string> webIds = _sessionContext.UserContext.WebIDs;

            if (webIds == null)
            {
                string webID = await GetServerWebID();

                string nameFilter = string.Format("{0}.MobileData*", _sessionContext.UserContext.Username);

                HttpResponseMessage responseGetPoints = await _piWebClient.GetPoints(webID, nameFilter);

                dynamic valueResult;
                if (responseGetPoints.StatusCode == HttpStatusCode.Ok)
                {
                    using (StreamReader sr = new StreamReader((await responseGetPoints.Content.ReadAsInputStreamAsync()).AsStreamForRead()))
                    {
                        using (JsonTextReader jReader = new JsonTextReader(sr))
                        {
                            valueResult = JObject.ReadFrom(jReader);
                        }
                    }

                    IList <PointDTO> points = valueResult["Items"].ToObject <List <PointDTO> >();

                    ApplicationDataCompositeValue webIdsStored = new ApplicationDataCompositeValue();

                    foreach (var pt in points)
                    {
                        webIdsStored.Add(pt.Name, pt.WebId);
                    }

                    AppSettingsManager.Instance.LocalSettings.Containers["UserSettings"].AddOrUpdateValue("WebIds", webIdsStored);
                }
            }
        }