コード例 #1
0
        public void Build(BogApiClientApplication clientApplication)
        {
            var restoreCommand = clientApplication.FindCommandByName(CommandTypeNameValues.RESTORE_COMMAND);

            if (restoreCommand == null)
            {
                throw new Exception($"Could not find {CommandTypeNameValues.RESTORE_COMMAND}");
            }

            restoreCommand.Command(CreateSubCommands.ARTICLE, app =>
            {
                app.HelpOption(CommandApplicationConfigurationValues.HELP_TEMPLATE);
                app.Description = "restore an existing bog article";

                var articleId = app.Argument(CommandApplicationArgumentValues.ARTICLE_ID, CommandApplicationDescriptions.ARTICLE_ID);

                app.OnExecute(async() =>
                {
                    if (string.IsNullOrWhiteSpace(articleId.Value) || string.IsNullOrWhiteSpace(articleId.Value))
                    {
                        app.ShowHelp();
                        return(1);
                    }

                    await _restoreArticleCommand.Restore(articleId.Value);
                    return(0);
                });
            });
        }
コード例 #2
0
        public void Build(BogApiClientApplication clientApplication)
        {
            var updateCommand = clientApplication.FindCommandByName(CommandTypeNameValues.UPDATE_COMMAND);

            updateCommand.Command(CreateSubCommands.MEDIA, app =>
            {
                app.HelpOption(CommandApplicationConfigurationValues.HELP_TEMPLATE);
                app.Description = "Upload all bog article entry media within the current context";

                var mediaGlobPatternArgument = app.Argument(
                    CommandApplicationArgumentValues.MEDIA_GLOB_PATTERN,
                    CommandApplicationDescriptions.MEDIA_GLOB_PATTERN,
                    (commandArg) => { commandArg.MultipleValues = true; });

                app.OnExecute(async() =>
                {
                    var mediaGlobPatterns = mediaGlobPatternArgument.Values;

                    if (mediaGlobPatternArgument.Values == null || !mediaGlobPatternArgument.Values.Any())
                    {
                        app.ShowHelp();
                        return(1);
                    }

                    await _updateMediaCommand.UpdateMediaFiles(mediaGlobPatterns.ToArray());
                    return(0);
                });
            });
        }
コード例 #3
0
        public void Build(BogApiClientApplication clientApplication)
        {
            var createCommand = clientApplication.FindCommandByName(CommandTypeNameValues.CREATE_COMMAND);

            createCommand.Command(CreateSubCommands.ARTICLE, app =>
            {
                app.HelpOption(CommandApplicationConfigurationValues.HELP_TEMPLATE);
                app.Description = "create a new bog article";

                var blogId      = app.Argument(CommandApplicationArgumentValues.BLOG_ID, CommandApplicationDescriptions.BLOG_ID);
                var author      = app.Argument(CommandApplicationArgumentValues.AUTHOR, CommandApplicationDescriptions.AUTHOR);
                var title       = app.Argument(CommandApplicationArgumentValues.TITLE, CommandApplicationDescriptions.TITLE);
                var description = app.Option(CommandApplicationOptionValues.DESCRIPTION, CommandApplicationDescriptions.DESCRIPTION, CommandOptionType.SingleValue);

                app.OnExecute(async() =>
                {
                    if (string.IsNullOrWhiteSpace(blogId.Value) ||
                        string.IsNullOrWhiteSpace(author.Value) ||
                        string.IsNullOrWhiteSpace(title.Value)
                        )
                    {
                        app.ShowHelp();
                        return(1);
                    }

                    await _cmd.CreateArticle(blogId.Value, author.Value, title.Value, description.Value());
                    return(0);
                });
            });
        }
コード例 #4
0
        public void Build(BogApiClientApplication clientApplication)
        {
            var updateCommand = clientApplication.FindCommandByName(CommandTypeNameValues.UPDATE_COMMAND);

            updateCommand.Command(CreateSubCommands.ARTICLE, app =>
            {
                app.HelpOption(CommandApplicationConfigurationValues.HELP_TEMPLATE);
                app.Description = "update a bog article within the current context";

                var author      = app.Option(CommandApplicationOptionValues.AUTHOR, CommandApplicationDescriptions.AUTHOR, CommandOptionType.SingleValue);
                var title       = app.Option(CommandApplicationOptionValues.TITLE, CommandApplicationDescriptions.TITLE, CommandOptionType.SingleValue);
                var description = app.Option(CommandApplicationOptionValues.DESCRIPTION, CommandApplicationDescriptions.DESCRIPTION, CommandOptionType.SingleValue);
                var publish     = app.Option(CommandApplicationOptionValues.PUBLISH, CommandApplicationDescriptions.PUBLISH, CommandOptionType.NoValue);
                var unPublish   = app.Option(CommandApplicationOptionValues.UNPUBLISH, CommandApplicationDescriptions.UNPUBLISH, CommandOptionType.NoValue);


                app.OnExecute(async() =>
                {
                    bool?isPublished = publish.HasValue()? true : null as bool?;
                    isPublished      = unPublish.HasValue() ? false : isPublished;
                    await _updateArticleCommand.UpdateArticle(author.Value(), title.Value(), description.Value(), isPublished);
                    return(0);
                });
            });
        }
コード例 #5
0
        public static CommandLineApplication FindCommandByName(this BogApiClientApplication clientApplication, string commandName)
        {
            var command = clientApplication.Commands.FirstOrDefault(c => c.Name == commandName);

            if (command == null)
            {
                throw new Exception($"Could not find {commandName}");
            }

            return(command);
        }
コード例 #6
0
        public void Build(BogApiClientApplication clientApplication)
        {
            clientApplication.Name = CommandApplicationConfigurationValues.NAME;
            clientApplication.HelpOption(CommandApplicationConfigurationValues.HELP_TEMPLATE);

            clientApplication.OnExecute(() =>
            {
                clientApplication.ShowHint();
                return(0);
            });
        }
コード例 #7
0
        public void Build(BogApiClientApplication clientApplication)
        {
            var deleteCommand = clientApplication.FindCommandByName(CommandTypeNameValues.DELETE_COMMAND);

            deleteCommand.Command(CreateSubCommands.ARTICLE, app =>
            {
                app.HelpOption(CommandApplicationConfigurationValues.HELP_TEMPLATE);
                app.Description = "mark bog article within the current context as deleted";

                app.OnExecute(async() =>
                {
                    await Task.CompletedTask;
                    await _deleteArticleCommand.MarkArticleAsDeleted();
                    return(0);
                });
            });
        }
コード例 #8
0
        public void Build(BogApiClientApplication clientApplication)
        {
            if (clientApplication == null)
            {
                throw new ArgumentNullException(nameof(clientApplication));
            }

            clientApplication.Command(CommandTypeNameValues.UPDATE_COMMAND, (app) =>
            {
                app.HelpOption(CommandApplicationConfigurationValues.HELP_TEMPLATE);
                app.Description = "Update instances of bog entities stored in the current context";

                app.OnExecute(() =>
                {
                    app.ShowHint();
                    return(0);
                });
            });
        }
コード例 #9
0
        public void Build(BogApiClientApplication clientApplication)
        {
            if (clientApplication == null)
            {
                throw new ArgumentNullException(nameof(clientApplication));
            }

            clientApplication.Command(CommandTypeNameValues.RESTORE_COMMAND, (app) =>
            {
                app.HelpOption(CommandApplicationConfigurationValues.HELP_TEMPLATE);
                app.Description = "Restore articles within the current directory";

                app.OnExecute(() =>
                {
                    app.ShowHint();
                    return(0);
                });
            });
        }
コード例 #10
0
        public void Build(BogApiClientApplication clientApplication)
        {
            if (clientApplication == null)
            {
                throw new ArgumentNullException(nameof(clientApplication));
            }

            clientApplication.Command(CommandTypeNameValues.PING_COMMAND, (app) =>
            {
                app.HelpOption(CommandApplicationConfigurationValues.HELP_TEMPLATE);
                app.Description = "Ping test for API health-check";

                app.OnExecute(async() =>
                {
                    await _pingCommand.SendHealthCheckPing();
                    return(0);
                });
            });
        }
コード例 #11
0
        public void Build(BogApiClientApplication clientApplication)
        {
            var updateCommand = clientApplication.FindCommandByName(CommandTypeNameValues.UPDATE_COMMAND);

            updateCommand.Command(CreateSubCommands.ENTRY, app =>
            {
                app.HelpOption(CommandApplicationConfigurationValues.HELP_TEMPLATE);
                app.Description = "update a bog article entry within the current context";

                var entryFileName = app.Argument(CommandApplicationArgumentValues.FILE_NAME, CommandApplicationDescriptions.FILE_NAME);

                app.OnExecute(async() =>
                {
                    if (string.IsNullOrWhiteSpace(entryFileName.Value))
                    {
                        app.ShowHelp();
                        return(1);
                    }

                    await _updateEntryCommand.UpdateEntry(entryFileName.Value);
                    return(0);
                });
            });
        }
コード例 #12
0
        public void Build(BogApiClientApplication clientApplication)
        {
            var updateCommand = clientApplication.FindCommandByName(CommandTypeNameValues.UPDATE_COMMAND);

            updateCommand.Command(CreateSubCommands.META_TAG, app =>
            {
                app.HelpOption(CommandApplicationConfigurationValues.HELP_TEMPLATE);
                app.Description = "update meta tags on a bog article";

                var tags = app.Argument(CommandApplicationArgumentValues.TAG, CommandApplicationDescriptions.TAG, true);

                app.OnExecute(async() =>
                {
                    if (!tags.Values.Any())
                    {
                        app.ShowHelp();
                        return(0);
                    }

                    await _updateMetaTagsCommand.UpdateMetaTags(tags.Values.ToArray());
                    return(0);
                });
            });
        }
コード例 #13
0
 public BogApplicationBuilderFactory(BogApiClientApplication app, params IApplicationBuilder[] builders)
 {
     _app      = app;
     _builders = builders;
 }