Ejemplo n.º 1
0
        /// <summary>
        /// Writes the specified <see cref="NzbDocument"/> asynchronously to the stream.
        /// </summary>
        /// <param name="nzbDocument">The NZB document to write.</param>
        /// <returns>A <see cref="Task"/> that can be awaited.</returns>
        public async Task WriteAsync(NzbDocument nzbDocument)
        {
            using (XmlWriter writer = GetXmlWriter())
            {
                await writer.WriteDocTypeAsync(
                    NzbKeywords.Nzb,
                    NzbKeywords.PubId,
                    NzbKeywords.SysId,
                    null);

                await writer.WriteStartElementAsync(
                    null,
                    NzbKeywords.Nzb,
                    NzbKeywords.Namespace);

                await WriteHeadAsync(writer, nzbDocument);
                await WriteFilesAsync(writer, nzbDocument);

                await writer.WriteEndElementAsync();

                await writer.WriteEndDocumentAsync();

                await writer.FlushAsync();
            }
        }
Ejemplo n.º 2
0
 private static void WriteFiles(XmlWriter writer, NzbDocument nzbDocument)
 {
     foreach (NzbFile file in nzbDocument.Files)
     {
         writer.WriteStartElement(NzbKeywords.File);
         writer.WriteAttributeString(NzbKeywords.Poster, file.Poster);
         writer.WriteAttributeString(NzbKeywords.Date, file.Date.ToUnixTimeSeconds().ToString(CultureInfo.InvariantCulture));
         writer.WriteAttributeString(NzbKeywords.Subject, file.Subject);
         WriteGroups(writer, file);
         WriteSegments(writer, file);
         writer.WriteEndElement();
     }
 }
Ejemplo n.º 3
0
 private static void WriteHead(XmlWriter writer, NzbDocument nzbDocument)
 {
     writer.WriteStartElement(NzbKeywords.Head);
     foreach (KeyValuePair <string, ImmutableHashSet <string> > header in nzbDocument.MetaData)
     {
         foreach (string value in header.Value)
         {
             writer.WriteStartElement(NzbKeywords.Meta);
             writer.WriteAttributeString(NzbKeywords.Type, header.Key);
             writer.WriteString(value);
             writer.WriteEndElement();
         }
     }
     writer.WriteEndElement();
 }
Ejemplo n.º 4
0
        private static async Task WriteFilesAsync(XmlWriter writer, NzbDocument nzbDocument)
        {
            foreach (NzbFile file in nzbDocument.Files)
            {
                await writer.WriteStartElementAsync(null, NzbKeywords.File, null);

                await writer.WriteAttributeStringAsync(null, NzbKeywords.Poster, null, file.Poster);

                await writer.WriteAttributeStringAsync(null, NzbKeywords.Date, null, file.Date.ToUnixTimeSeconds().ToString(CultureInfo.InvariantCulture));

                await writer.WriteAttributeStringAsync(null, NzbKeywords.Subject, null, file.Subject);
                await WriteGroupsAsync(writer, file);
                await WriteSegmentsAsync(writer, file);

                await writer.WriteEndElementAsync();
            }
        }
Ejemplo n.º 5
0
        private static async Task WriteHeadAsync(XmlWriter writer, NzbDocument nzbDocument)
        {
            await writer.WriteStartElementAsync(null, NzbKeywords.Head, null);

            foreach (KeyValuePair <string, ImmutableHashSet <string> > header in nzbDocument.MetaData)
            {
                foreach (string value in header.Value)
                {
                    await writer.WriteStartElementAsync(null, NzbKeywords.Meta, null);

                    await writer.WriteAttributeStringAsync(null, NzbKeywords.Type, null, header.Key);

                    await writer.WriteStringAsync(value);

                    await writer.WriteEndElementAsync();
                }
            }
            await writer.WriteEndElementAsync();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Writes the specified <see cref="NzbDocument"/> to the stream.
        /// </summary>
        /// <param name="nzbDocument">The NZB document to write.</param>
        /// <returns>A <see cref="Task"/> that can be awaited.</returns>
        public void Write(NzbDocument nzbDocument)
        {
            using (XmlWriter writer = GetXmlWriter())
            {
                writer.WriteDocType(
                    NzbKeywords.Nzb,
                    NzbKeywords.PubId,
                    NzbKeywords.SysId,
                    null);

                writer.WriteStartElement(
                    NzbKeywords.Nzb,
                    NzbKeywords.Namespace);

                WriteHead(writer, nzbDocument);
                WriteFiles(writer, nzbDocument);
                writer.WriteEndElement();
                writer.WriteEndDocument();
                writer.Flush();
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Writes the specified <see cref="NzbDocument"/> to the stream.
 /// </summary>
 /// <param name="textWriter">The <see cref="TextWriter"/> to use.</param>
 /// <param name="nzbDocument">The <see cref="NzbDocument"/> to write.</param>
 public static void WriteNzbDocument(this TextWriter textWriter, NzbDocument nzbDocument)
 {
     new NzbWriter(textWriter).Write(nzbDocument);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Writes the specified <see cref="NzbDocument"/> asynchronously to the stream.
 /// </summary>
 /// <param name="textWriter">The <see cref="TextWriter"/> to use.</param>
 /// <param name="nzbDocument">The <see cref="NzbDocument"/> to write.</param>
 /// <returns>A <see cref="Task"/> that can be awaited.</returns>
 public static Task WriteNzbDocumentAsync(this TextWriter textWriter, NzbDocument nzbDocument)
 {
     return(new NzbWriter(textWriter).WriteAsync(nzbDocument));
 }