Пример #1
0
        //////////////////////////////////////////////////////////////////////
        /// <summary>Parses an xml node to create a Reminder object.</summary>
        /// <param name="node">the node to parse node</param>
        /// <param name="parser">the xml parser to use if we need to dive deeper</param>
        /// <returns>the created Reminder object</returns>
        //////////////////////////////////////////////////////////////////////
        public IExtensionElementFactory CreateInstance(XmlNode node, AtomFeedParser parser)
        {
            Tracing.TraceCall();
            Reminder reminder = null;

            if (node != null)
            {
                object localname = node.LocalName;
                if (!localname.Equals(this.XmlName) ||
                    !node.NamespaceURI.Equals(this.XmlNameSpace))
                {
                    return(null);
                }
            }

            reminder = new Reminder();
            if (node != null && node.Attributes != null)
            {
                if (node.Attributes[GDataParserNameTable.XmlAttributeAbsoluteTime] != null)
                {
                    try
                    {
                        reminder.AbsoluteTime =
                            DateTime.Parse(node.Attributes[GDataParserNameTable.XmlAttributeAbsoluteTime].Value);
                    }
                    catch (FormatException fe)
                    {
                        throw new ArgumentException("Invalid g:reminder/@absoluteTime.", fe);
                    }
                }

                if (node.Attributes[GDataParserNameTable.XmlAttributeDays] != null)
                {
                    try
                    {
                        reminder.Days = Int32.Parse(node.Attributes[GDataParserNameTable.XmlAttributeDays].Value);
                    }
                    catch (FormatException fe)
                    {
                        throw new ArgumentException("Invalid g:reminder/@days.", fe);
                    }
                }

                if (node.Attributes[GDataParserNameTable.XmlAttributeHours] != null)
                {
                    try
                    {
                        reminder.Hours = Int32.Parse(node.Attributes[GDataParserNameTable.XmlAttributeHours].Value);
                    }
                    catch (FormatException fe)
                    {
                        throw new ArgumentException("Invalid g:reminder/@hours.", fe);
                    }
                }

                if (node.Attributes[GDataParserNameTable.XmlAttributeMinutes] != null)
                {
                    try
                    {
                        reminder.Minutes = Int32.Parse(node.Attributes[GDataParserNameTable.XmlAttributeMinutes].Value);
                    }
                    catch (FormatException fe)
                    {
                        throw new ArgumentException("Invalid g:reminder/@minutes.", fe);
                    }
                }

                if (node.Attributes[GDataParserNameTable.XmlAttributeMethod] != null)
                {
                    try
                    {
                        reminder.Method = (ReminderMethod)Enum.Parse(typeof(ReminderMethod),
                                                                     node.Attributes[GDataParserNameTable.XmlAttributeMethod].Value,
                                                                     true);
                    }
                    catch (Exception e)
                    {
                        throw new ArgumentException("Invalid g:reminder/@method.", e);
                    }
                }
            }
            return(reminder);
        }
Пример #2
0
        //////////////////////////////////////////////////////////////////////
        /// <summary>Parses an xml node to create a Where  object.</summary>
        /// <param name="node">the node to parse node</param>
        /// <param name="parser">the xml parser to use if we need to dive deeper</param>
        /// <returns>the created Where  object</returns>
        //////////////////////////////////////////////////////////////////////
        public IExtensionElementFactory CreateInstance(XmlNode node, AtomFeedParser parser)
        {
            Tracing.TraceCall();
            When when = null;

            if (node != null)
            {
                object localname = node.LocalName;
                if (!localname.Equals(this.XmlName) ||
                    !node.NamespaceURI.Equals(this.XmlNameSpace))
                {
                    return(null);
                }
            }

            bool startTimeFlag = false, endTimeFlag = false;

            when = new When();
            if (node != null)
            {
                if (node.Attributes != null)
                {
                    String value = node.Attributes[GDataParserNameTable.XmlAttributeStartTime] != null ?
                                   node.Attributes[GDataParserNameTable.XmlAttributeStartTime].Value : null;
                    if (value != null)
                    {
                        startTimeFlag  = true;
                        when.startTime = DateTime.Parse(value);
                        when.AllDay    = (value.IndexOf('T') == -1);
                    }

                    value = node.Attributes[GDataParserNameTable.XmlAttributeEndTime] != null ?
                            node.Attributes[GDataParserNameTable.XmlAttributeEndTime].Value : null;

                    if (value != null)
                    {
                        endTimeFlag  = true;
                        when.endTime = DateTime.Parse(value);
                        when.AllDay  = when.AllDay && (value.IndexOf('T') == -1);
                    }

                    if (node.Attributes[GDataParserNameTable.XmlAttributeValueString] != null)
                    {
                        when.valueString = node.Attributes[GDataParserNameTable.XmlAttributeValueString].Value;
                    }
                }
                // single event, g:reminder is inside g:when
                if (node.HasChildNodes)
                {
                    XmlNode whenChildNode      = node.FirstChild;
                    IExtensionElementFactory f = new Reminder() as IExtensionElementFactory;
                    while (whenChildNode != null)
                    {
                        if (whenChildNode is XmlElement)
                        {
                            if (String.Compare(whenChildNode.NamespaceURI, f.XmlNameSpace, true, CultureInfo.InvariantCulture) == 0)
                            {
                                if (String.Compare(whenChildNode.LocalName, f.XmlName, true, CultureInfo.InvariantCulture) == 0)
                                {
                                    Reminder r = f.CreateInstance(whenChildNode, null) as Reminder;
                                    when.Reminders.Add(r);
                                }
                            }
                        }
                        whenChildNode = whenChildNode.NextSibling;
                    }
                }
            }

            if (!startTimeFlag)
            {
                throw new ClientFeedException("g:when/@startTime is required.");
            }

            if (endTimeFlag && when.startTime.CompareTo(when.endTime) > 0)
            {
                throw new ClientFeedException("g:when/@startTime must be less than or equal to g:when/@endTime.");
            }

            return(when);
        }