序列化继续改进

This commit is contained in:
艾竹
2023-01-25 11:11:27 +08:00
parent a5005ac083
commit a01eb8825a
44 changed files with 319 additions and 398 deletions

View File

@@ -19,6 +19,7 @@ using System.Windows.Media;
using AIStudio.Wpf.Flowchart.Models;
using AIStudio.Wpf.SFC.Models;
using System.Windows;
using System;
namespace AIStudio.Wpf.DiagramApp.ViewModels
{
@@ -239,10 +240,13 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
{
try
{
var xmlobject = JsonConvert.DeserializeObject<DiagramDocument>(File.ReadAllText(filename));
var diagramItemData = xmlobject.DiagramItems[0].AllDesignerItems[0];
var xmlobject = JsonConvert.DeserializeObject<DiagramDocument>(File.ReadAllText(filename));
return diagramItemData;
Type type = TypeHelper.GetType(xmlobject.DiagramItems[0].DesignerItems[0].SerializableTypeName);
var itemBase = JsonConvert.DeserializeObject(xmlobject.DiagramItems[0].DesignerItems[0].SerializableString, type) as DesignerItemBase;
return itemBase;
}
catch
{
@@ -259,7 +263,7 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
DiagramDocument diagramDocument = new DiagramDocument();
diagramDocument.DiagramItems = new List<DiagramItem>();
DiagramItem diagramItem = new DiagramItem();
diagramItem.AddItems(new List<DesignerItemViewModelBase> { designer });
diagramItem.DesignerItems = new List<DiagramDesigner.Models.SerializableItem> { designer.ToSerializableItem(".json") };
diagramDocument.DiagramItems.Add(diagramItem);
string newname = NewNameHelper.GetNewName(MyToolBoxCategory.ToolBoxItems.OfType<DesignerItemToolBoxData>().Select(p => Path.GetFileNameWithoutExtension(p.FileName)), "");
var filename = $"{_custom}\\{newname}.json";