Send Data
This commit is contained in:
33
ApiServer/ApiStruct/Data.cs
Normal file
33
ApiServer/ApiStruct/Data.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DataClient.Struct;
|
||||
|
||||
namespace ApiServer.ApiStruct
|
||||
{
|
||||
public class DataCheckApi
|
||||
{
|
||||
public bool Status { get; set; }
|
||||
public DateTime DateAndTime { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
public class DataCheckClient
|
||||
{
|
||||
public bool Status { get; set; }
|
||||
public bool Exist { get; set; }
|
||||
public ulong DataSize { get; set; }
|
||||
}
|
||||
public class DataCreateApi
|
||||
{
|
||||
public bool Status { get; set; }
|
||||
public DateTime DateAndTime { get; set; }
|
||||
public string Name { get; set; }
|
||||
public byte[] Struct { get; set; }
|
||||
}
|
||||
public class DataCreateClient
|
||||
{
|
||||
public bool Status { get; set; }
|
||||
}
|
||||
|
||||
}
|
86
ApiServer/Controllers/DataController.cs
Normal file
86
ApiServer/Controllers/DataController.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ApiServer.ApiStruct;
|
||||
using Newtonsoft.Json;
|
||||
using System.IO;
|
||||
|
||||
namespace ApiServer.Controllers
|
||||
{
|
||||
[ApiController, Route("[controller]")]
|
||||
public class DataController : ControllerBase
|
||||
{
|
||||
private Logger log = LogManager.GetCurrentClassLogger();
|
||||
[HttpPost, Route("check")]
|
||||
public DataCheckClient Check([FromBody] object value)
|
||||
{
|
||||
try
|
||||
{
|
||||
var getResult = JsonConvert.DeserializeObject<DataCheckApi>(value.ToString());
|
||||
if (!getResult.Status || string.IsNullOrEmpty(getResult.Name))
|
||||
{
|
||||
log.Warn("Wrong answer.");
|
||||
return new DataCheckClient();
|
||||
}
|
||||
var dataDir = Path.Combine(
|
||||
Directory.GetCurrentDirectory(),
|
||||
"data", "data",
|
||||
getResult.DateAndTime.Year.ToString("D4"),
|
||||
getResult.DateAndTime.Month.ToString("D2"),
|
||||
getResult.DateAndTime.Day.ToString("D2"),
|
||||
getResult.Name);
|
||||
log.Info("Search data: " + dataDir);
|
||||
if (!System.IO.File.Exists(dataDir))
|
||||
{
|
||||
log.Info("Data not exist: " + dataDir);
|
||||
return new DataCheckClient { Status = true, Exist = false, DataSize = 0 };
|
||||
}
|
||||
var dataArr = System.IO.File.ReadAllBytes(dataDir);
|
||||
log.Info("Send data size: " + dataArr.Length + " | " + dataDir);
|
||||
return new DataCheckClient { Status = true, Exist = true, DataSize = (ulong)dataArr.Length };
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.Warn(e);
|
||||
return new DataCheckClient();
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost, Route("create")]
|
||||
public DataCreateClient Create([FromBody] object value)
|
||||
{
|
||||
try
|
||||
{
|
||||
var getResult = JsonConvert.DeserializeObject<DataCreateApi>(value.ToString());
|
||||
if (!getResult.Status ||
|
||||
string.IsNullOrEmpty(getResult.Name) ||
|
||||
getResult.Struct.Length == 0)
|
||||
{
|
||||
log.Warn("Wrong answer.");
|
||||
return new DataCreateClient();
|
||||
}
|
||||
var dataDir = Path.Combine(
|
||||
Directory.GetCurrentDirectory(),
|
||||
"data", "data",
|
||||
getResult.DateAndTime.Year.ToString("D4"),
|
||||
getResult.DateAndTime.Month.ToString("D2"),
|
||||
getResult.DateAndTime.Day.ToString("D2"));
|
||||
if (!Directory.Exists(dataDir))
|
||||
Directory.CreateDirectory(dataDir);
|
||||
dataDir = Path.Combine(dataDir, getResult.Name);
|
||||
System.IO.File.WriteAllBytes(dataDir, getResult.Struct);
|
||||
log.Info("Save data: " + dataDir);
|
||||
return new DataCreateClient { Status = true };
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.Warn(e);
|
||||
return new DataCreateClient();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||
-->
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<History>True|2021-08-01T14:33:24.0605718Z;True|2021-08-01T19:29:09.0622642+05:00;True|2021-08-01T16:14:00.2837619+05:00;True|2021-07-31T17:43:14.2797709+05:00;False|2021-07-31T17:41:49.3152422+05:00;True|2021-07-31T14:07:45.4057263+05:00;False|2021-07-31T13:53:38.4952669+05:00;</History>
|
||||
<History>True|2021-08-02T16:42:10.4757931Z;True|2021-08-01T19:33:24.0605718+05:00;True|2021-08-01T19:29:09.0622642+05:00;True|2021-08-01T16:14:00.2837619+05:00;True|2021-07-31T17:43:14.2797709+05:00;False|2021-07-31T17:41:49.3152422+05:00;True|2021-07-31T14:07:45.4057263+05:00;False|2021-07-31T13:53:38.4952669+05:00;</History>
|
||||
<_PublishTargetUrl>F:\GIT\ASCKU_PC\ApiServer\bin\Release\</_PublishTargetUrl>
|
||||
</PropertyGroup>
|
||||
</Project>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
|
||||
d29ca1fc6ac51c211fa6b3f4cdcf6f83a5b03d11
|
||||
0ba5eb43d3c8baaf93d0a30f42372f5107b7f4d6
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user