添加项目文件。

master
wenjy 2 years ago
parent bf62f13b49
commit edb1c8f0d5

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{8E2E1A40-99D9-4488-A4D1-6708B845E555}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FileDataUpload.Common</RootNamespace>
<AssemblyName>FileDataUpload.Common</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net, Version=2.0.15.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.15\lib\net45\log4net.dll</HintPath>
</Reference>
<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.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<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="INIFile.cs" />
<Compile Include="JsonChange.cs" />
<Compile Include="LogHelper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="log4net.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -0,0 +1,109 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace FileDataUpload.Common
{
/// <summary>
/// 配置操作类
/// </summary>
public class INIFile
{
private string skey = "?S?)??[I";
public string path;
public INIFile(string INIPath)
{
path = INIPath;
}
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string defVal, Byte[] retVal, int size, string filePath);
[DllImport("kernel32", EntryPoint = "GetPrivateProfileString")]
private static extern uint GetPrivateProfileStringA(string section, string key, string def, Byte[] retVal, int size, string filePath);
/// <summary>
/// 写INI文件
/// </summary>
/// <param name="Section"></param>
/// <param name="Key"></param>
/// <param name="Value"></param>
public void IniWriteValue(string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, this.path);
}
/// <summary>
/// 读取INI文件
/// </summary>
/// <param name="Section"></param>
/// <param name="Key"></param>
/// <returns></returns>
public string IniReadValue(string Section, string Key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path);
//return temp.ToString();
string str = temp.ToString();
return str;
}
public byte[] IniReadValues(string section, string key)
{
byte[] temp = new byte[255];
int i = GetPrivateProfileString(section, key, "", temp, 255, this.path);
return temp;
}
/// <summary>
/// 删除ini文件下所有段落
/// </summary>
public void ClearAllSection()
{
IniWriteValue(null, null, null);
}
/// <summary>
/// 删除ini文件下personal段落下的所有键
/// </summary>
/// <param name="Section"></param>
public void ClearSection(string Section)
{
IniWriteValue(Section, null, null);
}
public List<string> ReadKeys(String SectionName)
{
return ReadKeys(SectionName, this.path);
}
public List<string> ReadKeys(string SectionName, string iniFilename)
{
List<string> result = new List<string>();
Byte[] buf = new Byte[65536];
uint len = GetPrivateProfileStringA(SectionName, null, null, buf, buf.Length, iniFilename);
int j = 0;
for (int i = 0; i < len; i++)
if (buf[i] == 0)
{
result.Add(Encoding.Default.GetString(buf, j, i - j));
j = i + 1;
}
return result;
}
}
}

@ -0,0 +1,113 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Xml.Linq;
namespace FileDataUpload.Common
{
public class JsonChange
{
private static readonly Lazy<JsonChange> lazy = new Lazy<JsonChange>(() => new JsonChange());
public static JsonChange Instance
{
get
{
return lazy.Value;
}
}
private JsonChange() { }
/// <summary>
/// Model 实体转json
/// </summary>
/// <param name="Model">可以是单个实体也可是实体集ToList()</param>
/// <returns></returns>
public string ModeToJson(object Model)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
try
{
string str = serializer.Serialize(Model);
return str;
}
catch (Exception)
{
return "";
}
}
/// <summary>
/// json实体转Model
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="jsonStr"></param>
/// <returns></returns>
public T JsonToMode<T>(string jsonStr)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
try
{
var info = serializer.Deserialize<T>(jsonStr);
return info;
}
catch (Exception)
{
return default(T);
}
}
/// <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;
}
}
}

@ -0,0 +1,135 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FileDataUpload.Common
{
public sealed class LogHelper
{
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 static readonly Lazy<LogHelper> lazy = new Lazy<LogHelper>(() => new LogHelper());
public static LogHelper Instance
{
get
{
return lazy.Value;
}
}
private LogHelper() { }
/// <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;
}
}
}

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

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

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

@ -0,0 +1,120 @@
using FileDataUpload.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace FileDataUpload.Entity
{
public sealed class AppConfig
{
private static INIFile iNIFile = new INIFile(System.Environment.CurrentDirectory + "/App.InI");
private static readonly Lazy<AppConfig> lazy = new Lazy<AppConfig>(() => new AppConfig());
public static AppConfig Instance
{
get
{
return lazy.Value;
}
}
private AppConfig() { }
//public int pushFlag_RivetingRing = Convert.ToInt32(iNIFile.IniReadValue("system", "pushFlag_RivetingRing"));
//public int pushFlag_Stopper = Convert.ToInt32(iNIFile.IniReadValue("system", "pushFlag_Stopper"));
//public int pushFlag_displacingValve = Convert.ToInt32(iNIFile.IniReadValue("system", "pushFlag_displacingValve"));
/// <summary>
/// 铆压环 推送标志位
/// </summary>
public int pushFlag_RivetingRing
{
get { return Convert.ToInt32(iNIFile.IniReadValue("system", "pushFlag_RivetingRing")); }
set { iNIFile.IniWriteValue("system", "pushFlag_RivetingRing", value.ToString()); }
}
/// <summary>
/// 限位器 推送标志位
/// </summary>
public int pushFlag_Stopper
{
get { return Convert.ToInt32(iNIFile.IniReadValue("system", "pushFlag_Stopper")); }
set { iNIFile.IniWriteValue("system", "pushFlag_Stopper", value.ToString()); }
}
/// <summary>
/// 排气阀片 推送标志位
/// </summary>
public int pushFlag_displacingValve
{
get { return Convert.ToInt32(iNIFile.IniReadValue("system", "pushFlag_displacingValve")); }
set { iNIFile.IniWriteValue("system", "pushFlag_displacingValve", value.ToString()); }
}
public string filePath
{
get { return iNIFile.IniReadValue("system", "filePath"); }
set { iNIFile.IniWriteValue("system", "filePath", value); }
}
public string fileType
{
get { return iNIFile.IniReadValue("system", "fileType"); }
}
public string 线
{
get { return iNIFile.IniReadValue("system", "产线"); }
set { iNIFile.IniWriteValue("system", "产线", value); }
}
public string
{
get { return iNIFile.IniReadValue("system", "物料编号"); }
set { iNIFile.IniWriteValue("system", "物料编号", value); }
}
public string
{
get { return iNIFile.IniReadValue("system", "生产条码"); }
set { iNIFile.IniWriteValue("system", "生产条码", value); }
}
public string
{
get { return iNIFile.IniReadValue("system", "设备编码"); }
set { iNIFile.IniWriteValue("system", "设备编码", value); }
}
public string
{
get { return iNIFile.IniReadValue("system", "测试总结果"); }
set { iNIFile.IniWriteValue("system", "测试总结果", value); }
}
public string
{
get { return iNIFile.IniReadValue("system", "当日生产总数"); }
set { iNIFile.IniWriteValue("system", "当日生产总数", value); }
}
public string
{
get { return iNIFile.IniReadValue("system", "当日生产不良数"); }
set { iNIFile.IniWriteValue("system", "当日生产不良数", value); }
}
public string
{
get { return iNIFile.IniReadValue("system", "班次"); }
set { iNIFile.IniWriteValue("system", "班次", value); }
}
}
}

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FileDataUpload.Entity
{
public class DeviceParam
{
public string id { get; set; }
public ParamData data { get; set; }
}
}

@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FileDataUpload.Entity
{
/// <summary>
/// 参数信息
/// </summary>
public class DeviceParameterInfo
{
/// <summary>
/// 公司名称
/// </summary>
public string companyName { get; set; }
/// <summary>
/// 工件名称
/// </summary>
public string partName { get; set; }
/// <summary>
/// 工件编号
/// </summary>
public string partNumber { get; set; }
/// <summary>
/// 操作人员
/// </summary>
public string operatingPersonnel { get; set; }
/// <summary>
/// 参数值
/// </summary>
public List<DeviceParametersValue> deviceParametersValues { get; set; }
}
}

@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FileDataUpload.Entity
{
/// <summary>
/// 设备参数值
/// </summary>
public class DeviceParametersValue
{
/// <summary>
/// 参数编号
/// </summary>
public string paramNumber { get; set; }
/// <summary>
/// 内容
/// </summary>
public string paramContent { get; set; }
/// <summary>
/// 测量值
/// </summary>
public object observedValue { get; set; }
/// <summary>
/// 名义值
/// </summary>
public object nominalValue { get; set; }
/// <summary>
/// 超差值
/// </summary>
public object overproofValue { get; set; }
/// <summary>
/// 上公差
/// </summary>
public object upperDeviation { get; set; }
/// <summary>
/// 下公差
/// </summary>
public object lowerDeviation { get; set; }
/// <summary>
/// 状态
/// </summary>
public string state { get; set; }
}
}

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E7158B5C-2C09-432E-83AC-7D2C065E664F}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FileDataUpload.Entity</RootNamespace>
<AssemblyName>FileDataUpload.Entity</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AppConfig.cs" />
<Compile Include="DeviceParam.cs" />
<Compile Include="DeviceParameterInfo.cs" />
<Compile Include="DeviceParametersValue.cs" />
<Compile Include="ParamData.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PropertyValue.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FileDataUpload.Common\FileDataUpload.Common.csproj">
<Project>{8e2e1a40-99d9-4488-a4d1-6708b845e555}</Project>
<Name>FileDataUpload.Common</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FileDataUpload.Entity
{
public class ParamData
{
/// <summary>
///
/// </summary>
public string deviceCode { get; set; }
/// <summary>
///
/// </summary>
public string propertyCode { get; set; }
/// <summary>
///
/// </summary>
public int dataType { get; set; }
/// <summary>
///
/// </summary>
public object propertyValue { get; set; }
/// <summary>
///
/// </summary>
public string time { get; set; }
}
}

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

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FileDataUpload.Entity
{
public class PropertyValue
{
/// <summary>
///
/// </summary>
public string DEVICE_NAME { get; set; }
/// <summary>
///
/// </summary>
public string CHECK_ITEM { get; set; }
/// <summary>
///
/// </summary>
public string ITEM_VALUE { get; set; }
/// <summary>
///
/// </summary>
public string ACCURACYVALUE { get; set; }
/// <summary>
///
/// </summary>
public string STANDARDVALUE { get; set; }
/// <summary>
///
/// </summary>
public string STANDARDMAX { get; set; }
/// <summary>
///
/// </summary>
public string STANDARDMIN { get; set; }
/// <summary>
///
/// </summary>
public string TEST_STATUS { get; set; }
/// <summary>
///
/// </summary>
public string UOM { get; set; }
/// <summary>
///
/// </summary>
public string TEST_DETAIL_ID { get; set; }
}
}

@ -0,0 +1,66 @@
<?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>{000F3ED7-6A2F-44C6-A31A-DA0FD0C66061}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FileDataUpload.FileOperate</RootNamespace>
<AssemblyName>FileDataUpload.FileOperate</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="MiniExcel, Version=1.30.2.0, Culture=neutral, PublicKeyToken=e7310002a53eac39, processorArchitecture=MSIL">
<HintPath>..\packages\MiniExcel.1.30.2\lib\net45\MiniExcel.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<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="FileHelper.cs" />
<Compile Include="MonitorEngine.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FileDataUpload.Common\FileDataUpload.Common.csproj">
<Project>{8E2E1A40-99D9-4488-A4D1-6708B845E555}</Project>
<Name>FileDataUpload.Common</Name>
</ProjectReference>
<ProjectReference Include="..\FileDataUpload.Entity\FileDataUpload.Entity.csproj">
<Project>{E7158B5C-2C09-432E-83AC-7D2C065E664F}</Project>
<Name>FileDataUpload.Entity</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -0,0 +1,421 @@
using FileDataUpload.Common;
using FileDataUpload.Entity;
using MiniExcelLibs;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace FileDataUpload.FileOperate
{
public sealed class FileHelper
{
private int paramBeginRowNumber = 6;
private readonly JsonChange jsonChange = JsonChange.Instance;
private readonly LogHelper logHelper = LogHelper.Instance;
private AppConfig appConfig = AppConfig.Instance;
private static readonly Lazy<FileHelper> lazy = new Lazy<FileHelper>(() => new FileHelper());
public static FileHelper Instance
{
get
{
return lazy.Value;
}
}
private FileHelper() { }
[Obsolete]
public Dictionary<string, List<DeviceParam>> ReadExcelFile_New(string filePath)
{
try
{
Dictionary<string, List<DeviceParam>> keyValues = new Dictionary<string, List<DeviceParam>>();
var sheetNames = MiniExcel.GetSheetNames(filePath);
foreach (var sheetName in sheetNames)
{
List<DeviceParam> deviceParams = new List<DeviceParam>();
DeviceParam parameterInfo = new DeviceParam();
List<dynamic> info = MiniExcel.Query(filePath, sheetName: sheetName).ToList();
if (info != null && info.Count() > paramBeginRowNumber)
{
for(int i=8; i<16; i++)
{
DeviceParam deviceParam = new DeviceParam();
deviceParam.id = System.Guid.NewGuid().ToString("N");
ParamData param = new ParamData();
param.deviceCode = "EVtest";
param.propertyCode = info[i].C;
param.dataType = GetDataType(info[16].F == null ? "Text" : info[16].F);
param.propertyValue = info[i].E;
param.time = GetTimeStamp();
deviceParam.data = param;
deviceParams.Add(deviceParam);
}
DeviceParam deviceParam_17 = new DeviceParam();
deviceParam_17.id = System.Guid.NewGuid().ToString("N");
ParamData param_17 = new ParamData();
param_17.deviceCode = "EVtest";
param_17.propertyCode = info[17].C;
param_17.dataType = 5;
List<PropertyValue> propertyValues = new List<PropertyValue>();
//tag9 监测明细
for (int i = 17; i < info.Count();)
{
if (string.IsNullOrEmpty((string)info[i].D))
{
i = i + 6;
continue;
}
else
{
PropertyValue propertyValue = new PropertyValue();
propertyValue.CHECK_ITEM = MidStrEx_New((string)info[i].D, "-", "-");
propertyValue.ITEM_VALUE = info[i].E == null ? " " : string.Format("{0}",info[i].E);
propertyValue.TEST_STATUS = info[i + 1].E == null ? " " : string.Format("{0}", info[i + 1].E);
propertyValue.STANDARDVALUE = info[i + 2].E == null ? " " : string.Format("{0}", info[i + 2].E);
propertyValue.STANDARDMAX = info[i + 3].E == null ? " " : string.Format("{0}", info[i + 3].E);
propertyValue.STANDARDMIN = info[i + 4].E == null ? " " : string.Format("{0}", info[i + 4].E);
propertyValue.TEST_DETAIL_ID = System.Guid.NewGuid().ToString("N");
//空值处理
propertyValue.DEVICE_NAME = "";
propertyValue.ACCURACYVALUE = "";
propertyValue.UOM = "";
propertyValues.Add(propertyValue);
i = i + 6;
}
}
param_17.propertyValue = jsonChange.ModeToJson(propertyValues);
param_17.time = GetTimeStamp();
deviceParam_17.data = param_17;
deviceParams.Add(deviceParam_17);
//推送标志位
DeviceParam deviceParam_16 = new DeviceParam();
deviceParam_16.id = System.Guid.NewGuid().ToString("N");
ParamData param_16 = new ParamData();
param_16.deviceCode = "EVtest";
param_16.propertyCode = info[16].C;
param_16.dataType = GetDataType(info[16].F == null ? "Text" : info[16].F);
param_16.propertyValue = info[16].E == null ? "":info[16].E;
param_16.time = GetTimeStamp();
deviceParam_16.data = param_16;
deviceParams.Add(deviceParam_16);
}
keyValues.Add(sheetName, deviceParams);
}
return keyValues;
}
catch (Exception ex)
{
logHelper.Error("文件解析异常", ex);
return null;
}
}
[Obsolete]
public Dictionary<string, List<DeviceParam>> ReadExcelFile(string filePath)
{
try
{
List<DeviceParameterInfo> result = new List<DeviceParameterInfo>();
var sheetNames = MiniExcel.GetSheetNames(filePath);
foreach (var sheetName in sheetNames)
{
DeviceParameterInfo parameterInfo = new DeviceParameterInfo();
List<dynamic> info = MiniExcel.Query(filePath, sheetName: sheetName).ToList();
var rows = MiniExcel.Query(filePath, sheetName: sheetName);
//避免读取数据为空的工作表
if (info != null && info.Count() > paramBeginRowNumber)
{
//获取前两行参数公司名称B、工件名称E、工件编号B、操作人员E
parameterInfo.companyName = info[0].B;
parameterInfo.partName = info[0].E;
parameterInfo.partNumber = info[1].B;
parameterInfo.operatingPersonnel = info[2].E;
List<DeviceParametersValue> values = new List<DeviceParametersValue>();
var deviceParams = info.GetRange(paramBeginRowNumber, info.Count() - paramBeginRowNumber);
if (deviceParams == null) continue;
foreach (var item in deviceParams)
{
DeviceParametersValue parametersValue = new DeviceParametersValue();
if (item.A as string == null) continue;
parametersValue.paramNumber = item.A as string;
parametersValue.paramContent = item.B as string;
#region 备份修改 将double转为object
/*parametersValue.observedValue = item.C == null ? 0 : item.C;
parametersValue.nominalValue = item.D == null ? 0 : item.D;
parametersValue.overproofValue = item.E == null ? 0 : item.E;
parametersValue.upperDeviation = item.F == null ? 0 : item.F;
parametersValue.lowerDeviation = item.G == null ? 0 : item.G;
parametersValue.state = item.H as string;*/
#endregion
parametersValue.observedValue = string.IsNullOrEmpty(item.C) ? 0 : item.C;
parametersValue.nominalValue = string.IsNullOrEmpty(item.D)? 0 : item.D;
parametersValue.overproofValue = string.IsNullOrEmpty(item.E) ? 0 : item.E;
parametersValue.upperDeviation = string.IsNullOrEmpty(item.F) ? 0 : item.F;
parametersValue.lowerDeviation = string.IsNullOrEmpty(item.G) ? 0 : item.G;
parametersValue.state = item.H as string;
values.Add(parametersValue);
}
parameterInfo.deviceParametersValues = values;
}
else
{
continue;
}
result.Add(parameterInfo);
}
return formatFileData(result);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 格式化文件数据
/// </summary>
/// <returns></returns>
private Dictionary<string, List<DeviceParam>> formatFileData(List<DeviceParameterInfo> parameterInfos)
{
Dictionary<string, List<DeviceParam>> keyValues = new Dictionary<string, List<DeviceParam>>();
if (parameterInfos.Count == 0) return null;
foreach (var infos in parameterInfos)
{
List<DeviceParam> deviceParams = new List<DeviceParam>();
//add tag1-8、tag10
for (int i = 1; i < 9; i++)
{
DeviceParam deviceParam2 = new DeviceParam();
deviceParam2.id = System.Guid.NewGuid().ToString("N");
ParamData param2 = new ParamData();
param2.deviceCode = "EVtest";
param2.propertyCode = $"tag{i}";
param2.dataType = 5;
param2.propertyValue = getNodeValue(param2.propertyCode);
param2.time = GetTimeStamp();
deviceParam2.data = param2;
deviceParams.Add(deviceParam2);
}
DeviceParam deviceParam = new DeviceParam();
deviceParam.id = System.Guid.NewGuid().ToString("N");
ParamData param = new ParamData();
param.propertyCode = "tag9";
param.dataType = 5;
var ParametersValues = infos.deviceParametersValues;
List<PropertyValue> propertyValues = new List<PropertyValue>();
//tag9 监测明细
foreach (var item in ParametersValues)
{
PropertyValue propertyValue = new PropertyValue();
propertyValue.CHECK_ITEM = string.IsNullOrEmpty(item.paramContent) ? "" : item.paramContent;
propertyValue.ITEM_VALUE = string.IsNullOrEmpty(item.nominalValue.ToString()) ? "" : item.nominalValue.ToString();
propertyValue.ACCURACYVALUE = string.IsNullOrEmpty(item.observedValue.ToString()) ? "" : item.observedValue.ToString();
propertyValue.TEST_STATUS = string.IsNullOrEmpty(item.state) ? "" : item.state;
propertyValue.STANDARDVALUE = string.IsNullOrEmpty(item.overproofValue.ToString()) ? "" : item.overproofValue.ToString();
propertyValue.STANDARDMAX = string.IsNullOrEmpty(item.upperDeviation.ToString()) ? "" : item.upperDeviation.ToString();
propertyValue.STANDARDMIN = string.IsNullOrEmpty(item.lowerDeviation.ToString()) ? "" : item.lowerDeviation.ToString();
propertyValue.TEST_DETAIL_ID = System.Guid.NewGuid().ToString("N");
//空值处理
propertyValue.DEVICE_NAME = "";
propertyValue.UOM = "";
propertyValues.Add(propertyValue);
}
param.propertyValue = jsonChange.ModeToJson(propertyValues);
//param.propertyValue = propertyValues;
param.time = GetTimeStamp();
deviceParam.data = param;
deviceParams.Add(deviceParam);
//推送标志位
DeviceParam deviceParam_16 = new DeviceParam();
deviceParam_16.id = System.Guid.NewGuid().ToString("N");
ParamData param_16 = new ParamData();
param_16.deviceCode = "EVtest";
param_16.propertyCode = "tag10";
param_16.dataType = 5;
param_16.propertyValue = "";
param_16.time = GetTimeStamp();
deviceParam_16.data = param_16;
deviceParams.Add(deviceParam_16);
keyValues.Add("排气阀片", deviceParams);
}
return keyValues;
}
private string getNodeValue(string nodeStr)
{
string info = "";
switch(nodeStr)
{
case "tag1":
info = appConfig.线;
break;
case "tag2":
info = appConfig.;
break;
case "tag3":
info = appConfig.;
break;
case "tag4":
info = appConfig.;
break;
case "tag5":
info = appConfig.;
break;
case "tag6":
info = appConfig.;
break;
case "tag7":
info = appConfig.;
break;
case "tag8":
info = appConfig.;
break;
}
return info;
}
private string getNodeName(string nodeStr)
{
string info = "";
switch (nodeStr)
{
case "tag1":
info = "产线";
break;
case "tag2":
info = "物料编号";
break;
case "tag3":
info = "生产条码";
break;
case "tag4":
info = "设备编码";
break;
case "tag5":
info = "测试总结果";
break;
case "tag6":
info = "当日生产总数";
break;
case "tag7":
info = "当日生产不良数";
break;
case "tag8":
info = "班次";
break;
}
return info;
}
/// <summary>
/// 获取时间戳
/// </summary>
/// <returns></returns>
private string GetTimeStamp()
{
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
return Convert.ToInt64(ts.TotalMilliseconds).ToString();
}
/// <summary>
/// 字符串截取
/// </summary>
/// <param name="sourse"></param>
/// <param name="startstr"></param>
/// <param name="endstr"></param>
/// <returns></returns>
private string MidStrEx_New(string sourse, string startstr, string endstr)
{
Regex rg = new Regex("(?<=(" + startstr + "))[.\\s\\S]*?(?=(" + endstr + "))", RegexOptions.Multiline | RegexOptions.Singleline);
return rg.Match(sourse).Value;
}
/// <summary>
/// 数据类型
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
private int GetDataType(string str)
{
int result = 5;
switch (str)
{
case "Int32":
result = 0;
break;
case "Float":
result = 1;
break;
case "Double":
result = 2;
break;
case "Bool":
result = 3;
break;
case "Enum":
result = 4;
break;
case "Text":
result = 5;
break;
case "Time":
result = 6;
break;
case "Array":
result = 7;
break;
case "Struct":
result = 8;
break;
default:
result = 5;
break;
}
return result;
}
}
}

@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FileDataUpload.FileOperate
{
public sealed class MonitorEngine
{
public string Path;
public string Filter;
public delegate void FindOneFile(string path);
public event FindOneFile FindOneFileEvent;
private FileSystemWatcher watcher = new FileSystemWatcher();
private static readonly Lazy<MonitorEngine> lazy = new Lazy<MonitorEngine>(() => new MonitorEngine());
public static MonitorEngine Instance
{
get
{
return lazy.Value;
}
}
public MonitorEngine()
{
watcher.Changed += new FileSystemEventHandler(OnProcess);
watcher.Created += new FileSystemEventHandler(OnProcess);
watcher.Deleted += new FileSystemEventHandler(OnProcess);
watcher.Renamed += new RenamedEventHandler(OnRenamed);
watcher.NotifyFilter = NotifyFilters.Attributes | NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastAccess
| NotifyFilters.LastWrite | NotifyFilters.Security | NotifyFilters.Size;
}
/// <summary>
/// 监控文件夹
/// </summary>
/// <param name="path"></param>
/// <param name="filter"></param>
public void WatcherStrat()
{
if (!Directory.Exists(Path))
{
Directory.CreateDirectory(Path);
}
watcher.Path = Path;
watcher.Filter = Filter;
watcher.EnableRaisingEvents = true;
watcher.IncludeSubdirectories = true;
}
public void WatcherStop()
{
watcher.EnableRaisingEvents = false;
watcher.IncludeSubdirectories = false;
}
private void OnProcess(object source, FileSystemEventArgs e)
{
if (e.ChangeType == WatcherChangeTypes.Created)
{
OnCreated(source, e);
}
else if (e.ChangeType == WatcherChangeTypes.Changed)
{
OnChanged(source, e);
}
else if (e.ChangeType == WatcherChangeTypes.Deleted)
{
OnDeleted(source, e);
}
}
private void OnCreated(object source, FileSystemEventArgs e)
{
string TempFilePath = e.FullPath;
if (FindOneFileEvent != null)
{
FindOneFileEvent(TempFilePath);
}
//Console.WriteLine("文件新建事件处理逻辑 {0}  {1}  {2}", e.ChangeType, e.FullPath, e.Name);
}
private void OnChanged(object source, FileSystemEventArgs e)
{
Console.WriteLine("文件改变事件处理逻辑{0}  {1}  {2}", e.ChangeType, e.FullPath, e.Name);
}
private void OnDeleted(object source, FileSystemEventArgs e)
{
Console.WriteLine("文件删除事件处理逻辑{0}  {1}   {2}", e.ChangeType, e.FullPath, e.Name);
}
private void OnRenamed(object source, RenamedEventArgs e)
{
Console.WriteLine("文件重命名事件处理逻辑{0}  {1}  {2}", e.ChangeType, e.FullPath, e.Name);
}
}
}

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

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

@ -0,0 +1,54 @@
<?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>{863E1DDA-4A95-41FB-AFE6-292E9E0E2732}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FileDataUpload.Mqtt</RootNamespace>
<AssemblyName>FileDataUpload.Mqtt</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="MQTTnet, Version=4.1.0.247, Culture=neutral, PublicKeyToken=fdb7629f2e364a63, processorArchitecture=MSIL">
<HintPath>..\packages\MQTTnet.4.1.0.247\lib\net452\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>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -0,0 +1,127 @@
using MQTTnet.Client;
using MQTTnet;
using MQTTnet.Protocol;
using System;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Security.Authentication;
namespace FileDataUpload.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() { }
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 =>
{
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}");
}
}
public void DisConnect()
{
client.DisconnectAsync();
PrintMessageReceivedEvent?.Invoke($"断开连接");
}
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}");
}
}
public void Unsubscribe(string topic)
{
client.UnsubscribeAsync(topic);
PrintMessageReceivedEvent?.Invoke($"取消订阅,主题:{topic}");
}
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);
}
}
}

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

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

@ -0,0 +1,49 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33502.453
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileDataUpload", "FileDataUpload\FileDataUpload.csproj", "{8B936A6B-A96B-4D41-9BA6-BBC9D975ADE7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileDataUpload.FileOperate", "FileDataUpload.FileOperate\FileDataUpload.FileOperate.csproj", "{000F3ED7-6A2F-44C6-A31A-DA0FD0C66061}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileDataUpload.Entity", "FileDataUpload.Entity\FileDataUpload.Entity.csproj", "{E7158B5C-2C09-432E-83AC-7D2C065E664F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileDataUpload.Common", "FileDataUpload.Common\FileDataUpload.Common.csproj", "{8E2E1A40-99D9-4488-A4D1-6708B845E555}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileDataUpload.Mqtt", "FileDataUpload.Mqtt\FileDataUpload.Mqtt.csproj", "{863E1DDA-4A95-41FB-AFE6-292E9E0E2732}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8B936A6B-A96B-4D41-9BA6-BBC9D975ADE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8B936A6B-A96B-4D41-9BA6-BBC9D975ADE7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8B936A6B-A96B-4D41-9BA6-BBC9D975ADE7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8B936A6B-A96B-4D41-9BA6-BBC9D975ADE7}.Release|Any CPU.Build.0 = Release|Any CPU
{000F3ED7-6A2F-44C6-A31A-DA0FD0C66061}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{000F3ED7-6A2F-44C6-A31A-DA0FD0C66061}.Debug|Any CPU.Build.0 = Debug|Any CPU
{000F3ED7-6A2F-44C6-A31A-DA0FD0C66061}.Release|Any CPU.ActiveCfg = Release|Any CPU
{000F3ED7-6A2F-44C6-A31A-DA0FD0C66061}.Release|Any CPU.Build.0 = Release|Any CPU
{E7158B5C-2C09-432E-83AC-7D2C065E664F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E7158B5C-2C09-432E-83AC-7D2C065E664F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E7158B5C-2C09-432E-83AC-7D2C065E664F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E7158B5C-2C09-432E-83AC-7D2C065E664F}.Release|Any CPU.Build.0 = Release|Any CPU
{8E2E1A40-99D9-4488-A4D1-6708B845E555}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8E2E1A40-99D9-4488-A4D1-6708B845E555}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E2E1A40-99D9-4488-A4D1-6708B845E555}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E2E1A40-99D9-4488-A4D1-6708B845E555}.Release|Any CPU.Build.0 = Release|Any CPU
{863E1DDA-4A95-41FB-AFE6-292E9E0E2732}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{863E1DDA-4A95-41FB-AFE6-292E9E0E2732}.Debug|Any CPU.Build.0 = Debug|Any CPU
{863E1DDA-4A95-41FB-AFE6-292E9E0E2732}.Release|Any CPU.ActiveCfg = Release|Any CPU
{863E1DDA-4A95-41FB-AFE6-292E9E0E2732}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F808DDC2-2CBD-4309-9F8A-CACAF7420F6A}
EndGlobalSection
EndGlobal

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>

@ -0,0 +1,15 @@
<Application x:Class="FileDataUpload.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:FileDataUpload"
StartupUri="MainWindow.xaml">
<Application.Resources>
<!--Button样式-->
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="templates/style/Button.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace FileDataUpload
{
/// <summary>
/// App.xaml 的交互逻辑
/// </summary>
public partial class App : Application
{
}
}

@ -0,0 +1,164 @@
<?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>{8B936A6B-A96B-4D41-9BA6-BBC9D975ADE7}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>FileDataUpload</RootNamespace>
<AssemblyName>FileDataUpload</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="CommonServiceLocator, Version=2.0.2.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0, processorArchitecture=MSIL">
<HintPath>..\packages\CommonServiceLocator.2.0.2\lib\net45\CommonServiceLocator.dll</HintPath>
</Reference>
<Reference Include="GalaSoft.MvvmLight, Version=5.4.1.0, Culture=neutral, PublicKeyToken=e7570ab207bcb616, processorArchitecture=MSIL">
<HintPath>..\packages\MvvmLightLibs.5.4.1.1\lib\net45\GalaSoft.MvvmLight.dll</HintPath>
</Reference>
<Reference Include="GalaSoft.MvvmLight.Extras, Version=5.4.1.0, Culture=neutral, PublicKeyToken=669f0b5e8f868abf, processorArchitecture=MSIL">
<HintPath>..\packages\MvvmLightLibs.5.4.1.1\lib\net45\GalaSoft.MvvmLight.Extras.dll</HintPath>
</Reference>
<Reference Include="GalaSoft.MvvmLight.Platform, Version=5.4.1.0, Culture=neutral, PublicKeyToken=5f873c45e98af8a1, processorArchitecture=MSIL">
<HintPath>..\packages\MvvmLightLibs.5.4.1.1\lib\net45\GalaSoft.MvvmLight.Platform.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=2.0.15.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.15\lib\net45\log4net.dll</HintPath>
</Reference>
<Reference Include="MQTTnet, Version=4.1.0.247, Culture=neutral, PublicKeyToken=fdb7629f2e364a63, processorArchitecture=MSIL">
<HintPath>..\packages\MQTTnet.4.1.0.247\lib\net452\MQTTnet.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Web" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\MvvmLightLibs.5.4.1.1\lib\net45\System.Windows.Interactivity.dll</HintPath>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="SysConfigWindw.xaml.cs">
<DependentUpon>SysConfigWindw.xaml</DependentUpon>
</Compile>
<Compile Include="viewModel\MainWindowViewModel.cs" />
<Compile Include="viewModel\SystemConfigViewModel.cs" />
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="SysConfigWindw.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="templates\style\Button.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Resource Include="templates\icon\fileIcon.ico" />
</ItemGroup>
<ItemGroup>
<Resource Include="templates\icon\fileIcon.png" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FileDataUpload.Common\FileDataUpload.Common.csproj">
<Project>{8e2e1a40-99d9-4488-a4d1-6708b845e555}</Project>
<Name>FileDataUpload.Common</Name>
</ProjectReference>
<ProjectReference Include="..\FileDataUpload.Entity\FileDataUpload.Entity.csproj">
<Project>{E7158B5C-2C09-432E-83AC-7D2C065E664F}</Project>
<Name>FileDataUpload.Entity</Name>
</ProjectReference>
<ProjectReference Include="..\FileDataUpload.FileOperate\FileDataUpload.FileOperate.csproj">
<Project>{000F3ED7-6A2F-44C6-A31A-DA0FD0C66061}</Project>
<Name>FileDataUpload.FileOperate</Name>
</ProjectReference>
<ProjectReference Include="..\FileDataUpload.Mqtt\FileDataUpload.Mqtt.csproj">
<Project>{863e1dda-4a95-41fb-afe6-292e9e0e2732}</Project>
<Name>FileDataUpload.Mqtt</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -0,0 +1,103 @@
<Window x:Class="FileDataUpload.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:FileDataUpload"
mc:Ignorable="d"
Title="文件数据上传" Height="500" Width="650"
Icon="/templates/icon/fileIcon.ico" Loaded="Window_Loaded">
<!--ResizeMode="CanMinimize"-->
<Border Margin="5" Background="White" CornerRadius="10">
<Border.Effect>
<DropShadowEffect Color="Gray" ShadowDepth="0" BlurRadius="5" Opacity="0.3" Direction="0"></DropShadowEffect>
</Border.Effect>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="150"/>
<RowDefinition Height="300"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--顶部 菜单栏-->
<StackPanel Grid.Row="0">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Left" Orientation="Horizontal">
<Label Content="服务IP" Height="30" FontSize="18" Foreground="#007DFA" Width="75" />
<TextBox Text="{Binding BorkerIp}" Height="28" Width="150" FontSize="16" Foreground="#007DFA" Margin="0,0,10,0"/>
<Label Content="端口号:" Height="30" FontSize="18" Foreground="#007DFA" Width="75" />
<TextBox Text="{Binding BorkerPort}" Height="28" Width="90" FontSize="16" Foreground="#007DFA" Margin="0,0,10,0"/>
<Label Content="客户端Id" Height="30" FontSize="18" Foreground="#007DFA" Width="90" />
<TextBox Text="{Binding ClientId}" Height="28" Width="120" FontSize="16" Foreground="#007DFA"/>
</StackPanel>
<StackPanel Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Left" Orientation="Horizontal">
<!--<Label Content="用户名:" Height="30" FontSize="18" Foreground="#007DFA" Width="80" />
<TextBox Text="{Binding UserName}" Height="28" Width="95" FontSize="16" Foreground="#007DFA" Margin="0,0,10,0"/>
<Label Content="密码:" Height="30" FontSize="18" Foreground="#007DFA" Width="60" />
<TextBox Text="{Binding Password}" Height="28" Width="95" FontSize="16" Foreground="#007DFA" Margin="0,0,10,0"/>
<Label Content="主题:" Height="30" FontSize="18" Foreground="#007DFA" Width="80" />
<TextBox Text="{Binding Topical}" Height="28" Width="190" FontSize="16" Foreground="#007DFA"/>-->
<Label Content="监测路径:" Height="30" FontSize="18" Foreground="#007DFA" Width="80" />
<TextBox IsReadOnly="True" Text="{Binding FilePath}" Height="28" Width="410" FontSize="16" Foreground="#007DFA" Margin="0,0,10,0"/>
<Button Content="选择路径" Command="{Binding SaveFilePathCommand}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#009999" BorderBrush="#FF36B5C1" Margin="20,0"/>
</StackPanel>
<StackPanel Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Left" Orientation="Horizontal">
<!--<Button Content="连接" Command="{Binding ConnectCommand}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#009999" BorderBrush="#FF36B5C1" Margin="20,0"/>
<Button Content="断开" Command="{Binding DisConnectCommand}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#FF0033" BorderBrush="#FF0033" Margin="0,0"/>
<Button Content="订阅" Command="{Binding SubscriptionCommand}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#009999" BorderBrush="#FF36B5C1" Margin="20,0"/>
<Button Content="取消订阅" Command="{Binding UnsubscribeCommand}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#FF0033" BorderBrush="#FF0033" Margin="0,0,20,0"/>-->
<Button Content="系统配置" Command="{Binding SystemConfigCommand}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#009999" BorderBrush="#FF36B5C1" Margin="20,0"/>
<Button Content="手动上传" Command="{Binding UploadFileDataCommand}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#009933" BorderBrush="#009933" Margin="0,0"/>
<Button Content="开启扫描" Command="{Binding StartScanFilesCommand}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#00CC00" BorderBrush="#00CC00" Margin="20,0"/>
<Button Content="停止扫描" Command="{Binding StopScanFilesCommand}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#990000" BorderBrush="#990000" Margin="0,0"/>
<Label Content="状态:" Height="30" FontSize="16" Foreground="#007DFA" Width="50" Margin="20,0"/>
<Label Content="{Binding UploadMode}" Height="30" FontSize="16" Foreground="#007DFA" Width="60" />
</StackPanel>
</Grid>
</StackPanel>
<!--中部 数据查看-->
<StackPanel Grid.Row="1" Background="AliceBlue">
<Border Width="130" VerticalAlignment="Center" HorizontalAlignment="Left" BorderBrush="AliceBlue" BorderThickness="1,1,1,1" CornerRadius="2" Background="AliceBlue">
<TextBlock Text="日志输出" FontSize="15" Foreground="Gray" VerticalAlignment="Center" HorizontalAlignment="Left"/>
</Border>
<ListBox x:Name="listBox" Height="277" ItemsSource="{Binding ListBoxData}" Background="AliceBlue" BorderBrush="CornflowerBlue"/>
</StackPanel>
<!--底部 日志显示-->
<!--<StackPanel Grid.Row="2" Background="AliceBlue">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="500"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Background="AliceBlue" VerticalAlignment="Center" Orientation="Horizontal" HorizontalAlignment="Left">
<TextBox Text="{Binding MessageStr}" Height="90" Width="500" FontSize="18" Foreground="#007DFA" Margin="0,10,0,0" />
</StackPanel>
<StackPanel Grid.Column="1" Background="AliceBlue" VerticalAlignment="Top" Orientation="Vertical" HorizontalAlignment="Left">
<Button Content="选择文件" Command="{Binding ChooseFileCommand}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#99CC33" BorderBrush="#99CC33" Margin="10,15"/>
<Button Content="推送消息" Command="{Binding PushMessageCommand}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#009933" BorderBrush="#009933" Margin="10,0"/>
</StackPanel>
</Grid>
</StackPanel>-->
</Grid>
</Border>
</Window>

@ -0,0 +1,104 @@
using FileDataUpload.viewModel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace FileDataUpload
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
// private readonly NotifyIcon notifyIcon = new NotifyIcon();
public MainWindow()
{
InitializeComponent();
MainWindowViewModel mainWindowViewModel = new MainWindowViewModel();
this.DataContext = mainWindowViewModel;
}
/// <summary>
/// 窗体初始化
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Window_Loaded(object sender, RoutedEventArgs e)
{
/* notifyIcon.Visible = true;
notifyIcon.Text = "文件数据上传";
notifyIcon.Icon = new Icon("fileIcon.ico");
notifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(show_Click);
notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu();
System.Windows.Forms.MenuItem show = new System.Windows.Forms.MenuItem("显示");
show.Click += new EventHandler(show_Click);
notifyIcon.ContextMenu.MenuItems.Add(show);
System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem("退出");
exit.Click += new EventHandler(exit_Clikc);
notifyIcon.ContextMenu.MenuItems.Add(exit);*/
}
/// <summary>
/// 右键菜单显示按钮事件
/// </summary>
/// <param name="Sender"></param>
/// <param name="e"></param>
/*private void show_Click(object Sender, EventArgs e)
{
if (WindowState == WindowState.Minimized)
{
WindowState = WindowState.Normal;
}
Show();
Activate();
}*/
/// <summary>
/// 右键菜单退出按钮事件
/// </summary>
/// <param name="Sender"></param>
/// <param name="e"></param>
/*private void exit_Clikc(object Sender, EventArgs e)
{
MessageBoxResult info = System.Windows.MessageBox.Show("请确认是否退出文件上传系统", "文件上传系统退出", MessageBoxButton.OK, MessageBoxImage.Warning);
if (info == MessageBoxResult.OK)
{
Environment.Exit(0);
}
}*/
/*protected override void OnStateChanged(EventArgs e)
{
base.OnStateChanged(e);
}*/
/// <summary>
/// 关闭按钮事件
/// </summary>
/// <param name="e"></param>
/*protected override void OnClosing(CancelEventArgs e)
{
e.Cancel = true;
Hide();
base.OnClosing(e);
}*/
}
}

@ -0,0 +1,55 @@
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("FileDataUpload")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FileDataUpload")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
//若要开始生成可本地化的应用程序,请设置
//.csproj 文件中的 <UICulture>CultureYouAreCodingWith</UICulture>
//例如,如果您在源文件中使用的是美国英语,
//使用的是美国英语,请将 <UICulture> 设置为 en-US。 然后取消
//对以下 NeutralResourceLanguage 特性的注释。 更新
//以下行中的“en-US”以匹配项目文件中的 UICulture 设置。
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //主题特定资源词典所处位置
//(未在页面中找到资源时使用,
//或应用程序资源字典中找到时使用)
ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置
//(未在页面中找到资源时使用,
//、应用程序或任何主题专用资源字典中找到时使用)
)]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -0,0 +1,71 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本: 4.0.30319.42000
//
// 对此文件的更改可能导致不正确的行为,如果
// 重新生成代码,则所做更改将丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace FileDataUpload.Properties
{
/// <summary>
/// 强类型资源类,用于查找本地化字符串等。
/// </summary>
// 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
}
/// <summary>
/// 返回此类使用的缓存 ResourceManager 实例。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("FileDataUpload.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// 重写当前线程的 CurrentUICulture 属性,对
/// 使用此强类型资源类的所有资源查找执行重写。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
}
}

@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

@ -0,0 +1,30 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace FileDataUpload.Properties
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
return defaultInstance;
}
}
}
}

@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>

@ -0,0 +1,107 @@
<Window x:Class="FileDataUpload.SysConfigWindw"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:FileDataUpload"
mc:Ignorable="d"
Title="SysConfigWindw" Height="500" Width="450">
<Grid Margin="0,30,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right" Margin="0,0,20,0">
<TextBlock Text="产线:" FontSize="16" VerticalAlignment="Center" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="0" Grid.Column="1" Margin="10,0,0,0">
<TextBox Text="{Binding ProductionLine}" HorizontalAlignment="Left" VerticalAlignment="Center" Width="120" FontSize="16" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right" Margin="0,0,20,0">
<TextBlock Text="设备编码:" FontSize="16" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="1" Margin="10,0,0,0">
<TextBox Text="{Binding DeviceCode}" HorizontalAlignment="Left" VerticalAlignment="Center" Width="120" FontSize="16" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="2" Grid.Column="0" HorizontalAlignment="Right" Margin="0,0,20,0">
<TextBlock Text="生产条码:" FontSize="16" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="2" Grid.Column="1" Margin="10,0,0,0">
<TextBox Text="{Binding ProductionCode}" HorizontalAlignment="Left" VerticalAlignment="Center" Width="120" FontSize="16" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="3" Grid.Column="0" HorizontalAlignment="Right" Margin="0,0,20,0">
<TextBlock Text="物料编号:" FontSize="16" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="3" Grid.Column="1" Margin="10,0,0,0">
<TextBox Text="{Binding MaterialCode}" HorizontalAlignment="Left" VerticalAlignment="Center" Width="120" FontSize="16" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="4" Grid.Column="0" HorizontalAlignment="Right" Margin="0,0,20,0">
<TextBlock Text="当日生产不良数:" FontSize="16" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="4" Grid.Column="1" Margin="10,0,0,0">
<TextBox Text="{Binding DefectQuantity}" HorizontalAlignment="Left" VerticalAlignment="Center" Width="120" FontSize="16" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="5" Grid.Column="0" HorizontalAlignment="Right" Margin="0,0,20,0">
<TextBlock Text="当日生产总数:" FontSize="16" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="5" Grid.Column="1" Margin="10,0,0,0">
<TextBox Text="{Binding Totality}" HorizontalAlignment="Left" VerticalAlignment="Center" Width="120" FontSize="16" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="6" Grid.Column="0" HorizontalAlignment="Right" Margin="0,0,20,0">
<TextBlock Text="测试总结果:" FontSize="16" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="6" Grid.Column="1" Margin="10,0,0,0">
<TextBox Text="{Binding TestResult}" HorizontalAlignment="Left" VerticalAlignment="Center" Width="120" FontSize="16" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="7" Grid.Column="0" HorizontalAlignment="Right" Margin="0,0,20,0">
<TextBlock Text="班次:" FontSize="16" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="7" Grid.Column="1" Margin="10,0,0,0">
<TextBox Text="{Binding WorkShift}" HorizontalAlignment="Left" VerticalAlignment="Center" Width="120" FontSize="16" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="8" Grid.Column="0" HorizontalAlignment="Right" Margin="0,0,20,0">
<TextBlock Text="扫描路径:" FontSize="16" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="8" Grid.Column="1" Margin="10,0,0,0">
<TextBox Text="{Binding FilePath}" HorizontalAlignment="Left" VerticalAlignment="Center" Width="120" FontSize="16" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="12" Grid.Column="1" HorizontalAlignment="Center">
<Button Content="保存" Command="{Binding SaveAppConfigCommand}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#009933" BorderBrush="#009933" Margin="0,0,20,0"/>
</StackPanel>
<!--<StackPanel Orientation="Horizontal" Grid.Row="12" Grid.Column="1" HorizontalAlignment="Center">
<Button Content="取消" Command="{Binding CancelOnClickCommand}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#FF0033" BorderBrush="#FF0033" Margin="0,0,20,0"/>
</StackPanel>-->
</Grid>
</Window>

@ -0,0 +1,32 @@
using FileDataUpload.viewModel;
using GalaSoft.MvvmLight.Messaging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace FileDataUpload
{
/// <summary>
/// SysConfigWindw.xaml 的交互逻辑
/// </summary>
public partial class SysConfigWindw : Window
{
public SysConfigWindw()
{
InitializeComponent();
SystemConfigViewModel systemConfigViewModel = new SystemConfigViewModel();
this.DataContext = systemConfigViewModel;
}
}
}

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CommonServiceLocator" version="2.0.2" targetFramework="net452" />
<package id="log4net" version="2.0.15" targetFramework="net452" />
<package id="MQTTnet" version="4.1.0.247" targetFramework="net452" />
<package id="MvvmLightLibs" version="5.4.1.1" targetFramework="net452" />
</packages>

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

@ -0,0 +1,250 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:FileDataUpload">
<Style x:Key="Window" TargetType="Window">
<Setter Property="WindowStyle" Value="None"/>
<Setter Property="AllowsTransparency" Value="True"/>
<Setter Property="Background" Value="Transparent"/>
</Style>
<Style x:Key="BUTTON_MENUBAR" TargetType="Button">
<Setter Property="VerticalAlignment" Value="Top"/>
<Setter Property="HorizontalAlignment" Value="Right"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
<Grid Name="g" Opacity="0" Background="LightGray"/>
<Grid Name="grd" RenderTransformOrigin="0.5,0.5" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" Background="{TemplateBinding Background}" VerticalAlignment="Center" HorizontalAlignment="Center" >
<Grid.RenderTransform>
<TransformGroup>
<!--<RotateTransform x:Name="rotate" Angle="0"-->
<ScaleTransform x:Name="scale" ScaleX="0.8" ScaleY="0.8"/>
</TransformGroup>
</Grid.RenderTransform>
</Grid>
<ContentPresenter HorizontalAlignment="Left" VerticalAlignment="Center" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Trigger.EnterActions>
<BeginStoryboard >
<Storyboard>
<DoubleAnimation To="0.2" Duration="0:0:0.2" Storyboard.TargetName="g" Storyboard.TargetProperty="Opacity" />
<DoubleAnimation To="1" Duration="0:0:0.2" Storyboard.TargetName="scale" Storyboard.TargetProperty="ScaleX" />
<DoubleAnimation To="1" Duration="0:0:0.2" Storyboard.TargetName="scale" Storyboard.TargetProperty="ScaleY" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard >
<Storyboard>
<DoubleAnimation To="0" Duration="0:0:0.2" Storyboard.TargetName="g" Storyboard.TargetProperty="Opacity" />
<DoubleAnimation To="0.8" Duration="0:0:0.2" Storyboard.TargetName="scale" Storyboard.TargetProperty="ScaleX" />
<DoubleAnimation To="0.8" Duration="0:0:0.2" Storyboard.TargetName="scale" Storyboard.TargetProperty="ScaleY" />
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="BUTTON_MENUBAR_PATH" TargetType="Button">
<Setter Property="VerticalAlignment" Value="Top"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="Foreground" Value="Gray" />
<Setter Property="Height" Value="30"/>
<Setter Property="Width" Value="Auto"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
<Grid Name="g" Background="LightGray" Opacity="0" />
<Grid Name="grd" Width="22" Height="22" Background="{TemplateBinding Background}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" />
<Path Width="10" Height="30" HorizontalAlignment="Right" VerticalAlignment="Center" Data="M3,10 L7,15 L3,20" Stroke="Gray" StrokeThickness="1"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Trigger.EnterActions>
<BeginStoryboard >
<Storyboard>
<DoubleAnimation To="0.4" Duration="0:0:0.2" Storyboard.TargetName="g" Storyboard.TargetProperty="Opacity" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard >
<Storyboard>
<DoubleAnimation Duration="0:0:0.2" Storyboard.TargetName="g" Storyboard.TargetProperty="Opacity" />
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="BUTTON_MENUBAR_MINI" TargetType="Button">
<Setter Property="VerticalAlignment" Value="Top"/>
<Setter Property="HorizontalAlignment" Value="Right"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" ClipToBounds="True">
<Border Name="bdr" BorderBrush="LightGray" BorderThickness="2" Opacity="0">
<Border.Effect>
<DropShadowEffect x:Name="effect" BlurRadius="20" Opacity="0.8" ShadowDepth="0" Color="LightGray"/>
</Border.Effect>
</Border>
<Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" Background="{TemplateBinding Background}" VerticalAlignment="Center" HorizontalAlignment="Center" >
</Grid>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Trigger.EnterActions>
<BeginStoryboard >
<Storyboard>
<DoubleAnimation To="1" Duration="0:0:0.3" Storyboard.TargetName="bdr" Storyboard.TargetProperty="Opacity" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard >
<Storyboard>
<DoubleAnimation To="0" Duration="0:0:0.3" Storyboard.TargetName="bdr" Storyboard.TargetProperty="Opacity" />
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="BUTTON_AGREE" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="bdr" CornerRadius="3" Opacity="0.5" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1">
<!--可使用ContentPresenter代替-->
<!--Foreground的值White可以替换为{TemplateBinding Foreground}-->
<Label VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Foreground="White" Content="{TemplateBinding Content}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Trigger.EnterActions>
<BeginStoryboard >
<Storyboard>
<DoubleAnimation To="0.7" Duration="0:0:0.2" Storyboard.TargetName="bdr" Storyboard.TargetProperty="Opacity" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard >
<Storyboard>
<DoubleAnimation To="0.5" Duration="0:0:0.2" Storyboard.TargetName="bdr" Storyboard.TargetProperty="Opacity" />
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="BUTTON_DISAGREE" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border CornerRadius="3" BorderBrush="#FFEBEBEB" BorderThickness="1">
<Grid>
<Border Name="bdr" CornerRadius="3" Background="Gray" Opacity="0"/>
<Label VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Foreground="{TemplateBinding Foreground}" Content="{TemplateBinding Content}"/>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Trigger.EnterActions>
<BeginStoryboard >
<Storyboard>
<DoubleAnimation To="0.2" Duration="0:0:0.2" Storyboard.TargetName="bdr" Storyboard.TargetProperty="Opacity" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard >
<Storyboard>
<DoubleAnimation To="0" Duration="0:0:0.2" Storyboard.TargetName="bdr" Storyboard.TargetProperty="Opacity" />
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<SolidColorBrush x:Key="SOLIDCOLORBRUSH_LIGHT" Color="#FF6FD1FF"/>
<Color x:Key="COLOR_LIGHT" R="111" G="209" B="255" A="255" />
<Style x:Key="BUTTON_ELLIPSE" TargetType="{x:Type Button}">
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="ToolTip" Value="下一步"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border CornerRadius="15" Width="30" Height="30" Background="{DynamicResource SOLIDCOLORBRUSH_LIGHT}">
<Border.Effect>
<DropShadowEffect x:Name="effect" BlurRadius="7" Opacity="0.6" ShadowDepth="0" Color="{DynamicResource COLOR_LIGHT}"/>
</Border.Effect>
<Grid>
<Path Name="path" HorizontalAlignment="Left" Margin="0,0,0,0" Data="M5,15 L 15,23 L24,9" Stroke="White" StrokeThickness="1"/>
<Path Name="path2" HorizontalAlignment="Left" Opacity="0" Margin="0,0,0,0" Data="M5,15 H25 L17,7 M25,15 L17,22 " Stroke="White" StrokeThickness="1"/>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Trigger.EnterActions>
<BeginStoryboard >
<Storyboard>
<DoubleAnimation To="0.9" Duration="0:0:0.3" Storyboard.TargetName="effect" Storyboard.TargetProperty="Opacity" />
<DoubleAnimation To="15" Duration="0:0:0.3" Storyboard.TargetName="effect" Storyboard.TargetProperty="BlurRadius" />
<DoubleAnimation To="0" Duration="0:0:0.5" Storyboard.TargetName="path" Storyboard.TargetProperty="Opacity" />
<DoubleAnimation To="1" Duration="0:0:0.5" BeginTime="0:0:0.3" Storyboard.TargetName="path2" Storyboard.TargetProperty="Opacity" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard >
<Storyboard>
<DoubleAnimation Duration="0:0:0.3" Storyboard.TargetName="effect" Storyboard.TargetProperty="Opacity" />
<DoubleAnimation Duration="0:0:0.3" Storyboard.TargetName="effect" Storyboard.TargetProperty="BlurRadius" />
<DoubleAnimation Duration="0:0:0.5" BeginTime="0:0:0.3" Storyboard.TargetName="path" Storyboard.TargetProperty="Opacity" />
<DoubleAnimation Duration="0:0:0.5" Storyboard.TargetName="path2" Storyboard.TargetProperty="Opacity" />
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

@ -0,0 +1,517 @@
using FileDataUpload.Common;
using FileDataUpload.Entity;
using FileDataUpload.FileOperate;
using FileDataUpload.Mqtt;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FileDataUpload.viewModel
{
public class MainWindowViewModel : ViewModelBase
{
[DllImport("user32.dll")] public static extern int MessageBoxTimeoutA(IntPtr hWnd, string msg, string Caps, int type, int Id, int time);
private readonly FileHelper fileHelper = FileHelper.Instance;
private readonly JsonChange jsonChange = JsonChange.Instance;
private readonly MqttClient client = MqttClient.Instance;
private readonly LogHelper logHelper = LogHelper.Instance;
private AppConfig appConfig = AppConfig.Instance;
private MonitorEngine monitorEngine = MonitorEngine.Instance;
private ObservableCollection<dynamic> listItems = new ObservableCollection<dynamic>();
[Obsolete]
public MainWindowViewModel()
{
try
{
client.PrintMessageReceivedEvent += PrintMessageToListBox;
ConnectCommand = new RelayCommand(Connect);
DisConnectCommand = new RelayCommand(DisConnect);
SubscriptionCommand = new RelayCommand(Subscription);
UnsubscribeCommand = new RelayCommand(Unsubscribe);
UploadFileDataCommand = new RelayCommand(UploadFileData);
ChooseFileCommand = new RelayCommand(ChooseFile);
PushMessageCommand = new RelayCommand(PushMessage);
SystemConfigCommand = new RelayCommand(SystemConfigOnClick);
StartScanFilesCommand = new RelayCommand(StartScanFilesOnClick);
StopScanFilesCommand = new RelayCommand(StopScanFilesOnClick);
SaveFilePathCommand = new RelayCommand(SaveFilePathOnclick);
borkerIp = "scada.midea.com";
borkerPort = "1883";
uploadMode = "手动";
filePath = appConfig.filePath;
monitorEngine.Path = appConfig.filePath;
monitorEngine.Filter = "*";
monitorEngine.FindOneFileEvent += UploadFileData;
PrintMessageToListBox("文件数据上传程序初始化成功");
}
catch (Exception ex)
{
PrintMessageToListBox($"文件数据上传程序初始化失败:{ex.Message}");
}
}
#region Command
/// <summary>
/// 连接
/// </summary>
public RelayCommand ConnectCommand { get; set; }
/// <summary>
/// 断开
/// </summary>
public RelayCommand DisConnectCommand { get; set; }
/// <summary>
/// 订阅
/// </summary>
public RelayCommand SubscriptionCommand { get; set; }
/// <summary>
/// 取消订阅
/// </summary>
public RelayCommand UnsubscribeCommand { get; set; }
/// <summary>
/// 选择文件
/// </summary>
public RelayCommand ChooseFileCommand { get; set; }
/// <summary>
/// 上传文件数据
/// </summary>
public RelayCommand UploadFileDataCommand { get; set; }
/// <summary>
/// 推送消息
/// </summary>
public RelayCommand PushMessageCommand { get; set; }
/// <summary>
/// 系统配置
/// </summary>
public RelayCommand SystemConfigCommand { get; set; }
/// <summary>
/// 开启扫描文件
/// </summary>
public RelayCommand StartScanFilesCommand { get; set; }
/// <summary>
/// 停止扫描文件
/// </summary>
public RelayCommand StopScanFilesCommand { get; set; }
public RelayCommand SaveFilePathCommand { get; set; }
#endregion
private IEnumerable listBoxData;
/// <summary>
/// LisBox数据模板
/// </summary>
public IEnumerable ListBoxData
{
get { return listBoxData; }
set { listBoxData = value; RaisePropertyChanged(() => ListBoxData); }
}
public String borkerIp = String.Empty;
public String borkerPort = String.Empty;
public String clientId = String.Empty;
public String userName = String.Empty;
public String password = String.Empty;
public String topical = String.Empty;
public String messageStr = String.Empty;
public String uploadMode = String.Empty;
public String filePath = String.Empty;
public String BorkerIp
{
get { return borkerIp; }
set { borkerIp = value; RaisePropertyChanged(() => BorkerIp); }
}
public String BorkerPort
{
get { return borkerPort; }
set { borkerPort = value; RaisePropertyChanged(() => BorkerPort); }
}
public String ClientId
{
get { return clientId; }
set { clientId = value; RaisePropertyChanged(() => ClientId); }
}
public String UserName
{
get { return userName; }
set { userName = value; RaisePropertyChanged(() => UserName); }
}
public String Password
{
get { return password; }
set { password = value; RaisePropertyChanged(() => Password); }
}
public String Topical
{
get { return topical; }
set { topical = value; RaisePropertyChanged(() => Topical); }
}
public String MessageStr
{
get { return messageStr; }
set { messageStr = value; RaisePropertyChanged(() => MessageStr); }
}
public String UploadMode
{
get { return uploadMode; }
set { uploadMode = value; RaisePropertyChanged(() => UploadMode); }
}
public String FilePath
{
get { return filePath; }
set { filePath = value; RaisePropertyChanged(() => FilePath); }
}
/// <summary>
/// 建立连接
/// </summary>
public void Connect()
{
if (string.IsNullOrEmpty(BorkerIp) || string.IsNullOrEmpty(BorkerPort))
{
PrintMessageToListBox("连接失败Borker IP、Port不允许为空");
return;
}
if (string.IsNullOrEmpty(ClientId) || string.IsNullOrEmpty(UserName) || string.IsNullOrEmpty(Password))
{
PrintMessageToListBox("连接失败ClientId、UserName、Password不允许为空");
return;
}
client.Connect(BorkerIp, Convert.ToInt32(BorkerPort), ClientId, UserName, Password);
}
/// <summary>
/// 断开连接
/// </summary>
public void DisConnect()
{
client.DisConnect();
}
/// <summary>
/// 订阅主题
/// </summary>
public void Subscription()
{
if (string.IsNullOrEmpty(topical))
{
PrintMessageToListBox("订阅主题不允许为空");
return;
}
client.SubscriptionAsync(topical);
}
/// <summary>
/// 取消订阅
/// </summary>
public void Unsubscribe()
{
if (string.IsNullOrEmpty(topical))
{
PrintMessageToListBox("取消订阅主题不允许为空");
return;
}
client.Unsubscribe(topical);
}
/// <summary>
/// 选择文件
/// </summary>
[System.Obsolete]
public void ChooseFile()
{
string fileName = "";
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Multiselect = true; //该值确定是否可以选择多个文件
openFileDialog.Title = "请选择文件"; //弹窗的标题
openFileDialog.InitialDirectory = "D:\\"; //默认打开的文件夹的位置
openFileDialog.Filter = "MicroSoft Excel文件(*.xlsx)|*.xlsx|所有文件(*.*)|*.*"; //筛选文件
openFileDialog.ShowHelp = true; //是否显示“帮助”按钮
if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
fileName = openFileDialog.FileName;
//var info = fileHelper.ReadExcelFile_New(fileName);
var info = fileHelper.ReadExcelFile(fileName);
if (info != null)
{
MessageStr = jsonChange.ModeToJson(info);
PrintMessageToListBox($"文件读取成功:{MessageStr}");
}
else
{
PrintMessageToListBox($"文件读取失败,请仔细检查文件格式");
}
}
}
[Obsolete]
public void UploadFileData()
{
string fileName = "";
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Multiselect = true; //该值确定是否可以选择多个文件
openFileDialog.Title = "请选择文件"; //弹窗的标题
openFileDialog.InitialDirectory = "D:\\"; //默认打开的文件夹的位置
openFileDialog.Filter = "MicroSoft Excel文件(*.xlsx)|*.xlsx|所有文件(*.*)|*.*"; //筛选文件
openFileDialog.ShowHelp = true; //是否显示“帮助”按钮
if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
fileName = openFileDialog.FileName;
UploadFileData(fileName);
}
}
[Obsolete]
private async void UploadFileData(string path)
{
try
{
int pushFlag = 0;
PrintMessageToListBox($"解析文件:{path}");
await Task.Delay(1000 * 2);
Dictionary<string, List<DeviceParam>> info = fileHelper.ReadExcelFile(path);
if (info != null)
{
foreach (var item in info)
{
switch (item.Key)
{
case "铆压环":
clientId = "EV62Q0000501YASM346";
userName = "EV62Q0000501YASM346|1";
password = "30dc225be0cb418b974b68eb10339b31";
pushFlag = appConfig.pushFlag_RivetingRing + 1;
break;
case "限位器":
clientId = "EV33210110YTJDMC001";
userName = "EV33210110YTJDMC001|1";
password = "cebf88bcc61147c1a42a4749fadf2ed1";
pushFlag = appConfig.pushFlag_Stopper + 1;
break;
case "排气阀片":
clientId = "EV33200210YTJDMC008";
userName = "EV33200210YTJDMC008|1";
password = "396bf2a332f64810a12a0385cae8c5a9";
pushFlag = appConfig.pushFlag_displacingValve + 1;
break;
}
this.Connect();
await Task.Delay(1000 * 5);
var @params = item.Value.OrderBy(x => Convert.ToInt32(x.data.propertyCode.Substring(3, x.data.propertyCode.Length - 3))).ToList();
foreach (var param in @params)
{
param.data.deviceCode = ClientId;
PrintMessageToListBox($"{item.Key}---上传{param.data.propertyCode}数据:{jsonChange.ModeToJson(param)}");
topical = $"/sys/932e4a47e5414e058fdbd067a4942247/device/{clientId}/thing/property/{param.data.propertyCode}/post";
if (param.data.propertyCode == "tag10")
{
param.data.propertyValue = pushFlag;
}
messageStr = jsonChange.ModeToJson(param);
this.PushMessage();
await Task.Delay(1000 * 1);
}
UpdatePushFlag(item.Key);
this.DisConnect();
}
}
else
{
PrintMessageToListBox("文件读取失败,请仔细检查文件格式");
}
}
catch (Exception ex)
{
PrintMessageToListBox($"文件解析上传异常:{ex.Message}");
}
}
public void PushMessage()
{
try
{
if (string.IsNullOrEmpty(Topical) || string.IsNullOrEmpty(MessageStr))
{
PrintMessageToListBox("推送消息主题、内容不允许为空");
return;
}
client.Publish(Topical, MessageStr);
}
catch (Exception ex)
{
PrintMessageToListBox($"消息推送异常:{ex.Message}");
}
}
public void SystemConfigOnClick()
{
SysConfigWindw configWindw = new SysConfigWindw();
configWindw.ShowDialog();
if ((bool)configWindw.DialogResult)
{
PrintMessageToListBox("系统配置成功");
}
}
public void StartScanFilesOnClick()
{
try
{
monitorEngine.Path = appConfig.filePath;
monitorEngine.Filter = "*";
monitorEngine.WatcherStrat();
PrintMessageToListBox($"自动扫描开启成功,实时监测:{appConfig.filePath}");
UploadMode = "自动";
}
catch (Exception e)
{
PrintMessageToListBox($"自动扫描开启异常:{e.Message}");
}
}
public void StopScanFilesOnClick()
{
try
{
monitorEngine.WatcherStop();
PrintMessageToListBox($"自动扫描停止成功");
UploadMode = "手动";
}
catch (Exception e)
{
PrintMessageToListBox($"自动扫描停止异常:{e.Message}");
}
}
public void SaveFilePathOnclick()
{
FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
{
string selectedPath = folderBrowserDialog.SelectedPath;
//处理所选文件夹的代码
appConfig.filePath = selectedPath;
MessageBoxTimeoutA((IntPtr)0, $"自动上传文件路径保存成功:{selectedPath}3秒后关闭提示", "提示", 0, 0, 3000);
filePath = appConfig.filePath;
FilePath = selectedPath;
}
}
/// <summary>
/// listBox绑定日志
/// </summary>
/// <param name="message"></param>
private void PrintMessageToListBox(string message)
{
logHelper.Info(message);
listItems.Add($"{DateTime.Now.ToString("HH:mm:ss")}==>{message}");
ListBoxData = listItems.OrderByDescending(x => x);
}
/// <summary>
/// 更新推送标志位
/// </summary>
/// <param name="sheetName"></param>
private void UpdatePushFlag(string sheetName)
{
switch (sheetName)
{
case "铆压环":
appConfig.pushFlag_RivetingRing = appConfig.pushFlag_RivetingRing + 1;
break;
case "限位器":
appConfig.pushFlag_Stopper = appConfig.pushFlag_Stopper + 1;
break;
case "排气阀片":
appConfig.pushFlag_displacingValve = appConfig.pushFlag_displacingValve + 1;
break;
}
}
}
}

@ -0,0 +1,125 @@
using FileDataUpload.Entity;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
using System;
using System.Runtime.InteropServices;
using System.Windows.Input;
namespace FileDataUpload.viewModel
{
public class SystemConfigViewModel : ViewModelBase
{
[DllImport("user32.dll")] public static extern int MessageBoxTimeoutA(IntPtr hWnd, string msg, string Caps, int type, int Id, int time);
private AppConfig appConfig = AppConfig.Instance;
public String productionLine = String.Empty;
public String deviceCode = String.Empty;
public String productionCode = String.Empty;
public String materialCode = String.Empty;
public String defectQuantity = String.Empty;
public String totality = String.Empty;
public String testResult = String.Empty;
public String workShift = String.Empty;
public String filePath = String.Empty;
public String ProductionLine
{
get { return productionLine; }
set { productionLine = value; RaisePropertyChanged(() => ProductionLine); }
}
public String DeviceCode
{
get { return deviceCode; }
set { deviceCode = value; RaisePropertyChanged(() => DeviceCode); }
}
public String ProductionCode
{
get { return productionCode; }
set { productionCode = value; RaisePropertyChanged(() => ProductionCode); }
}
public String MaterialCode
{
get { return materialCode; }
set { materialCode = value; RaisePropertyChanged(() => MaterialCode); }
}
public String DefectQuantity
{
get { return defectQuantity; }
set { defectQuantity = value; RaisePropertyChanged(() => DefectQuantity); }
}
public String Totality
{
get { return totality; }
set { totality = value; RaisePropertyChanged(() => Totality); }
}
public String TestResult
{
get { return testResult; }
set { testResult = value; RaisePropertyChanged(() => testResult); }
}
public String WorkShift
{
get { return workShift; }
set { workShift = value; RaisePropertyChanged(() => WorkShift); }
}
public String FilePath
{
get { return filePath; }
set { filePath = value; RaisePropertyChanged(() => FilePath); }
}
public RelayCommand SaveAppConfigCommand { get; set; }
public RelayCommand CancelOnClickCommand { get; set; }
public SystemConfigViewModel()
{
productionLine = appConfig.线;
deviceCode = appConfig.;
productionCode = appConfig.;
materialCode = appConfig.;
defectQuantity = appConfig.;
totality = appConfig.;
testResult = appConfig.;
workShift = appConfig.;
filePath = appConfig.filePath;
SaveAppConfigCommand = new RelayCommand(SaveAppConfig);
CancelOnClickCommand = new RelayCommand(CancelOnClick);
}
public void SaveAppConfig()
{
appConfig.线 = productionLine;
appConfig. = deviceCode;
appConfig. = productionCode;
appConfig. = materialCode;
appConfig. = defectQuantity;
appConfig. = totality;
appConfig. = testResult;
appConfig. = workShift;
MessageBoxTimeoutA((IntPtr)0, "保存成功3秒后关闭提示", "提示", 0, 0, 3000);
}
public void CancelOnClick()
{
}
private void CloseMessage()
{
}
}
public class CloseMessage { }
}
Loading…
Cancel
Save