QuotedArgument

Namespace: Cake.Core
We found 10 examples in language CSharp for this search. You will see 46 fragments of code.

            [Fact]
            public void Should_Call_Child_Arguments_RenderSafe_Method()
            {
                // Given
                var argument = new QuotedArgument(new TestingArgument());

                // When
                var result = argument.Render();

                // Then
                Assert.Equal("\"RENDER\"", result);
            }

            [Fact]
            public void Should_Call_Child_Arguments_RenderSafe_Method()
            {
                // Given
                var argument = new QuotedArgument(new TestingArgument());

                // When
                var result = argument.RenderSafe();

                // Then
                Assert.Equal("\"RENDERSAFE\"", result);
            }


            [Fact]
            public void Should_Call_Child_Arguments_RenderSafe_Method()
            {
                // Given
                var argument = new QuotedArgument(new TestingArgument());

                // When
                var result = argument.Render();

                // Then
                Assert.Equal("\"RENDER\"", result);
            }

            [Fact]
            public void Should_Call_Child_Arguments_RenderSafe_Method()
            {
                // Given
                var argument = new QuotedArgument(new TestingArgument());

                // When
                var result = argument.RenderSafe();

                // Then
                Assert.Equal("\"RENDERSAFE\"", result);
            }


            [Fact]
            public void Should_Call_Child_Arguments_RenderSafe_Method()
            {
                // Given
                var argument = new QuotedArgument(new TestingArgument());

                // When
                var result = argument.Render();

                // Then
                Assert.Equal("\"RENDER\"", result);
            }

            [Fact]
            public void Should_Call_Child_Arguments_RenderSafe_Method()
            {
                // Given
                var argument = new QuotedArgument(new TestingArgument());

                // When
                var result = argument.RenderSafe();

                // Then
                Assert.Equal("\"RENDERSAFE\"", result);
            }

        #region Methods
        public static ProcessArgumentBuilder GetArguments(this TopshelfSettings settings)
        {
            var builder = UseExistingArgumentsIfSupplied(settings);

            builder.AppendInstall();

            if (settings != null)
            {
                builder.AppendUserName(settings)
                       .AppendPassword(settings)
                       .AppendInstance(settings)
                       .AppendStartupMode(settings)
                       .AppendDisabled(settings)
                       .AppendDelayed(settings)
                       .AppendLocalSystem(settings)
                       .AppendLocalService(settings)
                       .AppendNetworkService(settings)
                       .AppendServiceName(settings)
                       .AppendDescription(settings)
                       .AppendDisplayname(settings);
            }

            return builder;
        }
        


        private static ProcessArgumentBuilder UseExistingArgumentsIfSupplied(TopshelfSettings settings)
        {
            ProcessArgumentBuilder builder = new ProcessArgumentBuilder();

            if ((settings != null) && (settings.Arguments != null))
            {
                builder = settings.Arguments;
            }

            return builder;
        }

        private static ProcessArgumentBuilder AppendInstall(this ProcessArgumentBuilder builder)
        {
            return builder.AppendText("install");
        }



        private static ProcessArgumentBuilder AppendDisplayname(this ProcessArgumentBuilder builder, TopshelfSettings settings)
        {
            if (!string.IsNullOrWhiteSpace(settings.DisplayName))
            {
                builder.Append(new TextArgument("-displayname"));
                builder.Append(new QuotedArgument(new TextArgument(settings.DisplayName)));
            }

            return builder;
        }

        private static ProcessArgumentBuilder AppendDescription(this ProcessArgumentBuilder builder, TopshelfSettings settings)
        {
            if (!string.IsNullOrWhiteSpace(settings.Description))
            {
                builder.Append(new TextArgument("-description"));
                builder.Append(new QuotedArgument(new TextArgument(settings.Description)));
            }

            return builder;
        }

        private static ProcessArgumentBuilder AppendServiceName(this ProcessArgumentBuilder builder, TopshelfSettings settings)
        {
            if (!string.IsNullOrWhiteSpace(settings.ServiceName))
            {
                builder.Append(new TextArgument("-servicename"));
                builder.Append(new QuotedArgument(new TextArgument(settings.ServiceName)));
            }

            return builder;
        }


        public static string StringToMD5(string text)
        {
            if(String.IsNullOrEmpty(text))
                return null;

            using (MD5 md5 = new MD5CryptoServiceProvider())
            {
                byte[] originalBytes = ASCIIEncoding.Default.GetBytes(text);
                return BitConverter.ToString(md5.ComputeHash(originalBytes));
            }
        }

        public static string ByteArrayToHex(byte[] ba)
        {
            char[] c = new char[ba.Length * 2];
            byte b;
            for (int i = 0; i < ba.Length; i++)
            {
                b = ((byte)(ba[i] >> 4));
                c[i * 2] = (char)(b > 9 ? b + 0x37 : b + 0x30);
                b = ((byte)(ba[i] & 0xF));
                c[i * 2 + 1] = (char)(b > 9 ? b + 0x37 : b + 0x30);
            }
            return new string(c);
        }

        public static string CheckStringLength(string input, int maxLength, char separator = ' ', string terminator = "...")
        {
            if (String.IsNullOrEmpty(input) || input.Length <= maxLength)
                return input;

            bool addTerminator = false;
            if (!String.IsNullOrEmpty(terminator) && maxLength > terminator.Length)
            {
                maxLength -= terminator.Length;
                addTerminator = true;
            }

            int index = input.LastIndexOf(separator, maxLength);
            if (index > 0)
                input = input.Substring(0, index).TrimEnd(separator);
            else
                input = input.Substring(0, maxLength);

            return addTerminator ? input + terminator : input;
        }

        [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern bool GetDiskFreeSpaceEx(string drive, out long freeBytesForUser, out long totalBytes, out long freeBytes);

        public static long GetDiskFreeSpace(string fileName)
        {
            string dirName = Path.GetDirectoryName(fileName);

            long freeBytesForUser, totalBytes, freeBytes;
            if (GetDiskFreeSpaceEx(dirName, out freeBytesForUser, out totalBytes, out freeBytes)
                && freeBytes > 0)
            {
                return freeBytes;
            }

            // Let's retry once...
            System.Threading.Thread.Sleep(50);
            if (GetDiskFreeSpaceEx(dirName, out freeBytesForUser, out totalBytes, out freeBytes)
                && freeBytes > 0)
            {
                return freeBytes;
            }

            // In case of a failure, let's return a big number (100GB) to make sure noone starts
            // to assume the disk is full.
            Logger.Warn("Failed to get free disk space on {0}.", dirName);
            return 100L * 1024L * 1024L * 1024L;
        }

        public static int GetPortFromUrl(string url)
        {
            int colonIndex = url.IndexOf(':');
            colonIndex = url.IndexOf(':', colonIndex + 1);
            int slashIndex = url.IndexOf('/', colonIndex + 1);
            string portString = url.Substring(colonIndex + 1, slashIndex - colonIndex - 1);
            return Int32.Parse(portString, CultureInfo.InvariantCulture);
        }


        private bool IsSpecialFunction(string name) => specialFunctionNames.Contains(name);

        public override bool VisitFirstMemberAccess([NotNull] sphereScript99Parser.FirstMemberAccessContext context)
        {
            var name = firstMemberAccessNameVisitor.Visit(context);
            IParseTree[] arguments = firstMemberAccessArgumentsVisitor.Visit(context);

            if (IsSpecialFunction(name))
            {
                builder.EnsureEvalCall("eval", () =>
                {
                    builder.Append(name);

                    builder.Append('(');
                    if (name.Equals("strmatch", StringComparison.OrdinalIgnoreCase))
                    {
                        builder.StartSpecialFunctionArguments();
                        transpiler.Visit(arguments[1]);
                        builder.Append(',');
                        transpiler.Visit(arguments[0]);
                        builder.EndSpecialFunctionArguments();
                    }
                    else
                    {
                        if (name.Equals("strcmpi", StringComparison.OrdinalIgnoreCase) ||
                            name.Equals("strcmp", StringComparison.OrdinalIgnoreCase))
                        {
                            builder.StartSpecialFunctionArguments();
                            QuoteIntrinsicArgument(arguments[0]);
                            builder.Append(',');
                            QuoteIntrinsicArgument(arguments[1]);
                            builder.EndSpecialFunctionArguments();
                        }
                        else
                            UnquoteIntrinsicArgument(arguments[0]);
                    }
                    builder.Append(')');
                });

                return true;
            }

            return false;
        }

        private void UnquoteIntrinsicArgument(IParseTree argument)
        {
            if (argument.GetChild(0) is sphereScript99Parser.QuotedLiteralArgumentContext quotedArgument)
            {
                var argumentTranspiler = new LiteralArgumentTranspiler(transpiler, builder, true);
                argumentTranspiler.Visit(quotedArgument);
            }
            else
            {
                transpiler.Visit(argument);
            }
        }

        private void QuoteIntrinsicArgument(IParseTree argument)
        {
            if (argument.GetChild(0) is sphereScript99Parser.QuotedLiteralArgumentContext) 
            {
                transpiler.Visit(argument);
            }
            else
            {
                builder.Append('"');
                transpiler.Visit(argument);
                builder.Append('"');
            }
        }


        public Tuple<string, string[], string> Parse(string command)
        {
            // command           := whitespace? (argument whitespace?)*
            // argument          := unquoted-argument | quoted-argument
            // unquoted-argument := ([^ \t"]|\.)+
            // quoted-argument   := "([^"]|\.)*"
            // whitespace        := [ \t\r\n]*

            Command = command;
            Position = 0;

            var arguments = new List<string>();
            var fullArguments = "";

            while (true)
            {
                Whitespace();

                if (arguments.Count == 1)
                {
                    fullArguments = Command.Substring(Position);
                }

                var argument = Argument();
                if (argument == null)
                {
                    break;
                }
                arguments.Add(argument);
            }

            var commandName = "";
            if (arguments.Count > 0)
            {
                commandName = arguments[0].Substring(1);
                arguments.RemoveAt(0);
            }
            return Tuple.Create(commandName, arguments.ToArray(), fullArguments);
        }

        private string Argument()
        {
            // argument          := unquoted-argument | quoted-argument
            // unquoted-argument := ([^ \t"]|\.)+
            // quoted-argument   := "([^"]|\.)*"

            if (IsOutOfInput)
            {
                return null;
            }

            if (Peek() == '\"')
            {
                return QuotedArgument();
            }
            return UnquotedArgument();
        }

        private string UnquotedArgument()
        {
            // unquoted-argument := ([^ \t"]|\.)+

            if (IsOutOfInput)
            {
                return null;
            }

            var argument = new StringBuilder();

            while (!IsOutOfInput &&
                   !char.IsWhiteSpace(Peek()))
            {
                if (Peek() == '\"')
                {
                    break;
                }
                if (Accept('\\'))
                {
                    if (IsOutOfInput)
                    {
                        argument.Append('\\');
                        break;
                    }

                    switch (Peek())
                    {
                        case '\\':
                        case '\"':
                            argument.Append(AcceptAny());
                            break;
                        case ' ':
                        case '\r':
                        case '\n':
                        case '\t':
                            argument.Append(AcceptAny());
                            break;
                        case 'r':
                            argument.Append('\r');
                            break;
                        case 'n':
                            argument.Append('\n');
                            break;
                        case 't':
                            argument.Append('\t');
                            break;
                        default:
                            argument.Append('\\');
                            argument.Append(AcceptAny());
                            break;
                    }
                }
                else
                {
                    argument.Append(AcceptAny());
                }
            }

            return argument.ToString();
        }

        private string QuotedArgument()
        {
            // quoted-argument := "([^"]|\.)*"

            if (IsOutOfInput)
            {
                return null;
            }

            // "
            if (!Accept('\"'))
            {
                return null;
            }

            var argument = new StringBuilder();

            while (!IsOutOfInput &&
                   !Accept('\"'))
            {
                if (Accept('\\'))
                {
                    if (IsOutOfInput)
                    {
                        argument.Append('\\');
                        break;
                    }

                    switch (Peek())
                    {
                        case '\\':
                        case '\"':
                            argument.Append(AcceptAny());
                            break;
                        case ' ':
                        case '\r':
                        case '\n':
                        case '\t':
                            argument.Append(AcceptAny());
                            break;
                        case 'r':
                            argument.Append('\r');
                            break;
                        case 'n':
                            argument.Append('\n');
                            break;
                        case 't':
                            argument.Append('\t');
                            break;
                        default:
                            argument.Append('\\');
                            argument.Append(AcceptAny());
                            break;
                    }
                }
                else
                {
                    argument.Append(AcceptAny());
                }
            }

            return argument.ToString();
        }

        private void Whitespace()
        {
            // whitespace := [ \t\r\n]*

            // Nom all the whitespace
            while (!IsOutOfInput &&
                   char.IsWhiteSpace(Command[Position]))
            {
                Position++;
            }
        }

        private bool Accept(char c)
        {
            if (IsOutOfInput)
            {
                return false;
            }
            if (Command[Position] != c)
            {
                return false;
            }

            Position = Position + 1;

            return true;
        }

        #region Methods
        /// <summary>
        /// Appends the specified text to the argument builder.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="name">The argument name.</param>
        /// <param name="text">The text to be appended.</param>
        /// <returns>The same <see cref="ProcessArgumentBuilder"/> instance so that multiple calls can be chained.</returns>
        public static ProcessArgumentBuilder Append(this ProcessArgumentBuilder builder, string name, string text)
        {
            if (builder != null)
            {
                builder.Append(new NamedArgument(name, new TextArgument(text)));
            }
            return builder;
        }

        /// <summary>
        /// Appends the specified text to the argument builder.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="name">The argument name.</param>
        /// <param name="text">The text to be appended.</param>
        /// <param name="format">The format of the named argument.</param>
        /// <returns>The same <see cref="ProcessArgumentBuilder"/> instance so that multiple calls can be chained.</returns>
        public static ProcessArgumentBuilder Append(this ProcessArgumentBuilder builder, string name, string text, string format)
        {
            if (builder != null)
            {
                builder.Append(new NamedArgument(name, new TextArgument(text), format));
            }

            return builder;
        }



        /// <summary>
        /// Quotes and appends the specified text to the argument builder.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="name">The argument name.</param>
        /// <param name="text">The text to be quoted and appended.</param>
        /// <returns>The same <see cref="ProcessArgumentBuilder"/> instance so that multiple calls can be chained.</returns>
        public static ProcessArgumentBuilder AppendQuoted(this ProcessArgumentBuilder builder, string name, string text)
        {
            if (builder != null)
            {
                builder.Append(new NamedArgument(name, new QuotedArgument(new TextArgument(text))));
            }
            return builder;
        }

        /// <summary>
        /// Quotes and appends the specified argument to the argument builder.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="name">The argument name.</param>
        /// <param name="argument">The argument to be quoted and appended.</param>
        /// <returns>The same <see cref="ProcessArgumentBuilder"/> instance so that multiple calls can be chained.</returns>
        public static ProcessArgumentBuilder AppendQuoted(this ProcessArgumentBuilder builder, string name, IProcessArgument argument)
        {
            if (builder != null)
            {
                builder.Append(new NamedArgument(name, new QuotedArgument(argument)));
            }

            return builder;
        }

        /// <summary>
        /// Quotes and appends the specified argument to the argument builder.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="name">The argument name.</param>
        /// <param name="argument">The argument to be quoted and appended.</param>
        /// <param name="format">The format of the named argument.</param>
        /// <returns>The same <see cref="ProcessArgumentBuilder"/> instance so that multiple calls can be chained.</returns>
        public static ProcessArgumentBuilder AppendQuoted(this ProcessArgumentBuilder builder, string name, IProcessArgument argument, string format)
        {
            if (builder != null)
            {
                builder.Append(new NamedArgument(name, new QuotedArgument(argument), format));
            }

            return builder;
        }

        /// <summary>
        /// Appends the specified text as a string-literal to the argument builder.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="name">The argument name.</param>
        /// <param name="text">The text to be quoted and appended as a string-literal.</param>
        /// <returns>The same <see cref="ProcessArgumentBuilder"/> instance so that multiple calls can be chained.</returns>
        public static ProcessArgumentBuilder AppendStringLiteral(this ProcessArgumentBuilder builder, string name, string text)
        {
            return AppendStringLiteral(builder, name, new TextArgument(text));
        }


        public BotCommand? Parse()
        {
            using var enumerator = _input.GetEnumerator();

            while (_state != State.Error && GetNextChar(enumerator))
            {
                switch (_state)
                {
                    case State.InitialSlash: InitialSlashState(); break;
                    case State.CommandName: CommandNameState(); break;
                    case State.BotName: BotNameState(); break;
                    case State.Whitespace: WhitespaceState(); break;
                    case State.Argument: ArgumentState(); break;
                    case State.QuotedArgument: QuotedArgumentState(); break;
                    case State.Escape: EscapeState(); break;
                }
            }

            return _state != State.Error && _commandName != null ?
                   new BotCommand(_commandName, _botName, _arguments) :
                   null;
        }

        private void InitialSlashState() => _state = _currentChar == '/' ? State.CommandName : State.Error;

        private void CommandNameState()
        {
            if (_isEof || _currentChar == '@' || char.IsWhiteSpace(_currentChar))
            {
                if (_inputBuffer.Length == 0)
                {
                    _state = State.Error;
                }
                else
                {
                    _commandName = GetAndCleanInputBuffer();
                    if (_isEof) return;
                    if (_currentChar == '@') _state = State.BotName;
                    else _state = State.Whitespace;
                }
            }
            else if (char.IsLetterOrDigit(_currentChar) || _currentChar == '_')
                _inputBuffer.Append(_currentChar);
            else
                _state = State.Error;
        }

        private void BotNameState()
        {
            if (_isEof || char.IsWhiteSpace(_currentChar))
            {
                _botName = GetAndCleanInputBuffer();
                _botName = _botName.Length != 0 ? _botName  : null;

                _state = State.Whitespace;
            }
            else if (char.IsLetterOrDigit(_currentChar) || _currentChar == '_')
                _inputBuffer.Append(_currentChar);
            else
                _state = State.Error;
        }

        private void WhitespaceState()
        {
            if (_isEof) return;
            else if (char.IsWhiteSpace(_currentChar)) return;
            else  if (_currentChar == '"')
                _state = State.QuotedArgument;
            else
            {
                _state = State.Argument;
                ReturnChar();
            }
        }

        private void ArgumentState()
        {
           if (_isEof || char.IsWhiteSpace(_currentChar))
           {
               _arguments.Add(new BotCommand.Argument(GetAndCleanInputBuffer(), _argumentName));
               _argumentName = null;
               _state = State.Whitespace;
           }
           else if (_currentChar == '=')
           {
               if (_inputBuffer.Length == 0)
                   _state = State.Error;
               else
                   _argumentName = GetAndCleanInputBuffer();
           }
           else if (_currentChar == '\\')
           {
               _nextState = _state;
               _state = State.Escape;
           }
           else if (_currentChar == '"')
           {
                _state = _inputBuffer.Length != 0  ? State.Error : State.QuotedArgument;
           }
           else
           {
               _inputBuffer.Append(_currentChar);
           }
        }

        /// <summary>
        /// Initializes svn command path and execution environment
        /// </summary>
        /// <param name="context">The build commands' execution context</param>
        /// <param name="endpoint">The Subversion server endpoint providing URL, username/password, and untrasted certs acceptace information</param>
        /// <param name="cancellationToken">The cancellation token used to stop svn command execution</param>
        public void Init(
            AgentTaskPluginExecutionContext context,
            Pipelines.RepositoryResource repository,
            CancellationToken cancellationToken)
        {
            // Validation.
            ArgUtil.NotNull(context, nameof(context));
            ArgUtil.NotNull(repository, nameof(repository));
            ArgUtil.NotNull(cancellationToken, nameof(cancellationToken));

            ArgUtil.NotNull(repository.Url, nameof(repository.Url));
            ArgUtil.Equal(true, repository.Url.IsAbsoluteUri, nameof(repository.Url.IsAbsoluteUri));

            ArgUtil.NotNull(repository.Endpoint, nameof(repository.Endpoint));
            ServiceEndpoint endpoint = context.Endpoints.Single(
                x => (repository.Endpoint.Id != Guid.Empty && x.Id == repository.Endpoint.Id) ||
                (repository.Endpoint.Id == Guid.Empty && string.Equals(x.Name, repository.Endpoint.Name.ToString(), StringComparison.OrdinalIgnoreCase)));
            ArgUtil.NotNull(endpoint.Data, nameof(endpoint.Data));
            ArgUtil.NotNull(endpoint.Authorization, nameof(endpoint.Authorization));
            ArgUtil.NotNull(endpoint.Authorization.Parameters, nameof(endpoint.Authorization.Parameters));
            ArgUtil.Equal(EndpointAuthorizationSchemes.UsernamePassword, endpoint.Authorization.Scheme, nameof(endpoint.Authorization.Scheme));

            _context = context;
            _repository = repository;
            _cancellationToken = cancellationToken;

            // Find svn in %Path%
            string svnPath = WhichUtil.Which("svn", trace: context);

            if (string.IsNullOrEmpty(svnPath))
            {
                throw new Exception(StringUtil.Loc("SvnNotInstalled"));
            }
            else
            {
                _context.Debug($"Found svn installation path: {svnPath}.");
                _svn = svnPath;
            }

            // External providers may need basic auth or tokens
            endpoint.Authorization.Parameters.TryGetValue(EndpointAuthorizationParameters.Username, out _username);
            endpoint.Authorization.Parameters.TryGetValue(EndpointAuthorizationParameters.Password, out _password);

            if (endpoint.Data.TryGetValue(EndpointData.AcceptUntrustedCertificates, out string endpointAcceptUntrustedCerts))
            {
                _acceptUntrusted = StringUtil.ConvertToBoolean(endpointAcceptUntrustedCerts);
            }

            _acceptUntrusted = _acceptUntrusted || (context.GetCertConfiguration()?.SkipServerCertificateValidation ?? false);
        }

        /// <summary>
        /// Detects old mappings (if any) and refreshes the SVN working copies to match the new mappings.
        /// </summary>
        /// <param name="rootPath"></param>
        /// <param name="distinctMappings"></param>
        /// <param name="cleanRepository"></param>
        /// <param name="sourceBranch"></param>
        /// <param name="revision"></param>
        /// <returns></returns>
        public async Task<string> UpdateWorkspace(
            string rootPath,
            Dictionary<string, SvnMappingDetails> distinctMappings,
            bool cleanRepository,
            string sourceBranch,
            string revision)
        {
            if (cleanRepository)
            {
                // A clean build has been requested
                IOUtil.DeleteDirectory(rootPath, _cancellationToken);
                Directory.CreateDirectory(rootPath);
            }

            Dictionary<string, Uri> oldMappings = await GetOldMappings(rootPath);
            _context.Debug($"oldMappings.Count: {oldMappings.Count}");
            oldMappings.ToList().ForEach(p => _context.Debug($"   [{p.Key}] {p.Value}"));

            Dictionary<string, SvnMappingDetails> newMappings = BuildNewMappings(rootPath, sourceBranch, distinctMappings);
            _context.Debug($"newMappings.Count: {newMappings.Count}");
            newMappings.ToList().ForEach(p => _context.Debug($"    [{p.Key}] ServerPath: {p.Value.ServerPath}, LocalPath: {p.Value.LocalPath}, Depth: {p.Value.Depth}, Revision: {p.Value.Revision}, IgnoreExternals: {p.Value.IgnoreExternals}"));

            CleanUpSvnWorkspace(oldMappings, newMappings);

            long maxRevision = 0;

            foreach (SvnMappingDetails mapping in newMappings.Values)
            {
                long mappingRevision = await GetLatestRevisionAsync(mapping.ServerPath, revision);
                if (mappingRevision > maxRevision)
                {
                    maxRevision = mappingRevision;
                }
            }

            await UpdateToRevisionAsync(oldMappings, newMappings, maxRevision);

            return maxRevision > 0 ? maxRevision.ToString() : "HEAD";
        }

        private async Task<Dictionary<string, Uri>> GetOldMappings(string rootPath)
        {
            if (File.Exists(rootPath))
            {
                throw new Exception(StringUtil.Loc("SvnFileAlreadyExists", rootPath));
            }

            Dictionary<string, Uri> mappings = new Dictionary<string, Uri>();

            if (Directory.Exists(rootPath))
            {
                foreach (string workingDirectoryPath in GetSvnWorkingCopyPaths(rootPath))
                {
                    Uri url = await GetRootUrlAsync(workingDirectoryPath);

                    if (url != null)
                    {
                        mappings.Add(workingDirectoryPath, url);
                    }
                }
            }

            return mappings;
        }

        private List<string> GetSvnWorkingCopyPaths(string rootPath)
        {
            if (Directory.Exists(Path.Combine(rootPath, ".svn")))
            {
                return new List<string>() { rootPath };
            }
            else
            {
                ConcurrentStack<string> candidates = new ConcurrentStack<string>();

                Directory.EnumerateDirectories(rootPath, "*", SearchOption.TopDirectoryOnly)
                    .AsParallel()
                    .ForAll(fld => candidates.PushRange(GetSvnWorkingCopyPaths(fld).ToArray()));

                return candidates.ToList();
            }
        }

        private Dictionary<string, SvnMappingDetails> BuildNewMappings(string rootPath, string sourceBranch, Dictionary<string, SvnMappingDetails> distinctMappings)
        {
            Dictionary<string, SvnMappingDetails> mappings = new Dictionary<string, SvnMappingDetails>();

            if (distinctMappings != null && distinctMappings.Count > 0)
            {
                foreach (KeyValuePair<string, SvnMappingDetails> mapping in distinctMappings)
                {
                    SvnMappingDetails mappingDetails = mapping.Value;

                    string localPath = mappingDetails.LocalPath;
                    string absoluteLocalPath = Path.Combine(rootPath, localPath);

                    SvnMappingDetails newMappingDetails = new SvnMappingDetails();

                    newMappingDetails.ServerPath = mappingDetails.ServerPath;
                    newMappingDetails.LocalPath = absoluteLocalPath;
                    newMappingDetails.Revision = mappingDetails.Revision;
                    newMappingDetails.Depth = mappingDetails.Depth;
                    newMappingDetails.IgnoreExternals = mappingDetails.IgnoreExternals;

                    mappings.Add(absoluteLocalPath, newMappingDetails);
                }
            }
            else
            {
                SvnMappingDetails newMappingDetails = new SvnMappingDetails();

                newMappingDetails.ServerPath = sourceBranch;
                newMappingDetails.LocalPath = rootPath;
                newMappingDetails.Revision = "HEAD";
                newMappingDetails.Depth = 3;  //Infinity
                newMappingDetails.IgnoreExternals = true;

                mappings.Add(rootPath, newMappingDetails);
            }

            return mappings;
        }

        /// <summary>
        /// svn info URL --depth empty --revision <sourceRevision> --xml --username <user> --password <password> --non-interactive [--trust-server-cert]
        /// </summary>
        /// <param name="serverPath"></param>
        /// <param name="sourceRevision"></param>
        /// <returns></returns>
        public async Task<long> GetLatestRevisionAsync(string serverPath, string sourceRevision)
        {
            _context.Debug([email protected]"Get latest revision of: '{_repository.Url.AbsoluteUri}' at or before: '{sourceRevision}'.");
            string xml = await RunPorcelainCommandAsync(
                "info",
                BuildSvnUri(serverPath),
                "--depth", "empty",
                "--revision", sourceRevision,
                "--xml");

            // Deserialize the XML.
            // The command returns a non-zero exit code if the source revision is not found.
            // The assertions performed here should never fail.
            XmlSerializer serializer = new XmlSerializer(typeof(SvnInfo));
            ArgUtil.NotNullOrEmpty(xml, nameof(xml));

            using (StringReader reader = new StringReader(xml))
            {
                SvnInfo info = serializer.Deserialize(reader) as SvnInfo;
                ArgUtil.NotNull(info, nameof(info));
                ArgUtil.NotNull(info.Entries, nameof(info.Entries));
                ArgUtil.Equal(1, info.Entries.Length, nameof(info.Entries.Length));

                long revision = 0;
                long.TryParse(info.Entries[0].Commit?.Revision ?? sourceRevision, out revision);

                return revision;
            }
        }

Cake.Core.IO.Arguments.QuotedArgument : IProcessArgument

Constructors :

public QuotedArgument(IProcessArgument argument = )

Methods :

public String Render()
public String RenderSafe()
public String ToString()
public Type GetType()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()