public void TestSaveAndLoad() { Dictionary <string, string> PreSave = DOD.Parse(DOD3); DOD.Save(PreSave, "TestFile.DOD"); Dictionary <string, string> PostSave = DOD.Load("TestFile.DOD"); foreach (string Key in PreSave.Keys) { Assert.AreEqual(PreSave[Key], PostSave[Key]); } }
public void NullValues() { Dictionary <string, string> D = new Dictionary <string, string> { { "C", "C" }, { "D", null }, { "E", "E" } }; DOD.Save(D, "TestFile.DOD"); Dictionary <string, string> E = DOD.Load("TestFile.DOD"); Assert.AreEqual("C", E["C"]); Assert.IsTrue(string.IsNullOrEmpty(E["D"])); Assert.AreEqual("E", E["E"]); }
public static Clock LoadClock() { if (!File.Exists(dir)) { return(DefaultClock()); } Dictionary <String, String> LoadDict = DOD.Load(dir); try { Clock ReturnClock; if (string.IsNullOrWhiteSpace(FontDir)) { FontDir = LoadDict["FONT"]; } if (!string.IsNullOrWhiteSpace(FontDir)) { ReturnClock = new Clock(BasicFont.LoadFromFile(FontDir), 2, 1); } else { ReturnClock = new Clock(2, 1); } ReturnClock.BG = GraphicUtils.ColorCharToConsoleColor(LoadDict["BG"][0]); ReturnClock.FG = GraphicUtils.ColorCharToConsoleColor(LoadDict["FG"][0]); ReturnClock.MilitaryTime = Boolean.Parse(LoadDict["MILITTIME"]); ReturnClock.ShowDate = Boolean.Parse(LoadDict["SHOWDATE"]); ReturnClock.ShowSeconds = Boolean.Parse(LoadDict["SHOWSECONDS"]); ReturnClock.HourAdjust = int.Parse(LoadDict["ADJUSTHOURS"]); Audio = Boolean.Parse(LoadDict["AUDIO"]); Voice = Boolean.Parse(LoadDict["VOICE"]); Collapsed = Boolean.Parse(LoadDict["COLLAPSED"]); return(ReturnClock); } catch (Exception) { Draw.CenterText("There was an error loading file " + dir.Split('\\')[dir.Split('\\').Length - 1], Console.WindowHeight / 2, ConsoleColor.Red, ConsoleColor.Black); RenderUtils.Pause(); Draw.ClearLine(Console.WindowHeight / 2); return(DefaultClock()); } }
/// <summary>Loads a UserTrace from a directory.</summary> /// <param name="ProjectDir"></param> public Trace(string ProjectDir) { if (!Directory.Exists(ProjectDir) || !File.Exists(ProjectDir + "/" + "Project.UTrace") || !File.Exists(ProjectDir + "/" + "Users.DOD") || !Directory.Exists(ProjectDir + "/" + "Images") ) { throw new ArgumentException(ProjectDir + " does not contain a project"); } //Load the Project DOD Dictionary <string, string> ProjectDOD = DOD.Load(ProjectDir + "/" + "Project.UTrace"); //Load the Tile IMG and the Server Logo if (File.Exists(ProjectDir + "/TileBG.png")) { TileBackground = SafeLoadImage(ProjectDir + "/TileBG.png"); } if (File.Exists(ProjectDir + "/Logo.png")) { ServerLogo = SafeLoadImage(ProjectDir + "/Logo.png"); } //Load the server name and server start date ServerName = ProjectDOD["name"]; string[] DateTemp = ProjectDOD["date"].Split('-'); ServerCreationDate = new DateTime(int.Parse(DateTemp[0]), int.Parse(DateTemp[1]), int.Parse(DateTemp[2])); //Now load the users!!! Dictionary <string, string> UsersDOD = DOD.Load(ProjectDir + "/" + "Users.DOD"); //now we're going to load the root user RootUser = new User(UsersDOD[ProjectDOD["root"]], ProjectDir); //Now time to link the users LinkUsers(ref rootuser, ref UsersDOD, ProjectDir); //now let's add all the users AllUsers = rootuser.GetAllSubUsers(); //and that's it. }
//-[Internal Functions]------------------------------------------------------------------------------------------------ /// <summary>Loads a font from a filename</summary> /// <param name="Filename"></param> private void LoadFont(String Filename) { if (!File.Exists(Filename)) { MessageBox.Show("File Does not exist!", "BasicFont Editor", MessageBoxButtons.OK, MessageBoxIcon.Error); } FontBeingBuilt = DOD.Load(Filename); if (!FontBeingBuilt.ContainsKey("Name") | !FontBeingBuilt.ContainsKey("Author") | !FontBeingBuilt.ContainsKey("CharWidth") | !FontBeingBuilt.ContainsKey("CharHeight")) { MessageBox.Show("Provided font file is corrupt. It's missing certain details."); FontBeingBuilt = null; } NameBox.Text = FontBeingBuilt["Name"]; AuthorBox.Text = FontBeingBuilt["Author"]; this.Filename = Filename; LoadCharacters(""); MainTableLayout.Enabled = true; }
//-[Static methods]--------------------------------------------------------------------- /// <summary>Creates a BasicFont from a file</summary> /// <param name="Filename"></param> /// <returns></returns> public static BasicFont LoadFromFile(string Filename) { return(new BasicFont(DOD.Load(Filename))); }