protected void btnMatchDelete_Click(object sender, EventArgs e) { OSAEScriptManager.PatternMatchDelete(hdnSelectedMatchName.Text); loadMatches(); int selectedRow = Int32.Parse(hdnSelectedMatchRow.Text) - 1; if (selectedRow < 0) { hdnSelectedMatchRow.Text = ""; } else { hdnSelectedMatchRow.Text = selectedRow.ToString(); } }
protected void btnDeleteEventScript_Click(object sender, EventArgs e) { OSAEScriptManager.ObjectEventScriptDelete(hdnSelectedEventScriptID.Text); loadEventScripts(); int selectedRow = Int32.Parse(hdnSelectedEventScriptRow.Text) - 1; if (selectedRow < 0) { hdnSelectedEventScriptRow.Text = ""; } else { hdnSelectedEventScriptRow.Text = selectedRow.ToString(); } }
private void RunNormal() { Pipeline pipeline = null; Runspace runspace = null; try { RunspaceConfiguration runConfig = RunspaceConfiguration.Create(); PSSnapInException psEx = null; string script = OSAEScriptManager.GetScriptByName(Name); runConfig.AddPSSnapIn("OSA", out psEx); runspace = RunspaceFactory.CreateRunspace(runConfig); runspace.ThreadOptions = PSThreadOptions.UseCurrentThread; runspace.Open(); runspace.SessionStateProxy.SetVariable("parameter2", Parameter2); pipeline = runspace.CreatePipeline(); pipeline.Commands.AddScript(script); pipeline.Commands.Add("Out-String"); Collection <PSObject> results = pipeline.Invoke(); StringBuilder stringBuilder = new StringBuilder(); foreach (PSObject obj in results) { stringBuilder.AppendLine(obj.ToString()); } Log.Debug("Script return: \r\n" + stringBuilder.ToString()); } catch (Exception ex) { Log.Error("An error occured while trying to run the script, details", ex); } finally { if (pipeline != null) { pipeline.Dispose(); } if (runspace != null) { runspace.Close(); runspace.Dispose(); } } }
protected void btnDelete_Click(object sender, EventArgs e) { OSAEScriptManager.ScriptDelete(hdnSelectedScriptName.Text); loadScripts(); deleteAlert.Visible = true; int selectedRow = Int32.Parse(hdnSelectedRow.Text) - 1; if (selectedRow < 0) { hdnSelectedRow.Text = ""; } else { hdnSelectedRow.Text = selectedRow.ToString(); } }
protected void btnUpdate_Click(object sender, EventArgs e) { if (txtName.Text == "" || ddlScriptProcessor.SelectedValue == "") { alert.Visible = true; } else { OSAEScriptManager.ScriptUpdate(hdnSelectedScriptName.Text, txtName.Text, ddlScriptProcessor.SelectedValue, hdnScript.Value); loadScripts(); loadDDLs(); saveAlert.Visible = true; hdnSelectedScriptName.Text = txtName.Text; } Page.ClientScript.RegisterStartupScript(GetType(), "MyKey", "setSytaxHighlighter();", true); }
/// <summary> /// The Main Thread: This is where your Service is Run. /// </summary> static void Main(string[] args) { if (args.Length > 0) { string pattern = Common.MatchPattern(args[0]); Logging.AddToLog("Processing command: " + args[0] + ", Named Script: " + pattern, true, "OSACL"); if (pattern != string.Empty) { OSAEScriptManager.RunPatternScript(pattern, "", "OSACL"); } } else { ServiceBase.Run(new OSAEService()); } }
static void Main(string[] args) { if (args.Length > 0) { string pattern = Common.MatchPattern(args[0]); //this.Log.Info("Processing command: " + args[0] + ", Named Script: " + pattern); if (pattern != string.Empty) { OSAEScriptManager.RunPatternScript(pattern, "", "OSACL"); } } else { //Debugger.Launch(); ServiceBase.Run(new ClientService()); } }
void xmppCon_OnMessage(object sender, agsXMPP.protocol.client.Message msg) { // ignore empty messages (events) if (msg.Body == null) { return; } logging.AddToLog(String.Format("OnMessage from:{0} type:{1}", msg.From.Bare, msg.Type.ToString()), false); logging.AddToLog("Message: " + msg.Body, false); string pattern = Common.MatchPattern(msg.Body); if (pattern != string.Empty) { OSAEScriptManager.RunPatternScript(pattern, msg.From.Bare, "Jabber"); } }
public Boolean SendPattern(string match, string authkey) { // try // { // oRecognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(oRecognizer_SpeechRecognized); //oRecognizer.AudioStateChanged += new EventHandler<AudioStateChangedEventArgs>(oRecognizer_StateChanged); // } // catch (Exception ex) // { // Log.Error("Unable to configure oRecognizer", ex); // } // oRecognizer = OSAEGrammar.Load_Direct_Grammar(oRecognizer); // oRecognizer = OSAEGrammar.Load_Voice_Grammars(oRecognizer); // oRecognizer = OSAEGrammar.Load_Text_Only_Grammars(oRecognizer); //REPLACE WITH GRAMMAR // string patternName = Common.MatchPattern(match,""); // if (patternName != "") // { string uAuth = OSAESecurity.DecryptUser(authkey); if (uAuth != null) { OSAEScriptManager.RunScript(match, "", "Rest"); Log.Debug("Executing Script: " + match); return(true); } else { return(false); } // } // else //return false; }
protected void Page_PreRender(object sender, EventArgs e) { if (hdnSelectedRow.Text != "") { gvScripts.Rows[Int32.Parse(hdnSelectedRow.Text)].Attributes.Remove("onmouseout"); gvScripts.Rows[Int32.Parse(hdnSelectedRow.Text)].Style.Add("background", "lightblue"); txtName.Text = hdnSelectedScriptName.Text; ddlScriptProcessor.SelectedValue = gvScripts.DataKeys[Int32.Parse(hdnSelectedRow.Text)]["script_processor_name"].ToString(); hdnScript.Value = OSAEScriptManager.GetScript(gvScripts.DataKeys[Int32.Parse(hdnSelectedRow.Text)]["script_id"].ToString()); loadLinkage(gvScripts.DataKeys[Int32.Parse(hdnSelectedRow.Text)]["script_id"].ToString()); } if (hdnSelectedEventScriptRow.Text != "") { gvEventScripts.Rows[Int32.Parse(hdnSelectedEventScriptRow.Text)].Attributes.Remove("onmouseout"); gvEventScripts.Rows[Int32.Parse(hdnSelectedEventScriptRow.Text)].Style.Add("background", "lightblue"); } if (hdnSelectedObjTypeEventScriptRow.Text != "") { gvObjTypeScripts.Rows[Int32.Parse(hdnSelectedObjTypeEventScriptRow.Text)].Attributes.Remove("onmouseout"); gvObjTypeScripts.Rows[Int32.Parse(hdnSelectedObjTypeEventScriptRow.Text)].Style.Add("background", "lightblue"); } }
protected void Page_PreRender(object sender, EventArgs e) { if (hdnSelectedPatternRow.Text != "") { gvPatterns.Rows[Int32.Parse(hdnSelectedPatternRow.Text)].Attributes.Remove("onmouseout"); gvPatterns.Rows[Int32.Parse(hdnSelectedPatternRow.Text)].Style.Add("background", "lightblue"); pnlMatchForm.Visible = true; pnlScriptForm.Visible = true; txtPattern.Text = hdnSelectedPatternName.Text; lblExportPattern.Text = OSAEScriptManager.PatternExport(hdnSelectedPatternName.Text); } if (hdnSelectedMatchRow.Text != "") { gvMatches.Rows[Int32.Parse(hdnSelectedMatchRow.Text)].Attributes.Remove("onmouseout"); gvMatches.Rows[Int32.Parse(hdnSelectedMatchRow.Text)].Style.Add("background", "lightblue"); txtMatch.Text = hdnSelectedMatchName.Text; } if (hdnSelectedScriptRow.Text != "") { gvScripts.Rows[Int32.Parse(hdnSelectedScriptRow.Text)].Attributes.Remove("onmouseout"); gvScripts.Rows[Int32.Parse(hdnSelectedScriptRow.Text)].Style.Add("background", "lightblue"); } }
protected void btnPatternDelete_Click(object sender, EventArgs e) { if (OSAEScriptManager.PatternDelete(hdnSelectedPatternName.Text)) { loadPatterns(); int selectedRow = Int32.Parse(hdnSelectedPatternRow.Text) - 1; if (selectedRow < 0) { hdnSelectedPatternRow.Text = ""; } else { hdnSelectedPatternRow.Text = selectedRow.ToString(); } } else { Page.ClientScript.RegisterStartupScript( GetType(), "MyKey", "alert('Unable to delete pattern. Maybe a script is attached?');", true); } }
protected void btnMatchUpdate_Click(object sender, EventArgs e) { OSAEScriptManager.PatternMatchUpdate(hdnSelectedPatternName.Text, hdnSelectedMatchName.Text, txtMatch.Text); loadMatches(); }
protected void btnAddObjTypeEventScript_Click(object sender, EventArgs e) { OSAEScriptManager.ObjectTypeEventScriptAdd(ddlObjectType.SelectedItem.Text, ddlObjTypeEvent.SelectedItem.Value, Int32.Parse(ddlObjTypeScript.SelectedValue)); loadObjTypeEventScripts(); }
protected void btnTest_Click(object sender, EventArgs e) { OSAEScriptManager.ScriptDelete("Test Script"); OSAEScriptManager.ScriptAdd("Test Script", ddlScriptProcessor.SelectedValue, hdnScript.Value); OSAEScriptManager.RunScript("Test Script", txtTestParameter.Text, "WebUI"); }
protected void btnTest_Click(object sender, EventArgs e) { OSAEScriptManager.ScriptDelete("Test Script"); OSAEScriptManager.ScriptAdd("Test Script", ddlScriptProcessor.SelectedValue, hdnScript.Value); OSAEScriptManager.RunScript("Test Script", txtTestParameter.Text, Session["Username"].ToString()); }
public static string MatchPattern(string str) { string ScriptParameter = ""; try { DataSet dataset = new DataSet(); //command.CommandText = "SELECT pattern FROM osae_v_pattern WHERE `match`=@Name"; //command.Parameters.AddWithValue("@Name", str); dataset = OSAESql.RunSQL("SELECT pattern FROM osae_v_pattern WHERE `match`='" + str + "'"); if (dataset.Tables[0].Rows.Count > 0) { //Since we have a match, lets execute the scripts OSAEScriptManager.RunPatternScript(dataset.Tables[0].Rows[0]["pattern"].ToString(), "", "Jabber"); return(dataset.Tables[0].Rows[0]["pattern"].ToString()); } else { //Replace Words with place holders and retry the pattern match //example "Please turn the main light on" becomes "Please turn the [OBJECT] [STATE]" //Step 1: Break the Input into an Array to Query the Words for DB matches str = str.ToUpper(); string[] words = str.Split(' '); DataSet dsObjects = new DataSet(); foreach (String word in words) { dsObjects = OSAE.Common.ObjectNamesStartingWith(word); foreach (DataRow dr in dsObjects.Tables[0].Rows) { if (str.IndexOf(dr["object_name"].ToString()) > -1) //return "Found " + dr["object_name"].ToString(); { str = str.Replace(dr["object_name"].ToString(), "[OBJECT]"); ScriptParameter += dr["object_name"].ToString(); //Here We have found our Object, so we need to look for an appropriate state afterwards //So we are going to retrieve a state list and compare it to the remainder of the string DataSet dsStates = new DataSet(); dsStates = OSAEObjectStateManager.ObjectStateListGet(dr["object_name"].ToString()); foreach (DataRow drState in dsStates.Tables[0].Rows) { if (str.IndexOf(drState["state_label"].ToString().ToUpper()) > 0) { str = str.Replace(drState["state_label"].ToString().ToUpper(), "[STATE]"); ScriptParameter += ", " + drState["state_label"].ToString(); //Now that we have replaced the Object and State, Lets check for a match again //DataSet dataset = new DataSet(); //command.CommandText = "SELECT pattern FROM osae_v_pattern WHERE `match`=@Name"; //command.Parameters.AddWithValue("@Name", str); //dataset = OSAESql.RunQuery(command); dataset = OSAESql.RunSQL("SELECT pattern FROM osae_v_pattern WHERE `match`='" + str + "'"); if (dataset.Tables[0].Rows.Count > 0) { //return dataset.Tables[0].Rows[0]["pattern"].ToString(); //Since we have a match, lets execute the scripts OSAEScriptManager.RunPatternScript(dataset.Tables[0].Rows[0]["pattern"].ToString(), ScriptParameter, "Jabber"); return(dataset.Tables[0].Rows[0]["pattern"].ToString()); } break; } } break; } } } return(string.Empty); //return string.Empty; } } catch (Exception ex) { Logging.GetLogger().AddToLog("API - MatchPattern error: " + ex.Message, true); return(string.Empty); } }
protected void btnScriptExport_Click(object sender, EventArgs e) { OSAEScriptManager.GetScriptByName(hdnSelectedObjTypeEventScriptID.Text); }
protected void btnPatternUpdate_Click(object sender, EventArgs e) { OSAEScriptManager.PatternUpdate(hdnSelectedPatternName.Text, txtPattern.Text); loadPatterns(); }
protected void btnPatternAdd_Click(object sender, EventArgs e) { OSAEScriptManager.PatternAdd(txtPattern.Text); loadPatterns(); }
protected void btnScriptAdd_Click(object sender, EventArgs e) { OSAEScriptManager.PatternScriptAdd(hdnSelectedPatternName.Text, Int32.Parse(ddlScript.SelectedValue)); loadScripts(); }
protected void btnScriptAdd_Click(object sender, EventArgs e) { OSAEScriptManager.PatternScriptAdd(hdnSelectedPatternName.Text, ddlScript.SelectedItem.ToString()); loadScripts(); }