Example #1
0
        public bool NotifyFailed(Guid smsId, string clientId, string distibutionId = null, Dictionary <string, string> additionalParams = null)
        {
            long intClientId;
            bool result = false;

            if (long.TryParse(clientId, out intClientId))
            {
                ClientModel client = ClientRepo.GetClientConcrete(intClientId);
                if (client != null && client.Id.HasValue)
                {
                    if (client.DebtingType == DebtingType.ByDelivered)
                    {
                        if (!additionalParams.ContainsKey(ADEService.EXTERNAL))
                        {
                            long?intDistibutionId = null;
                            if (!string.IsNullOrEmpty(distibutionId))
                            {
                                long dId;
                                if (long.TryParse(distibutionId, out dId))
                                {
                                    intDistibutionId = dId;
                                }
                            }
                            result = BillingProcessor.ResetSMSSend(intClientId, distributionId: intDistibutionId);
                        }
                        else
                        {
                            result = BillingProcessor.ResetSMSSend(intClientId, extDistributionId: distibutionId);
                        }
                    }
                    else
                    {
                        result = true;
                    }
                }
            }
            return(result);
        }
Example #2
0
        public List <SMSSeriesId> SendSms(string sessionKey, List <string> addresses, string message, string distibutionId = null, string messageId = null, bool transliterate = false, DateTime?deliveryTime = null, TimeSpan?validalityPeriod = null)
        {
            List <SMSSeriesId> ids     = new List <SMSSeriesId>();
            ServiceSession     session = _sessionManager.GetSession(sessionKey);

            if (session != null)
            {
                Dictionary <string, string> custom = new Dictionary <string, string>();
                custom.Add(USER_ID, session.UserId);
                custom.Add(EXTERNAL, true.ToString());
                bool isSent   = false;
                long clientId = long.Parse(session.ClientId);
                if (BillingProcessor.SMSBeginSend(clientId, extDistributionId: distibutionId))
                {
                    try
                    {
                        try
                        {
                            ids = _gateService.SendSms(
                                session.GateSessionKey,
                                addresses,
                                message,
                                session.ClientId,
                                distibutionId,
                                messageId,
                                transliterate,
                                deliveryTime,
                                validalityPeriod,
                                custom);
                        }
                        catch
                        {
                            session.GateSessionKey = _gateService.Login(Settings.Default.GateUserName, Settings.Default.GatePassword, session.SenderName);
                            ids = _gateService.SendSms(
                                session.GateSessionKey,
                                addresses,
                                message,
                                session.ClientId,
                                distibutionId,
                                messageId,
                                transliterate,
                                deliveryTime,
                                validalityPeriod,
                                custom);
                        }
                        isSent = true;
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError("Ошибка отправки на шлюз {0}", ex);
                        isSent = false;
                    }
                }
                else
                {
                    throw new InvalidOperationException("Блокировка средств на вашем счету завершилась неудачей, отправка невозможна, проверьте ваш баланс");
                }

                if (isSent && session.DebtingType == DebtingType.BySent)
                {
                    BillingProcessor.CommintSMSSend(clientId, extDistributionId: distibutionId);
                }
                else
                {
                    BillingProcessor.ResetSMSSend(clientId, extDistributionId: distibutionId);
                }
                return(ids);
            }
            else
            {
                throw new Exception(Resources.Error_SessionIncorrect);
            }
        }