protected void btnExecute_Click(object sender, EventArgs e) { OSAEMethodManager.MethodQueueAdd(gvObjects.DataKeys[gvObjects.SelectedIndex]["object_name"].ToString(), ddlMethod.SelectedItem.Value, txtParam1.Text, txtParam2.Text, Session["Username"].ToString()); lblAlert.Text = "Method successfuly executed: " + ddlMethod.SelectedItem.Text; alert.Visible = true; divParameters.Visible = false; }
private void Button_Click(object sender, RoutedEventArgs e) { if (ctrlType == "Method") { if (inputParam1.Text == "[ASK]" | inputParam2.Text == "[ASK]") { // invalid input BadInputLab.Visibility = System.Windows.Visibility.Visible; OKButt.IsEnabled = false; } else { // Input Changed BadInputLab.Visibility = System.Windows.Visibility.Hidden; OKButt.IsEnabled = true; if (Param1 == "[ASK]") { Param1 = inputParam1.Text; } if (Param2 == "[ASK]") { Param2 = inputParam2.Text; } } OSAEMethodManager.MethodQueueAdd(ObjectName, MethodName, Param1, Param2, "GUI"); NotifyParentFinished(); } }
/// <summary> /// The service control manager has requested us to start /// </summary> /// <param name="args"></param> protected override void OnStart(string[] args) { //#if (DEBUG) // Debugger.Launch(); //<-- Simple form to debug a web services //#endif AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptions); try { Common.InitialiseLogFolder(); DeleteStoreFiles(); } catch (Exception ex) { logging.AddToLog("Error getting registry settings and/or deleting logs: " + ex.Message, true); } logging.AddToLog("OnStart", true); logging.AddToLog("Removing Orphaned methods", true); OSAEMethodManager.ClearMethodQueue(); Common.CreateComputerObject(sourceName); CreateServiceObject(); // Start the WCF service so messages can be sent // and received by the service StartWCFService(); // Start the threads that monitor the plugin // updates check the method queue and so on StartThreads(); }
public Boolean ExecuteMethod(string name, string method, string param1, string param2) { // execute a method on an object OSAEMethodManager.MethodQueueAdd(name, method, param1, param2, "Rest"); Log.Debug("Executing Method: " + name + "." + method + "." + param1 + "." + param2); return(true); }
protected void ddlMethod_SelectedIndexChanged(object sender, EventArgs e) { DataSet ds = OSAESql.RunSQL("SELECT param_1_label, param_2_label, param_1_default, param_2_default FROM osae_v_object_type_method otm INNER JOIN osae_object oo ON oo.object_type_id = otm.object_type_id WHERE object_name = '" + hdnSelectedObjectName.Text.Replace("'", "''") + "' AND method_name = '" + ddlMethod.SelectedItem.Value + "'"); DataTable dt = ds.Tables[0]; if (dt.Rows.Count > 0) { if (!string.IsNullOrEmpty(dt.Rows[0]["param_1_label"].ToString())) { divParameters.Visible = true; txtParam1.Text = dt.Rows[0]["param_1_default"].ToString(); txtParam2.Text = dt.Rows[0]["param_2_default"].ToString(); if (!String.IsNullOrEmpty(dt.Rows[0]["param_1_label"].ToString())) { lblParam1.Text = "(" + dt.Rows[0]["param_1_label"].ToString() + ")"; } if (!String.IsNullOrEmpty(dt.Rows[0]["param_2_label"].ToString())) { lblParam2.Text = "(" + dt.Rows[0]["param_2_label"].ToString() + ")"; } } else { OSAEMethodManager.MethodQueueAdd(hdnSelectedObjectName.Text, ddlMethod.SelectedItem.Value, "", "", "Web UI"); lblAlert.Text = "Method successfuly executed: " + ddlMethod.SelectedItem.Text; alert.Visible = true; } } else { OSAEMethodManager.MethodQueueAdd(hdnSelectedObjectName.Text, ddlMethod.SelectedItem.Value, "", "", "Web UI"); lblAlert.Text = "Method successfuly executed: " + ddlMethod.SelectedItem.Text; alert.Visible = true; } }
protected override void ProcessRecord() { Log.Debug("Invoke-OSA - ProcessRecord - Started"); OSAEMethodManager.MethodQueueAdd(Name, Method, parameter1, parameter2, "PowerShell"); WriteObject(true); }
protected void btnExecute_Click(object sender, EventArgs e) { OSAEMethodManager.MethodQueueAdd(hdnSelectedObjectName.Text, ddlMethod.SelectedItem.Value, txtParam1.Text, txtParam2.Text, "Web UI"); lblAlert.Text = "Method successfuly executed: " + ddlMethod.SelectedItem.Text; alert.Visible = true; divParameters.Visible = false; }
/// <summary> /// The service control manager has requested us to start /// </summary> /// <param name="args"></param> protected override void OnStart(string[] args) { Log.Debug("OnStart subroutine Starting..."); AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptions); var dbConnectionStatus = Common.TestConnection(); if (dbConnectionStatus.Success) { Log.Info("Verified successful connection to database."); } else { Log.Fatal("Unable to connect to database: " + dbConnectionStatus.CaughtException.Message); return; } try { string externalip = new System.Net.WebClient().DownloadString("https://api.ipify.org"); OSAEObjectPropertyManager.ObjectPropertySet("SYSTEM", "WAN IP", externalip, "SERVICE"); } catch (Exception ex) { Log.Fatal("Error getting registry settings and/or deleting logs: " + ex.Message, ex); } try { Common.InitialiseLogFolder(); DeleteStoreFiles(); } catch (Exception ex) { Log.Fatal("Error getting registry settings and/or deleting logs: " + ex.Message, ex); } Log.Info("Removing Orphaned Methods"); OSAEMethodManager.ClearMethodQueue(); try { OSAE.OSAESql.RunSQL("SET GLOBAL event_scheduler = ON;"); } catch (Exception ex) { Log.Fatal("Error setting the event scheduler: " + ex.Message, ex); } checkLog = new System.Timers.Timer(60000); checkLog.Elapsed += checkLogEvent; checkLog.Enabled = true; // Start the network service so messages can be // received by the service StartNetworkListener(); // Start the threads that monitor the plugin // updates check the method queue and so on StartThreads(serviceObject); }
protected void Button1_Click(object sender, EventArgs e) { if (CurState == "ON") { OSAEMethodManager.MethodQueueAdd(ObjectName, "OFF", "", "", "MYStateButton"); } else { OSAEMethodManager.MethodQueueAdd(ObjectName, "ON", "", "", "MYStateButton"); } }
private void State_Image_MouseLeftButtonUp(object sender, MouseEventArgs e) { if (CurState == "ON") { OSAEMethodManager.MethodQueueAdd(ObjectName, "OFF", "", "", "GUI"); OSAEObjectStateManager.ObjectStateSet(ObjectName, "OFF", "GUI"); } else { OSAEMethodManager.MethodQueueAdd(ObjectName, "ON", "", "", "GUI"); OSAEObjectStateManager.ObjectStateSet(ObjectName, "ON", "GUI"); } }
protected void btnState_Click(object sender, EventArgs e) { if (CurState == State1Name) { OSAEMethodManager.MethodQueueAdd(ObjectName, State2Name, "0", "", "SYSTEM"); OSAEObjectStateManager.ObjectStateSet(ObjectName, State2Name, "SYSTEM"); } else { OSAEMethodManager.MethodQueueAdd(ObjectName, State1Name, "0", "", "SYSTEM"); OSAEObjectStateManager.ObjectStateSet(ObjectName, State1Name, "SYSTEM"); } }
/// <summary> /// The service control manager has requested us to start /// </summary> /// <param name="args"></param> protected override void OnStart(string[] args) { AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptions); var dbConnectionStatus = Common.TestConnection(); if (dbConnectionStatus.Success) { this.Log.Info("Verified successful connection to database."); } else { this.Log.Fatal("Unable to connect to database: " + dbConnectionStatus.CaughtException.Message); return; } try { Common.InitialiseLogFolder(); DeleteStoreFiles(); } catch (Exception ex) { this.Log.Fatal("Error getting registry settings and/or deleting logs: " + ex.Message, ex); } this.Log.Info("OnStart"); this.Log.Info("Removing Orphaned Methods"); OSAEMethodManager.ClearMethodQueue(); Common.CreateComputerObject(sourceName); CreateServiceObject(); OSAE.OSAESql.RunSQL("SET GLOBAL event_scheduler = ON;"); checkLog = new System.Timers.Timer(60000); checkLog.Elapsed += checkLogEvent; checkLog.Enabled = true; // Start the network service so messages can be // received by the service StartNetworkListener(); // Start the threads that monitor the plugin // updates check the method queue and so on StartThreads(); }
public Boolean ExecuteMethod(string name, string method, string param1, string param2, string authkey) { string uAuth = OSAESecurity.DecryptUser(authkey); if (uAuth != null) { // execute a method on an object OSAEMethodManager.MethodQueueAdd(name, method, param1, param2, uAuth); Log.Debug("Executing Method: " + name + "." + method + "." + param1 + "." + param2); return(true); } else { return(false); } }
private void btnState_Click(object sender, RoutedEventArgs e) { if (currentUser == "") { return; } if (CurState == State1Name) { OSAEMethodManager.MethodQueueAdd(objName, State2Name, "0", "", currentUser); OSAEObjectStateManager.ObjectStateSet(objName, State2Name, currentUser); } else { OSAEMethodManager.MethodQueueAdd(objName, State1Name, "0", "", currentUser); OSAEObjectStateManager.ObjectStateSet(objName, State1Name, currentUser); } }
private void State_Image_MouseLeftButtonUp(object sender, MouseEventArgs e) { string param1 = "", param2 = "", newState = ""; string currentUser = OSAE.OSAEObjectPropertyManager.GetObjectPropertyValue(gAppName, "Current User").Value; if (currentUser == "") { return; } if (StateMatch == "State 1") { newState = OSAEObjectPropertyManager.GetObjectPropertyValue(screenObject.Name.ToString(), "State 2 Name").Value; } else { newState = OSAEObjectPropertyManager.GetObjectPropertyValue(screenObject.Name.ToString(), "State 1 Name").Value; } bool found = OSAEObjectTypeManager.ObjectTypeMethodExists(LinkedObject.Type, newState); if (found) { DataSet ds = OSAESql.RunSQL("SELECT param_1_label, param_2_label, param_1_default, param_2_default FROM osae_v_object_type_method WHERE object_type = '" + LinkedObject.Type.Replace("'", "''") + "' AND method_name = '" + newState + "'"); DataTable dt = ds.Tables[0]; if (dt.Rows.Count > 0) { if (!string.IsNullOrEmpty(dt.Rows[0]["param_1_label"].ToString())) { param1 = dt.Rows[0]["param_1_default"].ToString(); param2 = dt.Rows[0]["param_2_default"].ToString(); } } OSAEMethodManager.MethodQueueAdd(ObjectName, newState, param1, param2, currentUser); } else { OSAEObjectStateManager.ObjectStateSet(ObjectName, newState, currentUser); } }
private void Method_Image_MouseLeftButtonUp(object sender, MouseEventArgs e) { if (Param1 == "[ASK]" | Param2 == "[ASK]") { ParamInput addControl = new ParamInput("Method", screenObject); string cppX = screenObject.Property("X").Value; string cppY = screenObject.Property("Y").Value; double cpp_X = Convert.ToDouble(cppX); double cpp_Y = Convert.ToDouble(cppY); if (cpp_X < 320) { cpp_X = cpp_X + 200; } addControl.Left = cpp_X; addControl.Top = cpp_Y; addControl.Show(); } else { OSAEMethodManager.MethodQueueAdd(ObjectName, MethodName, Param1, Param2, "GUI"); } }
/// <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); } }
private void Click_Image_MouseLeftButtonDown(object sender, MouseEventArgs e) { string currentUser = OSAE.OSAEObjectPropertyManager.GetObjectPropertyValue(gAppName, "Current User").Value; if (currentUser == "") { return; } string imgName = screenObject.Property("Pressed Image").Value; OSAEImage img = imgMgr.GetImage(imgName); if (img != null) { var imageStream = new MemoryStream(img.Data); var bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = imageStream; bitmapImage.EndInit(); Image.Source = bitmapImage; Image.Visibility = System.Windows.Visibility.Visible; } // else // { // Image.Source = null; // Image.Visibility = System.Windows.Visibility.Hidden; // } if (PressMethodName != "") { if (PressMethodParam1 == "[ASK]" | PressMethodParam2 == "[ASK]") { ParamInput addControl = new ParamInput("Method", screenObject, currentUser); string cppX = screenObject.Property("X").Value; string cppY = screenObject.Property("Y").Value; double cpp_X = Convert.ToDouble(cppX); double cpp_Y = Convert.ToDouble(cppY); if (cpp_X < 320) { cpp_X = cpp_X + 200; } addControl.Left = cpp_X; addControl.Top = cpp_Y; addControl.Show(); } else { OSAEMethodManager.MethodQueueAdd(PressObjectName, PressMethodName, PressMethodParam1, PressMethodParam2, currentUser); } } if (PressScriptName != "") { if (PressMethodParam1 == "[ASK]" | PressMethodParam2 == "[ASK]") { ParamInput addControl = new ParamInput("Method", screenObject, currentUser); string cppX = screenObject.Property("X").Value; string cppY = screenObject.Property("Y").Value; double cpp_X = Convert.ToDouble(cppX); double cpp_Y = Convert.ToDouble(cppY); if (cpp_X < 320) { cpp_X = cpp_X + 200; } addControl.Left = cpp_X; addControl.Top = cpp_Y; addControl.Show(); } else { OSAEMethodManager.MethodQueueAdd(PressObjectName, PressMethodName, PressMethodParam1, PressMethodParam2, currentUser); } } }
public bool InstallPlugin(string PluginPackagePath, ref string ErrorText) { string exePath = Path.GetDirectoryName(Application.ExecutablePath); if (Directory.Exists(exePath + "/tempDir/")) { Directory.Delete(exePath + "/tempDir/", true); } PluginDescription desc = new PluginDescription(); string tempfolder = exePath + "/tempDir/"; string zipFileName = Path.GetFullPath(PluginPackagePath); string DescPath = null; bool NoError = true; ICSharpCode.SharpZipLib.Zip.FastZip fastZip = new ICSharpCode.SharpZipLib.Zip.FastZip(); try { fastZip.ExtractZip(zipFileName, tempfolder, null); // find all included plugin descriptions and install the plugins List <string> osapdFiles = new List <string>(); List <string> sqlFiles = new List <string>(); string[] pluginFile = Directory.GetFiles(tempfolder, "*.osapd", SearchOption.TopDirectoryOnly); osapdFiles.AddRange(pluginFile); string[] sqlFile = Directory.GetFiles(tempfolder, "*.sql", SearchOption.TopDirectoryOnly); sqlFiles.AddRange(sqlFile); if (osapdFiles.Count == 0) { MessageBox.Show("No plugin description files found."); return(false); } if (osapdFiles.Count > 1) { MessageBox.Show("More than one plugin description file found."); return(false); } if (osapdFiles.Count == 1) { DescPath = osapdFiles[0]; } if (!string.IsNullOrEmpty(DescPath)) { desc.Deserialize(DescPath); //NoError = desc.VerifyInstall(ref ErrorText); //uninstall previous plugin and delete the folder if (UninstallPlugin(desc)) { // get the plugin folder path string pluginFolder = desc.Path; if (!string.IsNullOrEmpty(pluginFolder)) //only extract valid plugins { string[] files = System.IO.Directory.GetFiles(tempfolder); string ConnectionString = string.Format("Uid={0};Pwd={1};Server={2};Port={3};Database={4};allow user variables=true", Common.DBUsername, Common.DBPassword, Common.DBConnection, Common.DBPort, Common.DBName); MySql.Data.MySqlClient.MySqlConnection connection = new MySql.Data.MySqlClient.MySqlConnection(ConnectionString); connection.Open(); foreach (string s in sqlFile) { try { MySql.Data.MySqlClient.MySqlScript script = new MySql.Data.MySqlClient.MySqlScript(connection, File.ReadAllText(s)); script.Execute(); } catch (Exception ex) { this.Log.Error("Error running sql script: " + s, ex); } } System.IO.Directory.Move(tempfolder, exePath + "/Plugins/" + pluginFolder); //Check if we are running a x64 bit architecture (This is a silly way to do it since I am not sure if every 64 bit machine has this directory...) bool is64bit = Environment.Is64BitOperatingSystem; //Do a check for any x64 assemblies, and prompt the user to install them if they are running a 64 bit machine if (is64bit && (desc.x64Assemblies.Count > 0)) { /* x64 assemblies generally have the same name as their x32 counterparts when referenced by the OSA app * however they are packaged as "filename.ext.x64" so we will replace the 32bit file which is installed by * default with the 64bit versioin with the same filename.ext */ if (MessageBox.Show( "You are running an x64 architecture and this plugin has specific assemblies built for 64bit machines." + " It is highly recommended that you install the 64bit versions to ensure proper compatibility", "Install 64bit Assemblies?", MessageBoxButtons.YesNo) == DialogResult.Yes) { //Install the 64bit assemblies over the 32 bit ones... string[] x64files = System.IO.Directory.GetFiles(exePath + "/Plugins/" + pluginFolder, "*.x64"); foreach (string str in x64files) { string destFile = System.IO.Path.Combine(exePath + "/Plugins/" + pluginFolder + "/", System.IO.Path.GetFileNameWithoutExtension(str)); //Copy it to the new destination overwriting the old file if it exists System.IO.File.Copy(str, destFile, true); } } } //Delete all the files with .x64 extensions since they aren't needed anymore string[] delfiles = System.IO.Directory.GetFiles(exePath + "/Plugins/" + pluginFolder, "*.x64"); foreach (string str in delfiles) { System.IO.File.Delete(str); } this.Log.Info("Sending message to service to load plugin."); } } else { return(false); } } } catch (Exception ex) { MessageBox.Show("catch: " + ex.Message); return(false); } if (Directory.Exists(exePath + "/tempDir/")) { deleteFolder(exePath + "/tempDir/"); } OSAEMethodManager.MethodQueueAdd("SERVICE-" + Common.ComputerName, "RELOAD PLUGINS", "", "", "Plugin Installer"); return(NoError); }
/// <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); } }
/// <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); } }
public Boolean ExecuteMethod(string name, string method, string param1, string param2) { // execute a method on an object OSAEMethodManager.MethodQueueAdd(name, method, param1, param2, sourceName); return(true); }
private void Slider_MouseUp(object sender, MouseButtonEventArgs e) { OSAEMethodManager.MethodQueueAdd(ObjectName, SliderMethod, Convert.ToUInt16(sldSlider.Value).ToString(), "", gAppName); updatingSlider = false; }
private void search() { try { Guid uuid = BluetoothService.L2CapProtocol; BluetoothDeviceInfo bdi; BluetoothAddress ba; byte tmp; bool found = false; int discarded; try { bc = new BluetoothClient(); } catch { Log.Error("No Bluetooth Adapters found!"); OSAEMethodManager.MethodQueueAdd(gAppName, "OFF", "", "", gAppName); return; } bc.InquiryLength = new TimeSpan(0, 0, 0, int.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(gAppName, "Discover Length").Value), 0); nearosaeDevices = bc.DiscoverDevices(10, false, false, true); for (int j = 0; j < nearosaeDevices.Length; j++) { string addr = nearosaeDevices[j].DeviceAddress.ToString(); Object obj = OSAEObjectManager.GetObjectByAddress(addr); if (obj == null) { if (OSAEObjectPropertyManager.GetObjectPropertyValue(gAppName, "Learning Mode").Value == "TRUE") { OSAEObjectManager.ObjectAdd(nearosaeDevices[j].DeviceName, "", nearosaeDevices[j].DeviceName, "BLUETOOTH DEVICE", nearosaeDevices[j].DeviceAddress.ToString(), string.Empty, 50, true); OSAEObjectPropertyManager.ObjectPropertySet(nearosaeDevices[j].DeviceName, "Discover Type", "0", gAppName); if (gDebug) { Log.Debug(addr + " - " + nearosaeDevices[j].DeviceName + ": added to OSA"); } } } } OSAEObjectCollection objects = OSAEObjectManager.GetObjectsByType("BLUETOOTH DEVICE"); foreach (OSAEObject obj in objects) { found = false; string address = obj.Address; byte[] byteArray = HexEncoding.GetBytes(address, out discarded); tmp = byteArray[0]; byteArray[0] = byteArray[5]; byteArray[5] = tmp; tmp = byteArray[1]; byteArray[1] = byteArray[4]; byteArray[4] = tmp; tmp = byteArray[2]; byteArray[2] = byteArray[3]; byteArray[3] = tmp; ba = new BluetoothAddress(byteArray); bdi = new BluetoothDeviceInfo(ba); //if (gDebug) Log.Debug("Begin search for " + address); for (int j = 0; j < nearosaeDevices.Length; j++) { if (nearosaeDevices[j].DeviceAddress.ToString() == address) { found = true; if (gDebug) { Log.Debug(address + " - " + obj.Name + ": found with DiscoverDevices"); } } } if (!found) { if (gDebug) { Log.Debug(address + " - " + obj.Name + ": failed with DiscoverDevices"); } } try { if (!found && (int.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(obj.Name, "Discover Type").Value) == 2 || Int32.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(obj.Name, "Discover Type").Value) == 0)) { if (gDebug) { Log.Debug(address + " - " + obj.Name + ": attempting GetServiceRecords"); } bdi.GetServiceRecords(uuid); found = true; if (gDebug) { Log.Debug(address + " - " + obj.Name + " found with GetServiceRecords"); } } } catch (Exception ex) { if (gDebug) { Log.Debug(address + " - " + obj.Name + " failed GetServiceRecords. exception: " + ex.Message); } } try { if (!found && (int.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(obj.Name, "Discover Type").Value) == 3 || int.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(obj.Name, "Discover Type").Value) == 0)) { if (gDebug) { Log.Debug(address + " - " + obj.Name + ": attempting Connection"); } //attempt a connect BluetoothEndPoint ep; ep = new BluetoothEndPoint(bdi.DeviceAddress, BluetoothService.Handsfree); //MessageBox.Show("attempt connect: " + pairedDevices[i].DeviceAddress); bc.Connect(ep); if (gDebug) { Log.Debug(address + " - " + obj.Name + " found with Connect attempt"); } bc.Close(); found = true; } } catch (Exception ex) { Log.Error(address + " - " + obj.Name + " failed with Connect attempt. exception: " + ex.Message); } if (found) { OSAEObjectStateManager.ObjectStateSet(obj.Name, "ON", gAppName); if (gDebug) { Log.Debug(obj.Name + " Status Updated in osae"); } } else { OSAEObjectStateManager.ObjectStateSet(obj.Name, "OFF", gAppName); if (gDebug) { Log.Debug(obj.Name + " Status Updated in osae"); } } } } catch (Exception ex) { Log.Error("Error searching for devices", ex); } }
private void Click_Image_MouseLeftButtonUp(object sender, MouseEventArgs e) { string imgName = screenObject.Property("Normal Image").Value; OSAEImage img = imgMgr.GetImage(imgName); if (img.Data != null) { var imageStream = new MemoryStream(img.Data); var bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = imageStream; bitmapImage.EndInit(); Image.Source = bitmapImage; Image.Visibility = System.Windows.Visibility.Visible; } else { Image.Source = null; Image.Visibility = System.Windows.Visibility.Hidden; } if (ReleaseMethodName != "") { if (ReleaseMethodParam1 == "[ASK]" | ReleaseMethodParam2 == "[ASK]") { ParamInput addControl = new ParamInput("Method", screenObject); string cppX = screenObject.Property("X").Value; string cppY = screenObject.Property("Y").Value; double cpp_X = Convert.ToDouble(cppX); double cpp_Y = Convert.ToDouble(cppY); if (cpp_X < 320) { cpp_X = cpp_X + 200; } addControl.Left = cpp_X; addControl.Top = cpp_Y; addControl.Show(); } else { OSAEMethodManager.MethodQueueAdd(ReleaseObjectName, ReleaseMethodName, ReleaseMethodParam1, ReleaseMethodParam2, "GUI"); } } if (PressScriptName != "") { if (PressScriptParam1 == "[ASK]" | PressScriptParam2 == "[ASK]") { ParamInput addControl = new ParamInput("Method", screenObject); string cppX = screenObject.Property("X").Value; string cppY = screenObject.Property("Y").Value; double cpp_X = Convert.ToDouble(cppX); double cpp_Y = Convert.ToDouble(cppY); if (cpp_X < 320) { cpp_X = cpp_X + 200; } addControl.Left = cpp_X; addControl.Top = cpp_Y; addControl.Show(); } else { OSAEMethodManager.MethodQueueAdd(ReleaseObjectName, ReleaseMethodName, ReleaseMethodParam1, ReleaseMethodParam2, "GUI"); } } }
private void Method_Image_MouseLeftButtonUp(object sender, MouseEventArgs e) { OSAEMethodManager.MethodQueueAdd(ObjectName, MethodName, Param1, Param2, "GUI"); }