//private string serviceName; public void startPlugin(string serviceName, Plugin plugin) { Log = new General.OSAELog(serviceName); Log.Info(plugin.PluginName + ": Starting Plugin..."); OSAEObject obj = OSAEObjectManager.GetObjectByName(plugin.PluginName); //Enabe and start seemed to be mixed, changed to start, enabe is handled at the Webui for now, maybe a method in the future //OSAEObjectManager.ObjectUpdate(plugin.PluginName, plugin.PluginName, obj.Alias, obj.Description, obj.Type, obj.Address, obj.Container, obj.MinTrustLevel, true); try { if (plugin.ActivatePlugin()) { // plugin.Enabled = true; plugin.RunInterface(serviceObject); OSAEObjectStateManager.ObjectStateSet(plugin.PluginName, "ON", "SYSTEM"); Log.Debug(plugin.PluginName + ": Plugin started."); } } catch (Exception ex) { Log.Error("Error activating plugin (" + plugin.PluginName + "): " + ex.Message, ex); OSAEObjectStateManager.ObjectStateSet(plugin.PluginName, "OFF", "SYSTEM"); } }
/// <summary> /// /// </summary> public void LoadPlugins(string serviceName) { Log = new General.OSAELog(serviceName); Log.Info("Loading Plugins..."); OSAEPluginCollection newPlugins = new OSAEPluginCollection(); var pluginAssemblies = new List<OSAEPluginBase>(); var types = PluginFinder.FindPlugins(); foreach (var type in types) { Log.Debug("TypeName: " + type.TypeName + ", AssemblyName: " + type.AssemblyName); var domain = Common.CreateSandboxDomain("Sandbox Domain", type.Location, SecurityZone.Internet, typeof(OSAEService)); domain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledPluginExceptions); Plugin p = new Plugin(type.AssemblyName, type.TypeName, domain, type.Location); if (!pluginLoaded(p.PluginType)) newPlugins.Add(p); } Log.Info("Found " + newPlugins.Count.ToString() + " Assemblies"); MySqlConnection connection = new MySqlConnection(Common.ConnectionString); foreach (Plugin plugin in newPlugins) { try { Log.Info("----------------------------------------------------"); if (plugin.PluginName != "") { OSAEObject obj = OSAEObjectManager.GetObjectByName(plugin.PluginName); if (obj == null) { bool found = OSAEObjectTypeManager.ObjectTypeExists(plugin.PluginType); if (found) { OSAEObjectManager.ObjectAdd(plugin.PluginName, "", plugin.PluginName + " plugin's Object", plugin.PluginType, "", serviceName, 50, false); obj = OSAEObjectManager.GetObjectByName(plugin.PluginName); if (obj == null) Log.Info(plugin.PluginName + ": I failed to create the Plugin Object!"); else Log.Info(obj.Name + ": Plugin Object was Not found, so I created a new Plugin Object."); } else Log.Info(": Plugin Object Type Not found for: " + plugin.PluginType + ". Plugin Object Cannot be Created."); } if (obj != null) { Log.Info(obj.Name + ": Plugin Object found. Plugin Object Enabled = " + obj.Enabled.ToString()); //No idea why the following line would run //OSAEObjectManager.ObjectUpdate(plugin.PluginName,plugin.PluginName, "", plugin.PluginName + " plugin's Object", plugin.PluginType, "", serviceName, 50, true); if (obj.Enabled == true) { plugin.Enabled = true; startPlugin(serviceObject, plugin); } else { plugin.Enabled = false; OSAEObjectStateManager.ObjectStateSet(obj.Name, "OFF", serviceObject); } Log.Info(obj.Name + ": Plugin Enabled = " + plugin.Enabled.ToString()); Log.Info(obj.Name + ": Plugin Version = " + plugin.PluginVersion); OSAEObjectManager.ObjectUpdate(plugin.PluginName, plugin.PluginName, "", plugin.PluginName + " plugin's Object", plugin.PluginType, obj.Address, serviceName, 50, plugin.Enabled); OSAEObjectPropertyManager.ObjectPropertySet(obj.Name, "Version", plugin.PluginVersion, serviceName); OSAEObjectPropertyManager.ObjectPropertySet(obj.Name, "Author", plugin.PluginAuthor, serviceName); } } else { bool found = OSAEObjectTypeManager.ObjectTypeExists(plugin.PluginType); if (found) { plugin.PluginName = plugin.PluginType; Log.Info(plugin.PluginName + ": Plugin object does not exist in DB!"); OSAEObjectManager.ObjectAdd(plugin.PluginName, "", plugin.PluginName, plugin.PluginType, "", "System", 50, false); OSAEObjectPropertyManager.ObjectPropertySet(plugin.PluginName, "Version", plugin.PluginVersion, serviceName); OSAEObjectPropertyManager.ObjectPropertySet(plugin.PluginName, "Author", plugin.PluginAuthor, serviceName); Log.Info(plugin.PluginName + ": Plugin added to DB."); //Uh, this still looks wrong below. I don't think it is needed, besides, any new plugin is disabled... //UDPConnection.SendObject("Plugin", plugin.PluginName + " | " + plugin.Enabled.ToString() + " | " + plugin.PluginVersion + " | Stopped | " + plugin.LatestAvailableVersion + " | " + plugin.PluginType + " | " + Common.ComputerName, new IPEndPoint(IPAddress.Broadcast, 10051)); } else Log.Info(": Plugin Object Type Not found for: " + plugin.PluginType + ". Plugin Object Cannot be Created!"); } plugins.Add(plugin); masterPlugins.Add(plugin); } catch (Exception ex) { Log.Error("Error loading plugin: " + ex.Message, ex); } } OSAEObjectStateManager.ObjectStateSet(serviceObject, "ON", serviceObject); }
/// <summary> /// /// </summary> public void LoadPlugins(string serviceName) { Log = new General.OSAELog(serviceName); Log.Info("Loading Plugins..."); OSAEPluginCollection newPlugins = new OSAEPluginCollection(); var pluginAssemblies = new List <OSAEPluginBase>(); var types = PluginFinder.FindPlugins(); foreach (var type in types) { Log.Debug("TypeName: " + type.TypeName + ", AssemblyName: " + type.AssemblyName); var domain = Common.CreateSandboxDomain("Sandbox Domain", type.Location, SecurityZone.Internet, typeof(OSAEService)); domain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledPluginExceptions); Plugin p = new Plugin(type.AssemblyName, type.TypeName, domain, type.Location); if (!pluginLoaded(p.PluginType)) { newPlugins.Add(p); } } Log.Info("Found " + newPlugins.Count.ToString() + " Assemblies"); MySqlConnection connection = new MySqlConnection(Common.ConnectionString); foreach (Plugin plugin in newPlugins) { try { Log.Info("----------------------------------------------------"); if (plugin.PluginName != "") { OSAEObject obj = OSAEObjectManager.GetObjectByName(plugin.PluginName); if (obj == null) { bool found = OSAEObjectTypeManager.ObjectTypeExists(plugin.PluginType); if (found) { OSAEObjectManager.ObjectAdd(plugin.PluginName, "", plugin.PluginName + " plugin's Object", plugin.PluginType, "", serviceName, 50, false); obj = OSAEObjectManager.GetObjectByName(plugin.PluginName); if (obj == null) { Log.Info(plugin.PluginName + ": I failed to create the Plugin Object!"); } else { Log.Info(obj.Name + ": Plugin Object was Not found, so I created a new Plugin Object."); } } else { Log.Info(": Plugin Object Type Not found for: " + plugin.PluginType + ". Plugin Object Cannot be Created."); } } if (obj != null) { Log.Info(obj.Name + ": Plugin Object found. Plugin Object Enabled = " + obj.Enabled.ToString()); //No idea why the following line would run //OSAEObjectManager.ObjectUpdate(plugin.PluginName,plugin.PluginName, "", plugin.PluginName + " plugin's Object", plugin.PluginType, "", serviceName, 50, true); if (obj.Enabled == true) { plugin.Enabled = true; startPlugin(serviceObject, plugin); } else { plugin.Enabled = false; OSAEObjectStateManager.ObjectStateSet(obj.Name, "OFF", serviceObject); } Log.Info(obj.Name + ": Plugin Enabled = " + plugin.Enabled.ToString()); Log.Info(obj.Name + ": Plugin Version = " + plugin.PluginVersion); OSAEObjectManager.ObjectUpdate(plugin.PluginName, plugin.PluginName, "", plugin.PluginName + " plugin's Object", plugin.PluginType, obj.Address, serviceName, 50, plugin.Enabled); OSAEObjectPropertyManager.ObjectPropertySet(obj.Name, "Version", plugin.PluginVersion, serviceName); OSAEObjectPropertyManager.ObjectPropertySet(obj.Name, "Author", plugin.PluginAuthor, serviceName); } } else { bool found = OSAEObjectTypeManager.ObjectTypeExists(plugin.PluginType); if (found) { plugin.PluginName = plugin.PluginType; Log.Info(plugin.PluginName + ": Plugin object does not exist in DB!"); OSAEObjectManager.ObjectAdd(plugin.PluginName, "", plugin.PluginName, plugin.PluginType, "", "System", 50, false); OSAEObjectPropertyManager.ObjectPropertySet(plugin.PluginName, "Version", plugin.PluginVersion, serviceName); OSAEObjectPropertyManager.ObjectPropertySet(plugin.PluginName, "Author", plugin.PluginAuthor, serviceName); Log.Info(plugin.PluginName + ": Plugin added to DB."); //Uh, this still looks wrong below. I don't think it is needed, besides, any new plugin is disabled... //UDPConnection.SendObject("Plugin", plugin.PluginName + " | " + plugin.Enabled.ToString() + " | " + plugin.PluginVersion + " | Stopped | " + plugin.LatestAvailableVersion + " | " + plugin.PluginType + " | " + Common.ComputerName, new IPEndPoint(IPAddress.Broadcast, 10051)); } else { Log.Info(": Plugin Object Type Not found for: " + plugin.PluginType + ". Plugin Object Cannot be Created!"); } } plugins.Add(plugin); masterPlugins.Add(plugin); } catch (Exception ex) { Log.Error("Error loading plugin: " + ex.Message, ex); } } OSAEObjectStateManager.ObjectStateSet(serviceObject, "ON", serviceObject); }
//private string serviceName; public void startPlugin(string serviceName,Plugin plugin) { Log = new General.OSAELog(serviceName); Log.Info(plugin.PluginName + ": Starting Plugin..."); OSAEObject obj = OSAEObjectManager.GetObjectByName(plugin.PluginName); //Enabe and start seemed to be mixed, changed to start, enabe is handled at the Webui for now, maybe a method in the future //OSAEObjectManager.ObjectUpdate(plugin.PluginName, plugin.PluginName, obj.Alias, obj.Description, obj.Type, obj.Address, obj.Container, obj.MinTrustLevel, true); try { if (plugin.ActivatePlugin()) { // plugin.Enabled = true; plugin.RunInterface(serviceObject); OSAEObjectStateManager.ObjectStateSet(plugin.PluginName, "ON", "SYSTEM"); Log.Debug(plugin.PluginName + ": Plugin started."); } } catch (Exception ex) { Log.Error("Error activating plugin (" + plugin.PluginName + "): " + ex.Message, ex); OSAEObjectStateManager.ObjectStateSet(plugin.PluginName, "OFF", "SYSTEM"); } }