MUDEngine:
* Created a FileSystem class. FileSystem acts as a back end class for saving and loading data. Adding additional file types or data management options such as SQL will not be easier to implement by creating a new class that the FileSystem class can use. * XmlSerialization class is no longer public. It's changed to internal and has its information passed to it via the FileSystem class. Project Manager: * Project Manager now uses the FileSystem class for saving and loading data instead of the XmlSerialization class.
This commit is contained in:
parent
6004bd0c58
commit
97274cb4aa
5 changed files with 92 additions and 6 deletions
41
MUDEngine/FileSystem/FileSystem.cs
Normal file
41
MUDEngine/FileSystem/FileSystem.cs
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace MUDEngine.FileSystem
|
||||||
|
{
|
||||||
|
public static class FileSystem
|
||||||
|
{
|
||||||
|
public enum OutputFormats
|
||||||
|
{
|
||||||
|
XML = 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The filetype that the MUDs files will be saved as
|
||||||
|
/// </summary>
|
||||||
|
public static OutputFormats FileType
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Save(string Filename, object o)
|
||||||
|
{
|
||||||
|
if (FileType == OutputFormats.XML)
|
||||||
|
{
|
||||||
|
XmlSerialization.Save(Filename, o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static object Load(string Filename, object o)
|
||||||
|
{
|
||||||
|
if (FileType == OutputFormats.XML)
|
||||||
|
{
|
||||||
|
return XmlSerialization.Load(Filename, o);
|
||||||
|
}
|
||||||
|
else return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
42
MUDEngine/FileSystem/XmlSerialization.cs
Normal file
42
MUDEngine/FileSystem/XmlSerialization.cs
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
#region ====== Using Statements ======
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Xml;
|
||||||
|
using System.Xml.Serialization;
|
||||||
|
using System.IO;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace MUDEngine.FileSystem
|
||||||
|
{
|
||||||
|
internal class XmlSerialization
|
||||||
|
{
|
||||||
|
internal static void Save(string Filename, object o)
|
||||||
|
{
|
||||||
|
Stream stream = File.Create(Filename);
|
||||||
|
|
||||||
|
XmlSerializer serializer = new XmlSerializer(o.GetType());
|
||||||
|
serializer.Serialize(stream, o);
|
||||||
|
stream.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Loads an item via Xml Deserialization
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Filename">The Xml document to deserialize.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
internal static object Load(string Filename, object o)
|
||||||
|
{
|
||||||
|
Stream stream = File.OpenRead(Filename);
|
||||||
|
|
||||||
|
object obj = new object();
|
||||||
|
XmlSerializer serializer = new XmlSerializer(o.GetType());
|
||||||
|
obj = (object)serializer.Deserialize(stream);
|
||||||
|
|
||||||
|
stream.Close();
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -54,7 +54,8 @@
|
||||||
<Compile Include="Environment\Realm.cs" />
|
<Compile Include="Environment\Realm.cs" />
|
||||||
<Compile Include="Environment\Room.cs" />
|
<Compile Include="Environment\Room.cs" />
|
||||||
<Compile Include="Environment\Zone.cs" />
|
<Compile Include="Environment\Zone.cs" />
|
||||||
<Compile Include="XmlSerialization.cs" />
|
<Compile Include="FileSystem\FileSystem.cs" />
|
||||||
|
<Compile Include="FileSystem\XmlSerialization.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
|
|
@ -15,14 +15,16 @@ namespace Project_Manager
|
||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
project = new MUDEngine.ProjectInformation();
|
|
||||||
//Make sure all our paths are created before we start working with the editor.
|
//Make sure all our paths are created before we start working with the editor.
|
||||||
MUDEngine.Engine.ValidateProjectPath(Application.StartupPath);
|
MUDEngine.Engine.ValidateProjectPath(Application.StartupPath);
|
||||||
|
MUDEngine.FileSystem.FileSystem.FileType = MUDEngine.FileSystem.FileSystem.OutputFormats.XML;
|
||||||
|
|
||||||
|
project = new MUDEngine.ProjectInformation();
|
||||||
|
|
||||||
//check if a project file exists, or use the new instance
|
//check if a project file exists, or use the new instance
|
||||||
if (System.IO.File.Exists(Application.StartupPath + @"\Data\project.xml"))
|
if (System.IO.File.Exists(Application.StartupPath + @"\Data\project.xml"))
|
||||||
{
|
{
|
||||||
project = (MUDEngine.ProjectInformation)MUDEngine.XmlSerialization.Load(Application.StartupPath + @"\Data\project.xml", project);
|
project = (MUDEngine.ProjectInformation)MUDEngine.FileSystem.FileSystem.Load(Application.StartupPath + @"\Data\project.xml", project);
|
||||||
}
|
}
|
||||||
|
|
||||||
//run the app
|
//run the app
|
||||||
|
@ -30,7 +32,7 @@ namespace Project_Manager
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
Application.Run(new frmMain());
|
Application.Run(new frmMain());
|
||||||
|
|
||||||
MUDEngine.XmlSerialization.Save(Application.StartupPath + @"\Data\project.xml", project);
|
MUDEngine.FileSystem.FileSystem.Save(Application.StartupPath + @"\Data\project.xml", project);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ namespace Project_Manager
|
||||||
//Instance a new realm
|
//Instance a new realm
|
||||||
MUDEngine.Environment.Realm newRealm = new MUDEngine.Environment.Realm();
|
MUDEngine.Environment.Realm newRealm = new MUDEngine.Environment.Realm();
|
||||||
//De-serialize the current realm.
|
//De-serialize the current realm.
|
||||||
newRealm = (MUDEngine.Environment.Realm)MUDEngine.XmlSerialization.Load(realm, newRealm);
|
newRealm = (MUDEngine.Environment.Realm)MUDEngine.FileSystem.FileSystem.Load(realm, newRealm);
|
||||||
//Add it to the available realms combo box.
|
//Add it to the available realms combo box.
|
||||||
comRealms.Items.Add(newRealm.Name);
|
comRealms.Items.Add(newRealm.Name);
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ namespace Project_Manager
|
||||||
{
|
{
|
||||||
MUDEngine.Environment.Zone newZone = new MUDEngine.Environment.Zone();
|
MUDEngine.Environment.Zone newZone = new MUDEngine.Environment.Zone();
|
||||||
//De-serialize the current zone.
|
//De-serialize the current zone.
|
||||||
newZone = (MUDEngine.Environment.Zone)MUDEngine.XmlSerialization.Load(zone, newZone);
|
newZone = (MUDEngine.Environment.Zone)MUDEngine.FileSystem.FileSystem.Load(zone, newZone);
|
||||||
//Add it to the available zones list box
|
//Add it to the available zones list box
|
||||||
lstZones.Items.Add(newZone.Name);
|
lstZones.Items.Add(newZone.Name);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue