public static CLIExitCode ParseAddUserOption()

in Configurator/Core/CLI/CommandLineParser.cs [126:217]


    public static CLIExitCode ParseAddUserOption(string value, out string[] serverUserItems)
    {
      serverUserItems = null;
      if (string.IsNullOrEmpty(value))
      {
        return new CLIExitCode(ExitCode.EmptyUserBlock, ADD_USER_OPTION_NAME);
      }

      serverUserItems = new string[5];
      int itemIndex = 0;
      var builder = new StringBuilder();
      var characters = value.ToCharArray();
      var index = 0;
      bool readingSingleQuoteBlock = false;
      while (index < characters.Length)
      {
        var character = characters[index];
        if (character == '\'')
        {
          readingSingleQuoteBlock = !readingSingleQuoteBlock;
        }

        // Assign value if we will start reading the next element.
        if (!readingSingleQuoteBlock
            && character == ':')
        {
          serverUserItems[itemIndex] = builder.ToString();
          builder.Clear();
          itemIndex++;
          if (itemIndex > 4)
          {
            return new CLIExitCode(ExitCode.TooManyElementsInUserBlock, value, ADD_USER_OPTION_NAME);
          }
        }
        else
        {
          builder.Append(character);
        }

        index++;
      }

      if (builder.Length > 0)
      {
        serverUserItems[itemIndex] = builder.ToString();
      }

      // Ensure all quotes were closed.
      if (readingSingleQuoteBlock)
      {
        return new CLIExitCode(ExitCode.MissingCustomUserClosingQuote, ADD_USER_OPTION_NAME, builder.ToString());
      }

      // All elements are mandatory except for the windows security token list.
      for(int i = 0; i< serverUserItems.Length - 1; i++)
      {
        if (string.IsNullOrEmpty(serverUserItems[i]))
        {
          return new CLIExitCode(ExitCode.InvalidCustomUserEmptyValue, value, ADD_USER_OPTION_NAME);
        }
      }

      // User name is expected to be enclosed in single or double quotes.
      if (!serverUserItems[0].StartsWith("'")
           && !serverUserItems[0].EndsWith("'"))
      {
        return new CLIExitCode(ExitCode.InvalidCustomUserUserNameValue, serverUserItems[0], ADD_USER_OPTION_NAME);
      }

      // User password/token is expected to be enclosed in single or double quotes.
      if (!serverUserItems[1].StartsWith("'")
           && !serverUserItems[1].EndsWith("'"))
      {
        return new CLIExitCode(ExitCode.InvalidCustomUserPasswordValue, serverUserItems[1], ADD_USER_OPTION_NAME);
      }

      // Role is expected to be enclosed in single or double quotes.
      if (!serverUserItems[3].StartsWith("'")
           && !serverUserItems[3].EndsWith("'"))
      {
        return new CLIExitCode(ExitCode.InvalidCustomUserRoleValue, serverUserItems[3], ADD_USER_OPTION_NAME);
      }

      // Validate Windows security token is populated (if applicable).
      if (serverUserItems[4].Equals("Windows", StringComparison.InvariantCultureIgnoreCase)
          && string.IsNullOrEmpty(serverUserItems[5]))
      {
        return new CLIExitCode(ExitCode.InvalidCustomUserEmptyToken, value, ADD_USER_OPTION_NAME);
      }

      return new CLIExitCode(ExitCode.Success);
    }