Example #1
0
        public async Task<bool> CreateSampleServicesAsync()
        {
            var localSettings = ApplicationData.Current.LocalSettings;
            GetOrCreateContainer(ServicesKey);
            var sampleStore = new SampleStore();

            var services = await sampleStore.GetAllSamplesAsync(AppData.CurrentVersion, AppData.DesiredVersion);
            int index = 0;
            foreach (var serviceInfo in services)
            {
                serviceInfo.Index = index;
                localSettings.Containers[ServicesKey].Values[serviceInfo.Name] = FormatServiceInfo(serviceInfo);
                await SaveSettingToFileAsync(serviceInfo.MetadataCacheFilename, serviceInfo.MetadataCache);
                ++index;
            }
            return true;
        }
Example #2
0
        public async Task<bool> UpdateSampleServicesAsync()
        {
            var localSettings = ApplicationData.Current.LocalSettings;
            GetOrCreateContainer(ServicesKey);
            var sampleStore = new SampleStore();

            var newServices = await sampleStore.GetNewSamplesAsync(AppData.CurrentVersion, AppData.DesiredVersion);
            int index = localSettings.Containers[ServicesKey].Values.Count;
            foreach (var serviceInfo in newServices)
            {
                serviceInfo.Index = index;
                localSettings.Containers[ServicesKey].Values[serviceInfo.Name] = FormatServiceInfo(serviceInfo);
                await SaveSettingToFileAsync(serviceInfo.MetadataCacheFilename, serviceInfo.MetadataCache);
                ++index;
            }

            var updatedServices = await sampleStore.GetUpdatedSamplesAsync(AppData.CurrentVersion, AppData.DesiredVersion);
            foreach (var serviceInfo in updatedServices)
            {
                if (localSettings.Containers[ServicesKey].Values.ContainsKey(serviceInfo.Name))
                {
                    await SaveSettingToFileAsync(serviceInfo.MetadataCacheFilename, serviceInfo.MetadataCache);
                }
            }

            var expiredServices = await sampleStore.GetExpiredSamplesAsync(AppData.CurrentVersion, AppData.DesiredVersion);
            foreach (var kv in localSettings.Containers[ServicesKey].Values
                .Where(x => expiredServices.Any(y => x.Key == y.Name)))
            {
                localSettings.Containers[ServicesKey].Values.Remove(kv);
            }

            return true;
        }