예제 #1
0
        /// <summary>
        /// Creates the 'feature' XML element which is part of a 'Stream Initiation'
        /// request.
        /// </summary>
        /// <param name="streamOptions">An enumerable collection of accepted stream
        /// methods.</param>
        /// <returns>An XML 'feature' element.</returns>
        /// <exception cref="ArgumentNullException">The streamOptions parameter
        /// is null.</exception>
        private XElement CreateFeatureElement(IEnumerable <string> streamOptions)
        {
            streamOptions.ThrowIfNull("streamOptions");
            // Create the data-form for stream-method selection.
            DataForm         form    = new RequestForm();
            HashSet <Option> options = new HashSet <Option>();

            foreach (string opt in streamOptions)
            {
                options.Add(new Option(opt));
            }
            form.Fields.Add(new ListField("stream-method", true, null, null,
                                          options));
            // Wrap it in a 'feature' element to create the offer.
            return(FeatureNegotiation.Create(form));
        }
예제 #2
0
        /// <summary>
        /// Parses the selected stream-method from the specified 'feature' XML
        /// element.
        /// </summary>
        /// <param name="feature">The 'feature' XML element.</param>
        /// <returns>The stream method contained in the 'feature' XML
        /// element.</returns>
        /// <exception cref="ArgumentNullException">The feature parameter is
        /// null.</exception>
        /// <exception cref="ArgumentException">The feature element contains
        /// invalid data.</exception>
        private string ParseStreamMethod(XElement feature)
        {
            feature.ThrowIfNull("feature");
            DataForm form = FeatureNegotiation.Parse(feature);
            // The data-form must contain a field named 'stream-method'.
            var field = form.Fields["stream-method"];

            if (field == null)
            {
                throw new ArgumentException("Missing or erroneous 'stream-method' field.");
            }
            string selected = field.Values.FirstOrDefault();

            if (selected == null)
            {
                throw new ArgumentException("No stream-method selected.");
            }
            return(selected);
        }