public void disablePlugin(Plugin p) { this.Log.Info(p.PluginName + ": Disabling Plugin..."); OSAEObject obj = OSAEObjectManager.GetObjectByName(p.PluginName); OSAEObjectManager.ObjectUpdate(p.PluginName, p.PluginName, obj.Alias, obj.Description, obj.Type, obj.Address, obj.Container, 0); try { p.Shutdown(); p.Enabled = false; p.Domain = Common.CreateSandboxDomain("Sandbox Domain", p.Location, SecurityZone.Internet, typeof(OSAEService)); } catch (Exception ex) { this.Log.Error("Error stopping plugin (" + p.PluginName + "): " + ex.Message, ex); } }
public void disablePlugin(Plugin p) { OSAEObject obj = osae.GetObjectByName(p.PluginName); osae.ObjectUpdate(p.PluginName, p.PluginName, obj.Description, obj.Type, obj.Address, obj.Container, 0); try { p.addin.Shutdown(); p.addin = null; GC.Collect(); p.Enabled = false; p.process.Shutdown(); sendMessageToClients("plugin", p.PluginName + " | " + p.Enabled.ToString() + " | " + p.PluginVersion + " | Stopped | " + p.LatestAvailableVersion + " | " + p.PluginType + " | " + osae.ComputerName); } catch (Exception ex) { osae.AddToLog("Error stopping plugin (" + p.PluginName + "): " + ex.Message + " - " + ex.InnerException, true); } }
public void enablePlugin(Plugin plugin) { OSAEObject obj = OSAEObjectManager.GetObjectByName(plugin.PluginName); OSAEObjectManager.ObjectUpdate(plugin.PluginName, plugin.PluginName, obj.Description, obj.Type, obj.Address, obj.Container, 1); try { if (plugin.ActivatePlugin()) { plugin.Enabled = true; plugin.RunInterface(); OSAEObjectStateManager.ObjectStateSet(plugin.PluginName, "ON", sourceName); logging.AddToLog("Plugin enabled: " + plugin.PluginName, true); } } catch (Exception ex) { logging.AddToLog("Error activating plugin (" + plugin.PluginName + "): " + ex.Message + " - " + ex.InnerException, true); } }
public void enablePlugin(Plugin plugin) { OSAEObject obj = OSAEObjectManager.GetObjectByName(plugin.PluginName); OSAEObjectManager.ObjectUpdate(plugin.PluginName, plugin.PluginName, obj.Description, obj.Type, obj.Address, obj.Container, 1); try { if (plugin.ActivatePlugin()) { plugin.Enabled = true; plugin.RunInterface(); OSAEObjectStateManager.ObjectStateSet(plugin.PluginName, "ON", sourceName); sendMessageToClients(WCF.OSAEWCFMessageType.PLUGIN, plugin.PluginName + " | " + plugin.Enabled.ToString() + " | " + plugin.PluginVersion + " | Running | " + plugin.LatestAvailableVersion + " | " + plugin.PluginType + " | " + Common.ComputerName); logging.AddToLog("Plugin enabled: " + plugin.PluginName, true); } } catch (Exception ex) { logging.AddToLog("Error activating plugin (" + plugin.PluginName + "): " + ex.Message + " - " + ex.InnerException, true); } }
public void enablePlugin(Plugin plugin) { this.Log.Info(plugin.PluginName + ": Enabling Plugin..."); OSAEObject obj = OSAEObjectManager.GetObjectByName(plugin.PluginName); OSAEObjectManager.ObjectUpdate(plugin.PluginName, plugin.PluginName, obj.Alias, obj.Description, obj.Type, obj.Address, obj.Container, 1); try { if (plugin.ActivatePlugin()) { plugin.Enabled = true; plugin.RunInterface(); OSAEObjectStateManager.ObjectStateSet(plugin.PluginName, "ON", sourceName); this.Log.Debug(plugin.PluginName + ": Plugin enabled."); } } catch (Exception ex) { this.Log.Error("Error activating plugin (" + plugin.PluginName + "): " + ex.Message, ex); } }
/// <summary> /// /// </summary> public void LoadPlugins() { this.Log.Info("Loading Plugins..."); OSAEPluginCollection newPlugins = new OSAEPluginCollection(); var pluginAssemblies = new List<OSAEPluginBase>(); var types = PluginFinder.FindPlugins(); foreach (var type in types) { this.Log.Debug("type.TypeName: " + type.TypeName); this.Log.Debug("type.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); } } this.Log.Info("Found " + newPlugins.Count.ToString() + " Assemblies"); MySqlConnection connection = new MySqlConnection(Common.ConnectionString); foreach (Plugin plugin in newPlugins) { try { if (plugin.PluginName != "") { this.Log.Info("----------------------------------------------------"); if (!goodConnection) { try { connection.Open(); goodConnection = true; } catch { } } this.Log.Info(plugin.PluginName + ": Connection Passed (" + goodConnection + ")"); if (goodConnection) { if (plugin.PluginName != "") { OSAEObject obj = OSAEObjectManager.GetObjectByName(plugin.PluginName); if (obj == null) { OSAEObjectManager.ObjectAdd(plugin.PluginName, plugin.PluginName, plugin.PluginName + " plugin's Object", plugin.PluginType, "", "", true); obj = OSAEObjectManager.GetObjectByName(plugin.PluginName); } if (obj != null) { this.Log.Info(obj.Name + ": Plugin Object found. Plugin Object Enabled = " + obj.Enabled.ToString()); if (obj.Enabled == 1) { enablePlugin(plugin); } else plugin.Enabled = false; this.Log.Info(obj.Name + ": Plugin Enabled = " + plugin.Enabled.ToString()); this.Log.Info(obj.Name + ": Plugin Version = " + plugin.PluginVersion); } } else { //add code to create the object. We need the plugin to specify the type though MySqlDataAdapter adapter; DataSet dataset = new DataSet(); DataSet dataset2 = new DataSet(); MySqlCommand command = new MySqlCommand(); command.Connection = connection; command.CommandText = "SELECT * FROM osae_object_type_property p inner join osae_object_type t on p.object_type_id = t.object_type_id WHERE object_type=@type AND property_name='Computer Name'"; command.Parameters.AddWithValue("@type", plugin.PluginType); adapter = new MySqlDataAdapter(command); adapter.Fill(dataset); command.CommandText = "SELECT * FROM osae_v_object WHERE object_type=@type"; command.Parameters.AddWithValue("@type", plugin.PluginType); adapter = new MySqlDataAdapter(command); adapter.Fill(dataset2); if (dataset.Tables[0].Rows.Count > 0 && dataset2.Tables[0].Rows.Count > 0) { plugin.PluginName = plugin.PluginType + "-" + Common.ComputerName; } else { plugin.PluginName = plugin.PluginType; } this.Log.Info(plugin.PluginName + ": Plugin object does not exist in DB!"); OSAEObjectManager.ObjectAdd(plugin.PluginName, plugin.PluginName, plugin.PluginName, plugin.PluginType, "", "System", false); OSAEObjectPropertyManager.ObjectPropertySet(plugin.PluginName, "Computer Name", Common.ComputerName, sourceName); this.Log.Info(plugin.PluginName + ": Plugin added to DB."); UDPConnection.SendObject("Plugin", plugin.PluginName + " | " + plugin.Enabled.ToString() + " | " + plugin.PluginVersion + " | Stopped | " + plugin.LatestAvailableVersion + " | " + plugin.PluginType + " | " + Common.ComputerName, new IPEndPoint(IPAddress.Broadcast, 10051)); } plugins.Add(plugin); masterPlugins.Add(plugin); } } else { this.Log.Info(plugin.PluginType + " Skipped! (Not Loaded due to missing Object or other issue)"); } } catch (Exception ex) { this.Log.Error("Error loading plugin: " + ex.Message, ex); } } }
private void checkForUpdates(string name, string version) { try { Plugin p = new Plugin(); bool plug = false; foreach (Plugin plugin in plugins) { if (plugin.PluginType == name) { p = plugin; plug = true; } } int curMajor, curMinor, curRevion, latestMajor = 0, latestMinor = 0, latestRevision = 0; string[] split = version.Split('.'); curMajor = Int32.Parse(split[0]); curMinor = Int32.Parse(split[1]); curRevion = Int32.Parse(split[2]); string url = "http://www.opensourceautomation.com/pluginUpdates.php?app=" + name + "&ver=" + version; logging.AddToLog("Checking for plugin updates: " + url, false); WebRequest request = HttpWebRequest.Create(url); WebResponse response = request.GetResponse(); Stream responseStream = response.GetResponseStream(); //XmlReader rdr = XmlReader.Create(responseStream); XElement xml = XElement.Load(responseStream); logging.AddToLog("XML retreived", false); var query = from e in xml.Elements("plugin") select new { B = e.Element("major").Value, C = e.Element("minor").Value, D = e.Element("revision").Value }; foreach (var e in query) { latestMajor = Int32.Parse(e.B); latestMinor = Int32.Parse(e.C); latestRevision = Int32.Parse(e.D); } if (latestMajor >= curMajor) { if (latestMinor >= curMinor) { if (latestRevision > curRevion) { p.LatestAvailableVersion = latestMajor + "." + latestMinor + "." + latestRevision; logging.AddToLog("current version: " + curMajor + "." + curMinor + "." + curRevion, false); logging.AddToLog("latest version: " + p.LatestAvailableVersion, false); string msg; if (!plug) { msg = version + "|" + latestMajor + "." + latestMinor + "." + latestRevision; sendMessageToClients(WCF.OSAEWCFMessageType.SERVICE, msg); } } } } response.Close(); if (plug) { string msg = p.PluginName + " | " + p.Enabled.ToString() + " | " + p.PluginVersion + " | " + p.Status + " | " + p.LatestAvailableVersion + " | " + p.PluginType + " | " + Common.ComputerName; sendMessageToClients(WCF.OSAEWCFMessageType.PLUGIN, msg); } } catch (Exception ex) { logging.AddToLog("plugin update error: " + ex.Message, true); } }
public void disablePlugin(Plugin p) { logging.AddToLog("Disabling Plugin: " + p.PluginName,true); OSAEObject obj = osae.GetObjectByName(p.PluginName); osae.ObjectUpdate(p.PluginName, p.PluginName, obj.Description, obj.Type, obj.Address, obj.Container, 0); try { p.Shutdown(); p.Enabled = false; p.Domain = CreateSandboxDomain("Sandbox Domain", p.Location, SecurityZone.Internet); sendMessageToClients(WCF.OSAEWCFMessageType.PLUGIN, p.PluginName + " | " + p.Enabled.ToString() + " | " + p.PluginVersion + " | Stopped | " + p.LatestAvailableVersion + " | " + p.PluginType + " | " + osae.ComputerName); } catch (Exception ex) { logging.AddToLog("Error stopping plugin (" + p.PluginName + "): " + ex.Message + " - " + ex.InnerException, true); } }
/// <summary> /// Event happens when a wcf client invokes it /// </summary> /// <param name="source"></param> /// <param name="e"></param> private void wcfService_MessageReceived(object source, WCF.CustomEventArgs e) { try { logging.AddToLog("received message: " + e.Message, false); if (e.Message.Type == WCF.OSAEWCFMessageType.CONNECT) { try { logging.AddToLog("client connected", false); foreach (Plugin p in masterPlugins) { string msg = p.PluginName + " | " + p.Enabled.ToString() + " | " + p.PluginVersion + " | " + p.Status + " | " + p.LatestAvailableVersion + " | " + p.PluginType + " | " + osae.ComputerName; sendMessageToClients(WCF.OSAEWCFMessageType.PLUGIN, msg); } } catch (Exception ex) { logging.AddToLog("Error sending plugin messages to clients: " + ex.Message, true); } } else { string[] arguments = e.Message.Message.Split('|'); if (arguments[0] == "ENABLEPLUGIN") { bool local = false; if (arguments[2] == "True") osae.ObjectStateSet(arguments[1], "ON"); else if (arguments[2] == "False") osae.ObjectStateSet(arguments[1], "OFF"); foreach (Plugin p in plugins) { if (p.PluginName == arguments[1]) { local = true; OSAEObject obj = osae.GetObjectByName(p.PluginName); if (obj != null) { if (arguments[2] == "True") { enablePlugin(p); } else if (arguments[2] == "False") { disablePlugin(p); } } } } if (!local) { sendMessageToClients(WCF.OSAEWCFMessageType.PLUGIN, e.Message.Message); } } else if (arguments[0] == "plugin") { bool found = false; foreach (Plugin plugin in masterPlugins) { if (plugin.PluginName == arguments[1]) { if (arguments[4].ToLower() == "true") plugin.Enabled = true; else plugin.Enabled = false; plugin.PluginVersion = arguments[3]; found = true; break; } } if (!found) { Plugin p = new Plugin(); p.PluginName = arguments[1]; p.PluginVersion = arguments[3]; if (arguments[4].ToLower() == "true") p.Enabled = true; else p.Enabled = false; masterPlugins.Add(p); } } else if (arguments[0] == "updatePlugin") { foreach (Plugin plugin in masterPlugins) { if (plugin.PluginName == arguments[1]) { if (plugin.Status == "Running") disablePlugin(plugin); //code for downloading and installing plugin break; } } } } logging.AddToLog("-----------Master plugin list", false); foreach (Plugin p in masterPlugins) logging.AddToLog(" --- " + p.PluginName, false); } catch (Exception ex) { logging.AddToLog("Error receiving message: " + ex.Message, true); } }
public void enablePlugin(Plugin plugin) { OSAEObject obj = osae.GetObjectByName(plugin.PluginName); osae.ObjectUpdate(plugin.PluginName, plugin.PluginName, obj.Description, obj.Type, obj.Address, obj.Container, 1); try { if (plugin.ActivatePlugin()) { plugin.addin.RunInterface(plugin.PluginName); osae.ObjectStateSet(plugin.PluginName, "ON"); sendMessageToClients("plugin", plugin.PluginName + " | " + plugin.Enabled.ToString() + " | " + plugin.PluginVersion + " | Running | " + plugin.LatestAvailableVersion + " | " + plugin.PluginType + " | " + osae.ComputerName); osae.AddToLog("Plugin enabled: " + plugin.PluginName, true); osae.AddToLog("Process ID: " + plugin.process.ProcessId.ToString(), true); } } catch (Exception ex) { osae.AddToLog("Error activating plugin (" + plugin.PluginName + "): " + ex.Message + " - " + ex.InnerException, true); } catch { osae.AddToLog("Error activating plugin", true); } }
/// <summary> /// /// </summary> public void LoadPlugins() { OSAEPluginCollection newPlugins = new OSAEPluginCollection(); var pluginAssemblies = new List<OSAEPluginBase>(); var types = PluginFinder.FindPlugins(); logging.AddToLog("Loading Plugins", true); foreach (var type in types) { logging.AddToLog("type.TypeName: " + type.TypeName, false); logging.AddToLog("type.AssemblyName: " + type.AssemblyName, false); 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); } } logging.AddToLog("Found " + plugins.Count.ToString() + " plugins", true); MySqlConnection connection = new MySqlConnection(Common.ConnectionString); foreach (Plugin plugin in newPlugins) { try { logging.AddToLog("---------------------------------------", true); logging.AddToLog("Plugin name: " + plugin.PluginName, true); logging.AddToLog("Testing connection", true); if (!goodConnection) { try { connection.Open(); goodConnection = true; } catch { } } if (goodConnection) { if (plugin.PluginName != "") { OSAEObject obj = OSAEObjectManager.GetObjectByName(plugin.PluginName); if (obj != null) { logging.AddToLog("Plugin Object found: " + obj.Name + " - Enabled: " + obj.Enabled.ToString(), true); if (obj.Enabled == 1) { enablePlugin(plugin); } else plugin.Enabled = false; logging.AddToLog("Status: " + plugin.Enabled.ToString(), true); logging.AddToLog("PluginVersion: " + plugin.PluginVersion, true); } } else { //add code to create the object. We need the plugin to specify the type though MySqlDataAdapter adapter; DataSet dataset = new DataSet(); MySqlCommand command = new MySqlCommand(); command.Connection = connection; command.CommandText = "SELECT * FROM osae_object_type_property p inner join osae_object_type t on p.object_type_id = t.object_type_id WHERE object_type=@type AND property_name='Computer Name'"; command.Parameters.AddWithValue("@type", plugin.PluginType); adapter = new MySqlDataAdapter(command); adapter.Fill(dataset); if (dataset.Tables[0].Rows.Count > 0) { plugin.PluginName = plugin.PluginType + "-" + Common.ComputerName; } else { plugin.PluginName = plugin.PluginType; } logging.AddToLog("Plugin object does not exist in DB: " + plugin.PluginName, true); OSAEObjectManager.ObjectAdd(plugin.PluginName, plugin.PluginName, plugin.PluginType, "", "System", false); OSAEObjectPropertyManager.ObjectPropertySet(plugin.PluginName, "Computer Name", Common.ComputerName, sourceName); logging.AddToLog("Plugin added to DB: " + plugin.PluginName, true); sendMessageToClients(WCF.OSAEWCFMessageType.PLUGIN, plugin.PluginName + " | " + plugin.Enabled.ToString() + " | " + plugin.PluginVersion + " | Stopped | " + plugin.LatestAvailableVersion + " | " + plugin.PluginType + " | " + Common.ComputerName); } plugins.Add(plugin); masterPlugins.Add(plugin); } } catch (Exception ex) { logging.AddToLog("Error loading plugin: " + ex.Message, true); } } }
/// <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); }
public void stopPlugin(string serviceName, Plugin p) { Log = new General.OSAELog("SERVICE"); Log.Info(p.PluginName + ": Disabling Plugin..."); OSAEObject obj = OSAEObjectManager.GetObjectByName(p.PluginName); // OSAEObjectManager.ObjectUpdate(p.PluginName, p.PluginName, obj.Alias, obj.Description, obj.Type, obj.Address, obj.Container, obj.MinTrustLevel, false); try { p.Shutdown(); OSAEObjectStateManager.ObjectStateSet(p.PluginName, "OFF", "SYSTEM"); p.Domain = Common.CreateSandboxDomain("Sandbox Domain", p.Location, SecurityZone.Internet, typeof(OSAEService)); } catch (Exception ex) { Log.Error("Error stopping plugin (" + p.PluginName + "): " + ex.Message, ex); } }
//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"); } }