Init - 初始化仓库

master
wenjy 1 year ago
commit c9e891ee31

Binary file not shown.

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{247C9F10-9DB6-4761-80E1-86D81018437A}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AucmaEms.Common</RootNamespace>
<AssemblyName>AucmaEms.Common</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net">
<HintPath>..\dll\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CheckUtil.cs" />
<Compile Include="ConfigHelper.cs" />
<Compile Include="ExpressionExtensions.cs" />
<Compile Include="JsonChange.cs" />
<Compile Include="LogHelper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StringChange.cs" />
</ItemGroup>
<ItemGroup>
<None Include="log4net.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AucmaEms.Common
{
public class CheckUtil
{
/// <summary>
/// 异或校验
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static int BCC(byte[] data)
{
int temp = 0;
for (int index = 0; index < data.Length; index++)
{
temp = temp ^ data[index];
}
return temp;
}
/// <summary>
/// CRC16_Modbus效验
/// </summary>
/// <param name="byteData">要进行计算的字节数组</param>
/// <returns>计算后的数组</returns>
public static byte[] ToModbus(byte[] byteData)
{
byte[] CRC = new byte[2];
UInt16 wCrc = 0xFFFF;
for (int i = 0; i < byteData.Length; i++)
{
wCrc ^= Convert.ToUInt16(byteData[i]);
for (int j = 0; j < 8; j++)
{
if ((wCrc & 0x0001) == 1)
{
wCrc >>= 1;
wCrc ^= 0xA001;//异或多项式
}
else
{
wCrc >>= 1;
}
}
}
CRC[1] = (byte)((wCrc & 0xFF00) >> 8);//高位在后
CRC[0] = (byte)(wCrc & 0x00FF); //低位在前
return CRC;
}
}
}

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AucmaEms.Common
{
/// <summary>
/// 获取配置
/// </summary>
/// <param name="sections">节点配置</param>
/// <returns></returns>
public class ConfigHelper
{
/// <summary>
/// 获取配置
/// </summary>
/// <param name="sections">节点配置</param>
/// <returns></returns>
public static string GetConfig(string sections)
{
try
{
return ConfigurationManager.AppSettings[sections].ToString();
}
catch (Exception) { }
return "";
}
/// <summary>
/// 更新Config文件若Key已存在替换当前Val值不存在则添加新的键值对
/// </summary>
/// <param name="str_newKey"></param>
/// <param name="str_newVal"></param>
public static void UpdateAppConfig(string key, string value)
{
//增加的内容写在appSettings段下 <add key="RegCode" value="0"/>
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
config.AppSettings.Settings.Add(key, value);
}
else
{
config.AppSettings.Settings[key].Value = value;
}
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
}
}
}

@ -0,0 +1,152 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace AucmaEms.Common
{
/// <summary>
/// 谓词表达式构建器
/// </summary>
public static class ExpressionExtensions
{
/// <summary>
/// 创建一个值恒为 <c>true</c> 的表达式。
/// </summary>
/// <typeparam name="T">表达式方法类型</typeparam>
/// <returns>一个值恒为 <c>true</c> 的表达式。</returns>
public static Expression<Func<T, bool>> True<T>() { return p => true; }
/// <summary>
/// 创建一个值恒为 <c>false</c> 的表达式。
/// </summary>
/// <typeparam name="T">表达式方法类型</typeparam>
/// <returns>一个值恒为 <c>false</c> 的表达式。</returns>
public static Expression<Func<T, bool>> False<T>() { return f => false; }
/// <summary>
/// 使用 Expression.OrElse 的方式拼接两个 System.Linq.Expression。
/// </summary>
/// <typeparam name="T">表达式方法类型</typeparam>
/// <param name="left">左边的 System.Linq.Expression 。</param>
/// <param name="right">右边的 System.Linq.Expression。</param>
/// <returns>拼接完成的 System.Linq.Expression。</returns>
public static Expression<T> Or<T>(this Expression<T> left, Expression<T> right)
{
return MakeBinary(left, right, Expression.OrElse);
}
/// <summary>
/// 使用 Expression.AndAlso 的方式拼接两个 System.Linq.Expression。
/// </summary>
/// <typeparam name="T">表达式方法类型</typeparam>
/// <param name="left">左边的 System.Linq.Expression 。</param>
/// <param name="right">右边的 System.Linq.Expression。</param>
/// <returns>拼接完成的 System.Linq.Expression。</returns>
public static Expression<T> And<T>(this Expression<T> left, Expression<T> right)
{
return MakeBinary(left, right, Expression.AndAlso);
}
/// <summary>
/// 使用自定义的方式拼接两个 System.Linq.Expression。
/// </summary>
/// <typeparam name="T">表达式方法类型</typeparam>
/// <param name="left">左边的 System.Linq.Expression 。</param>
/// <param name="right">右边的 System.Linq.Expression。</param>
/// <param name="func"> </param>
/// <returns>拼接完成的 System.Linq.Expression。</returns>
private static Expression<T> MakeBinary<T>(this Expression<T> left, Expression<T> right, Func<Expression, Expression, Expression> func)
{
return MakeBinary((LambdaExpression)left, right, func) as Expression<T>;
}
/// <summary>
/// 拼接两个 <paramref>
/// <name>System.Linq.Expression</name>
/// </paramref> ,两个 <paramref>
/// <name>System.Linq.Expression</name>
/// </paramref> 的参数必须完全相同。
/// </summary>
/// <param name="left">左边的 <paramref>
/// <name>System.Linq.Expression</name>
/// </paramref> </param>
/// <param name="right">右边的 <paramref>
/// <name>System.Linq.Expression</name>
/// </paramref> </param>
/// <param name="func">表达式拼接的具体逻辑</param>
/// <returns>拼接完成的 <paramref>
/// <name>System.Linq.Expression</name>
/// </paramref> </returns>
private static LambdaExpression MakeBinary(this LambdaExpression left, LambdaExpression right, Func<Expression, Expression, Expression> func)
{
var data = Combinate(right.Parameters, left.Parameters).ToArray();
right = ParameterReplace.Replace(right, data) as LambdaExpression;
return Expression.Lambda(func(left.Body, right.Body), left.Parameters.ToArray());
}
/// <summary>
/// 合并参数
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
private static IEnumerable<KeyValuePair<T, T>> Combinate<T>(IEnumerable<T> left, IEnumerable<T> right)
{
var a = left.GetEnumerator();
var b = right.GetEnumerator();
while (a.MoveNext() && b.MoveNext())
yield return new KeyValuePair<T, T>(a.Current, b.Current);
}
}
internal sealed class ParameterReplace : ExpressionVisitor
{
public static Expression Replace(Expression e, IEnumerable<KeyValuePair<ParameterExpression, ParameterExpression>> paramList)
{
var item = new ParameterReplace(paramList);
return item.Visit(e);
}
private readonly Dictionary<ParameterExpression, ParameterExpression> _parameters;
public ParameterReplace(IEnumerable<KeyValuePair<ParameterExpression, ParameterExpression>> paramList)
{
_parameters = paramList.ToDictionary(p => p.Key, p => p.Value, new ParameterEquality());
}
protected override Expression VisitParameter(ParameterExpression p)
{
ParameterExpression result;
if (_parameters.TryGetValue(p, out result))
return result;
return base.VisitParameter(p);
}
#region class: ParameterEquality
private class ParameterEquality : IEqualityComparer<ParameterExpression>
{
public bool Equals(ParameterExpression x, ParameterExpression y)
{
if (x == null || y == null)
return false;
return x.Type == y.Type;
}
public int GetHashCode(ParameterExpression obj)
{
if (obj == null)
return 0;
return obj.Type.GetHashCode();
}
}
#endregion
}
}

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
namespace AucmaEms.Common
{
/// <summary>
/// Json格式转换
/// </summary>
public class JsonChange
{
/// <summary>
/// Model 实体转json
/// </summary>
/// <param name="Model">可以是单个实体也可是实体集ToList()</param>
/// <returns></returns>
public static string ModeToJson(object Model)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
string str = serializer.Serialize(Model);
//HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
//return result;
return str;
}
}
}

@ -0,0 +1,135 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AucmaEms.Common
{
/// <summary>
/// 统一日志工具类
/// </summary>
public class LogHelper
{
private static readonly Lazy<LogHelper> lazy = new Lazy<LogHelper>(() => new LogHelper());
public static LogHelper Instance
{
get
{
return lazy.Value;
}
}
private LogHelper() { }
private readonly log4net.ILog loginfo = log4net.LogManager.GetLogger("loginfo");
private readonly log4net.ILog logerror = log4net.LogManager.GetLogger("logerror");
private readonly log4net.ILog logPlc = log4net.LogManager.GetLogger("plclog");
private readonly log4net.ILog logRfid = log4net.LogManager.GetLogger("rfidlog");
private readonly log4net.ILog logView = log4net.LogManager.GetLogger("viewlog");
private readonly log4net.ILog sqllog = log4net.LogManager.GetLogger("sqllog");
private readonly log4net.ILog semaphorelog = log4net.LogManager.GetLogger("semaphorelog");
/// <summary>
/// 记录Info日志
/// </summary>
/// <param name="msg"></param>
/// <param name="ex"></param>
public void Info(string msg)
{
if (loginfo.IsInfoEnabled)
{
loginfo.Info(msg);
}
}
/// <summary>
/// 记录PLC日志
/// </summary>
/// <param name="msg"></param>
public void PlcLog(string msg)
{
if (logPlc.IsInfoEnabled)
{
logPlc.Info(msg);
}
}
/// <summary>
/// 记录Rfid日志
/// </summary>
/// <param name="msg"></param>
public void RfidLog(string msg)
{
if (logRfid.IsInfoEnabled)
{
logRfid.Info(msg);
}
}
/// <summary>
/// 界面日志
/// </summary>
/// <param name="msg"></param>
public void ViewLog(string msg)
{
if (logView.IsInfoEnabled)
{
logView.Info(msg);
}
}
public void SqlLog(string msg)
{
if (sqllog.IsInfoEnabled)
{
sqllog.Info(msg);
}
}
public void SemaphoreLog(string msg)
{
if (semaphorelog.IsInfoEnabled)
{
semaphorelog.Info(msg);
}
}
/// <summary>
/// 记录Error日志
/// </summary>
/// <param name="errorMsg"></param>
/// <param name="ex"></param>
public void Error(string info, Exception ex = null)
{
if (!string.IsNullOrEmpty(info) && ex == null)
{
logerror.ErrorFormat("【附加信息】 : {0}<br>", new object[] { info });
}
else if (!string.IsNullOrEmpty(info) && ex != null)
{
string errorMsg = BeautyErrorMsg(ex);
logerror.ErrorFormat("【附加信息】 : {0}<br>{1}", new object[] { info, errorMsg });
}
else if (string.IsNullOrEmpty(info) && ex != null)
{
string errorMsg = BeautyErrorMsg(ex);
logerror.Error(errorMsg);
}
}
/// <summary>
/// 美化错误信息
/// </summary>
/// <param name="ex">异常</param>
/// <returns>错误信息</returns>
private static string BeautyErrorMsg(Exception ex)
{
string errorMsg = string.Format("【异常类型】:{0} <br>【异常信息】:{1} <br>【堆栈调用】:{2}", new object[] { ex.GetType().Name, ex.Message, ex.StackTrace });
errorMsg = errorMsg.Replace("\r\n", "<br>");
errorMsg = errorMsg.Replace("位置", "<strong style=\"color:red\">位置</strong>");
return errorMsg;
}
}
}

@ -0,0 +1,38 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("AucmaEms.Common")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AucmaEms.Common")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", ConfigFileExtension = "config", Watch = true)]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("247c9f10-9db6-4761-80e1-86d81018437a")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -0,0 +1,151 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AucmaEms.Common
{
/// <summary>
/// 数据类型转换
/// </summary>
public static class StringChange
{
#region 数据类型转换函数
/// <summary>
/// 将字符串强制转换成int转换失败则返回0
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static int ParseToInt(string str)
{
int returnInt = 0;
if (str == null || str.Trim().Length < 1)
{
return returnInt;
}
if (int.TryParse(str, out returnInt))
{
return returnInt;
}
else
{
return 0;
}
}
public static byte[] Swap16Bytes(byte[] OldU16)
{
byte[] ReturnBytes = new byte[2];
ReturnBytes[1] = OldU16[0];
ReturnBytes[0] = OldU16[1];
return ReturnBytes;
}
public static bool CompareBytes(byte[] byteA, byte[] byteB, int iLen)
{
for (int i = 0; i < iLen; i++)
{
if (byteA[i] != byteB[i])
{
return false;
}
}
return true;
}
public static string bytesToHexStr(byte[] bytes, int iLen)//e.g. { 0x01, 0x01} ---> " 01 01"
{
string returnStr = "";
if (bytes != null)
{
for (int i = 0; i < iLen; i++)
{
returnStr += bytes[i].ToString("X2");
}
}
return returnStr;
}
public static byte[] HexStrTorbytes(string strHex)//e.g. " 01 01" ---> { 0x01, 0x01}
{
strHex = strHex.Replace(" ", "");
if ((strHex.Length % 2) != 0)
strHex += " ";
byte[] returnBytes = new byte[strHex.Length / 2];
for (int i = 0; i < returnBytes.Length; i++)
returnBytes[i] = Convert.ToByte(strHex.Substring(i * 2, 2), 16);
return returnBytes;
}
public static string StringToHexString(string s, Encoding encode)
{
byte[] b = encode.GetBytes(s); //按照指定编码将string编程字节数组
string result = string.Empty;
for (int i = 0; i < b.Length; i++) //逐字节变为16进制字符以%隔开
{
result += "%" + Convert.ToString(b[i], 16);
}
return result;
}
public static string HexStringToString(string hs, Encoding encode)
{
//以%分割字符串,并去掉空字符
string[] chars = hs.Split(new char[] { '%' }, StringSplitOptions.RemoveEmptyEntries);
byte[] b = new byte[chars.Length];
//逐个字符变为16进制字节数据
for (int i = 0; i < chars.Length; i++)
{
b[i] = Convert.ToByte(chars[i], 16);
}
//按照指定编码将字节数组变为字符串
return encode.GetString(b);
}
public static short SwapInt16(this short n)
{
return (short)(((n & 0xff) << 8) | ((n >> 8) & 0xff));
}
public static ushort SwapUInt16(this ushort n)
{
return (ushort)(((n & 0xff) << 8) | ((n >> 8) & 0xff));
}
public static int SwapInt32(this int n)
{
return (int)(((SwapInt16((short)n) & 0xffff) << 0x10) |
(SwapInt16((short)(n >> 0x10)) & 0xffff));
}
public static uint SwapUInt32(this uint n)
{
return (uint)(((SwapUInt16((ushort)n) & 0xffff) << 0x10) |
(SwapUInt16((ushort)(n >> 0x10)) & 0xffff));
}
public static long SwapInt64(this long n)
{
return (long)(((SwapInt32((int)n) & 0xffffffffL) << 0x20) |
(SwapInt32((int)(n >> 0x20)) & 0xffffffffL));
}
public static ulong SwapUInt64(this ulong n)
{
return (ulong)(((SwapUInt32((uint)n) & 0xffffffffL) << 0x20) |
(SwapUInt32((uint)(n >> 0x20)) & 0xffffffffL));
}
public static byte[] intToBytesBig(int value)
{
byte[] src = new byte[4];
src[0] = (byte)((value >> 24) & 0xFF);
src[1] = (byte)((value >> 16) & 0xFF);
src[2] = (byte)((value >> 8) & 0xFF);
src[3] = (byte)(value & 0xFF);
return src;
}
#endregion
}
}

@ -0,0 +1,153 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="System.Configuration.IgnoreSectionHandler"/>
</configSections>
<appSettings>
</appSettings>
<log4net>
<!--错误日志类-->
<logger name="logerror">
<level value="ALL" />
<appender-ref ref="ErrorAppender" />
</logger>
<!--信息日志类-->
<logger name="loginfo">
<level value="ALL" />
<appender-ref ref="InfoAppender" />
</logger>
<!--PLC日志类-->
<logger name="plclog">
<level value="ALL" />
<appender-ref ref="PlcAppender" />
</logger>
<!--RFID日志类-->
<logger name="rfidlog">
<level value="ALL" />
<appender-ref ref="RfidAppender" />
</logger>
<!--RFID日志类-->
<logger name="viewlog">
<level value="ALL" />
<appender-ref ref="ViewAppender" />
</logger>
<!--Sql日志类-->
<logger name="sqllog">
<level value="ALL" />
<appender-ref ref="SqlAppender" />
</logger>
<!--信号量日志类-->
<logger name="semaphorelog">
<level value="ALL" />
<appender-ref ref="SemaphoreAppender" />
</logger>
<!--错误日志附加介质-->
<appender name="ErrorAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxSizeRollBackups" value="100" />
<param name="MaxFileSize" value="10240" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"LogError.html"'/>
<param name="RollingStyle" value="Date" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;HR COLOR=red&gt;%n异常时间%d [%t] &lt;BR&gt;%n异常级别%-5p &lt;BR&gt;%n异 常 类:%c [%x] &lt;BR&gt;%n%m &lt;BR&gt;%n &lt;HR Size=1&gt;" />
</layout>
</appender>
<!--信息日志附加介质-->
<appender name="InfoAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"LogInfo.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
<!--PLC日志附加介质-->
<appender name="PlcAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"PlcLog.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
<!--Rfid日志附加介质-->
<appender name="RfidAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"RfidLog.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
<appender name="ViewAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"ViewLog.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
<appender name="SqlAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"SqlLog.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
<appender name="SemaphoreAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"SemaphoreLog.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
</log4net>
</configuration>

@ -0,0 +1,153 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="System.Configuration.IgnoreSectionHandler"/>
</configSections>
<appSettings>
</appSettings>
<log4net>
<!--错误日志类-->
<logger name="logerror">
<level value="ALL" />
<appender-ref ref="ErrorAppender" />
</logger>
<!--信息日志类-->
<logger name="loginfo">
<level value="ALL" />
<appender-ref ref="InfoAppender" />
</logger>
<!--PLC日志类-->
<logger name="plclog">
<level value="ALL" />
<appender-ref ref="PlcAppender" />
</logger>
<!--RFID日志类-->
<logger name="rfidlog">
<level value="ALL" />
<appender-ref ref="RfidAppender" />
</logger>
<!--RFID日志类-->
<logger name="viewlog">
<level value="ALL" />
<appender-ref ref="ViewAppender" />
</logger>
<!--Sql日志类-->
<logger name="sqllog">
<level value="ALL" />
<appender-ref ref="SqlAppender" />
</logger>
<!--信号量日志类-->
<logger name="semaphorelog">
<level value="ALL" />
<appender-ref ref="SemaphoreAppender" />
</logger>
<!--错误日志附加介质-->
<appender name="ErrorAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxSizeRollBackups" value="100" />
<param name="MaxFileSize" value="10240" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"LogError.html"'/>
<param name="RollingStyle" value="Date" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;HR COLOR=red&gt;%n异常时间%d [%t] &lt;BR&gt;%n异常级别%-5p &lt;BR&gt;%n异 常 类:%c [%x] &lt;BR&gt;%n%m &lt;BR&gt;%n &lt;HR Size=1&gt;" />
</layout>
</appender>
<!--信息日志附加介质-->
<appender name="InfoAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"LogInfo.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
<!--PLC日志附加介质-->
<appender name="PlcAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"PlcLog.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
<!--Rfid日志附加介质-->
<appender name="RfidAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"RfidLog.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
<appender name="ViewAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"ViewLog.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
<appender name="SqlAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"SqlLog.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
<appender name="SemaphoreAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"SemaphoreLog.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
</log4net>
</configuration>

@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.5.2", FrameworkDisplayName = ".NET Framework 4.5.2")]

@ -0,0 +1,18 @@
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.Common\bin\Debug\log4net.config
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.Common\bin\Debug\AucmaEms.Common.dll
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.Common\bin\Debug\AucmaEms.Common.pdb
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.Common\bin\Debug\log4net.dll
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.Common\obj\Debug\AucmaEms.Common.csproj.AssemblyReference.cache
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.Common\obj\Debug\AucmaEms.Common.csproj.CoreCompileInputs.cache
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.Common\obj\Debug\AucmaEms.Common.csproj.CopyComplete
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.Common\obj\Debug\AucmaEms.Common.dll
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.Common\obj\Debug\AucmaEms.Common.pdb
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.Common\bin\Debug\log4net.config
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.Common\bin\Debug\AucmaEms.Common.dll
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.Common\bin\Debug\AucmaEms.Common.pdb
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.Common\bin\Debug\log4net.dll
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.Common\obj\Debug\AucmaEms.Common.csproj.AssemblyReference.cache
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.Common\obj\Debug\AucmaEms.Common.csproj.CoreCompileInputs.cache
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.Common\obj\Debug\AucmaEms.Common.csproj.CopyComplete
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.Common\obj\Debug\AucmaEms.Common.dll
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.Common\obj\Debug\AucmaEms.Common.pdb

@ -0,0 +1,44 @@
using AucmaEms.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AucmaEms.Entity
{
public sealed class AppConfig
{
private static readonly Lazy<AppConfig> lazy = new Lazy<AppConfig>(() => new AppConfig());
public static AppConfig Instance
{
get
{
return lazy.Value;
}
}
private AppConfig() { }
/// <summary>
/// 读取频率
/// </summary>
public int ReadIntervel = StringChange.ParseToInt(ConfigHelper.GetConfig("ReadIntervel"));
/// <summary>
/// 监听IP
/// </summary>
public string listenIp = ConfigHelper.GetConfig("listenIp");
/// <summary>
/// 监听端口号
/// </summary>
public int listenPort = StringChange.ParseToInt(ConfigHelper.GetConfig("listenPort"));
/// <summary>
/// 数据库字符串
/// </summary>
public string connectStr = ConfigHelper.GetConfig("connectStr");
}
}

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{86A58654-8FE5-44F0-B17D-5CCE78743C00}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AucmaEms.Entity</RootNamespace>
<AssemblyName>AucmaEms.Entity</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="SqlSugar">
<HintPath>..\dll\SqlSugar.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AppConfig.cs" />
<Compile Include="BaseMonitorInfo.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScadaEmsElectricLoss.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AucmaEms.Common\AucmaEms.Common.csproj">
<Project>{247C9F10-9DB6-4761-80E1-86D81018437A}</Project>
<Name>AucmaEms.Common</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -0,0 +1,82 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AucmaEms.Entity
{
/// <summary>
/// 测控点信息
///</summary>
[SugarTable("BASE_MONITOR_INFO")]
public class BaseMonitorInfo
{
/// <summary>
///
///</summary>
[SugarColumn(ColumnName = "OBJID")]
public string objid { get; set; }
/// <summary>
/// 测控点编号
///</summary>
[SugarColumn(ColumnName = "MONITOR_ID")]
public string monitorId { get; set; }
/// <summary>
/// 父级编号
///</summary>
[SugarColumn(ColumnName = "P_MONITOR_ID")]
public string pMonitorId { get; set; }
/// <summary>
/// 测控点名称
///</summary>
[SugarColumn(ColumnName = "MONITOR_NAME")]
public string monitorName { get; set; }
/// <summary>
/// 测控点类型
///</summary>
[SugarColumn(ColumnName = "MONITOR_TYPE")]
public decimal? monitorType { get; set; }
/// <summary>
/// 测控点位置
///</summary>
[SugarColumn(ColumnName = "MONITOR_ADDR")]
public string monitorAddr { get; set; }
/// <summary>
/// 测控点状态
///</summary>
[SugarColumn(ColumnName = "MONITOR_STATUS")]
public decimal? monitorStatus { get; set; }
/// <summary>
///
///</summary>
[SugarColumn(ColumnName = "CORRECT_VALUE")]
public decimal? correctValue { get; set; }
/// <summary>
/// PT值
///</summary>
[SugarColumn(ColumnName = "PT")]
public decimal pt { get; set; }
/// <summary>
/// CT值
///</summary>
[SugarColumn(ColumnName = "CT")]
public decimal ct { get; set; }
/// <summary>
///
///</summary>
[SugarColumn(ColumnName = "GRADE")]
public decimal? grade { get; set; }
/// <summary>
/// 记录时间
///</summary>
[SugarColumn(ColumnName = "RECORD_TIME")]
public DateTime? recordTime { get; set; }
/// <summary>
/// 测控点网络地址
///</summary>
[SugarColumn(ColumnName = "NETWORK_ADDRESS")]
public string networkAddress { get; set; }
}
}

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("AucmaEms.Entity")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AucmaEms.Entity")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("86a58654-8fe5-44f0-b17d-5cce78743c00")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -0,0 +1,143 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AucmaEms.Entity
{
/// <summary>
/// 电能
///</summary>
[SugarTable("SCADA_EMS_ELECTRICLOSS")]
public class ScadaEmsElectricLoss
{
/// <summary>
/// 编号
///</summary>
[SugarColumn(ColumnName = "UUID")]
public string uuid { get; set; }
/// <summary>
/// 传感器编号
///</summary>
[SugarColumn(ColumnName = "MONITOR_ID")]
public string monitorId { get; set; }
/// <summary>
/// 总有功功率
///</summary>
[SugarColumn(ColumnName = "ZYGGL")]
public decimal zyggl { get; set; }
/// <summary>
/// 总无功功率
///</summary>
[SugarColumn(ColumnName = "ZWGGL")]
public decimal zwggl { get; set; }
/// <summary>
/// A项电压
///</summary>
[SugarColumn(ColumnName = "VA")]
public decimal va { get; set; }
/// <summary>
/// B项电压
///</summary>
[SugarColumn(ColumnName = "VB")]
public decimal vb { get; set; }
/// <summary>
/// C项电压
///</summary>
[SugarColumn(ColumnName = "VC")]
public decimal vc { get; set; }
/// <summary>
/// A项电流
///</summary>
[SugarColumn(ColumnName = "IA")]
public decimal ia { get; set; }
/// <summary>
/// B项电流
///</summary>
[SugarColumn(ColumnName = "IB")]
public decimal ib { get; set; }
/// <summary>
/// C项电流
///</summary>
[SugarColumn(ColumnName = "IC")]
public decimal ic { get; set; }
/// <summary>
/// A项功率因数
///</summary>
[SugarColumn(ColumnName = "PF_A")]
public decimal pfA { get; set; }
/// <summary>
/// B项功率因数
///</summary>
[SugarColumn(ColumnName = "PF_B")]
public decimal pfB { get; set; }
/// <summary>
/// C项功率因数
///</summary>
[SugarColumn(ColumnName = "PF_C")]
public decimal pfC { get; set; }
/// <summary>
/// 总功率因数
///</summary>
[SugarColumn(ColumnName = "PF")]
public decimal pf { get; set; }
/// <summary>
/// 正向有功总电能
///</summary>
[SugarColumn(ColumnName = "ZXYG")]
public decimal zxyg { get; set; }
/// <summary>
/// 反向有功总电能
///</summary>
[SugarColumn(ColumnName = "FXYG")]
public decimal fxyg { get; set; }
/// <summary>
/// 有功电能总净值
///</summary>
[SugarColumn(ColumnName = "YGDNZJZ")]
public decimal ygdnzjz { get; set; }
/// <summary>
/// 有功总电能
///</summary>
[SugarColumn(ColumnName = "YGZDN")]
public decimal ygzdn { get; set; }
/// <summary>
/// 正向无功总电能
///</summary>
[SugarColumn(ColumnName = "ZXWG")]
public decimal zxwg { get; set; }
/// <summary>
/// 反向无功总电能
///</summary>
[SugarColumn(ColumnName = "FXWG")]
public decimal fxwg { get; set; }
/// <summary>
/// 无功电能总净值
///</summary>
[SugarColumn(ColumnName = "WGDNZJZ")]
public decimal wgdnzjz { get; set; }
/// <summary>
/// 无功总电能
///</summary>
[SugarColumn(ColumnName = "WGZDN")]
public decimal wgzdn { get; set; }
/// <summary>
/// PT值
///</summary>
[SugarColumn(ColumnName = "PT")]
public decimal pt { get; set; }
/// <summary>
/// CT值
///</summary>
[SugarColumn(ColumnName = "CT")]
public decimal ct { get; set; }
/// <summary>
/// 采集时间
///</summary>
[SugarColumn(ColumnName = "COLLECT_TIME")]
public DateTime collectTime { get; set; }
}
}

@ -0,0 +1,153 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="System.Configuration.IgnoreSectionHandler"/>
</configSections>
<appSettings>
</appSettings>
<log4net>
<!--错误日志类-->
<logger name="logerror">
<level value="ALL" />
<appender-ref ref="ErrorAppender" />
</logger>
<!--信息日志类-->
<logger name="loginfo">
<level value="ALL" />
<appender-ref ref="InfoAppender" />
</logger>
<!--PLC日志类-->
<logger name="plclog">
<level value="ALL" />
<appender-ref ref="PlcAppender" />
</logger>
<!--RFID日志类-->
<logger name="rfidlog">
<level value="ALL" />
<appender-ref ref="RfidAppender" />
</logger>
<!--RFID日志类-->
<logger name="viewlog">
<level value="ALL" />
<appender-ref ref="ViewAppender" />
</logger>
<!--Sql日志类-->
<logger name="sqllog">
<level value="ALL" />
<appender-ref ref="SqlAppender" />
</logger>
<!--信号量日志类-->
<logger name="semaphorelog">
<level value="ALL" />
<appender-ref ref="SemaphoreAppender" />
</logger>
<!--错误日志附加介质-->
<appender name="ErrorAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxSizeRollBackups" value="100" />
<param name="MaxFileSize" value="10240" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"LogError.html"'/>
<param name="RollingStyle" value="Date" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;HR COLOR=red&gt;%n异常时间%d [%t] &lt;BR&gt;%n异常级别%-5p &lt;BR&gt;%n异 常 类:%c [%x] &lt;BR&gt;%n%m &lt;BR&gt;%n &lt;HR Size=1&gt;" />
</layout>
</appender>
<!--信息日志附加介质-->
<appender name="InfoAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"LogInfo.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
<!--PLC日志附加介质-->
<appender name="PlcAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"PlcLog.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
<!--Rfid日志附加介质-->
<appender name="RfidAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"RfidLog.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
<appender name="ViewAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"ViewLog.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
<appender name="SqlAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"SqlLog.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
<appender name="SemaphoreAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"SemaphoreLog.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
</log4net>
</configuration>

@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.5.2", FrameworkDisplayName = ".NET Framework 4.5.2")]

@ -0,0 +1,24 @@
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.Entity\bin\Debug\log4net.config
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.Entity\bin\Debug\AucmaEms.Entity.dll
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.Entity\bin\Debug\AucmaEms.Entity.pdb
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.Entity\bin\Debug\AucmaEms.Common.dll
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.Entity\bin\Debug\SqlSugar.dll
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.Entity\bin\Debug\log4net.dll
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.Entity\bin\Debug\AucmaEms.Common.pdb
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.Entity\obj\Debug\AucmaEms.Entity.csproj.AssemblyReference.cache
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.Entity\obj\Debug\AucmaEms.Entity.csproj.CoreCompileInputs.cache
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.Entity\obj\Debug\AucmaEms.Entity.csproj.CopyComplete
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.Entity\obj\Debug\AucmaEms.Entity.dll
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.Entity\obj\Debug\AucmaEms.Entity.pdb
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.Entity\bin\Debug\log4net.config
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.Entity\bin\Debug\AucmaEms.Entity.dll
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.Entity\bin\Debug\AucmaEms.Entity.pdb
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.Entity\bin\Debug\AucmaEms.Common.dll
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.Entity\bin\Debug\SqlSugar.dll
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.Entity\bin\Debug\log4net.dll
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.Entity\bin\Debug\AucmaEms.Common.pdb
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.Entity\obj\Debug\AucmaEms.Entity.csproj.AssemblyReference.cache
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.Entity\obj\Debug\AucmaEms.Entity.csproj.CoreCompileInputs.cache
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.Entity\obj\Debug\AucmaEms.Entity.csproj.CopyComplete
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.Entity\obj\Debug\AucmaEms.Entity.dll
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.Entity\obj\Debug\AucmaEms.Entity.pdb

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2060415B-ADF1-4D90-BBFF-CE3D43EC03E5}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AucmaEms.SqlSugar</RootNamespace>
<AssemblyName>AucmaEms.SqlSugar</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Oracle.ManagedDataAccess">
<HintPath>..\dll\Oracle.ManagedDataAccess.dll</HintPath>
</Reference>
<Reference Include="SqlSugar">
<HintPath>..\dll\SqlSugar.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="IBaseServices.cs" />
<Compile Include="Impl\BaseServices.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AucmaEms.Common\AucmaEms.Common.csproj">
<Project>{247C9F10-9DB6-4761-80E1-86D81018437A}</Project>
<Name>AucmaEms.Common</Name>
</ProjectReference>
<ProjectReference Include="..\AucmaEms.Entity\AucmaEms.Entity.csproj">
<Project>{86A58654-8FE5-44F0-B17D-5CCE78743C00}</Project>
<Name>AucmaEms.Entity</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -0,0 +1,109 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace AucmaEms.SqlSugar
{
/// <summary>
/// 统一操作类
/// </summary>
/// <typeparam name="TEntity"></typeparam>
public interface IBaseServices<TEntity> where TEntity : class
{
Task<TEntity> QuerySingle(Expression<Func<TEntity, bool>> whereExpression);
Task<TEntity> QueryById(object objId);
Task<TEntity> QueryById(object objId, bool blnUseCache = false);
Task<List<TEntity>> QueryByIDs(object[] lstIds);
Task<int> Add(TEntity model);
Task<int> AddLog(TEntity model);
Task<int> Add(List<TEntity> listEntity);
Task<bool> DeleteById(object id);
Task<bool> Delete(TEntity model);
Task<bool> Delete(Expression<Func<TEntity, bool>> whereExpression);
Task<bool> DeleteByIds(object[] ids);
Task<bool> Update(TEntity model);
Task<bool> Update(TEntity entity, string strWhere);
Task<bool> Update(object operateAnonymousObjects);
Task<bool> Update(TEntity entity, List<string> lstColumns = null, List<string> lstIgnoreColumns = null, string strWhere = "");
Task<List<TEntity>> Query();
Task<List<TEntity>> Query(string strWhere);
List<TEntity> Query1(Expression<Func<TEntity, bool>> whereExpression);
Task<List<TEntity>> Query(Expression<Func<TEntity, bool>> whereExpression);
Task<List<TEntity>> Query(Expression<Func<TEntity, bool>> whereExpression, string strOrderByFileds);
Task<List<TEntity>> Query(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, object>> orderByExpression, bool isAsc = true);
Task<List<TEntity>> Query(string strWhere, string strOrderByFileds);
Task<TEntity> QueryFirst(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, object>> orderByExpression, bool isAsc = true);
Task<List<TEntity>> Query(Expression<Func<TEntity, bool>> whereExpression, int intTop, string strOrderByFileds);
Task<List<TEntity>> Query(string strWhere, int intTop, string strOrderByFileds);
Task<List<TEntity>> Query(
Expression<Func<TEntity, bool>> whereExpression, int intPageIndex, int intPageSize, string strOrderByFileds);
Task<List<TEntity>> Query(string strWhere, int intPageIndex, int intPageSize, string strOrderByFileds);
Task<List<TResult>> QueryMuch<T, T2, T3, T4, T5, TResult>(
Expression<Func<T, T2, T3, T4, T5, object[]>> joinExpression,
Expression<Func<T, T2, T3, T4, T5, TResult>> selectExpression,
Expression<Func<TResult, bool>> whereLambda = null) where T : class, new();
Task<List<TResult>> QueryMuch<T, T2, T3, T4, TResult>(
Expression<Func<T, T2, T3, T4, object[]>> joinExpression,
Expression<Func<T, T2, T3, T4, TResult>> selectExpression,
Expression<Func<TResult, bool>> whereLambda = null) where T : class, new();
Task<List<TResult>> QueryMuch<T, T2, T3, TResult>(
Expression<Func<T, T2, T3, object[]>> joinExpression,
Expression<Func<T, T2, T3, TResult>> selectExpression,
Expression<Func<TResult, bool>> whereLambda = null) where T : class, new();
Task<List<TResult>> QueryMuch<T, T2, TResult>(
Expression<Func<T, T2, object[]>> joinExpression,
Expression<Func<T, T2, TResult>> selectExpression,
Expression<Func<TResult, bool>> whereLambda = null) where T : class, new();
/// <summary>
/// 存储过程
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="parameters"></param>
/// <returns></returns>
Task<List<T>> QueryByProc<T>(string proc, List<SugarParameter> parameters) where T : class, new();
Task<Tuple<List<T>, List<T2>>> QueryByProc<T, T2>(string proc, List<SugarParameter> parameters)
where T : class, new();
/// <summary>
/// sql语句
/// </summary>
Task<List<T>> QueryBySql<T>(string sql, List<SugarParameter> parameters) where T : class, new();
}
}

@ -0,0 +1,573 @@
using AucmaEms.Common;
using AucmaEms.Entity;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace AucmaEms.SqlSugar.Impl
{
public class BaseServices<TEntity> : IBaseServices<TEntity> where TEntity : class, new()
{
private LogHelper logHelper = LogHelper.Instance;
private AppConfig appConfig = AppConfig.Instance;
private SqlSugarClient _dbBase;
private SqlSugarClient _db
{
get
{
try
{
_dbBase = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = appConfig.connectStr,
DbType = DbType.Oracle,
InitKeyType = InitKeyType.Attribute,//从特性读取主键和自增列信息
IsAutoCloseConnection = true,//开启自动释放模式和EF原理一样我就不多解释了
//InitKey默认SystemTable
});
//可注释
_dbBase.Aop.OnLogExecuting = (sql, pars) => //SQL执行中事件
{
Parallel.For(0, 1, e =>
{
string SqlLog = "";
foreach (string item in new string[] { GetParas(pars), "【SQL语句】" + sql })
{
SqlLog = SqlLog + item;
}
logHelper.SqlLog("SqlLog:" + SqlLog);
});
};
}
catch (Exception ex)
{
logHelper.Error("_db初始化连接异常", ex);
return null;
}
return _dbBase;
}
}
private string GetParas(SugarParameter[] pars)
{
string key = "【SQL参数】";
foreach (var param in pars)
{
key += $"{param.ParameterName}:{param.Value}\n";
}
return key;
}
internal SqlSugarClient Db
{
get { return _db; }
}
public async Task<TEntity> QuerySingle(Expression<Func<TEntity, bool>> whereExpression)
{
return await _db.Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).SingleAsync();
}
public async Task<TEntity> QueryById(object objId)
{
return await _db.Queryable<TEntity>().In(objId).SingleAsync();
}
/// <summary>
/// 功能描述:根据ID查询一条数据
///
/// </summary>
/// <param name="objId">id必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]如果是联合主键请使用Where条件</param>
/// <param name="blnUseCache">是否使用缓存</param>
/// <returns>数据实体</returns>
public async Task<TEntity> QueryById(object objId, bool blnUseCache = false)
{
return await _db.Queryable<TEntity>().WithCacheIF(blnUseCache).In(objId).SingleAsync();
}
/// <summary>
/// 功能描述:根据ID查询数据
///
/// </summary>
/// <param name="lstIds">id列表必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]如果是联合主键请使用Where条件</param>
/// <returns>数据实体列表</returns>
public async Task<List<TEntity>> QueryByIDs(object[] lstIds)
{
return await _db.Queryable<TEntity>().In(lstIds).ToListAsync();
}
/// <summary>
/// 写入实体数据
/// </summary>
/// <param name="entity">博文实体类</param>
/// <returns>影响行数</returns>
public async Task<int> Add(TEntity entity)
{
try
{
//return await _db.Insertable(entity).ExecuteReturnIdentityAsync();
return await _db.Insertable(entity).ExecuteCommandAsync();
}
catch (Exception ex)
{
return 0;
}
}
public async Task<int> AddLog(TEntity entity)
{
try
{
var insert = _db.Insertable(entity);
return await insert.ExecuteReturnIdentityAsync();
}
catch (Exception ex)
{
//LogHelper.Error("插入出錯:" + ex.Message);
return 0;
}
}
/// <summary>
/// 批量插入实体(速度快)
/// </summary>
/// <param name="listEntity">实体集合</param>
/// <returns>影响行数</returns>
public async Task<int> Add(List<TEntity> listEntity)
{
return await _db.Insertable(listEntity.ToArray()).ExecuteCommandAsync();
}
/// <summary>
/// 更新实体数据
/// </summary>
/// <param name="entity">博文实体类</param>
/// <returns></returns>
public async Task<bool> Update(TEntity entity)
{
////这种方式会以主键为条件
//var i = await Task.Run(() => _db.Updateable(entity).ExecuteCommand());
//return i > 0;
//这种方式会以主键为条件
return await _db.Updateable(entity).ExecuteCommandHasChangeAsync();
}
public async Task<bool> Update(TEntity entity, string strWhere)
{
//return await Task.Run(() => _db.Updateable(entity).Where(strWhere).ExecuteCommand() > 0);
return await _db.Updateable(entity).Where(strWhere).ExecuteCommandHasChangeAsync();
}
public async Task<bool> Update(string strSql, SugarParameter[] parameters = null)
{
//return await Task.Run(() => _db.Ado.ExecuteCommand(strSql, parameters) > 0);
return await _db.Ado.ExecuteCommandAsync(strSql, parameters) > 0;
}
public async Task<bool> Update(object operateAnonymousObjects)
{
return await _db.Updateable<TEntity>(operateAnonymousObjects).ExecuteCommandAsync() > 0;
}
public async Task<bool> Update(
TEntity entity,
List<string> lstColumns = null,
List<string> lstIgnoreColumns = null,
string strWhere = ""
)
{
IUpdateable<TEntity> up = _db.Updateable(entity);
if (lstIgnoreColumns != null && lstIgnoreColumns.Count > 0)
{
up = up.IgnoreColumns(lstIgnoreColumns.ToArray());
}
if (lstColumns != null && lstColumns.Count > 0)
{
up = up.UpdateColumns(lstColumns.ToArray());
}
if (!string.IsNullOrEmpty(strWhere))
{
up = up.Where(strWhere);
}
return await up.ExecuteCommandHasChangeAsync();
}
/// <summary>
/// 根据实体删除一条数据
/// </summary>
/// <param name="entity">实体类</param>
/// <returns></returns>
public async Task<bool> Delete(TEntity entity)
{
//var i = await Task.Run(() => _db.Deleteable(entity).ExecuteCommand());
//return i > 0;
return await _db.Deleteable(entity).ExecuteCommandHasChangeAsync();
}
/// <summary>
/// 根据表达式删除
/// </summary>
/// <param name="whereExpression"></param>
/// <returns></returns>
public async Task<bool> Delete(Expression<Func<TEntity, bool>> whereExpression)
{
return await _db.Deleteable<TEntity>().Where(whereExpression).ExecuteCommandHasChangeAsync();
}
/// <summary>
/// 删除指定ID的数据
/// </summary>
/// <param name="id">主键ID</param>
/// <returns></returns>
public async Task<bool> DeleteById(object id)
{
//var i = await Task.Run(() => _db.Deleteable<TEntity>(id).ExecuteCommand());
//return i > 0;
return await _db.Deleteable<TEntity>(id).ExecuteCommandHasChangeAsync();
}
/// <summary>
/// 删除指定ID集合的数据(批量删除)
/// </summary>
/// <param name="ids">主键ID集合</param>
/// <returns></returns>
public async Task<bool> DeleteByIds(object[] ids)
{
//var i = await Task.Run(() => _db.Deleteable<TEntity>().In(ids).ExecuteCommand());
//return i > 0;
return await _db.Deleteable<TEntity>().In(ids).ExecuteCommandHasChangeAsync();
}
/// <summary>
/// 功能描述:查询所有数据
///
/// </summary>
/// <returns>数据列表</returns>
public async Task<List<TEntity>> Query()
{
return await _db.Queryable<TEntity>().ToListAsync();
}
/// <summary>
/// 功能描述:查询数据列表
///
/// </summary>
/// <param name="strWhere">条件</param>
/// <returns>数据列表</returns>
public async Task<List<TEntity>> Query(string strWhere)
{
//return await Task.Run(() => _db.Queryable<TEntity>().WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToList());
return await _db.Queryable<TEntity>().WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToListAsync();
}
public List<TEntity> Query1(Expression<Func<TEntity, bool>> whereExpression)
{
try
{
return _db.Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).ToList();
}
catch (Exception ex)
{
//LogRecordService.LogAdd(new Model.Models.Base_LogRecord(Model.Enums.LogType.查询记录, null, "查询失败:" + ex.Message, DateTime.Now));
return null;
}
}
/// <summary>
/// 功能描述:查询数据列表
///
/// </summary>
/// <param name="whereExpression">whereExpression</param>
/// <returns>数据列表</returns>
public async Task<List<TEntity>> Query(Expression<Func<TEntity, bool>> whereExpression)
{
try
{
return await _db.Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).ToListAsync();
}
catch (Exception ex)
{
//LogRecordService.LogAdd(new Model.Models.Base_LogRecord(Model.Enums.LogType.查询记录, null, "查询失败:" + ex.Message, DateTime.Now));
return null;
}
}
/// <summary>
/// 功能描述:查询一个列表
///
/// </summary>
/// <param name="whereExpression">条件表达式</param>
/// <param name="strOrderByFileds">排序字段如name asc,age desc</param>
/// <returns>数据列表</returns>
public async Task<List<TEntity>> Query(Expression<Func<TEntity, bool>> whereExpression, string strOrderByFileds)
{
//return await Task.Run(() => _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).ToList());
return await _db.Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).OrderByIF(strOrderByFileds != null, strOrderByFileds).ToListAsync();
}
/// <summary>
/// 功能描述:查询一个列表
/// </summary>
/// <param name="whereExpression"></param>
/// <param name="orderByExpression"></param>
/// <param name="isAsc"></param>
/// <returns></returns>
public async Task<List<TEntity>> Query(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, object>> orderByExpression, bool isAsc = true)
{
//return await Task.Run(() => _db.Queryable<TEntity>().OrderByIF(orderByExpression != null, orderByExpression, isAsc ? OrderByType.Asc : OrderByType.Desc).WhereIF(whereExpression != null, whereExpression).ToList());
try
{
return await _db.Queryable<TEntity>().OrderByIF(orderByExpression != null, orderByExpression, isAsc ? OrderByType.Asc : OrderByType.Desc).WhereIF(whereExpression != null, whereExpression).ToListAsync();
}
catch (Exception ex)
{
//LogHelper.Error(ex.Message);
return null;
}
}
/// <summary>
/// 排序取第一条
/// </summary>
/// <param name="whereExpression"></param>
/// <param name="orderByExpression"></param>
/// <param name="isAsc"></param>
/// <returns></returns>
public async Task<TEntity> QueryFirst(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, object>> orderByExpression, bool isAsc = true)
{
try
{
TEntity info = await _db.Queryable<TEntity>().OrderByIF(orderByExpression != null, orderByExpression, isAsc ? OrderByType.Asc : OrderByType.Desc).WhereIF(whereExpression != null, whereExpression).FirstAsync();
//if (info != null)
//LogRecordService.LogAdd(new Model.Models.Base_LogRecord(Model.Enums.LogType.查询记录, "查询成功:" + JsonChange.ModeToJson(info), null, DateTime.Now));
return info;
}
catch (Exception ex)
{
//LogRecordService.LogAdd(new Model.Models.Base_LogRecord(Model.Enums.LogType.查询记录, null, "查询失败:" + ex.Message, DateTime.Now));
return null;
}
}
/// <summary>
/// 功能描述:查询一个列表
///
/// </summary>
/// <param name="strWhere">条件</param>
/// <param name="strOrderByFileds">排序字段如name asc,age desc</param>
/// <returns>数据列表</returns>
public async Task<List<TEntity>> Query(string strWhere, string strOrderByFileds)
{
//return await Task.Run(() => _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToList());
return await _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToListAsync();
}
/// <summary>
/// 功能描述:查询前N条数据
///
/// </summary>
/// <param name="whereExpression">条件表达式</param>
/// <param name="intTop">前N条</param>
/// <param name="strOrderByFileds">排序字段如name asc,age desc</param>
/// <returns>数据列表</returns>
public async Task<List<TEntity>> Query(
Expression<Func<TEntity, bool>> whereExpression,
int intTop,
string strOrderByFileds)
{
//return await Task.Run(() => _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).Take(intTop).ToList());
return await _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).Take(intTop).ToListAsync();
}
/// <summary>
/// 功能描述:查询前N条数据
///
/// </summary>
/// <param name="strWhere">条件</param>
/// <param name="intTop">前N条</param>
/// <param name="strOrderByFileds">排序字段如name asc,age desc</param>
/// <returns>数据列表</returns>
public async Task<List<TEntity>> Query(
string strWhere,
int intTop,
string strOrderByFileds)
{
//return await Task.Run(() => _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).Take(intTop).ToList());
return await _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).Take(intTop).ToListAsync();
}
/// <summary>
/// 功能描述:分页查询
///
/// </summary>
/// <param name="whereExpression">条件表达式</param>
/// <param name="intPageIndex">页码下标0</param>
/// <param name="intPageSize">页大小</param>
/// <param name="intTotalCount">数据总量</param>
/// <param name="strOrderByFileds">排序字段如name asc,age desc</param>
/// <returns>数据列表</returns>
public async Task<List<TEntity>> Query(
Expression<Func<TEntity, bool>> whereExpression,
int intPageIndex,
int intPageSize,
string strOrderByFileds)
{
//return await Task.Run(() => _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).ToPageList(intPageIndex, intPageSize));
return await _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).ToPageListAsync(intPageIndex, intPageSize);
}
/// <summary>
/// 功能描述:分页查询
///
/// </summary>
/// <param name="strWhere">条件</param>
/// <param name="intPageIndex">页码下标0</param>
/// <param name="intPageSize">页大小</param>
/// <param name="intTotalCount">数据总量</param>
/// <param name="strOrderByFileds">排序字段如name asc,age desc</param>
/// <returns>数据列表</returns>
public async Task<List<TEntity>> Query(
string strWhere,
int intPageIndex,
int intPageSize,
string strOrderByFileds)
{
//return await Task.Run(() => _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToPageList(intPageIndex, intPageSize));
return await _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToPageListAsync(intPageIndex, intPageSize);
}
/// <summary>
///查询-多表查询
/// </summary>
/// <typeparam name="T">实体1</typeparam>
/// <typeparam name="T2">实体2</typeparam>
/// <typeparam name="T3">实体3</typeparam>
/// <typeparam name="T4">实体4</typeparam>
/// <typeparam name="T5">实体5</typeparam>
/// <typeparam name="TResult">返回对象</typeparam>
/// <param name="joinExpression">关联表达式 (join1,join2) => new object[] {JoinType.Left,join1.UserNo==join2.UserNo}</param>
/// <param name="selectExpression">返回表达式 (s1, s2) => new { Id =s1.UserNo, Id1 = s2.UserNo}</param>
/// <param name="whereLambda">查询表达式 (w1, w2) =>w1.UserNo == "")</param>
/// <returns>值</returns>
public async Task<List<TResult>> QueryMuch<T, T2, T3, T4, T5, TResult>(
Expression<Func<T, T2, T3, T4, T5, object[]>> joinExpression,
Expression<Func<T, T2, T3, T4, T5, TResult>> selectExpression,
Expression<Func<TResult, bool>> whereLambda = null) where T : class, new()
{
if (whereLambda == null)
{
return await _db.Queryable(joinExpression).Select(selectExpression).ToListAsync();
}
return await _db.Queryable(joinExpression).Select(selectExpression).MergeTable().Where(whereLambda).ToListAsync();
}
/// <summary>
///查询-多表查询
/// </summary>
/// <typeparam name="T">实体1</typeparam>
/// <typeparam name="T2">实体2</typeparam>
/// <typeparam name="T3">实体3</typeparam>
/// <typeparam name="T4">实体4</typeparam>
/// <typeparam name="TResult">返回对象</typeparam>
/// <param name="joinExpression">关联表达式 (join1,join2) => new object[] {JoinType.Left,join1.UserNo==join2.UserNo}</param>
/// <param name="selectExpression">返回表达式 (s1, s2) => new { Id =s1.UserNo, Id1 = s2.UserNo}</param>
/// <param name="whereLambda">查询表达式 (w1, w2) =>w1.UserNo == "")</param>
/// <returns>值</returns>
public async Task<List<TResult>> QueryMuch<T, T2, T3, T4, TResult>(
Expression<Func<T, T2, T3, T4, object[]>> joinExpression,
Expression<Func<T, T2, T3, T4, TResult>> selectExpression,
Expression<Func<TResult, bool>> whereLambda = null) where T : class, new()
{
if (whereLambda == null)
{
return await _db.Queryable(joinExpression).Select(selectExpression).ToListAsync();
}
return await _db.Queryable(joinExpression).Select(selectExpression).MergeTable().Where(whereLambda).ToListAsync();
}
/// <summary>
///查询-多表查询
/// </summary>
/// <typeparam name="T">实体1</typeparam>
/// <typeparam name="T2">实体2</typeparam>
/// <typeparam name="T3">实体3</typeparam>
/// <typeparam name="TResult">返回对象</typeparam>
/// <param name="joinExpression">关联表达式 (join1,join2) => new object[] {JoinType.Left,join1.UserNo==join2.UserNo}</param>
/// <param name="selectExpression">返回表达式 (s1, s2) => new { Id =s1.UserNo, Id1 = s2.UserNo}</param>
/// <param name="whereLambda">查询表达式 (w1, w2) =>w1.UserNo == "")</param>
/// <returns>值</returns>
public async Task<List<TResult>> QueryMuch<T, T2, T3, TResult>(
Expression<Func<T, T2, T3, object[]>> joinExpression,
Expression<Func<T, T2, T3, TResult>> selectExpression,
Expression<Func<TResult, bool>> whereLambda = null) where T : class, new()
{
if (whereLambda == null)
{
return await _db.Queryable(joinExpression).Select(selectExpression).ToListAsync();
}
return await _db.Queryable(joinExpression).Select(selectExpression).MergeTable().Where(whereLambda).ToListAsync();
}
/// <summary>
///查询-多表查询
/// </summary>
/// <typeparam name="T">实体1</typeparam>
/// <typeparam name="T2">实体2</typeparam>
/// <typeparam name="TResult">返回对象</typeparam>
/// <param name="joinExpression">关联表达式 (join1,join2) => new object[] {JoinType.Left,join1.UserNo==join2.UserNo}</param>
/// <param name="selectExpression">返回表达式 (s1, s2) => new { Id =s1.UserNo, Id1 = s2.UserNo}</param>
/// <param name="whereLambda">查询表达式 (w1, w2) =>w1.UserNo == "")</param>
/// <returns>值</returns>
public async Task<List<TResult>> QueryMuch<T, T2, TResult>(
Expression<Func<T, T2, object[]>> joinExpression,
Expression<Func<T, T2, TResult>> selectExpression,
Expression<Func<TResult, bool>> whereLambda = null) where T : class, new()
{
if (whereLambda == null)
{
return await _db.Queryable(joinExpression).Select(selectExpression).ToListAsync();
}
return await _db.Queryable(joinExpression).Select(selectExpression).MergeTable().Where(whereLambda).ToListAsync();
}
/// <summary>
/// 存储过程
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="parameters"></param>
/// <returns></returns>
public async Task<List<T>> QueryByProc<T>(string proc, List<SugarParameter> parameters) where T : class, new()
{
//var nameP = new SugarParameter("@name", "张三");
//var ageP = new SugarParameter("@age", null, true);//isOutput=true
//var ddd = new List<SugarParameter>();
return await _db.Ado.UseStoredProcedure().SqlQueryAsync<T>(proc, parameters);
}
public async Task<Tuple<List<T>, List<T2>>> QueryByProc<T, T2>(string proc, List<SugarParameter> parameters) where T : class, new()
{
return await _db.Ado.UseStoredProcedure().SqlQueryAsync<T, T2>(proc, parameters);
}
/// <summary>
/// sql语句
/// </summary>
public async Task<List<T>> QueryBySql<T>(string sql, List<SugarParameter> parameters) where T : class, new()
{
return await _db.Ado.SqlQueryAsync<T>(sql, parameters);
}
}
}

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("AucmaEms.SqlSugar")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AucmaEms.SqlSugar")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("2060415b-adf1-4d90-bbff-ce3d43ec03e5")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -0,0 +1,153 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="System.Configuration.IgnoreSectionHandler"/>
</configSections>
<appSettings>
</appSettings>
<log4net>
<!--错误日志类-->
<logger name="logerror">
<level value="ALL" />
<appender-ref ref="ErrorAppender" />
</logger>
<!--信息日志类-->
<logger name="loginfo">
<level value="ALL" />
<appender-ref ref="InfoAppender" />
</logger>
<!--PLC日志类-->
<logger name="plclog">
<level value="ALL" />
<appender-ref ref="PlcAppender" />
</logger>
<!--RFID日志类-->
<logger name="rfidlog">
<level value="ALL" />
<appender-ref ref="RfidAppender" />
</logger>
<!--RFID日志类-->
<logger name="viewlog">
<level value="ALL" />
<appender-ref ref="ViewAppender" />
</logger>
<!--Sql日志类-->
<logger name="sqllog">
<level value="ALL" />
<appender-ref ref="SqlAppender" />
</logger>
<!--信号量日志类-->
<logger name="semaphorelog">
<level value="ALL" />
<appender-ref ref="SemaphoreAppender" />
</logger>
<!--错误日志附加介质-->
<appender name="ErrorAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxSizeRollBackups" value="100" />
<param name="MaxFileSize" value="10240" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"LogError.html"'/>
<param name="RollingStyle" value="Date" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;HR COLOR=red&gt;%n异常时间%d [%t] &lt;BR&gt;%n异常级别%-5p &lt;BR&gt;%n异 常 类:%c [%x] &lt;BR&gt;%n%m &lt;BR&gt;%n &lt;HR Size=1&gt;" />
</layout>
</appender>
<!--信息日志附加介质-->
<appender name="InfoAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"LogInfo.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
<!--PLC日志附加介质-->
<appender name="PlcAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"PlcLog.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
<!--Rfid日志附加介质-->
<appender name="RfidAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"RfidLog.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
<appender name="ViewAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"ViewLog.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
<appender name="SqlAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"SqlLog.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
<appender name="SemaphoreAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"SemaphoreLog.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
</log4net>
</configuration>

@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.5.2", FrameworkDisplayName = ".NET Framework 4.5.2")]

@ -0,0 +1,30 @@
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.SqlSugar\bin\Debug\log4net.config
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.SqlSugar\bin\Debug\AucmaEms.SqlSugar.dll
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.SqlSugar\bin\Debug\AucmaEms.SqlSugar.pdb
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.SqlSugar\bin\Debug\AucmaEms.Common.dll
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.SqlSugar\bin\Debug\AucmaEms.Entity.dll
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.SqlSugar\bin\Debug\Oracle.ManagedDataAccess.dll
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.SqlSugar\bin\Debug\SqlSugar.dll
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.SqlSugar\bin\Debug\log4net.dll
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.SqlSugar\bin\Debug\AucmaEms.Common.pdb
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.SqlSugar\bin\Debug\AucmaEms.Entity.pdb
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.SqlSugar\obj\Debug\AucmaEms.SqlSugar.csproj.AssemblyReference.cache
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.SqlSugar\obj\Debug\AucmaEms.SqlSugar.csproj.CoreCompileInputs.cache
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.SqlSugar\obj\Debug\AucmaEms.SqlSugar.csproj.CopyComplete
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.SqlSugar\obj\Debug\AucmaEms.SqlSugar.dll
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms.SqlSugar\obj\Debug\AucmaEms.SqlSugar.pdb
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.SqlSugar\bin\Debug\log4net.config
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.SqlSugar\bin\Debug\AucmaEms.SqlSugar.dll
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.SqlSugar\bin\Debug\AucmaEms.SqlSugar.pdb
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.SqlSugar\bin\Debug\AucmaEms.Common.dll
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.SqlSugar\bin\Debug\AucmaEms.Entity.dll
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.SqlSugar\bin\Debug\Oracle.ManagedDataAccess.dll
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.SqlSugar\bin\Debug\SqlSugar.dll
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.SqlSugar\bin\Debug\log4net.dll
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.SqlSugar\bin\Debug\AucmaEms.Common.pdb
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.SqlSugar\bin\Debug\AucmaEms.Entity.pdb
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.SqlSugar\obj\Debug\AucmaEms.SqlSugar.csproj.AssemblyReference.cache
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.SqlSugar\obj\Debug\AucmaEms.SqlSugar.csproj.CoreCompileInputs.cache
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.SqlSugar\obj\Debug\AucmaEms.SqlSugar.csproj.CopyComplete
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.SqlSugar\obj\Debug\AucmaEms.SqlSugar.dll
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms.SqlSugar\obj\Debug\AucmaEms.SqlSugar.pdb

@ -0,0 +1,43 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32825.248
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AucmaEms", "AucmaEms\AucmaEms.csproj", "{CF26E4CC-6371-4F38-986F-C015CCD50DCC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AucmaEms.Common", "AucmaEms.Common\AucmaEms.Common.csproj", "{247C9F10-9DB6-4761-80E1-86D81018437A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AucmaEms.Entity", "AucmaEms.Entity\AucmaEms.Entity.csproj", "{86A58654-8FE5-44F0-B17D-5CCE78743C00}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AucmaEms.SqlSugar", "AucmaEms.SqlSugar\AucmaEms.SqlSugar.csproj", "{2060415B-ADF1-4D90-BBFF-CE3D43EC03E5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CF26E4CC-6371-4F38-986F-C015CCD50DCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CF26E4CC-6371-4F38-986F-C015CCD50DCC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CF26E4CC-6371-4F38-986F-C015CCD50DCC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CF26E4CC-6371-4F38-986F-C015CCD50DCC}.Release|Any CPU.Build.0 = Release|Any CPU
{247C9F10-9DB6-4761-80E1-86D81018437A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{247C9F10-9DB6-4761-80E1-86D81018437A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{247C9F10-9DB6-4761-80E1-86D81018437A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{247C9F10-9DB6-4761-80E1-86D81018437A}.Release|Any CPU.Build.0 = Release|Any CPU
{86A58654-8FE5-44F0-B17D-5CCE78743C00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{86A58654-8FE5-44F0-B17D-5CCE78743C00}.Debug|Any CPU.Build.0 = Debug|Any CPU
{86A58654-8FE5-44F0-B17D-5CCE78743C00}.Release|Any CPU.ActiveCfg = Release|Any CPU
{86A58654-8FE5-44F0-B17D-5CCE78743C00}.Release|Any CPU.Build.0 = Release|Any CPU
{2060415B-ADF1-4D90-BBFF-CE3D43EC03E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2060415B-ADF1-4D90-BBFF-CE3D43EC03E5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2060415B-ADF1-4D90-BBFF-CE3D43EC03E5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2060415B-ADF1-4D90-BBFF-CE3D43EC03E5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {10BAA9FC-007A-4B44-B38F-AB06AA947BE4}
EndGlobalSection
EndGlobal

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<appSettings>
<add key="ReadIntervel" value="15" />
<add key="listenIp" value="0.0.0.0" />
<add key="listenPort" value="502" />
<add key="connectStr" value="Data Source=10.100.71.119/ORCL;User ID=system;Password=aucma;Max Pool Size=512;Pooling=true" />
</appSettings>
</configuration>

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{CF26E4CC-6371-4F38-986F-C015CCD50DCC}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>AucmaEms</RootNamespace>
<AssemblyName>AucmaEms</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Oracle.ManagedDataAccess">
<HintPath>..\dll\Oracle.ManagedDataAccess.dll</HintPath>
</Reference>
<Reference Include="SqlSugar, Version=5.0.3.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\dll\SqlSugar.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="TouchSocket, Version=0.7.7.0, Culture=neutral, PublicKeyToken=aab106fd42dbd097, processorArchitecture=MSIL">
<HintPath>..\packages\TouchSocket.0.7.7\lib\net45\TouchSocket.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Business.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TcpServer.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AucmaEms.Common\AucmaEms.Common.csproj">
<Project>{247C9F10-9DB6-4761-80E1-86D81018437A}</Project>
<Name>AucmaEms.Common</Name>
</ProjectReference>
<ProjectReference Include="..\AucmaEms.Entity\AucmaEms.Entity.csproj">
<Project>{86A58654-8FE5-44F0-B17D-5CCE78743C00}</Project>
<Name>AucmaEms.Entity</Name>
</ProjectReference>
<ProjectReference Include="..\AucmaEms.SqlSugar\AucmaEms.SqlSugar.csproj">
<Project>{2060415B-ADF1-4D90-BBFF-CE3D43EC03E5}</Project>
<Name>AucmaEms.SqlSugar</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -0,0 +1,165 @@
using AucmaEms.Common;
using AucmaEms.Entity;
using AucmaEms.SqlSugar;
using AucmaEms.SqlSugar.Impl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace AucmaEms
{
internal class Business
{
private LogHelper logHelper = LogHelper.Instance;
private IBaseServices<BaseMonitorInfo> baseServices = new BaseServices<BaseMonitorInfo>();
private IBaseServices<ScadaEmsElectricLoss> electricLossServices = new BaseServices<ScadaEmsElectricLoss>();
private static readonly Lazy<Business> lazy = new Lazy<Business>(() => new Business());
public static Business Instance
{
get
{
return lazy.Value;
}
}
private Business() { }
public async Task<BaseMonitorInfo> monitorInfo(string address)
{
try
{
Expression<Func<BaseMonitorInfo, bool>> exp = s1 => true;
exp = exp.And(x => x.pMonitorId == "PDS" && address.Contains(x.networkAddress));
List<BaseMonitorInfo> info = await baseServices.Query(exp);
var result = info.Where(x => address.Contains(x.networkAddress)).FirstOrDefault();
return result;
}
catch (Exception ex)
{
logHelper.Error("monitorInfo异常", ex);
}
return null;
}
/// <summary>
/// 获取测控点列表
/// </summary>
/// <param name="p_monitorInfo"></param>
/// <returns></returns>
public async Task<List<BaseMonitorInfo>> monitorInfos(string p_monitorInfo)
{
try
{
Expression<Func<BaseMonitorInfo, bool>> exp = s1 => true;
exp = exp.And(x => x.pMonitorId == p_monitorInfo);
List<BaseMonitorInfo> info = await baseServices.Query(exp);
return info;
}
catch (Exception ex)
{
logHelper.Error("monitorInfos异常", ex);
}
return null;
}
public async void SaveDate(BaseMonitorInfo monitorInfo, ScadaEmsElectricLoss electricLoss)
{
electricLoss.zxyg = electricLoss.zxyg * monitorInfo.pt * monitorInfo.ct;
//添加数据过滤 Add by wenjy 2022-11-22
if (await zxyFiltration(electricLoss) && electricLoss.zxyg > 0)
{
if (await electricLossServices.Add(electricLoss) > 0)
{
logHelper.Info(monitorInfo.monitorName + "数据保存成功");
}
else
{
logHelper.Info(monitorInfo.monitorName + "数据保存失败");
}
}
}
/// <summary>
/// 正向有功过滤当采集数据与上次数据相差超过100时不进行存储
/// </summary>
/// <param name="electricLoss"></param>
/// <returns></returns>
private async Task<bool> zxyFiltration(ScadaEmsElectricLoss electricLoss)
{
try
{
Expression<Func<ScadaEmsElectricLoss, bool>> exp = s1 => true;
exp = exp.And(x => x.monitorId == electricLoss.monitorId);
Expression<Func<ScadaEmsElectricLoss, object>> order = s1 => s1.collectTime;
ScadaEmsElectricLoss emsElectricLoss = await electricLossServices.QueryFirst(exp, order, false);
logHelper.Info(String.Format("设备{0},上一数据:{1}", electricLoss.monitorId, JsonChange.ModeToJson(emsElectricLoss)));
if (emsElectricLoss != null)
{
var result = electricLoss.zxyg - emsElectricLoss.zxyg;
logHelper.Info(String.Format("设备{0},当前能耗:{1},上次采集能耗:{2},相差:{3}", electricLoss.monitorId, electricLoss.zxyg, emsElectricLoss.zxyg, result));
if (result < 100 && result >= 0)
{
return true;
}
else
{
return false;
}
}
else
{
return true;
}
}
catch (Exception ex)
{
logHelper.Error("正向有功过滤异常", ex);
return false;
}
}
public decimal byteToFloat(byte[] buffer, int number)
{
try
{
if (buffer.Length > 0)
{
//logHelper.Info("byteToFloat:" + StringChange.bytesToHexStr(buffer, buffer.Length));
var info = Convert.ToDecimal(int.Parse(StringChange.bytesToHexStr(buffer, buffer.Length), System.Globalization.NumberStyles.AllowHexSpecifier)) / number;
return info;
}
else
{
return 0;
}
}
catch (Exception ex)
{
logHelper.Error("字节转换异常byteToFloat", ex);
return 0;
}
}
/// <summary>
/// 指令封装
/// </summary>
/// <param name="buffer"></param>
/// <returns></returns>
public byte[] packageBuffer(byte[] buffer)
{
byte[] check_1 = CheckUtil.ToModbus(buffer);
byte[] result_1 = new byte[8];
Array.Copy(buffer, 0, result_1, 0, 6);
Array.Copy(check_1, 0, result_1, 6, 2);
return result_1;
}
}
}

@ -0,0 +1,271 @@
using AucmaEms.Common;
using AucmaEms.Entity;
using AucmaEms.SqlSugar;
using AucmaEms.SqlSugar.Impl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web.UI.WebControls;
using TouchSocket.Core.Config;
using TouchSocket.Sockets;
using TcpClient = TouchSocket.Sockets.TcpClient;
namespace AucmaEms
{
internal class Program
{
private static TcpServer server = TcpServer.Instance;
private static LogHelper logHelper = LogHelper.Instance;
private static AppConfig appConfig = AppConfig.Instance;
static void Main(string[] args)
{
printMessage("服务启动");
Thread.Sleep(3000);
while (true)
{
CollectEmsData_2Q();
Thread.Sleep(1000 * 60 * appConfig.ReadIntervel);
}
}
/// <summary>
/// 一期采集读取现场电表数据
/// </summary>
static async void CollectEmsData_1Q()
{
Business business = Business.Instance;
List<BaseMonitorInfo> monitorInfos = await business.monitorInfos("PDS");
if (monitorInfos == null) return;
int monitorInfosLength = monitorInfos.Count;
try
{
for (int i = 0; i < monitorInfosLength; i++)
{
BaseMonitorInfo info = monitorInfos[i];
if (info != null)
{
TcpClient m_tcpClient = new TcpClient();
try
{
string title = info.monitorName + DateTime.Now.ToString("MM-dd HH:mm:ss");
Console.WriteLine("-------------------------" + title.PadRight(25,'-') + "-----------------------");
//声明配置
TouchSocketConfig config = new TouchSocketConfig();
config.SetRemoteIPHost(new IPHost(info.networkAddress+":502")).UsePlugin().SetBufferLength(1024 * 10);
//载入配置
m_tcpClient.Setup(config);
m_tcpClient.Connect();
ScadaEmsElectricLoss scadaEmsElectric = new ScadaEmsElectricLoss();
byte[] zxyg_Bytes = business.packageBuffer(new byte[]{ Convert.ToByte(info.monitorId), 0x03, 0x04, 0x4B, 0x00, 0x02 });
logHelper.SemaphoreLog(String.Format("{0}{1}发送获取正向有功指令:{2}",info.monitorName,info.networkAddress,StringChange.bytesToHexStr(zxyg_Bytes, zxyg_Bytes.Length)));
byte[] zxyg_buffer = m_tcpClient.GetWaitingClient(WaitingOptions.AllAdapter).SendThenReturn(zxyg_Bytes, 2000);
logHelper.SemaphoreLog(String.Format("{0}{1}接收正向有功指令:{2}", info.monitorName, info.networkAddress, StringChange.bytesToHexStr(zxyg_buffer, zxyg_buffer.Length)));
scadaEmsElectric.zxyg = business.byteToFloat(zxyg_buffer.Skip(3).Take(4).ToArray(), 100);
printMessage(String.Format("{0}正向有功:{1}", info.monitorName, scadaEmsElectric.zxyg));
//取三项电压
byte[] v_Byte = business.packageBuffer(new byte[] { Convert.ToByte(info.monitorId), 0x03, 0x03, 0xE7, 0x00, 0x06 });
logHelper.SemaphoreLog(String.Format("{0}{1}发送获取三相电压指令:{2}", info.monitorName, info.networkAddress, StringChange.bytesToHexStr(v_Byte, v_Byte.Length)));
byte[] v_Buffer = m_tcpClient.GetWaitingClient(WaitingOptions.AllAdapter).SendThenReturn(v_Byte, 2000);
logHelper.SemaphoreLog(String.Format("{0}{1}接收三相电压指令:{2}", info.monitorName, info.networkAddress, StringChange.bytesToHexStr(v_Buffer, v_Buffer.Length)));
scadaEmsElectric.va = business.byteToFloat(v_Buffer.Skip(3).Take(4).ToArray(), 1000);
scadaEmsElectric.vb = business.byteToFloat(v_Buffer.Skip(7).Take(4).ToArray(), 1000);
scadaEmsElectric.vc = business.byteToFloat(v_Buffer.Skip(11).Take(4).ToArray(), 1000);
printMessage(String.Format("{0}A项电压{1}B项电压{2}C项电压{3}", info.monitorName, scadaEmsElectric.va, scadaEmsElectric.vb, scadaEmsElectric.vc));
//取三项电流
byte[] i_Byte = business.packageBuffer(new byte[] { Convert.ToByte(info.monitorId), 0x03, 0x03, 0xF3, 0x00, 0x06 });
logHelper.SemaphoreLog(String.Format("{0}{1}发送获取三相电流指令:{2}", info.monitorName, info.networkAddress, StringChange.bytesToHexStr(i_Byte, i_Byte.Length)));
byte[] i_Buffer = m_tcpClient.GetWaitingClient(WaitingOptions.AllAdapter).SendThenReturn(i_Byte, 2000);
logHelper.SemaphoreLog(String.Format("{0}{1}接收三相电流指令:{2}", info.monitorName, info.networkAddress, StringChange.bytesToHexStr(i_Buffer, i_Buffer.Length)));
scadaEmsElectric.ia = business.byteToFloat(i_Buffer.Skip(3).Take(4).ToArray(), 1000);
scadaEmsElectric.ib = business.byteToFloat(i_Buffer.Skip(7).Take(4).ToArray(), 1000);
scadaEmsElectric.ic = business.byteToFloat(i_Buffer.Skip(11).Take(4).ToArray(), 1000);
printMessage(String.Format("{0}A项电流{1}B项电流{2}C项电流{3}", info.monitorName, scadaEmsElectric.ia, scadaEmsElectric.ib, scadaEmsElectric.ic));
scadaEmsElectric.collectTime = DateTime.Now;
scadaEmsElectric.monitorId = info.monitorId;
scadaEmsElectric.uuid = System.Guid.NewGuid().ToString("N");
business.SaveDate(info, scadaEmsElectric);
//断开连接
if (m_tcpClient.Online)
{
m_tcpClient.Shutdown(System.Net.Sockets.SocketShutdown.Both);
m_tcpClient.Close();
m_tcpClient.SafeDispose();
}
}
catch (TimeoutException)
{
printMessage(info.monitorName+"等待超时");
if (m_tcpClient.Online)
{
m_tcpClient.Shutdown(System.Net.Sockets.SocketShutdown.Both);
m_tcpClient.Close();
m_tcpClient.SafeDispose();
}
}
}
}
}
catch (Exception ex)
{
logHelper.Error("数据采集异常", ex);
}
}
/// <summary>
/// 二期采集读取现场电表数据
/// </summary>
static async void CollectEmsData_2Q()
{
Business business = Business.Instance;
List<BaseMonitorInfo> monitorInfos = await business.monitorInfos("2QPDG");
if (monitorInfos == null) return;
int monitorInfosLength = monitorInfos.Count;
try
{
for (int i = 0; i < monitorInfosLength; i++)
{
BaseMonitorInfo info = monitorInfos[i];
if (info != null)
{
string monitorId = info.monitorId.Replace("2Q_", "");
TcpClient m_tcpClient = new TcpClient();
try
{
string title = info.monitorName + DateTime.Now.ToString("MM-dd HH:mm:ss");
Console.WriteLine("-------------------------" + title.PadRight(25, '-') + "-----------------------");
//声明配置
TouchSocketConfig config = new TouchSocketConfig();
config.SetRemoteIPHost(new IPHost(info.networkAddress + ":502")).UsePlugin().SetBufferLength(1024 * 10);
//载入配置
m_tcpClient.Setup(config);
m_tcpClient.Connect();
ScadaEmsElectricLoss scadaEmsElectric = new ScadaEmsElectricLoss();
byte[] zxyg_Bytes = business.packageBuffer(new byte[] { Convert.ToByte(monitorId), 0x03, 0x04, 0x4B, 0x00, 0x02 });
logHelper.SemaphoreLog(String.Format("{0}{1}发送获取正向有功指令:{2}", info.monitorName, info.networkAddress, StringChange.bytesToHexStr(zxyg_Bytes, zxyg_Bytes.Length)));
byte[] zxyg_buffer = m_tcpClient.GetWaitingClient(WaitingOptions.AllAdapter).SendThenReturn(zxyg_Bytes, 2000);
logHelper.SemaphoreLog(String.Format("{0}{1}接收正向有功指令:{2}", info.monitorName, info.networkAddress, StringChange.bytesToHexStr(zxyg_buffer, zxyg_buffer.Length)));
scadaEmsElectric.zxyg = business.byteToFloat(zxyg_buffer.Skip(3).Take(4).ToArray(), 100);
printMessage(String.Format("{0}正向有功:{1}", info.monitorName, scadaEmsElectric.zxyg));
//取三项电压
byte[] v_Byte = business.packageBuffer(new byte[] { Convert.ToByte(monitorId), 0x03, 0x03, 0xE7, 0x00, 0x06 });
logHelper.SemaphoreLog(String.Format("{0}{1}发送获取三相电压指令:{2}", info.monitorName, info.networkAddress, StringChange.bytesToHexStr(v_Byte, v_Byte.Length)));
byte[] v_Buffer = m_tcpClient.GetWaitingClient(WaitingOptions.AllAdapter).SendThenReturn(v_Byte, 2000);
logHelper.SemaphoreLog(String.Format("{0}{1}接收三相电压指令:{2}", info.monitorName, info.networkAddress, StringChange.bytesToHexStr(v_Buffer, v_Buffer.Length)));
scadaEmsElectric.va = business.byteToFloat(v_Buffer.Skip(3).Take(4).ToArray(), 1000);
scadaEmsElectric.vb = business.byteToFloat(v_Buffer.Skip(7).Take(4).ToArray(), 1000);
scadaEmsElectric.vc = business.byteToFloat(v_Buffer.Skip(11).Take(4).ToArray(), 1000);
printMessage(String.Format("{0}A项电压{1}B项电压{2}C项电压{3}", info.monitorName, scadaEmsElectric.va, scadaEmsElectric.vb, scadaEmsElectric.vc));
//取三项电流
byte[] i_Byte = business.packageBuffer(new byte[] { Convert.ToByte(monitorId), 0x03, 0x03, 0xF3, 0x00, 0x06 });
logHelper.SemaphoreLog(String.Format("{0}{1}发送获取三相电流指令:{2}", info.monitorName, info.networkAddress, StringChange.bytesToHexStr(i_Byte, i_Byte.Length)));
byte[] i_Buffer = m_tcpClient.GetWaitingClient(WaitingOptions.AllAdapter).SendThenReturn(i_Byte, 2000);
logHelper.SemaphoreLog(String.Format("{0}{1}接收三相电流指令:{2}", info.monitorName, info.networkAddress, StringChange.bytesToHexStr(i_Buffer, i_Buffer.Length)));
scadaEmsElectric.ia = business.byteToFloat(i_Buffer.Skip(3).Take(4).ToArray(), 1000);
scadaEmsElectric.ib = business.byteToFloat(i_Buffer.Skip(7).Take(4).ToArray(), 1000);
scadaEmsElectric.ic = business.byteToFloat(i_Buffer.Skip(11).Take(4).ToArray(), 1000);
printMessage(String.Format("{0}A项电流{1}B项电流{2}C项电流{3}", info.monitorName, scadaEmsElectric.ia, scadaEmsElectric.ib, scadaEmsElectric.ic));
scadaEmsElectric.collectTime = DateTime.Now;
scadaEmsElectric.monitorId = info.monitorId;
scadaEmsElectric.uuid = System.Guid.NewGuid().ToString("N");
business.SaveDate(info, scadaEmsElectric);
//断开连接
if (m_tcpClient.Online)
{
m_tcpClient.Shutdown(System.Net.Sockets.SocketShutdown.Both);
m_tcpClient.Close();
m_tcpClient.SafeDispose();
}
}
catch (TimeoutException)
{
printMessage(info.monitorName + "等待超时");
if (m_tcpClient.Online)
{
m_tcpClient.Shutdown(System.Net.Sockets.SocketShutdown.Both);
m_tcpClient.Close();
m_tcpClient.SafeDispose();
}
}
}
}
}
catch (Exception ex)
{
logHelper.Error("数据采集异常", ex);
}
}
private static void printMessage(string message)
{
Console.WriteLine(message);
logHelper.Info(message);
}
}
}

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("AucmaEms")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AucmaEms")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("cf26e4cc-6371-4f38-986f-c015ccd50dcc")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -0,0 +1,153 @@
using AucmaEms.Common;
using AucmaEms.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI.WebControls;
using TouchSocket.Core;
using TouchSocket.Core.ByteManager;
using TouchSocket.Core.Config;
using TouchSocket.Core.Dependency;
using TouchSocket.Core.Log;
using TouchSocket.Sockets;
namespace AucmaEms
{
internal sealed class TcpServer
{
private LogHelper logHelper = LogHelper.Instance;
private AppConfig appConfig = AppConfig.Instance;
private TcpService m_service = new TcpService();
public List<string> clientList = new List<string>();
private static readonly Lazy<TcpServer> lazy = new Lazy<TcpServer>(() => new TcpServer());
public static TcpServer Instance
{
get
{
return lazy.Value;
}
}
private TcpServer()
{
m_service.Connecting = (client, e) =>
{
e.ID = $"{client.IP}:{client.Port}";
};//有客户端正在连接
m_service.Connected = this.M_service_Connected;//有客户端连接
m_service.Disconnected = this.M_service_Disconnected; ;//有客户端断开连接
m_service.Received = this.Service_Received;
}
public void Init()
{
string listenAddress = String.Format("{0}:{1}", appConfig.listenIp, appConfig.listenPort);
m_service.Setup(new TouchSocketConfig()//载入配置
.SetListenIPHosts(new IPHost[] { new IPHost(listenAddress), new IPHost(7790) })//同时监听两个地址
.SetMaxCount(10000)
.SetThreadCount(10)
.ConfigureContainer(a =>
{
a.SetSingletonLogger(new LoggerGroup(new EasyLogger(this.ShowMsg), new FileLogger()));
}))
.Start();//启动
m_service.Logger.Info("服务器成功启动");
}
/// <summary>
/// 客户端接入
/// </summary>
/// <param name="client"></param>
/// <param name="e"></param>
private void M_service_Connected(SocketClient client, TouchSocketEventArgs e)
{
try
{
clientList.Add(client.ID);
ShowMsg($"客户端{client.ID}接入成功");
}catch(Exception ex)
{
logHelper.Error("M_service_Connected异常", ex);
}
}
/// <summary>
/// 客户端断开
/// </summary>
/// <param name="client"></param>
/// <param name="e"></param>
private void M_service_Disconnected(SocketClient client, ClientDisconnectedEventArgs e)
{
try
{
clientList.Remove(client.ID);
ShowMsg($"客户端{client.ID}断开");
}
catch(Exception ex)
{
logHelper.Error("M_service_Disconnected异常", ex);
}
}
/// <summary>
/// 接收客户端信息
/// </summary>
/// <param name="client"></param>
/// <param name="byteBlock"></param>
/// <param name="requestInfo"></param>
private void Service_Received(SocketClient client, ByteBlock byteBlock, IRequestInfo requestInfo)
{
client.Logger.Info($"从客户端id={client.ID}ip={client.IP}port={client.Port}收到消息:{Encoding.UTF8.GetString(byteBlock.ToArray())}");//utf8解码。
}
/// <summary>
/// 发送并返回数据
/// </summary>
/// <param name="clientId"></param>
/// <param name="buffer"></param>
/// <returns></returns>
public byte[] SendThenReturn(string clientId, byte[] buffer)
{
//先找到与远程TcpClient对应的SocketClient
if (this.m_service.TryGetSocketClient(clientId, out SocketClient client))
{
try
{
//然后调用GetWaitingClient获取到IWaitingClient的对象。该对象会复用。
byte[] returnData = client.GetWaitingClient(WaitingOptions.AllAdapter).SendThenReturn(buffer,5000);
this.m_service.Logger.Info($"收到回应消息:{Encoding.UTF8.GetString(returnData)}");
return returnData;
}
catch (TimeoutException)
{
this.m_service.Logger.Error("等待超时");
}
catch (Exception ex)
{
this.m_service.Logger.Exception(ex);
}
}
else
{
this.m_service.Logger.Warning("客户端不存在");
}
return null;
}
private void ShowMsg(string msg)
{
Console.WriteLine(msg);
}
}
}

Binary file not shown.

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<appSettings>
<add key="ReadIntervel" value="15" />
<add key="listenIp" value="0.0.0.0" />
<add key="listenPort" value="502" />
<add key="connectStr" value="Data Source=10.100.71.119/ORCL;User ID=system;Password=aucma;Max Pool Size=512;Pooling=true" />
</appSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.122.1.0" newVersion="4.122.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

@ -0,0 +1,153 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="System.Configuration.IgnoreSectionHandler"/>
</configSections>
<appSettings>
</appSettings>
<log4net>
<!--错误日志类-->
<logger name="logerror">
<level value="ALL" />
<appender-ref ref="ErrorAppender" />
</logger>
<!--信息日志类-->
<logger name="loginfo">
<level value="ALL" />
<appender-ref ref="InfoAppender" />
</logger>
<!--PLC日志类-->
<logger name="plclog">
<level value="ALL" />
<appender-ref ref="PlcAppender" />
</logger>
<!--RFID日志类-->
<logger name="rfidlog">
<level value="ALL" />
<appender-ref ref="RfidAppender" />
</logger>
<!--RFID日志类-->
<logger name="viewlog">
<level value="ALL" />
<appender-ref ref="ViewAppender" />
</logger>
<!--Sql日志类-->
<logger name="sqllog">
<level value="ALL" />
<appender-ref ref="SqlAppender" />
</logger>
<!--信号量日志类-->
<logger name="semaphorelog">
<level value="ALL" />
<appender-ref ref="SemaphoreAppender" />
</logger>
<!--错误日志附加介质-->
<appender name="ErrorAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxSizeRollBackups" value="100" />
<param name="MaxFileSize" value="10240" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"LogError.html"'/>
<param name="RollingStyle" value="Date" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;HR COLOR=red&gt;%n异常时间%d [%t] &lt;BR&gt;%n异常级别%-5p &lt;BR&gt;%n异 常 类:%c [%x] &lt;BR&gt;%n%m &lt;BR&gt;%n &lt;HR Size=1&gt;" />
</layout>
</appender>
<!--信息日志附加介质-->
<appender name="InfoAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"LogInfo.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
<!--PLC日志附加介质-->
<appender name="PlcAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"PlcLog.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
<!--Rfid日志附加介质-->
<appender name="RfidAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"RfidLog.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
<appender name="ViewAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"ViewLog.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
<appender name="SqlAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"SqlLog.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
<appender name="SemaphoreAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Log\" />
<param name="AppendToFile" value="true" />
<param name="MaxFileSize" value="10240" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name="DatePattern" value='yyyy-MM-dd/"SemaphoreLog.txt"' />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="&lt;--------------&gt;%n日志时间%d [%t] %n日志级别%-5p %n日志内容%m %n " />
</layout>
</appender>
</log4net>
</configuration>

Binary file not shown.

@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.5.2", FrameworkDisplayName = ".NET Framework 4.5.2")]

@ -0,0 +1 @@
60757ad477b1ba4d40af4eb5292a9729685178cb

@ -0,0 +1,44 @@
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms\bin\Debug\log4net.config
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms\bin\Debug\AucmaEms.exe.config
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms\bin\Debug\AucmaEms.exe
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms\bin\Debug\AucmaEms.pdb
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms\bin\Debug\AucmaEms.Common.dll
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms\bin\Debug\AucmaEms.Entity.dll
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms\bin\Debug\AucmaEms.SqlSugar.dll
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms\bin\Debug\Oracle.ManagedDataAccess.dll
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms\bin\Debug\SqlSugar.dll
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms\bin\Debug\TouchSocket.dll
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms\bin\Debug\log4net.dll
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms\bin\Debug\AucmaEms.Common.pdb
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms\bin\Debug\AucmaEms.Entity.pdb
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms\bin\Debug\AucmaEms.SqlSugar.pdb
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms\bin\Debug\TouchSocket.xml
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms\obj\Debug\AucmaEms.csproj.AssemblyReference.cache
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms\obj\Debug\AucmaEms.csproj.SuggestedBindingRedirects.cache
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms\obj\Debug\AucmaEms.exe.config
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms\obj\Debug\AucmaEms.csproj.CoreCompileInputs.cache
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms\obj\Debug\AucmaEms.csproj.CopyComplete
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms\obj\Debug\AucmaEms.exe
E:\桌面\澳柯玛代码\电表数据测试\AucmaEms\AucmaEms\obj\Debug\AucmaEms.pdb
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms\bin\Debug\log4net.config
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms\bin\Debug\AucmaEms.exe.config
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms\bin\Debug\AucmaEms.exe
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms\bin\Debug\AucmaEms.pdb
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms\bin\Debug\AucmaEms.Common.dll
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms\bin\Debug\AucmaEms.Entity.dll
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms\bin\Debug\AucmaEms.SqlSugar.dll
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms\bin\Debug\Oracle.ManagedDataAccess.dll
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms\bin\Debug\SqlSugar.dll
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms\bin\Debug\TouchSocket.dll
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms\bin\Debug\log4net.dll
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms\bin\Debug\AucmaEms.Common.pdb
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms\bin\Debug\AucmaEms.Entity.pdb
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms\bin\Debug\AucmaEms.SqlSugar.pdb
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms\bin\Debug\TouchSocket.xml
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms\obj\Debug\AucmaEms.csproj.AssemblyReference.cache
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms\obj\Debug\AucmaEms.csproj.SuggestedBindingRedirects.cache
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms\obj\Debug\AucmaEms.exe.config
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms\obj\Debug\AucmaEms.csproj.CoreCompileInputs.cache
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms\obj\Debug\AucmaEms.csproj.CopyComplete
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms\obj\Debug\AucmaEms.exe
E:\桌面\澳柯玛代码\程序代码\AucmaEms\AucmaEms\obj\Debug\AucmaEms.pdb

@ -0,0 +1 @@
bcc3f871eb8848bfeb5baf7b16c44fcf8328cb25

Binary file not shown.

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<appSettings>
<add key="ReadIntervel" value="15" />
<add key="listenIp" value="0.0.0.0" />
<add key="listenPort" value="502" />
<add key="connectStr" value="Data Source=10.100.71.119/ORCL;User ID=system;Password=aucma;Max Pool Size=512;Pooling=true" />
</appSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.122.1.0" newVersion="4.122.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save