public static GsmStatusInfo GetGsmSmsStatusInfo(long responseId, DateTime createDate)
        {
            GsmStatusInfo   smallGsmStatusEntity = new GsmStatusInfo();
            SmsStatusResult smsStatusResult;
            int             messageStatus;

            List <GsmStatusInfo> gsmGetStatusEntitiyList = NotificationOperation.GetGsmSmsStatusOfSingleRecord(responseId, createDate);

            if (gsmGetStatusEntitiyList.Count == 0)
            {
                throw new EsbBusinessException("RecordNotFound");
            }

            if (gsmGetStatusEntitiyList.FirstOrDefault().Status != GsmOperatorStatus.Completed)
            {
                smsStatusResult = BuildSmsStatusRequestByOperator(gsmGetStatusEntitiyList);
                messageStatus   = smsStatusResult.GsmSmsStatusResultList.FirstOrDefault().MessageStatus;

                var gsmOperator                     = gsmGetStatusEntitiyList.FirstOrDefault().Operator;
                GsmOperatorSender sender            = new GsmOperatorSender(gsmOperator);
                string            statusExplanation = sender.GetStatusExplanationFromEnum(messageStatus);

                smallGsmStatusEntity.NotificationResponseId = responseId;
                smallGsmStatusEntity.GsmStatus            = messageStatus.ToString();
                smallGsmStatusEntity.GsmStatusExplanation = statusExplanation;
                smallGsmStatusEntity.DeliveryTime         = smsStatusResult.GsmSmsStatusResultList.FirstOrDefault().MessageDeliveryDate;
                smallGsmStatusEntity.Operator             = gsmOperator;
            }
            else
            {
                smallGsmStatusEntity = gsmGetStatusEntitiyList.FirstOrDefault();
            }

            return(smallGsmStatusEntity);
        }
        public void Process()
        {
            int loopCount = 1;

            while (true)
            {
                try {
                    CommonUtilities.SetEsbContext();
                    if (loopCount == 1)
                    {
                        NotificationOperation.InsertBulkSenderNotificationProcessingInfo(UpdatingInfo);
                    }
                    NotifyQueueViewRequest.PageNumber = PageNumber;
                    NotifyQueueViewRequest.PageSize   = GetPageSize();
                    List <NotificationQueueView> result = NotificationOperation.GetNotificationQueueWithPaging(NotifyQueueViewRequest);
                    if (result.Count == 0)
                    {
                        log.DebugFormat("No result found for sending notification NotificationBulkResender");
                        NotificationOperation.DeleteNotificationBulkProcessingInfo();
                        return;
                    }
                    else
                    {
                        NotificationOperation.RemoveFromQueue(result, UpdatingInfo);
                    }
                    NotificationOperation.AddToQueue(result);
                    loopCount++;
                }
                catch (Exception ex) {
                    log.ErrorFormat("Exception in adding queue NotificationBulkResender {0}", ex);
                    NotificationOperation.DeleteNotificationBulkProcessingInfo();
                    break;
                }
            }
        }
        static void Process(int takeCount)
        {
            while (true)
            {
                List <GsmStatusInfo>         gsmGetStatusEntitiyList        = null;
                List <List <GsmStatusInfo> > gsmGetStatusEntitiyGroupedList = new List <List <GsmStatusInfo> >();
                CommonUtilities.SetEsbContext();
                try {
                    try {
                        gsmGetStatusEntitiyList = NotificationOperation.GetGsmRecordsForStatusQuerying(takeCount);
                        if (gsmGetStatusEntitiyList.Count > 0)
                        {
                            gsmGetStatusEntitiyGroupedList = gsmGetStatusEntitiyList.GroupBy(o => o.Operator).Select(grp => grp.ToList()).ToList();
                        }
                    }
                    catch (Exception ex) {
                        log.ErrorFormat("An arror occoured while selecting gsm records from db, Error : {0}", ex);
                    }

                    foreach (var gsmListItem in gsmGetStatusEntitiyGroupedList)
                    {
                        try {
                            BuildSmsStatusRequestByOperator(gsmListItem);
                        }
                        catch (Exception ex) {
                            log.ErrorFormat("GsmStatusController process error : {0}", ex);
                            NotificationOperation.UpdateProcessingErrorLog(gsmListItem, ex);
                        }
                    }
                    if (gsmGetStatusEntitiyGroupedList.Count > 0)
                    {
                        Thread.Sleep(100);
                    }
                    else
                    {
                        var    sleepTime    = 3000;
                        string sleepTimeKey = Constants.GsmStatusControllerSleepTimeKey;
                        try {
                            sleepTime = ConfigurationHelper.GetConfiguration <int>(sleepTimeKey, sleepTime);
                        }
                        catch (Exception ex) {
                            log.ErrorFormat("{0} configuration deðeri bulunamadý.{1}", sleepTimeKey, ex);
                        }
                        Thread.Sleep(sleepTime);
                    }
                }
                catch (Exception outerException) {
                    log.ErrorFormat("GsmStatusController process error : {0}", outerException);
                }
            }
        }
        public static SmsStatusResult BuildSmsStatusRequestByOperator(List <GsmStatusInfo> gsmGetStatusEntitiyList)
        {
            try {
                CommonUtilities.SetEsbContext();
            }
            catch (Exception ex) {
                log.ErrorFormat("Error while creating new esb context :{0}", ex);
            }

            if (gsmGetStatusEntitiyList == null)
            {
                return(null);
            }

            var gsmOperator = gsmGetStatusEntitiyList.FirstOrDefault().Operator;
            GsmOperatorSender      sender           = new GsmOperatorSender(gsmOperator);
            SmsStatusRequestEntity smsGetStatusItem = new SmsStatusRequestEntity();

            foreach (var item in gsmGetStatusEntitiyList)
            {
                if (gsmOperator == GsmOperator.VODAFONE)
                {
                    smsGetStatusItem.MultipleStatusRequestKeys.Add(new MultipleStatusRequestKey {
                        MessageId = item.OperatorResponseId,
                        NotificationResponseId = item.NotificationResponseId,
                        SessionId   = item.SessionId,
                        GsmStatusId = item.Id
                    });
                    smsGetStatusItem.SessionId = item.SessionId;
                    smsGetStatusItem.NotificationResponseId = item.NotificationResponseId;
                }
                else
                {
                    smsGetStatusItem.MessageIdList.Add(item.OperatorResponseId);
                    if (!string.IsNullOrEmpty(item.SessionId))
                    {
                        smsGetStatusItem.SessionId = item.SessionId;
                    }
                }
            }

            SmsStatusRequest smsStatusRequest = sender.BuildSmsStatusRequest(smsGetStatusItem);
            SmsStatusResult  smsStatusResult  = sender.GetSmsStatus(smsStatusRequest);

            if (smsStatusResult.GsmSmsStatusResultList == null || smsStatusResult.GsmSmsStatusResultList.Count == 0)
            {
                throw new Exception(string.Format("Gsm status result null or empty, gsm operator:{0}", gsmOperator));
            }

            foreach (var smsStatusResulItem in smsStatusResult.GsmSmsStatusResultList)
            {
                var           gsmStatusFields = sender.SetGsmStatusFields(smsStatusResulItem, sender);
                GsmStatusInfo smallGsmEntitiy = GetInsertDateAndIdOfGsmItem(smsStatusResulItem.MessageId, smsStatusResulItem.SessionId, gsmOperator, gsmGetStatusEntitiyList);
                NotificationOperation.UpdateGsmSmsStatusResults(smsStatusResulItem, gsmOperator, smallGsmEntitiy, gsmStatusFields);
                if (gsmStatusFields.InternalStatus != GsmOperatorStatus.Completed)
                {
                    DateTime nexCheckDate = sender.SetNextStatusCheckDateOfGsmSms(smallGsmEntitiy.InsertDate, gsmStatusFields.InternalStatus);
                    NotificationOperation.UpdateNexCheckDateOfGsmRecord(nexCheckDate, smsStatusResulItem.MessageId, smallGsmEntitiy);
                }
            }
            return(smsStatusResult);
        }