public IReadOnlyCollection <CrmPluginViewModel> LoadPlugins() { var pluginsDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins"); if (!Directory.Exists(pluginsDir)) { Directory.CreateDirectory(pluginsDir); } var plugins = new List <CrmPluginViewModel>(); foreach (var file in Directory.GetFiles(pluginsDir, "*.dll")) { var assembly = Assembly.LoadFile(file); var type = assembly.GetExportedTypes().FirstOrDefault(t => typeof(ICrm).IsAssignableFrom(t) && t.IsClass); if (type == null) { continue; } var crmClient = Activator.CreateInstance(type) as ICrm; if (crmClient == null) { continue; } var passwordService = new PasswordService(crmClient.GetName()); var crmVM = new CrmPluginViewModel(crmClient, passwordService, navigationService); plugins.Add(crmVM); } return(plugins); }
public IReadOnlyCollection <CrmPluginViewModel> LoadPlugins() { var plugins = new List <CrmPluginViewModel>(); // ReSharper disable once JoinDeclarationAndInitializer IEnumerable <string> assemblyNames; #if DEBUG assemblyNames = Windows.ApplicationModel.Package.Current.InstalledLocation.GetFilesAsync().AsTask().Result .Where(file => file.FileType == ".dll" && file.Name.Contains("Api")) .Select(file => file.Name.Substring(0, file.Name.Length - file.FileType.Length)); #else assemblyNames = new[] { "JiraApi", "SaritasaApi" }; #endif foreach (var name in assemblyNames) { var assembly = Assembly.Load(new AssemblyName() { Name = name }); var type = assembly.GetExportedTypes().FirstOrDefault(t => typeof(ICrm).IsAssignableFrom(t)); if (type == null) { continue; } var crmClient = Activator.CreateInstance(type) as ICrm; if (crmClient == null) { continue; } var passwordService = new PasswordService(crmClient.GetName()); var crmVM = new CrmPluginViewModel(crmClient, passwordService, navigationService); plugins.Add(crmVM); } return(plugins); }