Exemple #1
0
        public async Task Restore(string articleIdValue)
        {
            if (articleIdValue == null)
            {
                throw new ArgumentNullException(nameof(articleIdValue));
            }

            if (_fileProvider.CheckMetaFileExists(MetaFileNameValues.ARTICLE))
            {
                Console.WriteLine("An Article already exists within the current context");
                return;
            }

            var articleId = Guid.Parse(articleIdValue);
            await _updateArticleContextWorkflow.GetAndUpdateArticleContext(articleId);
        }
        public async Task <ArticleResponse> GetArticleContext()
        {
            if (!_fileProvider.CheckMetaFileExists(MetaFileNameValues.ARTICLE))
            {
                Console.Error.WriteLine("No Article exists in current context");
                return(null);
            }

            var articleContext = await _fileProvider.ReadMetaFile <ArticleResponse>(MetaFileNameValues.ARTICLE);

            if (articleContext == null)
            {
                Console.Error.WriteLine("Could not read article information from current context");
            }

            return(articleContext);
        }
        public async Task CreateArticle(string blogId, string author, string title, string description = null)
        {
            if (string.IsNullOrWhiteSpace(blogId))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(blogId));
            }
            if (string.IsNullOrWhiteSpace(author))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(author));
            }
            if (string.IsNullOrWhiteSpace(title))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(title));
            }

            if (_fileProvider.CheckMetaFileExists(MetaFileNameValues.ARTICLE))
            {
                Console.WriteLine("An Article already exists within the current context");
                return;
            }

            var response = await _client.PostMessage(BogApiRouteValues.ARTICLE, new ArticleRequest
            {
                Author      = author,
                Title       = title,
                Description = description,
                BlogId      = Guid.Parse(blogId)
            });

            if (!response.IsSuccessStatusCode)
            {
                throw new HttpRequestException($"failed HTTP request: {response.StatusCode}\n{response.ReasonPhrase}");
            }

            var blogContentTask = response.Content.ReadAsStringAsync();
            await _fileProvider.WriteMetaFile(MetaFileNameValues.ARTICLE, blogContentTask);

            var contents = await blogContentTask;

            contents = JsonUtility.Prettify <ArticleResponse>(contents);
            Console.WriteLine(contents);
        }