/// <summary>
        /// Loads all persisted Prison instances.
        /// <remarks>
        /// Prison objects are stored in the system folder, in a directory named 'windows-prison-db'.
        /// This is usually 'c:\windows\system32\windows-prison-db'.
        /// </remarks>
        /// </summary>
        /// <returns>An array of Prison objects.</returns>
        public static Prison[] ReadAllPrisonsNoAttach()
        {
            List <Prison> result = new List <Prison>();

            Logger.Debug("Loading prison database from {0}", databaseDirectory);

            Directory.CreateDirectory(databaseDirectory);

            string[] prisonFiles = Directory.GetFiles(databaseDirectory, "*.xml", SearchOption.TopDirectoryOnly);

            Logger.Debug("Found {0} prison entries", prisonFiles.Length);

            DataContractSerializer serializer = new DataContractSerializer(typeof(Prison));

            foreach (string prisonLocation in prisonFiles)
            {
                using (FileStream readStream = File.OpenRead(prisonLocation))
                {
                    Prison loadedPrison = (Prison)serializer.ReadObject(readStream);
                    result.Add(loadedPrison);
                }
            }

            return(result.ToArray());
        }
        private static string GetPrisonFileName(Prison prison)
        {
            if (prison == null)
            {
                throw new ArgumentNullException("prison");
            }

            return(GetPrisonFileName(prison.Id));
        }
        public static Prison LoadPrisonAndAttach(Guid prisonId)
        {
            Prison loadedPrison = LoadPrisonNoAttach(prisonId);

            if (loadedPrison != null)
            {
                loadedPrison.Reattach();
                return(loadedPrison);
            }
            else
            {
                return(null);
            }
        }
        public static void DeletePersistedPrison(Prison prison)
        {
            if (prison == null)
            {
                throw new ArgumentNullException("prison");
            }

            Logger.Debug("Deleting persisted prison {0}", prison.Id);

            Directory.CreateDirectory(databaseDirectory);

            string fileName = GetPrisonFileName(prison);

            File.Delete(fileName);
        }
        public static void Save(Prison prison)
        {
            if (prison == null)
            {
                throw new ArgumentNullException("prison");
            }

            Logger.Debug("Persisting prison {0}", prison.Id);

            Directory.CreateDirectory(databaseDirectory);

            string fileName = GetPrisonFileName(prison);

            DataContractSerializer serializer = new DataContractSerializer(typeof(Prison));

            using (FileStream writeStream = File.Open(fileName, FileMode.Create, FileAccess.Write))
            {
                serializer.WriteObject(writeStream, prison);
            }
        }
        public static void Save(Prison prison)
        {
            if (prison == null)
            {
                throw new ArgumentNullException("prison");
            }

            Logger.Debug("Persisting prison {0}", prison.Id);

            Directory.CreateDirectory(databaseDirectory);

            string fileName = GetPrisonFileName(prison);

            DataContractSerializer serializer = new DataContractSerializer(typeof(Prison));

            using (FileStream writeStream = File.Open(fileName, FileMode.Create, FileAccess.Write))
            {
                serializer.WriteObject(writeStream, prison);
            }
        }
        public static void DeletePersistedPrison(Prison prison)
        {
            if (prison == null)
            {
                throw new ArgumentNullException("prison");
            }

            Logger.Debug("Deleting persisted prison {0}", prison.Id);

            Directory.CreateDirectory(databaseDirectory);

            string fileName = GetPrisonFileName(prison);

            File.Delete(fileName);
        }
Example #8
0
 internal PrisonExecutor(Prison prison)
 {
     this.prison = prison;
 }
 internal PrisonExecutor(Prison prison)
 {
     this.prison = prison;
 }
Example #10
0
 public abstract void Recover(Prison prison);
Example #11
0
 public abstract void Destroy(Prison prison);
Example #12
0
 public abstract void Apply(Prison prison);
Example #13
0
 public abstract void Recover(Prison prison);
Example #14
0
 public abstract void Destroy(Prison prison);
Example #15
0
 public abstract void Apply(Prison prison);
        private static string GetPrisonFileName(Prison prison)
        {
            if (prison == null)
            {
                throw new ArgumentNullException("prison");
            }

            return GetPrisonFileName(prison.Id);
        }
 public PrisonGuard(Prison prison)
 {
     this.prison = prison;
 }
 public PrisonGuard(Prison prison)
 {
     this.prison = prison;
 }