Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Last active April 14, 2016 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guitarrapc/55c0ce117d5fbe2a3fe38168659a2250 to your computer and use it in GitHub Desktop.
Save guitarrapc/55c0ce117d5fbe2a3fe38168659a2250 to your computer and use it in GitHub Desktop.
#r "Newtonsoft.Json"
using System;
using System.Net;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Linq;
public static string ToJoinedString<T>(this IEnumerable<T> source, string separator = "")
{
return string.Join(separator, source);
}
public static IEnumerable<TSource> Concat<TSource>(this IEnumerable<TSource> source, params TSource[] values)
{
if (source == null) throw new ArgumentNullException("source");
return source.ConcatCore(values);
}
private static IEnumerable<TSource> ConcatCore<TSource>(this IEnumerable<TSource> source, params TSource[] values)
{
foreach (var item in source) yield return item;
foreach (var x in values) yield return x;
}
#r "Newtonsoft.Json"
using System;
using System.Net;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Linq;
using Octokit;
using Octokit.Internal;
public static string NugetTest()
{
var hoge = typeof(Octokit.GitHubClient).Assembly.FullName;
return hoge;
}
{
"frameworks": {
"net46":{
"dependencies": {
"Octokit": "0.19.0"
}
}
}
}
#r "Newtonsoft.Json"
#load "test.csx"
#load "..\EnumerableExtensions.csx"
#load "..\NugetSample.csx"
using System;
using System.Net;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Linq;
public static async Task<object> Run(HttpRequestMessage req, TraceWriter log)
{
log.Verbose($"Webhook was triggered!");
string jsonContent = await req.Content.ReadAsStringAsync();
dynamic data = JsonConvert.DeserializeObject(jsonContent);
if (data.first == null || data.last == null) {
return req.CreateResponse(HttpStatusCode.BadRequest, new {
error = "Please pass first/last properties in the input object"
});
}
// Load .csx from same directory
var hoge = Test();
log.Verbose(hoge);
// Load .csx from same directory + pass TraceWriter
Test2(log);
// Load .csx from parent directory
var concat = Enumerable.Range(1, 10).Select(x => x * x).ToArray().ToJoinedString(",");
log.Verbose(concat);
// Load NuGet .csx test
var fuga = NugetTest();
log.Verbose(fuga);
return req.CreateResponse(HttpStatusCode.OK, new {
greeting = $"Hello {data.first} {data.last}!"
});
}
#r "Newtonsoft.Json"
using System;
using System.Net;
using System.Threading.Tasks;
using Newtonsoft.Json;
public static string Test()
{
return "External function loaded!";
}
public static void Test2(TraceWriter log)
{
log.Verbose($"External function2 loaded!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment