Exemple #1
0
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            try
            {
                base.OnFormClosing(e);
                if (e.CloseReason == CloseReason.WindowsShutDown)
                {
                    return;
                }

                if (MessageBox.Show(this, "Close Operator Gateway and kill process ?", "Closing", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    this.IsStop = true;
                    this.cancelToken.Cancel();
                    logger.Info("Stoped application !");
                    Process.GetCurrentProcess().Kill();
                }
                else
                {
                    e.Cancel = true;
                }
            }
            catch (Exception ex)
            {
                logger.Error(AppConst.A("OnFormClosing", ex));
                Process.GetCurrentProcess().Kill();
            }
        }
Exemple #2
0
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            try
            {
                base.OnFormClosing(e);
                if (e.CloseReason == CloseReason.WindowsShutDown)
                {
                    return;
                }

                if (MessageBox.Show(this, "Close PushSMS and kill process ?", "Closing", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    if (this.oracleDependency != null && this.oracleDependency.IsEnabled)
                    {
                        this.oracleDependency.OnChange -= new OnChangeEventHandler(OracleListenerCallback);
                        this.oracleDependency?.RemoveRegistration(this.connection);
                        this.connection?.Close();
                        this.connection?.Dispose();
                    }

                    logger.Info("Stoped application !");
                    Process.GetCurrentProcess().Kill();
                }
                else
                {
                    e.Cancel = true;
                }
            }
            catch (Exception ex)
            {
                logger.Error(AppConst.A("OnFormClosing", ex));
                Process.GetCurrentProcess().Kill();
            }
        }
Exemple #3
0
    /// <summary>
    /// Gửi tin quảng cáo
    /// Url: https://qc.vietguys.biz/api/sendsms.php
    /// </summary>
    /// <param name="user"></param>
    /// <param name="password"></param>
    /// <param name="sender"></param>
    /// <param name="sms"></param>
    /// <param name="listPhone"></param>
    /// <param name="date"></param>
    /// <param name="time"></param>
    /// <returns></returns>
    public async Task <string> SendSMS_QCAsync(string user, string password, string sender, string sms, string listPhone, string date, string time)
    {
        try
        {
            string url = String.Format("{0}?phone={1}&from={2}&sms={3}&u={4}&pwd={5}&day={6}&time={7}", this.Url, listPhone, sender, sms, user, password, date, time);

            using (HttpClient http = new HttpClient())
            {
                using (HttpRequestMessage httpRequest = new HttpRequestMessage(HttpMethod.Get, url))
                {
                    HttpResponseMessage response = await http.SendAsync(httpRequest);

                    if (response != null)
                    {
                        string result = await response.Content.ReadAsStringAsync();

                        logger.Info(AppConst.A("SendSMS_QCAsync", url, user, password, sender, sms, listPhone, date, time, result));
                        return(String.IsNullOrEmpty(result) ? String.Empty : result.Trim());
                    }
                }
            }
        }
        catch (Exception ex)
        {
            logger.Error(AppConst.A("SendSMS_QCAsync", this.Url, user, password, sender, sms, listPhone, date, time, ex));
        }

        return(String.Empty);
    }
Exemple #4
0
 private void OracleListenerCallback(object sender, OracleNotificationEventArgs events)
 {
     logger.Info(AppConst.A("OracleListenerCallback Event", events.Info.ToString()));
     if (events.Info == OracleNotificationInfo.Insert || events.Info == OracleNotificationInfo.Update)
     {
         PushSMSToQueue();
     }
 }
Exemple #5
0
        public async Task <IDictionary <string, object> > SendSMS_QCAsync(string url, string auth, string sender, string msg, string[] listPhone, string sentDate)
        {
            IDictionary <string, object> resultData = new Dictionary <string, object>();

            resultData.Add(AppConst.ERR_CODE, AppConst.SYS_MSG_EXCEPTION);
            resultData.Add(AppConst.ERR_CODE_PARTNER, String.Empty);
            resultData.Add(AppConst.RECEIVE_RESULT, AppConst.SYS_MSG_EXCEPTION);

            try
            {
                IDictionary <string, object> smsQC = new Dictionary <string, object>()
                {
                    { "Sender", sender },
                    { "Msg", msg },
                    { "ListPhone", listPhone },
                    { "SentDate", sentDate }
                };

                HttpResponseMessage response = await CallAPIAsync(url, auth, JsonConvert.SerializeObject(smsQC));

                if (response != null)
                {
                    string message = await response.Content.ReadAsStringAsync();

                    // {"Status":"1","Code":null,"Description":null,"CampaignId":"4609afe7-e80c-4b55-905a-1f3b3d4f6ddd"}
                    logger.Info(AppConst.A("SendSMS_QCAsync", url, auth, sender, msg, message));

                    if (!String.IsNullOrEmpty(message))
                    {
                        SouthReceiveQCModel southReceiveQC = JsonConvert.DeserializeObject <SouthReceiveQCModel>(message);

                        if (southReceiveQC.Status.Equals("1"))
                        {
                            resultData[AppConst.ERR_CODE]         = AppConst.SYS_ERR_OK;
                            resultData[AppConst.ERR_CODE_PARTNER] = southReceiveQC.Status;
                            resultData[AppConst.RECEIVE_RESULT]   = southReceiveQC.CampaignId;
                        }
                        else if (!southReceiveQC.Status.Equals("0"))
                        {
                            resultData[AppConst.ERR_CODE]         = AppConst.SYS_ERR_UNKNOW;
                            resultData[AppConst.ERR_CODE_PARTNER] = southReceiveQC.Status;
                            resultData[AppConst.RECEIVE_RESULT]   = message;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(AppConst.A("SendSMS_QCAsync", url, auth, sender, msg, sentDate, ex));
                resultData[AppConst.ERR_CODE]         = AppConst.SYS_MSG_EXCEPTION;
                resultData[AppConst.ERR_CODE_PARTNER] = String.Empty;
                resultData[AppConst.RECEIVE_RESULT]   = AppConst.SYS_MSG_EXCEPTION;
            }

            return(resultData);
        }
        /// <summary>
        /// Initialize new Worker
        /// </summary>
        private void StartWorker()
        {
            RabbitHelper rabbitWorker = new RabbitHelper();

            rabbitWorker.Initialize();
            rabbitWorker.Worker        = this.Worker++;
            rabbitWorker.ReceiveEvent += ReceivedHandlerCallback;
            rabbitWorker.ReceiveMessage(AppConfig.PARTNER_QUEUE);
            this.listRabbitWorker.Add(rabbitWorker);
            logger.Info(AppConst.A("StartWorker", rabbitWorker.Worker, AppConfig.PARTNER_QUEUE, "Started listener!"));
        }
Exemple #7
0
        protected override void OnStart(string[] args)
        {
            try
            {
                this.cancelToken = new CancellationTokenSource();

                this.rabbitHelper.Initialize();
                this.rabbitHelper.ReceiveEvent += ReceivedHandlerCallback;
                this.rabbitHelper.ReceiveMessage(AppConfig.QUEUE_ERROR);
                logger.Info(AppConst.A("OnStart", "Started listener!"));
            }
            catch (Exception ex)
            {
                logger.Error("OnStart", ex);
            }
        }
Exemple #8
0
 private async Task <HttpResponseMessage> CallAPIAsync(string url, string content)
 {
     try
     {
         using (HttpClient http = new HttpClient())
         {
             HttpRequestMessage httpRequest = new HttpRequestMessage(HttpMethod.Post, url);
             httpRequest.Content = new StringContent(content, Encoding.UTF8, "application/json");
             return(await http.SendAsync(httpRequest));
         }
     }
     catch (Exception ex)
     {
         logger.Error(AppConst.A("CallAPIAsync", url, content, ex));
         return(null);
     }
 }
Exemple #9
0
        private async void ReceivedHandlerCallback(string message, int task)
        {
            try
            {
                logger.Info(AppConst.A("ReceivedHandlerCallback Deliver", message));

                if (!String.IsNullOrEmpty(message))
                {
                    SmsModel sms = JsonConvert.DeserializeObject <SmsModel>(message);
                    await(new SmsRepository()).UpdateSMSErrorAsync(sms);
                }
            }
            catch (Exception ex)
            {
                logger.Error(AppConst.A("ReceivedHandlerCallback", ex));
            }
        }
Exemple #10
0
        public static async Task <int> SendSMS_APIAsync(string url, string username, string password, string requestId, string senderName, string phone, string message, string sentTime)
        {
            try
            {
                IDictionary <string, object> sms = new Dictionary <string, object>()
                {
                    { "reqid", requestId },
                    { "username", username },
                    { "password", password },
                    { "brandname", senderName },
                    { "textmsg", message },
                    { "sendtime", sentTime },
                    { "isunicode", 0 },
                    { "listmsisdn", phone }
                };

                using (HttpClient http = new HttpClient())
                {
                    HttpRequestMessage httpRequest = new HttpRequestMessage(HttpMethod.Post, url);
                    string             body        = JsonConvert.SerializeObject(sms);
                    logger.Info(AppConst.A("SendSMS_APIAsync", body));
                    httpRequest.Content = new StringContent(body, Encoding.UTF8, "application/json");
                    HttpResponseMessage response = await http.SendAsync(httpRequest);

                    if (response != null)
                    {
                        string result = await response.Content.ReadAsStringAsync();

                        logger.Info(AppConst.A("SendSMS_APIAsync", url, result));

                        Dictionary <string, dynamic> dict = CommonUtil.ConvertJsonToObject(result);
                        if (dict != null)
                        {
                            return(Convert.ToInt32(dict["code"]));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(AppConst.A("SendSMS_APIAsync", url, username, password, requestId, senderName, phone, message, sentTime, ex));
            }

            return(AppConst.SYS_ERR_UNKNOW);
        }
Exemple #11
0
        public async Task <int> SendSMSAsync(string url, string user, string password, string phone, string message, string tranId, string brandName, string dataEncode, string sendTime)
        {
            string result = String.Empty;

            try
            {
                IDictionary <string, string> smsCSKH = new Dictionary <string, string>()
                {
                    { "phone", phone },
                    { "mess", message },
                    { "user", user },
                    { "pass", password },
                    { "tranId", tranId },
                    { "brandName", brandName },
                    { "dataEncode", dataEncode },
                    { "sendTime", sendTime }
                };

                HttpResponseMessage response = await CallAPIAsync(url, JsonConvert.SerializeObject(smsCSKH));

                if (response != null)
                {
                    result = await response.Content.ReadAsStringAsync();

                    logger.Info(AppConst.A("SendSMS_CSKHAsync", url, tranId, result));

                    Dictionary <string, dynamic> dict = CommonUtil.ConvertJsonToObject(result);
                    if (dict != null && "1".Equals(dict["code"]))
                    {
                        return(AppConst.SYS_ERR_OK);
                    }
                    else if (dict != null && !"0".Equals(dict["code"]))
                    {
                        return(Convert.ToInt32(dict["code"]));
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(AppConst.A("SendSMS_CSKHAsync", url, tranId, result, ex));
            }

            return(AppConst.SYS_ERR_UNKNOW);
        }
Exemple #12
0
 private async Task <HttpResponseMessage> CallAPIAsync(string url, string auth, string content)
 {
     try
     {
         using (HttpClient http = new HttpClient())
         {
             HttpRequestMessage httpRequest = new HttpRequestMessage(HttpMethod.Post, url);
             httpRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
             httpRequest.Headers.Authorization = new AuthenticationHeaderValue("Basic", auth);
             httpRequest.Content = new StringContent(content, Encoding.UTF8, "application/json");
             return(await http.SendAsync(httpRequest));
         }
     }
     catch (Exception ex)
     {
         logger.Error(AppConst.A("CallAPIAsync", url, auth, content, ex));
         return(null);
     }
 }
        /// <summary>
        /// Run and limit tasks concurrency
        /// </summary>
        /// <param name="listSms"></param>
        /// <param name="maxConcurrency"></param>
        /// <param name="worker"></param>
        private async Task ProcessSMS_CSKH(IList <SmsModel> listSms, int maxConcurrency = 1, int worker = 0)
        {
            using (SemaphoreSlim semaphore = new SemaphoreSlim(maxConcurrency))
            {
                List <Task> tasks = new List <Task>();

                foreach (var sms in listSms)
                {
                    await semaphore.WaitAsync();

                    Task task = Task.Run(() =>
                    {
                        try
                        {
                            if (sms.SENDBY.Equals(AppConst.API))
                            {
                                SendHelper.SendSMS_API_CSKH(this.listRabbitWorker[worker], sms);
                            }
                            else if (sms.SENDBY.Equals(AppConst.SMPP))
                            {
                                SendHelper.SendSMS_SMPP(this.listRabbitWorker[worker], sms);
                            }
                            else
                            {
                                sms.ERR_CODE       = AppConst.SYS_ERR_EXCEPTION;
                                sms.RECEIVE_RESULT = "SMS Anonymous!";
                                this.listRabbitWorker[worker].PublishMessage(AppConfig.QUEUE_ERROR, JsonConvert.SerializeObject(sms));
                                logger.Error(AppConst.A("ProcessSMS", sms.ID, sms.RECEIVE_RESULT));
                            }
                        }
                        finally
                        {
                            semaphore.Release();
                        }
                    });

                    tasks.Add(task);
                }

                await Task.WhenAll(tasks);
            }
        }
Exemple #14
0
        public async Task <int> SendSMS_CSKHAsync(string url, string auth, string tranId, string from, string to, string text)
        {
            string result = String.Empty;

            try
            {
                IDictionary <string, string> smsCSKH = new Dictionary <string, string>()
                {
                    { "tranId", tranId },
                    { "from", from },
                    { "to", to },
                    { "text", text },
                    { "dlr", "1" }
                };

                HttpResponseMessage response = await CallAPIAsync(url, auth, JsonConvert.SerializeObject(smsCSKH));

                if (response != null)
                {
                    result = await response.Content.ReadAsStringAsync();

                    logger.Info(AppConst.A("SendSMS_CSKHAsync", url, auth, tranId, from, to, text, result));

                    Dictionary <string, dynamic> dict = CommonUtil.ConvertJsonToObject(result);
                    if (dict != null && "1".Equals(dict["Status"]))
                    {
                        return(AppConst.SYS_ERR_OK);
                    }
                    else if (dict != null && !"0".Equals(dict["Status"]))
                    {
                        return(Convert.ToInt32(dict["Status"]));
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(AppConst.A("SendSMS_CSKHAsync", url, auth, tranId, from, to, text, result, ex));
            }

            return(AppConst.SYS_ERR_UNKNOW);
        }
Exemple #15
0
        public async Task <IList <SmsBirthdayModel> > GetSmsBirthdayWaiting()
        {
            try
            {
                IDictionary <string, object> result = await(new DatabaseHelper()).GetSmsBirthdayCustomerAsync("pks_sms_birthday.pr_get_sms_birthday_wait");
                int v_ErrCode = Convert.ToInt32(result[AppConst.ERR_CODE]);
                if (v_ErrCode == AppConst.SYS_ERR_OK)
                {
                    string json = JsonConvert.SerializeObject(result[AppConst.DATA], Formatting.Indented);
                    IList <SmsBirthdayModel> smsList = JsonConvert.DeserializeObject <IList <SmsBirthdayModel> >(json);
                    logger.Info(AppConst.A("GetSmsBirthdayWaiting", json));
                    return(smsList);
                }
            }
            catch (Exception ex)
            {
                logger.Error("GetSmsBirthdayWaiting", ex);
            }

            return(null);
        }
        /// <summary>
        /// Event listener receive message from queue
        /// </summary>
        /// <param name="message">message receive</param>
        /// <param name="worker">worker receive</param>
        private void ReceivedHandlerCallback(string message, int worker)
        {
            try
            {
                logger.Info(AppConst.A("ReceivedHandlerCallback Deliver", worker, message));

                if (!String.IsNullOrEmpty(message))
                {
                    IList <SmsModel> listSms = JsonConvert.DeserializeObject <IList <SmsModel> >(message);
                    if (listSms[0].SMS_TYPE.Equals(AppConst.CSKH))
                    {
                        ProcessSMS_CSKH(listSms, AppConfig.WORKER_TASK_COUNT, worker).Wait();
                    }
                    else
                    {
                        SendHelper.SendSMS_API_QC(this.listRabbitWorker[worker], listSms);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(AppConst.A("ReceivedHandlerCallback", ex));
            }
        }
Exemple #17
0
    /// <summary>
    /// Gửi tin CSKH
    /// Url: https://cloudsms.vietguys.biz:4438/api/index.php
    /// </summary>
    /// <param name="username"></param>
    /// <param name="password"></param>
    /// <param name="sender"></param>
    /// <param name="phone"></param>
    /// <param name="sms"></param>
    /// <returns></returns>
    public async Task <int> SendSMS_CSKHAsync(string username, string password, string sender, string phone, string sms)
    {
        try
        {
            WebRequest webRequest = WebRequest.Create(string.Format(@"{0}?u={1}&pwd={2}&from={3}&phone={4}&sms={5}&bid=1&type=&json=", this.Url, username, password, sender, phone, sms));

            using (StreamReader reader = new StreamReader(webRequest.GetResponse().GetResponseStream()))
            {
                string result = await reader.ReadToEndAsync();

                logger.Info(AppConst.A("SendSMS_QCAsync", this.Url, username, password, sender, sms, phone, result));
                if (!String.IsNullOrEmpty(result))
                {
                    return(Convert.ToInt32(result));
                }
            }
        }
        catch
        {
            return(-86);
        }

        return(-86);
    }
Exemple #18
0
        private async void BtnStartPhoneChangeTelco_Click(object sender, EventArgs e)
        {
            try
            {
                this.IsStop                      = false;
                txtJSESSIONID.Enabled            = false;
                txtTS0165a601.Enabled            = false;
                txtTS017dff08.Enabled            = false;
                txtUrlData.Enabled               = false;
                chkEdu.Enabled                   = false;
                chkGateway.Enabled               = false;
                chkRedis.Enabled                 = false;
                btnStopPhoneChangeTelco.Enabled  = true;
                btnStartPhoneChangeTelco.Enabled = false;
                txtEndFile.Enabled               = false;
                txtStartFile.Enabled             = false;
                txtRange.Enabled                 = false;
                txtInterval.Enabled              = false;

                string JSESSIONID = txtJSESSIONID.Text;
                string TS0165a601 = txtTS0165a601.Text;
                string TS017dff08 = txtTS017dff08.Text;
                File.WriteAllText(this.pathLogSession, JSESSIONID + Environment.NewLine + TS0165a601 + Environment.NewLine + TS017dff08);

                int startFile = Convert.ToInt32(txtStartFile.Text);
                int endFile   = Convert.ToInt32(txtEndFile.Text);
                int interval  = Convert.ToInt32(txtInterval.Text);
                int range     = Convert.ToInt32(txtRange.Text);

                this.cancelToken = new CancellationTokenSource();

                while (!this.IsStop)
                {
                    IDictionary <String, PhoneChangeTelcoModel> dictPhoneChangeTelco = new Dictionary <String, PhoneChangeTelcoModel>();

                    await Task.Run(async() =>
                    {
                        SetTextMonitor("Start stream file " + startFile + " to " + endFile, Color.Green);

                        for (int i = startFile; i <= endFile; i++)
                        {
                            try
                            {
                                logger.Info("Start stream file " + i);

                                HttpWebRequest request = WebRequest.CreateHttp(txtUrlData.Text + i);
                                request.Headers.Add("Accept-Encoding", "gzip, deflate");
                                request.Headers.Add("Accept-Language", "en,vi-VN;q=0.8,vi;q=0.5,en-US;q=0.3");
                                request.Headers.Add("Cookie", String.Format(@"f5_cspm=1234; JSESSIONID={0}; TS017dff08={1}; TS0165a601={2}", txtJSESSIONID.Text, txtTS017dff08.Text, txtTS0165a601.Text));
                                request.Headers.Add("Upgrade-Insecure-Requests", "1");
                                request.Timeout = 20000;

                                using (StreamReader stream = new StreamReader(request.GetResponse().GetResponseStream()))
                                {
                                    while (!stream.EndOfStream)
                                    {
                                        string strLineValue = stream.ReadLine();

                                        if (strLineValue.Contains("<html>") || strLineValue.Contains("Expires"))
                                        {
                                            logger.Error(AppConst.A("BtnStartPhoneChangeTelco_Click", "Session expired, please retry login!"));
                                            SetTextMonitor(AppConst.A("BtnStartPhoneChangeTelco_Click", "Session expired, please retry login!"), Color.Red);
                                            ResetComponents();
                                            this.IsStop = true;
                                            return;
                                        }

                                        if (!String.IsNullOrEmpty(strLineValue))
                                        {
                                            if (strLineValue.Contains("<html>") || strLineValue.Contains("Expires"))
                                            {
                                                logger.Error(AppConst.A("BtnStartPhoneChangeTelco_Click", i, "Session expired, please retry login!"));
                                                SetTextMonitor(AppConst.A("BtnStartPhoneChangeTelco_Click", i, "Session expired, please retry login!"), Color.Red);
                                                break;
                                            }

                                            logger.Info(i + "," + strLineValue);

                                            if (strLineValue.Contains("MOBILE,"))
                                            {
                                                List <string> lstValue = strLineValue.Split(',').ToList();

                                                if (lstValue.Count > 5 && lstValue[2] != null && lstValue[3].Contains("84") && AppConfig.ListTelco.Contains(lstValue[4].Trim()))
                                                {
                                                    PhoneChangeTelcoModel phoneChangeTelco = new PhoneChangeTelcoModel()
                                                    {
                                                        ID_PROCESS = i.ToString(),
                                                        PHONE      = lstValue[3],
                                                        TELCO      = lstValue[4]
                                                    };

                                                    if (dictPhoneChangeTelco.ContainsKey(phoneChangeTelco.PHONE))
                                                    {
                                                        dictPhoneChangeTelco[phoneChangeTelco.PHONE] = phoneChangeTelco;
                                                    }
                                                    else
                                                    {
                                                        dictPhoneChangeTelco.Add(phoneChangeTelco.PHONE, phoneChangeTelco);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

                                if (this.IsStop)
                                {
                                    break;
                                }
                            }
                            catch (IOException ex)
                            {
                                logger.Error(AppConst.A("ScanFileOnline Error", i, ex));
                                COUNT_RETRY++;
                                await Task.Delay(3000);
                                if (COUNT_RETRY > 5)
                                {
                                    logger.Error(AppConst.A("ScanFileOnline", i, "Lỗi quá 5 lần rồi!"));
                                    SetTextMonitor(AppConst.A("ScanFileOnline", i, "Lỗi quá 5 lần rồi!"), Color.Red);
                                    break;
                                }
                                else
                                {
                                    i = i - 1;
                                    logger.Info(AppConst.A("ScanFileOnline", "Retry stream file", i, COUNT_RETRY));
                                    SetTextMonitor(AppConst.A("ScanFileOnline", "Retry stream file", i, COUNT_RETRY), Color.Red);
                                }
                            }
                            catch (ArgumentOutOfRangeException ex)
                            {
                                logger.Info(AppConst.A("ScanFileOnline Error", i, ex.ToString()));
                                SetTextMonitor(AppConst.A("ScanFileOnline Error", i, ex.ToString()), Color.Red);
                            }
                            catch (Exception ex)
                            {
                                logger.Error(AppConst.A("ScanFileOnline Error", i, ex));
                                SetTextMonitor(AppConst.A("ScanFileOnline Error", i, ex), Color.Red);
                            }
                        }
                    }, this.cancelToken.Token);

                    string idProcess = String.Empty;
                    SetTextMonitor("Total records: " + dictPhoneChangeTelco.Count, Color.Green);
                    if (dictPhoneChangeTelco.Count > 0)
                    {
                        idProcess = dictPhoneChangeTelco.Values.Last().ID_PROCESS;
                        File.WriteAllText(this.pathLogSession, JSESSIONID + Environment.NewLine + TS0165a601 + Environment.NewLine + TS017dff08 + Environment.NewLine + idProcess);

                        SetTextMonitor("Starting update !!!", Color.Green);
                        if (chkGateway.Checked)
                        {
                            _ = Task.Run(() => (new PhoneChangeTelcoRepository()).UpdateGateway(dictPhoneChangeTelco)).ContinueWith(t => SetTextMonitor("Update to database Gateway success", Color.Green), cancelToken.Token);
                        }
                        if (chkEdu.Checked)
                        {
                            _ = Task.Run(() => (new PhoneChangeTelcoRepository()).UpdateEdu(dictPhoneChangeTelco)).ContinueWith(t => SetTextMonitor("Update to database Edu success", Color.Green), cancelToken.Token);
                        }
                        if (chkRedis.Checked)
                        {
                            _ = Task.Run(() => (new PhoneChangeTelcoRepository()).UpdateRedis(dictPhoneChangeTelco)).ContinueWith(t => SetTextMonitor("Update to database Redis success", Color.Green), cancelToken.Token);
                        }
                    }

                    startFile = String.IsNullOrEmpty(idProcess) ? startFile : Convert.ToInt32(idProcess);
                    endFile   = startFile + range;

                    await Task.Delay(interval);

                    SetTextbox(startFile.ToString(), endFile.ToString());
                }
            }
            catch (Exception ex)
            {
                SetTextMonitor(ex.ToString(), Color.Red);
                logger.Error("BtnStartPhoneChangeTelco_Click.: " + ex);
                this.IsStop = true;
                ResetComponents();
            }
        }
Exemple #19
0
        protected override void OnStart(string[] args)
        {
            logger.Info(AppConst.A("OnStart", "Start service SMSBirthday"));
            IList <CustomerModel> listSms = (new CustomerRepository()).GetSmsBirthdayCustomerAsync().Result;

            logger.Info(AppConst.A("GetListCustomer", listSms.Count));
            IList <SysVarModel> listKey = (new SysVarRepository()).GetKeyWorkCSKH().Result;

            if (listSms.Count > 0)
            {
                for (int i = 0; i < listSms.Count; i++)
                {
                    String content = listSms[i].SMS_SEND;
                    content = CommonUtil.chuyenTiengVietKhongDau(content);
                    String phone = listSms[i].PHONE;
                    phone = CommonUtil.AddPhone84(phone);
                    string telco = CommonUtil.getLoaiNhaMang(phone);
                    int    count = CommonUtil.countNumberSms(content);

                    #region check keyword
                    SysVarModel sysVarModel  = listKey.FirstOrDefault(sysVar => sysVar.VAR_NAME == telco);
                    var         checkKeyword = 0;
                    if (sysVarModel != null)
                    {
                        var arrKey = sysVarModel.VAR_VALUE.Split(';');
                        foreach (var key in arrKey)
                        {
                            var key_compare     = key.ToLower();
                            var content_compare = content.ToLower();
                            if (key_compare != "" && key_compare != null && content.Contains(key_compare))
                            {
                                checkKeyword++;
                            }
                        }
                    }
                    #endregion

                    if (checkKeyword == 0 && !string.IsNullOrEmpty(telco) && !string.IsNullOrEmpty(content))
                    {
                        SmsBirthdayModel detail = new SmsBirthdayModel();
                        detail.ACCOUNT_ID    = listSms[i].ACCOUNT_ID;
                        detail.SENDER_NAME   = listSms[i].SENDER_NAME;
                        detail.SMS_CONTENT   = content;
                        detail.SMS_COUNT     = count;
                        detail.PHONE         = phone;
                        detail.TELCO         = telco;
                        detail.SCHEDULE_TIME = DateTime.Now.Year + "" + listSms[i].MONTH_SEND + "" + listSms[i].DAY_SEND + "" + listSms[i].HOUR_SEND;
                        detail.GROUP_ID      = listSms[i].GROUP_ID;
                        (new SmsBirthdayRepository()).InsertSmsBirthday(detail).Wait();
                        logger.Info(AppConst.A("InsertSmsBirthday", phone, content, DateTime.Now.Year + "" + listSms[i].MONTH_SEND + "" + listSms[i].DAY_SEND));
                    }
                }
            }

            IList <SmsBirthdayModel> listSmsWaiting = (new SmsBirthdayRepository()).GetSmsBirthdayWaiting().Result;
            for (int i = 0; i < listSmsWaiting.Count; i++)
            {
                String content = listSmsWaiting[i].SMS_CONTENT;
                content = CommonUtil.chuyenTiengVietKhongDau(content);
                String phone = listSmsWaiting[i].PHONE;
                phone = CommonUtil.AddPhone84(phone);
                string telco = CommonUtil.getLoaiNhaMang(phone);
                int    count = CommonUtil.countNumberSms(content);

                if (!string.IsNullOrEmpty(listSmsWaiting[i].GROUP_ID.ToString()))
                {
                    SmsModel sms = new SmsModel();
                    sms.ACCOUNT_ID    = listSmsWaiting[i].ACCOUNT_ID;
                    sms.SENDER_NAME   = listSmsWaiting[i].SENDER_NAME;
                    sms.PARTNER_NAME  = listSmsWaiting[i].PARTNER_NAME;
                    sms.SMS_CONTENT   = content;
                    sms.SMS_TYPE      = "CSKH";
                    sms.PHONE         = phone;
                    sms.SMS_COUNT     = count;
                    sms.TELCO         = telco;
                    sms.SCHEDULE_TIME = listSmsWaiting[i].SCHEDULE_TIME;
                    sms.VIA           = "SMS_BIRTHDAY";
                    (new SmsRepository()).InsertSmsBirthday(sms).Wait();
                    logger.Info(AppConst.A("InsertSms", listSmsWaiting[i].SENDER_NAME, phone, content, listSmsWaiting[i].SCHEDULE_TIME));
                }
            }
        }
Exemple #20
0
 protected override void OnStop()
 {
     logger.Info(AppConst.A("OnStop", "Stop service SMSBirthday"));
 }