AddOption() public méthode

Adds a dictionary value
public AddOption ( string optionName, string optionValue = "" ) : void
optionName string
optionValue string
Résultat void
Exemple #1
0
    /// <summary>
    /// Helper: Adds a command line parameter (if it exists) to the Options colleciton
    /// </summary>
    /// <param name="options"></param>
    /// <param name="optionKey"></param>
    /// <param name="commandLine"></param>
    /// <param name="commandLineKey"></param>
    private static void helper_AddValueIfExists(TaskMasterOptions options, string optionKey, CommandLineParser commandLine, string commandLineKey)
    {
        var commandlineValue = commandLine.GetParameterValue(commandLineKey);

        if (!string.IsNullOrWhiteSpace(commandlineValue))
        {
            options.AddOption(optionKey, commandlineValue);
        }
    }
    /// <summary>
    /// Creates a TaskMaster from command line arguments
    /// </summary>
    /// <param name="parsedCommandLine"></param>
    /// <returns></returns>
    public static TaskMaster FromCommandLine(CommandLineParser commandLine)
    {
        //----------------------------------------------------------------------
        //Add common options
        //----------------------------------------------------------------------
        var taskOptions = new TaskMasterOptions();
        //Log file
        helper_AddValueIfExists(taskOptions, TaskMasterOptions.OptionParameter_SaveLogFile, commandLine, CommandLineParser.Parameter_LogFile);
        //Error file
        helper_AddValueIfExists(taskOptions, TaskMasterOptions.OptionParameter_SaveErrorsFile, commandLine, CommandLineParser.Parameter_ErrorsFile);
        //Manual steps file
        helper_AddValueIfExists(taskOptions, TaskMasterOptions.OptionParameter_SaveManualSteps, commandLine, CommandLineParser.Parameter_ManualStepsFile);

        //Verbose logging
        if(commandLine.GetParameterValueAsBool(CommandLineParser.Parameter_LogVerbose, false))
        {
            taskOptions.AddOption(TaskMasterOptions.Option_LogVerbose);
        }

        //Background keep alive requests
        if (commandLine.GetParameterValueAsBool(CommandLineParser.Parameter_BackgroundKeepAlive, false))
        {
            taskOptions.AddOption(TaskMasterOptions.Option_BackgroundKeepAlive);
        }

        //----------------------------------------------------------------------------
        //Which command are we dealing with?
        //----------------------------------------------------------------------------
        var commandType = commandLine.GetParameterValue(CommandLineParser.Parameter_Command);

        if(commandType == CommandLineParser.ParameterValue_Command_Inventory)
        {
            return helper_CreateTaskMaster_SiteInventory(
                commandLine.GetParameterValue(CommandLineParser.Parameter_InventoryOutputFile)
                ,commandLine.GetParameterValue(CommandLineParser.Parameter_FromSiteUrl)
                ,commandLine.GetParameterValue(CommandLineParser.Parameter_FromUserId)
                ,commandLine.GetParameterValue(CommandLineParser.Parameter_FromUserPassword)
                ,commandLine.GetParameterValueAsBool(CommandLineParser.Parameter_FromSiteIsSystemAdmin)
                ,commandLine.GetParameterValueAsBool(CommandLineParser.Parameter_GenerateInventoryTwb, false)
                ,taskOptions
                );
        }
        else if (commandType == CommandLineParser.ParameterValue_Command_Export)
        {
            return helper_CreateTaskMaster_SiteExport(
                commandLine.GetParameterValue(CommandLineParser.Parameter_ExportDirectory)
                ,commandLine.GetParameterValue(CommandLineParser.Parameter_FromSiteUrl)
                ,commandLine.GetParameterValue(CommandLineParser.Parameter_FromUserId)
                ,commandLine.GetParameterValue(CommandLineParser.Parameter_FromUserPassword)
                ,commandLine.GetParameterValueAsBool(CommandLineParser.Parameter_FromSiteIsSystemAdmin) || commandLine.GetParameterValueAsBool(CommandLineParser.Parameter_FromSiteIsSiteAdmin)
                ,commandLine.GetParameterValue(CommandLineParser.Parameter_ExportSingleProject)
                ,commandLine.GetParameterValue(CommandLineParser.Parameter_ExportOnlyWithTag)
                ,commandLine.GetParameterValueAsBool(CommandLineParser.Parameter_RemoveTagAfterExport, false)
                ,commandLine.GetParameterValueAsBool(CommandLineParser.Parameter_GenerateInfoFilesForDownloads, false)
                , taskOptions
                );
        }
        else if (commandType == CommandLineParser.ParameterValue_Command_Import)
        {
            return helper_CreateTaskMaster_SiteImport(
                commandLine.GetParameterValue(CommandLineParser.Parameter_ImportDirectory)
                ,commandLine.GetParameterValue(CommandLineParser.Parameter_ToSiteUrl)
                ,commandLine.GetParameterValue(CommandLineParser.Parameter_ToUserId)
                ,commandLine.GetParameterValue(CommandLineParser.Parameter_ToUserPassword)
                ,commandLine.GetParameterValueAsBool(CommandLineParser.Parameter_ToSiteIsSystemAdmin) || commandLine.GetParameterValueAsBool(CommandLineParser.Parameter_ToSiteIsSiteAdmin)
                ,commandLine.GetParameterValueAsBool(CommandLineParser.Parameter_RemapDataserverReferences)
                ,commandLine.GetParameterValue(CommandLineParser.Parameter_DBCredentialsFile)
                ,commandLine.GetParameterValueAsBool(CommandLineParser.Parameter_ImportAssignContentOwnership)
                ,taskOptions
                );
        }

        AppDiagnostics.Assert(false, "Unknown command: " + commandType);
        return null;
    }
 /// <summary>
 /// Helper: Adds a command line parameter (if it exists) to the Options colleciton
 /// </summary>
 /// <param name="options"></param>
 /// <param name="optionKey"></param>
 /// <param name="commandLine"></param>
 /// <param name="commandLineKey"></param>
 private static void helper_AddValueIfExists(TaskMasterOptions options, string optionKey, CommandLineParser commandLine, string commandLineKey)
 {
     var commandlineValue = commandLine.GetParameterValue(commandLineKey);
     if (!string.IsNullOrWhiteSpace(commandlineValue))
     {
         options.AddOption(optionKey, commandlineValue);
     }
 }
Exemple #4
0
    /// <summary>
    /// Creates a TaskMaster from command line arguments
    /// </summary>
    /// <param name="parsedCommandLine"></param>
    /// <returns></returns>
    public static TaskMaster FromCommandLine(CommandLineParser commandLine)
    {
        //----------------------------------------------------------------------
        //Add common options
        //----------------------------------------------------------------------
        var taskOptions = new TaskMasterOptions();

        //Log file
        helper_AddValueIfExists(taskOptions, TaskMasterOptions.OptionParameter_SaveLogFile, commandLine, CommandLineParser.Parameter_LogFile);
        //Error file
        helper_AddValueIfExists(taskOptions, TaskMasterOptions.OptionParameter_SaveErrorsFile, commandLine, CommandLineParser.Parameter_ErrorsFile);
        //Manual steps file
        helper_AddValueIfExists(taskOptions, TaskMasterOptions.OptionParameter_SaveManualSteps, commandLine, CommandLineParser.Parameter_ManualStepsFile);

        //Verbose logging
        if (commandLine.GetParameterValueAsBool(CommandLineParser.Parameter_LogVerbose, false))
        {
            taskOptions.AddOption(TaskMasterOptions.Option_LogVerbose);
        }

        //Background keep alive requests
        if (commandLine.GetParameterValueAsBool(CommandLineParser.Parameter_BackgroundKeepAlive, false))
        {
            taskOptions.AddOption(TaskMasterOptions.Option_BackgroundKeepAlive);
        }

        //----------------------------------------------------------------------------
        //Which command are we dealing with?
        //----------------------------------------------------------------------------
        var commandType = commandLine.GetParameterValue(CommandLineParser.Parameter_Command);

        if (commandType == CommandLineParser.ParameterValue_Command_Inventory)
        {
            return(helper_CreateTaskMaster_SiteInventory(
                       commandLine.GetParameterValue(CommandLineParser.Parameter_InventoryOutputFile)
                       , commandLine.GetParameterValue(CommandLineParser.Parameter_FromSiteUrl)
                       , commandLine.GetParameterValue(CommandLineParser.Parameter_FromUserId)
                       , commandLine.GetParameterValue(CommandLineParser.Parameter_FromUserPassword)
                       , commandLine.GetParameterValueAsBool(CommandLineParser.Parameter_FromSiteIsSystemAdmin)
                       , commandLine.GetParameterValueAsBool(CommandLineParser.Parameter_GenerateInventoryTwb, false)
                       , taskOptions
                       ));
        }
        else if (commandType == CommandLineParser.ParameterValue_Command_Export)
        {
            return(helper_CreateTaskMaster_SiteExport(
                       commandLine.GetParameterValue(CommandLineParser.Parameter_ExportDirectory)
                       , commandLine.GetParameterValue(CommandLineParser.Parameter_FromSiteUrl)
                       , commandLine.GetParameterValue(CommandLineParser.Parameter_FromUserId)
                       , commandLine.GetParameterValue(CommandLineParser.Parameter_FromUserPassword)
                       , commandLine.GetParameterValueAsBool(CommandLineParser.Parameter_FromSiteIsSystemAdmin) || commandLine.GetParameterValueAsBool(CommandLineParser.Parameter_FromSiteIsSiteAdmin)
                       , commandLine.GetParameterValue(CommandLineParser.Parameter_ExportSingleProject)
                       , commandLine.GetParameterValue(CommandLineParser.Parameter_ExportOnlyWithTag)
                       , commandLine.GetParameterValueAsBool(CommandLineParser.Parameter_RemoveTagAfterExport, false)
                       , commandLine.GetParameterValueAsBool(CommandLineParser.Parameter_GenerateInfoFilesForDownloads, false)
                       , taskOptions
                       ));
        }
        else if (commandType == CommandLineParser.ParameterValue_Command_Import)
        {
            return(helper_CreateTaskMaster_SiteImport(
                       commandLine.GetParameterValue(CommandLineParser.Parameter_ImportDirectory)
                       , commandLine.GetParameterValue(CommandLineParser.Parameter_ToSiteUrl)
                       , commandLine.GetParameterValue(CommandLineParser.Parameter_ToUserId)
                       , commandLine.GetParameterValue(CommandLineParser.Parameter_ToUserPassword)
                       , commandLine.GetParameterValueAsBool(CommandLineParser.Parameter_ToSiteIsSystemAdmin) || commandLine.GetParameterValueAsBool(CommandLineParser.Parameter_ToSiteIsSiteAdmin)
                       , commandLine.GetParameterValueAsBool(CommandLineParser.Parameter_RemapDataserverReferences)
                       , commandLine.GetParameterValue(CommandLineParser.Parameter_DBCredentialsFile)
                       , commandLine.GetParameterValueAsBool(CommandLineParser.Parameter_ImportAssignContentOwnership)
                       , taskOptions
                       ));
        }

        AppDiagnostics.Assert(false, "Unknown command: " + commandType);
        return(null);
    }