-let load (filePath: string) : DocumentData =
- use file = ZipFile.Open(filePath, ZipArchiveMode.Read)
-
- let mainEntry = file.GetEntry(mainEntryName)
- use mainEntryReader = new StreamReader(mainEntry.Open())
- let info = JsonConvert.DeserializeObject<JSONInformation>(mainEntryReader.ReadToEnd())
-
- updateDocumentData info.fileVersion currentFileVersion
- { patientID = info.patientID
- images = [ let mutable imgNum = 0
- for imgEntry in file.Entries do
- if imgEntry.Name.EndsWith(imageExtension)
- then
- use bitmap = new System.Drawing.Bitmap(imgEntry.Open(), false)
- let img = new Image<Bgr, byte>(bitmap)
- imgNum <- imgNum + 1
- let imgEntry = file.GetEntry(imgEntry.Name + ".json")
- use imgEntryFileReader = new StreamReader(imgEntry.Open())
- let imgInfo = JsonConvert.DeserializeObject<JSONSourceImage>(imgEntryFileReader.ReadToEnd())
- let config = ParasitemiaCore.Config.Config(imgInfo.parameters)
+/// <exception cref="VersionFileNewerException">If the file version is newer than the current supported version</exception>
+let load (filePath : string) (defaultConfig : ParasitemiaCore.Config.Config) : DocumentData =
+ use file = ZipFile.Open (filePath, ZipArchiveMode.Read)
+
+ let mainEntry = file.GetEntry (MAIN_ENTRY_NAME)
+ use mainEntryReader = new StreamReader (mainEntry.Open ())
+ let info = JsonConvert.DeserializeObject<JSONInformation> (mainEntryReader.ReadToEnd ())
+
+ if info.fileVersion > CURRENT_FILE_VERSION then
+ raise <| VersionFileNewerException info.fileVersion
+
+ updateDocumentData info.fileVersion CURRENT_FILE_VERSION
+ {
+ patientID = info.patientID
+ images =
+ [
+ for imgEntry in file.Entries do
+ if imgEntry.Name.EndsWith JSON_EXTENSION |> not then
+ use bitmap = new System.Drawing.Bitmap (imgEntry.Open (), false)
+ let img = bitmap.ToImage<Bgr, byte> ()
+ let imgJSONEntry = file.GetEntry (imgEntry.Name + JSON_EXTENSION)
+ use imgJSONFileReader = new StreamReader (imgJSONEntry.Open ())
+ let imgInfo = JsonConvert.DeserializeObject<JSONSourceImage> (imgJSONFileReader.ReadToEnd ())
+ let imgNum = imgInfo.num
+
+ let config = defaultConfig.Copy ()
+ config.Parameters <-
+ {
+ ParasitemiaCore.Config.defaultParameters with
+ resolution = imgInfo.parameters.resolution
+ }
+