Пример #1
0
        /// <summary>
        /// Register providers from user settings, where they were previously saved.
        /// </summary>
        public async Task RestoreProviders()
        {
            // Load available IProvider types into memory
            if (ProviderService.Available.Count == 0)
            {
                ProviderService.LoadProviders();
            }

            var tasks = new Dictionary <string, Task <bool> >();

            // ToList() is needed because the original Dictionary is changing while we iterating
            SettingsService.Current.SafeProviders
            .ToList()
            .ForEach(p => tasks[p.Key] = ProviderService.RegisterProvider(
                         ProviderService.GetProviderById(p.Value.Id), p.Key, p.Value.State, false));

            // Wait for tasks to finish and remove unloaded providers
            foreach (var task in tasks)
            {
                if (!ProviderService.Loaded.ContainsKey(task.Key) && !await task.Value)
                {
                    ToastService.Create(string.Format(Resources.ProviderRegistrationFailed, task.Key));
                    ProviderService.ClearProvider(task.Key);
                }
            }
        }