Esempio n. 1
0
 public void Serialize(TextWriter writer, XNode node, MediaRange mediaType)
 {
     Contract.Requires<ArgumentNullException>(node != null);
     Contract.Requires<ArgumentNullException>(writer != null);
     Contract.Requires<ArgumentNullException>(mediaType != null);
     throw new System.NotImplementedException();
 }
Esempio n. 2
0
        public void Serialize(TextWriter writer, XNode node, MediaRange mediaType)
        {
            var element = node is XDocument ? ((XDocument)node).Root : node as XElement;
            if (element == null)
                throw new InvalidOperationException();

            // Each element node is visited in document order, except non-relevant elements are skipped if the relevant
            // setting of the submission is true. Each visited element that has no child element nodes (i.e., each leaf
            // element node) is selected for inclusion, including those that have no value (no text node). Note that
            // attribute information is not preserved.

            var separ = false;
            var items = element
                .DescendantsAndSelf()
                .Where(i => !i.HasElements);

            foreach (var item in items)
            {
                // write separator on subsequent nodes
                if (separ)
                    writer.Write(';');

                // encode values
                writer.Write(Encode(item.Name.LocalName));
                writer.Write('=');
                writer.Write(Encode(item.Value));
                separ = true;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Returns the given input data converted into the given output type.
        /// </summary>
        /// <param name="inputType"></param>
        /// <param name="input"></param>
        /// <param name="outputType"></param>
        /// <returns></returns>
        public Stream Convert(MediaRange inputType, Stream input, MediaRange outputType)
        {
            var converter = GetConverter(inputType, input, outputType);
            if (converter == null)
                throw new NullReferenceException();

            return converter.Convert(inputType, input, outputType);
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="status"></param>
        /// <param name="content"></param>
        /// <param name="contentType"></param>
        public IOResponse(IORequest request, IOStatus status, Stream content, MediaRange contentType)
            : this(request, status)
        {
            Contract.Requires<ArgumentNullException>(request != null);
            Contract.Requires<ArgumentNullException>(content != null);

            this.content = content;
            this.contentType = contentType;
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="contentType"></param>
        /// <param name="lastModifiedTime"></param>
        /// <param name="etag"></param>
        public ViewModuleInfo(string name, Action<Stream> writer, MediaRange contentType, DateTime lastModifiedTime, string etag)
            : this(name, writer, contentType)
        {
            Contract.Requires<ArgumentNullException>(name != null);
            Contract.Requires<ArgumentNullException>(writer != null);
            Contract.Requires<ArgumentNullException>(contentType != null);

            this.lastModifiedTime = lastModifiedTime;
            this.etag = etag;
        }
Esempio n. 6
0
        /// <summary>
        /// Returns the given input data converted into the given output type.
        /// </summary>
        /// <param name="inputType"></param>
        /// <param name="input"></param>
        /// <param name="outputType"></param>
        /// <returns></returns>
        public Stream Convert(MediaRange inputType, Stream input, MediaRange outputType)
        {
            var converter = GetConverter(inputType, input, outputType);

            if (converter == null)
            {
                throw new NullReferenceException();
            }

            return(converter.Convert(inputType, input, outputType));
        }
Esempio n. 7
0
        /// <summary>
        /// Deserailizes the incoming <see cref="JObject"/> into an XForms data model, given the definition 
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="mediaType"></param>
        /// <returns></returns>
        public XDocument Deserialize(TextReader reader, MediaRange mediaType)
        {
            using (var json = new JsonTextReader(reader))
            {
                var token = JToken.ReadFrom(json);
                if (token == null)
                    return null;

                return ToDocument(token);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Deserializes the <see cref="TextReader"/> to a <see cref="XNode"/>.
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="mediaType"></param>
        /// <returns></returns>
        protected XNode Deserialize(TextReader reader, MediaRange mediaType)
        {
            Contract.Requires<ArgumentNullException>(reader != null);
            Contract.Requires<ArgumentNullException>(mediaType != null);

            // obtain serializer
            var deserializer = GetDeserializer(mediaType);
            if (deserializer == null)
                throw new InvalidOperationException();

            return deserializer.Deserialize(reader, mediaType);
        }
Esempio n. 9
0
        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="write"></param>
        /// <param name="contentType"></param>
        public ViewModuleInfo(string name, Action<Stream> write, MediaRange contentType)
        {
            Contract.Requires<ArgumentNullException>(name != null);
            Contract.Requires<ArgumentNullException>(write != null);
            Contract.Requires<ArgumentNullException>(contentType != null);

            this.name = name;
            this.write = write;
            this.contentType = contentType;
            this.lastModifiedTime = DateTime.UtcNow;
            this.etag = null;
        }
Esempio n. 10
0
 /// <summary>
 /// Gets the first <see cref="IMediaConverter"/> capable of handling the given input type, data and output type.
 /// </summary>
 /// <param name="inputType"></param>
 /// <param name="input"></param>
 /// <param name="outputType"></param>
 /// <returns></returns>
 IMediaConverter GetConverter(MediaRange inputType, Stream input, MediaRange outputType)
 {
     return(converters
            .Select(i => new
     {
         Converter = i,
         Priority = i.CanConvert(inputType, input, outputType),
     })
            .Where(i => i.Priority != Priority.Ignore)
            .OrderByDescending(i => i.Priority)
            .Select(i => i.Converter)
            .FirstOrDefault());
 }
Esempio n. 11
0
 /// <summary>
 /// Gets the first <see cref="IMediaConverter"/> capable of handling the given input type, data and output type.
 /// </summary>
 /// <param name="inputType"></param>
 /// <param name="input"></param>
 /// <param name="outputType"></param>
 /// <returns></returns>
 IMediaConverter GetConverter(MediaRange inputType, Stream input, MediaRange outputType)
 {
     return converters
         .Select(i => new
         {
             Converter = i,
             Priority = i.CanConvert(inputType, input, outputType),
         })
         .Where(i => i.Priority != Priority.Ignore)
         .OrderByDescending(i => i.Priority)
         .Select(i => i.Converter)
         .FirstOrDefault();
 }
Esempio n. 12
0
 public XDocument Deserialize(TextReader reader, MediaRange mediaType)
 {
     Contract.Requires<ArgumentNullException>(reader != null);
     Contract.Requires<ArgumentNullException>(mediaType != null);
     throw new NotImplementedException();
 }
Esempio n. 13
0
 public Priority CanSerialize(XNode node, MediaRange mediaType)
 {
     Contract.Requires<ArgumentNullException>(node != null);
     Contract.Requires<ArgumentNullException>(mediaType != null);
     throw new NotImplementedException();
 }
Esempio n. 14
0
 /// <summary>
 /// Adds a script to be delivered and executed on the client.
 /// </summary>
 /// <param name="type"></param>
 /// <param name="code"></param>
 public void Add(MediaRange type, string code)
 {
     state.Value.scripts.Enqueue(new Script(type, code));
 }
Esempio n. 15
0
 /// <summary>
 /// Returns <c>true</c> if the given input data can be converted into the given output type.
 /// </summary>
 /// <param name="inputType"></param>
 /// <param name="input"></param>
 /// <param name="outputType"></param>
 /// <returns></returns>
 public bool CanConvert(MediaRange inputType, Stream input, MediaRange outputType)
 {
     return GetConverter(inputType, input, outputType) != null;
 }
Esempio n. 16
0
 public XDocument Deserialize(TextReader reader, MediaRange mediaType)
 {
     return serializer.Deserialize(XDocument.Load(reader));
 }
Esempio n. 17
0
 /// <summary>
 /// Returns <c>true</c> if the given input data can be converted into the given output type.
 /// </summary>
 /// <param name="inputType"></param>
 /// <param name="input"></param>
 /// <param name="outputType"></param>
 /// <returns></returns>
 public bool CanConvert(MediaRange inputType, Stream input, MediaRange outputType)
 {
     return(GetConverter(inputType, input, outputType) != null);
 }
Esempio n. 18
0
        /// <summary>
        /// Whether or not a media range matches another, taking into account wildcards.
        /// </summary>
        /// <param name="other">Other media range.</param>
        /// <returns>True if matching, false if not.</returns>
        public bool Matches(MediaRange other)
        {
            Contract.Requires<ArgumentNullException>(other != null);

            return type.Matches(other.type) && subtype.Matches(other.subtype);
        }
Esempio n. 19
0
 public Priority CanDeserialize(MediaRange mediaType)
 {
     return MEDIA_RANGE.Any(i => i.Matches(mediaType)) ? Priority.Default : Priority.Ignore;
 }
Esempio n. 20
0
 /// <summary>
 /// Initializes a new instance.
 /// </summary>
 /// <param name="mediaRange"></param>
 public SubmissionSerialization(MediaRange mediaRange)
 {
     this.none = false;
     this.mediaRange = mediaRange;
 }
Esempio n. 21
0
        /// <summary>
        /// Whether or not a media range matches another, taking into account wildcards and parameters.
        /// </summary>
        /// <param name="other">Other media range.</param>
        /// <returns>True if matching, false if not.</returns>
        public bool MatchesWithParameters(MediaRange other)
        {
            Contract.Requires<ArgumentNullException>(other != null);

            return Matches(other) && parameters.Matches(other.parameters);
        }
Esempio n. 22
0
 public void Serialize(TextWriter writer, XNode node, MediaRange mediaType)
 {
     using (var json = new JsonTextWriter(writer))
         ToJObject(node).WriteTo(json);
 }
Esempio n. 23
0
 public void Serialize(TextWriter writer, XNode node, MediaRange mediaType)
 {
     using (var xml = XmlWriter.Create(writer))
         node.WriteTo(xml);
 }
Esempio n. 24
0
 /// <summary>
 /// Initializes a new instance.
 /// </summary>
 /// <param name="language"></param>
 /// <param name="code"></param>
 public Script(MediaRange language, string code)
 {
     Language = language;
     Code = code;
 }
Esempio n. 25
0
 public Priority CanSerialize(XNode node, MediaRange mediaType)
 {
     return MEDIA_RANGE.Any(i => i.Matches(mediaType)) && (node is XDocument || node is XElement) ? Priority.Default : Priority.Ignore;
 }
Esempio n. 26
0
        /// <summary>
        /// Whether or not a media range matches another, taking into account wildcards.
        /// </summary>
        /// <param name="other">Other media range.</param>
        /// <returns>True if matching, false if not.</returns>
        public bool Matches(MediaRange other)
        {
            Contract.Requires <ArgumentNullException>(other != null);

            return(type.Matches(other.type) && subtype.Matches(other.subtype));
        }
Esempio n. 27
0
        /// <summary>
        /// Serializes the <see cref="XNode"/> to a <see cref="TextWriter"/>.
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="node"></param>
        /// <param name="mediaType"></param>
        protected void Serialize(TextWriter writer, XNode node, MediaRange mediaType)
        {
            Contract.Requires<ArgumentNullException>(writer != null);
            Contract.Requires<ArgumentNullException>(node != null);
            Contract.Requires<ArgumentNullException>(mediaType != null);

            // obtain serializer
            var serializer = GetSerializer(node, mediaType);
            if (serializer == null)
                throw new UnsupportedMediaTypeException();

            serializer.Serialize(writer, node, mediaType);
        }
Esempio n. 28
0
        /// <summary>
        /// Whether or not a media range matches another, taking into account wildcards and parameters.
        /// </summary>
        /// <param name="other">Other media range.</param>
        /// <returns>True if matching, false if not.</returns>
        public bool MatchesWithParameters(MediaRange other)
        {
            Contract.Requires <ArgumentNullException>(other != null);

            return(Matches(other) && parameters.Matches(other.parameters));
        }
Esempio n. 29
0
        /// <summary>
        /// Gets the deserializer which supports the given <see cref="MediaRange"/>.
        /// </summary>
        /// <param name="mediaType"></param>
        /// <returns></returns>
        protected IModelDeserializer GetDeserializer(MediaRange mediaType)
        {
            Contract.Requires<ArgumentNullException>(mediaType != null);

            return deserializers
                .Select(i => new { Priority = i.CanDeserialize(mediaType), Serializer = i })
                .Where(i => i.Priority != Priority.Ignore)
                .OrderByDescending(i => i.Priority)
                .Select(i => i.Serializer)
                .FirstOrDefault();
        }
Esempio n. 30
0
 /// <summary>
 /// Initializes a new instance.
 /// </summary>
 /// <param name="none"></param>
 public SubmissionSerialization(bool none)
 {
     this.none = none;
     this.mediaRange = null;
 }