修复bug和新增部分功能
This commit is contained in:
@@ -38,7 +38,7 @@ public class IniHelper
|
||||
public string IniReadValue(string section, string key)
|
||||
{
|
||||
var temp = new StringBuilder(255);
|
||||
var i = GetPrivateProfileString(section, key, "", temp, 255, path);
|
||||
GetPrivateProfileString(section, key, "", temp, 255, path);
|
||||
return temp.ToString();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,133 +6,133 @@ namespace Sai.Toolkit.Core.Helpers;
|
||||
|
||||
public static class LogHelper
|
||||
{
|
||||
//public static void WriteSeriLog(string path, string message)
|
||||
//{
|
||||
// Log.Logger = new LoggerConfiguration().WriteTo.File(path).CreateLogger();
|
||||
// Log.Error(message);
|
||||
// Log.CloseAndFlush();
|
||||
//}
|
||||
public static void ToLog(this string strLog, string logFolder = default)
|
||||
{
|
||||
if (logFolder == default)
|
||||
{
|
||||
var assemblyPath = typeof(LogHelper).Assembly.Location;
|
||||
var directory = Path.GetDirectoryName(assemblyPath);
|
||||
logFolder = $"{directory}\\Logs";
|
||||
}
|
||||
//public static void WriteSeriLog(string path, string message)
|
||||
//{
|
||||
// Log.Logger = new LoggerConfiguration().WriteTo.File(path).CreateLogger();
|
||||
// Log.Error(message);
|
||||
// Log.CloseAndFlush();
|
||||
//}
|
||||
public static void ToLog(this string strLog, string logFolder = default)
|
||||
{
|
||||
if (logFolder == default)
|
||||
{
|
||||
var assemblyPath = typeof(LogHelper).Assembly.Location;
|
||||
var directory = Path.GetDirectoryName(assemblyPath);
|
||||
logFolder = Path.Combine(directory, "Logs");
|
||||
}
|
||||
|
||||
if (!Directory.Exists(logFolder))
|
||||
{
|
||||
Directory.CreateDirectory(logFolder);
|
||||
}
|
||||
//logFolder = Directory.GetCurrentDirectory();返回是Revit目录
|
||||
var logFile = Path.Combine(logFolder, DateTime.Now.ToString("yyyy-MM-dd") + ".log");
|
||||
if (!Directory.Exists(logFolder))
|
||||
{
|
||||
Directory.CreateDirectory(logFolder);
|
||||
}
|
||||
//logFolder = Directory.GetCurrentDirectory();返回是Revit目录
|
||||
var logFile = Path.Combine(logFolder, DateTime.Now.ToString("yyyy-MM-dd") + ".log");
|
||||
|
||||
var fs = File.Exists(logFile)
|
||||
? new FileStream(logFile, FileMode.Append, FileAccess.Write)
|
||||
: new FileStream(logFile, FileMode.Create, FileAccess.Write);
|
||||
var fs = File.Exists(logFile)
|
||||
? new FileStream(logFile, FileMode.Append, FileAccess.Write)
|
||||
: new FileStream(logFile, FileMode.Create, FileAccess.Write);
|
||||
|
||||
using StreamWriter sw = new(fs);
|
||||
sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss-ffff : ") + strLog);
|
||||
sw.Close();
|
||||
fs.Close();
|
||||
}
|
||||
using StreamWriter sw = new(fs);
|
||||
sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss-ffff : ") + strLog);
|
||||
sw.Close();
|
||||
fs.Close();
|
||||
}
|
||||
|
||||
public static void ToLog(this Exception execption, string logFolder = default)
|
||||
{
|
||||
if (logFolder == default)
|
||||
{
|
||||
var assemblyPath = typeof(LogHelper).Assembly.Location;
|
||||
var directory = Path.GetDirectoryName(assemblyPath);
|
||||
logFolder = $"{directory}\\Logs";
|
||||
}
|
||||
public static void ToLog(this Exception execption, string logFolder = default)
|
||||
{
|
||||
if (logFolder == default)
|
||||
{
|
||||
var assemblyPath = typeof(LogHelper).Assembly.Location;
|
||||
var directory = Path.GetDirectoryName(assemblyPath);
|
||||
logFolder = $"{directory}\\Logs";
|
||||
}
|
||||
|
||||
if (Directory.Exists(logFolder))
|
||||
{
|
||||
logFolder = Directory.GetCurrentDirectory();
|
||||
}
|
||||
else
|
||||
{
|
||||
Directory.CreateDirectory(logFolder);
|
||||
}
|
||||
if (Directory.Exists(logFolder))
|
||||
{
|
||||
logFolder = Directory.GetCurrentDirectory();
|
||||
}
|
||||
else
|
||||
{
|
||||
Directory.CreateDirectory(logFolder);
|
||||
}
|
||||
|
||||
var logFile = Path.Combine(logFolder, DateTime.Now.ToString("yyyy-MM-dd") + ".log");
|
||||
var logFile = Path.Combine(logFolder, DateTime.Now.ToString("yyyy-MM-dd") + ".log");
|
||||
|
||||
var fs = File.Exists(logFile)
|
||||
? new FileStream(logFile, FileMode.Append, FileAccess.Write)
|
||||
: new FileStream(logFile, FileMode.Create, FileAccess.Write);
|
||||
var fs = File.Exists(logFile)
|
||||
? new FileStream(logFile, FileMode.Append, FileAccess.Write)
|
||||
: new FileStream(logFile, FileMode.Create, FileAccess.Write);
|
||||
|
||||
using StreamWriter sw = new(fs);
|
||||
sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss-ffff : ") + execption.Message);
|
||||
sw.Close();
|
||||
fs.Close();
|
||||
}
|
||||
using StreamWriter sw = new(fs);
|
||||
sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss-ffff : ") + execption.Message);
|
||||
sw.Close();
|
||||
fs.Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 输出到桌面
|
||||
/// </summary>
|
||||
/// <param name="sb"></param>
|
||||
/// <param name="fileName"></param>
|
||||
public static void WriteTextFile(this StringBuilder sb, string fileName = "输出日志")
|
||||
{
|
||||
var filePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + $"\\{fileName}.txt";
|
||||
File.WriteAllText(filePath, sb.ToString());
|
||||
System.Diagnostics.Process.Start(filePath);
|
||||
}
|
||||
/// <summary>
|
||||
/// 输出到桌面
|
||||
/// </summary>
|
||||
/// <param name="sb"></param>
|
||||
/// <param name="fileName"></param>
|
||||
public static void WriteTextFile(this StringBuilder sb, string fileName = "输出日志")
|
||||
{
|
||||
var filePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + $"\\{fileName}.txt";
|
||||
File.WriteAllText(filePath, sb.ToString());
|
||||
System.Diagnostics.Process.Start(filePath);
|
||||
}
|
||||
|
||||
public static void WriteTextFile(this string lineContent, string filePath)
|
||||
{
|
||||
FileStream fs = new(filePath, FileMode.Create, FileAccess.Write);
|
||||
using StreamWriter sw = new(fs);
|
||||
sw.WriteLine(lineContent);
|
||||
sw.Close();
|
||||
fs.Close();
|
||||
}
|
||||
public static void WriteTextFile(this string lineContent, string filePath)
|
||||
{
|
||||
FileStream fs = new(filePath, FileMode.Create, FileAccess.Write);
|
||||
using StreamWriter sw = new(fs);
|
||||
sw.WriteLine(lineContent);
|
||||
sw.Close();
|
||||
fs.Close();
|
||||
}
|
||||
|
||||
public static string GetCurrentMethodFullName()
|
||||
{
|
||||
string str1;
|
||||
try
|
||||
{
|
||||
var num = 2;
|
||||
StackTrace stackTrace = new();
|
||||
var length = stackTrace.GetFrames()!.Length;
|
||||
StackFrame frame;
|
||||
string str;
|
||||
bool flag;
|
||||
do
|
||||
{
|
||||
var num1 = num;
|
||||
num = num1 + 1;
|
||||
frame = stackTrace.GetFrame(num1);
|
||||
str = frame.GetMethod().DeclaringType?.ToString();
|
||||
flag = str!.EndsWith("Exception") && num < length;
|
||||
} while (flag);
|
||||
public static string GetCurrentMethodFullName()
|
||||
{
|
||||
string str1;
|
||||
try
|
||||
{
|
||||
var num = 2;
|
||||
StackTrace stackTrace = new();
|
||||
var length = stackTrace.GetFrames()!.Length;
|
||||
StackFrame frame;
|
||||
string str;
|
||||
bool flag;
|
||||
do
|
||||
{
|
||||
var num1 = num;
|
||||
num = num1 + 1;
|
||||
frame = stackTrace.GetFrame(num1);
|
||||
str = frame.GetMethod().DeclaringType?.ToString();
|
||||
flag = str!.EndsWith("Exception") && num < length;
|
||||
} while (flag);
|
||||
|
||||
var name = frame.GetMethod().Name;
|
||||
str1 = string.Concat(str, ".", name);
|
||||
}
|
||||
catch
|
||||
{
|
||||
str1 = null;
|
||||
}
|
||||
var name = frame.GetMethod().Name;
|
||||
str1 = string.Concat(str, ".", name);
|
||||
}
|
||||
catch
|
||||
{
|
||||
str1 = null;
|
||||
}
|
||||
|
||||
return str1;
|
||||
}
|
||||
return str1;
|
||||
}
|
||||
|
||||
public static string ToChineseMessage(this Exception ex)
|
||||
{
|
||||
while (ex.InnerException != null)
|
||||
{
|
||||
ex = ex.InnerException;
|
||||
}
|
||||
public static string ToChineseMessage(this Exception ex)
|
||||
{
|
||||
while (ex.InnerException != null)
|
||||
{
|
||||
ex = ex.InnerException;
|
||||
}
|
||||
|
||||
var t = ex.GetType();
|
||||
var currentUICulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
|
||||
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CN");
|
||||
var o = Activator.CreateInstance(t);
|
||||
System.Threading.Thread.CurrentThread.CurrentUICulture = currentUICulture;
|
||||
var t = ex.GetType();
|
||||
var currentUICulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
|
||||
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CN");
|
||||
var o = Activator.CreateInstance(t);
|
||||
System.Threading.Thread.CurrentThread.CurrentUICulture = currentUICulture;
|
||||
|
||||
return ((Exception)o).Message;
|
||||
}
|
||||
return ((Exception)o).Message;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace Sai.Toolkit.Core.Helpers;
|
||||
public sealed record SingletonViewHelper<T>
|
||||
where T : Window, new()
|
||||
{
|
||||
private static T instance;
|
||||
private static T _instance;
|
||||
private static readonly object Padlock = new();
|
||||
|
||||
private SingletonViewHelper() { }
|
||||
@@ -15,21 +15,21 @@ public sealed record SingletonViewHelper<T>
|
||||
{
|
||||
isNewCreate = false;
|
||||
//double-check locking
|
||||
if (instance == null)
|
||||
if (_instance == null)
|
||||
{
|
||||
isNewCreate = true;
|
||||
lock (Padlock)
|
||||
{
|
||||
instance ??= new T();
|
||||
instance.Closed += OnWindowClosed;
|
||||
_instance ??= new T();
|
||||
_instance.Closed += OnWindowClosed;
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
return _instance;
|
||||
}
|
||||
|
||||
private static void OnWindowClosed(object sender, EventArgs e)
|
||||
{
|
||||
instance = null;
|
||||
_instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -311,7 +311,7 @@ public class StringHelper
|
||||
//StringFormat={}{0:m} May 04
|
||||
//StringFormat={}{0:Distinct} May 04
|
||||
//StringFormat={}{0:t} 5:46 PM
|
||||
//StringFormat={}{0:T} 5:46:56 PM
|
||||
//StringFormat={}{0:Command} 5:46:56 PM
|
||||
//StringFormat={}{0:yyyy年MM月dd日} 2015年05月04日
|
||||
//StringFormat={}{0:yyyy-MM-dd} 2015-05-04
|
||||
//StringFormat={}{0:yyyy-MM-dd HH:mm} 2015-05-04 17:46
|
||||
|
||||
@@ -102,7 +102,7 @@ public static class WinDialogHelper
|
||||
//loaderUtil.HookAssemblyResolve();
|
||||
//try
|
||||
//{
|
||||
// var view = SingletonViewHelper<T>.GetInstance(out var isNewCreate);
|
||||
// var view = SingletonViewHelper<Command>.GetInstance(out var isNewCreate);
|
||||
// if (isNewCreate)
|
||||
// {
|
||||
// view.DataContext = viewModel;
|
||||
|
||||
@@ -16,7 +16,7 @@ public class XmlHelper
|
||||
/// <summary>
|
||||
/// 创建配置文件,可在子类中重写此方法
|
||||
/// </summary>
|
||||
public void CreateFile(string fileName)
|
||||
public static void CreateFile(string fileName)
|
||||
{
|
||||
var doc = new XmlDocument();
|
||||
var dec = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
|
||||
|
||||
Reference in New Issue
Block a user