public void SaveServiceSettings(Guid id, AuthSettingsBase settings) { SettingsStore[id] = settings; }
/// <summary> /// Find all available services in all assemblies /// </summary> public void FindServices() { serviceConsumers = new Dictionary <Guid, ServiceConsumerInfo>(); AppDomainSetup setup = new AppDomainSetup(); setup.ApplicationName = "TempDomain"; setup.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; setup.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; setup.PrivateBinPath = AppDomain.CurrentDomain.SetupInformation.PrivateBinPath; setup.PrivateBinPathProbe = AppDomain.CurrentDomain.SetupInformation.PrivateBinPathProbe; AppDomain tempDomain = AppDomain.CreateDomain("TempDomain", AppDomain.CurrentDomain.Evidence, setup, AppDomain.CurrentDomain.PermissionSet, new StrongName[0]); var proxy = tempDomain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, typeof(LoadServiceTypesProxy).FullName) as LoadServiceTypesProxy; if (proxy == null) { Log.Error("Proxy is null!"); return; } // find all types which implement IServiceConsumer String path = (AppDomain.CurrentDomain.SetupInformation.PrivateBinPath ?? AppDomain.CurrentDomain.SetupInformation.ApplicationBase); DirectoryInfo binDir = new DirectoryInfo(path); Log.Debug("Scanning for service consumers in '" + binDir.FullName + "'."); foreach (FileInfo assemblyFile in binDir.GetFiles("*.dll")) { try { String assemblyName; String[] consumerTypes = proxy.LoadServiceTypes(assemblyFile.FullName, out assemblyName); foreach (String consumerType in consumerTypes) { IServiceConsumer consumer = tempDomain.CreateInstanceAndUnwrap(assemblyName, consumerType) as IServiceConsumer; if (consumer == null || String.IsNullOrEmpty(consumer.Name)) { Log.Error("Error instantiating type or consumer of type " + consumerType + " has an invalid name."); continue; } LoadConsumer(assemblyName, consumerType, consumer.Name); } } catch (BadImageFormatException) { // don't log those errors } catch (Exception ex) { Log.Error("ServiceManager.FindServices", ex); } } AppDomain.Unload(tempDomain); // create the apps for the services // store the service settings in the database SettingsManager settingsManager = new SettingsManager(); List <ServiceConsumerInfo> tempConsumers = new List <ServiceConsumerInfo>(ServiceConsumers.Values); foreach (ServiceConsumerInfo consumerInfo in tempConsumers) { IServiceConsumer consumer = consumerInfo.ServiceConsumer; try { // save default authentication settings if they don't exist AuthSettingsBase authSettings = settingsManager.GetServiceSettings(consumerInfo.Id); if (authSettings == null || authSettings.GetType().Name != consumer.Settings.GetType().Name) { settingsManager.SaveServiceSettings(consumerInfo.Id, consumer.Settings); } else { consumer.Settings = authSettings; } } catch (Exception ex) { Log.Error("ServiceManager.FindServices.InitializeConsumer", ex); UnloadConsumer(consumerInfo); } } }