コード例 #1
0
        public void UpdateRssFeed(PodcastPost podcastPost)
        {
            //1. search for the existing feed media item
            WordPressMedia media = _wordPressService.FindMediaByTitle("scfFeed");

            //2. download the existing feed - get the URL from the item
            XDocument doc = GetRssFeedAsXml(media.source_url);

            //3. update it with the details of the new podcast
            AddPodcastItemToDocument(doc, podcastPost);

            //3.5 save a copy of the file locally
            SaveRssFeedLocally(doc);

            //4. delete the existing feed
            //http://windows7vm/wordpress/wp-json/wp/v2/media/2663?force=true
            WordPressResult deleteMediaResult = _wordPressService.DeleteMedia(media.id);

            if (!deleteMediaResult.IsSuccess)
            {
                throw new InvalidOperationException("Error deleting the existing RSS feed");
            }

            //5. create the new one
            WordPressResult addMediaResult = _wordPressService.AddMedia("scfFeed.xml", "text/xml");
            //http://windows7vm/wordpress/wp-json/wp/v2/media

            //6. download the media to make sure it is there
            //- validate it against a schema??
        }
コード例 #2
0
        private WordPressResult UploadAudioFile(PodcastPost podcastPost)
        {
            Console.Write("Uploading the audio file... ");
            _logger.Info("Beginning upload of audio file");

            WordPressResult result = _podcastService.UploadAudioFile(podcastPost.AudioFilePath);

            if (result.IsSuccess)
            {
                Console.WriteLine($"Success! (Id = {result.Id})");
                _logger.Info($"Upload was successful - id = {result.Id}");
                _logger.Info($"Audio file URL = {result.Url}");
            }
            else
            {
                Console.WriteLine("Oh dear, it didn't work - here is the error: ");
                Console.WriteLine(result.ErrorMessage);
                Console.WriteLine("See the log file for more details...");

                _logger.Error($"Upload failed with error: {result.ErrorMessage}");
                //TODO need to capture the detailed error somehow
            }

            return(result);
        }
コード例 #3
0
        public WordPressResult CreatePodcastPost(PodcastPost podcastPost)
        {
            //1. read in template
            string templateText = ReadTemplate();

            //2. make substitutions to template
            List <string> substitutions = new List <string> {
                podcastPost.Speaker,                //{0}
                podcastPost.BibleText,              //{1}
                podcastPost.GetFormattedDuration(), //{2}
                podcastPost.GetFormattedSize(),     //{3}
                podcastPost.PodcastMediaUrl,        //{4}
                podcastPost.Title                   //{5}
            };
            string content = string.Format(templateText, substitutions.ToArray());

            //3. call WordPress to add the post
            WordPressPost wordPressPost = new WordPressPost()
            {
                status         = "publish",
                title          = GetTitlePrefixedWithDate(podcastPost),
                content        = content,
                date           = podcastPost.Date.ToString("yyyy-MM-dd hh:mm:ss"),
                categories     = new [] { _configurationService.Configuration.WordPressPodcastCategoryId },
                author         = _configurationService.Configuration.WordPressAuthorId,
                featured_media = podcastPost.FeaturedMediaId
            };
            WordPressResult result = _wordPressService.AddPost(wordPressPost);

            //4. return result
            return(result);
        }
コード例 #4
0
        private WordPressResult CreatePost(PodcastPost podcastPost)
        {
            Console.Write("Creating WordPress post...  ");
            _logger.Info("Beginning creation of post");

            WordPressResult result = _podcastService.CreatePodcastPost(podcastPost);

            if (result.IsSuccess)
            {
                Console.WriteLine($"Success! (Id = {result.Id})");
                Console.WriteLine($"The URL of the new post is:\n{result.Url}");
                _logger.Info($"Post creation succeeded - id = {result.Id}");
                _logger.Info($"Post URL = {result.Url}");
            }
            else
            {
                Console.WriteLine("Oh dear, it didn't work - here is the error: ");
                Console.WriteLine(result.ErrorMessage);
                Console.WriteLine("See the log file for more details...");
            }

            return(result);
        }
コード例 #5
0
        public void Run(string[] args)
        {
            CommandLineArgs commandLineArgs = ParseArgs(args);

            //where should we get the podcast details from?
            PodcastPost podcastPost;

            if (commandLineArgs.IsInteractive)
            {
                podcastPost = PromptUserForPodcastDetails();
            }
            else
            {
                podcastPost = LoadDetailsFromFile();
            }

            //create the MP3 file
            podcastPost.AudioFilePath = CreateMp3File(podcastPost.AudioFilePath, podcastPost);

            //upload the file
            WordPressResult audioFileResult = UploadAudioFile(podcastPost);

            if (!audioFileResult.IsSuccess)
            {
                return;
            }

            podcastPost.PodcastMediaUrl = audioFileResult.Url;

            //create the post on WordPress
            WordPressResult createPostResult = CreatePost(podcastPost);

            podcastPost.PodcastPostUrl = createPostResult.Url;

            //update the RSS feed
            UpdateRssFeed(podcastPost);
        }