You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.6 KiB

using Swashbuckle.Swagger;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
namespace ILMocup.Controllers
{
public class ILController : ApiController
{
[HttpPost]
[Route("API/Fast")]
public IHttpActionResult Fast()
{
string json = "";
if (HttpContext.Current.Request.InputStream.Length > 0)
{
using (var inputStream = new StreamReader(HttpContext.Current.Request.InputStream))
{
json = inputStream.ReadToEnd();
}
}
string filename = @"X:\jsontemp\ILMockup" + @"\fast_" + DateTime.Now.ToString("yyyymmdd_hhMMss") + ".json";
System.IO.File.WriteAllText(filename, json);
return Content(HttpStatusCode.OK, RandomString(6));
}
[HttpPost]
[Route("API/Slow")]
public IHttpActionResult Slow()
{
string json = "";
string rs = RandomString(6);
if (HttpContext.Current.Request.InputStream.Length > 0)
{
using (var inputStream = new StreamReader(HttpContext.Current.Request.InputStream))
{
json = inputStream.ReadToEnd();
}
}
string filename = @"X:\jsontemp\ILMockup" + @"\Slow_" + DateTime.Now.ToString("yyyyMMdd_hhmmss") + "_"+rs+".json";
System.IO.File.WriteAllText(filename, json);
return Content(HttpStatusCode.OK, rs);
}
public IHttpActionResult Revision()
{
string json = "";
string rs = RandomString(6);
if (HttpContext.Current.Request.InputStream.Length > 0)
{
using (var inputStream = new StreamReader(HttpContext.Current.Request.InputStream))
{
json = inputStream.ReadToEnd();
}
}
string filename = @"X:\jsontemp\ILMockup" + @"\Revision_" + DateTime.Now.ToString("yyyyMMdd_hhmmss") + "_" + rs + ".json";
System.IO.File.WriteAllText(filename, json);
return Content(HttpStatusCode.OK, rs);
}
private static Random random = new Random();
public static string RandomString(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
}
}