initial commit
[CPE_learningsite] / CPE / CPE.App / CPE.App.Api / WebHooks / GitHubWebHookHandler.cs
1 
2
3
4
5 using Microsoft.AspNet.WebHooks;
6 using Newtonsoft.Json.Linq;
7 using System;
8 using System.Diagnostics;
9 using System.IO;
10 using System.Linq;
11 using System.Threading.Tasks;
12
13 namespace CPE.App.Api.WebHooks
14 {
15     public class GitHubWebHookHandler : WebHookHandler
16     {
17         public GitHubWebHookHandler()
18         {
19             this.Receiver = "github";
20         }
21
22         public override Task ExecuteAsync(string receiver, WebHookHandlerContext context)
23         {
24             string action = context.Actions.First();
25             JObject data = context.GetDataOrDefault<JObject>();
26
27             Debug.WriteLine("Made it to reciever");
28             TextWriter writer = null;
29             try
30             {
31                 var contentsToWriteToFile = data;
32                 writer = new StreamWriter("C:/bitbucket/githubWebhookdata.txt", false);
33                 writer.Write(contentsToWriteToFile);
34             }
35             finally
36             {
37                 if (writer != null)
38                     writer.Close();
39             }
40             
41             return Task.FromResult(true);
42         }
43     }
44 }