Code//FrameworkConfiguraconfigManager完成代码 using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Xml.Serialization; namespace cn.CodeMarks.Framework.Plugin { public class FrameworkConfigurationManager { private static FrameworkConfigurationManager instance = null; public static FrameworkConfigurationManager Instance { get { if (FrameworkConfigurationManager.instance == null) { FrameworkConfigurationManager.instance = new FrameworkConfigurationManager(); } return FrameworkConfigurationManager.instance; } } private FrameworkConfiguration config = new FrameworkConfiguration(); public FrameworkConfiguration Config { get { return config; } set { config = value; } } public void Save() { FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write); XmlSerializer ser = new XmlSerializer(typeof(FrameworkConfiguration), new Type[] { typeof(PluginSettings), typeof(PluginSetting), typeof(AssemblyFile), }); ser.Serialize(fs, this.config); fs.Close(); } private string fileName = "FrameworkConfig.xml"; public void Load() { //不存配置文件 if (!File.Exists(fileName)) { this.config = new FrameworkConfiguration(); return; } FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); XmlSerializer ser = new XmlSerializer(typeof(FrameworkConfiguration), new Type[] { typeof(PluginSetting), typeof(PluginSettings), typeof(AssemblyFile) }); this.config = (FrameworkConfiguration)ser.Deserialize(fs); fs.Close(); } public void TestData() { PluginSetting ps1 = new PluginSetting(); ps1.PluginName = "UserPlugin"; ps1.Author = "codemarks"; ps1.Descript = " "; ps1.Version = "1.0"; ps1.WebRoot = "/plugin/user/webroot/"; AssemblyFile af1 = new AssemblyFile(); af1.Name = "CodeMarks.Framework.Plugin.Adapter.User"; af1.AdapterClassName = "CodeMarks.Framework.Plugin.Adapter.User.UserAdapter"; ps1.Items.Add(af1); this.config.PluginSettings.AddPlugin(ps1); PluginSetting ps = new PluginSetting(); ps.PluginName = "UserPlugin2"; ps.Author = "codemarks2"; ps.Descript = " "; ps.Version = "1.0"; ps.WebRoot = "/plugin/user/webroot/"; AssemblyFile af = new AssemblyFile(); af.Name = "CodeMarks.Framework.Plugin.Adapter.User2"; af.AdapterClassName = "CodeMarks.Framework.Plugin.Adapter.User.UserAdapter"; ps.Items.Add(af); this.config.PluginSettings.AddPlugin(ps); this.config.AppSettings.Items.Add(new AppSetting("conn", ".\\nbaqn")); this.config.AppSettings.Items.Add(new AppSetting("config", "frame.config")); this.config.AppSettings.Items.Add(new AppSetting("catch", "sql")); } } }