-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoreController.cs
42 lines (40 loc) · 1.58 KB
/
CoreController.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
namespace CarBoyWebservice.Controllers
{
public class CoreController : ApiController
{
[HttpPost]
public async Task<HttpResponseMessage> GetCore()
{
byte[] data = await Request.Content.ReadAsByteArrayAsync();
MBProtoLib.Core.UserAuth core = new MBProtoLib.Core.UserAuth(MBProto.Contractors.constructors,
System.Configuration.ConfigurationManager.ConnectionStrings["CarBoyDBConnectionString"].ConnectionString, "");
try
{
var response = core.Receive(data);
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new ByteArrayContent(response);
return result;
}
catch (MBProto.Exceptions.AuthException ext)
{
return Request.CreateResponse(ext.Serialize<HttpStatusCode>(), ext.Serialize<string>());
}
catch (MBProtoLib.Exceptions.AuthException ext)
{
return Request.CreateResponse(ext.Serialize<HttpStatusCode>(), ext.Serialize<string>());
}
catch
{
var ext = new MBProtoLib.Exceptions.AuthException(new MBProtoLib.Exceptions.AuthException.InternalServerError());
return Request.CreateResponse(ext.Serialize<HttpStatusCode>(), ext.Serialize<string>());
}
}
}
}