public HttpResponseMessage ConfirmBulk(BulkSmsModel bulkInfo)
        {
            var principal = Thread.CurrentPrincipal;

            if (!principal.Identity.IsAuthenticated)
            {
                throw new BusinessException(HttpStatusCode.Accepted, ErrorCode.AccountIsInvalid, Language.GetString("AccountIsInvalid"));
            }

            User userInfo = ((MyPrincipal)principal).UserDetails;

            if (!SecurityManager.HasServicePermission(userInfo.UserGuid, (int)Business.Services.GetBulkMessagesFromAPI))
            {
                throw new BusinessException(HttpStatusCode.Accepted, ErrorCode.AccessDenied, Language.GetString("AccessDenied"));
            }

            if (bulkInfo.Id == 0)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            if (!ManageQueue.SendMessage(Queues.ConfirmBulk, bulkInfo, bulkInfo.Id.ToString()))
            {
                throw new BusinessException(HttpStatusCode.Accepted, ErrorCode.InternalServerError, Language.GetString("InternalServerError"));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Beispiel #2
0
        static async Task SendToQueue()
        {
            var manager = new ManagementClient(connStr);

            if (!await manager.QueueExistsAsync(queueName))
            {
                var queueManager = new ManageQueue(connStr, queueName);
                await queueManager.CreateQueue();
            }

            IQueueClient queueClient = new QueueClient(connStr, queueName);

            try
            {
                for (int count = 0; count < 10; count++)
                {
                    var messageBody = "Message " + (count + 1);
                    var message     = new Message(Encoding.UTF8.GetBytes(messageBody));
                    Console.WriteLine("Sending Message: " + messageBody);
                    await queueClient.SendAsync(message);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Something wrong happened: " + ex.Message);
            }
            finally
            {
                await queueClient.CloseAsync();
            }
        }
        //[IPAuthentication]
        public HttpResponseMessage SendReport(HttpRequestMessage request)
        {
            string strIncomingMessage = string.Empty;

            StreamReader MyStreamReader = new StreamReader(request.Content.ReadAsStreamAsync().Result);

            strIncomingMessage = MyStreamReader.ReadToEnd();

            dynamic         result      = JValue.Parse(strIncomingMessage);
            dynamic         reportTasks = JArray.Parse(result.rpts.ToString()) as JArray;
            dynamic         failedReportTask;
            dynamic         successReportTask;
            DeliveryMessage deliveryMessage = new DeliveryMessage();

            deliveryMessage.FailedMobile  = new List <string>();
            deliveryMessage.SuccessMobile = new List <string>();

            LogController <ServiceLogs> .LogInFile(ServiceLogs.WebAPI, string.Format("strIncomingMessage : {0}", strIncomingMessage));

            deliveryMessage.Agent = (int)SmsSenderAgentReference.GSMGateway;

            LogController <ServiceLogs> .LogInFile(ServiceLogs.WebAPI, string.Format("reportTasks[0].failed : {0}", reportTasks[0].failed));

            if (Helper.GetInt(reportTasks[0].failed) > 0)
            {
                LogController <ServiceLogs> .LogInFile(ServiceLogs.WebAPI, string.Format("reportTasks[0].failed is > 0"));

                failedReportTask = JArray.Parse(reportTasks[0].fdr.ToString()) as JArray;
                LogController <ServiceLogs> .LogInFile(ServiceLogs.WebAPI, string.Format("failedReportTask : {0}", failedReportTask));

                foreach (dynamic failedTask in failedReportTask)
                {
                    LogController <ServiceLogs> .LogInFile(ServiceLogs.WebAPI, string.Format("failedTask[1] : {0}", failedTask[1].ToString()));

                    deliveryMessage.FailedMobile.Add(Helper.GetLocalMobileNumber(failedTask[1].ToString()));
                }
            }

            LogController <ServiceLogs> .LogInFile(ServiceLogs.WebAPI, string.Format("reportTasks[0].sent : {0}", reportTasks[0].sent));

            if (Helper.GetInt(reportTasks[0].sent) > 0)
            {
                successReportTask = JArray.Parse(reportTasks[0].sdr.ToString()) as JArray;
                LogController <ServiceLogs> .LogInFile(ServiceLogs.WebAPI, string.Format("successReportTask : {0}", successReportTask));

                foreach (dynamic successTask in successReportTask)
                {
                    LogController <ServiceLogs> .LogInFile(ServiceLogs.WebAPI, string.Format("successTask[1] : {0}", successTask[1].ToString()));

                    deliveryMessage.SuccessMobile.Add(Helper.GetLocalMobileNumber(successTask[1].ToString()));
                }
            }

            LogController <ServiceLogs> .LogInFile(ServiceLogs.WebAPI, string.Format("batchid : {0}", reportTasks[0].tid.ToString()));

            deliveryMessage.BatchId = reportTasks[0].tid.ToString();

            ManageQueue.SendMessage(Queues.SaveGsmDelivery, deliveryMessage, string.Format("Agent:{0}=>SuccessMobile:{1}-FailedMobile:{2}-BatchId:{3}", deliveryMessage.Agent, deliveryMessage.SuccessMobile.Count, deliveryMessage.FailedMobile.Count, deliveryMessage.BatchId));
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Beispiel #4
0
        private void InsertSentMessages(BatchMessage batch)
        {
            try
            {
                if (Arad.SMS.Gateway.Facade.OutboxNumber.InsertSentMessages(batch))
                {
                    ReceiveMessageFromQueue(batch);
                }

                if (batch.Receivers.Count > 0)
                {
                    ManageQueue.SendMessage(batch.QueueName, batch, string.Format("{0}-{1}", batch.Id, batch.PageNo));
                }
            }
            catch (Exception ex)
            {
                LogController <ServiceLogs> .LogInFile(ServiceLogs.SaveSentMessage, string.Format("\r\n-------------------------------------------------------------------------"));

                LogController <ServiceLogs> .LogInFile(ServiceLogs.SaveSentMessage, string.Format("\r\n SaveSentMessage : {0}", ex.ToString()));

                LogController <ServiceLogs> .LogInFile(ServiceLogs.SaveSentMessage, string.Format("\r\n SaveSentMessage : {0}", ex.StackTrace));

                LogController <ServiceLogs> .LogInFile(ServiceLogs.SaveSentMessage, string.Format("\r\n-------------------------------------------------------------------------"));
            }
        }
        public HttpResponseMessage ReceiveSms(string destAddress, string srcAddress, string msgBody)
        {
            ReceiveMessage receiveMessage = new ReceiveMessage();

            receiveMessage.Sender          = srcAddress;
            receiveMessage.Receiver        = Helper.GetLocalPrivateNumber(destAddress);
            receiveMessage.SmsText         = HttpUtility.UrlDecode(Helper.PersianNumberToEnglish(msgBody));
            receiveMessage.ReceiveDateTime = DateTime.Now;
            receiveMessage.UDH             = string.Empty;

            ManageQueue.SendMessage(Queues.ReceiveMessagesQueue, receiveMessage, string.Format("{0}=>{1}", receiveMessage.Sender, receiveMessage.Receiver));
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
        public HttpResponseMessage ReceiveMessage([FromUri] GetReceiveSmsModel receive)
        {
            ReceiveMessage receiveMessage = new ReceiveMessage();

            receiveMessage.Sender          = receive.From;
            receiveMessage.Receiver        = Helper.GetLocalPrivateNumber(receive.To);
            receiveMessage.SmsText         = Helper.PersianNumberToEnglish(receive.Text);
            receiveMessage.ReceiveDateTime = DateTime.Now;
            receiveMessage.UDH             = receive.UDH;

            ManageQueue.SendMessage(Queues.ReceiveMessagesQueue, receiveMessage, string.Format("{0}=>{1}", receiveMessage.Sender, receiveMessage.Receiver));
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
        private void InsertDelivery()
        {
            List <int> deliveryStayInQueue = new List <int>();

            deliveryStayInQueue.Add((int)DeliveryStatus.SentToItc);
            deliveryStayInQueue.Add((int)DeliveryStatus.ReceivedByItc);
            deliveryStayInQueue.Add((int)DeliveryStatus.Sent);

            foreach (BatchMessage batch in batchMessageList)
            {
                foreach (InProgressSms sms in batch.Receivers)
                {
                    if (!sms.SaveDelivery)
                    {
                        continue;
                    }

                    deliveryMessage = new DeliveryMessage();

                    deliveryMessage.Agent    = (int)batch.SmsSenderAgentReference;
                    deliveryMessage.BatchId  = sms.ReturnID;
                    deliveryMessage.ReturnId = sms.ReturnID;
                    deliveryMessage.Mobile   = sms.RecipientNumber;
                    deliveryMessage.Status   = (int)sms.DeliveryStatus;
                    deliveryMessage.Date     = DateTime.Now.Date;
                    deliveryMessage.Time     = DateTime.Now.TimeOfDay;

                    ManageQueue.SendMessage(saveDeliveryQueue, deliveryMessage, string.Format("Agent:{0}=>Mobile:{1}-ReturnId:{2}-Status:{3}", deliveryMessage.Agent, deliveryMessage.Mobile, deliveryMessage.ReturnId, deliveryMessage.Status));
                }

                batch.Receivers.RemoveAll(sms => sms.SaveDelivery && (sms.DeliveryTryCount > 5 || !deliveryStayInQueue.Contains((int)sms.DeliveryStatus)));
            }

            foreach (BatchMessage batch in batchMessageList)
            {
                if (batch.Receivers.Count > 0)
                {
                    foreach (InProgressSms sms in batch.Receivers)
                    {
                        sms.SaveDelivery = false;
                    }

                    ManageQueue.SendMessage(queueName, batch, string.Format("Id:{0}-batchGuid:{1}=>SenderId:{2}-ReceiverCount:{3}", batch.Id, batch.Guid, batch.SenderNumber, batch.Receivers.Count));
                }

                ReceiveMessageFromQueue(batch.QueueMessageId);
            }
        }
        public HttpResponseMessage GetDelivery([FromUri] GetDeliverySmsModel delivery)
        {
            DeliveryMessage deliveryMessage = new DeliveryMessage();

            deliveryMessage.Agent    = delivery.Agent;
            deliveryMessage.BatchId  = delivery.ReturnId;
            deliveryMessage.ReturnId = delivery.ReturnId;
            deliveryMessage.CheckId  = delivery.CheckId;
            deliveryMessage.Mobile   = delivery.Mobile;
            deliveryMessage.Status   = GetDeliveryStatus(delivery.Agent, Helper.GetInt(delivery.Status));
            deliveryMessage.Date     = DateTime.Now;
            deliveryMessage.Time     = DateTime.Now.TimeOfDay;

            ManageQueue.SendMessage(Queues.SaveDelivery, deliveryMessage, string.Format("Agent:{0}=>Mobile:{1}-ReturnId:{2}-Status:{3}", delivery.Agent, delivery.Mobile, delivery.ReturnId, delivery.Status));
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Beispiel #9
0
        public bool UpdateGsmDeliveryStatus(DeliveryStatus status, List <string> mobiles, string batchId, DeliveryMessage deliveryMessage)
        {
            int msgstatus = 3;

            if (status == DeliveryStatus.SentAndReceivedbyPhone)
            {
                msgstatus = 1;
            }
            if (status == DeliveryStatus.NotSent)
            {
                msgstatus = 10;
            }

            try
            {
                string    mobile         = string.Empty;;
                DataTable dtSavedNumbers = FetchSPDataTable("UpdateGsmDeliveryStatus",
                                                            "@Status", (int)status,
                                                            "@Mobiles", string.Join(",", mobiles.Select(number => string.Format("'{0}'", number))),
                                                            "@ReturnId", batchId);
                foreach (DataRow row in dtSavedNumbers.Rows)
                {
                    mobile = row["Mobile"].ToString();

                    deliveryMessage.BatchId           = row["OutboxGuid"].ToString();
                    deliveryMessage.PrivateNumberGuid = Helper.GetGuid(row["PrivateNumberGuid"]);
                    deliveryMessage.UserGuid          = Helper.GetGuid(row["UserGuid"]);

                    deliveryMessage.Mobile = mobile;
                    deliveryMessage.Status = msgstatus;
                    ManageQueue.SendMessage(ManageQueue.Queues.DeliveryRelay.ToString(), deliveryMessage, string.Format("DeliveryRelay=> batchid={0},mobile={1},status={2}", batchId, mobile, msgstatus));

                    if (mobiles.Contains(mobile))
                    {
                        mobiles.Remove(mobile);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void SaveGsmDelivery(List <Message> messages)
        {
            try
            {
                DeliveryMessage deliveryMessage;
                foreach (Message msg in messages)
                {
                    deliveryMessage           = new DeliveryMessage();
                    msg.Formatter             = new BinaryMessageFormatter();
                    deliveryMessage           = (DeliveryMessage)msg.Body;
                    deliveryMessage.MessageId = msg.Id;

                    try
                    {
                        if (deliveryMessage.FailedMobile.Count > 0)
                        {
                            Arad.SMS.Gateway.Facade.OutboxNumber.UpdateGsmDeliveryStatus(DeliveryStatus.NotSent, deliveryMessage.FailedMobile, deliveryMessage.BatchId, deliveryMessage);
                        }
                        if (deliveryMessage.SuccessMobile.Count > 0)
                        {
                            Arad.SMS.Gateway.Facade.OutboxNumber.UpdateGsmDeliveryStatus(DeliveryStatus.SentAndReceivedbyPhone, deliveryMessage.SuccessMobile, deliveryMessage.BatchId, deliveryMessage);
                        }

                        if (deliveryMessage.FailedMobile.Count > 0 || deliveryMessage.SuccessMobile.Count > 0)
                        {
                            ManageQueue.SendMessage(queueName, deliveryMessage, string.Format("Agent:{0}=>SuccessMobile:{1}-FailedMobile:{2}-BatchId:{3}", deliveryMessage.Agent, deliveryMessage.SuccessMobile.Count, deliveryMessage.FailedMobile.Count, deliveryMessage.BatchId));
                        }

                        ReceiveMessageFromQueue(msg.Id);
                    }
                    catch (Exception ex)
                    {
                        LogController <ServiceLogs> .LogInFile(ServiceLogs.SaveDelivery, string.Format("On UpdateGsmDeliveryStatus Method : {0}*{1}", ex.Message, ex.StackTrace));
                    }
                }
            }
            catch (Exception ex)
            {
                LogController <ServiceLogs> .LogInFile(ServiceLogs.SaveGsmDelivery, string.Format("On SaveDeliveryStatus : {0}*{1}", ex.Message, ex.StackTrace));

                throw ex;
            }
        }
Beispiel #11
0
        private void InsertSentMessages()
        {
            string messageId;

            foreach (BatchMessage batch in batchMessageList)
            {
                messageId = ManageQueue.SendMessage(sentMessageQueue, batch, string.Format("{0}-{1}", batch.Id, batch.PageNo));
                ReceiveMessageFromQueue(batch);

                if (!isActiveDeliveryRelay)
                {
                    batch.Receivers.RemoveAll(sms => sms.DeliveryStatus != (int)DeliveryStatus.SentToItc);
                    if (batch.Receivers.Count > 0)
                    {
                        ManageQueue.SendMessage(getDeliveryQueue, batch, string.Format("batchId:{0}=>SenderId:{1}-ReceiverCount:{2}", batch.Id, batch.SenderNumber, batchMessage.Receivers.Count));
                    }
                }
            }
        }
        public HttpResponseMessage ReceiveMessage(HttpRequestMessage request)
        {
            string strIncomingMessage = string.Empty;

            StreamReader MyStreamReader = new StreamReader(request.Content.ReadAsStreamAsync().Result);

            strIncomingMessage = MyStreamReader.ReadToEnd();

            dynamic result      = JValue.Parse(strIncomingMessage);
            dynamic reportTasks = JArray.Parse(result.sms.ToString()) as JArray;

            foreach (dynamic receiveSms in reportTasks)
            {
                ReceiveMessage receiveMessage = new ReceiveMessage();
                receiveMessage.Sender          = receiveSms[3].ToString();
                receiveMessage.Receiver        = receiveSms[1].ToString();
                receiveMessage.SmsText         = Helper.Base64Decode(receiveSms[5].ToString());
                receiveMessage.ReceiveDateTime = DateTime.Now;
                receiveMessage.UDH             = "";

                ManageQueue.SendMessage(Queues.ReceiveMessagesQueue, receiveMessage, string.Format("{0}=>{1}", receiveMessage.Sender, receiveMessage.Receiver));
            }
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
        public HttpResponseMessage Send(PostSendVASMessageModel vas)
        {
            if (!ModelState.IsValid)
            {
                ResponseMessage rm = new ResponseMessage();
                rm.IsSuccessful = false;
                rm.StatusCode   = (int)ErrorCode.ValidationNotValid;
                foreach (ModelState modelState in ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        rm.Message += string.Format("{0}", error.ErrorMessage);
                    }
                }
                throw new BusinessException(HttpStatusCode.Accepted, ErrorCode.ValidationNotValid, rm.Message);
            }

            if (string.IsNullOrEmpty(vas.SenderId) || vas.PrivateNumberGuid == Guid.Empty)
            {
                throw new BusinessException(HttpStatusCode.Accepted, ErrorCode.ServiceIdIsInvalid, Language.GetString("ServiceIdIsInvalid"));
            }

            if (vas.ReferenceGuid == Guid.Empty)
            {
                throw new BusinessException(HttpStatusCode.Accepted, ErrorCode.ServiceIdIsInvalid, Language.GetString("ServiceIdIsInvalid"));
            }

            if (vas.InProgressSmsList.Count > 0)
            {
                if (Facade.PhoneBook.RecipientIsRegisteredToVasGroup(vas.GroupId, vas.Receiver) == Guid.Empty)
                {
                    throw new BusinessException(HttpStatusCode.Accepted, ErrorCode.ServiceIdIsInvalid, Language.GetString("ServiceIdIsInvalid"));
                }
            }

            if (vas.InProgressSmsList.Count == 0 && !string.IsNullOrEmpty(vas.Receiver))
            {
                throw new BusinessException(HttpStatusCode.Accepted, ErrorCode.ReceiversIsEmpty, Language.GetString("ReceiversIsEmpty"));
            }

            var principal = System.Threading.Thread.CurrentPrincipal;

            if (principal.Identity.IsAuthenticated)
            {
                Common.User userInfo = ((MyPrincipal)principal).UserDetails;

                BatchMessage batchMessage = new BatchMessage();
                batchMessage.UserGuid          = userInfo.UserGuid;
                batchMessage.Guid              = vas.BatchId;
                batchMessage.CheckId           = vas.CheckId.ToString();
                batchMessage.SmsText           = vas.SmsText;
                batchMessage.SmsLen            = vas.SmsLen;
                batchMessage.SenderNumber      = vas.SenderId;
                batchMessage.PrivateNumberGuid = vas.PrivateNumberGuid;
                batchMessage.ServiceId         = vas.ServiceId;
                batchMessage.Receivers         = vas.InProgressSmsList;
                batchMessage.IsUnicode         = vas.IsUnicode;
                batchMessage.ReferenceGuid     = new List <Guid>()
                {
                    vas.ReferenceGuid
                };
                batchMessage.SmsSendType = (int)Common.SmsSendType.SendSmsFromAPI;

                if (!ManageQueue.SendMessage(Queues.ApiSendMessage, batchMessage, batchMessage.SenderNumber))
                {
                    throw new BusinessException(HttpStatusCode.Accepted, ErrorCode.InternalServerError, Language.GetString("InternalServerError"));
                }

                SendSmsResponse sendsms = new SendSmsResponse();
                sendsms.IsSuccessful = true;
                sendsms.BatchId      = batchMessage.Guid;

                return(Request.CreateResponse <SendSmsResponse>(HttpStatusCode.Created, sendsms));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }
        }
Beispiel #14
0
        public static bool UpdateDeliveryStatus(List <DeliveryMessage> lstDelivery)
        {
            Business.OutboxNumber outboxNumberController = new Business.OutboxNumber();
            string          outerMessageIds     = string.Empty;
            string          numbers             = string.Empty;
            DataTable       dtDeliveryRelayInfo = new DataTable();
            DeliveryMessage deliveryMessage;

            try
            {
                LogController <ServiceLogs> .LogInFile(ServiceLogs.SaveDelivery, string.Join(Environment.NewLine, lstDelivery.Select(deliver => string.Format("agent:{0}, status:{1}, mobile:{2}, returnId:{3},batchid:{4}", deliver.Agent, deliver.Status, deliver.Mobile, deliver.ReturnId, deliver.BatchId))));

                var deliveryGroup = lstDelivery.Where(msg => msg.Agent != (int)SmsSenderAgentReference.RahyabRG &&
                                                      msg.Agent != (int)SmsSenderAgentReference.SLS)
                                    .GroupBy(msg => msg.Status).Select(grp => new { key = grp.Key, lstMessages = grp.ToList() }).ToList();
                foreach (var item in deliveryGroup)
                {
                    LogController <ServiceLogs> .LogInFile(ServiceLogs.SaveDelivery, string.Format("status:{0},returnIds:{1}", item.key, string.Join(",", item.lstMessages.Select(msg => string.Format("'{0}'", msg.ReturnId)))));

                    outerMessageIds     = string.Join(",", item.lstMessages.Select(msg => string.Format("'{0}'", msg.ReturnId)));
                    dtDeliveryRelayInfo = outboxNumberController.UpdateDeliveryStatus(outerMessageIds, item.key);
                    foreach (DataRow row in dtDeliveryRelayInfo.Rows)
                    {
                        deliveryMessage                   = new DeliveryMessage();
                        deliveryMessage.BatchId           = row["OutboxGuid"].ToString();
                        deliveryMessage.Mobile            = row["ToNumber"].ToString();
                        deliveryMessage.Status            = Helper.GetInt(row["DeliveryStatus"]);
                        deliveryMessage.PrivateNumberGuid = Helper.GetGuid(row["PrivateNumberGuid"]);
                        deliveryMessage.UserGuid          = Helper.GetGuid(row["UserGuid"]);

                        ///// New 8-3-2019
                        if (!string.IsNullOrEmpty(GetDeliveryURL(deliveryMessage.PrivateNumberGuid)))
                        {
                            ManageQueue.SendMessage(ManageQueue.Queues.DeliveryRelay.ToString(), deliveryMessage, string.Format("DeliveryRelay=> batchid={0},mobile={1},status={2}", deliveryMessage.BatchId, deliveryMessage.Mobile, deliveryMessage.Status));
                        }
                    }
                }

                var deliveryBatchGroup = lstDelivery.Where(msg => msg.Agent == (int)SmsSenderAgentReference.RahyabRG ||
                                                           msg.Agent == (int)SmsSenderAgentReference.SLS)
                                         .GroupBy(msg => new { msg.BatchId, msg.Status })
                                         .Select(grp => new { batchId = grp.Key.BatchId, status = grp.Key.Status, lstMessages = grp.ToList() }).ToList();
                foreach (var item in deliveryBatchGroup)
                {
                    LogController <ServiceLogs> .LogInFile(ServiceLogs.SaveDelivery, string.Format("status:{0},batchid:{1},mobiles:{2}", item.status, item.batchId, string.Join(",", item.lstMessages.Select(msg => string.Format("'{0}'", msg.Mobile)))));

                    numbers = string.Join(",", item.lstMessages.Select(msg => string.Format("'{0}'", msg.Mobile)));

                    dtDeliveryRelayInfo = outboxNumberController.UpdateDeliveryStatus(item.batchId, numbers, item.status);
                    foreach (DataRow row in dtDeliveryRelayInfo.Rows)
                    {
                        deliveryMessage                   = new DeliveryMessage();
                        deliveryMessage.BatchId           = row["OutboxGuid"].ToString();
                        deliveryMessage.Mobile            = row["ToNumber"].ToString();
                        deliveryMessage.Status            = Helper.GetInt(row["DeliveryStatus"]);
                        deliveryMessage.PrivateNumberGuid = Helper.GetGuid(row["PrivateNumberGuid"]);
                        deliveryMessage.UserGuid          = Helper.GetGuid(row["UserGuid"]);

                        ///// New 8-3-2019
                        if (!string.IsNullOrEmpty(GetDeliveryURL(deliveryMessage.PrivateNumberGuid)))
                        {
                            ManageQueue.SendMessage(ManageQueue.Queues.DeliveryRelay.ToString(), deliveryMessage, string.Format("DeliveryRelay=> batchid={0},mobile={1},status={2}", deliveryMessage.BatchId, deliveryMessage.Mobile, deliveryMessage.Status));
                        }
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                LogController <ServiceLogs> .LogInFile(ServiceLogs.SaveDelivery, string.Format("UpdateDeliveryStatus Error Message : {0}", ex.Message));

                throw ex;
            }
        }
        public HttpResponseMessage GetDelivery(HttpRequestMessage request)
        {
            string strIncomingMessage = string.Empty;
            string element            = string.Empty;

            StreamReader MyStreamReader = new StreamReader(request.Content.ReadAsStreamAsync().Result);

            strIncomingMessage = MyStreamReader.ReadToEnd();
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.XmlResolver   = null;
            settings.DtdProcessing = DtdProcessing.Parse;
            XmlReader objXMLReader = XmlReader.Create(new StringReader(strIncomingMessage), settings);

            while (objXMLReader.Read())
            {
                switch (objXMLReader.NodeType)
                {
                case XmlNodeType.Element:
                    element = objXMLReader.Name;
                    break;
                }
                if (!string.IsNullOrEmpty(element))
                {
                    break;
                }
            }

            switch (element.ToLower())
            {
            case "smsdeliver":
                #region ReceiveSms
                ReceiveMessage receiveMessage = new ReceiveMessage();
                while (objXMLReader.Read())
                {
                    switch (objXMLReader.NodeType)
                    {
                    case XmlNodeType.Element:
                        element = objXMLReader.Name;
                        if (element == "destAddrNbr")
                        {
                            receiveMessage.Receiver = objXMLReader.Value;
                        }
                        if (element == "origAddr")
                        {
                            receiveMessage.Sender = objXMLReader.Value;
                        }
                        if (element == "message")
                        {
                            receiveMessage.SmsText = objXMLReader.Value;
                        }

                        break;

                    case XmlNodeType.Text:
                        if (element == "destAddrNbr")
                        {
                            receiveMessage.Receiver = objXMLReader.Value;
                            break;
                        }
                        if (element == "origAddr")
                        {
                            receiveMessage.Sender = objXMLReader.Value;
                            break;
                        }
                        if (element == "message")
                        {
                            receiveMessage.SmsText = objXMLReader.Value;
                            break;
                        }
                        break;

                    case XmlNodeType.CDATA:
                        if (element == "origAddr")
                        {
                            receiveMessage.Sender = objXMLReader.Value;
                        }
                        if (element == "message")
                        {
                            receiveMessage.SmsText = objXMLReader.Value;
                        }
                        break;
                    }
                }
                if (strIncomingMessage.IndexOf("binary=") != -1)
                {
                    int    index   = strIncomingMessage.IndexOf("binary=") + 8;
                    string strLang = strIncomingMessage.Substring(index, 1);
                    if (strLang == "t")
                    {
                        receiveMessage.SmsText = DecodeUCS2(receiveMessage.SmsText);
                        receiveMessage.SmsText = Helper.PersianNumberToEnglish(receiveMessage.SmsText);
                    }
                }
                receiveMessage.ReceiveDateTime = DateTime.Now;
                receiveMessage.SmsText         = Helper.PersianNumberToEnglish(receiveMessage.SmsText);

                ManageQueue.SendMessage(Queues.ReceiveMessagesQueue, receiveMessage, receiveMessage.Sender);
                break;

                #endregion
            case "smsstatusnotification":
                #region DeliveryStatus
                Common.DeliveryMessage deliveryMessage = new Common.DeliveryMessage();
                deliveryMessage.Agent = (int)SmsSenderAgentReference.RahyabRG;
                while (objXMLReader.Read())
                {
                    switch (objXMLReader.NodeType)
                    {
                    case XmlNodeType.Element:
                        element = objXMLReader.Name;
                        if (element == "batch")
                        {
                            deliveryMessage.BatchId = objXMLReader.GetAttribute("batchID").Split('+')[1];
                        }
                        if (element == "sms")
                        {
                            deliveryMessage.ReturnId = objXMLReader.GetAttribute("smsId");
                        }
                        if (element == "destAddr")
                        {
                            deliveryMessage.Mobile = objXMLReader.Value;
                        }
                        if (element == "status")
                        {
                            deliveryMessage.Status = GetDeliveryStatus(objXMLReader.Value);
                        }
                        if (element == "time")
                        {
                            deliveryMessage.Date = !string.IsNullOrEmpty(objXMLReader.Value) ? DateManager.GetChristianDateForDB(objXMLReader.Value) : DateTime.Now;
                        }
                        break;

                    case XmlNodeType.CDATA:
                        if (element == "destAddr")
                        {
                            deliveryMessage.Mobile = objXMLReader.Value;
                        }
                        break;

                    case XmlNodeType.Text:
                        if (element == "status")
                        {
                            deliveryMessage.Status = GetDeliveryStatus(objXMLReader.Value);
                        }
                        if (element == "time")
                        {
                            deliveryMessage.Date = !string.IsNullOrEmpty(objXMLReader.Value) ? DateTime.Parse(objXMLReader.Value.Replace('-', '/')) : DateTime.Now;
                        }
                        break;
                    }
                }

                ManageQueue.SendMessage(Queues.SaveDelivery, deliveryMessage, deliveryMessage.ReturnId);
                break;

                #endregion
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Beispiel #16
0
        private void Analyze(List <Message> messages)
        {
            foreach (Message message in messages)
            {
                try
                {
                    ReceiveMessage receiveMessage = (ReceiveMessage)message.Body;

                    receiveMessage.Receiver = Helper.GetLocalPrivateNumber(receiveMessage.Receiver);
                    receiveMessage.Sender   = Helper.GetLocalMobileNumber(receiveMessage.Sender);


                    DataTable dtSmsInfo = Facade.Inbox.InsertReceiveMessage(receiveMessage);

                    if (dtSmsInfo.Rows.Count > 0)
                    {
                        foreach (DataRow row in dtSmsInfo.Rows)
                        {
                            LogController <ServiceLogs> .LogInFile(ServiceLogs.SmsParser,
                                                                   string.Format(@"On ParseReceivedMessage{6}SmsGuid : {0},{6}NumberGuid : {1},{6}SmsTrafficRelayGuid : {2},{6}Sender :{3},{6}Receiver : {4},{6}Text:{5}{6}",
                                                                                 Helper.GetGuid(row["SmsGuid"]),
                                                                                 Helper.GetGuid(row["NumberGuid"]),
                                                                                 Helper.GetGuid(row["SmsTrafficRelayGuid"]),
                                                                                 receiveMessage.Sender,
                                                                                 receiveMessage.Receiver,
                                                                                 receiveMessage.SmsText,
                                                                                 Environment.NewLine));

                            receiveMessage.Guid = Helper.GetGuid(row["SmsGuid"]);
                            receiveMessage.PrivateNumberGuid   = Helper.GetGuid(row["NumberGuid"]);
                            receiveMessage.UserGuid            = Helper.GetGuid(row["OwnerGuid"]);
                            receiveMessage.SmsTrafficRelayGuid = Helper.GetGuid(row["SmsTrafficRelayGuid"]);

                            try
                            {
                                WriteReceiveSmsToXmlFile(receiveMessage);
                            }
                            catch
                            {
                            }
                            finally
                            {
                                ManageQueue.SendMessage("SmsRelay", receiveMessage, string.Format("{0}->{1}", receiveMessage.Sender, receiveMessage.Receiver));

                                Facade.SmsParser.ParseReceiveSms(Helper.GetGuid(row["SmsGuid"]), Helper.GetGuid(row["NumberGuid"]), receiveMessage.SmsText, receiveMessage.Sender);

                                ReceiveMessageFromQueue(message.Id);
                            }
                        }
                    }
                    else
                    {
                        ReceiveMessageFromQueue(message.Id);
                    }
                }
                catch (Exception ex)
                {
                    LogController <ServiceLogs> .LogInFile(ServiceLogs.SmsParser, string.Format("On ProcessMessage : {0}", ex.Message));

                    LogController <ServiceLogs> .LogInFile(ServiceLogs.SmsParser, string.Format("On ProcessMessage : {0}", ex.StackTrace));

                    throw ex;
                }
            }
        }
        public HttpResponseMessage SendViaURL([FromUri] GetSendSmsModel sms)
        {
            if (!ModelState.IsValid)
            {
                ResponseMessage rm = new ResponseMessage();
                rm.IsSuccessful = false;
                rm.StatusCode   = (int)ErrorCode.ValidationNotValid;
                foreach (ModelState modelState in ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        rm.Message += string.Format("{0}", error.ErrorMessage);
                    }
                }
                throw new BusinessException(HttpStatusCode.Accepted, ErrorCode.ValidationNotValid, rm.Message);
            }

            if (sms.ReceiverList.Count == 0)
            {
                throw new BusinessException(HttpStatusCode.Accepted, ErrorCode.ReceiversIsEmpty, Language.GetString("ReceiversIsEmpty"));
            }

            if ((200 / sms.SmsLen) < sms.ReceiverList.Count)
            {
                throw new BusinessException(HttpStatusCode.Accepted, ErrorCode.ReceiverCountNotValid, Language.GetString("ReceiverCountNotValid"));
            }

            var principal = Thread.CurrentPrincipal;

            if (principal.Identity.IsAuthenticated)
            {
                Common.User userInfo = ((MyPrincipal)principal).UserDetails;

                BatchMessage batchMessage = new BatchMessage();
                batchMessage.UserGuid          = userInfo.UserGuid;
                batchMessage.Guid              = sms.BatchId;
                batchMessage.CheckId           = sms.CheckId.ToString();
                batchMessage.SmsText           = sms.SmsText;
                batchMessage.SmsLen            = sms.SmsLen;
                batchMessage.SenderNumber      = sms.SenderId;
                batchMessage.PrivateNumberGuid = Facade.PrivateNumber.GetUserNumberGuid(batchMessage.SenderNumber, batchMessage.UserGuid);
                batchMessage.Receivers         = sms.InProgressSmsList;
                batchMessage.IsUnicode         = sms.IsUnicode;
                batchMessage.IsFlash           = sms.IsFlash;
                batchMessage.ReferenceGuid     = null;
                batchMessage.SmsSendType       = (int)SmsSendType.SendSmsFromAPI;

                if (batchMessage.PrivateNumberGuid == Guid.Empty)
                {
                    throw new BusinessException(HttpStatusCode.Accepted, ErrorCode.SenderIsInvalid, Language.GetString("SenderIsInvalid"));
                }

                string messageLabel = (batchMessage.SenderNumber == null ? batchMessage.Guid.ToString() : batchMessage.SenderNumber);
                if (int.Parse(ConfigurationManager.GetSetting("ActiveQ")) == 0)
                {
                    if (!ManageQueue.SendMessage(Queues.ApiSendMessage, batchMessage, messageLabel))
                    {
                        throw new BusinessException(HttpStatusCode.Accepted, ErrorCode.InternalServerError, Language.GetString("InternalServerError"));
                    }
                }
                else if (int.Parse(ConfigurationManager.GetSetting("ActiveQ")) == 1)
                {
                    SaveToDB(batchMessage);
                }

                SendSmsResponse sendsms = new SendSmsResponse();
                sendsms.IsSuccessful = true;
                sendsms.BatchId      = batchMessage.Guid;

                return(Request.CreateResponse <SendSmsResponse>(HttpStatusCode.Created, sendsms));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Accepted));
            }
        }