• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C#实现WebService服务 项目完整总结

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

先说一下这个项目做了什么。先介绍一下背景(备注一下,每次项目发生更改之后,要进行clean 和rebuild两个操作,否则最新的更改保存不到exe文件中,这样上线后的系统还是执行得原有的已编译过的程序代码,所以得出的结论就是在上线测试阶段,对于程序代码的每一次更改都要rebuild操作,来保证每次的更改作用于exe文件,保证编译是最新的;;)

上面这个流程图介绍了当我们需要take training follow-up的时候,我们需要在sharepoint Desinger中设置工作流,来完成这些功能,但是现在遇到一个问题,workflow的触发是由于登录页面的用户log一条item记录的时候触发的,如果我们要实现邮件的定时提醒功能,那么就需要在每天都触发执行一次workflow,但是由谁来触发呢?刚开始网上搜了很多资料,内网 外网资料都搜了一圈,好不容易看到一个帖子说可以实现,但最后试着用workflow来解决,但是始终行不通,就算让它执行个15分钟,过了会儿就会挂掉。我估计系统可能开着这个线程太占用系统资源了。最终逼不得已才决定使用web service来解决这个问题,但是问题又来了,对于Java还算了解,但是对C#还是完全陌生,如果采用C#来做这个定时发送邮件的功能的话,带来的risk无法估量,而且极有可能造成project的delay,所以在前期的决策上,试着采用了Java做了一部分调研,但是考虑到公司的sharepoint是部署位置及其Java与windows底层通信协议可能带来的risk:项目进行到后期,极有可能无法完成,所以最终决定用C#来实现这个功能。。

该学习的技术还是要学的,你越逃避的事情,它越会找上你。所以,学习新技术也要趁早,等你的项目中需要用到的时候,你已经可以游刃有余了。

如上,为C#程序中要实现的逻辑。程序的整体实现逻辑是这样的。我们取出list列表,然后进行过滤,当满足我们的要求的时候,我们发邮件,然后做一些异常处理。Servic.cs代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Xml;
using System.Timers;
using System.Configuration;

//using System.Web.Mail;
using System.Net.Mail;


namespace SharePointWorklow
{
    public partial class Service1 : ServiceBase
    {
        //static private long FIVE_DAYS = 432000000L;
        public Service1()
        {
            InitializeComponent();
        }

        public void Debug(string[] args)
        {
            this.OnStart(args);
        }

        protected override void OnStart(string[] args)
        {
            //Debugger.Launch();
            System.Timers.Timer TimeCheck = new System.Timers.Timer();
            TimeCheck.Interval = Double.Parse(ConfigurationSettings.AppSettings["INTERVAL"]);
            //TimeCheck.Interval = 60000;
            TimeCheck.Elapsed += new System.Timers.ElapsedEventHandler(timer1_Tick);
            TimeCheck.AutoReset = true;
            TimeCheck.Enabled = true;
            timer1_Tick(this, ElapsedEventArgs.Empty);
            TimeCheck.Start();

        }

        public static String MailBody(XmlNode node, Double delayDays)
        {
            String URL = @"http://ent261.sharepoint.hp.com/teams/jupiter_2/Lists/Training%20Record%20FY14/MyItems.aspx";
            String start = "Congratulations for completing your training course: \n\nCourse Name: " + node.Attributes["ows_LinkTitle"].Value + ";\n";
            String time = "Time: " + node.Attributes["ows_CreateTime"].Value;
            if (node.Attributes["ows_End_x0020_Time_x0020_of_x0020_Tr"] != null)
            {
                time = "From: " + node.Attributes["ows_CreateTime"].Value + "; \nTo: " + node.Attributes["ows_End_x0020_Time_x0020_of_x0020_Tr"].Value + ";\n\n";
            }

            String mention = "We mentioned you have not finished your follow-up with your PL for " + (int)delayDays + " days.\n";
            String end = "Please check this link for finishing the following up of this course: \n";
            String mailBody = start + time + mention + end + URL;

            return mailBody;
        }

        /*
        public static void SendE_Mail(XmlNode node, Double day, String name, String ccName, String fromName)
        {
            String time = "Time: " + node.Attributes["ows_CreateTime"].Value;
            String deadline = "";
            String deadline1 = "";
            if (node.Attributes["ows_End_x0020_Time_x0020_of_x0020_Tr"] != null)   //未修改过的training按照end time计算deadline
            {
                DateTime a = Convert.ToDateTime(node.Attributes["ows_End_x0020_Time_x0020_of_x0020_Tr"].Value).AddDays(42);
                DateTime b= new DateTime(2015,3,31);
                if (Convert.ToDateTime(node.Attributes["ows_End_x0020_Time_x0020_of_x0020_Tr"].Value) < new DateTime(2015,4,1) && Convert.ToDateTime(node.Attributes["ows_End_x0020_Time_x0020_of_x0020_Tr"].Value) > new DateTime(2015, 3, 1))
                {   //判断training是否是3月-4月的training
                    a = b.AddDays(42);
                }
                deadline = "<b>before " + a.ToShortDateString().ToString() + @" </b>";
                deadline1 = "before " + a.ToShortDateString().ToString() + @"";
                time = "From: <b>" + node.Attributes["ows_CreateTime"].Value + "</b> to: <b>" + node.Attributes["ows_End_x0020_Time_x0020_of_x0020_Tr"].Value + "</b><Br /><Br />";
            }
            if(node.Attributes["ows_Update_x0020_Date"] != null)    //修改过的training按照修改日期计算deadline
            {
                if (Convert.ToDateTime(node.Attributes["ows_Update_x0020_Date"].Value) > Convert.ToDateTime(node.Attributes["ows_End_x0020_Time_x0020_of_x0020_Tr"].Value))
                {
                    DateTime a = Convert.ToDateTime(node.Attributes["ows_Update_x0020_Date"].Value).AddDays(21);
                    //Console.WriteLine(a.ToShortDateString());
                    deadline = "<b>before " + a.ToShortDateString().ToString() + @" </b>";
                    deadline1 = "before " + a.ToShortDateString().ToString() + @"";
                }               
            }
            //string ls_Subject = "" + (String)k2 + ", " + (String)k1 + @" Takes " + node.Attributes["ows_LinkTitle"].Value + @"";
            string ls_Subject = "" + node.Attributes["ows_LinkTitle"].Value + @"Training Follow-up Reminder: Required Completion Date "+ deadline1 +@"";
            SmtpMail.SmtpServer = "smtp-americas.hp.com";

            MailMessage lo_Message = new MailMessage();
            lo_Message.From = "[email protected]";
            //lo_Message.To = node.Attributes["ows_Name"].Value.Substring(node.Attributes["ows_Name"].Value.IndexOf('#') + 1);
            lo_Message.Cc = "[email protected]";
            lo_Message.Subject = ls_Subject;
            lo_Message.Priority = MailPriority.High;
            lo_Message.Body =
            @"<html>
                <body>
                <table border='0'>
                    <tr>
                        <font face='HP Simplified' size='小四'><td>Hello " + (String)name + @"</td></font>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <font face='HP Simplified' size='小四'>
                        <td>This is a kind reminder that you have not completed your training follow-up with your PM for <b>" + (int)day + @" days</b>.Please follow the link below and take actions " + deadline + @". </td>
                        </font>                    
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <font face='HP Simplified' size='小四'>
                        <td>Course Name: <b>" + node.Attributes["ows_LinkTitle"].Value + @"</b></td>
                        </font>
                    </tr>
                    <tr><font face='HP Simplified' size='小四'><td>" + time + @"</td></font>
                    </tr>  
                    <tr>
                        <td><a href=" + @"http://ent261.sharepoint.hp.com/teams/jupiter_2/Lists/Training%20Record%20FY14/MyItems.aspx" + @"><font color='blue' face='HP Simplified' size='小四'>My Training Items</font></a></td>
                    </tr>
                    <tr>
                    <font color='blue' face='HP Simplified' size='小四'>*Complete training follow-up in time is a mandatory action, according to Jupiter ground rules*</font>
                    </tr>
                    <br/><br/><br/><br/>
                        </td>
                            <font color='red' face='HP Simplified' size='小四'>FROM<br/>" + (String)fromName + @"</font>
                        </td>
                        <br/>
                        </td>
                            <font color='red' face='HP Simplified' size='小四'>TO<br/>" + (String)fromName + @"</font>
                        </td>
                        <br/>
                        </td>
                            <font color='red' face='HP Simplified' size='小四'>CC<br/>" + (String)ccName + @"</font>
                        </td>
                    </tr>
                </table>
                </body>
            </html>";
            lo_Message.BodyEncoding = System.Text.Encoding.UTF8;
            lo_Message.BodyFormat = MailFormat.Html;
            SmtpMail.Send(lo_Message);
        }

        public static void SendE_Mail_Second(XmlNode node, Double day, String name, String ccName, String fromName)
        {                    
            string ls_Subject = "" + node.Attributes["ows_LinkTitle"].Value + @" Training Follow-up Final Notification";
            String time = "Time: " + node.Attributes["ows_CreateTime"].Value;
            String deadline = "";
            if (node.Attributes["ows_End_x0020_Time_x0020_of_x0020_Tr"] != null)   //未修改过的training按照end time计算deadline
            {
                DateTime a = Convert.ToDateTime(node.Attributes["ows_End_x0020_Time_x0020_of_x0020_Tr"].Value).AddDays(42);
                DateTime b= new DateTime(2015,3,31);
                if (Convert.ToDateTime(node.Attributes["ows_End_x0020_Time_x0020_of_x0020_Tr"].Value)<=new DateTime(2015,3,31))
                {
                      a = b.AddDays(42); 
                }
                deadline = "<b>before " + a.ToShortDateString().ToString() + @" </b>";
                time = "From: <b>" + node.Attributes["ows_CreateTime"].Value + "</b> to: <b>" + node.Attributes["ows_End_x0020_Time_x0020_of_x0020_Tr"].Value + "</b><Br /><Br />";
            }
            if (node.Attributes["ows_Update_x0020_Date"] != null)    //修改过的training按照修改日期计算deadline
            {
                if (Convert.ToDateTime(node.Attributes["ows_Update_x0020_Date"].Value) > Convert.ToDateTime(node.Attributes["ows_End_x0020_Time_x0020_of_x0020_Tr"].Value))
                {
                    DateTime a = Convert.ToDateTime(node.Attributes["ows_Update_x0020_Date"].Value).AddDays(21);
                    //Console.WriteLine(a.ToShortDateString());
                    deadline = "<b>before " + a.ToShortDateString().ToString() + @" </b>";
                }    
            } 
            SmtpMail.SmtpServer = "smtp-americas.hp.com";
            
            MailMessage lo_Message = new MailMessage();
            lo_Message.From = "[email protected]";
            lo_Message.Cc = "[email protected]";
            lo_Message.Subject = ls_Subject;
            lo_Message.Priority = MailPriority.High;
            lo_Message.Body =
            @"<html>
                <body>
                <table border='0'>
                    <tr>
                        <font face='HP Simplified' size='小四'><td>Hello " + (String)name + @"</td></font>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <font face='HP Simplified' size='小四'>
                        <td>This is a kind reminder that you have not completed your training follow-up action with your PM " + deadline + @".</td>
                        </font>
                       </tr>               
                    <tr>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <font face='HP Simplified' size='小四'>
                        <td>Course Name: <b>" + node.Attributes["ows_LinkTitle"].Value + @"</b></td>
                        </font>
                    </tr>
                    <tr>
                        <font face='HP Simplified' size='小四'>
                        time " + time + @"
                        </font>
                    </tr>                  
                    <tr>
                        <td><a href=" + @"http://ent261.sharepoint.hp.com/teams/jupiter_2/Lists/Training%20Record%20FY14/MyItems.aspx" + @"><font color='blue' face='HP Simplified' size='小四'>My Training Items</font></a></td>
                    </tr>
                    <tr>
                        <td>
                            <font color='blue' face='HP Simplified' size='小四'>*Complete training follow-up in time is a mandatory action, according to Jupiter ground rules*</font>
                        </td>
                        <br/><br/><br/><br/>
                        </td>
                            <font color='red' face='HP Simplified' size='小四'>FROM<br/>" + (String)fromName + @"</font>
                        </td>
                        <br/>
                        </td>
                            <font color='red' face='HP Simplified' size='小四'>TO<br/>" + (String)fromName + @"</font>
                        </td>
                        <br/>
                        </td>
                            <font color='red' face='HP Simplified' size='小四'>CC<br/>" + (String)ccName + @"</font>
                        </td>
                    </tr>
                </table>
                </body>
            </html>";
            lo_Message.BodyEncoding = System.Text.Encoding.UTF8;
            lo_Message.BodyFormat = MailFormat.Html;
            SmtpMail.Send(lo_Message);
        }
          
         protected override void OnStop()
        {
            string ls_Subject = "Training Course Reminding Service Shut Down";
            SmtpMail.SmtpServer = "smtp-americas.hp.com";

            MailMessage lo_Message = new MailMessage();
            lo_Message.From = "[email protected]";
            lo_Message.To = "[email protected]";
            lo_Message.Cc = "[email protected]";
            lo_Message.Subject = ls_Subject;
            lo_Message.Priority = MailPriority.High;
            lo_Message.Body =
            @"<html>
                <body>
                <table border='0'>
                    <tr>
                            <td>Hello,</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                            <td>This is a kind reminder that the training course reminding service has been shut down;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                            <td>Please review with PM if need it restart</td>
                    </tr>
                </table>
                </body>
            </html>";
            lo_Message.BodyEncoding = System.Text.Encoding.UTF8;
            lo_Message.BodyFormat = MailFormat.Html;
            SmtpMail.Send(lo_Message);
        }
        */

        public static void SendE_Mail(XmlNode node, Double day, String name, String ccName, String fromName)
        {
            String time = "Time: " + node.Attributes["ows_CreateTime"].Value;
            String deadline = "";
            String deadline1 = "";
            if (node.Attributes["ows_End_x0020_Time_x0020_of_x0020_Tr"] != null)   //未修改过的training按照end time计算deadline
            {
                DateTime a = Convert.ToDateTime(node.Attributes["ows_End_x0020_Time_x0020_of_x0020_Tr"].Value).AddDays(42);
                DateTime b = new DateTime(2015, 3, 31);
                if (Convert.ToDateTime(node.Attributes["ows_End_x0020_Time_x0020_of_x0020_Tr"].Value) < new DateTime(2015, 4, 1) && Convert.ToDateTime(node.Attributes["ows_End_x0020_Time_x0020_of_x0020_Tr"].Value) > new DateTime(2015, 3, 1))
                {   //判断training是否是3月-4月的training
                    a = b.AddDays(42);
                }
                //deadline = "<b>before " + a.ToShortDateString().ToString() + @" </b>";
                deadline = "<b>before " + a.Year.ToString() + @"-" + a.Month.ToString() + @"-" + a.Day.ToString() + @" </b>";


                //deadline1 = "before " + a.ToShortDateString().ToString() + @"";
                deadline1 = "Before " + a.Year.ToString() + @"-" + a.Month.ToString() + @"-" + a.Day.ToString() + @"";

                time = "<font color='black' face='HP Simplified' size='小六'>·</font>&nbsp;From <b>" + @"<font style='font-weight:normal'>" + node.Attributes["ows_CreateTime"].Value + @"</font>" + @"</b> to <b>" + @"<font style='font-weight:normal'>" + node.Attributes["ows_End_x0020_Time_x0020_of_x0020_Tr"].Value + @"</font>" + @"</b><Br />";
            }
            if (node.Attributes["ows_Update_x0020_Date"] != null)    //修改过的training按照修改日期计算deadline
            {
                if (Convert.ToDateTime(node.Attributes["ows_Update_x0020_Date"].Value) > Convert.ToDateTime(node.Attributes["ows_End_x0020_Time_x0020_of_x0020_Tr"].Value))
                {
                    DateTime a = Convert.ToDateTime(node.Attributes["ows_Update_x0020_Date"].Value).AddDays(21);
                    //Console.WriteLine(a.ToShortDateString());
                    //deadline = "<b>before " + a.ToShortDateString().ToString() + @" </b>";
                    deadline = "<b>before " + a.Year.ToString() + @"-" + a.Month.ToString() + @"-" + a.Day.ToString() + @" </b>";
                    //deadline1 = "before " + a.ToShortDateString().ToString() + @"";
                    deadline1 = "Before " + a.Year.ToString() + @"-" + a.Month.ToString() + @"-" + a.Day.ToString() + @"";
                }
            }

            string ls_Subject = "" + node.Attributes["ows_LinkTitle"].Value + @"Training Follow-up Reminder: Required Completion Date " + deadline1 + @"";

            MailMessage mailMsg = new MailMessage();
            mailMsg.From = new MailAddress("[email protected]");
            mailMsg.To.Add(fromName);
            mailMsg.CC.Add(ConfigurationSettings.AppSettings["PM"]);
            if (ccName != null) 
            {
                mailMsg.CC.Add(ccName);
            }
            
            mailMsg.Subject = ls_Subject;
            mailMsg.BodyEncoding = Encoding.UTF8;
            mailMsg.IsBodyHtml = true; 
            mailMsg.Priority = MailPriority.High;
            mailMsg.Body =
            @"<html>
                <body>
                <table border='0'>
                    <tr>
                        <font face='HP Simplified' size='小四'><td>Hello " + (String)name + @"</td></font>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <font face='HP Simplified' size='小四'>
                        <td>This is a kind reminder that you have not completed your training follow-up with your PM for <b>" + (int)day + @" days</b>. Please follow the link below and take actions " + deadline + @". </td>
                        </font>                    
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <font face='HP Simplified' size='小四'>
                        
                        <td><font color='black' face='HP Simplified' size='小六'>·</font>&nbsp;Course Name: <b>" + @"<font style='font-weight:normal'>" + node.Attributes["ows_LinkTitle"].Value + @"</font>" + @"</b></td>
                        </font>
                    </tr>
                    <tr><font face='HP Simplified' size='小四'><td>" + time + @"</td></font>
                    </tr>  
                    <tr>
                        <td><font color='black' face='HP Simplified' size='小六'>·</font>&nbsp;<a href=" + @"http://ent261.sharepoint.hp.com/teams/jupiter_2/Lists/Training%20Record%20FY14/MyItems.aspx" + @"><font color='#0096D6' face='HP Simplified' size='小四'>My Training Items</font></a></td>
                    </tr>
                    <tr>
                    <font color='#0096D6' face='HP Simplified' size='小四'><Br /><i>*Complete training follow-up in time is a mandatory action, according to Jupiter ground rules*</i></font>
                    </tr>       
                </table>
                </body>
            </html>";
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp-americas.hp.com";
            smtp.Send(mailMsg);
        }
        
        public static void SendE_Mail_Second(XmlNode node, Double day, String name, String ccName, String fromName)
        {
            string ls_Subject = "" + node.Attributes["ows_LinkTitle"].Value + @" Training Follow-up Final Notification";
            String time = "Time: " + node.Attributes["ows_CreateTime"].Value;
            String deadline = "";
            if (node.Attributes["ows_End_x0020_Time_x0020_of_x0020_Tr"] != null)   //未修改过的training按照end time计算deadline
            {
                DateTime a = Convert.ToDateTime(node.Attributes["ows_End_x0020_Time_x0020_of_x0020_Tr"].Value).AddDays(42);
                DateTime b = new DateTime(2015, 3, 31);
                if (Convert.ToDateTime(node.Attributes["ows_End_x0020_Time_x0020_of_x0020_Tr"].Value) <= new DateTime(2015, 3, 31))
                {
                    a = b.AddDays(42);
                }
                //deadline = "<b>before " + a.ToShortDateString().ToString() + @" </b>";
                deadline = "<b>before " + a.Year.ToString() + @"-" + a.Month.ToString() + @"-" + a.Day.ToString() + @" </b>";

                time = "<font color='black' face='HP Simplified' size='小六'>·</font>&nbsp;From <b>" + @"<font style='font-weight:normal'>" + node.Attributes["ows_CreateTime"].Value + @"</font>" + @"</b> to <b>" + @"<font style='font-weight:normal'>" + node.Attributes["ows_End_x0020_Time_x0020_of_x0020_Tr"].Value + @"</font>" + "</b><Br />";


                //Console.WriteLine("deadline"+deadline);
                //Console.WriteLine("a"+a);
                //Console.WriteLine("a.ToString()"+a.ToString());
                //Console.WriteLine("sucre style:" + a.Year+"-"+a.Month+"-"+a.Day);

            }
            if (node.Attributes["ows_Update_x0020_Date"] != null)    //修改过的training按照修改日期计算deadline
            {
                if (Convert.ToDateTime(node.Attributes["ows_Update_x0020_Date"].Value) > Convert.ToDateTime(node.Attributes["ows_End_x0020_Time_x0020_of_x0020_Tr"].Value))
                {
                    DateTime a = Convert.ToDateTime(node.Attributes["ows_Update_x0020_Date"].Value).AddDays(21);
                    //Console.WriteLine(a.ToShortDateString());
                    //deadline = "<b>before " + a.ToShortDateString().ToString() + @" </b>";
                    deadline = "<b>before " + a.Year.ToString() + @"-" + a.Month.ToString() + @"-" + a.Day.ToString() + @" </b>";
                }
            }

            

            MailMessage mailMsg = new MailMessage();
            mailMsg.From = new MailAddress("[email protected]");
            mailMsg.To.Add(fromName);
            mailMsg.CC.Add(ConfigurationSettings.AppSettings["PM"]);           
            if (ccName != null)
            {
                mailMsg.CC.Add(ccName);
            }
            mailMsg.Subject = ls_Subject;
            mailMsg.BodyEncoding = Encoding.UTF8;
            mailMsg.IsBodyHtml = true;
            mailMsg.Priority = MailPriority.High;
            mailMsg.Body =
            @"<html>
                <body>
                <table border='0'>
                    <tr>
                        <font face='HP Simplified' size='小四'><td>Hello " + (String)name + @"</td></font>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <font face='HP Simplified' size='小四'>
                        <td>This is a kind reminder that you have not completed your training follow-up action with your PM " + deadline + @".</td>
                        </font>
                       </tr>               
                    <tr>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <font face='HP Simplified' size='小四'>
                        <td><font color='black' face='HP Simplified' size='小六'>·</font>&nbsp;Course Name: <b>" + @"<font style='font-weight:normal'>" + node.Attributes["ows_LinkTitle"].Value + @"</font>" + @"</b></td>
                        </font>
                    </tr>
                    <tr>
                        <font face='HP Simplified' size='小四'><td>" + time + @"</td></font>
                    </tr>                
                    <tr>                       
                        <td><font color='black' face='HP Simplified' size='小六'>·</font>&nbsp;<a href=" + @"http://ent261.sharepoint.hp.com/teams/jupiter_2/Lists/Training%20Record%20FY14/MyItems.aspx" + @"><font color='#0096D6' face='HP Simplified' size='小四'>My Training Items</font></a></td>
                    </tr>
                    <tr>
                        <td>
                            <font color='#0096D6' face='HP Simplified' size='小四'><Br /><i>*Complete training follow-up in time is a mandatory action, according to Jupiter ground rules*</i></font>
                        </td>
                    </tr>
                </table>
                </body>
            </html>";
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp-americas.hp.com";
            smtp.Send(mailMsg);
        }
        

        protected override void OnStop()
        {
            string ls_Subject = "Training Course Reminding Service Shut Down";

            MailMessage mailMsg = new MailMessage();
            mailMsg.From = new MailAddress("[email protected]");
            mailMsg.To.Add("[email protected]");
            mailMsg.CC.Add("[email protected]");
            mailMsg.Subject = ls_Subject;
            mailMsg.Priority = MailPriority.High;
            mailMsg.Body =
            @"<html>
                <body>
                <table border='0'>
                    <tr>
                            <font color='black' face='HP Simplified' size='小四'>
                            <td>Hello Zhao, Xu-Guang (Sucre, SSIT),</td>
                            </font>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                            <font color='red' face='HP Simplified' size='小四'>
                            <td>This is a kind reminder that the training course reminding service has been shut down;</td>
                            </font>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                            <font color='black' face='HP Simplified' size='小四'>
                            <td>Please review with PM if need it restart.</td>
                            </font>
                    </tr>
                </table>
                </body>
            </html>";
            mailMsg.BodyEncoding = Encoding.UTF8;
            mailMsg.IsBodyHtml = true;
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp-americas.hp.com";
            smtp.Send(mailMsg);
        }

        public void timer1_Tick(object sender, EventArgs e)
        {
            KMService.Lists lists = new KMService.Lists();
            lists.Url = "http://ent261.sharepoint.hp.com/teams/jupiter_2/_vti_bin/Lists.asmx";
            
            lists.Credentials = CredentialCache.DefaultCredentials;
            XmlNode nodelistitems = null;
            // AllItem viewName = 728101AF-6727-430B-9220-35304FC7A3E5
            nodelistitems = lists.GetListItems("8C851226-1615-44E0-B98E-08718E772D04", "728101AF-6727-430B-9220-35304FC7A3E5", null, null, "", null, null);

            //nodelistitems = lists.GetListItems("8C851226-1615-44E0-B98E-08718E772D04", null, null, null, "", null, null);

            XmlNode rsData = nodelistitems["rs:data"];
            // ows_CreateTime = start time
            // ows_End_x0020_Time_x0020_of_x0020_Tr = end time
          
                foreach (XmlNode zRow in rsData.ChildNodes)
                {
                    if (zRow.GetType().Name.ToString() != "XmlWhitespace")
                    {
                        
                        if(zRow.Attributes["ows_CreateTime"]!=null){
                            if (Convert.ToDateTime(zRow.Attributes["ows_CreateTime"].Value) >= new DateTime(2015, 3, 1))
                            {    
                                //判断Log training日期是否为3月1号之后
                                if (zRow.Attributes["ows_Follow_x002d_up_x0020_needed"] != null)
                                {
                                    //Console.WriteLine(zRow.OuterXml); 
                                    if ((zRow.Attributes["ows_Follow_x002d_up_x0020_needed"].Value == "Y"
                                    || zRow.Attributes[" 
                       
                    
                    

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C#开源实现MJPEG流传输发布时间:2022-07-10
下一篇:
一个21行C#代码实现的神经网络发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap