Compare commits

..

No commits in common. 'master' and 'source' have entirely different histories.

@ -1,4 +0,0 @@
[*.{cs,vb}]
# IDE0044: 添加只读修饰符
dotnet_style_readonly_field = false

402
.gitignore vendored

@ -1,402 +0,0 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
# StyleCop
StyleCopReport.xml
.idea
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
# but not Directory.Build.rsp, as it configures directory-level build defaults
!Directory.Build.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.tlog
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*.json
coverage*.xml
coverage*.info
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio 6 auto-generated project file (contains which files were open etc.)
*.vbp
# Visual Studio 6 workspace and project file (working project files containing files to include in project)
*.dsw
*.dsp
# Visual Studio 6 technical files
*.ncb
*.aps
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# Visual Studio History (VSHistory) files
.vshistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd
# VS Code files for those working on multiple tools
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
.VSCodeCounter/
# Local History for Visual Studio Code
.history/
# Windows Installer files from build outputs
*.cab
*.msi
*.msix
*.msm
*.msp
# JetBrains Rider
*.sln.iml

Binary file not shown.

Binary file not shown.

@ -1,63 +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>{89A1EDD9-D79E-468D-B6D3-7D07B8843562}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>HighWayIot.Common</RootNamespace>
<AssemblyName>HighWayIot.Common</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</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>
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.3</Version>
</PackageReference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<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="JsonChange.cs" />
<Compile Include="MsgUtil.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StringChange.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HighWayIot.Log4net\HighWayIot.Log4net.csproj">
<Project>{deabc30c-ec6f-472e-bd67-d65702fdaf74}</Project>
<Name>HighWayIot.Log4net</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<?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>{89A1EDD9-D79E-468D-B6D3-7D07B8843562}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>HighWayIot.Common</RootNamespace>
<AssemblyName>HighWayIot.Common</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</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="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<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="JsonChange.cs" />
<Compile Include="MsgUtil.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StringChange.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HighWayIot.Log4net\HighWayIot.Log4net.csproj">
<Project>{deabc30c-ec6f-472e-bd67-d65702fdaf74}</Project>
<Name>HighWayIot.Log4net</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -1,115 +1,115 @@
using HighWayIot.Log4net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Xml.Linq;
namespace HighWayIot.Common
{
public class JsonChange
{
private static readonly Lazy<JsonChange> lazy = new Lazy<JsonChange>(() => new JsonChange());
public static JsonChange Instance
{
get
{
return lazy.Value;
}
}
private LogHelper log = LogHelper.Instance;
private JsonChange() { }
/// <summary>
/// Model 实体转json
/// </summary>
/// <param name="Model">可以是单个实体也可是实体集ToList()</param>
/// <returns></returns>
public string ModeToJson(object Model)
{
string str = "";
JavaScriptSerializer serializer = new JavaScriptSerializer();
try
{
str = serializer.Serialize(Model);
}
catch (Exception ex)
{
log.Error("Model转Json异常",ex);
}
return str;
}
/// <summary>
/// json实体转Model
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="jsonStr"></param>
/// <returns></returns>
public T JsonToMode<T>(string jsonStr)
{
T info = default(T);
JavaScriptSerializer serializer = new JavaScriptSerializer();
try
{
info = serializer.Deserialize<T>(jsonStr);
}
catch (Exception ex)
{
log.Error("Json转Model异常" ,ex);
}
return info;
}
/// <summary>
/// object转dictionary
/// </summary>
/// <param name="jsonData"></param>
/// <returns></returns>
public Dictionary<string, object> objectToDictionary(string jsonData)
{
Dictionary<string, object> result = new Dictionary<string, object>();
var inf = JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonData);
foreach (KeyValuePair<string, object> item in inf)
{
if (item.Value != null)
{
var type = item.Value.GetType();
if (type == typeof(JObject))
{
var info = objectToDictionary(JsonConvert.SerializeObject(item.Value));
foreach (KeyValuePair<string, object> ite in info)
{
result.Add(ite.Key, ite.Value);
}
continue;
}
else if (type == typeof(JArray))
{
JArray array = (JArray)item.Value;
var info = objectToDictionary(JsonConvert.SerializeObject(array[0]));
foreach (KeyValuePair<string, object> ite in info)
{
result.Add(item.Key + ite.Key, ite.Value);
}
continue;
}
}
result.Add(item.Key, item.Value);
}
return result;
}
}
}
using HighWayIot.Log4net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Xml.Linq;
namespace HighWayIot.Common
{
public class JsonChange
{
private static readonly Lazy<JsonChange> lazy = new Lazy<JsonChange>(() => new JsonChange());
public static JsonChange Instance
{
get
{
return lazy.Value;
}
}
private LogHelper log = LogHelper.Instance;
private JsonChange() { }
/// <summary>
/// Model 实体转json
/// </summary>
/// <param name="Model">可以是单个实体也可是实体集ToList()</param>
/// <returns></returns>
public string ModeToJson(object Model)
{
string str = "";
JavaScriptSerializer serializer = new JavaScriptSerializer();
try
{
str = serializer.Serialize(Model);
}
catch (Exception ex)
{
log.Error("Model转Json异常",ex);
}
return str;
}
/// <summary>
/// json实体转Model
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="jsonStr"></param>
/// <returns></returns>
public T JsonToMode<T>(string jsonStr)
{
T info = default(T);
JavaScriptSerializer serializer = new JavaScriptSerializer();
try
{
info = serializer.Deserialize<T>(jsonStr);
}
catch (Exception ex)
{
log.Error("Json转Model异常" ,ex);
}
return info;
}
/// <summary>
/// object转dictionary
/// </summary>
/// <param name="jsonData"></param>
/// <returns></returns>
public Dictionary<string, object> objectToDictionary(string jsonData)
{
Dictionary<string, object> result = new Dictionary<string, object>();
var inf = JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonData);
foreach (KeyValuePair<string, object> item in inf)
{
if (item.Value != null)
{
var type = item.Value.GetType();
if (type == typeof(JObject))
{
var info = objectToDictionary(JsonConvert.SerializeObject(item.Value));
foreach (KeyValuePair<string, object> ite in info)
{
result.Add(ite.Key, ite.Value);
}
continue;
}
else if (type == typeof(JArray))
{
JArray array = (JArray)item.Value;
var info = objectToDictionary(JsonConvert.SerializeObject(array[0]));
foreach (KeyValuePair<string, object> ite in info)
{
result.Add(item.Key + ite.Key, ite.Value);
}
continue;
}
}
result.Add(item.Key, item.Value);
}
return result;
}
}
}

File diff suppressed because it is too large Load Diff

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

@ -1,257 +1,216 @@
using HighWayIot.Log4net;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace HighWayIot.Common
{
public class StringChange
{
private static readonly Lazy<StringChange> lazy = new Lazy<StringChange>(() => new StringChange());
public static StringChange Instance
{
get
{
return lazy.Value;
}
}
private StringChange() { }
/// <summary>
/// 将字符串强制转换成int转换失败则返回0
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public 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;
}
}
/// <summary>
/// char数组转Array
/// </summary>
/// <param name="cha"></param>
/// <param name="len"></param>
/// <returns></returns>
public string CharArrayToString(char[] cha, int len)
{
string str = "";
for (int i = 0; i < len; i++)
{
str += string.Format("{0}", cha[i]);
}
return str;
}
public 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 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 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 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 byte[] Swap16Bytes(byte[] OldU16)
{
byte[] ReturnBytes = new byte[2];
ReturnBytes[1] = OldU16[0];
ReturnBytes[0] = OldU16[1];
return ReturnBytes;
}
/// <param name="strbase64">64Base码</param>
/// <param name="path">保存路径</param>
/// <param name="filename">文件名称</param>
/// <returns></returns>
public bool Base64ToImage(string strbase64, string path, string filename)
{
bool Flag = false;
try
{
//base64编码的文本 转为 图片
//图片名称
byte[] arr = Convert.FromBase64String(strbase64);//将指定的字符串(它将二进制数据编码为 Base64 数字)转换为等效的 8 位无符号整数数组。
using (MemoryStream ms = new MemoryStream(arr))
{
Bitmap bmp = new Bitmap(ms);//加载图像
if (!Directory.Exists(path))//判断保存目录是否存在
{
Directory.CreateDirectory(path);
}
bmp.Save((path + "\\" + filename + ".png"),System.Drawing.Imaging.ImageFormat.Png);//将图片以JPEG格式保存在指定目录(可以选择其他图片格式)
ms.Close();//关闭流并释放
if (File.Exists(path + "\\" + filename + ".png"))//判断是否存在
{
Flag = true;
}
}
}
catch (Exception ex)
{
Console.WriteLine("图片保存失败:" + ex.Message);
}
return Flag;
}
/// <summary>
/// 获取时间戳
/// </summary>
/// <returns></returns>
public long GetTimeStamp()
{
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
return Convert.ToInt64(ts.TotalSeconds);
}
public byte[] ConvertFloatToINt(byte[] floatBytes)
{
byte[] intBytes = new byte[floatBytes.Length / 2];
for (int i = 0; i < intBytes.Length; i++)
{
intBytes[i] = floatBytes[i * 2 + 1];
}
return intBytes;
}
//CRC异或校验
public byte CalculateVerify(byte[] pMessage, int iLength)
{
UInt16 i;
byte iVerify = 0;
iVerify = pMessage[0];
for (i = 1; i < iLength; i++)
{
iVerify = (byte)(iVerify ^ pMessage[i]);
}
return iVerify;
}
public int HexStringToNegative(string strNumber)
{
int iNegate = 0;
int iNumber = Convert.ToInt32(strNumber, 16);
if (iNumber > 127)
{
int iComplement = iNumber - 1;
string strNegate = string.Empty;
char[] binchar = Convert.ToString(iComplement, 2).PadLeft(8, '0').ToArray();
foreach (char ch in binchar)
{
if (Convert.ToInt32(ch) == 48)
{
strNegate += "1";
}
else
{
strNegate += "0";
}
}
iNegate = -Convert.ToInt32(strNegate, 2);
}
return iNegate;
}
/// <summary>
/// 提取字符串中的数字并转换为uint32
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="ArgumentException"></exception>
/// <exception cref="OverflowException"></exception>
public static uint ExtractUInt32(string input)
{
try
{
if (input == null)
return 0;
// 移除非数字字符(等价于 [^0-9]
string numberStr = Regex.Replace(input, @"\D", "");
if (numberStr.Length == 0)
return 0;
// uint最大值为429496729510位
if (numberStr.Length > 10)
return 0;
// 处理前导零
numberStr = numberStr.TrimStart('0');
// 全零情况
if (numberStr.Length == 0) numberStr = "0";
if (ulong.Parse(numberStr) > uint.MaxValue)
return 0;
return uint.Parse(numberStr);
}
catch (Exception ex)
{
return 0;
}
}
}
using HighWayIot.Log4net;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HighWayIot.Common
{
public class StringChange
{
private static readonly Lazy<StringChange> lazy = new Lazy<StringChange>(() => new StringChange());
public static StringChange Instance
{
get
{
return lazy.Value;
}
}
private StringChange() { }
/// <summary>
/// 将字符串强制转换成int转换失败则返回0
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public 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;
}
}
/// <summary>
/// char数组转Array
/// </summary>
/// <param name="cha"></param>
/// <param name="len"></param>
/// <returns></returns>
public string CharArrayToString(char[] cha, int len)
{
string str = "";
for (int i = 0; i < len; i++)
{
str += string.Format("{0}", cha[i]);
}
return str;
}
public 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 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 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 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 byte[] Swap16Bytes(byte[] OldU16)
{
byte[] ReturnBytes = new byte[2];
ReturnBytes[1] = OldU16[0];
ReturnBytes[0] = OldU16[1];
return ReturnBytes;
}
/// <param name="strbase64">64Base码</param>
/// <param name="path">保存路径</param>
/// <param name="filename">文件名称</param>
/// <returns></returns>
public bool Base64ToImage(string strbase64, string path, string filename)
{
bool Flag = false;
try
{
//base64编码的文本 转为 图片
//图片名称
byte[] arr = Convert.FromBase64String(strbase64);//将指定的字符串(它将二进制数据编码为 Base64 数字)转换为等效的 8 位无符号整数数组。
using (MemoryStream ms = new MemoryStream(arr))
{
Bitmap bmp = new Bitmap(ms);//加载图像
if (!Directory.Exists(path))//判断保存目录是否存在
{
Directory.CreateDirectory(path);
}
bmp.Save((path + "\\" + filename + ".png"),System.Drawing.Imaging.ImageFormat.Png);//将图片以JPEG格式保存在指定目录(可以选择其他图片格式)
ms.Close();//关闭流并释放
if (File.Exists(path + "\\" + filename + ".png"))//判断是否存在
{
Flag = true;
}
}
}
catch (Exception ex)
{
Console.WriteLine("图片保存失败:" + ex.Message);
}
return Flag;
}
/// <summary>
/// 获取时间戳
/// </summary>
/// <returns></returns>
public long GetTimeStamp()
{
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
return Convert.ToInt64(ts.TotalSeconds);
}
public byte[] ConvertFloatToINt(byte[] floatBytes)
{
byte[] intBytes = new byte[floatBytes.Length / 2];
for (int i = 0; i < intBytes.Length; i++)
{
intBytes[i] = floatBytes[i * 2 + 1];
}
return intBytes;
}
//CRC异或校验
public byte CalculateVerify(byte[] pMessage, int iLength)
{
UInt16 i;
byte iVerify = 0;
iVerify = pMessage[0];
for (i = 1; i < iLength; i++)
{
iVerify = (byte)(iVerify ^ pMessage[i]);
}
return iVerify;
}
public int HexStringToNegative(string strNumber)
{
int iNegate = 0;
int iNumber = Convert.ToInt32(strNumber, 16);
if (iNumber > 127)
{
int iComplement = iNumber - 1;
string strNegate = string.Empty;
char[] binchar = Convert.ToString(iComplement, 2).PadLeft(8, '0').ToArray();
foreach (char ch in binchar)
{
if (Convert.ToInt32(ch) == 48)
{
strNegate += "1";
}
else
{
strNegate += "0";
}
}
iNegate = -Convert.ToInt32(strNegate, 2);
}
return iNegate;
}
}
}

File diff suppressed because it is too large Load Diff

@ -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,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]

@ -0,0 +1,36 @@
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Common\obj\Debug\HighWayIot.Common.csproj.AssemblyReference.cache
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Common\obj\Debug\HighWayIot.Common.csproj.CoreCompileInputs.cache
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Common\bin\Debug\HighWayIot.Common.dll
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Common\bin\Debug\HighWayIot.Common.pdb
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Common\bin\Debug\HighWayIot.Log4net.dll
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Common\bin\Debug\Newtonsoft.Json.dll
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Common\bin\Debug\log4net.dll
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Common\bin\Debug\HighWayIot.Log4net.pdb
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Common\bin\Debug\Newtonsoft.Json.xml
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Common\obj\Debug\HighWayIot.Common.csproj.CopyComplete
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Common\obj\Debug\HighWayIot.Common.dll
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Common\obj\Debug\HighWayIot.Common.pdb
\\Mac\Home\Desktop\日常代码\HighWayIot\HighWayIot.Common\bin\Debug\HighWayIot.Common.dll
\\Mac\Home\Desktop\日常代码\HighWayIot\HighWayIot.Common\bin\Debug\HighWayIot.Common.pdb
\\Mac\Home\Desktop\日常代码\HighWayIot\HighWayIot.Common\bin\Debug\HighWayIot.Log4net.dll
\\Mac\Home\Desktop\日常代码\HighWayIot\HighWayIot.Common\bin\Debug\Newtonsoft.Json.dll
\\Mac\Home\Desktop\日常代码\HighWayIot\HighWayIot.Common\bin\Debug\log4net.dll
\\Mac\Home\Desktop\日常代码\HighWayIot\HighWayIot.Common\bin\Debug\HighWayIot.Log4net.pdb
\\Mac\Home\Desktop\日常代码\HighWayIot\HighWayIot.Common\bin\Debug\Newtonsoft.Json.xml
\\Mac\Home\Desktop\日常代码\HighWayIot\HighWayIot.Common\obj\Debug\HighWayIot.Common.csproj.AssemblyReference.cache
\\Mac\Home\Desktop\日常代码\HighWayIot\HighWayIot.Common\obj\Debug\HighWayIot.Common.csproj.CoreCompileInputs.cache
\\Mac\Home\Desktop\日常代码\HighWayIot\HighWayIot.Common\obj\Debug\HighWayIot.Common.csproj.CopyComplete
\\Mac\Home\Desktop\日常代码\HighWayIot\HighWayIot.Common\obj\Debug\HighWayIot.Common.dll
\\Mac\Home\Desktop\日常代码\HighWayIot\HighWayIot.Common\obj\Debug\HighWayIot.Common.pdb
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Common\bin\Debug\HighWayIot.Common.dll
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Common\bin\Debug\HighWayIot.Common.pdb
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Common\bin\Debug\HighWayIot.Log4net.dll
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Common\bin\Debug\Newtonsoft.Json.dll
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Common\bin\Debug\log4net.dll
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Common\bin\Debug\HighWayIot.Log4net.pdb
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Common\bin\Debug\Newtonsoft.Json.xml
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Common\obj\Debug\HighWayIot.Common.csproj.AssemblyReference.cache
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Common\obj\Debug\HighWayIot.Common.csproj.CoreCompileInputs.cache
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Common\obj\Debug\HighWayIot.Common.csproj.CopyComplete
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Common\obj\Debug\HighWayIot.Common.dll
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Common\obj\Debug\HighWayIot.Common.pdb

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net452" />
</packages>

File diff suppressed because it is too large Load Diff

@ -1,16 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mesnac.Controls.ChemicalWeighing
{
public enum HslDirectionStyle
{
/// <summary>控件是横向摆放的</summary>
Horizontal = 1,
/// <summary>控件是纵向摆放的</summary>
Vertical = 2,
}
}

@ -1,639 +0,0 @@
using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Mesnac.Controls.ChemicalWeighing
{
/// <summary>整个组件的代码辅助工具,提供了一个基础的类库方法</summary>
public class HslHelper
{
static HslHelper()
{
HslHelper.StringFormatDefault = new StringFormat();
HslHelper.StringFormatCenter = new StringFormat();
HslHelper.StringFormatCenter.Alignment = StringAlignment.Center;
HslHelper.StringFormatCenter.LineAlignment = StringAlignment.Center;
HslHelper.StringFormatLeft = new StringFormat();
HslHelper.StringFormatLeft.LineAlignment = StringAlignment.Center;
HslHelper.StringFormatLeft.Alignment = StringAlignment.Near;
HslHelper.StringFormatRight = new StringFormat();
HslHelper.StringFormatRight.LineAlignment = StringAlignment.Center;
HslHelper.StringFormatRight.Alignment = StringAlignment.Far;
HslHelper.StringFormatTopCenter = new StringFormat();
HslHelper.StringFormatTopCenter.Alignment = StringAlignment.Center;
HslHelper.StringFormatTopCenter.LineAlignment = StringAlignment.Near;
}
/// <summary>返回中间范围值数据,如果大于最大值,则返回最大值,如果小于最小值,则返回最小值</summary>
/// <param name="min">最小值</param>
/// <param name="value">实际值</param>
/// <param name="max">最大值</param>
/// <returns>中间值信息</returns>
public static int Middle(int min, int value, int max)
{
if (value > max)
return max;
return value < min ? min : value;
}
/// <summary>从一个矩形的图形中获取菱形的坐标数组</summary>
/// <param name="rect">矩形</param>
/// <returns>数组结果</returns>
public static Point[] GetRhombusFromRectangle(Rectangle rect) => new Point[5]
{
new Point(rect.X, rect.Y + rect.Height / 2),
new Point(rect.X + rect.Width / 2, rect.Y + rect.Height - 1),
new Point(rect.X + rect.Width - 1, rect.Y + rect.Height / 2),
new Point(rect.X + rect.Width / 2, rect.Y),
new Point(rect.X, rect.Y + rect.Height / 2)
};
/// <summary>计算绘图时的相对偏移值</summary>
/// <param name="max">0-100分的最大值就是指准备绘制的最大值</param>
/// <param name="min">0-100分的最小值就是指准备绘制的最小值</param>
/// <param name="height">实际绘图区域的高度</param>
/// <param name="value">需要绘制数据的当前值</param>
/// <returns>相对于0的位置还需要增加上面的偏值</returns>
public static float ComputePaintLocationY(int max, int min, int height, int value) => (double)(max - min) == 0.0 ? (float)height : (float)height - (float)(value - min) * 1f / (float)(max - min) * (float)height;
/// <summary>计算绘图Y轴时的相对偏移值</summary>
/// <param name="max">0-100分的最大值就是指准备绘制的最大值</param>
/// <param name="min">0-100分的最小值就是指准备绘制的最小值</param>
/// <param name="height">实际绘图区域的高度</param>
/// <param name="value">需要绘制数据的当前值</param>
/// <returns>相对于0的位置还需要增加上面的偏值</returns>
public static float ComputePaintLocationY(float max, float min, float height, float value)
{
if ((double)max - (double)min == 0.0)
return height;
float num = max - min;
if ((double)num == 0.0)
num = 1f;
return height - (value - min) / num * height;
}
/// <summary>计算绘图X轴时的相对偏移值</summary>
/// <param name="max">0-100分的最大值就是指准备绘制的最大值</param>
/// <param name="min">0-100分的最小值就是指准备绘制的最小值</param>
/// <param name="width">实际绘图区域的宽度</param>
/// <param name="value">需要绘制数据的当前值</param>
/// <returns>相对于0的位置还需要增加上面的偏值</returns>
public static float ComputePaintLocationX(float max, float min, float width, float value)
{
if ((double)max - (double)min == 0.0)
return width;
float num = max - min;
if ((double)num == 0.0)
num = 1f;
return (value - min) / num * width;
}
/// <summary>根据绘制的值计算原始的值信息</summary>
/// <param name="max">0-100分的最大值就是指准备绘制的最大值</param>
/// <param name="min">0-100分的最小值就是指准备绘制的最小值</param>
/// <param name="height">实际绘图区域的高度</param>
/// <param name="paint">实际绘制的位置信息</param>
/// <returns>实际的值信息</returns>
public static float ComputeValueFromPaintLocationY(
float max,
float min,
float height,
float paint)
{
if ((double)max - (double)min == 0.0)
return max;
float num = max - min;
if ((double)num == 0.0)
num = 1f;
return (height - paint) * num / height + min;
}
/// <summary>计算绘图时的相对偏移值</summary>
/// <param name="referenceAxis">坐标轴信息</param>
/// <param name="height">实际绘图区域的高度</param>
/// <param name="value">需要绘制数据的当前值</param>
/// <returns>相对于0的位置还需要增加上面的偏值</returns>
public static float ComputePaintLocationY(
ReferenceAxis referenceAxis,
float height,
float value)
{
return HslHelper.ComputePaintLocationY(referenceAxis.Max, referenceAxis.Min, height, value);
}
/// <summary>绘制坐标系中的刻度线</summary>
/// <param name="g">绘图对象</param>
/// <param name="penLine">画坐标轴的画笔</param>
/// <param name="penDash"></param>
/// <param name="font"></param>
/// <param name="brush"></param>
/// <param name="sf"></param>
/// <param name="degree"></param>
/// <param name="max"></param>
/// <param name="min"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="left"></param>
/// <param name="right"></param>
/// <param name="up"></param>
/// <param name="down"></param>
public static void PaintCoordinateDivide(
Graphics g,
System.Drawing.Pen penLine,
System.Drawing.Pen penDash,
Font font,
System.Drawing.Brush brush,
StringFormat sf,
int degree,
int max,
int min,
int width,
int height,
int left = 60,
int right = 8,
int up = 8,
int down = 8)
{
for (int index = 0; index <= degree; ++index)
{
int num1 = (max - min) * index / degree + min;
int num2 = (int)HslHelper.ComputePaintLocationY(max, min, height - up - down, num1) + up + 1;
g.DrawLine(penLine, left - 1, num2, left - 4, num2);
if (index != 0)
g.DrawLine(penDash, left, num2, width - right, num2);
g.DrawString(num1.ToString(), font, brush, (RectangleF)new Rectangle(-5, num2 - font.Height / 2, left, font.Height), sf);
}
}
/// <summary>根据指定的方向绘制一个箭头</summary>
/// <param name="g"></param>
/// <param name="brush"></param>
/// <param name="point"></param>
/// <param name="size"></param>
/// <param name="direction"></param>
public static void PaintTriangle(
Graphics g,
System.Drawing.Brush brush,
Point point,
int size,
GraphDirection direction)
{
Point[] points = new Point[4];
switch (direction)
{
case GraphDirection.Upward:
points[0] = new Point(point.X - size, point.Y);
points[1] = new Point(point.X + size, point.Y);
points[2] = new Point(point.X, point.Y - 2 * size);
break;
case GraphDirection.Leftward:
points[0] = new Point(point.X, point.Y - size);
points[1] = new Point(point.X, point.Y + size);
points[2] = new Point(point.X - 2 * size, point.Y);
break;
case GraphDirection.Rightward:
points[0] = new Point(point.X, point.Y - size);
points[1] = new Point(point.X, point.Y + size);
points[2] = new Point(point.X + 2 * size, point.Y);
break;
default:
points[0] = new Point(point.X - size, point.Y);
points[1] = new Point(point.X + size, point.Y);
points[2] = new Point(point.X, point.Y + 2 * size);
break;
}
points[3] = points[0];
g.FillPolygon(brush, points);
}
/// <summary>绘制向左或是向右的箭头,例如 &lt;&lt; 或是 &gt;&gt;</summary>
/// <param name="g">画刷资源</param>
/// <param name="pen">画笔资源</param>
/// <param name="rectangle">绘制的矩形</param>
/// <param name="direction">方向信息</param>
public static void DrawLeftRight(
Graphics g,
System.Drawing.Pen pen,
Rectangle rectangle,
GraphDirection direction)
{
if (direction == GraphDirection.Leftward)
{
g.DrawLines(pen, new Point[3]
{
new Point(rectangle.X + rectangle.Width / 2, rectangle.Y),
new Point(rectangle.X, rectangle.Y + rectangle.Height / 2),
new Point(rectangle.X + rectangle.Width / 2, rectangle.Y + rectangle.Height)
});
g.DrawLines(pen, new Point[3]
{
new Point(rectangle.X + rectangle.Width, rectangle.Y),
new Point(rectangle.X + rectangle.Width / 2, rectangle.Y + rectangle.Height / 2),
new Point(rectangle.X + rectangle.Width, rectangle.Y + rectangle.Height)
});
}
else
{
if (direction != GraphDirection.Rightward)
return;
g.DrawLines(pen, new Point[3]
{
new Point(rectangle.X, rectangle.Y),
new Point(rectangle.X + rectangle.Width / 2, rectangle.Y + rectangle.Height / 2),
new Point(rectangle.X, rectangle.Y + rectangle.Height)
});
g.DrawLines(pen, new Point[3]
{
new Point(rectangle.X + rectangle.Width / 2, rectangle.Y),
new Point(rectangle.X + rectangle.Width, rectangle.Y + rectangle.Height / 2),
new Point(rectangle.X + rectangle.Width / 2, rectangle.Y + rectangle.Height)
});
}
}
/// <summary>根据指定的方向绘制一个箭头</summary>
/// <param name="g"></param>
/// <param name="brush"></param>
/// <param name="point"></param>
/// <param name="size"></param>
/// <param name="direction"></param>
public static void PaintTriangle(
Graphics g,
System.Drawing.Brush brush,
PointF point,
int size,
GraphDirection direction)
{
PointF[] points = new PointF[4];
switch (direction)
{
case GraphDirection.Upward:
points[0] = new PointF(point.X - (float)size, point.Y);
points[1] = new PointF(point.X + (float)size, point.Y);
points[2] = new PointF(point.X, point.Y - (float)(2 * size));
break;
case GraphDirection.Leftward:
points[0] = new PointF(point.X, point.Y - (float)size);
points[1] = new PointF(point.X, point.Y + (float)size);
points[2] = new PointF(point.X - (float)(2 * size), point.Y);
break;
case GraphDirection.Rightward:
points[0] = new PointF(point.X, point.Y - (float)size);
points[1] = new PointF(point.X, point.Y + (float)size);
points[2] = new PointF(point.X + (float)(2 * size), point.Y);
break;
default:
points[0] = new PointF(point.X - (float)size, point.Y);
points[1] = new PointF(point.X + (float)size, point.Y);
points[2] = new PointF(point.X, point.Y + (float)(2 * size));
break;
}
points[3] = points[0];
g.FillPolygon(brush, points);
}
/// <summary>
/// 一个通用的数组新增个数方法,会自动判断越界情况,越界的情况下,会自动的截断或是填充 -&gt;
/// A common array of new methods, will automatically determine the cross-border situation, in the case of cross-border, will be automatically truncated or filled
/// </summary>
/// <typeparam name="T">数据类型</typeparam>
/// <param name="array">原数据</param>
/// <param name="data">等待新增的数据</param>
/// <param name="max">原数据的最大值</param>
public static void AddArrayData<T>(ref T[] array, T[] data, int max)
{
if (data == null || data.Length == 0)
return;
if (array.Length == max)
{
Array.Copy((Array)array, data.Length, (Array)array, 0, array.Length - data.Length);
Array.Copy((Array)data, 0, (Array)array, array.Length - data.Length, data.Length);
}
else if (array.Length + data.Length > max)
{
T[] objArray = new T[max];
for (int index = 0; index < max - data.Length; ++index)
objArray[index] = array[index + (array.Length - max + data.Length)];
for (int index = 0; index < data.Length; ++index)
objArray[objArray.Length - data.Length + index] = data[index];
array = objArray;
}
else
{
T[] objArray = new T[array.Length + data.Length];
for (int index = 0; index < array.Length; ++index)
objArray[index] = array[index];
for (int index = 0; index < data.Length; ++index)
objArray[objArray.Length - data.Length + index] = data[index];
array = objArray;
}
}
/// <summary>尺寸转换,计算旋转后的尺寸。</summary>
/// <param name="size"></param>
/// <param name="angle"></param>
/// <returns></returns>
public static SizeF ConvertSize(SizeF size, float angle)
{
System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix();
matrix.Rotate(angle);
PointF[] pts = new PointF[4];
pts[0].X = (float)(-(double)size.Width / 2.0);
pts[0].Y = (float)(-(double)size.Height / 2.0);
pts[1].X = (float)(-(double)size.Width / 2.0);
pts[1].Y = size.Height / 2f;
pts[2].X = size.Width / 2f;
pts[2].Y = size.Height / 2f;
pts[3].X = size.Width / 2f;
pts[3].Y = (float)(-(double)size.Height / 2.0);
matrix.TransformPoints(pts);
float num1 = float.MaxValue;
float num2 = float.MinValue;
float num3 = float.MaxValue;
float num4 = float.MinValue;
foreach (PointF pointF in pts)
{
if ((double)pointF.X < (double)num1)
num1 = pointF.X;
if ((double)pointF.X > (double)num2)
num2 = pointF.X;
if ((double)pointF.Y < (double)num3)
num3 = pointF.Y;
if ((double)pointF.Y > (double)num4)
num4 = pointF.Y;
}
return new SizeF(num2 - num1, num4 - num3);
}
/// <summary>绘制旋转文本</summary>
/// <param name="g"></param>
/// <param name="s"></param>
/// <param name="font"></param>
/// <param name="brush"></param>
/// <param name="point"></param>
/// <param name="format"></param>
/// <param name="angle"></param>
public static void DrawString(
Graphics g,
string s,
Font font,
System.Drawing.Brush brush,
PointF point,
StringFormat format,
float angle)
{
System.Drawing.Drawing2D.Matrix transform1 = g.Transform;
System.Drawing.Drawing2D.Matrix transform2 = g.Transform;
transform2.RotateAt(angle, point);
g.Transform = transform2;
g.DrawString(s, font, brush, point, format);
g.Transform = transform1;
}
private static int GetPow(int digit)
{
int pow = 1;
for (int index = 0; index < digit; ++index)
pow *= 10;
return pow;
}
/// <summary>将int数组转换为double数组</summary>
/// <param name="values">int数组值</param>
/// <returns>结果值</returns>
public static double[] TranlateArrayToDouble(int[] values)
{
if (values == null)
return (double[])null;
double[] numArray = new double[values.Length];
for (int index = 0; index < values.Length; ++index)
numArray[index] = (double)values[index];
return numArray;
}
/// <summary>将float数组转换为double数组值</summary>
/// <param name="values">float数组值</param>
/// <returns>结果值</returns>
public static double[] TranlateArrayToDouble(float[] values)
{
double[] numArray = new double[values.Length];
for (int index = 0; index < values.Length; ++index)
numArray[index] = (double)values[index];
return numArray;
}
/// <summary>获得数据的上限值,这个上限值是自动计算的。</summary>
/// <param name="values">数据值</param>
/// <returns>数据值</returns>
public static int CalculateMaxSectionFrom(double[] values)
{
double a = ((IEnumerable<double>)values).Max();
if (a <= 5.0)
return 5;
if (a <= 9.0)
return 10;
int int32 = Convert.ToInt32(Math.Ceiling(a));
int digit = int32.ToString().Length - 2;
int num = int.Parse(int32.ToString().Substring(0, 2));
if (num < 11)
return 12 * HslHelper.GetPow(digit);
if (num < 13)
return 14 * HslHelper.GetPow(digit);
if (num < 15)
return 16 * HslHelper.GetPow(digit);
if (num < 17)
return 18 * HslHelper.GetPow(digit);
if (num < 19)
return 20 * HslHelper.GetPow(digit);
if (num < 21)
return 22 * HslHelper.GetPow(digit);
if (num < 23)
return 24 * HslHelper.GetPow(digit);
if (num < 25)
return 26 * HslHelper.GetPow(digit);
if (num < 27)
return 28 * HslHelper.GetPow(digit);
if (num < 29)
return 30 * HslHelper.GetPow(digit);
if (num < 33)
return 34 * HslHelper.GetPow(digit);
if (num < 40)
return 40 * HslHelper.GetPow(digit);
if (num < 50)
return 50 * HslHelper.GetPow(digit);
if (num < 60)
return 60 * HslHelper.GetPow(digit);
if (num < 80)
return 80 * HslHelper.GetPow(digit);
return num < 95 ? 100 * HslHelper.GetPow(digit) : 100 * HslHelper.GetPow(digit);
}
/// <inheritdoc cref="M:HslControls.HslHelper.CalculateMaxSectionFrom(System.Double[])" />
public static int CalculateMaxSectionFrom(Dictionary<string, double[]> values) => HslHelper.CalculateMaxSectionFrom(values.Select<KeyValuePair<string, double[]>, double>((Func<KeyValuePair<string, double[]>, double>)(m => ((IEnumerable<double>)m.Value).Max())).ToArray<double>());
/// <summary>获取当前颜色更淡的颜色信息</summary>
/// <param name="color">颜色信息</param>
/// <returns>颜色</returns>
public static System.Drawing.Color GetColorLight(System.Drawing.Color color) => HslHelper.GetColorLight(color, 40);
/// <summary>获取当前颜色更深的颜色信息</summary>
/// <param name="color">颜色信息</param>
/// <returns>颜色</returns>
public static System.Drawing.Color GetColorDeep(System.Drawing.Color color) => HslHelper.GetColorLight(color, -40);
/// <summary>获取当前颜色更淡的颜色信息需要指定系数0-1000时是原来的原色100时是纯白色</summary>
/// <param name="color">颜色信息</param>
/// <param name="scale">获取颜色的系数信息</param>
/// <returns>颜色</returns>
public static System.Drawing.Color GetColorLight(System.Drawing.Color color, int scale) => scale > 0 ? System.Drawing.Color.FromArgb((int)color.R + ((int)byte.MaxValue - (int)color.R) * scale / 100, (int)color.G + ((int)byte.MaxValue - (int)color.G) * scale / 100, (int)color.B + ((int)byte.MaxValue - (int)color.B) * scale / 100) : System.Drawing.Color.FromArgb((int)color.R + (int)color.R * scale / 100, (int)color.G + (int)color.G * scale / 100, (int)color.B + (int)color.B * scale / 100);
/// <summary>获取颜色的偏移信息</summary>
/// <param name="color">颜色值</param>
/// <param name="offset">颜色偏移信息</param>
/// <returns>颜色值</returns>
public static System.Drawing.Color GetColorOffset(System.Drawing.Color color, int offset)
{
int red = (int)color.R + offset;
if (red < 0)
red = 0;
if (red > (int)byte.MaxValue)
red = (int)byte.MaxValue;
int green = (int)color.G + offset;
if (green < 0)
green = 0;
if (green > (int)byte.MaxValue)
green = (int)byte.MaxValue;
int blue = (int)color.B + offset;
if (blue < 0)
blue = 0;
if (blue > (int)byte.MaxValue)
blue = (int)byte.MaxValue;
return System.Drawing.Color.FromArgb(red, green, blue);
}
///// <summary>获取当前颜色更淡的颜色信息</summary>
///// <param name="color">颜色信息</param>
///// <returns>颜色</returns>
//public static System.Drawing.Color GetColorLightFive(System.Drawing.Color color) => HslHelper.GetColorLight(color, 50);
///// <summary>获取当前颜色更淡的颜色信息</summary>
///// <param name="color">颜色信息</param>
///// <returns>颜色</returns>
//public static System.Windows.Media.Color GetColorLight(System.Windows.Media.Color color) => System.Windows.Media.Color.FromRgb((byte)((uint)color.R + (uint)(((int)byte.MaxValue - (int)color.R) * 40 / 100)), (byte)((uint)color.G + (uint)(((int)byte.MaxValue - (int)color.G) * 40 / 100)), (byte)((uint)color.B + (uint)(((int)byte.MaxValue - (int)color.B) * 40 / 100)));
///// <summary>获取当前颜色更淡的颜色信息</summary>
///// <param name="color">颜色信息</param>
///// <returns>颜色</returns>
//public static System.Windows.Media.Color GetColorLightFive(System.Windows.Media.Color color) => System.Windows.Media.Color.FromRgb((byte)((uint)color.R + (uint)(((int)byte.MaxValue - (int)color.R) * 50 / 100)), (byte)((uint)color.G + (uint)(((int)byte.MaxValue - (int)color.G) * 50 / 100)), (byte)((uint)color.B + (uint)(((int)byte.MaxValue - (int)color.B) * 50 / 100)));
/// <summary>从字符串表示的点位信息里解析出真正的点位信息</summary>
/// <param name="points">字符串的点位</param>
/// <param name="soureWidth">原来的长度信息</param>
/// <param name="sourceHeight">原来的高度信息</param>
/// <param name="width">实际的宽度信息</param>
/// <param name="height">实际的高度信息</param>
/// <param name="dx">x偏移量信息</param>
/// <param name="dy">y偏移量信息</param>
/// <returns></returns>
public static PointF[] GetPointsFrom(
string points,
float soureWidth,
float sourceHeight,
float width,
float height,
float dx = 0.0f,
float dy = 0.0f)
{
string[] strArray = points.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
PointF[] pointsFrom = new PointF[strArray.Length];
for (int index = 0; index < strArray.Length; ++index)
{
int length = strArray[index].IndexOf(',');
float single1 = Convert.ToSingle(strArray[index].Substring(0, length));
float single2 = Convert.ToSingle(strArray[index].Substring(length + 1));
pointsFrom[index] = new PointF(width * (single1 + dx) / soureWidth, height * (single2 + dy) / sourceHeight);
}
return pointsFrom;
}
/// <summary>根据矩形及其各个定点的配置信息,获取圆角的路径信息,可以指定每个定点的圆角情况</summary>
/// <param name="rectangle"></param>
/// <param name="radius"></param>
/// <param name="topLeft"></param>
/// <param name="topRight"></param>
/// <param name="buttomRight"></param>
/// <param name="buttomLeft"></param>
/// <returns></returns>
public static GraphicsPath GetRoundRectange(
Rectangle rectangle,
int radius,
bool topLeft,
bool topRight,
bool buttomRight,
bool buttomLeft)
{
GraphicsPath roundRectange = new GraphicsPath();
Point pt1_1 = new Point(rectangle.X + (topLeft ? radius : 0), rectangle.Y);
Point pt2_1 = new Point(rectangle.X + rectangle.Width - 1 - (topRight ? radius : 0), rectangle.Y);
roundRectange.AddLine(pt1_1, pt2_1);
if (topRight && radius > 0)
roundRectange.AddArc(rectangle.X + rectangle.Width - radius * 2 - 1, rectangle.Y, radius * 2, radius * 2, 270f, 90f);
Point pt1_2 = new Point(rectangle.X + rectangle.Width - 1, rectangle.Y + (topRight ? radius : 0));
Point pt2_2 = new Point(rectangle.X + rectangle.Width - 1, rectangle.Y + rectangle.Height - 1 - (buttomRight ? radius : 0));
roundRectange.AddLine(pt1_2, pt2_2);
if (buttomRight && radius > 0)
roundRectange.AddArc(rectangle.X + rectangle.Width - radius * 2 - 1, rectangle.Y + rectangle.Height - radius * 2 - 1, radius * 2, radius * 2, 0.0f, 90f);
Point pt1_3 = new Point(rectangle.X + rectangle.Width - 1 - (buttomRight ? radius : 0), rectangle.Y + rectangle.Height - 1);
Point pt2_3 = new Point(rectangle.X + (buttomLeft ? radius : 0), rectangle.Y + rectangle.Height - 1);
roundRectange.AddLine(pt1_3, pt2_3);
if (buttomLeft && radius > 0)
roundRectange.AddArc(rectangle.X, rectangle.Y + rectangle.Height - radius * 2 - 1, radius * 2, radius * 2, 90f, 90f);
Point pt1_4 = new Point(rectangle.X, rectangle.Y + rectangle.Height - 1 - (buttomLeft ? radius : 0));
Point pt2_4 = new Point(rectangle.X, rectangle.Y + (topLeft ? radius : 0));
roundRectange.AddLine(pt1_4, pt2_4);
if (topLeft && radius > 0)
roundRectange.AddArc(rectangle.X, rectangle.Y, radius * 2, radius * 2, 180f, 90f);
return roundRectange;
}
private static string FloatMatchEvaluator(Match m) => m.Value.Length == 5 ? m.Value.Substring(0, 3) : m.Value.Substring(0, 2);
/// <summary>获取浮点数值的格式化文本信息,如果发生了异常,则返回错误消息</summary>
/// <param name="format">格式化信息</param>
/// <param name="value">值信息</param>
/// <param name="remainZero">是否保留0的信息</param>
/// <returns>等待显示的文本</returns>
public static string GetFormatString(string format, float value, bool remainZero = false)
{
try
{
string input = string.Format(format, (object)value);
return remainZero ? input : Regex.Replace(input, "[Ee][+-][0]+", new MatchEvaluator(HslHelper.FloatMatchEvaluator));
}
catch
{
return "Wrong";
}
}
/// <summary>矩形中间的字符串对齐机制</summary>
public static StringFormat StringFormatCenter { get; set; }
/// <summary>矩形的左侧中间的对齐机制</summary>
public static StringFormat StringFormatLeft { get; set; }
/// <summary>矩形的右侧的中间对齐机制</summary>
public static StringFormat StringFormatRight { get; set; }
/// <summary>矩形的的默认的左上角对齐的机制</summary>
public static StringFormat StringFormatDefault { get; set; }
/// <summary>矩形的下方中间的对齐的机制</summary>
public static StringFormat StringFormatTopCenter { get; set; }
}
}

@ -1,254 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mesnac.Controls.ChemicalWeighing
{
/// <summary>
/// 移动的文本控件
/// </summary>
// Token: 0x02000045 RID: 69
[Description("移动文本控件,支持文件正向反向移动,支持设置移动速度")]
public class HslMoveText : UserControl
{
/// <summary>
/// 实例化一个默认的对象
/// </summary>
// Token: 0x060005CE RID: 1486 RVA: 0x00039D44 File Offset: 0x00037F44
public HslMoveText()
{
this.InitializeComponent();
this.sf = new StringFormat();
this.sf.Alignment = StringAlignment.Center;
this.sf.LineAlignment = StringAlignment.Center;
base.SetStyle(ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor, true);
base.SetStyle(ControlStyles.ResizeRedraw, true);
base.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
base.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.timer = new Timer();
this.timer.Interval = 30;
this.timer.Tick += this.Timer_Tick;
this.timer.Start();
}
/// <summary>
/// 获取或设置控件的背景色
/// </summary>
// Token: 0x170001CB RID: 459
// (get) Token: 0x060005CF RID: 1487 RVA: 0x00039E30 File Offset: 0x00038030
// (set) Token: 0x060005D0 RID: 1488 RVA: 0x00039E38 File Offset: 0x00038038
[Browsable(true)]
[Description("获取或设置控件的背景色")]
[Category("HslControls")]
[DefaultValue(typeof(Color), "Transparent")]
[EditorBrowsable(EditorBrowsableState.Always)]
public override Color BackColor
{
get
{
return base.BackColor;
}
set
{
base.BackColor = value;
}
}
/// <summary>
/// 获取或设置当前控件的文本
/// </summary>
// Token: 0x170001CC RID: 460
// (get) Token: 0x060005D1 RID: 1489 RVA: 0x00039E44 File Offset: 0x00038044
// (set) Token: 0x060005D2 RID: 1490 RVA: 0x00039E5C File Offset: 0x0003805C
[Browsable(true)]
[Description("获取或设置当前控件的文本")]
[Category("HslControls")]
[EditorBrowsable(EditorBrowsableState.Always)]
[Bindable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public override string Text
{
get
{
return base.Text;
}
set
{
base.Text = value;
base.Invalidate();
}
}
/// <summary>
/// 获取或设置泵控件是否是横向的还是纵向的
/// </summary>
// Token: 0x170001CD RID: 461
// (get) Token: 0x060005D3 RID: 1491 RVA: 0x00039E70 File Offset: 0x00038070
// (set) Token: 0x060005D4 RID: 1492 RVA: 0x00039E88 File Offset: 0x00038088
[Browsable(true)]
[Description("获取或设置泵控件是否是横向的还是纵向的")]
[Category("HslControls")]
[DefaultValue(typeof(HslDirectionStyle), "Vertical")]
public HslDirectionStyle PumpStyle
{
get
{
return this.hslValvesStyle;
}
set
{
this.hslValvesStyle = value;
base.Invalidate();
}
}
/// <summary>
/// 获取或设置泵的动画速度0为静止正数为正向流动负数为反向流动
/// </summary>
// Token: 0x170001CE RID: 462
// (get) Token: 0x060005D5 RID: 1493 RVA: 0x00039E9C File Offset: 0x0003809C
// (set) Token: 0x060005D6 RID: 1494 RVA: 0x00039EB4 File Offset: 0x000380B4
[Browsable(true)]
[Description("获取或设置传送带流动的速度0为静止正数为正向流动负数为反向流动")]
[Category("HslControls")]
[DefaultValue(1f)]
public float MoveSpeed
{
get
{
return this.moveSpeed;
}
set
{
this.moveSpeed = value;
base.Invalidate();
}
}
/// <summary>
/// 重绘控件的
/// </summary>
/// <param name="e">重绘事件</param>
// Token: 0x060005D7 RID: 1495 RVA: 0x00039EC8 File Offset: 0x000380C8
protected override void OnPaint(PaintEventArgs e)
{
Graphics graphics = e.Graphics;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
this.PaintHslControls(graphics, base.Width, base.Height);
base.OnPaint(e);
}
/// <inheritdoc cref="M:HslControls.HslArrow.PaintHslControls(System.Drawing.Graphics,System.Single,System.Single)" />
// Token: 0x060005D8 RID: 1496 RVA: 0x00039F18 File Offset: 0x00038118
public void PaintHslControls(Graphics g, int width, int height)
{
bool flag2 = this.hslValvesStyle == HslDirectionStyle.Vertical;
if (flag2)
{
this.PaintMain(g, (float)width, (float)height);
}
else
{
g.TranslateTransform((float)width, 0f);
g.RotateTransform(90f);
this.PaintMain(g, (float)height, (float)width);
g.ResetTransform();
}
}
// Token: 0x060005D9 RID: 1497 RVA: 0x00039F80 File Offset: 0x00038180
private void PaintMain(Graphics g, float width, float height)
{
this.fontWidth = g.MeasureString(this.Text, this.Font).Width + 3f;
Brush brush = new SolidBrush(this.ForeColor);
RectangleF layoutRectangle = new RectangleF(this.startLocationX, 0f, this.fontWidth, height);
g.DrawString(this.Text, this.Font, brush, layoutRectangle, this.sf);
}
// Token: 0x060005DA RID: 1498 RVA: 0x00039FF4 File Offset: 0x000381F4
private PointF[] GetPointsFrom(string points, float width, float height, float dx = 0f, float dy = 0f)
{
return HslHelper.GetPointsFrom(points, 80.7f, 112.5f, width, height, dx, dy);
}
// Token: 0x060005DB RID: 1499 RVA: 0x0003A01C File Offset: 0x0003821C
private void Timer_Tick(object sender, EventArgs e)
{
if (this.moveSpeed != 0f)
{
if (this.startLocationX < -this.fontWidth - 5f)
{
this.startLocationX = (float)(base.Width + 1);
}
else
{
this.startLocationX -= this.moveSpeed;
}
base.Invalidate();
}
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false。</param>
// Token: 0x060005DC RID: 1500 RVA: 0x0003A088 File Offset: 0x00038288
protected override void Dispose(bool disposing)
{
bool flag = disposing && this.components != null;
if (flag)
{
this.components.Dispose();
}
base.Dispose(disposing);
}
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
// Token: 0x060005DD RID: 1501 RVA: 0x0003A0C0 File Offset: 0x000382C0
private void InitializeComponent()
{
base.SuspendLayout();
base.AutoScaleMode = AutoScaleMode.None;
this.BackColor = Color.Transparent;
base.Name = "HslMoveText";
base.Size = new Size(720, 41);
base.ResumeLayout(false);
}
// Token: 0x040002DD RID: 733
private float fontWidth = 100f;
// Token: 0x040002DE RID: 734
private StringFormat sf = null;
// Token: 0x040002DF RID: 735
private HslDirectionStyle hslValvesStyle = HslDirectionStyle.Vertical;
// Token: 0x040002E0 RID: 736
private float moveSpeed = 1f;
// Token: 0x040002E1 RID: 737
private Timer timer = null;
// Token: 0x040002E2 RID: 738
private float startLocationX = -100000f;
/// <summary>
/// 必需的设计器变量。
/// </summary>
// Token: 0x040002E3 RID: 739
private IContainer components = null;
}
}

@ -1,145 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace Mesnac.Controls.ChemicalWeighing
{
/// <summary>参考坐标系的轴信息</summary>
[TypeConverter(typeof(ReferenceAxisConverter))]
public class ReferenceAxis
{
private float _max;
private float _min;
private string _unit;
private string _format;
private Color _color;
private UserControl _control;
private Pen _pen;
/// <summary>实例化一个默认的对象</summary>
public ReferenceAxis()
{
this.Max = 100f;
this.Min = 0.0f;
this.Color = Color.LightGray;
this.Format = "{0}";
}
/// <summary>实例化一个默认的对象</summary>
public ReferenceAxis(UserControl userControl)
: this()
{
this._control = userControl;
}
/// <summary>实例化一个默认的对象</summary>
/// <param name="max">最大值</param>
/// <param name="min">最小值</param>
public ReferenceAxis(float max, float min)
{
this.Max = max;
this.Min = min;
}
/// <summary>最大值</summary>
[Category("HslControls")]
[Description("获取或设置当前的Y轴的最大值")]
[Browsable(true)]
[DefaultValue(100f)]
public float Max
{
get => this._max;
set
{
this._max = value;
this._control?.Invalidate();
}
}
/// <summary>最小值</summary>
[Category("HslControls")]
[Description("获取或设置当前的Y轴的最小值")]
[Browsable(true)]
[DefaultValue(0.0f)]
public float Min
{
get => this._min;
set
{
this._min = value;
this._control?.Invalidate();
}
}
/// <summary>单位信息</summary>
[Category("HslControls")]
[Description("获取或设置当前的Y轴的单位值")]
[Browsable(true)]
[DefaultValue("")]
public string Unit
{
get => this._unit;
set
{
this._unit = value;
this._control?.Invalidate();
}
}
/// <summary>获取或设置当前的坐标系的颜色信息</summary>
[Category("HslControls")]
[Description("获取或设置当前的坐标系的颜色信息")]
[Browsable(true)]
[DefaultValue(typeof(Color), "LightGray")]
public Color Color
{
get => this._color;
set
{
this._color = value;
this.Brush?.Dispose();
this.Brush = (Brush)new SolidBrush(this._color);
this._pen?.Dispose();
this._pen = new Pen(this._color, 1f);
this._control?.Invalidate();
}
}
/// <summary>获取或设置当前坐标轴数字的格式化信息,默认为 {0}, 直接转字符串</summary>
[Category("HslControls")]
[Description("获取或设置当前坐标轴数字的格式化信息,默认为 {0}, 直接转字符串")]
[Browsable(true)]
[DefaultValue("{0}")]
public string Format
{
get => this._format;
set
{
this._format = value;
this._control?.Invalidate();
}
}
/// <summary>获取画笔信息</summary>
/// <returns>画笔信息</returns>
public Pen GetPen()
{
if (this._pen != null)
return this._pen;
this._pen = new Pen(this.Color, 1f);
return this._pen;
}
/// <summary>画刷资源</summary>
[Browsable(false)]
public Brush Brush { get; set; }
}
}

@ -1,25 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mesnac.Controls.ChemicalWeighing
{
/// <summary>参考坐标轴的转换器</summary>
public class ReferenceAxisConverter : TypeConverter
{
/// <inheritdoc />
public override PropertyDescriptorCollection GetProperties(
ITypeDescriptorContext context,
object value,
Attribute[] attributes)
{
return TypeDescriptor.GetProperties(value, attributes);
}
/// <inheritdoc />
public override bool GetPropertiesSupported(ITypeDescriptorContext context) => true;
}
}

@ -1,57 +0,0 @@
<?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>{DDEE27AA-0694-47A6-9335-E9308261F63A}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>HighWayIot.Controls</RootNamespace>
<AssemblyName>HighWayIot.Controls</AssemblyName>
<TargetFrameworkVersion>v4.8</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="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.Drawing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Controls\ControlHelper.cs" />
<Compile Include="Controls\HslDirectionStyle.cs" />
<Compile Include="Controls\HslHelper.cs" />
<Compile Include="Controls\HslMoveText.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Controls\ReferenceAxis.cs" />
<Compile Include="Controls\ReferenceAxisConverter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Service Include="{94E38DFF-614B-4cbd-B67C-F211BB35CE8B}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -1,33 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("HighWayIot.Controls")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HighWayIot.Controls")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("ddee27aa-0694-47a6-9335-e9308261f63a")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -1,57 +1,55 @@
<?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>{DEABC30C-EC6F-472E-BD67-D65702FDAF74}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>HighWayIot.Log4net</RootNamespace>
<AssemblyName>HighWayIot.Log4net</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</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>..\HighWayIot.Library\log4net.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="LogHelper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="config\log4net.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<?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>{DEABC30C-EC6F-472E-BD67-D65702FDAF74}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>HighWayIot.Log4net</RootNamespace>
<AssemblyName>HighWayIot.Log4net</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</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>..\HighWayIot.Library\log4net.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="LogHelper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="config\log4net.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -1,158 +1,147 @@
using log4net.Config;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HighWayIot.Log4net
{
public class LogHelper
{
private static readonly Lazy<LogHelper> lazy = new Lazy<LogHelper>(() => new LogHelper());
public static LogHelper Instance
{
get
{
return lazy.Value;
}
}
string currentDirectory = Environment.CurrentDirectory;
private readonly log4net.ILog loginfo = log4net.LogManager.GetLogger("loginfo");
private readonly log4net.ILog logerror = log4net.LogManager.GetLogger("logerror");
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");
private readonly log4net.ILog logPlc = log4net.LogManager.GetLogger("plclog");
private readonly log4net.ILog logRfid = log4net.LogManager.GetLogger("rfidlog");
/**
*
*
*/
//private readonly string fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log4net.config");
private readonly string fileName = $"{Environment.CurrentDirectory}\\config\\log4net.config";
private LogHelper()
{
if (File.Exists(fileName))
{
XmlConfigurator.Configure(new FileInfo(fileName));
}
}
/// <summary>
/// 记录Info日志 控制台 log
/// </summary>
/// <param name="msg"></param>
/// <param name="ex"></param>
public void Info(string msg)
{
if (loginfo.IsInfoEnabled)
{
loginfo.Info(msg);
}
}
/// <summary>
/// 记录PLC日志 log
/// </summary>
/// <param name="msg"></param>
public void PlcLog(string msg)
{
if (logPlc.IsInfoEnabled)
{
logPlc.Debug(msg);
}
}
/// <summary>
/// 记录Rfid日志 log
/// </summary>
/// <param name="msg"></param>
public void RfidLog(string msg)
{
if (logRfid.IsInfoEnabled)
{
logRfid.Debug(msg);
}
}
/// <summary>
/// 界面日志 log
/// </summary>
/// <param name="msg"></param>
public void ViewLog(string msg)
{
if (logView.IsInfoEnabled)
{
logView.Info(msg);
}
}
/// <summary>
/// 数据库日志 log
/// </summary>
/// <param name="msg"></param>
public void SqlLog(string msg)
{
if (sqllog.IsInfoEnabled)
{
sqllog.Debug(msg);
}
}
/// <summary>
/// 信号量日志 log
/// </summary>
/// <param name="msg"></param>
public void SemaphoreLog(string msg)
{
if (semaphorelog.IsInfoEnabled)
{
semaphorelog.Info(msg);
}
}
/// <summary>
/// 记录Error日志 控制台 log
/// </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}", new object[] { info });
}
else if (!string.IsNullOrEmpty(info) && ex != null)
{
string errorMsg = BeautyErrorMsg(ex);
logerror.ErrorFormat("[附加信息] : {0} message : {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 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;
}
}
}
using log4net.Config;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HighWayIot.Log4net
{
public class LogHelper
{
private static readonly Lazy<LogHelper> lazy = new Lazy<LogHelper>(() => new LogHelper());
public static LogHelper Instance
{
get
{
return lazy.Value;
}
}
private readonly log4net.ILog loginfo = log4net.LogManager.GetLogger("loginfo");
private readonly log4net.ILog logerror = log4net.LogManager.GetLogger("logerror");
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");
private readonly log4net.ILog logPlc = log4net.LogManager.GetLogger("plclog");
private readonly log4net.ILog logRfid = log4net.LogManager.GetLogger("rfidlog");
/**
*
*
*/
//private readonly string fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log4net.config");
private readonly string fileName = "Z:\\Desktop\\日常代码\\HighWayIot\\HighWayIot.Log4net\\config\\log4net.config";
private LogHelper()
{
if (File.Exists(fileName))
{
XmlConfigurator.Configure(new FileInfo(fileName));
}
}
/// <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 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;
}
}
}

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

@ -1,182 +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" />
<appender-ref ref="ColoredConsoleAppender" />
</logger>
<!--信息日志类-->
<logger name="loginfo">
<level value="ALL" />
<appender-ref ref="InfoAppender" />
<appender-ref ref="ColoredConsoleAppender" />
</logger>
<!--PLC日志类-->
<logger name="plclog">
<level value="ALL" />
<appender-ref ref="PlcAppender" />
<!--<appender-ref ref="ColoredConsoleAppender" />-->
</logger>
<!--RFID日志类-->
<logger name="rfidlog">
<level value="ALL" />
<appender-ref ref="RfidAppender" />
<appender-ref ref="ColoredConsoleAppender" />
</logger>
<!--RFID日志类-->
<logger name="viewlog">
<level value="ALL" />
<appender-ref ref="ViewAppender" />
<!--<appender-ref ref="ColoredConsoleAppender" />-->
</logger>
<!--Sql日志类-->
<logger name="sqllog">
<level value="ALL" />
<appender-ref ref="SqlAppender" />
<!--<appender-ref ref="ColoredConsoleAppender" />-->
</logger>
<!--信号量日志类-->
<logger name="semaphorelog">
<level value="ALL" />
<appender-ref ref="SemaphoreAppender" />
<!--<appender-ref ref="ColoredConsoleAppender" />-->
</logger>
<!-- 将日志输出到控制台 -->
<appender name="ColoredConsoleAppender" type="log4net.Appender.ColoredConsoleAppender">
<mapping>
<level value="ERROR" />
<foreColor value="Red, HighIntensity" />
</mapping>
<mapping>
<level value="Info" />
<foreColor value="White" />
</mapping>
<mapping>
<level value="Debug" />
<foreColor value="Yellow, HighIntensity" />
</mapping>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
</layout>
</appender>
<!--错误日志附加介质-->
<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>
<?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,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]

@ -0,0 +1,23 @@
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Log4net\bin\Debug\HighWayIot.Log4net.dll
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Log4net\bin\Debug\HighWayIot.Log4net.pdb
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Log4net\obj\Debug\HighWayIot.Log4net.csproj.AssemblyReference.cache
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Log4net\obj\Debug\HighWayIot.Log4net.csproj.CoreCompileInputs.cache
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Log4net\obj\Debug\HighWayIot.Log4net.dll
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Log4net\obj\Debug\HighWayIot.Log4net.pdb
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Log4net\bin\Debug\log4net.dll
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Log4net\obj\Debug\HighWayIot.Log4net.csproj.CopyComplete
\\Mac\Home\Desktop\日常代码\HighWayIot\HighWayIot.Log4net\bin\Debug\HighWayIot.Log4net.dll
\\Mac\Home\Desktop\日常代码\HighWayIot\HighWayIot.Log4net\bin\Debug\HighWayIot.Log4net.pdb
\\Mac\Home\Desktop\日常代码\HighWayIot\HighWayIot.Log4net\bin\Debug\log4net.dll
\\Mac\Home\Desktop\日常代码\HighWayIot\HighWayIot.Log4net\obj\Debug\HighWayIot.Log4net.csproj.CoreCompileInputs.cache
\\Mac\Home\Desktop\日常代码\HighWayIot\HighWayIot.Log4net\obj\Debug\HighWayIot.Log4net.csproj.CopyComplete
\\Mac\Home\Desktop\日常代码\HighWayIot\HighWayIot.Log4net\obj\Debug\HighWayIot.Log4net.dll
\\Mac\Home\Desktop\日常代码\HighWayIot\HighWayIot.Log4net\obj\Debug\HighWayIot.Log4net.pdb
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Log4net\bin\Debug\HighWayIot.Log4net.dll
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Log4net\bin\Debug\HighWayIot.Log4net.pdb
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Log4net\bin\Debug\log4net.dll
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Log4net\obj\Debug\HighWayIot.Log4net.csproj.AssemblyReference.cache
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Log4net\obj\Debug\HighWayIot.Log4net.csproj.CoreCompileInputs.cache
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Log4net\obj\Debug\HighWayIot.Log4net.csproj.CopyComplete
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Log4net\obj\Debug\HighWayIot.Log4net.dll
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Log4net\obj\Debug\HighWayIot.Log4net.pdb

@ -1,55 +1,55 @@
<?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>{CD9B8712-0E09-42D2-849B-B8EAB02C7AB8}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>HighWayIot.Mqtt</RootNamespace>
<AssemblyName>HighWayIot.Mqtt</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</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>..\HighWayIot.Library\log4net.dll</HintPath>
</Reference>
<Reference Include="MQTTnet">
<HintPath>..\HighWayIot.Library\MQTTnet.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="MqttClient.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<?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>{CD9B8712-0E09-42D2-849B-B8EAB02C7AB8}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>HighWayIot.Mqtt</RootNamespace>
<AssemblyName>HighWayIot.Mqtt</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</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>..\HighWayIot.Library\log4net.dll</HintPath>
</Reference>
<Reference Include="MQTTnet">
<HintPath>..\HighWayIot.Library\MQTTnet.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="MqttClient.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -1,153 +1,153 @@
using MQTTnet.Client;
using MQTTnet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Security.Authentication;
namespace HighWayIot.Mqtt
{
public sealed class MqttClient
{
public delegate void PrintMessageReceived(string message);
public event PrintMessageReceived PrintMessageReceivedEvent;
private IMqttClient client;
private static readonly Lazy<MqttClient> lazy = new Lazy<MqttClient>(() => new MqttClient());
public static MqttClient Instance
{
get
{
return lazy.Value;
}
}
private MqttClient() { }
/// <summary>
/// 链接服务器
/// </summary>
/// <param name="ip"></param>
/// <param name="port"></param>
/// <param name="clientId"></param>
/// <param name="username"></param>
/// <param name="password"></param>
public async void Connect(string ip, int port, string clientId, string username, string password)
{
try
{
MqttClientOptions options = new MqttClientOptionsBuilder()
.WithTcpServer(ip, port)
.WithClientId(clientId)
.WithCredentials(username, password)
.WithTls(o => //开启ssl
{
o.CertificateValidationHandler = _ => true;
o.SslProtocol = SslProtocols.Tls12;
}).Build();
client = new MqttFactory().CreateMqttClient();
client.ApplicationMessageReceivedAsync += MqttClient_ApplicationMessageReceived;
MqttClientConnectResult result = await client.ConnectAsync(options);
if (result != null)
{
if (result.ResultCode == MQTTnet.Client.MqttClientConnectResultCode.Success)
{
PrintMessageReceivedEvent?.Invoke($"连接服务器成功{ip}:{port}");
}
else
{
PrintMessageReceivedEvent?.Invoke($"连接服务器失败");
}
}
}
catch (Exception ex)
{
PrintMessageReceivedEvent?.Invoke($"连接服务器异常:{ex.Message}");
}
}
/// <summary>
/// 断开链接
/// </summary>
public void DisConnect()
{
client.DisconnectAsync();
PrintMessageReceivedEvent?.Invoke($"断开连接");
}
/// <summary>
/// 订阅主题
/// </summary>
/// <param name="topic"></param>
public async void SubscriptionAsync(string topic)
{
try
{
var mqttFactory = new MqttFactory();
var mqttSubscribeOptions = mqttFactory.CreateSubscribeOptionsBuilder()
.WithTopicFilter(
f =>
{
f.WithTopic(topic);
})
.Build();
MqttClientSubscribeResult result = await client.SubscribeAsync(mqttSubscribeOptions, CancellationToken.None);
PrintMessageReceivedEvent?.Invoke($"订阅主题:{topic}");
}
catch (Exception ex)
{
PrintMessageReceivedEvent?.Invoke($"订阅主题异常:{ex.Message}");
}
}
/// <summary>
/// 取消订阅
/// </summary>
/// <param name="topic"></param>
public void Unsubscribe(string topic)
{
client.UnsubscribeAsync(topic);
PrintMessageReceivedEvent?.Invoke($"取消订阅,主题:{topic}");
}
/// <summary>
/// 推送消息
/// </summary>
/// <param name="topic"></param>
/// <param name="message"></param>
public void Publish(string topic, string message)
{
try
{
var msg = new MqttApplicationMessageBuilder().WithTopic(topic).WithPayload(message)
.Build();
client.PublishAsync(msg, CancellationToken.None);
PrintMessageReceivedEvent?.Invoke($"向服务端推送成功,主题:{topic};内容:{message}");
}
catch (Exception ex)
{
PrintMessageReceivedEvent?.Invoke($"向服务端推送消息异常:{ex.Message}");
}
}
private async Task MqttClient_ApplicationMessageReceived(MqttApplicationMessageReceivedEventArgs eventArgs)
{
var info = $"接收到主题:{eventArgs.ApplicationMessage.Topic}的消息,内容:{Encoding.UTF8.GetString(eventArgs.ApplicationMessage.Payload)}";
PrintMessageReceivedEvent?.Invoke(info);
}
}
using MQTTnet.Client;
using MQTTnet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Security.Authentication;
namespace HighWayIot.Mqtt
{
public sealed class MqttClient
{
public delegate void PrintMessageReceived(string message);
public event PrintMessageReceived PrintMessageReceivedEvent;
private IMqttClient client;
private static readonly Lazy<MqttClient> lazy = new Lazy<MqttClient>(() => new MqttClient());
public static MqttClient Instance
{
get
{
return lazy.Value;
}
}
private MqttClient() { }
/// <summary>
/// 链接服务器
/// </summary>
/// <param name="ip"></param>
/// <param name="port"></param>
/// <param name="clientId"></param>
/// <param name="username"></param>
/// <param name="password"></param>
public async void Connect(string ip, int port, string clientId, string username, string password)
{
try
{
MqttClientOptions options = new MqttClientOptionsBuilder()
.WithTcpServer(ip, port)
.WithClientId(clientId)
.WithCredentials(username, password)
.WithTls(o => //开启ssl
{
o.CertificateValidationHandler = _ => true;
o.SslProtocol = SslProtocols.Tls12;
}).Build();
client = new MqttFactory().CreateMqttClient();
client.ApplicationMessageReceivedAsync += MqttClient_ApplicationMessageReceived;
MqttClientConnectResult result = await client.ConnectAsync(options);
if (result != null)
{
if (result.ResultCode == MQTTnet.Client.MqttClientConnectResultCode.Success)
{
PrintMessageReceivedEvent?.Invoke($"连接服务器成功{ip}:{port}");
}
else
{
PrintMessageReceivedEvent?.Invoke($"连接服务器失败");
}
}
}
catch (Exception ex)
{
PrintMessageReceivedEvent?.Invoke($"连接服务器异常:{ex.Message}");
}
}
/// <summary>
/// 断开链接
/// </summary>
public void DisConnect()
{
client.DisconnectAsync();
PrintMessageReceivedEvent?.Invoke($"断开连接");
}
/// <summary>
/// 订阅主题
/// </summary>
/// <param name="topic"></param>
public async void SubscriptionAsync(string topic)
{
try
{
var mqttFactory = new MqttFactory();
var mqttSubscribeOptions = mqttFactory.CreateSubscribeOptionsBuilder()
.WithTopicFilter(
f =>
{
f.WithTopic(topic);
})
.Build();
MqttClientSubscribeResult result = await client.SubscribeAsync(mqttSubscribeOptions, CancellationToken.None);
PrintMessageReceivedEvent?.Invoke($"订阅主题:{topic}");
}
catch (Exception ex)
{
PrintMessageReceivedEvent?.Invoke($"订阅主题异常:{ex.Message}");
}
}
/// <summary>
/// 取消订阅
/// </summary>
/// <param name="topic"></param>
public void Unsubscribe(string topic)
{
client.UnsubscribeAsync(topic);
PrintMessageReceivedEvent?.Invoke($"取消订阅,主题:{topic}");
}
/// <summary>
/// 推送消息
/// </summary>
/// <param name="topic"></param>
/// <param name="message"></param>
public void Publish(string topic, string message)
{
try
{
var msg = new MqttApplicationMessageBuilder().WithTopic(topic).WithPayload(message)
.Build();
client.PublishAsync(msg, CancellationToken.None);
PrintMessageReceivedEvent?.Invoke($"向服务端推送成功,主题:{topic};内容:{message}");
}
catch (Exception ex)
{
PrintMessageReceivedEvent?.Invoke($"向服务端推送消息异常:{ex.Message}");
}
}
private async Task MqttClient_ApplicationMessageReceived(MqttApplicationMessageReceivedEventArgs eventArgs)
{
var info = $"接收到主题:{eventArgs.ApplicationMessage.Topic}的消息,内容:{Encoding.UTF8.GetString(eventArgs.ApplicationMessage.Payload)}";
PrintMessageReceivedEvent?.Invoke(info);
}
}
}

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

@ -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,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]

@ -0,0 +1,27 @@
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Mqtt\bin\Debug\HighWayIot.Mqtt.dll
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Mqtt\bin\Debug\HighWayIot.Mqtt.pdb
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Mqtt\bin\Debug\log4net.dll
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Mqtt\obj\Debug\HighWayIot.Mqtt.csproj.AssemblyReference.cache
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Mqtt\obj\Debug\HighWayIot.Mqtt.csproj.CoreCompileInputs.cache
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Mqtt\obj\Debug\HighWayIot.Mqtt.csproj.CopyComplete
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Mqtt\obj\Debug\HighWayIot.Mqtt.dll
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Mqtt\obj\Debug\HighWayIot.Mqtt.pdb
Z:\Desktop\日常代码\HighWayIot\HighWayIot.Mqtt\bin\Debug\MQTTnet.dll
\\Mac\Home\Desktop\日常代码\HighWayIot\HighWayIot.Mqtt\bin\Debug\HighWayIot.Mqtt.dll
\\Mac\Home\Desktop\日常代码\HighWayIot\HighWayIot.Mqtt\bin\Debug\HighWayIot.Mqtt.pdb
\\Mac\Home\Desktop\日常代码\HighWayIot\HighWayIot.Mqtt\bin\Debug\log4net.dll
\\Mac\Home\Desktop\日常代码\HighWayIot\HighWayIot.Mqtt\bin\Debug\MQTTnet.dll
\\Mac\Home\Desktop\日常代码\HighWayIot\HighWayIot.Mqtt\obj\Debug\HighWayIot.Mqtt.csproj.AssemblyReference.cache
\\Mac\Home\Desktop\日常代码\HighWayIot\HighWayIot.Mqtt\obj\Debug\HighWayIot.Mqtt.csproj.CoreCompileInputs.cache
\\Mac\Home\Desktop\日常代码\HighWayIot\HighWayIot.Mqtt\obj\Debug\HighWayIot.Mqtt.csproj.CopyComplete
\\Mac\Home\Desktop\日常代码\HighWayIot\HighWayIot.Mqtt\obj\Debug\HighWayIot.Mqtt.dll
\\Mac\Home\Desktop\日常代码\HighWayIot\HighWayIot.Mqtt\obj\Debug\HighWayIot.Mqtt.pdb
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Mqtt\bin\Debug\HighWayIot.Mqtt.dll
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Mqtt\bin\Debug\HighWayIot.Mqtt.pdb
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Mqtt\bin\Debug\log4net.dll
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Mqtt\bin\Debug\MQTTnet.dll
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Mqtt\obj\Debug\HighWayIot.Mqtt.csproj.AssemblyReference.cache
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Mqtt\obj\Debug\HighWayIot.Mqtt.csproj.CoreCompileInputs.cache
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Mqtt\obj\Debug\HighWayIot.Mqtt.csproj.CopyComplete
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Mqtt\obj\Debug\HighWayIot.Mqtt.dll
C:\项目代码\澳柯玛MES项目\HighWayIot\HighWayIot.Mqtt\obj\Debug\HighWayIot.Mqtt.pdb

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

Loading…
Cancel
Save