首次提交:添加src文件夹代码
This commit is contained in:
76
Cowain.Bake.Common/Core/BasicFramework.cs
Normal file
76
Cowain.Bake.Common/Core/BasicFramework.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace Cowain.Bake.Common.Core
|
||||
{
|
||||
public class BasicFramework
|
||||
{
|
||||
private static BasicFramework instance;
|
||||
private static readonly object locker = new object();
|
||||
public Dictionary<string, string> RegularDic = new Dictionary<string, string>();
|
||||
public static BasicFramework Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new BasicFramework();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BasicFramework()
|
||||
{
|
||||
SetRegularDic();
|
||||
}
|
||||
|
||||
private void SetRegularDic()
|
||||
{
|
||||
RegularDic.Clear();
|
||||
RegularDic.Add("decimal2", "^([1-9]+[\\d]*(.[0-9]{1,2})?)$");
|
||||
RegularDic.Add("Int32", @"^(0|-?[1-9]\d*)$");// "^[0-9]*$");
|
||||
RegularDic.Add("Int16", "^([1-9](\\d{0,3}))$|^([1-5]\\d{4})$|^(6[0-4]\\d{3})$|^(65[0-4]\\d{2})$|^(655[0-2]\\d)$|^(6553[0-5])$");
|
||||
RegularDic.Add("bool", "^[01]$");
|
||||
RegularDic.Add("Float", @"^(?!\.?$)\d+(\.\d+)?([eE][-+]?\d+)?$");
|
||||
}
|
||||
public static T DeepCopy<T>(T obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return obj;
|
||||
}
|
||||
if (obj is string || obj.GetType().IsValueType)
|
||||
return obj;
|
||||
|
||||
object retval = Activator.CreateInstance(obj.GetType());
|
||||
FieldInfo[] fields = obj.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
|
||||
foreach (var field in fields)
|
||||
{
|
||||
try
|
||||
{
|
||||
field.SetValue(retval, DeepCopy(field.GetValue(obj)));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Instance.GetCurrentClassError((typeof(BasicFramework) + "DeepCopy异常:" + ex.Message));
|
||||
}
|
||||
}
|
||||
|
||||
return (T)retval;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
273
Cowain.Bake.Common/Core/CSVHelper.cs
Normal file
273
Cowain.Bake.Common/Core/CSVHelper.cs
Normal file
@@ -0,0 +1,273 @@
|
||||
using CsvHelper;
|
||||
using CsvHelper.Configuration;
|
||||
using Microsoft.Win32;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
|
||||
namespace Cowain.Bake.Common.Core
|
||||
{
|
||||
public class CSVHelper
|
||||
{
|
||||
public static void WriteDataTableToCsv<T>(IEnumerable<T> list)
|
||||
{
|
||||
string filePath = GetFilePath();
|
||||
if (string.IsNullOrEmpty(filePath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
using (var writer = new StreamWriter(filePath))
|
||||
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
|
||||
{
|
||||
csv.WriteRecords(list);
|
||||
}
|
||||
}
|
||||
|
||||
//列头是中文,所有字段都写入
|
||||
public static void WriteDataTableToCsv<T>(IEnumerable<T> list, List<string> nameCols)
|
||||
{
|
||||
string filePath = GetFilePath();
|
||||
if (string.IsNullOrEmpty(filePath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
|
||||
{
|
||||
// 设置列头编码为UTF8以支持中文
|
||||
Encoding = System.Text.Encoding.UTF8,
|
||||
// 设置不写入列头
|
||||
HasHeaderRecord = false
|
||||
};
|
||||
|
||||
using (var writer = new StreamWriter(filePath, false, System.Text.Encoding.UTF8))
|
||||
using (var csv = new CsvWriter(writer, config))
|
||||
{
|
||||
// 写入列头,使用中文列名
|
||||
foreach(var col in nameCols)
|
||||
{
|
||||
csv.WriteField(col);
|
||||
}
|
||||
csv.NextRecord();
|
||||
|
||||
// 写入数据行
|
||||
csv.WriteRecords(list);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 将List的特定列写入CSV文件的方法
|
||||
public static void WriteDataTableToCsv<T>(IEnumerable<T> list, IEnumerable<string> columnsToSave)
|
||||
{
|
||||
string filePath = GetFilePath();
|
||||
if (string.IsNullOrEmpty(filePath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
|
||||
{
|
||||
// 设置列头编码为UTF8以支持中文
|
||||
Encoding = System.Text.Encoding.UTF8,
|
||||
// 设置不写入列头
|
||||
HasHeaderRecord = false
|
||||
};
|
||||
|
||||
using (var writer = new StreamWriter(filePath, false, System.Text.Encoding.UTF8))
|
||||
using (var csv = new CsvWriter(writer, config))
|
||||
{
|
||||
// 写入列头
|
||||
foreach (var columnName in columnsToSave)
|
||||
{
|
||||
csv.WriteField(columnName);
|
||||
}
|
||||
csv.NextRecord();
|
||||
|
||||
// 写入特定列数据
|
||||
foreach (var person in list)
|
||||
{
|
||||
foreach (var columnName in columnsToSave)
|
||||
{
|
||||
var property = typeof(T).GetProperty(columnName);
|
||||
if (property != null)
|
||||
{
|
||||
csv.WriteField(property.GetValue(person));
|
||||
}
|
||||
}
|
||||
csv.NextRecord();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static string GetFilePath()
|
||||
{
|
||||
string filePath = "";
|
||||
//创建一个保存文件式的对话框
|
||||
SaveFileDialog saveFileDialog = new SaveFileDialog();
|
||||
//设置保存的文件的类型,注意过滤器的语法
|
||||
saveFileDialog.Filter = "CSV|*.csv";
|
||||
if (saveFileDialog.ShowDialog() == true)
|
||||
{
|
||||
filePath = saveFileDialog.FileName;
|
||||
}
|
||||
|
||||
return filePath;
|
||||
}
|
||||
public static void WriteMap<T, TMap>(IEnumerable<T> list, string filePath) where TMap : ClassMap
|
||||
{
|
||||
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
|
||||
{
|
||||
// 设置列头编码为UTF8以支持中文
|
||||
Delimiter = ",",
|
||||
HasHeaderRecord = true,
|
||||
Encoding = System.Text.Encoding.UTF8
|
||||
};
|
||||
|
||||
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
config.HasHeaderRecord = false; // 获取字段描述作为列头
|
||||
}
|
||||
|
||||
using (var writer = new StreamWriter(filePath, true, System.Text.Encoding.UTF8))
|
||||
using (var csv = new CsvWriter(writer, config))
|
||||
{
|
||||
// 注册自定义映射
|
||||
//csv.Context.RegisterClassMap<BatteryInfoMap>();
|
||||
csv.Context.RegisterClassMap<TMap>();
|
||||
// 写入记录
|
||||
csv.WriteRecords(list);
|
||||
}
|
||||
}
|
||||
public static void WriteMap<T, TMap>(IEnumerable<T> list ) where TMap : ClassMap //where TMap : ClassMap<T> // 约束:必须是 ClassMap<T> 或其子类
|
||||
{
|
||||
string filePath = GetFilePath();
|
||||
if (string.IsNullOrEmpty(filePath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
WriteMap<T, TMap>(list, filePath);
|
||||
}
|
||||
|
||||
// 将List的特定列写入CSV文件的方法
|
||||
public static void WriteDataTableToCsv<T>(IEnumerable<T> list, IEnumerable<string> columnsToSave, IEnumerable<string> columnsToShow)
|
||||
{
|
||||
string filePath = GetFilePath();
|
||||
if (string.IsNullOrEmpty(filePath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
|
||||
{
|
||||
// 设置列头编码为UTF8以支持中文
|
||||
Encoding = System.Text.Encoding.UTF8,
|
||||
HasHeaderRecord = false
|
||||
};
|
||||
|
||||
using (var writer = new StreamWriter(filePath, false, System.Text.Encoding.UTF8))
|
||||
using (var csv = new CsvWriter(writer, config))
|
||||
{
|
||||
// 写入列头
|
||||
foreach (var columnName in columnsToShow)
|
||||
{
|
||||
csv.WriteField(columnName);
|
||||
}
|
||||
csv.NextRecord();
|
||||
|
||||
// 写入特定列数据
|
||||
foreach (var person in list)
|
||||
{
|
||||
foreach (var columnName in columnsToSave)
|
||||
{
|
||||
var property = typeof(T).GetProperty(columnName);
|
||||
if (property != null)
|
||||
{
|
||||
csv.WriteField(property.GetValue(person));
|
||||
}
|
||||
}
|
||||
csv.NextRecord();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 将List的特定列写入CSV文件的方法
|
||||
public static void WriteDataTableToCsv<T>(IEnumerable<T> list, IEnumerable<string> columnsToSave, IEnumerable<string> columnsToShow, string filePath)
|
||||
{
|
||||
bool isFileExists = false;
|
||||
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
|
||||
{
|
||||
// 设置列头编码为UTF8以支持中文
|
||||
Encoding = System.Text.Encoding.UTF8,
|
||||
HasHeaderRecord = false
|
||||
};
|
||||
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
// 获取字段描述作为列头
|
||||
isFileExists = true;
|
||||
}
|
||||
|
||||
using (var writer = new StreamWriter(filePath, true, System.Text.Encoding.UTF8))
|
||||
using (var csv = new CsvWriter(writer, config))
|
||||
{
|
||||
// 写入列头
|
||||
if (!isFileExists)
|
||||
{
|
||||
foreach (var columnHeader in columnsToShow)
|
||||
{
|
||||
csv.WriteField(columnHeader);
|
||||
}
|
||||
csv.NextRecord();
|
||||
}
|
||||
|
||||
// 写入特定列数据
|
||||
foreach (var person in list)
|
||||
{
|
||||
foreach (var columnName in columnsToSave)
|
||||
{
|
||||
var property = typeof(T).GetProperty(columnName);
|
||||
if (property != null)
|
||||
{
|
||||
csv.WriteField(property.GetValue(person));
|
||||
}
|
||||
}
|
||||
csv.NextRecord();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 将DataTable写入CSV文件的方法
|
||||
public static void WriteDataTableToCsv(DataTable dataTable)
|
||||
{
|
||||
string filePath = GetFilePath();
|
||||
if (string.IsNullOrEmpty(filePath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
using (var writer = new StreamWriter(filePath))
|
||||
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
|
||||
{
|
||||
// 写入表头
|
||||
foreach (DataColumn column in dataTable.Columns)
|
||||
{
|
||||
csv.WriteField(column.ColumnName);
|
||||
}
|
||||
csv.NextRecord();
|
||||
|
||||
// 写入数据行
|
||||
foreach (DataRow row in dataTable.Rows)
|
||||
{
|
||||
for (var i = 0; i < dataTable.Columns.Count; i++)
|
||||
{
|
||||
csv.WriteField(row[i]);
|
||||
}
|
||||
csv.NextRecord();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
46
Cowain.Bake.Common/Core/CommonCoreHelper.cs
Normal file
46
Cowain.Bake.Common/Core/CommonCoreHelper.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using Cowain.Bake.Model;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
||||
namespace Cowain.Bake.Common.Core
|
||||
{
|
||||
|
||||
public class CommonCoreHelper
|
||||
{
|
||||
|
||||
//IsCompleted:true,CompleteAdding()已被调用(表示不再有新项添加)该集合是否已被标记为“添加完成”(即 CompleteAdding() 已被调用)
|
||||
public BlockingCollection<TTaskRecord> BlockTask = new BlockingCollection<TTaskRecord>();
|
||||
public BlockingCollection<TDeviceConfig> BlockStatusColor = new BlockingCollection<TDeviceConfig>();
|
||||
|
||||
// 参数表示初始状态:true表示初始有信号,false表示初始无信号
|
||||
|
||||
public AutoResetEvent MainViewAutoEvent = new AutoResetEvent(true);
|
||||
private static CommonCoreHelper instance;
|
||||
|
||||
public static CommonCoreHelper Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new CommonCoreHelper();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
public List<string> StringToListConverter(string input)
|
||||
{
|
||||
string[] separators = { " ", ":", ",", ";" };
|
||||
if (string.IsNullOrWhiteSpace(input))
|
||||
{
|
||||
return new List<string>();
|
||||
}
|
||||
string[] items = input.Split(separators, StringSplitOptions.RemoveEmptyEntries);
|
||||
List<string> itemList = new List<string>(items);
|
||||
return itemList;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
103
Cowain.Bake.Common/Core/INIHelper.cs
Normal file
103
Cowain.Bake.Common/Core/INIHelper.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Cowain.Bake.Common.Core
|
||||
{
|
||||
public class INIHelper
|
||||
{
|
||||
[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);
|
||||
|
||||
//ini文件名称
|
||||
private static string inifilename = "Config.ini";
|
||||
//获取ini文件路径
|
||||
public static string inifilepath = Application.StartupPath + "\\" + inifilename;
|
||||
|
||||
public static string ReadValue(string key)
|
||||
{
|
||||
StringBuilder s = new StringBuilder(1024);
|
||||
GetPrivateProfileString("Config", key, "", s, 1024, inifilepath);
|
||||
return s.ToString();
|
||||
}
|
||||
public static bool ReadBool(string section, string key, bool value = false)
|
||||
{
|
||||
bool reVal = false;
|
||||
StringBuilder s = new StringBuilder(1024);
|
||||
GetPrivateProfileString(section, key, "", s, 1024, inifilepath);
|
||||
bool b = bool.TryParse(s.ToString(), out reVal);
|
||||
if (b)
|
||||
{
|
||||
return reVal;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static string ReadString(string section, string key, string value = "")
|
||||
{
|
||||
StringBuilder s = new StringBuilder(1024);
|
||||
GetPrivateProfileString(section, key, "", s, 1024, inifilepath);
|
||||
if (0 == s.ToString().Length)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
return s.ToString();
|
||||
}
|
||||
|
||||
public static int ReadInt(string section, string key, int nDefault = 0)
|
||||
{
|
||||
// 每次从ini中读取多少字节
|
||||
System.Text.StringBuilder temp = new StringBuilder(1024);
|
||||
// section=配置节,key=键名,temp=上面,path=路径
|
||||
GetPrivateProfileString(section, key, "", temp, 1024, inifilepath);
|
||||
string t = temp.ToString();
|
||||
int v = 0;
|
||||
if (int.TryParse(t, out v))
|
||||
{
|
||||
return v;
|
||||
}
|
||||
return nDefault;
|
||||
}
|
||||
|
||||
public static float ReadFloat(string section, string key, float fDefault = 0)
|
||||
{
|
||||
// 每次从ini中读取多少字节
|
||||
System.Text.StringBuilder temp = new System.Text.StringBuilder(255);
|
||||
// section=配置节,key=键名,temp=上面,path=路径
|
||||
GetPrivateProfileString(section, key, "", temp, 255, inifilepath);
|
||||
string t = temp.ToString();
|
||||
float v = 0;
|
||||
if (float.TryParse(t, out v))
|
||||
{
|
||||
return v;
|
||||
}
|
||||
return fDefault;
|
||||
}
|
||||
|
||||
/// <param name="value"></param>
|
||||
public static void Write(string section, string key, string value)
|
||||
{
|
||||
// section=配置节,key=键名,value=键值,path=路径
|
||||
WritePrivateProfileString(section, key, value, inifilepath);
|
||||
}
|
||||
|
||||
public static void WriteValue(string key, string value)
|
||||
{
|
||||
try
|
||||
{
|
||||
WritePrivateProfileString("Config", key, value, inifilepath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
169
Cowain.Bake.Common/Core/LogHelper.cs
Normal file
169
Cowain.Bake.Common/Core/LogHelper.cs
Normal file
@@ -0,0 +1,169 @@
|
||||
using Cowain.Bake.Common.Enums;
|
||||
using NLog;
|
||||
using NLog.Config;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
|
||||
namespace Cowain.Bake.Common.Core
|
||||
{
|
||||
public class LogHelper
|
||||
{
|
||||
private static LogHelper instance;
|
||||
|
||||
public static LogHelper Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new LogHelper();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
private Logger logger; //初始化日志类
|
||||
|
||||
/// <summary>
|
||||
/// 事件定义
|
||||
/// </summary>
|
||||
public Action<string> OnComplated;
|
||||
public Action<string, bool, E_LogType> OnShowInvoke { set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 时间触发
|
||||
/// </summary>
|
||||
/// <param name="msg">自定义消息</param>
|
||||
/// <param name="isUI">是否触发事件通知</param>
|
||||
private void Notice(string msg, bool isShow, E_LogType logType)
|
||||
{
|
||||
if (OnShowInvoke != null)
|
||||
{
|
||||
OnShowInvoke?.Invoke(msg, isShow, logType);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 静态构造函数
|
||||
/// </summary>
|
||||
private LogHelper()
|
||||
{
|
||||
logger = NLog.LogManager.GetCurrentClassLogger(); //初始化日志类
|
||||
//string rootPath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
|
||||
|
||||
//string fileName = string.Format(@"{0}NLog.config", rootPath);
|
||||
|
||||
////初始化配置日志
|
||||
//NLog.LogManager.Configuration = new XmlLoggingConfiguration(fileName);
|
||||
}
|
||||
|
||||
public void Trace(string msg)
|
||||
{
|
||||
To(msg, E_LogType.Trace, false);
|
||||
}
|
||||
|
||||
public void Debug(string msg, bool isShow = false)
|
||||
{
|
||||
To(msg, E_LogType.Debug, isShow);
|
||||
}
|
||||
|
||||
public void Info(string msg, bool isShow = false)
|
||||
{
|
||||
To(msg, E_LogType.Info, isShow);
|
||||
}
|
||||
|
||||
public void Warn(string msg, bool isShow = false)
|
||||
{
|
||||
To(msg, E_LogType.Warn, isShow);
|
||||
}
|
||||
|
||||
public void Error(string msg, bool isShow = false)
|
||||
{
|
||||
To(msg, E_LogType.Error, isShow);
|
||||
}
|
||||
|
||||
public void Fatal(string msg, bool isShow = false)
|
||||
{
|
||||
To(msg, E_LogType.Fatal, isShow);
|
||||
}
|
||||
#region 当前类也打印出来
|
||||
public void GetCurrentClassDebug(string msg, bool isShow = false,
|
||||
[CallerMemberName] string memberName = "",
|
||||
[CallerFilePath] string sourceFilePath = "",
|
||||
[CallerLineNumber] int sourceLineNumber = 0)
|
||||
{
|
||||
msg = $"File:{sourceFilePath},Fun:{memberName},LineNum:{sourceLineNumber},{msg}";
|
||||
To(msg, E_LogType.Debug, isShow);
|
||||
}
|
||||
|
||||
public void GetCurrentClassInfo(string msg, bool isShow = false,
|
||||
[CallerMemberName] string memberName = "",
|
||||
[CallerFilePath] string sourceFilePath = "",
|
||||
[CallerLineNumber] int sourceLineNumber = 0)
|
||||
{
|
||||
msg = $"File:{sourceFilePath},Fun:{memberName},LineNum:{sourceLineNumber},{msg}";
|
||||
To(msg, E_LogType.Info, isShow);
|
||||
}
|
||||
|
||||
public void GetCurrentClassWarn(string msg, bool isShow = false,
|
||||
[CallerMemberName] string memberName = "",
|
||||
[CallerFilePath] string sourceFilePath = "",
|
||||
[CallerLineNumber] int sourceLineNumber = 0)
|
||||
{
|
||||
msg = $"File:{sourceFilePath},Fun:{memberName},LineNum:{sourceLineNumber},{msg}";
|
||||
To(msg, E_LogType.Warn, isShow);
|
||||
}
|
||||
|
||||
public void GetCurrentClassError(string msg, bool isShow = false,
|
||||
[CallerMemberName] string memberName = "",
|
||||
[CallerFilePath] string sourceFilePath = "",
|
||||
[CallerLineNumber] int sourceLineNumber = 0)
|
||||
{
|
||||
msg = $"File:{sourceFilePath},Fun:{memberName},LineNum:{sourceLineNumber},{msg}";
|
||||
To(msg, E_LogType.Error, isShow);
|
||||
}
|
||||
|
||||
public void GetCurrentClassFatal(string msg,bool isShow = false,
|
||||
[CallerMemberName] string memberName = "",
|
||||
[CallerFilePath] string sourceFilePath = "",
|
||||
[CallerLineNumber] int sourceLineNumber = 0)
|
||||
{
|
||||
msg = $"File:{sourceFilePath},Fun:{memberName},LineNum:{sourceLineNumber},{msg}";
|
||||
To(msg, E_LogType.Fatal, isShow);
|
||||
}
|
||||
#endregion
|
||||
private void To(string msg, E_LogType logType, bool isShow = false)
|
||||
{
|
||||
switch (logType)
|
||||
{
|
||||
case E_LogType.Debug:
|
||||
logger.Debug(msg);
|
||||
break;
|
||||
case E_LogType.Info:
|
||||
logger.Info(msg);
|
||||
break;
|
||||
case E_LogType.Warn:
|
||||
logger.Warn(msg);
|
||||
break;
|
||||
case E_LogType.Error:
|
||||
logger.Error(msg);
|
||||
break;
|
||||
case E_LogType.Fatal:
|
||||
logger.Fatal(msg);
|
||||
break;
|
||||
default:
|
||||
logger.Trace(msg);
|
||||
break;
|
||||
}
|
||||
Notice(msg, isShow, logType);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
46
Cowain.Bake.Common/Core/MessageEventWaitHandle.cs
Normal file
46
Cowain.Bake.Common/Core/MessageEventWaitHandle.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Cowain.Bake.Common.Core
|
||||
{
|
||||
public class MessageEventWaitHandle<T> : EventWaitHandle
|
||||
{
|
||||
private T message;
|
||||
private readonly object lockEvent = new object();//定义锁
|
||||
public MessageEventWaitHandle(bool initialState, EventResetMode mode)
|
||||
: base(initialState, mode)
|
||||
{
|
||||
}
|
||||
|
||||
public bool Set(T message)
|
||||
{
|
||||
//lock (lockEvent)
|
||||
{
|
||||
this.message = message;
|
||||
return base.Set();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public T GetMessage(int timeOut)
|
||||
{
|
||||
//lock (lockEvent)//因为这里锁住了,set给不了信号
|
||||
{
|
||||
if (!base.WaitOne(timeOut)) //为假超时
|
||||
{
|
||||
base.Reset();
|
||||
return default(T);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.Reset();
|
||||
return this.message;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
222
Cowain.Bake.Common/Core/SettingProvider.cs
Normal file
222
Cowain.Bake.Common/Core/SettingProvider.cs
Normal file
@@ -0,0 +1,222 @@
|
||||
using Cowain.Bake.Common.Core;
|
||||
using Cowain.Bake.Common.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Cowain.Bake.Common.Core
|
||||
{
|
||||
public class SettingProvider
|
||||
{
|
||||
const string MAIN = "Main";
|
||||
private static SettingProvider instance;
|
||||
public string PWD;
|
||||
|
||||
public string ProductionLineName;
|
||||
private static readonly object locker = new object();
|
||||
private int? _waterPallet;
|
||||
//private int? _stoveLayers;
|
||||
private int? _palletRows;
|
||||
private int? _palletCols;
|
||||
|
||||
private Enums.EDispatchMode _dispMode;
|
||||
public Enums.EDispatchMode DispMode
|
||||
{
|
||||
get
|
||||
{
|
||||
return _dispMode;
|
||||
}
|
||||
set
|
||||
{
|
||||
_dispMode = (Enums.EDispatchMode)value;
|
||||
INIHelper.Write(MAIN, "DispatchMode", _dispMode.ToString());
|
||||
}
|
||||
}
|
||||
public int WaterPallet
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == _waterPallet)
|
||||
{
|
||||
_waterPallet = INIHelper.ReadInt(MAIN, "WaterPallet", 0);
|
||||
}
|
||||
|
||||
return _waterPallet ?? 0;
|
||||
}
|
||||
set
|
||||
{
|
||||
_waterPallet = value;
|
||||
INIHelper.Write(MAIN, "WaterPallet", _waterPallet.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
//public int StoveLayers
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// if (null == _stoveLayers)
|
||||
// {
|
||||
// _stoveLayers = INIHelper.ReadInt(MAIN, "StoveLayers", 0);
|
||||
// }
|
||||
// return _stoveLayers ?? 0;
|
||||
// }
|
||||
//}
|
||||
|
||||
public int PalletRows
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == _palletRows)
|
||||
{
|
||||
_palletRows = INIHelper.ReadInt(MAIN, "PalletRows", 48);
|
||||
}
|
||||
return _palletRows ?? 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int PalletCols
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == _palletCols)
|
||||
{
|
||||
_palletCols = INIHelper.ReadInt(MAIN, "PalletCols", 2);
|
||||
}
|
||||
return _palletCols ?? 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int? _skinType;
|
||||
public int SkinType
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == _skinType)
|
||||
{
|
||||
_skinType = INIHelper.ReadInt(MAIN, "SkinType", 0);
|
||||
}
|
||||
|
||||
return _skinType ?? 0;
|
||||
}
|
||||
set
|
||||
{
|
||||
_skinType = value;
|
||||
INIHelper.Write(MAIN, "SkinType", _skinType.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public bool? _autoUpdate;
|
||||
public bool AutoUpdate
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == _autoUpdate)
|
||||
{
|
||||
_autoUpdate = INIHelper.ReadBool(MAIN, "AutoUpdate", false);
|
||||
}
|
||||
|
||||
return _autoUpdate ?? false;
|
||||
}
|
||||
set
|
||||
{
|
||||
_autoUpdate = value;
|
||||
INIHelper.Write(MAIN, "AutoUpdate", _autoUpdate.Value ? "1" : "0");
|
||||
}
|
||||
}
|
||||
|
||||
public string _autoUpdateUrl;
|
||||
public string AutoUpdateUrl
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(_autoUpdateUrl))
|
||||
{
|
||||
_autoUpdateUrl = INIHelper.ReadString(MAIN, "AutoUpdateUrl", "http://127.0.0.1:6688/update/update.xml");
|
||||
}
|
||||
|
||||
return _autoUpdateUrl;
|
||||
}
|
||||
set
|
||||
{
|
||||
_autoUpdateUrl = value;
|
||||
INIHelper.Write(MAIN, "AutoUpdateUrl", _autoUpdateUrl);
|
||||
}
|
||||
}
|
||||
|
||||
private EIsReverseOrder? _stoveDispDirection;
|
||||
public EIsReverseOrder StoveDispDirection
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == _stoveDispDirection)
|
||||
{
|
||||
_stoveDispDirection = (EIsReverseOrder)INIHelper.ReadInt(MAIN, "StoveDispDirection", 0);
|
||||
}
|
||||
|
||||
return _stoveDispDirection.Value;
|
||||
}
|
||||
}
|
||||
|
||||
private EIsReverseOrder? _isReverseOrder;
|
||||
public EIsReverseOrder IsReverseOrder
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == _isReverseOrder)
|
||||
{
|
||||
_isReverseOrder = (EIsReverseOrder)INIHelper.ReadInt(MAIN, "IsReverseOrder", 0);
|
||||
}
|
||||
|
||||
return _isReverseOrder.Value;
|
||||
}
|
||||
}
|
||||
|
||||
private int? _countCmd;
|
||||
public int CountCmd
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == _countCmd)
|
||||
{
|
||||
_countCmd = INIHelper.ReadInt(MAIN, "CountCmd", 0);
|
||||
}
|
||||
if (3000 <= _countCmd)
|
||||
{
|
||||
CountCmd = 0;
|
||||
}
|
||||
return _countCmd ?? 0;
|
||||
}
|
||||
set
|
||||
{
|
||||
_countCmd = value;
|
||||
INIHelper.Write(MAIN, "CountCmd", _countCmd.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public static SettingProvider Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new SettingProvider();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
SettingProvider()
|
||||
{
|
||||
PWD = INIHelper.ReadString(MAIN, "PassWord", "cowain2024");
|
||||
DispMode = (Enums.EDispatchMode)INIHelper.ReadInt(MAIN, "DispatchMode", 2);
|
||||
ProductionLineName = INIHelper.ReadString(MAIN, "ProductionLineName", ""); //有乱码
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user