137 lines
4.1 KiB
C#
137 lines
4.1 KiB
C#
using System.Text;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Http.HttpResults;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Scripting.Utils;
|
|
using IotManager.Common;
|
|
using ViewModels;
|
|
using CommonEntity;
|
|
|
|
namespace SupplierManager.Controllers
|
|
{
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class ConfigPYController : ControllerBase
|
|
{
|
|
[HttpPost()]
|
|
[Authorize()]
|
|
public async Task<ReturnInfo> GetConfigString()
|
|
{
|
|
ReturnInfo r = new ReturnInfo();
|
|
try
|
|
{
|
|
string[] str = await System.IO.File.ReadAllLinesAsync("script\\webapi.py");
|
|
|
|
List<VK> ll = new List<VK>();
|
|
foreach (var item in str)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(item))
|
|
{
|
|
string[] a = item.Split('=');
|
|
VK v = new VK();
|
|
v.VarName = a[0];
|
|
v.VarValue = a[1];
|
|
ll.Add(v);
|
|
}
|
|
}
|
|
|
|
r.isok = true;
|
|
r.response = ll;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
r.isok = false;
|
|
r.message = ex.Message;
|
|
}
|
|
return r;
|
|
}
|
|
|
|
[HttpPost()]
|
|
[Authorize()]
|
|
public ReturnInfo RefreshConfig()
|
|
{
|
|
ReturnInfo info = new ReturnInfo();
|
|
info.isok = true;
|
|
try
|
|
{
|
|
StaticData.GetWebAPIMethod();
|
|
StaticData.GetWebAPIMethod1();
|
|
info.message = "Sucess";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
info.isok = false;
|
|
info.message = ex.Message;
|
|
}
|
|
return info;
|
|
}
|
|
|
|
public class VK
|
|
{
|
|
public string VarName { get; set; }
|
|
public string VarValue { get; set; }
|
|
}
|
|
[HttpPost()]
|
|
[Authorize()]
|
|
public async Task<ReturnInfo> SaveOrAddConfigString([FromBody] VK data)
|
|
{
|
|
ReturnInfo info = new ReturnInfo();
|
|
info.isok = true;
|
|
try
|
|
{
|
|
var sss = System.IO.File.ReadAllLines("script\\webapi.py", Encoding.UTF8).ToList<string>();
|
|
for (int i = 0; i < sss.Count; i++)
|
|
{
|
|
string item = sss[i];
|
|
string[] txtdata = item.Split('=');
|
|
if (txtdata[0].Equals(data.VarName))
|
|
{
|
|
txtdata[1] = data.VarValue;
|
|
sss[i] = txtdata[0] + "=" + txtdata[1];
|
|
}
|
|
}
|
|
bool exists = sss.Any(A => A.StartsWith(data.VarName));
|
|
|
|
if (exists == false)
|
|
{
|
|
sss.AddRange<string>(new string[] { data.VarName + "=" + data.VarValue });
|
|
}
|
|
|
|
await System.IO.File.WriteAllLinesAsync("script\\webapi.py", sss, Encoding.UTF8);
|
|
StaticData.GetWebAPIMethod();
|
|
info.message = "Sucess";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
info.isok = false;
|
|
info.message = ex.Message;
|
|
}
|
|
return info;
|
|
}
|
|
[HttpPost()]
|
|
[Authorize()]
|
|
public ReturnInfo GetSingleValue([FromBody] Dictionary<string, string> dic)
|
|
{
|
|
ReturnInfo info = new ReturnInfo();
|
|
info.isok = true;
|
|
try
|
|
{
|
|
string VarValue = dic["VarName"];
|
|
if (!string.IsNullOrEmpty(VarValue))
|
|
{
|
|
var QQQ = StaticData.scope1.GetVariable(VarValue);
|
|
string str = System.Text.Json.JsonSerializer.Serialize(QQQ);
|
|
info.response = str;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
info.isok = false;
|
|
info.message = ex.Message;
|
|
}
|
|
return info;
|
|
}
|
|
}
|
|
}
|