Esempio n. 1
0
        public static IEnumerable<ReportRow> GetListOfUsedStatements(DateTime startDate)
        {
            if (startDate == DateTime.MinValue)
                startDate = _currentCard.RegisterDate;

            // initialize statementA.asp get request
            var request = (HttpWebRequest)WebRequest.Create("https://www.sbsibank.by/statementA.asp");
            AddCommonHeadersToHttpRequest(request);
            request.Referer = "https://www.sbsibank.by/left.asp";

            // get response
            Log.Info("Open https://www.sbsibank.by/statementA.asp");
            using (var response = (HttpWebResponse)request.GetResponse())
            {
                var responseStream = response.GetResponseStream();
                if (responseStream != null)
                {
                    var reports = ParseHtmlHelper.ParseStatementsList(new StreamReader(responseStream, Encoding.GetEncoding(1251)));
                    var endDate = DateTime.UtcNow.AddDays(-1);

                    var preparedRanges = new List<ReportRow>();
                    var reportsToCreate = new List<ReportRow>();
                    if (reports != null)
                    {
                        ReportRow range = null;
                        do
                        {
                            if (startDate > endDate) continue;

                            range = reports.Where(r => r.PeriodStartDate <= startDate && r.PeriodEndDate > startDate)
                                        .OrderByDescending(r => r.PeriodEndDate).FirstOrDefault() ??
                                    reports.Where(r => r.PeriodStartDate > startDate).OrderBy(r => r.PeriodStartDate)
                                        .FirstOrDefault();

                            if (range == null) continue;

                            range.IsCreated = true;
                            Log.Info(range.ToString());

                            if (range.PeriodStartDate > startDate)
                            {
                                var start = startDate;
                                do
                                {
                                    if (DaysBetween(range.PeriodStartDate, start) > _maxDaysPeriod)
                                    {
                                        var end = start.AddDays(_maxDaysPeriod);
                                        var createReport = new ReportRow
                                                               {
                                                                   PeriodStartDate = start,
                                                                   PeriodEndDate = end,
                                                                   IsCreated = false
                                                               };
                                        reportsToCreate.Add(createReport);
                                        Log.Info(createReport.ToString());

                                        start = end.AddDays(1);
                                    }
                                    else
                                    {
                                        var createReport = new ReportRow
                                        {
                                            PeriodStartDate = start,
                                            PeriodEndDate = range.PeriodStartDate.AddDays(-1),
                                            IsCreated = false
                                        };
                                        reportsToCreate.Add(createReport);
                                        Log.Info(createReport.ToString());
                                        start = range.PeriodStartDate.AddDays(1);
                                    }

                                } while (start < range.PeriodStartDate);
                            }
                            preparedRanges.Add(range);
                            startDate = range.PeriodEndDate.AddDays(1);
                        } while (range != null);
                    }

                    var start2 = startDate;
                    do
                    {
                        if (DaysBetween(endDate, start2) > _maxDaysPeriod)
                        {
                            var end = start2.AddDays(_maxDaysPeriod);
                            var createReport = new ReportRow
                            {
                                PeriodStartDate = start2,
                                PeriodEndDate = end,
                                IsCreated = false
                            };
                            reportsToCreate.Add(createReport);
                            Log.Info(createReport.ToString());

                            start2 = end.AddDays(1);
                        }
                        else
                        {
                            var createReport = new ReportRow
                            {
                                PeriodStartDate = start2,
                                PeriodEndDate = endDate,
                                IsCreated = false
                            };
                            reportsToCreate.Add(createReport);
                            Log.Info(createReport.ToString());
                            start2 = endDate;
                        }

                    } while (start2 < endDate);

                    return preparedRanges;
                }
            }
            return null;
        }
Esempio n. 2
0
 public static void CreateReport(ReportRow range)
 {
 }