mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-07-06 22:50:30 -04:00
Removed NioTSO client and server
- NioTSO client isn't needed because we're using RayLib - Added FreeSO's API server to handle most backend operations
This commit is contained in:
parent
f12ba1502b
commit
22191ce648
591 changed files with 53264 additions and 3362 deletions
78
server/FSO.Server.Api.Core/Utils/ApiResponse.cs
Executable file
78
server/FSO.Server.Api.Core/Utils/ApiResponse.cs
Executable file
|
@ -0,0 +1,78 @@
|
|||
using FSO.Common.Utils;
|
||||
using FSO.Server.Database.DA.Utils;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Xml;
|
||||
|
||||
namespace FSO.Server.Api.Core.Utils
|
||||
{
|
||||
public class ApiResponse
|
||||
{
|
||||
public static IActionResult Plain(HttpStatusCode code, string text)
|
||||
{
|
||||
return new ContentResult
|
||||
{
|
||||
StatusCode = (int)code,
|
||||
Content = text,
|
||||
ContentType = "text/plain"
|
||||
};
|
||||
}
|
||||
|
||||
public static IActionResult Json(HttpStatusCode code, object obj)
|
||||
{
|
||||
return new ContentResult
|
||||
{
|
||||
StatusCode = (int)code,
|
||||
Content = Newtonsoft.Json.JsonConvert.SerializeObject(obj),
|
||||
ContentType = "application/json"
|
||||
};
|
||||
}
|
||||
|
||||
public static IActionResult PagedList<T>(HttpRequest request, HttpStatusCode code, PagedList<T> list)
|
||||
{
|
||||
request.HttpContext.Response.Headers.Add("X-Total-Count", list.Total.ToString());
|
||||
request.HttpContext.Response.Headers.Add("X-Offset", list.Offset.ToString());
|
||||
|
||||
return new ContentResult
|
||||
{
|
||||
StatusCode = (int)code,
|
||||
Content = Newtonsoft.Json.JsonConvert.SerializeObject(list),
|
||||
ContentType = "application/json"
|
||||
};
|
||||
}
|
||||
|
||||
public static IActionResult Xml(HttpStatusCode code, IXMLEntity xml)
|
||||
{
|
||||
var doc = new XmlDocument();
|
||||
var firstChild = xml.Serialize(doc);
|
||||
doc.AppendChild(firstChild);
|
||||
|
||||
return new ContentResult
|
||||
{
|
||||
StatusCode = (int)code,
|
||||
Content = doc.OuterXml,
|
||||
ContentType = "text/xml"
|
||||
};
|
||||
}
|
||||
|
||||
public static Func<IActionResult> XmlFuture(HttpStatusCode code, IXMLEntity xml)
|
||||
{
|
||||
var doc = new XmlDocument();
|
||||
var firstChild = xml.Serialize(doc);
|
||||
doc.AppendChild(firstChild);
|
||||
var serialized = doc.OuterXml;
|
||||
|
||||
return () =>
|
||||
{
|
||||
return new ContentResult
|
||||
{
|
||||
StatusCode = (int)code,
|
||||
Content = serialized,
|
||||
ContentType = "text/xml"
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue