private static IGitProvider GetProvider(ProviderType providerType) { var loaderConfigurationSection = (ConfigurationManager.GetSection("LoaderConfiguration") as LoaderConfigurationSection); if (loaderConfigurationSection == null) { throw new ApplicationException("LoaderConfiguration section is missing"); } var providerConfig = loaderConfigurationSection.Providers.Where(w => w.Type == providerType).FirstOrDefault(); if (providerConfig == null) { throw new ApplicationException(string.Format("{0} provider configuration is missing", providerType)); } IGitProvider provider; if (providerType == ProviderType.Github) { var githubService = new GithubService(providerConfig); provider = new GithubProvider(githubService); } else { var bitbucketService = new BitbucketService(providerConfig); provider = new BitbucketProvider(bitbucketService); } return(provider); }
public void Github(GithubArgs args) { try { var userInfo = new UserInfo(args.Username, args.Email, args.AccessToken); var sourceControl = new GitSourceControlAsync(Logger, userInfo); var sourceControlProvider = new GithubProvider(Logger, sourceControl, args.Username, args.AccessToken); using (var stopwatch = new StopwatchHelper()) { var repos = new List <RepositoryInfo>(); using (var stopwatch2 = new StopwatchHelper()) { repos.AddRange(sourceControlProvider.FetchRepositories(args.RepositoryMatchers) .ConfigureAwait(false) .GetAwaiter() .GetResult()); Logger.Information("Fetching repositories took {TotalMs}ms ({Min}:{Sec} mm:ss)", stopwatch2.Result.TotalMilliseconds, stopwatch2.Result.Minutes, stopwatch2.Result.Seconds); } sourceControlProvider.EnsureRepositoriesSync(repos, args.RepositoryPathTemplate, args.BranchMatchers) .ConfigureAwait(false) .GetAwaiter() .GetResult(); Logger.Information("Done! Process took {TotalMs}ms ({Min}:{Sec} mm:ss)", stopwatch.Result.TotalMilliseconds, stopwatch.Result.Minutes, stopwatch.Result.Seconds); } } catch (Exception ex) { Logger.Error(ex, "There was an unhandled exception!"); Console.ReadLine(); } }