diff --git a/src/ISADotNet.QueryModel/Row.fs b/src/ISADotNet.QueryModel/Row.fs index a0e870f3..ad6ad566 100644 --- a/src/ISADotNet.QueryModel/Row.fs +++ b/src/ISADotNet.QueryModel/Row.fs @@ -107,7 +107,7 @@ type QRow = (characteristics |> List.map Characteristic) @ (parameters |> List.map Parameter) @ (factors |> List.map Factor) - |> List.sortBy (fun v -> v.ValueIndex) + |> List.sortBy (fun v -> v.TryValueIndex |> Option.defaultValue System.Int32.MaxValue) { Input = Input |> Option.defaultValue "" diff --git a/src/ISADotNet.QueryModel/Value.fs b/src/ISADotNet.QueryModel/Value.fs index 3257ff3c..8328b20e 100644 --- a/src/ISADotNet.QueryModel/Value.fs +++ b/src/ISADotNet.QueryModel/Value.fs @@ -96,7 +96,16 @@ type ISAValue = | Factor f -> f.ValueWithUnitText member this.ValueIndex = + try + match this with + | Parameter p -> p.GetValueIndex() + | Characteristic c -> c.GetValueIndex() + | Factor f -> f.GetValueIndex() + with + | _ -> failwithf $"Value index could not be retrieved for value {this.NameText}" + + member this.TryValueIndex = match this with - | Parameter p -> p.GetValueIndex() - | Characteristic c -> c.GetValueIndex() - | Factor f -> f.GetValueIndex() \ No newline at end of file + | Parameter p -> p.TryGetValueIndex() + | Characteristic c -> c.TryGetValueIndex() + | Factor f -> f.TryGetValueIndex() \ No newline at end of file diff --git a/src/ISADotnet/ValueIndex.fs b/src/ISADotnet/ValueIndex.fs index 2dbed301..da16c48a 100644 --- a/src/ISADotnet/ValueIndex.fs +++ b/src/ISADotnet/ValueIndex.fs @@ -66,12 +66,20 @@ module ValueIndexExtensions = member this.GetValueIndex() = ValueIndex.tryGetFactorIndex this |> Option.get + static member tryGetValueIndex(f) = ValueIndex.tryGetFactorIndex f + + member this.TryGetValueIndex() = ValueIndex.tryGetFactorIndex this + type FactorValue with static member getValueIndex(f) = ValueIndex.tryGetFactorValueIndex f |> Option.get member this.GetValueIndex() = ValueIndex.tryGetFactorValueIndex this |> Option.get + static member tryGetValueIndex(f) = ValueIndex.tryGetFactorValueIndex f + + member this.TryGetValueIndex() = ValueIndex.tryGetFactorValueIndex this + type MaterialAttribute with /// Create a ISAJson characteristic from ISATab string entries @@ -86,12 +94,20 @@ module ValueIndexExtensions = member this.GetValueIndex() = ValueIndex.tryGetCharacteristicIndex this |> Option.get + static member tryGetValueIndex(m) = ValueIndex.tryGetCharacteristicIndex m + + member this.TryGetValueIndex() = ValueIndex.tryGetCharacteristicIndex this + type MaterialAttributeValue with static member getValueIndex(m) = ValueIndex.tryGetCharacteristicValueIndex m |> Option.get member this.GetValueIndex() = ValueIndex.tryGetCharacteristicValueIndex this |> Option.get + static member tryGetValueIndex(m) = ValueIndex.tryGetCharacteristicValueIndex m + + member this.TryGetValueIndex() = ValueIndex.tryGetCharacteristicValueIndex this + type ProtocolParameter with /// Create a ISAJson parameter from ISATab string entries @@ -106,8 +122,16 @@ module ValueIndexExtensions = member this.GetValueIndex() = ValueIndex.tryGetParameterIndex this |> Option.get + static member tryGetValueIndex(p) = ValueIndex.tryGetParameterIndex p + + member this.TryGetValueIndex() = ValueIndex.tryGetParameterIndex this + type ProcessParameterValue with static member getValueIndex(p) = ValueIndex.tryGetParameterValueIndex p |> Option.get member this.GetValueIndex() = ValueIndex.tryGetParameterValueIndex this |> Option.get + + static member tryGetValueIndex(p) = ValueIndex.tryGetParameterValueIndex p + + member this.TryGetValueIndex() = ValueIndex.tryGetParameterValueIndex this \ No newline at end of file