private static void Send(TcpClient tcpClient) { ConsoleKeyInfo key = new ConsoleKeyInfo(); try { while (key.Key != ConsoleKey.Escape) { if (tcpClient.Connected && threadRead == null) { threadRead = new Thread(new ParameterizedThreadStart(Read)); threadRead.Start(tcpClient); } string data = Console.ReadLine(); if (tcpClient.Connected) { client.Send(data); } else { break; } } tcpClient.Close(); } catch { } }
private void buttonSend_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(textBoxNumber.Text)) { /* * Command Format Sending SMS * -------------------------- * ISMS.Send(+param: number={0} +param: message={1}) * * e.g. ISMS.Send(+param: number=081818181 +param: message=lorem ipsum) * -------------------------- */ string formattedCommand = string.Format(command.Get("ISMS.Send"), textBoxNumber.Text, textBoxMessage.Text); for (int i = 0; i < numericUpDownMultiple.Value; i++) { Thread.Sleep(250); gsmClient.Send(formattedCommand); } } }
//public void OnDataSent(string data) //{ //} public void OnDataReceived(string data) { List <BaseResult <SMSReadResult> > list = JsonHelper.JsonDeserialize <List <BaseResult <SMSReadResult> > >(data); if (list.Count > 0) { foreach (BaseResult <SMSReadResult> read in list) { if (read.Response.TypeName.Contains("SMSRead")) { if (keywords.Any()) { foreach (QuizModel keyword in keywords) { Match match = new Regex(@"(.*[a-zA-Z]) (.*[a-zA-Z])").Match(keyword.Keyword); if (match.Success) { if (read.Response.Message.ToLower().Contains(match.Groups[1].Value.ToLower())) { string[] arg = read.Response.Message.ToLower().Split(new string[] { match.Groups[1].Value.ToLower() }, StringSplitOptions.RemoveEmptyEntries); using (IQuery con = new DapperDbContext(DatabaseConst.SMSGateway)) { List <Answer> result = con.Query <Answer>(keyword.Response, new { KeyID = arg[0].Trim() }); if (result.Any()) { smsSender = new GSMClient.Client(ipStr, Convert.ToInt32(portStr)); smsSender.Open(); smsSender.Send(string.Format(GSMClient.Command.CommandCollection.SMSSend, read.Response.From, result.SingleOrDefault().Description)); smsSender.Close(); } } break; } } } } } } } }
//public void OnDataSent(string data) //{ //} public void OnDataReceived(string data) { List<BaseResult<SMSReadResult>> list = JsonHelper.JsonDeserialize<List<BaseResult<SMSReadResult>>>(data); if (list.Count > 0) { foreach (BaseResult<SMSReadResult> read in list) { if (read.Response.TypeName.Contains("SMSRead")) { if (keywords.Any()) { foreach (QuizModel keyword in keywords) { Match match = new Regex(@"(.*[a-zA-Z]) (.*[a-zA-Z])").Match(keyword.Keyword); if (match.Success) { if (read.Response.Message.ToLower().Contains(match.Groups[1].Value.ToLower())) { string[] arg = read.Response.Message.ToLower().Split(new string[] { match.Groups[1].Value.ToLower() }, StringSplitOptions.RemoveEmptyEntries); using (IQuery con = new DapperDbContext(DatabaseConst.SMSGateway)) { List<Answer> result = con.Query<Answer>(keyword.Response, new { KeyID = arg[0].Trim() }); if (result.Any()) { smsSender = new GSMClient.Client(ipStr, Convert.ToInt32(portStr)); smsSender.Open(); smsSender.Send(string.Format(GSMClient.Command.CommandCollection.SMSSend, read.Response.From, result.SingleOrDefault().Description)); smsSender.Close(); } } break; } } } } } } } }