Exemple #1
0
        public static async Task <DiscoveryServiceCache> CreateAndSaveAsync(string userId, IDictionary <string, CapabilityDiscoveryResult> discoveryInfoForServices)
        {
            var cache = new DiscoveryServiceCache
            {
                UserId = userId,
                DiscoveryInfoForServices = discoveryInfoForServices
            };

            StorageFolder localFolder = ApplicationData.Current.LocalFolder;

            StorageFile textFile = await localFolder.CreateFileAsync(FileName, CreationCollisionOption.ReplaceExisting);

            try
            {
                _lock.EnterWriteLock();
                using (IRandomAccessStream textStream = await textFile.OpenAsync(FileAccessMode.ReadWrite))
                {
                    using (DataWriter textWriter = new DataWriter(textStream))
                    {
                        cache.Save(textWriter);
                        await textWriter.StoreAsync();
                    }
                }
            }
            finally
            {
                _lock.ExitWriteLock();
            }

            return(cache);
        }
Exemple #2
0
        public static async Task <ServiceCapabilityCache> LoadAsync(ServiceCapabilities capability)
        {
            CapabilityDiscoveryResult capabilityDiscoveryResult = null;

            DiscoveryServiceCache cache = await LoadAsync();

            cache.DiscoveryInfoForServices.TryGetValue(capability.ToString(), out capabilityDiscoveryResult);

            if (cache == null || capabilityDiscoveryResult == null)
            {
                return(null);
            }

            return(new ServiceCapabilityCache
            {
                UserId = cache.UserId,
                CapabilityResult = capabilityDiscoveryResult
            });
        }
Exemple #3
0
        private static DiscoveryServiceCache Load(DataReader textReader)
        {
            var cache = new DiscoveryServiceCache();

            cache.UserId = textReader.ReadString();
            var entryCount = textReader.ReadInt32();

            cache.DiscoveryInfoForServices = new Dictionary <string, CapabilityDiscoveryResult>(entryCount);

            for (var i = 0; i < entryCount; i++)
            {
                var key = textReader.ReadString();

                var serviceResourceId  = textReader.ReadString();
                var serviceEndpointUri = new Uri(textReader.ReadString());
                var serviceApiVersion  = textReader.ReadString();

                cache.DiscoveryInfoForServices.Add(key, new CapabilityDiscoveryResult(serviceEndpointUri, serviceResourceId, serviceApiVersion));
            }

            return(cache);
        }
        public static async Task<DiscoveryServiceCache> CreateAndSaveAsync(string userId, IDictionary<string, CapabilityDiscoveryResult> discoveryInfoForServices)
        {
            var cache = new DiscoveryServiceCache
            {
                UserId = userId,
                DiscoveryInfoForServices = discoveryInfoForServices
            };

            StorageFolder localFolder = ApplicationData.Current.LocalFolder;

            StorageFile textFile = await localFolder.CreateFileAsync(FileName, CreationCollisionOption.ReplaceExisting);
            try
            {
                _lock.EnterWriteLock();
                using (IRandomAccessStream textStream = await textFile.OpenAsync(FileAccessMode.ReadWrite))
                {
                    using (DataWriter textWriter = new DataWriter(textStream))
                    {
                        cache.Save(textWriter);
                        await textWriter.StoreAsync();
                    }
                }
            }
            finally
            {
                _lock.ExitWriteLock();
            }

            return cache;
        }
        private static DiscoveryServiceCache Load(DataReader textReader)
        {
            var cache = new DiscoveryServiceCache();

            cache.UserId = textReader.ReadString();
            var entryCount = textReader.ReadInt32();

            cache.DiscoveryInfoForServices = new Dictionary<string, CapabilityDiscoveryResult>(entryCount);

            for (var i = 0; i < entryCount; i++)
            {
                var key = textReader.ReadString();

                var serviceResourceId = textReader.ReadString();
                var serviceEndpointUri = new Uri(textReader.ReadString());
                var serviceApiVersion = textReader.ReadString();

                cache.DiscoveryInfoForServices.Add(key, new CapabilityDiscoveryResult(serviceEndpointUri, serviceResourceId, serviceApiVersion));
            }

            return cache;
        }