diff --git a/src/ARCtrl/ARC.fs b/src/ARCtrl/ARC.fs index cf138fd1..f05bbc6c 100644 --- a/src/ARCtrl/ARC.fs +++ b/src/ARCtrl/ARC.fs @@ -89,15 +89,15 @@ type ARC(?isa : ArcInvestigation, ?cwl : unit, ?fs : FileSystem.FileSystem) = with get() = _fs and set(fs) = _fs <- fs - member this.WriteAsync(arcPath) = + member this.TryWriteAsync(arcPath) = this.GetWriteContracts() |> fullFillContractBatchAsync arcPath - member this.UpdateAsync(arcPath) = + member this.TryUpdateAsync(arcPath) = this.GetUpdateContracts() |> fullFillContractBatchAsync arcPath - static member loadAsync (arcPath : string) = + static member tryLoadAsync (arcPath : string) = crossAsync { let! paths = FileSystemHelper.getAllFilePathsAsync arcPath @@ -138,7 +138,7 @@ type ARC(?isa : ArcInvestigation, ?cwl : unit, ?fs : FileSystem.FileSystem) = s.ToUpdateContract() |] - member this.RemoveAssayAsync(arcPath : string, assayIdentifier: string) = + member this.TryRemoveAssayAsync(arcPath : string, assayIdentifier: string) = this.GetAssayRemoveContracts(assayIdentifier) |> fullFillContractBatchAsync arcPath @@ -160,7 +160,7 @@ type ARC(?isa : ArcInvestigation, ?cwl : unit, ?fs : FileSystem.FileSystem) = yield! this.GetUpdateContracts() |] - member this.RenameAssayAsync(arcPath : string, oldAssayIdentifier: string, newAssayIdentifier: string) = + member this.TryRenameAssayAsync(arcPath : string, oldAssayIdentifier: string, newAssayIdentifier: string) = this.GetAssayRenameContracts(oldAssayIdentifier,newAssayIdentifier) |> fullFillContractBatchAsync arcPath @@ -179,7 +179,7 @@ type ARC(?isa : ArcInvestigation, ?cwl : unit, ?fs : FileSystem.FileSystem) = isa.ToUpdateContract() |] - member this.RemoveStudyAsync(arcPath : string, studyIdentifier: string) = + member this.TryRemoveStudyAsync(arcPath : string, studyIdentifier: string) = this.GetStudyRemoveContracts(studyIdentifier) |> fullFillContractBatchAsync arcPath @@ -201,60 +201,103 @@ type ARC(?isa : ArcInvestigation, ?cwl : unit, ?fs : FileSystem.FileSystem) = yield! this.GetUpdateContracts() |] - member this.RenameStudyAsync(arcPath : string, oldStudyIdentifier: string, newStudyIdentifier: string) = + member this.TryRenameStudyAsync(arcPath : string, oldStudyIdentifier: string, newStudyIdentifier: string) = this.GetStudyRenameContracts(oldStudyIdentifier,newStudyIdentifier) |> fullFillContractBatchAsync arcPath + + member this.WriteAsync(arcPath) = + crossAsync { + let! result = this.TryWriteAsync(arcPath) + match result with + | Ok _ -> () + | Error errors -> + let appended = errors |> Array.map (fun e -> e.ToString()) |> String.concat "\n" + failwithf "Could not write ARC, failed with the following errors %s" appended + } + + member this.UpdateAsync(arcPath) = + crossAsync { + let! result = this.TryUpdateAsync(arcPath) + match result with + | Ok _ -> () + | Error errors -> + let appended = errors |> Array.map (fun e -> e.ToString()) |> String.concat "\n" + failwithf "Could not update ARC, failed with the following errors %s" appended + } + + member this.RemoveAssayAsync(arcPath, assayIdentifier) = + crossAsync { + let! result = this.TryRemoveAssayAsync(arcPath, assayIdentifier) + match result with + | Ok _ -> () + | Error errors -> + let appended = errors |> Array.map (fun e -> e.ToString()) |> String.concat "\n" + failwithf "Could not remove assay, failed with the following errors %s" appended + } + + member this.RenameAssayAsync(arcPath, oldAssayIdentifier, newAssayIdentifier) = + crossAsync { + let! result = this.TryRenameAssayAsync(arcPath, oldAssayIdentifier, newAssayIdentifier) + match result with + | Ok _ -> () + | Error errors -> + let appended = errors |> Array.map (fun e -> e.ToString()) |> String.concat "\n" + failwithf "Could not rename assay, failed with the following errors %s" appended + } + + member this.RemoveStudyAsync(arcPath, studyIdentifier) = + crossAsync { + let! result = this.TryRemoveStudyAsync(arcPath, studyIdentifier) + match result with + | Ok _ -> () + | Error errors -> + let appended = errors |> Array.map (fun e -> e.ToString()) |> String.concat "\n" + failwithf "Could not remove study, failed with the following errors %s" appended + } + + member this.RenameStudyAsync(arcPath, oldStudyIdentifier, newStudyIdentifier) = + crossAsync { + let! result = this.TryRenameStudyAsync(arcPath, oldStudyIdentifier, newStudyIdentifier) + match result with + | Ok _ -> () + | Error errors -> + let appended = errors |> Array.map (fun e -> e.ToString()) |> String.concat "\n" + failwithf "Could not rename study, failed with the following errors %s" appended + } + + static member loadAsync (arcPath) = + crossAsync { + let! result = ARC.tryLoadAsync arcPath + match result with + | Ok arc -> return arc + | Error errors -> + let appended = errors |> Array.map (fun e -> e.ToString()) |> String.concat "\n" + failwithf "Could not load ARC, failed with the following errors %s" appended + return (ARC()) + } #if FABLE_COMPILER_PYTHON || !FABLE_COMPILER member this.Write(arcPath) = - match Async.RunSynchronously (this.WriteAsync(arcPath)) with - | Ok _ -> () - | Error errors -> - let appended = errors |> Array.map (fun e -> e.ToString()) |> String.concat "\n" - failwithf "Could not write ARC, failed with the following errors %s" appended + Async.RunSynchronously (this.WriteAsync(arcPath)) member this.Update(arcPath) = - match Async.RunSynchronously (this.UpdateAsync(arcPath)) with - | Ok _ -> () - | Error errors -> - let appended = errors |> Array.map (fun e -> e.ToString()) |> String.concat "\n" - failwithf "Could not update ARC, failed with the following errors %s" appended + Async.RunSynchronously (this.UpdateAsync(arcPath)) member this.RemoveAssay(arcPath, assayIdentifier) = - match Async.RunSynchronously (this.RemoveAssayAsync(arcPath, assayIdentifier)) with - | Ok _ -> () - | Error errors -> - let appended = errors |> Array.map (fun e -> e.ToString()) |> String.concat "\n" - failwithf "Could not remove assay, failed with the following errors %s" appended + Async.RunSynchronously (this.RemoveAssayAsync(arcPath, assayIdentifier)) member this.RenameAssay(arcPath, oldAssayIdentifier, newAssayIdentifier) = - match Async.RunSynchronously (this.RenameAssayAsync(arcPath, oldAssayIdentifier, newAssayIdentifier)) with - | Ok _ -> () - | Error errors -> - let appended = errors |> Array.map (fun e -> e.ToString()) |> String.concat "\n" - failwithf "Could not rename assay, failed with the following errors %s" appended + Async.RunSynchronously (this.RenameAssayAsync(arcPath, oldAssayIdentifier, newAssayIdentifier)) member this.RemoveStudy(arcPath, studyIdentifier) = - match Async.RunSynchronously (this.RemoveStudyAsync(arcPath, studyIdentifier)) with - | Ok _ -> () - | Error errors -> - let appended = errors |> Array.map (fun e -> e.ToString()) |> String.concat "\n" - failwithf "Could not remove study, failed with the following errors %s" appended + Async.RunSynchronously (this.RemoveStudyAsync(arcPath, studyIdentifier)) member this.RenameStudy(arcPath, oldStudyIdentifier, newStudyIdentifier) = - match Async.RunSynchronously (this.RenameStudyAsync(arcPath, oldStudyIdentifier, newStudyIdentifier)) with - | Ok _ -> () - | Error errors -> - let appended = errors |> Array.map (fun e -> e.ToString()) |> String.concat "\n" - failwithf "Could not rename study, failed with the following errors %s" appended + Async.RunSynchronously (this.RenameStudyAsync(arcPath, oldStudyIdentifier, newStudyIdentifier)) static member load (arcPath) = - match Async.RunSynchronously (ARC.loadAsync arcPath) with - | Ok arc -> arc - | Error errors -> - let appended = errors |> Array.map (fun e -> e.ToString()) |> String.concat "\n" - failwithf "Could not load ARC, failed with the following errors %s" appended + Async.RunSynchronously (ARC.loadAsync arcPath) #endif diff --git a/tests/ARCtrl/ARCtrl.Tests.fs b/tests/ARCtrl/ARCtrl.Tests.fs index 5beb8e13..9beca1c5 100644 --- a/tests/ARCtrl/ARCtrl.Tests.fs +++ b/tests/ARCtrl/ARCtrl.Tests.fs @@ -949,7 +949,7 @@ let tests_load = testList "Load" [ testCaseCrossAsync "simpleARC" (crossAsync { let p = TestObjects.IO.testSimpleARC - let! result = ARC.loadAsync(p) + let! result = ARC.tryLoadAsync(p) let result = Expect.wantOk result "ARC should load successfully" Expect.isSome result.ISA "Should contain an ISA part" @@ -979,7 +979,7 @@ let tests_write = let p = ArcPathHelper.combine TestObjects.IO.testResultsFolder "ARC_Write_Empty" let a = ARC() - let! result = a.WriteAsync(p) + let! result = a.TryWriteAsync(p) Expect.wantOk result "ARC should write successfully" |> ignore @@ -1014,7 +1014,7 @@ let tests_write = arc.ISA <- Some i arc.UpdateFileSystem() - let! result = arc.WriteAsync(p) + let! result = arc.TryWriteAsync(p) Expect.wantOk result "ARC should write successfully" |> ignore let expectedPaths = @@ -1046,7 +1046,7 @@ let tests_write = testCaseCrossAsync "LoadSimpleARCAndAddAssay" (crossAsync { let p = ArcPathHelper.combine TestObjects.IO.testResultsFolder "ARC_Write_SimpleARCWithAssay" - let! readResult = ARC.loadAsync(TestObjects.IO.testSimpleARC) + let! readResult = ARC.tryLoadAsync(TestObjects.IO.testSimpleARC) let arc = Expect.wantOk readResult "ARC should load correctly" let i = arc.ISA.Value @@ -1060,7 +1060,7 @@ let tests_write = arc.UpdateFileSystem() - let! writeResult = arc.WriteAsync(p) + let! writeResult = arc.TryWriteAsync(p) Expect.wantOk writeResult "ARC should write successfully" |> ignore @@ -1131,7 +1131,7 @@ let tests_Update = arc.ISA <- Some i arc.UpdateFileSystem() - let! writeResult = arc.WriteAsync(p) + let! writeResult = arc.TryWriteAsync(p) Expect.wantOk writeResult "ARC should write successfully" |> ignore @@ -1141,7 +1141,7 @@ let tests_Update = arc.ISA <- Some i arc.UpdateFileSystem() - let! updateResult = arc.UpdateAsync(p) + let! updateResult = arc.TryUpdateAsync(p) Expect.wantOk updateResult "ARC should update successfully" |> ignore @@ -1194,14 +1194,14 @@ let tests_renameAssay = arc.ISA <- Some i arc.UpdateFileSystem() - let! updateResult = arc.WriteAsync(p) + let! updateResult = arc.TryWriteAsync(p) Expect.wantOk updateResult "ARC should write successfully" |> ignore // rename assay let newAssayName = "MyNewAssay" - let! renameResult = arc.RenameAssayAsync(p,assayName, newAssayName) + let! renameResult = arc.TryRenameAssayAsync(p,assayName, newAssayName) Expect.wantOk renameResult "Assay should be renamed successfully" |> ignore let expectedPaths = @@ -1247,14 +1247,14 @@ let tests_RenameStudy = arc.ISA <- Some i arc.UpdateFileSystem() - let! writeResult = arc.WriteAsync(p) + let! writeResult = arc.TryWriteAsync(p) Expect.wantOk writeResult "ARC should write successfully" |> ignore // rename study let newStudyName = "MyNewStudy" - let! renameResult = arc.RenameStudyAsync(p,studyName, newStudyName) + let! renameResult = arc.TryRenameStudyAsync(p,studyName, newStudyName) Expect.wantOk renameResult "Study should be renamed successfully" |> ignore let expectedPaths = @@ -1301,13 +1301,13 @@ let tests_RemoveAssay = arc.ISA <- Some i arc.UpdateFileSystem() - let! writeResult = arc.WriteAsync(p) + let! writeResult = arc.TryWriteAsync(p) Expect.wantOk writeResult "ARC should write successfully" |> ignore // remove assay - let! removeResult = arc.RemoveAssayAsync(p,assayName) + let! removeResult = arc.TryRemoveAssayAsync(p,assayName) Expect.wantOk removeResult "Assay should be removed successfully" |> ignore let expectedPaths = @@ -1349,13 +1349,13 @@ let tests_RemoveStudy = arc.ISA <- Some i arc.UpdateFileSystem() - let! writeResult = arc.WriteAsync(p) + let! writeResult = arc.TryWriteAsync(p) Expect.wantOk writeResult "ARC should write successfully" |> ignore // remove study - let! removeResult = arc.RemoveStudyAsync(p,studyName) + let! removeResult = arc.TryRemoveStudyAsync(p,studyName) Expect.wantOk removeResult "Study should be removed successfully" |> ignore let expectedPaths =