2021-07-23 09:42:22 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
using System.Xml.Serialization;
|
2022-10-28 22:45:39 +08:00
|
|
|
|
using AIStudio.Wpf.DiagramDesigner;
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2022-10-28 22:45:39 +08:00
|
|
|
|
namespace AIStudio.Wpf.DiagramApp.Models
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
[XmlRootAttribute(Namespace = DiagramDocument.XMLNS, IsNullable = false)]
|
|
|
|
|
|
public class DiagramDocument
|
|
|
|
|
|
{
|
|
|
|
|
|
[XmlAttribute]
|
|
|
|
|
|
public string Title { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
[XmlAttribute]
|
|
|
|
|
|
public DiagramType DiagramType { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
[XmlArray]
|
|
|
|
|
|
public List<DiagramItem> DiagramItems { get; set; }
|
|
|
|
|
|
|
2023-01-25 11:11:27 +08:00
|
|
|
|
public const string XMLNS = "https://gitee.com/akwkevin/aistudio.-wpf.-diagram";
|
2021-07-23 09:42:22 +08:00
|
|
|
|
private readonly object saveLock = new Object();
|
|
|
|
|
|
|
|
|
|
|
|
public void Save(FileInfo designFile)
|
|
|
|
|
|
{
|
|
|
|
|
|
lock (saveLock)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
FileStream streamToUse;
|
|
|
|
|
|
XmlSerializer serializer = new XmlSerializer(typeof(DiagramDocument));
|
|
|
|
|
|
|
|
|
|
|
|
if (designFile.Exists)
|
|
|
|
|
|
{
|
|
|
|
|
|
File.Delete(designFile.FullName);
|
|
|
|
|
|
}
|
|
|
|
|
|
streamToUse = designFile.Open(FileMode.OpenOrCreate, FileAccess.Write);
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings();
|
|
|
|
|
|
settings.Indent = true;
|
|
|
|
|
|
XmlWriter writer = XmlWriter.Create(streamToUse, settings);
|
|
|
|
|
|
serializer.Serialize(writer, this);
|
|
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
streamToUse.Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|