示例#1
0
        private void searchMessageSenderRecievedFromServer()
        {
            BLL.tb_log        log = new BLL.tb_log();
            List <BLL.tb_log> l_list = log.LoadlogstoSendReplyToUser(); // Reply from server
            List <BLL.tb_log> l_list_not_replied = log.LoadlogstoNotReplied();
            string            command, reply;

            for (int i = 0; i < l_list_not_replied.Count(); i++)
            {
                command = l_list_not_replied[i].msg_text;

                for (int j = 0; j < l_list.Count(); j++)
                {
                    reply = l_list[j].msg_text; // always a reply
                    if (isMatch(command, reply))
                    {
                        //MessageBox.Show(command +"Found in"+reply +"and reply number is"+l_list_not_replied[i].sender_mobile_number);

                        if (l_list_not_replied[i].sender_mobile_number != server_number && l_list_not_replied[i].sender_mobile_number != server_number2 && l_list_not_replied[i].sender_mobile_number != server_number155)
                        {
                            SendMessagetoUser(reply, l_list_not_replied[i].sender_mobile_number);
                        }

                        log.to_user_time_stamp = DateTime.Now;
                        log.isUserReplied      = true;
                        log.logger_id          = l_list_not_replied[i].logger_id;
                        log.UpdateReplySentToUser(log);
                    }
                }
            }
        }
        private void sendCommandToServer()
        {
            BLL.tb_log        log    = new BLL.tb_log();
            List <BLL.tb_log> l_list = log.LoadlogstoSendCommandToServer();

            for (int i = 0; i < l_list.Count; i++)
            {
                SendMessage(l_list[i].msg_text.Trim(), l_list[i].logger_id);
            }
        }
示例#3
0
        public bool SaveLog(tb_log log)
        {
            bool saved = false;

            try
            {
                dc.tb_logs.InsertOnSubmit(log);
                dc.SubmitChanges();
            }
            catch (Exception en)
            {
                throw en;
            }
            return(saved);
        }
示例#4
0
        public void UpdateReplySentToUser(tb_log log)
        {
            try
            {
                tb_log l = dc.tb_logs.Single(ls => ls.logger_id == log.logger_id);

                l.isUserReplied      = log.isUserReplied;
                l.to_user_time_stamp = log.to_user_time_stamp;

                dc.SubmitChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#5
0
        private void sendCommandToServer()
        {
            BLL.tb_log        log    = new BLL.tb_log();
            List <BLL.tb_log> l_list = log.LoadlogstoSendCommandToServer();

            for (int i = 0; i < l_list.Count; i++)
            {
                SendMessage(l_list[i].msg_text.Trim());
                log.logger_id             = l_list[i].logger_id;
                log.to_command_time_stamp = DateTime.Now;
                log.isCommandSent         = true;
                log.UpdateCommandSentToServer(log);
                txtLogs.Text     += DateTime.Now + "-" + ("Message Sent to Server for Processing..." + "\r\n");
                txtLogs.ForeColor = Color.Magenta;
            }
        }
示例#6
0
        public bool UpdateCommandSentToServer(tb_log log)
        {
            try
            {
                tb_log l = dc.tb_logs.Single(ls => ls.logger_id == log.logger_id);

                l.isCommandSent         = log.isCommandSent;
                l.to_command_time_stamp = log.to_command_time_stamp;


                dc.SubmitChanges();
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 private void detach_tb_logs(tb_log entity)
 {
     this.SendPropertyChanging();
     entity.tb_user = null;
 }
 private void attach_tb_logs(tb_log entity)
 {
     this.SendPropertyChanging();
     entity.tb_user = this;
 }
 partial void Deletetb_log(tb_log instance);
 partial void Updatetb_log(tb_log instance);
 partial void Inserttb_log(tb_log instance);
        private async void RetrieveNewMessages()
        {
            // check message syntax......
            if (string.IsNullOrEmpty(txtIPAddress.Text))
            {
                //MessageBox.Show("Please enter an IP address", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtIPAddress.Focus();
                return;
            }

            try
            {
                btnRefresh.Enabled = false;

                using (var client = new HttpClient())
                {
                    string url = ConstructBaseUri();
                    client.BaseAddress = new Uri(url);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    if (!string.IsNullOrEmpty(txtUserName.Text) && !string.IsNullOrEmpty(txtPassword.Text))
                    {
                        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
                            "Basic",
                            Convert.ToBase64String(
                                ASCIIEncoding.ASCII.GetBytes(
                                    string.Format("{0}:{1}", txtUserName.Text, txtPassword.Text))));
                    }


                    HttpResponseMessage response = await client.GetAsync(MessagesUrlPath + "?status=0");

                    if (response.IsSuccessStatusCode)
                    {
                        GetMessageResponse result = await response.Content.ReadAsAsync <GetMessageResponse>();

                        if (result.IsSuccessful)
                        {
                            //  txtOutput.Text = "";

                            //


                            // MyMessage myMessage = new MyMessage();

                            List <DeviceMessage> mList = new List <DeviceMessage>();

                            int uid = 0;

                            List <BLL.tb_log> l_list = new List <BLL.tb_log>();

                            foreach (DeviceMessage msg in result.Messages)
                            {
                                uid = isAuthorised(msg.Number);

                                if (uid > 0)
                                {
                                    BLL.tb_log log = new BLL.tb_log();
                                    log.user_id = uid;
                                    log.sender_mobile_number = msg.Number;
                                    if (msg.Number.Equals(server_number) || msg.Number.Equals(server_number2) || msg.Number.Equals(server_number155))
                                    {
                                        log.isFromServer = true;
                                    }
                                    else
                                    {
                                        log.isFromServer = false;
                                    }
                                    log.msg_text      = msg.Message;
                                    log.isCommandSent = false;
                                    log.isUserReplied = false;
                                    mList.Add(msg);
                                    log.SaveLog(log);
                                    markMessageAsRead(msg.Id);
                                }
                            }
                            dgViewMessage.DataSource = mList;

                            string t = "No Message from Regd Users...";
                            if (mList.Count < 1)
                            {
                                txtLogs.Text += DateTime.Now + "-" + (t + "\r\n");
                            }
                        }
                        else
                        {
                            this.dgViewMessage.DataSource = null;
                            this.dgViewMessage.Rows.Clear();
                            txtLogs.Text += DateTime.Now + "-" + (result.Description + "\r\n");
                            // txtLogs.Text = result.Description;
                            // MessageBox.Show(result.Description, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        txtLogs.Text += DateTime.Now + "-" + (response.ToString() + "\r\n");
                        //
                        // MessageBox.Show(response.ToString(), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            catch (Exception ex)
            {
                txtLogs.Text += DateTime.Now + "-" + (ex.Message + "\r\n");
                // MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                btnRefresh.Enabled = true;
            }
        }
        private async void SendMessage(String message_text, int log_id)
        {
            message_sent = false;
            //if (message_text.StartsWith("loc", true, null))
            //{
            //    if(message_text.Length>15){
            //    string number = message_text.Substring(4, 12);
            //    string net = getNetwork(number);
            //    //MessageBox.Show("Number is= "+number +"Netwotk is   "+net);
            //    string command = "";
            //    string address = "";
            //    string subj = "";

            //    if (net.Equals("mobilink"))
            //    {
            //        subj = "Loc Query";
            //        command = number;
            //        address = "*****@*****.**";
            //    }
            //    else if (net.Equals("warid"))
            //    {
            //        subj = "Location Query";
            //        command = number;
            //        address = "*****@*****.**";
            //    }
            //    else if (net.Equals("ufone"))
            //    {
            //        subj = number;
            //        command = "";
            //        address = "*****@*****.**";

            //    }
            //    else if (net.Equals("zong"))
            //    {
            //        subj = "FIR";
            //        command = "Location Please = " + number;
            //        address = "*****@*****.**";
            //    }
            //    else if (net.Equals("telenor"))
            //    {
            //        subj = "FIR";
            //        command = "Loc " + number;
            //        address = "*****@*****.**";
            //    }

            //    txtLogs.Text = subj + " Command= " + command + " Address= " + address;
            //    if (sendCommand(subj, command, address))
            //    {
            //        txtLogs.Text += DateTime.Now + "-" + ("Email Command Sent..." + "\r\n");
            //    }
            //    }
            //    return;
            //}

            string sender_number;

            if (message_text.StartsWith("cnic", true, null) || message_text.StartsWith("sub", true, null) || message_text.StartsWith("vehicle", true, null))
            {
                sender_number = server_number155;
                // server_number = server_number155;
            }
            else
            {
                sender_number = server_number;
            }

            try
            {
                using (var client = new HttpClient())
                {
                    string url = ConstructBaseUri();
                    client.BaseAddress = new Uri(url);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    if (!string.IsNullOrEmpty(txtUserName.Text) && !string.IsNullOrEmpty(txtPassword.Text))
                    {
                        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
                            "Basic",
                            Convert.ToBase64String(
                                ASCIIEncoding.ASCII.GetBytes(
                                    string.Format("{0}:{1}", txtUserName.Text, txtPassword.Text))));
                    }


                    var postData = new List <KeyValuePair <string, string> >();
                    postData.Add(new KeyValuePair <string, string>("to", sender_number));
                    postData.Add(new KeyValuePair <string, string>("message", message_text));
                    HttpContent content = new FormUrlEncodedContent(postData);


                    HttpResponseMessage response = await client.PostAsync(MessagesUrlPath, content);

                    if (response.IsSuccessStatusCode)
                    {
                        PostMessageResponse result = await response.Content.ReadAsAsync <PostMessageResponse>();

                        if (result.IsSuccessful)
                        {
                            message_sent = true;

                            //Update log

                            BLL.tb_log log = new BLL.tb_log();
                            log.logger_id             = log_id;
                            log.to_command_time_stamp = DateTime.Now;
                            log.isCommandSent         = true;
                            if (log.UpdateCommandSentToServer(log))
                            {
                                //  txtLogs.Text += DateTime.Now + "-" + ("Message Sent to Server for Processing..." + "\r\n");
                                txtLogs.Text += DateTime.Now + "-" + ("Command Sent to   " + sender_number + " - Command - " + message_text + "\r\n");

                                txtLogs.ForeColor = Color.Magenta;
                            }
                        }
                        else
                        {
                            txtLogs.Text += DateTime.Now + "-" + ("Unable to Send Command..." + "\r\n");
                        }
                    }
                    else
                    {
                        txtLogs.Text += DateTime.Now + "-" + ("Unable to Send Command..." + "\r\n");
                    }
                }
            }
            catch (Exception ex)
            {
                txtLogs.Text += DateTime.Now + "-" + ("Unable to Send Command..." + "\r\n");
            }
        }