protected async Task <List <CrawlJob> > CreateJobsFromGitHubFolders(string gitHubOwner, string gitHubRepo, string token, string[] ignoreList, string templateNamePattern)
        {
            List <CrawlJob> jobs      = new List <CrawlJob>();
            var             gitHub    = new GitHubClient(new ProductHeaderValue("archi-bot"));
            var             tokenAuth = new Credentials(token);

            gitHub.Credentials = tokenAuth;
            var contents = await gitHub.Repository.Content.GetAllContents(gitHubOwner, gitHubRepo);

            var folders = from f in contents
                          where f.Type == ContentType.Dir &&
                          (ignoreList == null || Array.IndexOf(ignoreList, f.Path) < 0)
                          select f;

            foreach (var folder in folders)
            {
                var folderContents = gitHub.Repository.Content.GetAllContents(gitHubOwner, gitHubRepo, folder.Path).Result;
                var templateFile   = (from f in folderContents
                                      where f.Name == templateNamePattern
                                      select f).FirstOrDefault();
                if (templateFile != null)
                {
                    var job = new CrawlJob(templateFile.Path, templateFile.DownloadUrl);
                    Trace.TraceInformation("Job created - Name:{0}, Download Uri:{1}", job.Name, job.DownloadUrl);
                    jobs.Add(job);
#if DEBUG
                    break;
#endif
                }
            }
            return(jobs);
        }
Example #2
0
        public override async Task <List <AppGraph> > Handle(CrawlJob job)
        {
            HttpClient          client     = new HttpClient();
            var                 jsonString = string.Empty;
            HttpResponseMessage response   = client.GetAsync(job.DownloadUrl).Result;

            jsonString = await response.Content.ReadAsStringAsync();

            var template = JsonConvert.DeserializeObject <AzureARMObjectModels.Template>(jsonString);

            List <AppGraph> ret = new List <AppGraph>();

            foreach (var resource in template.Resources)
            {
                AppGraph graph = new AppGraph
                {
                };
                ret.Add(graph);
            }

            return(ret);
        }
 public abstract Task <List <AppGraph> > Handle(CrawlJob job);