-
Notifications
You must be signed in to change notification settings - Fork 0
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
16 changed files
with
243 additions
and
47 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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using PluginCore.Attribute; | ||
|
||
namespace Core.SDKs.Services.Config; | ||
|
||
public class ScenarioMethodAttributeJsonCtr : JsonConverter<ScenarioMethodAttribute> | ||
{ | ||
public override ScenarioMethodAttribute? Read(ref Utf8JsonReader reader, Type typeToConvert, | ||
JsonSerializerOptions options) | ||
{ | ||
// 创建一个 ScenarioMethodAttribute 实例 | ||
ScenarioMethodAttribute attribute = new ScenarioMethodAttribute(); | ||
|
||
// 确保 JSON 数据以对象开始 | ||
if (reader.TokenType != JsonTokenType.StartObject) | ||
{ | ||
throw new JsonException(); | ||
} | ||
|
||
// 读取 JSON 对象的属性 | ||
while (reader.Read()) | ||
{ | ||
// 检查是否已经到达对象的结尾 | ||
if (reader.TokenType == JsonTokenType.EndObject) | ||
{ | ||
return attribute; | ||
} | ||
|
||
// 读取属性名称 | ||
string propertyName = reader.GetString(); | ||
reader.Read(); // 进入属性值 | ||
|
||
// 根据属性名称将值分配给属性 | ||
switch (propertyName) | ||
{ | ||
case "Name": | ||
attribute.Name = reader.GetString(); | ||
break; | ||
case "ParameterName": | ||
attribute.ParameterName = | ||
JsonSerializer.Deserialize<Dictionary<string, string>>(ref reader, options); | ||
break; | ||
default: | ||
// 跳过未处理的属性 | ||
reader.Skip(); | ||
break; | ||
} | ||
} | ||
|
||
return attribute; | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, ScenarioMethodAttribute value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteStartObject(); | ||
writer.WriteString("Name", value.Name); | ||
writer.WritePropertyName("ParameterName"); | ||
JsonSerializer.Serialize(writer, value.ParameterName, value.ParameterName.GetType(), options); | ||
writer.WriteEndObject(); | ||
} | ||
} |
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,36 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using Core.SDKs.CustomScenario; | ||
using Core.SDKs.Services.Plugin; | ||
|
||
namespace Core.SDKs.Services.Config; | ||
|
||
public class ScenarioMethodJsonCtr : JsonConverter<ScenarioMethod> | ||
{ | ||
public override ScenarioMethod? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
Console.WriteLine("OnDeserializing"); | ||
|
||
|
||
ScenarioMethod scenario = JsonSerializer.Deserialize<ScenarioMethod>(ref reader, options); | ||
if (scenario.IsFromPlugin) | ||
{ | ||
scenario.ServiceProvider = PluginManager.EnablePlugin[scenario.PluginInfo.ToPlgString()].ServiceProvider; | ||
scenario.Method = PluginManager.EnablePlugin[scenario.PluginInfo.ToPlgString()] | ||
.GetMethod(scenario._methodAbsolutelyName); | ||
} | ||
|
||
return scenario; | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, ScenarioMethod value, JsonSerializerOptions options) | ||
{ | ||
Console.WriteLine("OnSerializing"); | ||
|
||
// Don't pass in options when recursively calling Serialize. | ||
JsonSerializer.Serialize(writer, value, options); | ||
|
||
// Place "after" code here (OnSerialized) | ||
Console.WriteLine("OnSerialized"); | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.