コード例 #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();
            }
        }
コード例 #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();
     }
 }
コード例 #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();
 }
コード例 #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();
            }
        }
コード例 #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();
        }
コード例 #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();
            }
        }
コード例 #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);
 }
コード例 #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));
 }