Example #1
0
        private List <Pair> getPlan()
        {
            var plan = new List <Pair>();

            var web_db        = new WebModelContainer();
            var emailAccounts = web_db.EmailAccounts.ToList();

            int pos   = 0;
            int total = Bcc.Count;

            foreach (var acct in emailAccounts)
            {
                if (!acct.Verified)
                {
                    continue;
                }
                var dailyCount = acct.DailyCounts.Where(d => d.WhichDate == DateTime.Today).SingleOrDefault();
                if (dailyCount == null)
                {
                    dailyCount = new DailyCount
                    {
                        WhichDate      = DateTime.Today,
                        Count          = 0,
                        EmailAccount   = acct,
                        EmailAccountId = acct.Id,
                    };
                    web_db.DailyCounts.Add(dailyCount);
                    web_db.SaveChanges();
                }
                if (dailyCount.Count >= acct.SmtpDailyLimit)
                {
                    continue;
                }

                var msg          = new MailMessage();
                int perTimeCount = 0;
                while ((pos < total) && (dailyCount.Count < acct.SmtpDailyLimit) && (perTimeCount < acct.SmtpPerTimeLimit))
                {
                    msg.Bcc.Add(Bcc.ElementAt(pos));
                    pos++;
                    dailyCount.Count++;
                    perTimeCount++;
                }

                msg.Subject    = Subject;
                msg.Body       = Body;
                msg.IsBodyHtml = true;
                msg.From       = new MailAddress(acct.From);
                plan.Add(new Pair(acct, msg));

                if (pos == total)
                {
                    break;
                }
            }
            web_db.Dispose();
            return(plan);
        }
Example #2
0
        public override int GetHashCode()
        {
            var hashCode = 465562093;

            hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Loc);

            hashCode = hashCode * -1521134295 + DailyCount.GetHashCode();
            hashCode = hashCode * -1521134295 + TotalCount.GetHashCode();
            hashCode = hashCode * -1521134295 + DailyDCount.GetHashCode();
            hashCode = hashCode * -1521134295 + TotalDCount.GetHashCode();
            return(hashCode);
        }
Example #3
0
        public int CompareTo(CvStat other)
        {
            int result = TotalCount.CompareTo(other.TotalCount);

            if (result == 0)
            {
                result = Loc.CompareTo(other.Loc);
            }
            if (result == 0)
            {
                result = DailyCount.CompareTo(other.DailyCount);
            }
            if (result == 0)
            {
                result = TotalDCount.CompareTo(other.TotalDCount);
            }
            if (result == 0)
            {
                result = DailyDCount.CompareTo(other.DailyDCount);
            }
            return(result);
        }
        public async Task <DailyCount[]> GetDailyActivity()
        {
            DateTime[] sessionsTimes = await Datetimes();

            DailyCount[] day = new DailyCount[24];

            for (int i = 0; i < 24; i++)
            {
                DailyCount hour = new DailyCount();
                hour.Hour  = i;
                hour.Count = 0;
                day[i]     = hour;
            }

            foreach (DateTime d in sessionsTimes)
            {
                int hour = d.Hour;
                day[hour].Count += 1;
            }

            day = day.OrderByDescending(day => day.Count).ToArray();
            return(day);
        }
Example #5
0
        public void Send()
        {
            var plan   = getPlan();
            var web_db = new WebModelContainer();

            foreach (var p in plan)
            {
                var acct = web_db.EmailAccounts.Find(p.acct.Id);
                var ret  = send(p);
                if ("success" != ret)
                {
                    // acct.Verified = false;
                    this.FailedCount   += p.msg.Bcc.Count;
                    this.ErrorAccounts += ", " + p.acct.Name + ":" + ret + ": " + this.FailedCount.ToString();
                }

                if (acct != null)
                {
                    var dailyCount = acct.DailyCounts.Where(d => d.WhichDate == DateTime.Today).SingleOrDefault();
                    if (dailyCount == null)
                    {
                        dailyCount = new DailyCount
                        {
                            WhichDate      = DateTime.Today,
                            Count          = 0,
                            EmailAccount   = acct,
                            EmailAccountId = acct.Id,
                        };
                        web_db.DailyCounts.Add(dailyCount);
                    }
                    dailyCount.Count += p.msg.Bcc.Count;
                }
                this.Count += p.msg.Bcc.Count();
            }
            web_db.SaveChanges();
            web_db.Dispose();
        }