1.初始化项目。保险起见bin目录完整提交 2.基于现场代码为调整过的初始项目(此次提交还未解决代码差异问题)

This commit is contained in:
龚记林
2026-08-19 11:14:30 +08:00
parent b820c71956
commit 2b30644d28
382 changed files with 140652 additions and 1 deletions
@@ -0,0 +1,73 @@
using Nancy;
using System;
using System.Collections.Generic;
using Nancy.ModelBinding;
using Newtonsoft.Json;
namespace HxBusiness
{
public class APIContainer : NancyModule
{
public APIContainer()
{
var tasks = new Dictionary<int, string>();
//Get["api/get"] = GetStr;
Get("api/get", parameters => GetStr(parameters));
//更新任务
//Post("api/sendpermission") = UpdateTraffic;
Post("api/sendpermission", parameters => UpdateTraffic(parameters));
}
private object GetStr(dynamic o)
{
try
{
string str = Request.Query["id"];
return "test Api" + str;
}
catch (Exception ex)
{
return ex.ToString();
}
}
/// <summary>
/// 更新任务
/// </summary>
/// <param name="o"></param>
/// <returns></returns>
private object UpdateTraffic(dynamic o)
{
ResponseModel resultmodel = new ResponseModel();
try
{
string[] tagPoint = { "280", "282" };
SendModel parmmodel = this.Bind<SendModel>();
string str = JsonConvert.SerializeObject(parmmodel);
WriteTxt.SaveLog1("接收到授权请求!" + str, "api日志");
if (parmmodel.interchangePointCode.Equals(tagPoint[0]) || parmmodel.interchangePointCode.Equals(tagPoint[1]))
{
resultmodel.code = 0;
resultmodel.msg = "成功";
resultmodel.data = "";
}
else
{
resultmodel.code = -2;
resultmodel.msg = "交汇点地标不存在!";
}
}
catch (Exception ex)
{
resultmodel.code = -1;
resultmodel.data = "服务器错误:" + ex.ToString();
}
return JsonConvert.SerializeObject(resultmodel);
}
public object Root(dynamic o)
{
return null;
}
}
}
@@ -0,0 +1,129 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
namespace HxBusiness
{
public class ConfigBiz
{
private const int TryReadWriteCount = 10;
private int readcount = 0;
private int writecount = 0;
/// <summary>
/// 指定程序目录
/// </summary>
private string xmlPath;
//设置读写锁
private ReaderWriterLockSlim objlock;
public ConfigBiz()
{
xmlPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "/Config/";
objlock = new ReaderWriterLockSlim();
}
/// <summary>
/// 写json到文件
/// </summary>
/// <typeparam name="T">任意模型,根据模型匹配文件名</typeparam>
/// <param name="list">返回指定模型数据</param>
/// <returns></returns>
public bool WriteDb<T>(object parm)
{
objlock.EnterWriteLock();
try
{
string fileName = typeof(T).Name.ToString() + ".json";
//如果没有则创建文件夹
if (!Directory.Exists(xmlPath))
{
Directory.CreateDirectory(xmlPath);
}//如果没有则创建文件
if (!File.Exists(xmlPath + fileName))
{
FileStream fs1 = new FileStream(xmlPath + fileName, FileMode.Create, FileAccess.ReadWrite);
fs1.Close();
}
else
{
//保证每次文件的更新
FileInfo finfo = new FileInfo(xmlPath + fileName);
finfo.Delete();
FileStream fs1 = new FileStream(xmlPath + fileName, FileMode.Create, FileAccess.ReadWrite);
fs1.Close();
}
File.WriteAllText(xmlPath + fileName, JsonConvert.SerializeObject(parm, Formatting.Indented));
return true;
}
catch (Exception ex)
{
Console.WriteLine("write error!" + ex.ToString());
//CreateLog.Log.Error("write error!" + ex.ToString());
if (writecount < TryReadWriteCount)
{
Thread.Sleep(1);
writecount++;
WriteDb<T>(parm);
}
return false;
}
finally
{
objlock.ExitWriteLock();
}
}
/// <summary>
/// 读文件到json
/// </summary>
/// <typeparam name="T">任意模型,根据模型匹配文件名</typeparam>
/// <returns></returns>
public string ReadDb<T>()
{
//using (BaseAccess access = new BaseAccess())
//{
// List<AgvInfo> lsit = access.Select<AgvInfo>();
//}
objlock.EnterReadLock();
try
{
string fileName = typeof(T).Name.ToString() + ".json";
//如果没有则创建文件夹
if (!Directory.Exists(xmlPath))
{
Directory.CreateDirectory(xmlPath);
}//如果没有则创建文件
if (!File.Exists(xmlPath + fileName))
{
FileStream fs1 = new FileStream(xmlPath + fileName, FileMode.Create, FileAccess.ReadWrite);
fs1.Close();
return null;
}
else
{
var temp = File.ReadAllText(xmlPath + fileName);
return temp;
//return JsonConvert.DeserializeObject<List<T>>(temp);
}
}
catch (Exception ex)
{
Console.WriteLine("read error!" + ex.ToString());
if (readcount < TryReadWriteCount)
{
Thread.Sleep(1);
readcount++;
ReadDb<T>();
}
//CreateLog.Log.Error("read error!" + ex.ToString());
return null;
}
finally
{
objlock.ExitReadLock();
}
}
}
}
@@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.IO;
using System.Text;
using System.Configuration;
using Newtonsoft.Json;
using System.Threading.Tasks;
using System.Linq;
using System.Net.NetworkInformation;
using System.Collections.Specialized;
using System.Reflection;
namespace HxBusiness
{
public class ConnectedManager
{
public bool isOpen(string url)
{
if (string.IsNullOrEmpty(url))
{
return false;
}
Ping p = new Ping();
Uri uri = new Uri(url);
if (p.Send(uri.Host, 150).Status == IPStatus.Success)
{
return true;
}
return false;
}
/// <summary>
/// 获取配置信息
/// </summary>
/// <returns></returns>
public string GetUrl(string url)
{
try
{
if (string.IsNullOrEmpty(url))
{
return "-1";
}
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Method = "GET";
request.ContentType = "application/json";
HttpWebResponse Response2 = request.GetResponse() as HttpWebResponse;
StreamReader reader = new StreamReader(Response2.GetResponseStream(), Encoding.UTF8);
string jsontmp = reader.ReadToEnd();
reader.Close();
Response2.Close();
return jsontmp;
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return "-2";
}
}
public string PostForUrl(string url, string postdb)
{
try
{
if (string.IsNullOrEmpty(url))
{
return "-1";
}
byte[] byteArray = Encoding.UTF8.GetBytes(postdb);
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
//设置请求头
SetHeaderValue(request.Headers, "owl-ois-adapter-tag", "HUAXIAO");
request.Method = "POST";
request.ContentType = "application/json";
request.ContentLength = byteArray.Length;
Stream newStream = request.GetRequestStream();//创建一个Stream,赋值是写入HttpWebRequest对象提供的一个stream里面
newStream.Write(byteArray, 0, byteArray.Length);
newStream.Close();
HttpWebResponse Response2 = request.GetResponse() as HttpWebResponse;
StreamReader reader = new StreamReader(Response2.GetResponseStream(), Encoding.UTF8);
string jsontmp = reader.ReadToEnd();
reader.Close();
Response2.Close();
return jsontmp;
}
catch (Exception ex)
{
Console.WriteLine("服务错误:" + ex.ToString() + "提示:" + ex.StackTrace);
return "-2";
}
}
public static void SetHeaderValue(WebHeaderCollection header, string name, string value)
{
var property = typeof(WebHeaderCollection).GetProperty("InnerCollection", BindingFlags.Instance | BindingFlags.NonPublic);
if (property != null)
{
var collection = property.GetValue(header, null) as NameValueCollection;
collection[name] = value;
}
}
}
}