96 lines
2.9 KiB
C#
96 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Xml.Serialization;
|
|
|
|
namespace CloudBuilder.CodeGenerator.Config
|
|
{
|
|
public class ToolInitConfig
|
|
{
|
|
private static ToolInitConfig instance = null;
|
|
private static string filename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config\\tool-init-config.xml");
|
|
private static ToolInitConfig Load()
|
|
{
|
|
if (!System.IO.File.Exists(filename))
|
|
{
|
|
throw new ValidationException("ToolInitConfig config file not found");
|
|
}
|
|
|
|
StringReader textReader = new StringReader(System.IO.File.ReadAllText(filename, Encoding.UTF8));
|
|
XmlSerializer serializer = new XmlSerializer(typeof(ToolInitConfig));
|
|
return (ToolInitConfig)serializer.Deserialize(textReader);
|
|
}
|
|
|
|
public static void ClearInstance()
|
|
{
|
|
instance = null;
|
|
}
|
|
|
|
public static ToolInitConfig GetInstance()
|
|
{
|
|
if (instance == null)
|
|
{
|
|
instance = Load();
|
|
}
|
|
return instance;
|
|
}
|
|
|
|
public string TemplatePath { get; set; }
|
|
public string CurrentAssembly { get; set; }
|
|
|
|
public string Using { get; set; }
|
|
|
|
public NamespaceObject[] NamespaceObjects { get; set; }
|
|
|
|
public AssemblyReference[] AssemblyReferences { get; set; }
|
|
|
|
public string[] ExculdePropertyTypes { get; set; }
|
|
|
|
public static void Save(ToolInitConfig toolInitConfig)
|
|
{
|
|
XmlSerializer xmlSerializer = new XmlSerializer(typeof(ToolInitConfig));
|
|
string xml = null;
|
|
|
|
using (MemoryStream stream = new MemoryStream())
|
|
{
|
|
StreamWriter writer = new StreamWriter(stream, Encoding.UTF8);
|
|
xmlSerializer.Serialize((TextWriter)writer, toolInitConfig);
|
|
stream.Seek(0L, SeekOrigin.Begin);
|
|
StreamReader reader = new StreamReader(stream, Encoding.UTF8);
|
|
xml = reader.ReadToEnd();
|
|
}
|
|
|
|
StreamWriter sw = new StreamWriter(filename, false);
|
|
sw.WriteLine(xml);
|
|
sw.Close();
|
|
sw.Dispose();
|
|
}
|
|
}
|
|
|
|
public class AssemblyReference
|
|
{
|
|
public string AssemblyFileName { get; set; }
|
|
}
|
|
|
|
public class NamespaceObject
|
|
{
|
|
public const string OUT_FILE_PATH = "OutFilePath";
|
|
public const string ASSEMBLY = "Assembly";
|
|
public const string NAMESPACE = "Namespace";
|
|
|
|
public string TemplateType { get; set; }
|
|
public string TemplateFileName { get; set; }
|
|
public string OutFilePath { get; set; }
|
|
public string Assembly { get; set; }
|
|
public string Namespace { get; set; }
|
|
|
|
public string FileNameSuffix { get; set; }
|
|
|
|
public string FileNamePrefix { get; set; }
|
|
|
|
}
|
|
}
|