Esempio n. 1
0
        public IEnumerable<CampaignInboxingStatistics> GetCampaignInboxingStatistics(int recordLookBackMinutes)
        {
            var batchStats = GetInboxingStatistics(recordLookBackMinutes).ToList();
            var campaigns = new List<CampaignInboxingStatistics>();

            foreach (var hs in batchStats)
            {
                var batchData = _oenContext.JobTargets.Where(jt => jt.batch_id == hs.BatchId)
                                                      .Select(jt=>new {
                                                                        jt.Job.Campaign,
                                                                        DeliveryGroup = jt.Job.deliverygroup_id.HasValue?jt.Job.DeliveryGroup
                                                                        : _oenContext.ClientDeliveryGroups.FirstOrDefault(c => c.clientKey_id == jt.Job.Campaign.key_id).DeliveryGroup
                                                                      }).FirstOrDefault();
                
                if (batchData != null)
                {
                    var campaignStats = campaigns.FirstOrDefault(c => c.Campaign.campaign_id == batchData.Campaign.campaign_id);

                    if (campaignStats == null)
                    {
                        campaignStats = new CampaignInboxingStatistics(batchData.Campaign);
                        campaigns.Add(campaignStats);
                    }
                    campaignStats.BatchStatistics.Add(hs);

                    if (batchData.DeliveryGroup != null && !campaignStats.DeliveryGroups.Contains(batchData.DeliveryGroup))
                    {
                        campaignStats.DeliveryGroups.Add(batchData.DeliveryGroup);
                    }
                }

            }

            return campaigns;
        }
Esempio n. 2
0
        private void PurgeAndCancelByCampaignContent(IPmtaRepository pmtaRepository, DateTime nextReset, CampaignInboxingStatistics campaignStats, IDeliveryGroupRepository deliveryGroupRepository, Event dblogEvent)
        {
            var jobs = Job.GetHotmailRelatedJobsSent(_jobRepository, campaignStats.Campaign, nextReset).ToArray();
            var dvgs = (from d in DeliveryGroup.GetMonitored(deliveryGroupRepository).ToArray()
                        where jobs.Select(j => j.deliverygroup_id.Value)
                                  .Distinct()
                                  .Contains(d.deliverygroup_id)
                        select new { Id = d.deliverygroup_id, Pmtas = Pmta.GetPmtasByDeliveryGroup(pmtaRepository, d).ToArray() }).ToArray();
            var mtaEventDetails = new List<EventAction>();

            var mtaJobDeleteTask = new Task(() =>
                              {
                                  var commandsSent = 0;
                                  _logger.DebugFormat("Deleting Related Jobs from MTAs");
                                  foreach (var job in jobs)
                                  {
                                      try
                                      {
                                          var pmtas = dvgs.FirstOrDefault(d => d.Id == job.deliverygroup_id.Value).Pmtas;

                                          if (pmtas.Any())
                                          {
                                              foreach (var pmta in pmtas)
                                              {
                                                  _mtaAgent.DeleteJob(pmta.ToMta(), job.job_id);
                                                  commandsSent++;
                                              }
                                          }
                                          else
                                          {
                                              _logger.TraceFormat("No DeliveryServers found for DeliveryGroup {0}", job.deliverygroup_id);
                                          }

                                          mtaEventDetails.Add(new EventAction()
                                          {
                                              Action = EventAction.Actions.MTAJobDelete,
                                              ActedOnDeliveryGroupId = job.deliverygroup_id,
                                              JobId = job.job_id
                                          });
                                      }
                                      catch (Exception ex)
                                      {
                                          _logger.ErrorFormat("Job {0}: {1}", job.job_id, ex.UnwrapForLog(true));
                                      }
                                  }
                                  _logger.DebugFormat("Sent {0} delete commands for {1} Jobs to MTAs", commandsSent, jobs.Count());
                              });

            try
            {
                mtaJobDeleteTask.Start();

                try
                {
                    _logger.DebugFormat("Cancelling Related Jobs");
                    Job.CancelHotmailRelatedJobs(_jobRepository, _logger, campaignStats.Campaign, nextReset, dblogEvent);
                }
                catch (Exception ex)
                {
                    _logger.ErrorFormat("Campaign {0}: {1}", campaignStats.Campaign.campaign_id, ex.UnwrapForLog(true));
                }

                mtaJobDeleteTask.Wait();
            }
            catch (AggregateException ex)
            {
                foreach (var innerException in ex.InnerExceptions)
                {
                    _logger.Error(innerException.UnwrapForLog(false));
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex.UnwrapForLog());
            }

            mtaEventDetails.ForEach(e => dblogEvent.EventActions.Add(e));

            _unitOfWork.SaveChanges();
        }