/
QuoterController.cs
86 lines (78 loc) · 2.81 KB
/
QuoterController.cs
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
namespace QuoterService.Controllers
{
[Route("api/[controller]")]
public class QuoterController : Controller
{
[HttpGet]
public string Get(
string sourceText,
NodeKind nodeKind = NodeKind.CompilationUnit,
bool openCurlyOnNewLine = false,
bool closeCurlyOnNewLine = false,
bool preserveOriginalWhitespace = false,
bool keepRedundantApiCalls = false,
bool avoidUsingStatic = false)
{
string responseText = "Quoter is currently down for maintenance. Please check back later.";
if (string.IsNullOrEmpty(sourceText))
{
responseText = "Please specify the source text.";
}
else if (sourceText.Length > 2000)
{
responseText = "Only strings shorter than 2000 characters are supported; your input string is " + sourceText.Length + " characters long.";
}
else
{
try
{
var quoter = new Quoter
{
OpenParenthesisOnNewLine = openCurlyOnNewLine,
ClosingParenthesisOnNewLine = closeCurlyOnNewLine,
UseDefaultFormatting = !preserveOriginalWhitespace,
RemoveRedundantModifyingCalls = !keepRedundantApiCalls,
ShortenCodeWithUsingStatic = !avoidUsingStatic
};
responseText = quoter.Quote(sourceText, nodeKind);
}
catch (Exception ex)
{
responseText = ex.ToString();
}
}
Response.Headers.Add("Cache-Control", new[] { "no-cache" });
Response.Headers.Add("Pragma", new[] { "no-cache" });
Response.Headers.Add("Expires", new[] { "-1" });
Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
Response.Headers.Add("Access-Control-Allow-Headers", new[] { "Content-Type" });
return responseText;
}
// GET api/values/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
// POST api/values
[HttpPost]
public void Post([FromBody]string value)
{
}
// PUT api/values/5
[HttpPut("{id}")]
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/values/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}