예제 #1
0
        /// <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();
            }
        }
예제 #2
0
        /// <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);
            }
        }
예제 #3
0
        /// <summary>
        /// Save the object to XML.
        /// </summary>
        /// <param name="encogObject">The object to save.</param>
        /// <param name="xmlOut">The XML writer.</param>
        public void Save(IEncogPersistedObject encogObject, WriteXML xmlOut)
        {
            this.xmlOut = xmlOut;

            PersistorUtil.BeginEncogObject(encogObject.GetType().Name
                                           , xmlOut, encogObject, true);

            this.tagger.Analyze(encogObject);

            foreach (FieldInfo childField in ReflectionUtil
                     .GetAllFields(encogObject.GetType()))
            {
                if (ReflectionUtil.ShouldAccessField(childField, true))
                {
                    Object childValue = childField.GetValue(encogObject);
                    xmlOut.BeginTag(childField.Name);
                    SaveField(childValue);
                    xmlOut.EndTag();
                }
            }

            xmlOut.EndTag();
        }