void socketmanager_Disconnected(object sender) { this.localizator.Culture = this.optset.Language; string startString = this.localizator["0008"]; if (this.InvokeRequired) { Invoke(new SetPropertyDelegate(SetProperty), new object[] { (object)btnStartStop, "Text", startString }); Invoke(new SetPropertyDelegate(SetProperty), new object[] { (object)btnStartStop, "Enabled", true }); Invoke(new SetPropertyDelegate(SetProperty), new object[] { (object)btnConfig, "Enabled", true }); Invoke(new SetPropertyDelegate(SetProperty), new object[] { (object)pnlExtension, "Visible", false }); Invoke(new SetPropertyDelegate(SetProperty), new object[] { (object)noOpTimer, "Enabled", false }); Invoke(new SetPropertyDelegate(SetProperty), new object[] { (object)lblLineState, "Text", "" }); } else { this.btnStartStop.Text = startString; this.btnStartStop.Enabled = true; this.btnConfig.Enabled = true; this.pnlExtension.Visible = false; this.noOpTimer.Enabled = false; this.lblLineState.Text = ""; } this.protocolStatus = PROTOCOL_STATES.STATUS_UNKNOWN; if (!this.Visible) { DoFormShow(); } }
void socketmanager_Connected(object sender) { if (this.InvokeRequired) { Invoke(new SetPropertyDelegate(SetProperty), new object[] { (object)noOpTimer, "Enabled", true }); Invoke(new SetPropertyDelegate(SetProperty), new object[] { (object)pnlExtension, "Visible", true }); Invoke(new SetPropertyDelegate(SetProperty), new object[] { (object)btnStartStop, "Enabled", true }); } else { this.noOpTimer.Enabled = true; this.pnlExtension.Visible = true; this.btnStartStop.Enabled = true; } this.protocolStatus = PROTOCOL_STATES.STATUS_UNKNOWN; }
public frmMain() { InitializeComponent(); Stream s = this.GetType().Assembly.GetManifestResourceStream("AstCTIClient.mainform.gif"); Bitmap bmp = new Bitmap(s); this.DoubleBuffered = true; this.Region = BitmapToRegion.Convert(bmp, bmp.GetPixel(0, 0), TransparencyMode.ColorKeyTransparent); this.notifyIcon1.Visible = false; this.MouseDown += new MouseEventHandler(frmMain_MouseDown); this.notifyIcon1.DoubleClick += new EventHandler(notifyIcon1_DoubleClick); this.txtPassword.LostFocus += new EventHandler(txtPassword_LostFocus); this.txtUsername.LostFocus += new EventHandler(txtUsername_LostFocus); this.txtPhoneNumber.TextChanged += new EventHandler(txtPhoneNumber_TextChanged); this.cboOutboundContextes.SelectedIndexChanged += new EventHandler(cboOutboundContextes_SelectedIndexChanged); this.socketmanager = null; this.parser = null; this.protocolStatus = PROTOCOL_STATES.STATUS_UNKNOWN; this.lblLineState.Text = ""; sm = new SettingsManager.SettingsManager(); this.CheckRegistrySettings(); try { if (optset == null) { sm.AppSettingsObject = new LocalAppSettings(); sm.ReadConfig(); optset = (LocalAppSettings)sm.AppSettingsObject; } if (this.parser == null) { this.parser = new ProtocolParser(); this.parser.Parsed += new ProtocolParser.OnParsed(parser_Parsed); } if (this.socketmanager == null) { this.socketmanager = new SocketManager(this.optset.Host, this.optset.Port); this.socketmanager.Connected += new SocketManager.OnConnected(socketmanager_Connected); this.socketmanager.Disconnected += new SocketManager.OnDisconnected(socketmanager_Disconnected); this.socketmanager.DataArrival += new SocketManager.OnDataArrival(socketmanager_DataArrival); this.socketmanager.SocketError += new SocketManager.OnSocketError(socketmanager_SocketError); } this.noOpTimer = new System.Windows.Forms.Timer(); this.noOpTimer.Tick += new EventHandler(noOpTimer_Tick); this.noOpTimer.Interval = this.optset.SocketTimeout; this.UpdateOutboundContextes(); this.txtUsername.Text = optset.Username; this.txtPassword.Text = optset.Password; this.lblExtension.Text = optset.PhoneExt; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } this.localizator = new Localizator(); this.localizator.Culture = this.optset.Language; this.localizator.Localize(this); UpdateTooltips(); this.FormSetFont(); }
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 } }
public frmMain() { InitializeComponent(); Stream s = this.GetType().Assembly.GetManifestResourceStream("AstCTIClient.mainform.gif"); Bitmap bmp = new Bitmap(s); this.DoubleBuffered = true; this.Region = BitmapToRegion.Convert(bmp, bmp.GetPixel(0, 0), TransparencyMode.ColorKeyTransparent); this.notifyIcon1.Visible = false; this.MouseDown += new MouseEventHandler(frmMain_MouseDown); this.notifyIcon1.DoubleClick += new EventHandler(notifyIcon1_DoubleClick); this.txtPassword.LostFocus += new EventHandler(txtPassword_LostFocus); this.txtUsername.LostFocus += new EventHandler(txtUsername_LostFocus); this.txtPhoneNumber.TextChanged += new EventHandler(txtPhoneNumber_TextChanged); this.cboOutboundContextes.SelectedIndexChanged += new EventHandler(cboOutboundContextes_SelectedIndexChanged); this.socketmanager = null; this.parser = null; this.protocolStatus = PROTOCOL_STATES.STATUS_UNKNOWN; this.lblLineState.Text = ""; sm = new SettingsManager.SettingsManager(); this.CheckRegistrySettings(); try { if (optset == null) { sm.AppSettingsObject = new LocalAppSettings(); sm.ReadConfig(); optset = (LocalAppSettings)sm.AppSettingsObject; } if (this.parser == null) { this.parser = new ProtocolParser(); this.parser.Parsed += new ProtocolParser.OnParsed(parser_Parsed); } if (this.socketmanager == null) { this.socketmanager = new SocketManager(this.optset.Host, this.optset.Port); this.socketmanager.Connected += new SocketManager.OnConnected(socketmanager_Connected); this.socketmanager.Disconnected += new SocketManager.OnDisconnected(socketmanager_Disconnected); this.socketmanager.DataArrival += new SocketManager.OnDataArrival(socketmanager_DataArrival); this.socketmanager.SocketError += new SocketManager.OnSocketError(socketmanager_SocketError); } this.noOpTimer = new System.Windows.Forms.Timer(); this.noOpTimer.Tick += new EventHandler(noOpTimer_Tick); this.noOpTimer.Interval = this.optset.SocketTimeout; this.UpdateOutboundContextes(); this.txtUsername.Text = optset.Username; this.txtPassword.Text = optset.Password; this.lblExtension.Text = optset.PhoneExt; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } this.localizator = new Localizator(); this.localizator.Culture = this.optset.Language; this.localizator.Localize(this); UpdateTooltips(); this.FormSetFont(); }
void socketmanager_Disconnected(object sender) { this.localizator.Culture = this.optset.Language; string startString = this.localizator["0008"]; if (this.InvokeRequired) { Invoke(new SetPropertyDelegate(SetProperty), new object[] { (object)btnStartStop, "Text", startString }); Invoke(new SetPropertyDelegate(SetProperty), new object[] { (object)btnStartStop, "Enabled", true }); Invoke(new SetPropertyDelegate(SetProperty), new object[] { (object)btnConfig, "Enabled", true }); Invoke(new SetPropertyDelegate(SetProperty), new object[] { (object)pnlExtension, "Visible", false}); Invoke(new SetPropertyDelegate(SetProperty), new object[] { (object)noOpTimer, "Enabled", false }); Invoke(new SetPropertyDelegate(SetProperty), new object[] { (object)lblLineState, "Text", "" }); } else { this.btnStartStop.Text = startString; this.btnStartStop.Enabled = true; this.btnConfig.Enabled = true; this.pnlExtension.Visible = false; this.noOpTimer.Enabled = false; this.lblLineState.Text = ""; } this.protocolStatus = PROTOCOL_STATES.STATUS_UNKNOWN; if (!this.Visible) { DoFormShow(); } }
void socketmanager_Connected(object sender) { if (this.InvokeRequired) { Invoke(new SetPropertyDelegate(SetProperty), new object[] { (object)noOpTimer, "Enabled", true }); Invoke(new SetPropertyDelegate(SetProperty), new object[] { (object)pnlExtension, "Visible", true }); Invoke(new SetPropertyDelegate(SetProperty), new object[] { (object)btnStartStop, "Enabled", true }); } else { this.noOpTimer.Enabled = true; this.pnlExtension.Visible = true; this.btnStartStop.Enabled = true; } this.protocolStatus = PROTOCOL_STATES.STATUS_UNKNOWN; }
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 } }