/// <summary> /// periodically checks the command queue to see if there is any commands that need to be processed by plugins /// </summary> private void QueryCommandQueue() { while (running) { try { foreach (OSAEMethod method in OSAEMethodManager.GetMethodsInQueue()) { logging.AddToLog("Method in Queue, ObjectName: " + method.ObjectName + " MethodName: " + method.MethodName, false); sendMessageToClients(WCF.OSAEWCFMessageType.LOG, "found method in queue: " + method.ObjectName + "(" + method.MethodName + ") p1: " + method.Parameter1 + " p2: " + method.Parameter2); LogMethodInformation(method); if (method.ObjectName == "SERVICE-" + Common.ComputerName) { switch (method.MethodName) { case "EXECUTE": logging.AddToLog("Recieved Execute Method Name", true); sendMessageToClients(WCF.OSAEWCFMessageType.CMDLINE, method.Parameter1 + " | " + method.Parameter2 + " | " + Common.ComputerName); break; case "START PLUGIN": StartPlugin(method); break; case "STOP PLUGIN": StopPlugin(method); break; case "RELOAD PLUGINS": LoadPlugins(); break; } OSAEMethodManager.MethodQueueDelete(method.Id); } else if (method.ObjectName.Split('-')[0] == "SERVICE") { if (method.MethodName == "EXECUTE") { sendMessageToClients(WCF.OSAEWCFMessageType.CMDLINE, method.Parameter1 + " | " + method.Parameter2 + " | " + method.ObjectName.Substring(8)); } OSAEMethodManager.MethodQueueDelete(method.Id); } else { bool processed = false; foreach (Plugin plugin in plugins) { if (plugin.Enabled == true && (method.Owner.ToLower() == plugin.PluginName.ToLower() || method.ObjectName.ToLower() == plugin.PluginName.ToLower())) { logging.AddToLog("Removing method from queue with ID: " + method.Id, false); plugin.ExecuteCommand(method); processed = true; break; } } if (!processed) { sendMessageToClients(WCF.OSAEWCFMessageType.METHOD, method.ObjectName + " | " + method.Owner + " | " + method.MethodName + " | " + method.Parameter1 + " | " + method.Parameter2 + " | " + method.Address + " | " + method.Id); logging.AddToLog("Removing method from queue with ID: " + method.Id, false); } OSAEMethodManager.MethodQueueDelete(method.Id); } } } catch (Exception ex) { logging.AddToLog("Error in QueryCommandQueue: " + ex.Message + " InnerException: " + ex.InnerException, true); } System.Threading.Thread.Sleep(100); } }
/// <summary> /// periodically checks the command queue to see if there is any commands that need to be processed by plugins /// </summary> private void QueryCommandQueue() { this.Log.Debug("QueryCommandQueue"); while (running) { try { foreach (OSAEMethod method in OSAEMethodManager.GetMethodsInQueue()) { this.Log.Debug("Method in Queue, ObjectName: " + method.ObjectName + " MethodLabel: " + method.MethodLabel + " MethodName: " + method.MethodName); LogMethodInformation(method); if (method.ObjectName == "SERVICE-" + Common.ComputerName) { switch (method.MethodName) { case "EXECUTE": this.Log.Info("Recieved Execute Method Name"); UDPConnection.SendObject("Command", method.Parameter1 + " | " + method.Parameter2 + " | " + Common.ComputerName, new IPEndPoint(IPAddress.Broadcast, 10051)); break; case "START PLUGIN": StartPlugin(method); break; case "STOP PLUGIN": StopPlugin(method); break; case "RELOAD PLUGINS": LoadPlugins(); break; } OSAEMethodManager.MethodQueueDelete(method.Id); } else if (method.ObjectName.Split('-')[0] == "SERVICE") { this.Log.Debug("Method for client service. Sending Broadcast."); if (method.MethodName == "EXECUTE") { UDPConnection.SendObject("Command", method.Parameter1 + " | " + method.Parameter2 + " | " + method.ObjectName.Substring(8), new IPEndPoint(IPAddress.Broadcast, 10051)); } OSAEMethodManager.MethodQueueDelete(method.Id); } else { bool processed = false; foreach (Plugin plugin in plugins) { if (plugin.Enabled == true && (method.Owner.ToLower() == plugin.PluginName.ToLower() || method.ObjectName.ToLower() == plugin.PluginName.ToLower())) { this.Log.Debug("Removing method from queue with ID: " + method.Id); plugin.ExecuteCommand(method); processed = true; break; } } if (!processed) { this.Log.Debug("Method found for client service plugin. Sending Broadcast."); UDPConnection.SendObject("Method", method.ObjectName + " | " + method.Owner + " | " + method.MethodName + " | " + method.Parameter1 + " | " + method.Parameter2 + " | " + method.Address + " | " + method.Id, new IPEndPoint(IPAddress.Broadcast, 10051)); this.Log.Debug("Removing method from queue with ID: " + method.Id); } OSAEMethodManager.MethodQueueDelete(method.Id); } } } catch (Exception ex) { this.Log.Error("Error in QueryCommandQueue: " + ex.Message, ex); } System.Threading.Thread.Sleep(100); } }
/// <summary> /// periodically checks the command queue to see if there is any commands that need to be processed by plugins /// </summary> private void QueryCommandQueue() { while (running) { try { foreach (OSAEMethod method in OSAEMethodManager.GetMethodsInQueue()) { Log.Debug("Method in queue for: " + method.Owner + " Method: " + method.ObjectName + "." + method.MethodName + "," + method.Parameter1 + "," + method.Parameter2); if (method.ObjectName == "SERVICE") // This Service { switch (method.MethodName) { case "BROADCAST": Log.Info("-> UDP: " + method.Parameter1 + ", " + method.Parameter2); UDPConnection.SendObject(method.Parameter1, method.Parameter2, new IPEndPoint(IPAddress.Broadcast, 10051)); break; case "EXECUTE": Log.Info("Received Execute Method"); UDPConnection.SendObject("Command", method.Parameter1 + " | " + method.Parameter2 + " | " + Common.ComputerName, new IPEndPoint(IPAddress.Broadcast, 10051)); break; case "START PLUGIN": StartPlugin(serviceObject, method); break; case "STOP PLUGIN": StopPlugin(serviceObject, method); break; case "RELOAD PLUGINS": LoadPlugins(serviceObject); break; } OSAEMethodManager.MethodQueueDelete(method.Id); } else if (method.ObjectName.Split('-')[0] == "SERVICE") // Client Services { Log.Debug("Method for client service. Sending Broadcast."); switch (method.MethodName) { case "ON": Log.Info("-> UDP " + method.ObjectName + " | ON"); UDPConnection.SendObject("Manager", method.ObjectName + " | ON", new IPEndPoint(IPAddress.Broadcast, 10052)); break; case "OFF": Log.Info("-> UDP " + method.ObjectName + " | OFF"); UDPConnection.SendObject("Manager", method.ObjectName + " | OFF", new IPEndPoint(IPAddress.Broadcast, 10052)); break; case "EXECUTE": Log.Info("Recieved Execute Method Name"); UDPConnection.SendObject("Command", method.Parameter1 + " | " + method.Parameter2 + " | " + method.ObjectName.Substring(8), new IPEndPoint(IPAddress.Broadcast, 10051)); break; case "START PLUGIN": UDPConnection.SendObject("Plugin", method.ObjectName + " | ON", new IPEndPoint(IPAddress.Broadcast, 10051)); Log.Info("-> UDP: Plugin, " + method.ObjectName + " | ON"); //object name | owner | method name | param1 | param 2 | address | from object //StartPlugin(method); break; case "STOP PLUGIN": UDPConnection.SendObject("Plugin", method.ObjectName + " | OFF", new IPEndPoint(IPAddress.Broadcast, 10051)); Log.Info("-> UDP: Plugin, " + method.ObjectName + " | OFF"); //StopPlugin(method); break; } OSAEMethodManager.MethodQueueDelete(method.Id); } else if (method.ObjectName.Split('-')[0] != "SERVICE") {// THIS IS NOT GOOD ENOUGH. it intercepts all plugins not just local service ones.... //Look up the basetype, if it is a plugin, THEN you can parse on and off for the intercept. //You must also look at the container and see if it is this service like above. OSAEObject tempObj = OSAEObjectManager.GetObjectByName(method.ObjectName); string isContainerService = tempObj.Container.Split('-')[0]; if (tempObj.BaseType == "PLUGIN" && tempObj.Container == ("SERVICE")) // Plugins on the localhost { switch (method.MethodName) { case "ON": OSAEMethodManager.MethodQueueDelete(method.Id); Log.Info("Recieved Start for: " + method.Owner); StartPlugin(serviceObject, method); break; case "OFF": OSAEMethodManager.MethodQueueDelete(method.Id); Log.Info("Recieved Stop for: " + method.Owner); StopPlugin(serviceObject, method); break; default: { foreach (Plugin plugin in plugins) { if (method.ObjectName == plugin.PluginName) { plugin.ExecuteCommand(method); break; } } break; } } OSAEMethodManager.MethodQueueDelete(method.Id); } else if (tempObj.BaseType == "PLUGIN" && isContainerService == "SERVICE") // Plugins on a remote Client Service { //We can translate the the Object from the method to a parameter and just tell the client service to start/stop the plugin switch (method.MethodName) { case "ON": Log.Info("Sending Remote Start for: " + method.Owner); UDPConnection.SendObject("Plugin", method.ObjectName + " | ON", new IPEndPoint(IPAddress.Broadcast, 10051)); Log.Info("-> UDP: Plugin, " + method.ObjectName + " | ON"); break; case "OFF": Log.Info("Sending Remote Stop for: " + method.Owner); UDPConnection.SendObject("Plugin", method.ObjectName + " | OFF", new IPEndPoint(IPAddress.Broadcast, 10051)); Log.Info("-> UDP: Plugin, " + method.ObjectName + " | OFF"); break; default: { Log.Debug("-> UDP: Command, " + method.ObjectName + " | " + method.Owner + " | " + method.MethodName + " | " + method.Parameter1 + " | " + method.Parameter2 + " | " + method.Address + " | " + method.Id); UDPConnection.SendObject("Method", method.ObjectName + " | " + method.MethodName + " | " + method.Parameter1 + " | " + method.Parameter2 + " | " + method.Address + " | " + method.Owner + " | " + method.FromObject, new IPEndPoint(IPAddress.Broadcast, 10051)); break; } } Log.Debug("Removing method from queue with ID: " + method.Id); OSAEMethodManager.MethodQueueDelete(method.Id); } else { bool processed = false; foreach (Plugin plugin in plugins) { if (string.IsNullOrEmpty(method.Owner) || method.Owner.ToLower() == plugin.PluginName.ToLower() || method.ObjectName.ToLower() == plugin.PluginName.ToLower()) { plugin.ExecuteCommand(method); processed = true; break; } } if (!processed) { Log.Debug("Method found for client service plugin. Sending Broadcast."); UDPConnection.SendObject("Plugin", method.ObjectName + " | ON", new IPEndPoint(IPAddress.Broadcast, 10051)); Log.Debug("-> UDP: Command, " + method.ObjectName + " | " + method.Owner + " | " + method.MethodName + " | " + method.Parameter1 + " | " + method.Parameter2 + " | " + method.Address + " | " + method.Id); UDPConnection.SendObject("Command", method.ObjectName + " | " + method.Owner + " | " + method.MethodName + " | " + method.Parameter1 + " | " + method.Parameter2 + " | " + method.Address + " | " + method.Id, new IPEndPoint(IPAddress.Broadcast, 10051)); UDPConnection.SendObject("Command", "Testing", new IPEndPoint(IPAddress.Broadcast, 10051)); UDPConnection.SendObject("Method", "Testing", new IPEndPoint(IPAddress.Broadcast, 10051)); UDPConnection.SendObject("Plugin", "Testing", new IPEndPoint(IPAddress.Broadcast, 10051)); Log.Debug("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"); } Log.Debug("Removing method from queue with ID: " + method.Id); OSAEMethodManager.MethodQueueDelete(method.Id); break; } } } } catch (Exception ex) { Log.Error("Error in QueryCommandQueue!", ex); } Thread.Sleep(100); } }