示例#1
0
        /// <summary>
        /// 从XML文件中读取Interval的值
        /// </summary>
        /// <param name="str">一个xml字符串</param>
        /// <returns></returns>
        public static REPEATINTERVAL GetRepeatInfo(string str)
        {
            REPEATINTERVAL interval = new REPEATINTERVAL();
            XmlDocument    doc      = new XmlDocument();

            doc.LoadXml(str);
            XmlNode      node;
            XmlElement   element;
            XmlAttribute attr;

            //选择指定的节点
            node           = doc.SelectSingleNode("/RepeatInterval/Daily");
            interval.Daily = bool.Parse(node.InnerText);

            node          = doc.SelectSingleNode("/RepeatInterval/Once");
            interval.Once = bool.Parse(node.InnerText);

            //选择属性,Weekly包含一个名为Status的属性
            node            = doc.SelectSingleNode("/RepeatInterval/Weekly");
            element         = (XmlElement)node;
            attr            = element.GetAttributeNode("Status");
            interval.Weekly = bool.Parse(attr.InnerText);

            node             = doc.SelectSingleNode("/RepeatInterval/Monthly");
            element          = (XmlElement)node;
            attr             = element.GetAttributeNode("Status");
            interval.Monthly = bool.Parse(attr.InnerText);

            node = doc.SelectSingleNode("/RepeatInterval/Monthly/DayOfMonth");
            interval.DayOfMonth = int.Parse(node.InnerText);

            node            = doc.SelectSingleNode("/RepeatInterval/Weekly/Monday");
            interval.Monday = bool.Parse(node.InnerText);

            node             = doc.SelectSingleNode("/RepeatInterval/Weekly/Tuesday");
            interval.Tuesday = bool.Parse(node.InnerText);

            node = doc.SelectSingleNode("/RepeatInterval/Weekly/Wednesday");
            interval.Wednesday = bool.Parse(node.InnerText);

            node = doc.SelectSingleNode("/RepeatInterval/Weekly/Thursday");
            interval.Thursday = bool.Parse(node.InnerText);

            node            = doc.SelectSingleNode("/RepeatInterval/Weekly/Friday");
            interval.Friday = bool.Parse(node.InnerText);

            node = doc.SelectSingleNode("/RepeatInterval/Weekly/Saturday");
            interval.Saturday = bool.Parse(node.InnerText);

            node            = doc.SelectSingleNode("/RepeatInterval/Weekly/Sunday");
            interval.Sunday = bool.Parse(node.InnerText);
            return(interval);
        }
示例#2
0
        /// <summary>
        /// 将RepeatInterval结构体写入字符串
        /// </summary>
        /// <param name="interval"></param>
        /// <returns></returns>
        public static string GetRepeatIntervalString(REPEATINTERVAL interval)
        {
            string result = "<?xml version=\"1.0\" encoding=\"utf-8\"?><RepeatInterval><Once>" +
                            interval.Once + "</Once>" + "<Monthly Status=\"" + interval.Monthly + "\"><DayOfMonth>" +
                            (interval.Monthly == true ? interval.DayOfMonth : 0) + "</DayOfMonth></Monthly>" +
                            "<Daily>" + interval.Daily + "</Daily><Weekly Status=\"" + interval.Weekly + "\"><Monday>" +
                            interval.Monday + "</Monday><Tuesday>" + interval.Tuesday + "</Tuesday><Wednesday>" +
                            interval.Wednesday + "</Wednesday><Thursday>" + interval.Thursday + "</Thursday><Friday>" +
                            interval.Friday + "</Friday><Saturday>" + interval.Saturday + "</Saturday><Sunday>" +
                            interval.Sunday + "</Sunday></Weekly></RepeatInterval>";

            return(result);
        }