public static bool TryGetUserInfo(this Uri uri, out string userName, out string password) { EnsureArgument.NotNull(uri, nameof(uri)); userName = null; password = null; if (string.IsNullOrWhiteSpace(uri.UserInfo)) { return(false); } /* According to RFC 3986 section 3.2.1 (https://tools.ietf.org/html/rfc3986#section-3.2.1) * the user information component of a URI should look like: * * url-encode(username):url-encode(password) */ string[] split = uri.UserInfo.Split(new[] { ':' }, count: 2); if (split.Length > 0) { userName = WebUtility.UrlDecode(split[0]); } if (split.Length > 1) { password = WebUtility.UrlDecode(split[1]); } return(split.Length > 0); }
public static IEnumerable <string> GetGitConfigurationScopes(this Uri uri) { EnsureArgument.NotNull(uri, nameof(uri)); string schemeAndDelim = $"{uri.Scheme}{Uri.SchemeDelimiter}"; string host = uri.Host.TrimEnd('/'); string path = uri.AbsolutePath.Trim('/'); // Unfold the path by component, right-to-left while (!string.IsNullOrWhiteSpace(path)) { yield return($"{schemeAndDelim}{host}/{path}"); // Trim off the last path component if (!TryTrimString(path, StringExtensions.TruncateFromLastIndexOf, '/', out path)) { break; } } // Unfold the host by sub-domain, left-to-right while (!string.IsNullOrWhiteSpace(host)) { if (host.Contains(".")) // Do not emit just the TLD { yield return($"{schemeAndDelim}{host}"); } // Trim off the left-most sub-domain if (!TryTrimString(host, StringExtensions.TrimUntilIndexOf, '.', out host)) { break; } } }
public HostProviderRegistry(ICommandContext context) { EnsureArgument.NotNull(context, nameof(context)); _context = context; _hostProviders = new List <IHostProvider>(); }
public EnvironmentVariables(IDictionary variables) { EnsureArgument.NotNull(variables, nameof(variables)); // On Windows it is technically possible to get env vars which differ only by case // even though the general assumption is that they are case insensitive on Windows. // For example, some of the standard .NET types like System.Diagnostics.Process // will fail to start a process on Windows if given duplicate environment variables. // See this issue for more information: https://github.com/dotnet/corefx/issues/13146 // If we're on the Windows platform we should de-duplicate by setting the string // comparer to OrdinalIgnoreCase. var comparer = PlatformUtils.IsWindows() ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal; var dict = new Dictionary <string, string>(comparer); foreach (var key in variables.Keys) { if (key is string name && variables[key] is string value) { dict[name] = value; } } _envars = dict; }
public HostProviderRegistry(ICommandContext context) { EnsureArgument.NotNull(context, nameof(context)); _context = context; _hostProviders = new Dictionary <HostProviderPriority, ICollection <IHostProvider> >(); }
public void Register(IHostProvider hostProvider, HostProviderPriority priority) { EnsureArgument.NotNull(hostProvider, nameof(hostProvider)); if (StringComparer.OrdinalIgnoreCase.Equals(hostProvider.Id, Constants.ProviderIdAuto)) { throw new ArgumentException( $"A host provider cannot be registered with the ID '{Constants.ProviderIdAuto}'", nameof(hostProvider)); } if (hostProvider.SupportedAuthorityIds.Any(y => StringComparer.OrdinalIgnoreCase.Equals(y, Constants.AuthorityIdAuto))) { throw new ArgumentException( $"A host provider cannot be registered with the legacy authority ID '{Constants.AuthorityIdAuto}'", nameof(hostProvider)); } if (!_hostProviders.TryGetValue(priority, out ICollection <IHostProvider> providers)) { providers = new List <IHostProvider>(); _hostProviders[priority] = providers; } providers.Add(hostProvider); }
public Gpg(string gpgPath, ISessionManager sessionManager) { EnsureArgument.NotNullOrWhiteSpace(gpgPath, nameof(gpgPath)); EnsureArgument.NotNull(sessionManager, nameof(sessionManager)); _gpgPath = gpgPath; _sessionManager = sessionManager; }
internal GitProcessConfiguration(ITrace trace, GitProcess git) { EnsureArgument.NotNull(trace, nameof(trace)); EnsureArgument.NotNull(git, nameof(git)); _trace = trace; _git = git; }
public Settings(IEnvironmentVariables environmentVariables, IGit git) { EnsureArgument.NotNull(environmentVariables, nameof(environmentVariables)); EnsureArgument.NotNull(git, nameof(git)); _environment = environmentVariables; _git = git; }
public Settings(IEnvironment environment, IGit git) { EnsureArgument.NotNull(environment, nameof(environment)); EnsureArgument.NotNull(git, nameof(git)); _environment = environment; _git = git; }
public Settings(IEnvironment environment, IGit git, string repositoryPath = null) { EnsureArgument.NotNull(environment, nameof(environment)); EnsureArgument.NotNull(git, nameof(git)); _environment = environment; _git = git; RepositoryPath = repositoryPath; }
public PlaintextCredentialStore(IFileSystem fileSystem, string storeRoot, string @namespace = null) { EnsureArgument.NotNull(fileSystem, nameof(fileSystem)); EnsureArgument.NotNullOrWhiteSpace(storeRoot, nameof(storeRoot)); FileSystem = fileSystem; StoreRoot = storeRoot; Namespace = @namespace; }
internal GitProcessConfiguration(ITrace trace, GitProcess git, GitConfigurationLevel filterLevel = GitConfigurationLevel.All) { EnsureArgument.NotNull(trace, nameof(trace)); EnsureArgument.NotNull(git, nameof(git)); _trace = trace; _git = git; _filterLevel = filterLevel; }
public GitProcess(ITrace trace, string gitPath, string workingDirectory = null) { EnsureArgument.NotNull(trace, nameof(trace)); EnsureArgument.NotNullOrWhiteSpace(gitPath, nameof(gitPath)); _trace = trace; _gitPath = gitPath; _workingDirectory = workingDirectory; }
public HttpClientFactory(ITrace trace, ISettings settings, IStandardStreams streams) { EnsureArgument.NotNull(trace, nameof(trace)); EnsureArgument.NotNull(settings, nameof(settings)); EnsureArgument.NotNull(streams, nameof(streams)); _trace = trace; _settings = settings; _streams = streams; }
public GenericHostProvider(ICommandContext context, IBasicAuthentication basicAuth, IWindowsIntegratedAuthentication winAuth) : base(context) { EnsureArgument.NotNull(basicAuth, nameof(basicAuth)); EnsureArgument.NotNull(winAuth, nameof(winAuth)); _basicAuth = basicAuth; _winAuth = winAuth; }
internal Application(ICommandContext context, IHostProviderRegistry providerRegistry, IConfigurationService configurationService) : base(context) { EnsureArgument.NotNull(providerRegistry, nameof(providerRegistry)); EnsureArgument.NotNull(configurationService, nameof(configurationService)); _providerRegistry = providerRegistry; _configurationService = configurationService; _configurationService.AddComponent(this); }
/// <summary> /// Truncate the string from the last index of the given character, also removing the indexed character. /// </summary> /// <param name="str">String to truncate.</param> /// <param name="c">Character to locate the index of.</param> /// <returns>Truncated string.</returns> public static string TruncateFromLastIndexOf(this string str, char c) { EnsureArgument.NotNull(str, nameof(str)); int last = str.LastIndexOf(c); if (last > -1) { return(str.Substring(0, last)); } return(str); }
/// <summary> /// Trim all characters at the start of the string until the first index of the given string, /// also removing the indexed character. /// </summary> /// <param name="str">String to trim.</param> /// <param name="value">String to locate the index of.</param> /// <param name="comparisonType">Comparison rule for locating the string.</param> /// <returns>Trimmed string.</returns> public static string TrimUntilIndexOf(this string str, string value, StringComparison comparisonType = StringComparison.Ordinal) { EnsureArgument.NotNull(str, nameof(str)); int first = str.IndexOf(value, comparisonType); if (first > -1) { return(str.Substring(first + value.Length, str.Length - first - value.Length)); } return(str); }
/// <summary> /// Trim all characters at the start of the string until the first index of the given character, /// also removing the indexed character. /// </summary> /// <param name="str">String to trim.</param> /// <param name="c">Character to locate the index of.</param> /// <returns>Trimmed string.</returns> public static string TrimUntilIndexOf(this string str, char c) { EnsureArgument.NotNull(str, nameof(str)); int first = str.IndexOf(c); if (first > -1) { return(str.Substring(first + 1, str.Length - first - 1)); } return(str); }
private static string FormatText(string message, string filePath, int lineNumber, string memberName) { const int sourceColumnMaxWidth = 23; EnsureArgument.NotNull(message, nameof(message)); EnsureArgument.NotNull(filePath, nameof(filePath)); EnsureArgument.PositiveOrZero(lineNumber, nameof(lineNumber)); EnsureArgument.NotNull(memberName, nameof(memberName)); // Source column format is file:line string source = $"{filePath}:{lineNumber}"; if (source.Length > sourceColumnMaxWidth) { int idx = 0; int maxlen = sourceColumnMaxWidth - 3; int srclen = source.Length; while (idx >= 0 && (srclen - idx) > maxlen) { idx = source.IndexOf('\\', idx + 1); } // If we cannot find a path separator which allows the path to be long enough, just truncate the file name if (idx < 0) { idx = srclen - maxlen; } source = "..." + source.Substring(idx); } // Git's trace format is "{timestamp,-15} {source,-23} trace: {details}" string text = $"{DateTime.Now:HH:mm:ss.ffffff} {source,-23} trace: [{memberName}] {message}"; return(text); }
protected EnvironmentBase(IFileSystem fileSystem) { EnsureArgument.NotNull(fileSystem, nameof(fileSystem)); FileSystem = fileSystem; }
protected ApplicationBase(ICommandContext context) { EnsureArgument.NotNull(context, nameof(context)); Context = context; }
public CredentialStore(ICommandContext context) { EnsureArgument.NotNull(context, nameof(context)); _context = context; }
public ConfigurationService(ICommandContext context) { EnsureArgument.NotNull(context, nameof(context)); _context = context; }