Created
October 13, 2017 09:06
-
-
Save anonymous/4b2b29ef01cec29da2023eb0843a3544 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json; | |
using Newtonsoft.Json.Linq; | |
using System; | |
using System.Diagnostics; | |
using System.Net.Http; | |
using System.Runtime.CompilerServices; | |
using System.Threading.Tasks; | |
namespace Demo | |
{ | |
internal class Program | |
{ | |
[CompilerGenerated] | |
[Serializable] | |
private sealed class <>c | |
{ | |
private sealed class <<Function>b__1_3>d : IAsyncStateMachine | |
{ | |
public int <>1__state; | |
public AsyncTaskMethodBuilder<string> <>t__builder; | |
[System.Runtime.CompilerServices.TupleElementNames(new string[] | |
{ | |
"http", | |
"url" | |
})] | |
public System.ValueTuple<HttpClient, string> httpinfo; | |
public Program.<>c <>4__this; | |
private string <>s__1; | |
private TaskAwaiter<string> <>u__1; | |
void IAsyncStateMachine.MoveNext() | |
{ | |
int num = this.<>1__state; | |
string result2; | |
try | |
{ | |
if (num != 0) | |
{ | |
} | |
try | |
{ | |
TaskAwaiter<string> taskAwaiter; | |
if (num != 0) | |
{ | |
taskAwaiter = this.httpinfo.Item1.GetStringAsync(this.httpinfo.Item2).GetAwaiter(); | |
if (!taskAwaiter.IsCompleted) | |
{ | |
this.<>1__state = 0; | |
this.<>u__1 = taskAwaiter; | |
Program.<>c.<<Function>b__1_3>d <<Function>b__1_3>d = this; | |
this.<>t__builder.AwaitUnsafeOnCompleted<TaskAwaiter<string>, Program.<>c.<<Function>b__1_3>d>(ref taskAwaiter, ref <<Function>b__1_3>d); | |
return; | |
} | |
} | |
else | |
{ | |
taskAwaiter = this.<>u__1; | |
this.<>u__1 = default(TaskAwaiter<string>); | |
this.<>1__state = -1; | |
} | |
string result = taskAwaiter.GetResult(); | |
taskAwaiter = default(TaskAwaiter<string>); | |
this.<>s__1 = result; | |
result2 = this.<>s__1; | |
} | |
catch | |
{ | |
result2 = null; | |
} | |
} | |
catch (Exception exception) | |
{ | |
this.<>1__state = -2; | |
this.<>t__builder.SetException(exception); | |
return; | |
} | |
this.<>1__state = -2; | |
this.<>t__builder.SetResult(result2); | |
} | |
[DebuggerHidden] | |
void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine) | |
{ | |
} | |
} | |
public static readonly Program.<>c <>9 = new Program.<>c(); | |
public static Func<int, int> <>9__1_1; | |
[System.Runtime.CompilerServices.TupleElementNames(new string[] | |
{ | |
"http", | |
"url" | |
})] | |
public static Func<int, System.ValueTuple<HttpClient, string>> <>9__1_2; | |
[System.Runtime.CompilerServices.TupleElementNames(new string[] | |
{ | |
"http", | |
"url" | |
})] | |
public static Func<System.ValueTuple<HttpClient, string>, Task<string>> <>9__1_3; | |
public static Func<string, bool> <>9__1_4; | |
public static Func<string, JObject> <>9__1_5; | |
[System.Runtime.CompilerServices.TupleElementNames(new string[] | |
{ | |
"title", | |
"num" | |
})] | |
public static Func<JObject, System.ValueTuple<string, int?>> <>9__1_6; | |
[System.Runtime.CompilerServices.TupleElementNames(new string[] | |
{ | |
"title", | |
"num" | |
})] | |
public static Action<System.ValueTuple<string, int?>> <>9__1_7; | |
internal int <Function>b__1_1(int num) | |
{ | |
return num; | |
} | |
[return: System.Runtime.CompilerServices.TupleElementNames(new string[] | |
{ | |
"http", | |
"url" | |
})] | |
internal System.ValueTuple<HttpClient, string> <Function>b__1_2(int num) | |
{ | |
return new System.ValueTuple<HttpClient, string>(new HttpClient | |
{ | |
DefaultRequestHeaders = | |
{ | |
{ | |
"User-Agent", | |
"Demo" | |
} | |
} | |
}, string.Format("https://api.github.com/repos/Microsoft/TypeScript/issues/{0}", num)); | |
} | |
[DebuggerStepThrough, AsyncStateMachine(typeof(Program.<>c.<<Function>b__1_3>d))] | |
internal Task<string> <Function>b__1_3([System.Runtime.CompilerServices.TupleElementNames(new string[] | |
{ | |
"http", | |
"url" | |
})] System.ValueTuple<HttpClient, string> httpinfo) | |
{ | |
Program.<>c.<<Function>b__1_3>d <<Function>b__1_3>d = new Program.<>c.<<Function>b__1_3>d(); | |
<<Function>b__1_3>d.<>4__this = this; | |
<<Function>b__1_3>d.httpinfo = httpinfo; | |
<<Function>b__1_3>d.<>t__builder = AsyncTaskMethodBuilder<string>.Create(); | |
<<Function>b__1_3>d.<>1__state = -1; | |
AsyncTaskMethodBuilder<string> <>t__builder = <<Function>b__1_3>d.<>t__builder; | |
<>t__builder.Start<Program.<>c.<<Function>b__1_3>d>(ref <<Function>b__1_3>d); | |
return <<Function>b__1_3>d.<>t__builder.Task; | |
} | |
internal bool <Function>b__1_4(string html) | |
{ | |
return !string.IsNullOrEmpty(html); | |
} | |
internal JObject <Function>b__1_5(string html) | |
{ | |
return JsonConvert.DeserializeObject(html) as JObject; | |
} | |
[return: System.Runtime.CompilerServices.TupleElementNames(new string[] | |
{ | |
"title", | |
"num" | |
})] | |
internal System.ValueTuple<string, int?> <Function>b__1_6(JObject jo) | |
{ | |
string arg_4F_0; | |
if (jo == null) | |
{ | |
arg_4F_0 = null; | |
} | |
else | |
{ | |
JToken expr_11 = jo["title"]; | |
arg_4F_0 = ((expr_11 != null) ? expr_11.Value<string>() : null); | |
} | |
int? arg_4F_1; | |
if (jo == null) | |
{ | |
arg_4F_1 = null; | |
} | |
else | |
{ | |
JToken expr_36 = jo["num"]; | |
arg_4F_1 = ((expr_36 != null) ? new int?(expr_36.Value<int>()) : null); | |
} | |
return new System.ValueTuple<string, int?>(arg_4F_0, arg_4F_1); | |
} | |
internal void <Function>b__1_7([System.Runtime.CompilerServices.TupleElementNames(new string[] | |
{ | |
"title", | |
"num" | |
})] System.ValueTuple<string, int?> issue) | |
{ | |
Console.WriteLine(string.Format("[{0}] : {1}", issue.Item2, issue.Item1)); | |
} | |
} | |
private static void Main(string[] args) | |
{ | |
Program.Function(); | |
Console.Read(); | |
} | |
[DebuggerStepThrough, AsyncStateMachine(typeof(Program.<Function>d__1))] | |
private static void Function() | |
{ | |
Program.<Function>d__1 <Function>d__ = new Program.<Function>d__1(); | |
<Function>d__.<>t__builder = AsyncVoidMethodBuilder.Create(); | |
<Function>d__.<>1__state = -1; | |
AsyncVoidMethodBuilder <>t__builder = <Function>d__.<>t__builder; | |
<>t__builder.Start<Program.<Function>d__1>(ref <Function>d__); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json; | |
using Newtonsoft.Json.Linq; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Net.Http; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Demo | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
GetRandomIssues(); | |
Console.Read(); | |
} | |
async static void GetRandomIssues() | |
{ | |
var random = new Random(Environment.TickCount); | |
(await Task.WhenAll( | |
Enumerable | |
.Range(0, 50) | |
.Select(r => random.Next(1, 1)) | |
.Distinct() | |
.OrderBy(num=>num) | |
.Select(num => | |
{ | |
var http = new HttpClient(); | |
http.DefaultRequestHeaders.Add("User-Agent", "Demo"); | |
return (http: http, url: $"https://api.github.com/repos/Microsoft/TypeScript/issues/{num}"); | |
}) | |
.Select(async httpinfo => | |
{ | |
try | |
{ | |
return await httpinfo.http.GetStringAsync(httpinfo.url); | |
} | |
catch { return null; } | |
}))) | |
.Where(html => !string.IsNullOrEmpty(html)) | |
.Select(html => JsonConvert.DeserializeObject(html) as JObject) | |
.Select(jo =>(title: jo?["title"]?.Value<string>(),num: jo?["num"]?.Value<int>())) | |
.ToList() | |
.ForEach(issue => Console.WriteLine($"[{issue.num}] : {issue.title}")); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment