Beispiel #1
0
        private ProcessorResult ProcessPodcastsElements(XmlReader reader)
        {
            var result = ProcessorResult.Processed;

            var elementName = reader.LocalName;

            switch (elementName)
            {
            case "global":
                XmlSerializationHelper.ProcessElement(reader, "global", ProcessGlobalElements);
                break;

            case "podcast":
                var newPodcast = new PodcastInfo(this);
                newPodcast.ReadXml(reader);
                Podcasts.Add(newPodcast);
                break;

            default:
                result = ProcessorResult.Ignored;
                break;
            }

            return(result);
        }
        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>
        /// A new object that is a copy of this instance.
        /// </returns>
        /// <filterpriority>2</filterpriority>
        public object Clone()
        {
            var copy = new PodcastInfo(_controlFileGlobalDefaults);

            XmlSerializationHelper.CloneUsingXmlSerialization("podcast", this, copy);
            return(copy);
        }
Beispiel #3
0
        /// <summary>
        /// Converts an object into its XML representation.
        /// </summary>
        /// <param name="writer">The <see cref="T:System.Xml.XmlWriter"/> stream to which the object is serialized.
        ///                 </param>
        public void WriteXml(XmlWriter writer)
        {
            Assembly     me   = System.Reflection.Assembly.GetExecutingAssembly();
            AssemblyName name = me.GetName();

            writer.WriteComment(string.Format(CultureInfo.InvariantCulture, "Written by PodcastUtilities.Common v{0}", name.Version));

            writer.WriteStartElement("global");
            if (SourceRoot != null)
            {
                writer.WriteElementString("sourceRoot", SourceRoot);
            }
            if (DestinationRoot != null)
            {
                writer.WriteElementString("destinationRoot", DestinationRoot);
            }
            if (PlaylistFileName != null)
            {
                writer.WriteElementString("playlistFilename", PlaylistFileName);
            }
            writer.WriteElementString("playlistFormat", WritePlaylistFormat(PlaylistFormat));
            writer.WriteElementString("playlistPathSeparator", PlaylistPathSeparator);
            writer.WriteElementString("freeSpaceToLeaveOnDestinationMB", FreeSpaceToLeaveOnDestination.ToString(CultureInfo.InvariantCulture));
            writer.WriteElementString("freeSpaceToLeaveOnDownloadMB", FreeSpaceToLeaveOnDownload.ToString(CultureInfo.InvariantCulture));
            writer.WriteElementString("maximumNumberOfConcurrentDownloads", MaximumNumberOfConcurrentDownloads.ToString(CultureInfo.InvariantCulture));
            writer.WriteElementString("retryWaitInSeconds", RetryWaitInSeconds.ToString(CultureInfo.InvariantCulture));

            writer.WriteElementString("number", DefaultNumberOfFiles.ToString(CultureInfo.InvariantCulture));
            writer.WriteElementString("pattern", DefaultFilePattern);
            writer.WriteElementString("deleteEmptyFolder", DefaultDeleteEmptyFolder.ToString(CultureInfo.InvariantCulture));
            writer.WriteElementString("sortfield", PodcastInfo.WriteSortField(DefaultSortField));
            writer.WriteElementString("sortdirection", PodcastInfo.WriteSortDirection(DefaultAscendingSort));
            writer.WriteElementString("postdownloadcommand", DefaultPostDownloadCommand);

            writer.WriteStartElement("feed");
            writer.WriteElementString("maximumDaysOld", DefaultFeedMaximumDaysOld.ToString(CultureInfo.InvariantCulture));
            writer.WriteElementString("deleteDownloadsDaysOld", DefaultFeedDeleteDownloadsDaysOld.ToString(CultureInfo.InvariantCulture));
            writer.WriteElementString("format", FeedInfo.WriteFeedFormat(DefaultFeedFormat));
            writer.WriteElementString("namingStyle", FeedInfo.WriteFeedEpisodeNamingStyle(DefaultFeedEpisodeNamingStyle));
            writer.WriteElementString("downloadStrategy", FeedInfo.WriteFeedEpisodeDownloadStrategy(DefaultFeedEpisodeDownloadStrategy));
            writer.WriteEndElement();

            writer.WriteStartElement("diagnostics");
            writer.WriteElementString("retainTempFiles", WriteDiagnosticRetainTemporaryFiles(DiagnosticRetainTemporaryFiles));
            writer.WriteElementString("outputLevel", WriteDiagnosticOutputLevel(DiagnosticOutput));
            writer.WriteEndElement();

            writer.WriteStartElement("postdownloadcommand");
            writer.WriteElementString("command", DefaultPostDownloadCommand);
            writer.WriteElementString("arguments", DefaultPostDownloadArguments);
            writer.WriteElementString("workingdirectory", DefaultPostDownloadWorkingDirectory);
            writer.WriteEndElement();

            writer.WriteEndElement();

            foreach (var podcastInfo in Podcasts)
            {
                // simulate the behaviour of XmlSerialisation
                writer.WriteStartElement("podcast");
                podcastInfo.WriteXml(writer);
                writer.WriteEndElement();
            }
        }
        private ProcessorResult ProcessGlobalElements(XmlReader reader)
        {
            var result = ProcessorResult.Processed;

            var elementName = reader.LocalName;

            if (elementName == "feed")
            {
                XmlSerializationHelper.ProcessElement(reader, "feed", ProcessGlobalFeedElements);
                return(result);
            }
            if (elementName == "postdownloadcommand")
            {
                XmlSerializationHelper.ProcessElement(reader, "postdownloadcommand", ProcessGlobalPostDownloadCommandElements);
                return(result);
            }
            if (elementName == "diagnostics")
            {
                XmlSerializationHelper.ProcessElement(reader, "diagnostics", ProcessGlobalDiagnosticsElements);
                return(result);
            }

            if (!reader.IsEmptyElement)
            {
                reader.Read();
            }
            var content = reader.Value.Trim();

            long longValue;
            int  intValue;
            bool boolValue;

            switch (elementName)
            {
            case "sourceRoot":
                SourceRoot = content;
                break;

            case "destinationRoot":
                DestinationRoot = content;
                break;

            case "playlistFilename":
                PlaylistFileName = content;
                break;

            case "playlistFormat":
                PlaylistFormat = ReadPlaylistFormat(content);
                break;

            case "playlistPathSeparator":
                PlaylistPathSeparator = content;
                break;

            case "freeSpaceToLeaveOnDestinationMB":
                if (long.TryParse(content, NumberStyles.Integer, CultureInfo.InvariantCulture, out longValue))
                {
                    FreeSpaceToLeaveOnDestination = longValue;
                }
                break;

            case "freeSpaceToLeaveOnDownloadMB":
                if (long.TryParse(content, NumberStyles.Integer, CultureInfo.InvariantCulture, out longValue))
                {
                    FreeSpaceToLeaveOnDownload = longValue;
                }
                break;

            case "maximumNumberOfConcurrentDownloads":
                if (int.TryParse(content, NumberStyles.Integer, CultureInfo.InvariantCulture, out intValue))
                {
                    MaximumNumberOfConcurrentDownloads = intValue;
                }
                break;

            case "retryWaitInSeconds":
                if (int.TryParse(content, NumberStyles.Integer, CultureInfo.InvariantCulture, out intValue))
                {
                    RetryWaitInSeconds = intValue;
                }
                break;

            case "number":
                if (int.TryParse(content, NumberStyles.Integer, CultureInfo.InvariantCulture, out intValue))
                {
                    DefaultNumberOfFiles = intValue;
                }
                break;

            case "pattern":
                if (!string.IsNullOrEmpty(content))
                {
                    DefaultFilePattern = content;
                }
                break;

            case "deleteEmptyFolder":
                if (bool.TryParse(content, out boolValue))
                {
                    DefaultDeleteEmptyFolder = boolValue;
                }
                break;

            case "sortfield":
                DefaultSortField = PodcastInfo.ReadSortField(content);
                break;

            case "sortdirection":
                DefaultAscendingSort = PodcastInfo.ReadSortDirection(content);
                break;

            default:
                result = ProcessorResult.Ignored;
                break;
            }
            return(result);
        }