-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBiocondaRetriever.cs
More file actions
70 lines (63 loc) · 2.73 KB
/
BiocondaRetriever.cs
File metadata and controls
70 lines (63 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Net.Http;
using Newtonsoft.Json.Linq;
using System.Linq;
namespace UnsupportedPackageWriter
{
class BiocondaRetriever
{
public List<string> GenerateListAsync()
{
List<string> packageList = new List<string>();
using (HttpClient hc = new HttpClient())
{
try
{
hc.DefaultRequestHeaders.UserAgent.ParseAdd("Everything");
JArray commits = null;
var json = hc.GetAsync("https://api.github.com/repos/bioconda/bioconda-recipes/commits").ContinueWith((taskwithresponse) =>
{
var response = taskwithresponse.Result;
var jsonTask = response.Content.ReadAsStringAsync();
jsonTask.Wait();
commits = JArray.Parse(jsonTask.Result);
});
json.Wait();
String newestCommitSHA = commits[0]["sha"].ToString();
JArray repoData = null;
json = hc.GetAsync("https://api.github.com/repos/bioconda/bioconda-recipes/git/trees/" + newestCommitSHA).ContinueWith((taskwithresponse) =>
{
var response = taskwithresponse.Result;
var jsonTask = response.Content.ReadAsStringAsync();
jsonTask.Wait();
repoData = (JArray)JObject.Parse(jsonTask.Result)["tree"];
});
json.Wait();
JObject recipeJObject = repoData.Children<JObject>().FirstOrDefault(o => o["path"] != null && o["path"].ToString().Equals("recipes"));
String recipeURL = recipeJObject["url"].ToString();
JArray packages = null;
json = hc.GetAsync(recipeURL).ContinueWith((taskwithresponse) =>
{
var response = taskwithresponse.Result;
var jsonTask = response.Content.ReadAsStringAsync();
jsonTask.Wait();
packages = JArray.Parse(JObject.Parse(jsonTask.Result)["tree"].ToString());
});
json.Wait();
foreach (var package in packages.Children())
{
packageList.Add(package["path"].ToString());
}
}
catch (Exception e)
{
Console.Out.WriteLine("Exception: " + e);
}
}
return packageList;
}
}
}