Utility class for writing Encog persisted class files.
        /// <summary>
        /// Create the file.
        /// </summary>
        public void Create()
        {
            this.filePrimary.Delete();
            PersistWriter writer = new PersistWriter(this.filePrimary);

            writer.Begin();
            writer.WriteHeader();
            writer.BeginObjects();
            writer.EndObjects();
            writer.End();
            writer.Close();

            this.directory.Clear();
        }
        /// <summary>
        /// Update any header properties for an Encog object, for example,
        /// a rename.
        /// </summary>
        /// <param name="name">The name of the object to change. </param>
        /// <param name="newName">The new name of this object.</param>
        /// <param name="newDesc">The description for this object.</param>
        public void UpdateProperties(String name, String newName,
                                     String newDesc)
        {
            PersistWriter writer = new PersistWriter(this.fileTemp);

            writer.Begin();
            writer.WriteHeader();
            writer.BeginObjects();
            writer.ModifyObject(this.filePrimary, name, newName, newDesc);
            writer.EndObjects();
            writer.End();
            writer.Close();
            MergeTemp();
            BuildDirectory();
        }
        /// <summary>
        /// Delete the specified object.
        /// </summary>
        /// <param name="name">The object name.</param>
        public void Delete(String name)
        {
            PersistWriter writer = new PersistWriter(this.fileTemp);

            writer.Begin();
            writer.WriteHeader();
            writer.BeginObjects();
            writer.MergeObjects(this.filePrimary, name);
            writer.EndObjects();
            writer.End();
            writer.Close();
            MergeTemp();
            foreach (DirectoryEntry d in this.directory)
            {
                if (d.Name.Equals(name))
                {
                    this.directory.Remove(d);
                    break;
                }
            }
        }
        /// <summary>
        /// Add an EncogPersistedObject to the collection.
        /// </summary>
        /// <param name="name">The name of the object to load.</param>
        /// <param name="obj">The object to add.</param>
        public void Add(String name, IEncogPersistedObject obj)
        {
            if (obj is BasicNetwork)
            {
                ((BasicNetwork)obj).Structure.UpdateFlatNetwork();
            }

            obj.Name = name;
            PersistWriter writer = new PersistWriter(this.fileTemp);

            writer.Begin();
            writer.WriteHeader();
            writer.BeginObjects();
            writer.WriteObject(obj);
            writer.MergeObjects(this.filePrimary, name);
            writer.EndObjects();
            writer.End();
            writer.Close();
            MergeTemp();
            BuildDirectory();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Save the contents of this collection to a location.
        /// </summary>
        /// <param name="location">The location to save to.</param>
        public void Save(IPersistenceLocation location)
        {
            PersistWriter writer = null;

            writer = new PersistWriter(location);
            try
            {
                writer.Begin();
                writer.WriteHeader();
                writer.BeginObjects();
                foreach (IEncogPersistedObject obj in this.Contents.Values)
                {
                    writer.WriteObject(obj);
                }
                writer.EndObjects();
            }
            finally
            {
                writer.End();
                writer.Close();
            }
        }
        /// <summary>
        /// Update any header properties for an Encog object, for example,
        /// a rename.
        /// </summary>
        /// <param name="name">The name of the object to change. </param>
        /// <param name="newName">The new name of this object.</param>
        /// <param name="newDesc">The description for this object.</param>
        public void UpdateProperties(String name, String newName,
                 String newDesc)
        {
            PersistWriter writer = new PersistWriter(this.fileTemp);
            writer.Begin();
            writer.WriteHeader();
            writer.BeginObjects();
            writer.ModifyObject(this.filePrimary, name, newName, newDesc);
            writer.EndObjects();
            writer.End();
            writer.Close();
            MergeTemp();
            BuildDirectory();

        }
 /// <summary>
 /// Delete the specified object.
 /// </summary>
 /// <param name="name">The object name.</param>
 public void Delete(String name)
 {
     PersistWriter writer = new PersistWriter(this.fileTemp);
     writer.Begin();
     writer.WriteHeader();
     writer.BeginObjects();
     writer.MergeObjects(this.filePrimary, name);
     writer.EndObjects();
     writer.End();
     writer.Close();
     MergeTemp();
     foreach (DirectoryEntry d in this.directory )
     {
         if (d.Name.Equals(name))
         {
             this.directory.Remove(d);
             break;
         }
     }
 }
        /// <summary>
        /// Create the file.
        /// </summary>
        public void Create()
        {
            this.filePrimary.Delete();
            PersistWriter writer = new PersistWriter(this.filePrimary);
            writer.Begin();
            writer.WriteHeader();
            writer.BeginObjects();
            writer.EndObjects();
            writer.End();
            writer.Close();

            this.directory.Clear();
        }
        /// <summary>
        /// Add an EncogPersistedObject to the collection.
        /// </summary>
        /// <param name="name">The name of the object to load.</param>
        /// <param name="obj">The object to add.</param>
        public void Add(String name, IEncogPersistedObject obj)
        {
            if (obj is BasicNetwork)
            {
                ((BasicNetwork)obj).Structure.UpdateFlatNetwork();
            }

            obj.Name = name;
            PersistWriter writer = new PersistWriter(this.fileTemp);
            writer.Begin();
            writer.WriteHeader();
            writer.BeginObjects();
            writer.WriteObject(obj);
            writer.MergeObjects(this.filePrimary, name);
            writer.EndObjects();
            writer.End();
            writer.Close();
            MergeTemp();
            BuildDirectory();
        }
        /// <summary>
        /// Save the contents of this collection to a location.
        /// </summary>
        /// <param name="location">The location to save to.</param>
        public void Save(IPersistenceLocation location)
        {
            PersistWriter writer = null;

            writer = new PersistWriter(location);
            try
            {
                writer.Begin();
                writer.WriteHeader();
                writer.BeginObjects();
                foreach (IEncogPersistedObject obj in this.Contents.Values)
                {
                    writer.WriteObject(obj);
                }
                writer.EndObjects();
            }
            finally
            {
                writer.End();
                writer.Close();
            }
        }