/// <summary> /// Static method that maps XML object to AsteriskCall Object /// </summary> /// <param name="data">Data to parse</param> /// <param name="eventId">Outputs the eventId</param> /// <returns>An AsteriskCall object if parse is successfull. Otherwise null</returns> public static AsteriskCall CallFromXml(string data, out string eventId) { AsteriskCall xmlcall = null; XmlDocument doc = new XmlDocument(); doc.InnerXml = data; XmlElement root = doc.DocumentElement; eventId = ""; if (root.Name.ToLower().Equals("event")) { eventId = root.GetAttribute("id"); XmlNode call = root.ChildNodes[0]; xmlcall = new AsteriskCall(); foreach (XmlElement prop in call.ChildNodes) { if (prop.Name.Equals("uniqueid")) { xmlcall.Uniqueid = prop.InnerText; } if (prop.Name.Equals("channel")) { xmlcall.Channel = prop.InnerText; } if (prop.Name.Equals("calleridnum")) { xmlcall.CallerIDNum = prop.InnerText; } if (prop.Name.Equals("calleridname")) { xmlcall.CallerIDName = prop.InnerText; } if (prop.Name.Equals("context")) { xmlcall.Context = prop.InnerText; } if (prop.Name.Equals("appdata")) { xmlcall.AppData = prop.InnerText; } if (prop.Name.Equals("state")) { xmlcall.State = prop.InnerText; } } } return(xmlcall); }
void ExecCTIApplication(CTIContext ctx, AsteriskCall call) { if ((!ctx.InternalBrowser) & (!File.Exists(ctx.Application))) { GenericStringAction scf = new GenericStringAction(this.MessageBoxShow); scf.Invoke(string.Format("{0} {1}", this.localizator["0015"], ctx.DisplayName)); return; } string parameters = ctx.Parameters; if (parameters != null) { parameters = parameters.Replace("{CALLERID}", call.CallerIDNum); parameters = parameters.Replace("{CALLERNAME}", call.CallerIDName); parameters = parameters.Replace("{CONTEXT}", call.Context); parameters = parameters.Replace("{CALLDATA}", call.AppData); parameters = parameters.Replace("{CHANNEL}", call.Channel); parameters = parameters.Replace("{UNIQUEID}", call.Uniqueid); } if (ctx.InternalBrowser) { Thread t = new Thread(this.OpenBrowserForm); t.SetApartmentState(ApartmentState.STA); t.Start(parameters); //GenericStringAction scf = new GenericStringAction(this.OpenBrowserForm); //scf.Invoke(parameters); } else { System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents = false; proc.StartInfo.Arguments = parameters; proc.StartInfo.FileName = ctx.Application; proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; proc.Start(); } }
/// <summary> /// Static method that maps XML object to AsteriskCall Object /// </summary> /// <param name="data">Data to parse</param> /// <param name="eventId">Outputs the eventId</param> /// <returns>An AsteriskCall object if parse is successfull. Otherwise null</returns> public static AsteriskCall CallFromXml(string data, out string eventId) { AsteriskCall xmlcall = null; XmlDocument doc = new XmlDocument(); doc.InnerXml = data; XmlElement root = doc.DocumentElement; eventId = ""; if (root.Name.ToLower().Equals("event")) { eventId = root.GetAttribute("id"); XmlNode call = root.ChildNodes[0]; xmlcall = new AsteriskCall(); foreach (XmlElement prop in call.ChildNodes) { if (prop.Name.Equals("uniqueid")) xmlcall.Uniqueid = prop.InnerText; if (prop.Name.Equals("channel")) xmlcall.Channel = prop.InnerText; if (prop.Name.Equals("calleridnum")) xmlcall.CallerIDNum = prop.InnerText; if (prop.Name.Equals("calleridname")) xmlcall.CallerIDName = prop.InnerText; if (prop.Name.Equals("context")) xmlcall.Context = prop.InnerText; if (prop.Name.Equals("appdata")) xmlcall.AppData = prop.InnerText; if (prop.Name.Equals("state")) xmlcall.State = prop.InnerText; } } return xmlcall; }
void parser_Parsed(int message, string data) { if (message == 0) { #region Asterisk Events string eventId = ""; string state = ""; AsteriskCall call = AsteriskCall.CallFromXml(data, out eventId); if (call != null) { switch (eventId) { case "Newstate": state = call.State; if (state != null) { switch (state) { case "Up": state = this.localizator["0101"]; // "Off Hook"; break; case "Ringing": state = this.localizator["0102"]; // "Ringing"; break; case "Down": state = this.localizator["0103"]; //"On Hook"; break; } } else { state = ""; } Invoke(new SetPropertyDelegate(SetProperty), new object[] { (object)lblLineState, "Text", state }); break; case "Newcallerid": if (this.optset.TriggerCallerId) { // Check matching contextes before popup GenericStringAction scf = new GenericStringAction(this.OpenCallerIdForm); scf.Invoke(call.CallerIDNum); return; } break; case "Link": EnableCallActions(false); CTIContext tostart = null; foreach (CTIContext ctx in this.optset.CTIContextes) { if (ctx.Context.Equals(call.Context)) { if (ctx.Enabled) { tostart = ctx; break; } } } // Check for a CatchAll if (tostart == null) { foreach (CTIContext ctx in this.optset.CTIContextes) { if ((ctx.CatchAll) & (ctx.Enabled)) { tostart = ctx; break; } } } state = this.localizator["0104"]; // "Connected" Invoke(new SetPropertyDelegate(SetProperty), new object[] { (object)lblLineState, "Text", state }); if (tostart != null) { ExecCTIApplication(tostart, call); } break; case "Hangup": state = this.localizator["0105"]; // "Hangup" Invoke(new SetPropertyDelegate(SetProperty), new object[] { (object)lblLineState, "Text", state }); EnableCallActions(true); break; } } #endregion } else { #region Main Switch switch (message) { case 100: switch (this.protocolStatus) { case PROTOCOL_STATES.STATUS_UNKNOWN: this.protocolStatus = PROTOCOL_STATES.SENDED_USERNAME; this.socketmanager.SendData("USER " + this.txtUsername.Text); break; case PROTOCOL_STATES.SENDED_USERNAME: this.protocolStatus = PROTOCOL_STATES.SENDED_PASSWORD; this.socketmanager.SendData("PASS " + ProtocolParser.MD5(this.txtPassword.Text)); break; default: break; } break; case 101: if (this.socketmanager.IsConnected) { this.socketmanager.SendData("QUIT"); this.socketmanager.Disconnect(); MessageBox.Show(this.localizator["0014"]); // "Invalid credentials" } break; case 102: switch (this.protocolStatus) { case PROTOCOL_STATES.SENDED_PASSWORD: string stopString = this.localizator["0009"]; this.protocolStatus = PROTOCOL_STATES.LOGGED_IN; if (this.InvokeRequired) { Invoke(new SetPropertyDelegate(SetProperty), new object[] { (object)btnStartStop, "Text", stopString }); Invoke(new SetPropertyDelegate(SetProperty), new object[] { (object)btnStartStop, "Enabled", true }); Invoke(new SetPropertyDelegate(SetProperty), new object[] { (object)btnConfig, "Enabled", false }); Invoke(new SetPropertyDelegate(SetProperty), new object[] { (object)lblLineState, "Text", "" }); if (this.optset.MinimizeOnStart) { Invoke(new SetMethodDelegate(SetMethod), new object[] { (object)this, "DoFormHide", null }); } } else { this.btnStartStop.Text = stopString; this.btnStartStop.Enabled = true; this.btnConfig.Enabled = false; this.DoFormHide(); } break; } break; } #endregion } }
void ExecCTIApplication(CTIContext ctx, AsteriskCall call) { if ( (!ctx.InternalBrowser) & (!File.Exists(ctx.Application)) ) { GenericStringAction scf = new GenericStringAction(this.MessageBoxShow); scf.Invoke(string.Format("{0} {1}", this.localizator["0015"], ctx.DisplayName)); return; } string parameters = ctx.Parameters; if (parameters != null) { parameters = parameters.Replace("{CALLERID}", call.CallerIDNum); parameters = parameters.Replace("{CALLERNAME}", call.CallerIDName); parameters = parameters.Replace("{CONTEXT}", call.Context); parameters = parameters.Replace("{CALLDATA}", call.AppData); parameters = parameters.Replace("{CHANNEL}", call.Channel); parameters = parameters.Replace("{UNIQUEID}", call.Uniqueid); } if (ctx.InternalBrowser) { Thread t = new Thread(this.OpenBrowserForm); t.SetApartmentState(ApartmentState.STA); t.Start(parameters); //GenericStringAction scf = new GenericStringAction(this.OpenBrowserForm); //scf.Invoke(parameters); } else { System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents = false; proc.StartInfo.Arguments = parameters; proc.StartInfo.FileName = ctx.Application; proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; proc.Start(); } }