/// <summary> /// Unregister a provider. /// </summary> /// <param name="name"></param> public static void ClearProvider(string name) { // Remove from the registered providers if (registeredProviders.ContainsKey(name)) { registeredProviders.Remove(name); RegisteredProvidersChanged?.Invoke(); } // Remove from the configuration file if (ConfigService.Current.SafeProviders.ContainsKey(name)) { ConfigService.Current.SafeProviders.Remove(name); } }
/// <summary> /// Try to register a provider. /// </summary> /// <param name="provider">An IProvider class.</param> /// <param name="nick">The nick of the provider - CAN BE ANYTHING!</param> /// <param name="savedState">A saved state that the Provider will try to interpret - if it fails, the registration form will be used.</param> /// <param name="showForm">Enable or disable registration form.</param> /// <returns></returns> public static async Task <bool> RegisterProvider(IProvider provider, string nick, string savedState = null, bool showForm = true) { if (provider == null) { return(false); } // If there is already a REGISTERED PROVIDER with this (exact) nick, return with true if (registeredProviders.ContainsKey(nick)) { return(provider.Name == registeredProviders[nick].Name); } // Try to register the provider form the savedState var state = await provider.Register(savedState, showForm); // If the the registration failed, return with false if (state == null) { return(false); } // Save the provider to the config ConfigService.Current.Providers[nick] = new SavedProvider() { Id = provider.Id, State = state }; // Save the provider as registered registeredProviders[nick] = provider; // Notify listeners RegisteredProvidersChanged?.Invoke(); return(true); }