/// <summary> /// Initializes the Historical data package /// </summary> /// <param name="filePath">The path to the file to load</param> /// <param name="factory">THe factory used to create instances of the loaded file</param> public static History Load(string filePath, Generated.Factory factory) { History retVal = null; acceptor.setFactory(factory); if (File.Exists(filePath)) { // Do not rely on XmlBFileContext since it does not care about encoding. // File encoding is UTF-8 XmlBStringContext ctxt; using (StreamReader file = new StreamReader(filePath)) { ctxt = new XmlBStringContext(file.ReadToEnd()); file.Close(); } try { retVal = acceptor.accept(ctxt) as History; } catch (XmlBException) { Console.WriteLine(ctxt.errorMessage()); } } return(retVal); }
/// <summary> /// Loads a file and locks it if required /// </summary> /// <param name="filePath"></param> /// <param name="enclosing"></param> /// <param name="lockFiles"></param> /// <returns></returns> public static T LoadFile <T>(string filePath, ModelElement enclosing, bool lockFiles) where T : class, IXmlBBase { T retVal = null; // Do not rely on XmlBFileContext since it does not care about encoding. // File encoding is UTF-8 XmlBStringContext ctxt; using (StreamReader file = new StreamReader(filePath)) { ctxt = new XmlBStringContext(file.ReadToEnd()); file.Close(); } DontNotify(() => { try { retVal = acceptor.accept(ctxt) as T; if (retVal != null) { retVal.setFather(enclosing); if (lockFiles) { LockFile(filePath); } } } catch (XmlBException) { Console.WriteLine(ctxt.errorMessage()); } }); return(retVal); }