示例#1
0
 protected static void ParseArgs(string[] args)
 {
     Arguments = new ParsedArguments(args, ValidArgumentInfo.ToArray());
     if (Arguments.Status == ArgumentParseStatus.Error || Arguments.Status == ArgumentParseStatus.Invalid)
     {
         ArgsParsedError?.Invoke(Arguments);
     }
     else if (Arguments.Status == ArgumentParseStatus.Success)
     {
         ArgsParsed?.Invoke(Arguments);
     }
 }
        /// <summary>
        /// Gets the value for the argument
        /// </summary>
        /// <param name="parameterName">Parameter name whose value to get</param>
        /// <returns>Value of the argument</returns>
        public string[] GetValue(string parameterName)
        {
            if (String.IsNullOrEmpty(parameterName))
            {
                throw new ArgumentException(nameof(parameterName));
            }

            var possibleArgument = Command.GetParameter(parameterName);

            if (possibleArgument != null)
            {
                return(GetValue(possibleArgument));
            }
            else
            {
                return(ArgsParsed.ContainsKey(parameterName) ? ArgsParsed[parameterName] : null);
            }
        }
示例#3
0
文件: Program.cs 项目: flecoqui/azure
        static void Main(string[] args)
        {
            ArgsParsed arg = ParseArgs(args);

            if (string.IsNullOrEmpty(arg.ErrorMessage))
            {
                if (arg.action == Action.Create)
                {
                    if (CreatePlayList(arg.StorageAccountName, arg.StorageAccountKey, arg.ContainerName, arg.extensions, arg.outputFileName, out arg.ErrorMessage) != true)
                    {
                        DumpSyntax(arg.ErrorMessage);
                    }
                }
                else if (arg.action == Action.Dump)
                {
                    if (CreatePlayList(arg.StorageAccountName, arg.StorageAccountKey, arg.ContainerName, arg.extensions, null, out arg.ErrorMessage) != true)
                    {
                        DumpSyntax(arg.ErrorMessage);
                    }
                }
                else if (arg.action == Action.LocalCreate)
                {
                    if (CreateLocalPlayList(arg.Folder, arg.extensions, arg.outputFileName, out arg.ErrorMessage) != true)
                    {
                        DumpSyntax(arg.ErrorMessage);
                    }
                }
                else if (arg.action == Action.LocalDump)
                {
                    if (CreateLocalPlayList(arg.Folder, arg.extensions, null, out arg.ErrorMessage) != true)
                    {
                        DumpSyntax(arg.ErrorMessage);
                    }
                }
                else
                {
                    DumpSyntax("Not implemented");
                }
            }
            else
            {
                DumpSyntax(arg.ErrorMessage);
            }
        }
示例#4
0
文件: Program.cs 项目: flecoqui/azure
        static void CheckArgs(ArgsParsed arg)
        {
            arg.ErrorMessage = string.Empty;

            if (arg.action == Action.Create)
            {
                if (string.IsNullOrEmpty(arg.outputFileName) &&
                    string.IsNullOrEmpty(arg.StorageAccountName) &&
                    string.IsNullOrEmpty(arg.StorageAccountKey) &&
                    string.IsNullOrEmpty(arg.extensions) &&
                    string.IsNullOrEmpty(arg.ContainerName))
                {
                    arg.ErrorMessage = string.Empty;
                }
                else
                {
                    arg.ErrorMessage = "Missing argument for Create Playlist scenario";
                }
            }
            else if (arg.action == Action.Dump)
            {
                if (string.IsNullOrEmpty(arg.StorageAccountName) &&
                    string.IsNullOrEmpty(arg.StorageAccountKey) &&
                    string.IsNullOrEmpty(arg.extensions) &&
                    string.IsNullOrEmpty(arg.ContainerName))
                {
                    arg.ErrorMessage = string.Empty;
                }
                else
                {
                    arg.ErrorMessage = "Missing argument for Dump Playlist scenario";
                }
            }
            else
            {
                arg.ErrorMessage = "Unexpected action";
            }
        }
        /// <summary>
        /// Gets the value for the argument
        /// </summary>
        /// <param name="parameter">Parameter whose value to get</param>
        /// <returns>Value of the argument</returns>
        public string[] GetValue(CommandParameter parameter)
        {
            if (parameter == null)
            {
                throw new ArgumentException(nameof(parameter));
            }

            // Check in arguments parsed
            var longName = parameter?.GetFullLongName();
            var value    = ArgsParsed.ContainsKey(longName) ? ArgsParsed[longName] : null;

            // Check in short names
            if (value == null)
            {
                var shortName = NameMap.ContainsKey(longName) ? NameMap[longName] : null;
                if (shortName != null)
                {
                    value = ArgsParsed.ContainsKey(shortName) ? ArgsParsed[shortName] : null;
                }
            }

            return(value);
        }
示例#6
0
文件: Program.cs 项目: flecoqui/azure
        static ArgsParsed ParseArgs(string[] args)
        {
            ArgsParsed result = new ArgsParsed();

            result.ErrorMessage = string.Empty;
            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "-action":
                    if (++i < args.Length)
                    {
                        if (args[i] == "create")
                        {
                            result.action = Action.Create;
                        }
                        else if (args[i] == "dump")
                        {
                            result.action = Action.Dump;
                        }
                        else if (args[i] == "localcreate")
                        {
                            result.action = Action.LocalCreate;
                        }
                        else if (args[i] == "localdump")
                        {
                            result.action = Action.LocalDump;
                        }
                        else
                        {
                            result.action = Action.None;
                        }
                    }
                    break;

                case "-outputfilename":
                    if (++i < args.Length)
                    {
                        result.outputFileName = args[i];
                    }
                    break;

                case "-storageaccountname":
                    if (++i < args.Length)
                    {
                        result.StorageAccountName = args[i];
                    }
                    break;

                case "-storageaccountkey":
                    if (++i < args.Length)
                    {
                        result.StorageAccountKey = args[i];
                    }
                    break;

                case "-containername":
                    if (++i < args.Length)
                    {
                        result.ContainerName = args[i];
                    }
                    break;

                case "-folder":
                    if (++i < args.Length)
                    {
                        result.Folder = args[i];
                    }
                    break;

                case "-extensions":
                    if (++i < args.Length)
                    {
                        result.extensions = args[i];
                    }
                    break;
                }
            }
            CheckArgs(result);
            return(result);
        }