/// <summary> /// Load the contents of a location. /// </summary> /// <param name="location">The location to load from.</param> public void Load(IPersistenceLocation location) { PersistReader reader = null; this.location = location; try { reader = new PersistReader(location); IDictionary <String, String> header = reader.ReadHeader(); if (header != null) { this.FileVersion = int.Parse(header["fileVersion"]); this.EncogVersion = header["encogVersion"]; this.Platform = header["platform"]; } reader.AdvanceObjectsCollection(); ReadXML xmlIn = reader.XMLInput; this.Contents.Clear(); while (xmlIn.ReadToTag()) { if (xmlIn.IsIt(PersistReader.TAG_OBJECTS, false)) { break; } String type = xmlIn.LastTag.Name; String name = xmlIn.LastTag.Attributes["name"]; IPersistor persistor = PersistorUtil .CreatePersistor(type); if (persistor == null) { throw new PersistError("Do not know how to load: " + type); } IEncogPersistedObject obj = persistor.Load(xmlIn); this.Contents[name] = obj; } } finally { if (reader != null) { reader.Close(); } BuildDirectory(); } }
/// <summary> /// Read the specific object, search through the objects until its found. /// </summary> /// <param name="name">The name of the object you are looking for.</param> /// <returns>The object found, null if not found.</returns> public IEncogPersistedObject ReadObject(String name) { // did we find the object? if (Advance(name)) { String objectType = this.xmlIn.LastTag.Name; IPersistor persistor = PersistorUtil .CreatePersistor(objectType); if (persistor == null) { throw new PersistError( "Do not know how to load: " + objectType); } return(persistor.Load(this.xmlIn)); } else { return(null); } }