惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
SegmentFault 最新的问题
爱范儿
爱范儿
博客园 - 三生石上(FineUI控件)
Microsoft Security Blog
Microsoft Security Blog
Google DeepMind News
Google DeepMind News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
GbyAI
GbyAI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
V2EX
酷 壳 – CoolShell
酷 壳 – CoolShell
量子位
博客园_首页
T
Tailwind CSS Blog
aimingoo的专栏
aimingoo的专栏
A
About on SuperTechFans
T
The Blog of Author Tim Ferriss
Stack Overflow Blog
Stack Overflow Blog
Recent Announcements
Recent Announcements
P
Proofpoint News Feed
博客园 - 司徒正美
有赞技术团队
有赞技术团队
Engineering at Meta
Engineering at Meta
Last Week in AI
Last Week in AI
MongoDB | Blog
MongoDB | Blog

博客园 - newr2006

Android adb.exe 开发模试安装 HttpWebRequest 模拟浏览器访问网站 jquery check box Fiddler Post Debug symbol MC 3090 upgrade to symbol MC 3190 ALTER TABLE unable to add host to SCVMM 2008R2 Cannot generate SSPI context ASP.NET代码对页面输出进行清理 - newr2006 - 博客园 线程 Thread 传参数 好的博客 Login failed for user 'NT AUTHORITY\NETWORK SERVICE'. 解决办法 - newr2006 Hashtable(HashSet),ListDictionary,HybridDictionary 和 NameValueCollection Pocket pc 与 Smartphone 开发的区别 XMl 文件属性的读取 USA 的网站终于把中国的名字排上去了. Menu 控件弹出窗口(popupwindow) 删除一些难删除的程序 Page_ClientValidate 用法
提前两天发邮件
newr2006 · 2009-05-04 · via 博客园 - newr2006

提前两天发邮件,

public static void SendMail(object sender, ElapsedEventArgs e)
        {          
            foreach (KeyValuePair<string, System.Timers.Timer> keyValuePair in Globals.TimerLists)
            {
                if (keyValuePair.Value == sender)
                {
                    string machineId = keyValuePair.Key;
                    using (Database accessor = new Database())
                    {
                        CheckOutInfo info = accessor.SelectCheckoutRecord(machineId);
                        if(info == null)
                        {
                            return;
                        }
                        //info.DueDate is expriation day
                        TimeSpan diff = DateTime.Now.Subtract(info.DueDate) + new TimeSpan(2, 0, 0, 0, 0);
                        diff = diff.Add(new TimeSpan(1, 0, 0)); // Add 1 hour to ignore the short time elapsed during processing.

                        // reSet the interval to let timer trigger next day.
                        if (diff.TotalDays < 0)
                        {
                            Debug.WriteLine("diff.Seconds< 0");
                            System.Timers.Timer reminderTimer = (System.Timers.Timer)sender;
                            reminderTimer.Interval = GetNextTriggerInterval(info.DueDate);
                            Debug.WriteLine(reminderTimer.Interval.ToString());
                            reminderTimer.AutoReset = false;
                            reminderTimer.Enabled = true;
                            break;
                        }
                        //Email reminder should be sent from 2 days before expiration;
                        else if (diff.TotalDays <= 2.0 && diff.TotalDays>=0.0)
                        {
                            VM vm = ShareFactory.GetVMByID(new Guid(machineId));
                            if (vm != null)
                            {
                                System.Timers.Timer reminderTimer = (System.Timers.Timer)sender;
                                reminderTimer.Interval = GetNextTriggerInterval(info.DueDate);
                                Debug.WriteLine(reminderTimer.Interval.ToString());
                                reminderTimer.AutoReset = false;
                                reminderTimer.Enabled = true;

                                string  Language = accessor.GetMachineLanguage(machineId);
                                ReservePolicy reservePolicy = ConfigurationFactory.GetReservePolicy(info.ReserveType);
                                if (info.ExtendTimes < reservePolicy.ExtendTimes)
                                {
                                    Debug.WriteLine("SendExpireEmail");                                 
                                }
                                else
                                {
                                    Debug.WriteLine("SendCheckinEmail");
                                 
                                }
                            }
                            else
                            {
                                // Machine does not exist. Just delete the records.
                               Debug.WriteLine("Machine does not exist. Just delete the records.");                             
                                Globals.TimerLists.Remove(machineId);
                            }

                        }
                        else
                        {
                             Debug.WriteLine("CheckIn");                           
                        }
                    }

                    break;
                }
            }
        }