Пример #1
0
        public async Task LoadFromGithub(GitHubConfig config, ILoggerFactory loggerFactory)
        {
            ThrowIf.Null(config, nameof(config));
            ThrowIf.Null(loggerFactory, nameof(loggerFactory));

            var logger = loggerFactory.CreateLogger(nameof(PlaybookData));

            await _eventTypes.AddSeedDataFromGitHub(
                logger,
                config,
                nameof(EventType)
                ).ConfigureAwait(continueOnCapturedContext: false);

            await _globalActions.AddSeedDataFromGitHub(
                logger,
                config,
                "Global" + nameof(Domain.Playbook.Action)
                ).ConfigureAwait(continueOnCapturedContext: false);
        }
Пример #2
0
        public static async Task AddSeedDataFromGitHub <T>(
            this Dictionary <long, T> index,
            ILogger logger,
            GitHubConfig config,
            string searchTerm
            )
            where T : class, IEntity
        {
            var request = new SearchCodeRequest(searchTerm, config.RepositoryOwner, config.RepositoryName)
            {
                In        = new[] { CodeInQualifier.Path },
                Extension = "json"
            };

            var result = await config.Client.Search
                         .SearchCode(request)
                         .ConfigureAwait(continueOnCapturedContext: false);

            var recordsToAddTasks = result
                                    .Items
                                    .Select(ExtractContents(config.Client, config.Repository))
                                    .ToArray();

            Task.WaitAll(
                recordsToAddTasks
                .Select(taskTuple => taskTuple.contentsTask)
                .ToArray()
                );
            var recordsToAdd = recordsToAddTasks
                               .Where(taskTuple => taskTuple.contentsTask.IsCompletedSuccessfully)
                               .Select(taskTuple => (
                                           contents: taskTuple.contentsTask.Result,
                                           filePath: taskTuple.filePath)
                                       );

            LogFileRetrievalFailures(logger, recordsToAddTasks);

            var content = recordsToAdd
                          .SelectMany(DeserializeContents <T>(logger))
                          .Where(et => !(et is null));

            index.AddSeedDataToDictionary(content);
        }