コード例 #1
0
        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));
        }
コード例 #2
0
        private void Confirm(List <Message> messages)
        {
            foreach (Message message in messages)
            {
                try
                {
                    BulkSmsModel bulkInfo = (BulkSmsModel)message.Body;
                    Dictionary <DeliveryStatus, List <string> > lstNumbers = new Dictionary <DeliveryStatus, List <string> >();
                    lstNumbers.Add(DeliveryStatus.NotSent, bulkInfo.Receivers.Split(',').ToList());

                    Facade.Outbox.UpdateStatus(Guid.Empty, bulkInfo.Status, bulkInfo.Id);
                    Facade.OutboxNumber.UpdateDeliveryStatus(Guid.Empty, lstNumbers, bulkInfo.Id);
                    ReceiveMessageFromQueue(message.Id);
                }
                catch (Exception ex)
                {
                    LogController <ServiceLogs> .LogInFile(ServiceLogs.ConfirmBulk, string.Format("On ConfirmBulk : {0}", ex.Message));

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

                    throw ex;
                }
            }
        }
コード例 #3
0
        public HttpResponseMessage GetBulkMessages()
        {
            MessageQueue queue;
            BatchMessage batchMessage = new BatchMessage();
            BulkSmsModel bulkInfo     = new BulkSmsModel();

            string queuePath = string.Format(@".\private$\SocialNetworks-bulk");

            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 (!MessageQueue.Exists(queuePath))
            {
                throw new BusinessException(HttpStatusCode.Accepted, ErrorCode.InternalServerError, Language.GetString("InternalServerError"));
            }

            queue           = new MessageQueue(queuePath);
            queue.Formatter = new BinaryMessageFormatter();

            BulkSmsResponse response = new BulkSmsResponse();

            response.IsSuccessful = true;

            var msgEnumerator = queue.GetMessageEnumerator2();

            while (msgEnumerator.MoveNext(new TimeSpan(0, 0, 1)))
            {
                using (var msg = msgEnumerator.Current)
                {
                    msg.Formatter = new BinaryMessageFormatter();
                    batchMessage  = (BatchMessage)msg.Body;

                    bulkInfo.Id         = batchMessage.Id;
                    bulkInfo.IsUnicode  = batchMessage.IsUnicode;
                    bulkInfo.SmsLen     = batchMessage.SmsLen;
                    bulkInfo.SmsText    = batchMessage.SmsText;
                    bulkInfo.TotalCount = batchMessage.TotalCount;
                    bulkInfo.Status     = SendStatus.IsBeingSent;
                    bulkInfo.Receivers  = string.Join(",", batchMessage.Receivers.Where(receiver => !Helper.GetBool(receiver.IsBlackList)).Select(receiver => receiver.RecipientNumber).ToList());

                    response.BulkInfo = bulkInfo;

                    Parallel.ForEach <InProgressSms>(batchMessage.Receivers, (receiver) =>
                    {
                        if (!Helper.GetBool(receiver.IsBlackList))
                        {
                            receiver.ReturnID       = random.Next().ToString();
                            receiver.SendStatus     = (int)SendStatus.Sent;
                            receiver.DeliveryStatus = (int)DeliveryStatus.SentToItc;
                            receiver.SendTryCount  += 1;
                        }
                        else
                        {
                            receiver.SendStatus     = (int)SendStatus.BlackList;
                            receiver.DeliveryStatus = (int)DeliveryStatus.BlackListTable;
                            receiver.SendTryCount  += 1;
                        }
                    });

                    SqlLibrary.ManageQueue.SendMessage(ConfigurationManager.GetSetting("SentMessageQueue"), batchMessage, string.Format("{0}-{1}", batchMessage.Id, batchMessage.PageNo));
                    queue.ReceiveById(msg.Id);
                    break;
                }
            }

            return(Request.CreateResponse <BulkSmsResponse>(HttpStatusCode.Accepted, response));
        }