private void SaveMessage(SmsDeliveryStatus status)
    {
        try
        {
            List <string> list = new List <string>();
            FileStream    file = new FileStream(Request.MapPath(this.deiveryStatusFilePath), FileMode.OpenOrCreate, FileAccess.Read);
            StreamReader  sr   = new StreamReader(file);

            string line;
            while ((line = sr.ReadLine()) != null)
            {
                list.Add(line);
            }
            sr.Close();
            file.Close();

            if (list.Count > this.numberOfDeliveryStatusToStore)
            {
                int diff = list.Count - this.numberOfDeliveryStatusToStore;
                list.RemoveRange(0, diff);
            }

            if (list.Count == this.numberOfDeliveryStatusToStore)
            {
                if (list.Count > 1)
                {
                    list.RemoveAt(0);
                }
            }

            string statusInfoToStore = status.DeliveryInfoNotification.MessageId + "_-_-" + status.DeliveryInfoNotification.DeliveryInfo.Address + "_-_-" + status.DeliveryInfoNotification.DeliveryInfo.DeliveryStatus;
            list.Add(statusInfoToStore);

            using (StreamWriter sw = File.CreateText(Request.MapPath(this.deiveryStatusFilePath)))
            {
                int tempCount = 0;
                while (tempCount < list.Count)
                {
                    string lineToWrite = list[tempCount];
                    sw.WriteLine(lineToWrite);
                    tempCount++;
                }
                sw.Close();
            }
        }
        catch (Exception ex)
        {
            File.AppendAllText(Request.MapPath("Error.txt"), DateTime.Now.ToString() + ": " + ex.ToString() + Environment.NewLine);
        }
    }
    private void SaveMessage(SmsDeliveryStatus status)
    {
        try
        {
            List<string> list = new List<string>();
            FileStream file = new FileStream(Request.MapPath(this.deiveryStatusFilePath), FileMode.OpenOrCreate, FileAccess.Read);
            StreamReader sr = new StreamReader(file);

            string line;
            while ((line = sr.ReadLine()) != null)
            {
                list.Add(line);

            }
            sr.Close();
            file.Close();

            if (list.Count > this.numberOfDeliveryStatusToStore)
            {
                int diff = list.Count - this.numberOfDeliveryStatusToStore;
                list.RemoveRange(0, diff);
            }

            if (list.Count == this.numberOfDeliveryStatusToStore)
            {
                if (list.Count > 1)
                list.RemoveAt(0);
            }

            string statusInfoToStore = status.DeliveryInfoNotification.MessageId + "_-_-" + status.DeliveryInfoNotification.DeliveryInfo.Address + "_-_-" + status.DeliveryInfoNotification.DeliveryInfo.DeliveryStatus;
            list.Add(statusInfoToStore);

            using (StreamWriter sw = File.CreateText(Request.MapPath(this.deiveryStatusFilePath)))
            {
                int tempCount = 0;
                while (tempCount < list.Count)
                {
                    string lineToWrite = list[tempCount];
                    sw.WriteLine(lineToWrite);
                    tempCount++;
                }
                sw.Close();
            }
        }
        catch (Exception ex)
        {
            File.AppendAllText(Request.MapPath("Error.txt"), DateTime.Now.ToString() + ": " + ex.ToString() + Environment.NewLine);
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        this.deiveryStatusFilePath = ConfigurationManager.AppSettings["deiveryStatusFilePath"];
        if (string.IsNullOrEmpty(this.deiveryStatusFilePath))
        {
            this.deiveryStatusFilePath = "DeliveryStatus.txt";
        }

        string numOfDeiveryStatusToStore = ConfigurationManager.AppSettings["numberOfDeliveryStatusToStore"];

        if (!string.IsNullOrEmpty(numOfDeiveryStatusToStore))
        {
            this.numberOfDeliveryStatusToStore = Convert.ToInt32(numOfDeiveryStatusToStore);
        }
        else
        {
            this.numberOfDeliveryStatusToStore = 5;
        }

        try
        {
            System.IO.Stream inputStream = Request.InputStream;

            SmsDeliveryStatus deliveryStatus = RequestFactory.GetSMSDeliveryStatus(inputStream);

            if (null != deliveryStatus)
            {
                this.SaveMessage(deliveryStatus);
            }
        }
        catch (ArgumentException ae)
        {
            File.AppendAllText(Request.MapPath("Error.txt"), DateTime.Now.ToString() + ": " + ae.Message + Environment.NewLine);
        }
        catch (Exception ex)
        {
            File.AppendAllText(Request.MapPath("Error.txt"), DateTime.Now.ToString() + ": " + ex.ToString() + Environment.NewLine);
        }
    }
        public async Task AddAsync(SmsProvider provider, string countryCode, SmsDeliveryStatus status)
        {
            var entity = await _tableStorage.GetDataAsync(SmsProviderInfoEntity.GeneratePartitionKey(provider),
                                                          SmsProviderInfoEntity.GenerateRowKey(countryCode));

            if (entity == null)
            {
                entity = SmsProviderInfoEntity.Create(provider, countryCode, status);
                await _tableStorage.TryInsertAsync(entity);
            }
            else
            {
                await _tableStorage.MergeAsync(SmsProviderInfoEntity.GeneratePartitionKey(provider), SmsProviderInfoEntity.GenerateRowKey(countryCode),
                                               infoEntity =>
                {
                    switch (status)
                    {
                    case SmsDeliveryStatus.Delivered:
                        infoEntity.DeliveredCount++;
                        break;

                    case SmsDeliveryStatus.Failed:
                        infoEntity.DeliveryFailedCount++;
                        break;

                    case SmsDeliveryStatus.Unknown:
                        infoEntity.UnknownCount++;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(status), status, null);
                    }

                    return(infoEntity);
                });
            }
        }
 internal static SmsProviderInfoEntity Create(SmsProvider provider, string countryCode, SmsDeliveryStatus status)
 {
     return(new SmsProviderInfoEntity
     {
         PartitionKey = GeneratePartitionKey(provider),
         RowKey = GenerateRowKey(countryCode),
         Provider = provider.ToString(),
         CountryCode = countryCode,
         DeliveredCount = status == SmsDeliveryStatus.Delivered ? 1 : 0,
         DeliveryFailedCount = status == SmsDeliveryStatus.Failed ? 1 : 0,
         UnknownCount = status == SmsDeliveryStatus.Unknown ? 1 : 0
     });
 }
Example #6
0
 public static string AsString(SmsDeliveryStatus item)
 {
     return Items[item];
 }
Example #7
0
 public static string AsString(SmsDeliveryStatus item)
 {
     return(Items[item]);
 }