/// <summary> /// Loads the type. /// </summary> /// <param name="component">The type.</param> public void LoadComponent(Configuration.GlobalPlugin component) { _type = component; var globalSettings = ProgramSettings.GetGlobalSettings(); Image icon = Resources.add_on; if (component.Icon != null) { icon = component.Icon; if (string.IsNullOrWhiteSpace(component.IconPath)) { component.IconPath = PluginsManager.SaveIconOnCache(component.Icon, globalSettings); } } else if (!string.IsNullOrWhiteSpace(component.IconPath)) { string iconLocation = Path.Combine(globalSettings.DirectoriesSettings.CacheDirectory, component.IconPath); if (File.Exists(iconLocation)) { component.Icon = Image.FromFile(iconLocation); icon = component.Icon; } else if (component.PluginInstance != null) { component.Icon = component.PluginInstance.Icon; component.IconPath = PluginsManager.SaveIconOnCache(component.Icon, globalSettings); icon = component.Icon; } else { component.IconPath = null; } } pictureTypeIcon.Image = icon; lblCreatedBy.Text = component.CreatedBy; lblVersion.Text = component.Version; Uri uriReleaseInfo; lnkReleasaeInfo.Visible = !string.IsNullOrWhiteSpace(component.ReleaseNotesUrl) && Uri.TryCreate(component.ReleaseNotesUrl, UriKind.Absolute, out uriReleaseInfo) && uriReleaseInfo.Scheme == Uri.UriSchemeHttp; Uri uriAuthorWebsite; lnkAuthorWebsite.Visible = !string.IsNullOrWhiteSpace(component.AuthorWebsiteUrl) && Uri.TryCreate(component.AuthorWebsiteUrl, UriKind.Absolute, out uriAuthorWebsite) && uriAuthorWebsite.Scheme == Uri.UriSchemeHttp; txtPluginDescription.Text = component.Description; }
/// <summary> /// Verify the Assembly looking for classes that are compatible plugins and /// then register it in the global settings /// </summary> /// <param name="relativeLocation"></param> /// <param name="assembly">The assembly.</param> /// <param name="settings">The global settings.</param> /// <param name="addToSettings"></param> private static bool CheckAssembly(string relativeLocation, Assembly assembly, GlobalSettings settings, bool addToSettings = true) { _logger.Trace("PluginsManager.CheckAssembly()"); bool isValidAssembly = false; bool isNew = false; // Check all public non-abstract classes foreach (Type type in assembly.GetExportedTypes().Where(t => t.IsClass && !t.IsAbstract)) { Configuration.GlobalPlugin pluginComponent = new Configuration.GlobalPlugin(); bool isValidPlugin = false; try { // Try to create an instance and check if inherit for IPluginBase interface var instance = assembly.CreateInstance(type.FullName) as IPluginBase; if (instance != null) { pluginComponent.Title = instance.Title; pluginComponent.CreatedBy = instance.CreatedBy; pluginComponent.Icon = instance.Icon; pluginComponent.Description = instance.Description; pluginComponent.Version = instance.Version; pluginComponent.ReleaseNotesUrl = instance.ReleaseNotesUrl; pluginComponent.AuthorWebsiteUrl = instance.AuthorWebsiteUrl; pluginComponent.Class = type.FullName; pluginComponent.Enabled = true; pluginComponent.IsValid = true; if (instance is IGeneratorTemplate) { pluginComponent.Base = "GeneratorTemplate"; } else if (instance is IAccessModelController) { pluginComponent.Base = "AccessModelController"; } isValidPlugin = true; } } catch (Exception ex) { _logger.Error(ex, ex.Message); isValidPlugin = false; } if (isValidPlugin) { isValidAssembly = true; // Get Assembly fileName string assemblyName = assembly.GetName().Name; string guid = ((GuidAttribute)assembly.GetCustomAttributes(typeof(GuidAttribute), true)[0]).Value; // Check if assembly was already registered in the global settings var settingsAssembly = settings.Assemblies.FirstOrDefault(a => a.Guid.Equals(guid, StringComparison.InvariantCultureIgnoreCase)); // if not add to the list if (settingsAssembly == null) { settingsAssembly = new GlobalAssembly(); settingsAssembly.Title = assemblyName; settingsAssembly.Guid = guid; settingsAssembly.Version = assembly.GetName().Version.ToString(); settingsAssembly.File = relativeLocation; settingsAssembly.DateInstalled = DateTime.Now; settingsAssembly.IsValid = true; IAssemblyDetails assemblyDetails = GetAssemblyDetails(assembly); if (assemblyDetails != null) { settingsAssembly.Title = assemblyDetails.Title; settingsAssembly.Version = assemblyDetails.Version; settingsAssembly.Description = assemblyDetails.Description; settingsAssembly.Author = assemblyDetails.Author; settingsAssembly.Url = assemblyDetails.Url; } if (addToSettings) { settings.Assemblies.Add(settingsAssembly); } isNew = true; } // Check if the Class was already registered in the assembly if (!settingsAssembly.Plugins.Exists(t => t.Class.Equals(type.FullName, StringComparison.InvariantCultureIgnoreCase)) && addToSettings) { // if not add to the list settingsAssembly.Plugins.Add(pluginComponent); isNew = true; } } } return(isValidAssembly && isNew); }