/// <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 void loadPlugins() { pluginList = new BindingList <PluginDescription>(); List <string> osapdFiles = new List <string>(); string[] pluginFile = Directory.GetFiles(Common.ApiPath + "\\Plugins", "*.osapd", SearchOption.AllDirectories); osapdFiles.AddRange(pluginFile); bool bFoundObject = false; foreach (string path in osapdFiles) { if (!string.IsNullOrEmpty(path)) { bFoundObject = false; PluginDescription desc = new PluginDescription(); desc.Deserialize(path); desc.Status = "No Object"; desc.Enabled = false; this.Log.Info(desc.Type + ": Plugin DLL found, Desc ID = " + desc.ID); OSAEObjectCollection objs = OSAEObjectManager.GetObjectsByType(desc.Type); foreach (OSAEObject o in objs) { if (OSAEObjectPropertyManager.GetObjectPropertyValue(o.Name, "Computer Name").Value == Common.ComputerName || desc.Type == o.Name) { desc.Name = o.Name; bFoundObject = true; if (o.Enabled == 1) { desc.Enabled = true; } if (o.State.Value == "ON") { desc.Status = "Running"; } else if (o.State.Value == "OFF") { desc.Status = "Stopped"; } else { desc.Status = o.State.Value; } this.Log.Info(desc.Type + ": Plugin Object found, Object Name = " + o.Name); pluginList.Add(desc); } } // Here we try to create the Object if none was found above, we need a valid Object Type for this. if (bFoundObject == false) { this.Log.Info(desc.Type + ": Plugin Object Missing!"); bool bObjectTypeExists = OSAEObjectTypeManager.ObjectTypeExists(desc.Type); if (bObjectTypeExists) { this.Log.Info(desc.Type + ": Valid Object Type found. Attempting to create Object..."); OSAEObjectManager.ObjectAdd(desc.Type, desc.Type, desc.Type + " plugin's Object", desc.Type, "", "SYSTEM", false); OSAEObject obj = OSAEObjectManager.GetObjectByName(desc.Type); if (obj != null) { desc.Name = obj.Name; desc.Enabled = false; if (obj.State.Value == "ON") { desc.Status = "Running"; } else if (obj.State.Value == "OFF") { desc.Status = "Stopped"; } else { desc.Status = obj.State.Value; } this.Log.Info(desc.Type + ": Plugin Object now found!"); pluginList.Add(desc); } } else { this.Log.Info(desc.Type + ": NO Valid Object Type found! I cannot create an Object! Please run Install.sql for this plugin."); } } } } dgLocalPlugins.ItemsSource = pluginList; }