Esempio n. 1
0
        /// <summary>
        /// Create an object based on the specified location.
        /// </summary>
        /// <param name="location">The location to load/save from.</param>
        /// <param name="mode">The file mode.</param>
        public EncogPersistedCollection(IPersistenceLocation location, FileMode mode)
        {
            this.filePrimary = location;

            if (this.filePrimary is FilePersistence)
            {
                String file = ((FilePersistence)this.filePrimary).FileName;

                int index = file.LastIndexOf('.');
                if (index != -1)
                {
                    file = file.Substring(0, index);
                }
                file         += ".tmp";
                this.fileTemp = new FilePersistence(file);

                if (this.filePrimary.Exists())
                {
                    BuildDirectory();
                }
                else
                {
                    Create();
                }
            }
            else
            {
                this.fileTemp = null;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Modify the specified object, such as changing its name or
        /// description.
        /// </summary>
        /// <param name="location">The location of the object being modified.</param>
        /// <param name="name">The old name of the object being modified.</param>
        /// <param name="newName">The new name of the object being modified.</param>
        /// <param name="newDesc">The new description of the object being modified.</param>
        public void ModifyObject(IPersistenceLocation location,
                                 String name, String newName, String newDesc)
        {
            PersistReader reader = new PersistReader(location);

            reader.SaveModified(this.xmlOut, name, newName, newDesc);
            reader.Close();
        }
Esempio n. 3
0
        /// <summary>
        /// Merge the objects from this collection into the new one.
        /// Skip the specified object.
        /// </summary>
        /// <param name="location">The location to merge to.</param>
        /// <param name="skip">The object to skip.</param>
        public void MergeObjects(IPersistenceLocation location,
                                 String skip)
        {
            PersistReader reader = new PersistReader(location);

            reader.SaveTo(this.xmlOut, skip);
            reader.Close();
        }
        /// <summary>
        /// Rename this file to a different location.
        /// </summary>
        /// <param name="toLocation">What to rename to.</param>
        public void RenameTo(IPersistenceLocation toLocation)
        {
            String str =
                "Rename is not supported on this location type.";

#if logging
            if (this.logger.IsErrorEnabled)
            {
                this.logger.Error(str);
            }
#endif
            throw new PersistError(str);
        }
Esempio n. 5
0
        /// <summary>
        /// Rename is not supported for resource persistence.
        /// </summary>
        /// <param name="toLocation">Not used.</param>
        public void RenameTo(IPersistenceLocation toLocation)
        {
            String str =
                "The ResourcePersistence location does not suppor rename operations.";

#if logging
            if (this.logger.IsErrorEnabled)
            {
                this.logger.Error(str);
            }
#endif
            throw new PersistError(str);
        }
Esempio n. 6
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();
            }
        }
        /// <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>
        /// Create an object based on the specified location.
        /// </summary>
        /// <param name="location">The location to load/save from.</param>
        /// <param name="mode">The file mode.</param>
        public EncogPersistedCollection(IPersistenceLocation location, FileMode mode)
        {
            this.filePrimary = location;

            if (this.filePrimary is FilePersistence)
            {
                FilePersistence locationObj = (FilePersistence)this.filePrimary;

                if (locationObj.containsByteData)
                {
                    this.fileTemp = new FilePersistence();
                    ((FilePersistence)this.fileTemp).AddStreamData(locationObj.byteData);

                    if (this.filePrimary.Exists())
                    {
                        BuildDirectory();
                    }
                }
                else
                {
                    String file = locationObj.FileName;

                    int index = file.LastIndexOf('.');
                    if (index != -1)
                    {
                        file = file.Substring(0, index);
                    }
                    file         += ".tmp";
                    this.fileTemp = new FilePersistence(file);

                    if (this.filePrimary.Exists())
                    {
                        BuildDirectory();
                    }
                    else
                    {
                        Create();
                    }
                }
            }
            else
            {
                this.fileTemp = null;
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Rename this file to a different location.
        /// </summary>
        /// <param name="toLocation">What to rename to.</param>
        public void RenameTo(IPersistenceLocation toLocation)
        {
            if (!(toLocation is FilePersistence))
            {
                String str =
                    "Can only rename from one FilePersistence location to another";
#if logging
                if (this.logger.IsErrorEnabled)
                {
                    this.logger.Error(str);
                }
#endif
                throw new PersistError(str);
            }

            String toFile = ((FilePersistence)toLocation).FileName;

            File.Move(this.file, toFile);
        }
Esempio n. 10
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>
        /// Create an object based on the specified location.
        /// </summary>
        /// <param name="location">The location to load/save from.</param>
        /// <param name="mode">The file mode.</param>
        public EncogPersistedCollection(IPersistenceLocation location, FileMode mode)
        {
            this.filePrimary = location;

            if (this.filePrimary is FilePersistence)
            {
                String file = ((FilePersistence)this.filePrimary).FileName;

                int index = file.LastIndexOf('.');
                if (index != -1)
                {
                    file = file.Substring(0, index);
                }
                file += ".tmp";
                this.fileTemp = new FilePersistence(file);

                if (this.filePrimary.Exists())
                {
                    BuildDirectory();
                }
                else
                {
                    Create();
                }
            }
            else
            {
                this.fileTemp = null;
            }
        }
 /// <summary>
 /// Create a writer for the specified location.
 /// </summary>
 /// <param name="location">The location.</param>
 public PersistWriter(IPersistenceLocation location)
 {
     this.fileOutput = location.CreateStream(FileMode.OpenOrCreate);
     this.xmlOut = new WriteXML(this.fileOutput);
 }
        /// <summary>
        /// Modify the specified object, such as changing its name or
        /// description.
        /// </summary>
        /// <param name="location">The location of the object being modified.</param>
        /// <param name="name">The old name of the object being modified.</param>
        /// <param name="newName">The new name of the object being modified.</param>
        /// <param name="newDesc">The new description of the object being modified.</param>
        public void ModifyObject(IPersistenceLocation location,
                 String name, String newName, String newDesc)
        {

            PersistReader reader = new PersistReader(location);
            reader.SaveModified(this.xmlOut, name, newName, newDesc);
            reader.Close();

        }
 /// <summary>
 /// Merge the objects from this collection into the new one.
 /// Skip the specified object.
 /// </summary>
 /// <param name="location">The location to merge to.</param>
 /// <param name="skip">The object to skip.</param>
 public void MergeObjects(IPersistenceLocation location,
          String skip)
 {
     PersistReader reader = new PersistReader(location);
     reader.SaveTo(this.xmlOut, skip);
     reader.Close();
 }
        /// <summary>
        /// Rename this file to a different location.
        /// </summary>
        /// <param name="toLocation">What to rename to.</param>
        public void RenameTo(IPersistenceLocation toLocation)
        {
                String str =
                   "Rename is not supported on this location type.";
#if logging
                if (this.logger.IsErrorEnabled)
                {
                    this.logger.Error(str);
                }
#endif
                throw new PersistError(str);
 
        }
Esempio n. 16
0
        /// <summary>
        /// Rename this file to a different location.
        /// </summary>
        /// <param name="toLocation">What to rename to.</param>
        public void RenameTo(IPersistenceLocation toLocation)
        {
            if (!(toLocation is FilePersistence))
            {
                String str =
                   "Can only rename from one FilePersistence location to another";
#if logging
                if (this.logger.IsErrorEnabled)
                {
                    this.logger.Error(str);
                }
#endif
                throw new PersistError(str);
            }

            String toFile = ((FilePersistence)toLocation).FileName;

            File.Move(this.file, toFile);
        }
        /// <summary>
        /// Rename is not supported for resource persistence.
        /// </summary>
        /// <param name="toLocation">Not used.</param>
        public void RenameTo(IPersistenceLocation toLocation)
        {
            String str =
           "The ResourcePersistence location does not suppor rename operations.";
#if logging            
            if (this.logger.IsErrorEnabled)
            {
                this.logger.Error(str);
            }
#endif
            throw new PersistError(str);
        }
Esempio n. 18
0
 /// <summary>
 /// Create a writer for the specified location.
 /// </summary>
 /// <param name="location">The location.</param>
 public PersistWriter(IPersistenceLocation location)
 {
     this.fileOutput = location.CreateStream(FileMode.OpenOrCreate);
     this.xmlOut     = new WriteXML(this.fileOutput);
 }
Esempio n. 19
0
 /// <summary>
 /// Construct a persist reader.
 /// </summary>
 /// <param name="location">The location to use.</param>
 public PersistReader(IPersistenceLocation location)
 {
     this.fileInput = location.CreateStream(FileMode.Open);
     this.xmlIn     = new ReadXML(this.fileInput);
 }
Esempio n. 20
0
 /// <summary>
 /// Construct a persist reader.
 /// </summary>
 /// <param name="location">The location to use.</param>
 public PersistReader(IPersistenceLocation location)
 {
     this.fileInput = location.CreateStream(FileMode.Open);
     this.xmlIn = new ReadXML(this.fileInput);
 }
        /// <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();
            }
        }