整理代码
This commit is contained in:
97
ShrlAlgo.Addin.Test/GdiAssist.cs
Normal file
97
ShrlAlgo.Addin.Test/GdiAssist.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using Color = System.Drawing.Color;
|
||||
using Point = System.Drawing.Point;
|
||||
using Rectangle = System.Drawing.Rectangle;
|
||||
|
||||
namespace ShrlAlgoToolkit.Core.Assists;
|
||||
|
||||
public static class GdiAssist
|
||||
{
|
||||
public static void DrawArc(Graphics graphics)
|
||||
{
|
||||
Pen myPen = new(Color.Blue, 5);
|
||||
Rectangle myRectangle = new(70, 20, 100, 60);
|
||||
graphics.DrawArc(myPen, myRectangle, 210, 120);
|
||||
}
|
||||
|
||||
public static void DrawBezier(Graphics graphics)
|
||||
{
|
||||
Pen myPen = new(Color.Red, 5);
|
||||
var startX = 50.0F;
|
||||
var startY = 80.0F;
|
||||
var controlX1 = 150.0F;
|
||||
var controlY1 = 20.0F;
|
||||
var controlX2 = 230.0F;
|
||||
var controlY2 = 50.0F;
|
||||
var endX = 190.0F;
|
||||
var endY = 80.0F;
|
||||
graphics.DrawBezier(myPen, startX, startY, controlX1, controlY1, controlX2, controlY2, endX, endY);
|
||||
}
|
||||
|
||||
public static void DrawCurve(Graphics graphics)
|
||||
{
|
||||
Pen myPen = new(Color.Red, 5);
|
||||
Point point1 = new(50, 20);
|
||||
Point point2 = new(60, 30);
|
||||
Point point3 = new(70, 25);
|
||||
Point point4 = new(100, 50);
|
||||
Point point5 = new(130, 30);
|
||||
Point point6 = new(150, 45);
|
||||
Point[] myPoints = { point1, point2, point3, point4, point5, point6 };
|
||||
graphics.DrawCurve(myPen, myPoints, 1.0F);
|
||||
}
|
||||
|
||||
public static void DrawEllipse(Graphics graphics)
|
||||
{
|
||||
Pen myPen = new(Color.Blue, 3);
|
||||
Rectangle myRectangle = new(70, 20, 100, 60);
|
||||
graphics.DrawEllipse(myPen, myRectangle);
|
||||
}
|
||||
|
||||
public static void DrawLine(Graphics graphics)
|
||||
{
|
||||
//Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);
|
||||
Pen myPen = new(Color.Blue, 2);
|
||||
graphics.DrawLine(myPen, 50, 30, 170, 30);
|
||||
}
|
||||
|
||||
public static void DrawLine(Graphics graphics, Point p1, Point p2)
|
||||
{
|
||||
//Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);
|
||||
Pen myPen = new(Color.Blue, 2);
|
||||
graphics.DrawLine(myPen, p1.X, p1.Y, p2.X, p2.Y);
|
||||
}
|
||||
|
||||
public static void DrawPath(Graphics graphics)
|
||||
{
|
||||
GraphicsPath myGraphicsPath = new();
|
||||
Pen myPen = new(Color.Blue, 1);
|
||||
Point[] myPoints = { new(15, 30), new(30, 40), new(50, 30) };
|
||||
myGraphicsPath.AddArc(15, 20, 80, 50, 210, 120);
|
||||
myGraphicsPath.StartFigure();
|
||||
myGraphicsPath.AddCurve(myPoints);
|
||||
myGraphicsPath.AddString("图形路径", new FontFamily("华文行楷"), (int)FontStyle.Underline, 50, new PointF(20, 50), new StringFormat());
|
||||
myGraphicsPath.AddPie(180, 20, 80, 50, 210, 120);
|
||||
graphics.DrawPath(myPen, myGraphicsPath);
|
||||
}
|
||||
|
||||
public static void DrawPolygon(Graphics graphics)
|
||||
{
|
||||
Pen myPen = new(Color.Red, 5);
|
||||
Point point1 = new(80, 20);
|
||||
Point point2 = new(40, 50);
|
||||
Point point3 = new(80, 80);
|
||||
Point point4 = new(160, 80);
|
||||
Point point5 = new(200, 50);
|
||||
Point point6 = new(160, 20);
|
||||
Point[] myPoints = { point1, point2, point3, point4, point5, point6 };
|
||||
graphics.DrawPolygon(myPen, myPoints);
|
||||
}
|
||||
|
||||
public static void DrawRectangle(Graphics graphics)
|
||||
{
|
||||
Pen myPen = new(Color.Blue, 2);
|
||||
graphics.DrawRectangle(myPen, 70, 20, 80, 50);
|
||||
}
|
||||
}
|
||||
138
ShrlAlgo.Addin.Test/LogAssist.cs
Normal file
138
ShrlAlgo.Addin.Test/LogAssist.cs
Normal file
@@ -0,0 +1,138 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace ShrlAlgoToolkit.Core.Assists;
|
||||
|
||||
public static class LogAssist
|
||||
{
|
||||
//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(LogAssist).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");
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public static void ToLog(this Exception execption, string logFolder = default)
|
||||
{
|
||||
if (logFolder == default)
|
||||
{
|
||||
var assemblyPath = typeof(LogAssist).Assembly.Location;
|
||||
var directory = Path.GetDirectoryName(assemblyPath);
|
||||
logFolder = $"{directory}\\Logs";
|
||||
}
|
||||
|
||||
if (Directory.Exists(logFolder))
|
||||
{
|
||||
logFolder = Directory.GetCurrentDirectory();
|
||||
}
|
||||
else
|
||||
{
|
||||
Directory.CreateDirectory(logFolder);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
var name = frame.GetMethod().Name;
|
||||
str1 = string.Concat(str, ".", name);
|
||||
}
|
||||
catch
|
||||
{
|
||||
str1 = null;
|
||||
}
|
||||
|
||||
return str1;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
return ((Exception)o).Message;
|
||||
}
|
||||
}
|
||||
@@ -120,6 +120,7 @@ public class RevitAddin : ExternalCommand
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
|
||||
public override void Execute()
|
||||
{
|
||||
try
|
||||
|
||||
@@ -50,8 +50,5 @@
|
||||
<PackageReference Include="EPPlus.Core.Extensions" Version="2.4.0" />
|
||||
<PackageReference Include="Nice3point.Revit.Toolkit" Version="2019.*" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ShrlAlgoToolkit.Core\ShrlAlgoToolkit.Core.csproj" />
|
||||
</ItemGroup>
|
||||
<Import Project="..\ShrlAlgoToolkit.Revit\ShrlAlgoToolkit.Revit.projitems" Label="Shared" />
|
||||
</Project>
|
||||
Reference in New Issue
Block a user