Created
October 9, 2017 21:41
-
-
Save lukehoban/b2cd40aa683cddd7ffcb434ca08b9385 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Runtime.Serialization; | |
using System.ServiceModel; | |
using System.Text; | |
using System.ServiceModel.Activation; | |
using System.Net; | |
using System.IO; | |
using System.Web; | |
namespace JavascriptWebClient.Web | |
{ | |
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "ClosureCompile" in code, svc and config file together. | |
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] | |
[ServiceBehavior(IncludeExceptionDetailInFaults=true)] | |
public class ClosureCompile : IClosureCompile | |
{ | |
public string DoWork(string srcText) | |
{ | |
System.Diagnostics.Debug.WriteLine("Hello!"); | |
var request = WebRequest.Create("http://closure-compiler.appspot.com/compile"); | |
request.Method = "POST"; | |
request.ContentType = "application/x-www-form-urlencoded"; | |
var stream = request.GetRequestStream(); | |
// Send the post variables | |
StreamWriter writer = new StreamWriter(stream); | |
writer.Write("output_format=xml"); | |
writer.Write("&output_info=compiled_code"); | |
writer.Write("&output_info=warnings"); | |
writer.Write("&output_info=errors"); | |
writer.Write("&output_info=statistics"); | |
writer.Write("&compilation_level=ADVANCED_OPTIMIZATIONS"); | |
writer.Write("&warning_level=verbose"); | |
writer.Write("&js_code=" + HttpUtility.UrlEncode(srcText)); | |
writer.Flush(); | |
writer.Close(); | |
var response = request.GetResponse(); | |
Stream responseStream = response.GetResponseStream(); | |
StreamReader reader = new StreamReader(responseStream); | |
// get the result text | |
string result = reader.ReadToEnd(); | |
return result; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment