コード例 #1
0
        /// <summary>
        /// Creates a data-form instance of the proper type from the specified
        /// XML element.
        /// </summary>
        /// <param name="element">The XML element to create the data-form instance
        /// from.</param>
        /// <returns>An initialized instance of a data-form class of the respectiv
        /// type which derives from the DataForm base class.</returns>
        /// <exception cref="ArgumentNullException">The element parameter is
        /// null.</exception>
        /// <exception cref="ArgumentException">The specified XML element is not a
        /// valid data-form element.</exception>
        public static DataForm Create(XmlElement element)
        {
            element.ThrowIfNull("element");
            if (element.Name != "x" || element.NamespaceURI != "jabber:x:data")
                throw new ArgumentException("Invalid root element: " + element.Name);
            string s = element.GetAttribute("type");
            if (String.IsNullOrEmpty(s))
                throw new ArgumentException("Missing 'type' attribute.");
            try
            {
                DataFormType type = Util.ParseEnum<DataFormType>(s);
                switch (type)
                {
                    case DataFormType.Form:
                        return new RequestForm(element);

                    case DataFormType.Submit:
                        return new SubmitForm(element);

                    case DataFormType.Cancel:
                        return new CancelForm(element);

                    case DataFormType.Result:
                        return new ResultForm(element);

                    default:
                        throw new ArgumentException("Invalid form type: " + type);
                }
            }
            catch (Exception e)
            {
                throw new XmlException("Invalid data-form element.", e);
            }
        }
コード例 #2
0
		/// <summary>
		/// Parses the the specified negotiation offer or result.
		/// </summary>
		/// <param name="feature">The 'feature' element containing the data-form</param>
		/// <returns>An initialized data-form instance.</returns>
		/// <exception cref="ArgumentNullException">The feature parameter is
		/// null.</exception>
		/// <exception cref="ArgumentException">The feature parameter is not a
		/// valid 'feature' XML element, or the feature element contains invalid
		/// data.</exception>
		public static DataForm Parse(XmlElement feature) {
			feature.ThrowIfNull("feature");
			if (feature.Name != "feature" || feature.NamespaceURI !=
				"http://jabber.org/protocol/feature-neg" || feature["x"] == null) {
					throw new ArgumentException("Invalid XML 'feature' element.");
			}
			return DataFormFactory.Create(feature["x"]);
		}
コード例 #3
0
ファイル: Posts.cs プロジェクト: summer-breeze/ChengGouHui
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="Element">Element containing post info</param>
 public Posts(XmlElement Element)
 {
     Element.ThrowIfNull("Element");
     PostList = new List<Post>();
     foreach (XmlNode Children in Element.ChildNodes)
     {
         if (Children.Name.Equals("post", StringComparison.CurrentCultureIgnoreCase))
             PostList.Add(new Post((XmlElement)Children));
     }
 }
コード例 #4
0
ファイル: Tags.cs プロジェクト: JKLFA/Craig-s-Utility-Library
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="Element">Element containing tags info</param>
 public Tags(XmlElement Element)
 {
     Element.ThrowIfNull("Element");
     TagList = new List<Tag>();
     foreach (XmlNode Children in Element.ChildNodes)
     {
         if (Children.Name.Equals("tag", StringComparison.CurrentCultureIgnoreCase))
             TagList.Add(new Tag((XmlElement)Children));
     }
 }
コード例 #5
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="Element">Categories element</param>
 public Categories(XmlElement Element)
 {
     Element.ThrowIfNull("Element");
     CategoryList = new List<Category>();
     foreach (XmlNode Children in Element.ChildNodes)
     {
         if (Children.Name.Equals("category", StringComparison.CurrentCultureIgnoreCase))
             CategoryList.Add(new Category((XmlElement)Children));
     }
 }
コード例 #6
0
 public Authors(XmlElement Element)
 {
     Element.ThrowIfNull("Element");
     AuthorList = new List<Author>();
     foreach (XmlNode Children in Element.ChildNodes)
     {
         if (Children.Name.Equals("author", StringComparison.CurrentCultureIgnoreCase))
             AuthorList.Add(new Author((XmlElement)Children));
     }
 }
コード例 #7
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="Element">XML element containing the author info</param>
 public Author(XmlElement Element)
 {
     Element.ThrowIfNull("Element");
     ID = Element.Attributes["id"] != null ? Element.Attributes["id"].Value : "";
     Email = Element.Attributes["email"] != null ? Element.Attributes["email"].Value : "";
     REF = Element.Attributes["ref"] != null ? Element.Attributes["ref"].Value : "";
     foreach (XmlNode Children in Element.ChildNodes)
     {
         if (Children.Name.Equals("title", StringComparison.CurrentCultureIgnoreCase))
             Title = Children.InnerText;
     }
 }
コード例 #8
0
ファイル: Category.cs プロジェクト: jerrymds/Concord
 public Category(XmlElement Element)
 {
     Element.ThrowIfNull("Element");
     ID = Element.Attributes["id"] != null ? Element.Attributes["id"].Value : "";
     REF = Element.Attributes["ref"] != null ? Element.Attributes["ref"].Value : "";
     DateCreated = Element.Attributes["date-created"] != null ? DateTime.Parse(Element.Attributes["date-created"].Value, CultureInfo.InvariantCulture) : DateTime.Now;
     DateModified = Element.Attributes["date-modified"] != null ? DateTime.Parse(Element.Attributes["date-modified"].Value, CultureInfo.InvariantCulture) : DateTime.Now;
     ParentREF = Element.Attributes["parentref"] != null ? Element.Attributes["parentref"].Value : "";
     foreach (XmlNode Children in Element.ChildNodes)
     {
         if (Children.Name.Equals("title", StringComparison.CurrentCultureIgnoreCase))
             Title = Children.InnerText;
     }
 }
コード例 #9
0
        public Post(XmlElement Element)
        {
            Element.ThrowIfNull("Element");
            DateCreated = DateTime.Now;
            DateModified = DateTime.Now;
            ID = Element.Attributes["id"] != null ? Element.Attributes["id"].Value : "";
            PostURL = Element.Attributes["post-url"] != null ? Element.Attributes["post-url"].Value : "";
            DateCreated = Element.Attributes["date-created"] != null ? DateTime.Parse(Element.Attributes["date-created"].Value, CultureInfo.InvariantCulture) : DateTime.MinValue;
            DateModified = Element.Attributes["date-modified"] != null ? DateTime.Parse(Element.Attributes["date-modified"].Value, CultureInfo.InvariantCulture) : DateCreated;

            foreach (XmlElement Children in Element.ChildNodes)
            {
                if (Children.Name.Equals("title", StringComparison.CurrentCultureIgnoreCase))
                {
                    Title = Children.InnerText;
                }
                else if (Children.Name.Equals("content", StringComparison.CurrentCultureIgnoreCase))
                {
                    Content = Children.InnerText;
                }
                else if (Children.Name.Equals("post-name", StringComparison.CurrentCultureIgnoreCase))
                {
                    PostName = Children.InnerText;
                }
                else if (Children.Name.Equals("excerpt", StringComparison.CurrentCultureIgnoreCase))
                {
                    Excerpt = Children.InnerText;
                }
                else if (Children.Name.Equals("authors", StringComparison.CurrentCultureIgnoreCase))
                {
                    Authors = new Authors(Children);
                }
                else if (Children.Name.Equals("categories", StringComparison.CurrentCultureIgnoreCase))
                {
                    Categories = new Categories(Children);
                }
                else if (Children.Name.Equals("tags", StringComparison.CurrentCultureIgnoreCase))
                {
                    Tags = new Tags(Children);
                }
                else if (Children.Name.Equals("comments", StringComparison.CurrentCultureIgnoreCase))
                {
                    Comments = new Comments(Children);
                }
            }
        }
コード例 #10
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="Element">Element containing the post info</param>
        public Comment(XmlElement Element)
        {
            Element.ThrowIfNull("Element");
            DateCreated = Element.Attributes["date-created"] != null ? DateTime.Parse(Element.Attributes["date-created"].Value) : DateTime.MinValue;
            Approved = Element.Attributes["approved"] != null ? bool.Parse(Element.Attributes["approved"].Value) : false;
            UserName = Element.Attributes["user-name"] != null ? Element.Attributes["user-name"].Value : "";
            UserEmail = Element.Attributes["user-email"] != null ? Element.Attributes["user-email"].Value : "";
            UserIP = Element.Attributes["user-ip"] != null ? Element.Attributes["user-ip"].Value : "";
            UserURL = Element.Attributes["user-url"] != null ? Element.Attributes["user-url"].Value : "";

            foreach (XmlNode Children in Element.ChildNodes)
            {
                if (Children.Name.Equals("title", StringComparison.CurrentCultureIgnoreCase))
                    Title = Children.InnerText;
                else if (Children.Name.Equals("content", StringComparison.CurrentCultureIgnoreCase))
                    Content = Children.InnerText;
            }
        }
コード例 #11
0
ファイル: XmppError.cs プロジェクト: agimenezwally/Sharp.Xmpp
 /// <summary>
 /// Initializes a new Error instance from the specified XML element.
 /// </summary>
 /// <param name="error">The 'error' XML element to initialize this
 /// instance with.</param>
 /// <exception cref="ArgumentNullException">The error parameter is null.</exception>
 /// <exception cref="ArgumentException">The error parameter contains
 /// invalid XML data.</exception>
 internal XmppError(XmlElement error)
 {
     error.ThrowIfNull("error");
     // Verify mandatory error type attribute.
     ErrorType type = (ErrorType)Enum.Parse(typeof(ErrorType),
         error.GetAttribute("type"), true);
     // Look for mandatory error condition element.
     ErrorCondition? condition = null;
     foreach (var v in Enum.GetValues(typeof(ErrorCondition)))
     {
         string s = ErrorConditionToTagName((ErrorCondition)v);
         if (error[s] != null)
             condition = (ErrorCondition)v;
     }
     if (!condition.HasValue)
         throw new ArgumentException("The error XML element does not contain a " +
             "valid XMPP error condition element.");
     Data = error;
     Type = type;
     Condition = condition.Value;
 }
コード例 #12
0
ファイル: DataField.cs プロジェクト: agimenezwally/Sharp.Xmpp
 /// <summary>
 /// Initializes a new instance of the DataField class from the specified
 /// XML element.
 /// </summary>
 /// <param name="element">The XML 'field' element to initialize the instance
 /// with.</param>
 /// <exception cref="ArgumentNullException">The element parameter is
 /// null.</exception>
 /// <exception cref="ArgumentException">The specified XML element is not a
 /// valid data-field element.</exception>
 internal DataField(XmlElement element)
 {
     element.ThrowIfNull("element");
     this.element = element;
     try
     {
         // Call GetDataFieldType method to verify the 'type' attribute.
         GetDataFieldType();
     }
     catch (XmlException e)
     {
         throw new ArgumentException("The element parameter is not a valid " +
             "data-field.", e);
     }
 }
コード例 #13
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="Element">Element containing the tag info</param>
 public Tag(XmlElement Element)
 {
     Element.ThrowIfNull("Element");
     if (Element.Attributes["ref"] != null)
         REF = Element.Attributes["ref"].Value;
 }
コード例 #14
0
ファイル: Stanza.cs プロジェクト: agimenezwally/Sharp.Xmpp
 /// <summary>
 /// Initializes a new instance of the Stanza class using the specified
 /// XmlElement.
 /// </summary>
 /// <param name="element">The XmlElement to create the stanza from.</param>
 /// <exception cref="ArgumentNullException">The element parameter is
 /// null.</exception>
 protected Stanza(XmlElement element)
 {
     element.ThrowIfNull("element");
     this.element = element;
 }
コード例 #15
0
ファイル: ListField.cs プロジェクト: REPLDigital/Sharp.Xmpp
 /// <summary>
 /// Creates an Option instance from the specified XML element.
 /// </summary>
 /// <param name="element">The XML element to create an option from.</param>
 /// <returns>An initialized instance of the Option class.</returns>
 /// <exception cref="ArgumentNullException">The element parameter is
 /// null.</exception>
 /// <exception cref="ArgumentException">The specified XML element is not
 /// a valid 'option' element.</exception>
 private Option OptionFromElement(XmlElement element)
 {
     element.ThrowIfNull("element");
     string label = element.GetAttribute("label");
     if (label == string.Empty)
         label = null;
     if (element["value"] == null)
         throw new ArgumentException("Missing 'value' child.");
     string value = element["value"].InnerText;
     return new Option(value, label);
 }
コード例 #16
0
ファイル: XmppCore.cs プロジェクト: vanklompf/Sharp.Xmpp
		/// <summary>
		/// Serializes and sends the specified XML element to the server.
		/// </summary>
		/// <param name="element">The XML element to send.</param>
		/// <exception cref="ArgumentNullException">The element parameter
		/// is null.</exception>
		/// <exception cref="IOException">There was a failure while writing
		/// to the network.</exception>
		void Send(XmlElement element) {
			element.ThrowIfNull("element");
			Send(element.ToXmlString());
		}
コード例 #17
0
ファイル: DataForm.cs プロジェクト: BlueBasher/S22.Xmpp
		/// <summary>
		/// Initializes a new instance of the DataForm class from the specified
		/// XML element.
		/// </summary>
		/// <param name="element">The XML 'field' element to initialize the instance
		/// with.</param>
		/// <param name="readOnly">Set to true to create a read-only form to
		/// which no fields may be added, otherwise false.</param>
		/// <exception cref="ArgumentNullException">The element parameter is
		/// null.</exception>
		/// <exception cref="ArgumentException">The specified XML element is not a
		/// valid data-form element.</exception>
		internal DataForm(XmlElement element, bool readOnly = false) {
			element.ThrowIfNull("element");
			this.element = element;
			try {
				fields = new FieldList(element, readOnly);
				// Call GetDataFormType method to verify the 'type' attribute.
				GetDataFormType();
			} catch (XmlException e) {
				throw new ArgumentException("The element parameter is not a valid " +
					"data-form.", e);
			}
		}
コード例 #18
0
ファイル: Message.cs プロジェクト: REPLDigital/Sharp.Xmpp
        /// <summary>
        /// Initializes a new instance of the Message class from the specified
        /// instance.
        /// </summary>
        /// <param name="messageNode">A message xml node</param>
        /// <param name="timestamp">The timestamp to use for the message</param>
        /// <exception cref="ArgumentNullException">The message parameter is null.</exception>
        /// <exception cref="ArgumentException">The 'type' attribute of
        /// the specified message stanza is invalid.</exception>
        internal Message(XmlElement messageNode, DateTimeOffset timestamp)
        {
            messageNode.ThrowIfNull("messageNode");
            type = ParseType(messageNode.GetAttribute("type"));
            Element = messageNode;
            AlternateSubjects = new XmlDictionary(Element, "subject", "xml:lang");
            AlternateBodies = new XmlDictionary(Element, "body", "xml:lang");
            Timestamp = timestamp;

            var forwardedMessageNode = Element["forwarded"];
            if (forwardedMessageNode != null && forwardedMessageNode.NamespaceURI == "urn:xmpp:forward:0")
            {
                var forwardedTimestamp = DelayedDelivery.GetDelayedTimestampOrNow(forwardedMessageNode);
                ForwardedMessage = new Message(forwardedMessageNode["message"], forwardedTimestamp);
            }
        }