-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
936 additions
and
739 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,44 @@ | ||
重新扫描文件! | ||
|
||
new ApplicationContext(new Form1()) | ||
|
||
检测到空成员文件 G:\Project\OpenSource\Natasha\samples\WinFormsSample\obj\Debug\net8.0-windows\WinFormsSample.GlobalUsings.g.cs. | ||
|
||
检测到空成员文件 G:\Project\OpenSource\Natasha\samples\WinFormsSample\obj\Release\net8.0-windows\WinFormsSample.GlobalUsings.g.cs. | ||
Renamed: G:\Project\OpenSource\Natasha\samples\WinFormsSample\Form1.Designer.cs -> G:\Project\OpenSource\Natasha\samples\WinFormsSample\Form1.Designer.cs~RF14d970e3.TMP | ||
|
||
Renamed: G:\Project\OpenSource\Natasha\samples\WinFormsSample\Program.cs -> G:\Project\OpenSource\Natasha\samples\WinFormsSample\Program.cs~RF5efaba5.TMP | ||
|
||
准备执行热编译... | ||
获取元数据.... | ||
|
||
new ApplicationContext(new Form1()) | ||
|
||
执行主入口前导方法.... | ||
|
||
A | ||
|
||
GC | ||
|
||
GC | ||
|
||
GC | ||
|
||
GC | ||
|
||
GC | ||
|
||
GC | ||
|
||
Na99a54ab23654527abf6159dc1a1ee02 �� | ||
|
||
Default �� | ||
|
||
N59b7ef6b28574ff38d072b805e886eaf �� | ||
|
||
AFGB | ||
|
||
3 | ||
|
||
执行主入口回调方法.... | ||
|
||
当前将被注销的开放窗体 Form1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...tasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/DelegateHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using System.Text; | ||
|
||
namespace Natasha.CSharp.HotExecutor.Component | ||
{ | ||
public static class DelegateHelper<T> | ||
{ | ||
public static Action<T>? Execute; | ||
public static void GetDelegate(string methodName,BindingFlags flags) | ||
{ | ||
var methodInfo = typeof(T).GetMethod(methodName, flags); | ||
Execute = (Action<T>)Delegate.CreateDelegate(typeof(Action<T>), methodInfo); | ||
} | ||
} | ||
public static class DelegateHelper<T,R> | ||
{ | ||
public static Action<T,R>? Execute; | ||
public static void GetDelegate(string methodName, BindingFlags flags) | ||
{ | ||
var methodInfo = typeof(T).GetMethod(methodName, flags); | ||
Execute = (Action<T, R>)Delegate.CreateDelegate(typeof(Action<T, R>), methodInfo); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/IOUtils/HEFileHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using Natasha.CSharp.Extension.HotExecutor; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Text; | ||
|
||
namespace Natasha.CSharp.HotExecutor.Component | ||
{ | ||
public static class HEFileHelper | ||
{ | ||
public async static Task<string> ReadUtf8FileAsync(string file) | ||
{ | ||
if (!File.Exists(file)) | ||
{ | ||
#if DEBUG | ||
HEProxy.ShowMessage($"不存在文件:{file}"); | ||
#endif | ||
return string.Empty; | ||
} | ||
StreamReader stream; | ||
do | ||
{ | ||
try | ||
{ | ||
stream = new(file, Encoding.UTF8); | ||
var content = await stream.ReadToEndAsync(); | ||
stream.Dispose(); | ||
return content; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Debug.WriteLine("命中文件读锁!"); | ||
Thread.Sleep(200); | ||
} | ||
|
||
|
||
} while (true); | ||
|
||
} | ||
public async static Task WriteUtf8FileAsync(string file, string msg) | ||
{ | ||
do | ||
{ | ||
try | ||
{ | ||
using StreamWriter stream = new(file, true, Encoding.UTF8); | ||
await stream.WriteLineAsync(msg); | ||
await stream.FlushAsync(); | ||
} | ||
catch (Exception) | ||
{ | ||
Debug.WriteLine("命中文件写锁!"); | ||
Thread.Sleep(200); | ||
} | ||
|
||
|
||
} while (true); | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/IOUtils/HEFileLogger.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using Natasha.CSharp.Extension.HotExecutor; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Text; | ||
|
||
namespace Natasha.CSharp.HotExecutor.Component | ||
{ | ||
public class HEFileLogger | ||
{ | ||
private readonly HESpinLock _fileLock = new(); | ||
//private readonly StreamWriter _writer; | ||
private readonly string _file; | ||
public HEFileLogger(string file) | ||
{ | ||
var folder = Path.GetDirectoryName(file); | ||
if (!Directory.Exists(folder)) | ||
{ | ||
Directory.CreateDirectory(folder); | ||
} | ||
_file = file; | ||
|
||
} | ||
|
||
public async Task WriteUtf8FileAsync(string msg) | ||
{ | ||
bool isWritten = false; | ||
_fileLock.GetAndWaitLock(); | ||
do | ||
{ | ||
try | ||
{ | ||
using StreamWriter _writer = new(_file, true, Encoding.UTF8); | ||
if (_writer.BaseStream.CanWrite) | ||
{ | ||
await _writer.WriteLineAsync(msg); | ||
isWritten = true; | ||
_fileLock.ReleaseLock(); | ||
await _writer.FlushAsync(); | ||
} | ||
return; | ||
} | ||
catch (Exception) | ||
{ | ||
Debug.WriteLine("命中 HE 日志写锁!"); | ||
Thread.Sleep(200); | ||
} | ||
|
||
} while (!isWritten); | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
.../Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxUtils/CS0104Analyser.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using Microsoft.CodeAnalysis; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Natasha.CSharp.HotExecutor.Component.SyntaxUtils | ||
{ | ||
internal class CS0104Analyser | ||
{ | ||
public static string _proxyCommentCS0104Using = "//HE:CS0104".ToLower(); | ||
public static HashSet<string> Handle(CompilationUnitSyntax root) | ||
{ | ||
HashSet<string> tempSets = []; | ||
HashSet<SyntaxTrivia> triviaSets = []; | ||
foreach (SyntaxNode node in root.DescendantNodesAndSelf()) | ||
{ | ||
foreach (SyntaxTrivia trivia in node.GetLeadingTrivia()) | ||
{ | ||
if (triviaSets.Contains(trivia)) | ||
{ | ||
continue; | ||
} | ||
if (trivia.IsKind(SyntaxKind.SingleLineCommentTrivia)) | ||
{ | ||
var commentText = trivia.ToString().Trim().ToLower(); | ||
if (commentText.Length > _proxyCommentCS0104Using.Length) | ||
{ | ||
if (commentText.StartsWith(_proxyCommentCS0104Using)) | ||
{ | ||
triviaSets.Add(trivia); | ||
//#if DEBUG | ||
// Debug.WriteLine($"找到剔除点:{commentText}"); | ||
// Debug.WriteLine($"整个节点为:{node.ToFullString()}"); | ||
//#endif | ||
var usingStrings = trivia.ToString().Trim().Substring(_proxyCommentCS0104Using.Length, commentText.Length - _proxyCommentCS0104Using.Length); | ||
tempSets.UnionWith(usingStrings.Split([';'], StringSplitOptions.RemoveEmptyEntries).Select(item => item.Trim())); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return tempSets; | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...p/Extension/HotExecutor/Natasha.CSharp.HotExecutor/Component/SyntaxUtils/ConsoleWriter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
|
||
namespace Natasha.CSharp.HotExecutor.Component.SyntaxUtils | ||
{ | ||
internal static class ConsoleWriter | ||
{ | ||
public static BlockSyntax? Handle(BlockSyntax blockSyntax) | ||
{ | ||
if (blockSyntax.Statements.Count > 0) | ||
{ | ||
var node = blockSyntax.Statements.Last(); | ||
if (node.IsKind(Microsoft.CodeAnalysis.CSharp.SyntaxKind.ExpressionStatement)) | ||
{ | ||
if (node.ToString() == "Console.ReadKey();") | ||
{ | ||
return blockSyntax.RemoveNode(node, SyntaxRemoveOptions.KeepExteriorTrivia); | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
} | ||
} |
Oops, something went wrong.