/// <summary> /// Initializes a new instance of the /// <see cref="T:HospitalAllocation.Providers.Allocation.JsonFile.AllocationJsonFileStore"/> class. /// </summary> /// <param name="file">The file backing the JSON store</param> /// <param name="allocation">The initial allocation data for the file store</param> private AllocationJsonFileStore(FileInfo file, IcuAllocation allocation) { _jsonFile = file; _allocation = new AllocationMemoryStore(); AllocationProvider.SetPodAllocation(_allocation.PodA, allocation.PodA); AllocationProvider.SetPodAllocation(_allocation.PodB, allocation.PodB); AllocationProvider.SetPodAllocation(_allocation.PodC, allocation.PodC); AllocationProvider.SetPodAllocation(_allocation.PodD, allocation.PodD); AllocationProvider.SetSeniorTeamAllocation(_allocation.SeniorTeam, allocation.SeniorTeam); }
/// <summary> /// Create a JSON allocation store around a given file /// </summary> /// <returns>A new AllocationJsonFileStore using the given file as a persistence layer</returns> /// <param name="fileName">The path where the JSON file storing the allocation will be</param> public static AllocationJsonFileStore CreateFromFile(string fileName) { // If the file does not exist, we start with an empty allocation and don't read anything in if (!File.Exists(fileName)) { return(new AllocationJsonFileStore(new FileInfo(fileName), IcuAllocation.Empty)); } // Read in the file, create an allocation from it, and use that to initialise the JSON store object using (StreamReader file = File.OpenText(fileName)) { JsonSerializer serialiser = new JsonSerializer(); IcuAllocation allocation = (IcuAllocation)serialiser.Deserialize(file, typeof(IcuAllocation)); Console.Error.WriteLine("Got allocation: " + allocation); return(new AllocationJsonFileStore(new FileInfo(fileName), allocation)); } }