public static void LoadPluginTabItem(PluginInstance pluginInstance) { try { if (!pluginInstance.Loaded) { return; } var pluginName = pluginInstance.Instance.FriendlyName; if (SettingsViewModel.Instance.HomePluginList.Any(p => p.ToUpperInvariant() .StartsWith(pluginName.ToUpperInvariant()))) { pluginName = String.Format("{0}[{1}]", pluginName, new Random().Next(1000, 9999)); } SettingsViewModel.Instance.HomePluginList.Add(pluginName); var tabItem = pluginInstance.Instance.CreateTab(); tabItem.Name = Regex.Replace(pluginInstance.Instance.Name, @"[^A-Za-z]", ""); var iconfile = String.Format("{0}\\{1}", Path.GetDirectoryName(pluginInstance.AssemblyPath), pluginInstance.Instance.Icon); var icon = new BitmapImage(new Uri(Common.Constants.DefaultIcon)); icon = File.Exists(iconfile) ? ImageUtilities.LoadImageFromStream(iconfile) : icon; tabItem.HeaderTemplate = ImageHeader(icon, pluginInstance.Instance.FriendlyName); AppViewModel.Instance.PluginTabItems.Add(tabItem); } catch (Exception ex) { } }
/// <summary> /// </summary> /// <param name="plugin"> </param> public void Remove(PluginInstance plugin) { List.Remove(plugin); }
/// <summary> /// </summary> /// <param name="plugin"> </param> public void Add(PluginInstance plugin) { List.Add(plugin); }
/// <summary> /// </summary> /// <param name="assemblyPath"></param> private void VerifyPlugin(string assemblyPath) { try { var bytes = File.ReadAllBytes(assemblyPath); var pAssembly = Assembly.Load(bytes); var pType = pAssembly.GetType(pAssembly.GetName() .Name + ".Plugin"); var implementsIPlugin = typeof (IPlugin).IsAssignableFrom(pType); if (!implementsIPlugin) { Logging.Log(Logger, String.Format("*IPlugin Not Implemented* :: {0}", pAssembly.GetName() .Name)); return; } var plugin = new PluginInstance { Instance = (IPlugin) Activator.CreateInstance(pType), AssemblyPath = assemblyPath }; plugin.Instance.Initialize(Instance); Loaded.Add(plugin); } catch (Exception ex) { } }
/// <summary> /// </summary> /// <param name="assemblyPath"></param> private void VerifyPlugin(string assemblyPath) { try { var bytes = File.ReadAllBytes(assemblyPath); var pAssembly = Assembly.Load(bytes); var references = pAssembly.GetReferencedAssemblies(); var load = true; foreach (var valid in references.Where(a => DependencyUpgrades.Contains(a.Name)) .Select(assembly => HostAssemblyValidation(assembly.Name, assembly.Version)) .Where(valid => !valid)) { load = false; } var pType = pAssembly.GetType(pAssembly.GetName() .Name + ".Plugin"); var implementsIPlugin = typeof (IPlugin).IsAssignableFrom(pType); if (!implementsIPlugin) { Logging.Log(Logger, String.Format("*IPlugin Not Implemented* :: {0}", pAssembly.GetName() .Name)); return; } var plugin = new PluginInstance { Instance = (IPlugin) Activator.CreateInstance(pType), AssemblyPath = assemblyPath }; plugin.Instance.Initialize(Instance); plugin.Loaded = load; Loaded.Add(plugin); } catch (Exception ex) { } }