예제 #1
0
        protected void GetDataFromDB(List <ReportItem> items, string dateFormat)
        {
            List <string> guids = items.Select(it => it.ResultId).Distinct().ToList();

            var sqlHelper = new SqlHelper();

            try
            {
                int i = 0;
                while (i < guids.Count)
                {
                    // TODO use skip take from linq.
                    var aux = new List <string>();
                    for (int count = 0; i < guids.Count && count < 1000; count++)
                    {
                        aux.Add(guids[i]);
                        i++;
                    }

                    List <DBReportItem> dbReportItemList = sqlHelper.GetResultsByDeliveryList(UserId, aux);
                    foreach (DBReportItem dbReportItem in dbReportItemList)
                    {
                        ReportItem item = items.FirstOrDefault(x => x.ResultId == dbReportItem.MessageGuid);
                        if (item != null)
                        {
                            string status;
                            string description;
                            GetStatusAndDescription(dbReportItem, out status, out description);

                            foreach (ReportFieldConfiguration reportField in _reportConfiguration.ReportFields.Where(x => !string.IsNullOrEmpty(x.NameInDB)))
                            {
                                switch (reportField.NameInDB)
                                {
                                case "CreatedAt":
                                    item.AddValue(dbReportItem.CreatedAt.AddHours(ReportGMT).ToString(dateFormat), reportField.Position);
                                    break;

                                case "Status":
                                    item.AddValue(status, reportField.Position);
                                    break;

                                case "Description":
                                    item.AddValue(description, reportField.Position);
                                    break;

                                case "ClickEventsCount":
                                    item.AddValue(dbReportItem.ClickEventsCount.ToString(), reportField.Position);
                                    break;

                                case "OpenEventsCount":
                                    item.AddValue(dbReportItem.OpenEventsCount.ToString(), reportField.Position);
                                    break;

                                case "Subject":
                                    item.AddValue(dbReportItem.Subject, reportField.Position);
                                    break;

                                case "FromEmail":
                                    item.AddValue(dbReportItem.FromEmail, reportField.Position);
                                    break;

                                case "FromName":
                                    item.AddValue(dbReportItem.FromName, reportField.Position);
                                    break;

                                case "Address":
                                    item.AddValue(dbReportItem.Address, reportField.Position);
                                    break;

                                case "OpenDate":
                                    item.AddValue(dbReportItem.OpenDate.AddHours(ReportGMT).ToString(dateFormat), reportField.Position);
                                    break;

                                case "ClickDate":
                                    item.AddValue(dbReportItem.ClickDate.AddHours(ReportGMT).ToString(dateFormat), reportField.Position);
                                    break;

                                case "BounceDate":
                                    item.AddValue(dbReportItem.BounceDate.AddHours(ReportGMT).ToString(dateFormat), reportField.Position);
                                    break;
                                }
                            }
                        }
                    }

                    aux.Clear();
                }

                sqlHelper.CloseConnection();
            }
            catch (Exception e)
            {
                _logger.Error($"Error on get data from DB {e}");
                throw;
            }
        }