From b58b4932e93abf83013b3cfdc9bdf23b263299c2 Mon Sep 17 00:00:00 2001 From: jaroslavbliznak Date: Wed, 13 Dec 2023 07:05:16 +0100 Subject: [PATCH 1/2] FIX-2045 BE-fix conditions, empty strings and using constants --- Src/Witsml/CommonConstants.cs | 30 +++++++++ Src/Witsml/Data/Curves/DateTimeIndex.cs | 11 ++-- Src/Witsml/Data/Curves/DepthIndex.cs | 10 +-- Src/Witsml/Data/Curves/DepthUnit.cs | 8 +-- Src/Witsml/Data/Curves/Index.cs | 4 +- Src/Witsml/Data/Curves/Point.cs | 7 +- Src/Witsml/Data/Curves/Row.cs | 2 +- Src/Witsml/Data/Curves/TimeSpanIndex.cs | 4 +- Src/Witsml/Data/Curves/Unit.cs | 3 +- Src/Witsml/Data/Measures/Measure.cs | 4 +- .../Data/Measures/WitsmlMeasureWithDatum.cs | 6 +- Src/Witsml/Data/Tubular/WitsmlHoleOpener.cs | 3 +- Src/Witsml/Data/Tubular/WitsmlMotor.cs | 12 ++-- Src/Witsml/Data/Tubular/WitsmlNozzle.cs | 3 +- .../Data/Tubular/WitsmlRotarySteerableTool.cs | 4 +- Src/Witsml/Data/Tubular/WitsmlStabilizer.cs | 2 +- Src/Witsml/Data/Tubular/WitsmlTubular.cs | 5 +- .../Data/Tubular/WitsmlTubularComponent.cs | 5 +- Src/Witsml/Data/WitsmlBitRecord.cs | 9 +-- Src/Witsml/Data/WitsmlCustomData.cs | 2 +- Src/Witsml/Data/WitsmlData.cs | 2 +- Src/Witsml/Data/WitsmlExtensionValue.cs | 4 +- Src/Witsml/Data/WitsmlIndex.cs | 4 +- Src/Witsml/Data/WitsmlLocation.cs | 3 +- Src/Witsml/Data/WitsmlTrajectory.cs | 3 +- Src/Witsml/Data/WitsmlTrajectoryStation.cs | 19 +++--- Src/Witsml/Extensions/DateTimeExtensions.cs | 2 +- Src/Witsml/Extensions/WitsmlLogExtensions.cs | 4 +- Src/Witsml/WitsmlClient.cs | 10 +-- Src/Witsml/WitsmlClientOptions.cs | 2 +- Src/Witsml/Xml/Serializer.cs | 2 +- .../Extensions/BuilderExtensions.cs | 4 +- Src/WitsmlExplorer.Api/Query/LogQueries.cs | 3 +- Src/WitsmlExplorer.Api/Query/QueryHelper.cs | 8 ++- .../Services/LogDataReader.cs | 2 +- .../Services/LogObjectService.cs | 9 +-- .../Services/WitsmlClientProvider.cs | 4 +- .../Workers/CheckLogHeaderWorker.cs | 19 +++--- .../Workers/CompareLogDataWorker.cs | 4 +- .../Workers/Copy/CopyLogDataWorker.cs | 10 +-- .../Workers/ImportLogDataWorker.cs | 8 +-- .../Workers/SpliceLogsWorker.cs | 20 +++--- .../Services/ObjectServiceTests.cs | 4 +- .../Workers/AnalyzeGapWorkerTests.cs | 16 ++--- .../Workers/CheckLogHeaderWorkerTests.cs | 2 +- .../Workers/CompareLogDataWorker.Tests.cs | 64 +++++++++---------- .../Workers/CopyLogDataWorkerTests.cs | 14 ++-- .../Workers/CopyLogWorkerTests.cs | 2 +- .../Workers/CountLogDataRowWorkerTest.cs | 4 +- .../Workers/CreateLogWorkerTests.cs | 6 +- .../Workers/CreateRigWorkerTests.cs | 4 +- .../Workers/CreateTrajectoryWorkerTests.cs | 2 +- .../Workers/CreateWellWorkerTests.cs | 6 +- .../Workers/CreateWellboreWorkerTests.cs | 8 +-- .../Workers/ImportLogDataWorkerTests.cs | 14 ++-- .../Workers/LogUtils.cs | 20 +++--- .../Workers/LogWorkerToolsTests.cs | 9 +-- .../Workers/MissingDataWorkerTests.cs | 2 +- .../ModifyFormationMarkerWorkerTests.cs | 2 +- .../Workers/ModifyLogCurveInfoWorkerTests.cs | 14 ++-- .../Workers/ModifyLogObjectWorkerTests.cs | 2 +- .../Workers/ModifyTrajectoryWorkerTests.cs | 2 +- .../ModifyTubularComponentWorkerTests.cs | 6 +- .../Workers/ModifyTubularWorkerTests.cs | 2 +- .../Workers/ModifyWellWorkerTests.cs | 2 +- .../Workers/ModifyWellboreWorkerTests.cs | 36 +++++------ .../Workers/SpliceLogsWorkerTests.cs | 64 +++++++++---------- .../Api/Workers/CopyLogWorkerTests.cs | 4 +- 68 files changed, 315 insertions(+), 276 deletions(-) diff --git a/Src/Witsml/CommonConstants.cs b/Src/Witsml/CommonConstants.cs index 7613e5ff7..7eb93c2ea 100644 --- a/Src/Witsml/CommonConstants.cs +++ b/Src/Witsml/CommonConstants.cs @@ -7,5 +7,35 @@ public static class CommonConstants { public const int DefaultNumberOfRoundedPlaces = 3; public const string DataSeparator = ","; + public const string PropertySeparator = "."; public const string NewLine = "\n"; + public const int DefaultClientRequestTimeOut = 90; + public const int DefaultReloadInterval = 15; + + public static class DepthIndex + { + public const string DefaultUnit = Unit.Meter; + public const double NullValue = -999.25; + public const double OffsetEpsilon = 1e-3; + public const double Epsilon = 1e-5; + } + + public static class DateTimeIndex + { + public const string IsoPattern = "yyyy-MM-ddTHH:mm:ss.fffZ"; + public const string NullValue = "1900-01-01T00:00:00.000Z"; + } + + public static class TimeSpanIndex + { + public const string Pattern = @"hh\:mm\:ss"; + } + + public static class Unit + { + public const string Unitless = "unitless"; + public const string Meter = "m"; + public const string Feet = "ft"; + public const string Second = "s"; + } } diff --git a/Src/Witsml/Data/Curves/DateTimeIndex.cs b/Src/Witsml/Data/Curves/DateTimeIndex.cs index e760e0c7b..2a58d1b8d 100644 --- a/Src/Witsml/Data/Curves/DateTimeIndex.cs +++ b/Src/Witsml/Data/Curves/DateTimeIndex.cs @@ -5,10 +5,7 @@ namespace Witsml.Data.Curves { public class DateTimeIndex : Index { - public DateTime Value { get; } - public const string IsoPattern = "yyyy-MM-ddTHH:mm:ss.fffZ"; - public const string NullValue = "1900-01-01T00:00:00.000Z"; public DateTimeIndex(DateTime dateTime) { @@ -17,14 +14,14 @@ public DateTimeIndex(DateTime dateTime) public static DateTimeIndex FromString(string dateString) { - return DateTime.TryParseExact(dateString, IsoPattern, null, DateTimeStyles.None, out DateTime parsedDateTime) + return DateTime.TryParseExact(dateString, CommonConstants.DateTimeIndex.IsoPattern, null, DateTimeStyles.None, out DateTime parsedDateTime) ? new DateTimeIndex(parsedDateTime) : throw new Exception($"Date format not recognized: {dateString}"); } public static bool TryParseISODate(string dateString, out DateTimeIndex dateTimeIndex) { - if (DateTime.TryParseExact(dateString, IsoPattern, null, DateTimeStyles.None, out DateTime tmpDateTime)) + if (DateTime.TryParseExact(dateString, CommonConstants.DateTimeIndex.IsoPattern, null, DateTimeStyles.None, out DateTime tmpDateTime)) { dateTimeIndex = new DateTimeIndex(tmpDateTime); return true; @@ -48,7 +45,7 @@ public override int CompareTo(Index that) public override string GetValueAsString() { - return Value.ToUniversalTime().ToString(IsoPattern, CultureInfo.InvariantCulture); + return Value.ToUniversalTime().ToString(CommonConstants.DateTimeIndex.IsoPattern, CultureInfo.InvariantCulture); } public override bool IsContinuous(Index that) @@ -65,7 +62,7 @@ public override bool IsNegative() public override bool IsNullValue() { - return Value.Date.Equals(DateTime.Parse(NullValue)); + return Value.Date.Equals(DateTime.Parse(CommonConstants.DateTimeIndex.NullValue)); } public override string ToString() diff --git a/Src/Witsml/Data/Curves/DepthIndex.cs b/Src/Witsml/Data/Curves/DepthIndex.cs index dbbcd0f84..d501a6e07 100644 --- a/Src/Witsml/Data/Curves/DepthIndex.cs +++ b/Src/Witsml/Data/Curves/DepthIndex.cs @@ -6,10 +6,6 @@ namespace Witsml.Data.Curves { public class DepthIndex : Index { - private const double OffsetEpsilon = 1e-3; - private const double Epsilon = 1e-5; - public const double NullValue = -999.25; - public double Value { get; } public DepthUnit Uom { get; } @@ -40,7 +36,7 @@ public DepthIndex(int value) private bool HasSameUnitAs(DepthIndex that) => Uom.Equals(that.Uom); [Obsolete("AddEpsilon is deprecated due to assuming 3 decimals of precision for depth indexes. Some WITSML servers do not use 3 decimals.")] - public override Index AddEpsilon() => new DepthIndex(Value + OffsetEpsilon, Uom); + public override Index AddEpsilon() => new DepthIndex(Value + CommonConstants.DepthIndex.OffsetEpsilon, Uom); private Index Subtract(Index that) { @@ -55,7 +51,7 @@ public override int CompareTo(Index that) { throw new ArgumentException("Cannot compare depths with different unit types"); } - var isEqual = Math.Abs(Value - thatDepthIndex.Value) < Epsilon; + var isEqual = Math.Abs(Value - thatDepthIndex.Value) < CommonConstants.DepthIndex.Epsilon; return isEqual ? 0 : Value.CompareTo(thatDepthIndex.Value); } @@ -82,7 +78,7 @@ public override bool IsContinuous(Index that) public override bool IsNegative() => Value <= 0.0; public override bool IsNullValue() { - return Math.Abs(Value - NullValue) < 0; + return Math.Abs(Value - CommonConstants.DepthIndex.NullValue) < 0; } diff --git a/Src/Witsml/Data/Curves/DepthUnit.cs b/Src/Witsml/Data/Curves/DepthUnit.cs index 26be518af..05569716a 100644 --- a/Src/Witsml/Data/Curves/DepthUnit.cs +++ b/Src/Witsml/Data/Curves/DepthUnit.cs @@ -4,16 +4,16 @@ namespace Witsml.Data.Curves { public class DepthUnit : Unit { - public static readonly DepthUnit Meter = new("m"); - public static readonly DepthUnit Feet = new("ft"); + public static readonly DepthUnit Meter = new(CommonConstants.Unit.Meter); + public static readonly DepthUnit Feet = new(CommonConstants.Unit.Feet); public DepthUnit(string unitCode) : base(unitCode) { } public static DepthUnit FromString(string unitCode) { - return "m".Equals(unitCode, StringComparison.InvariantCulture) + return CommonConstants.Unit.Meter.Equals(unitCode, StringComparison.InvariantCulture) ? Meter - : ("ft".Equals(unitCode, StringComparison.InvariantCulture) + : (CommonConstants.Unit.Feet.Equals(unitCode, StringComparison.InvariantCulture) ? Feet : throw new ArgumentException($"Unit \"{unitCode}\" is not supported!")); } diff --git a/Src/Witsml/Data/Curves/Index.cs b/Src/Witsml/Data/Curves/Index.cs index 8c21efe7c..6717d5758 100644 --- a/Src/Witsml/Data/Curves/Index.cs +++ b/Src/Witsml/Data/Curves/Index.cs @@ -59,7 +59,7 @@ public static Index Start(WitsmlLog log, string customIndexValue = "") : new DepthIndex( double.Parse(customIndexValue.IsNumeric() ? customIndexValue : log.StartIndex.Value, CultureInfo.InvariantCulture), - log.StartIndex?.Uom ?? "m"), + log.StartIndex?.Uom ?? CommonConstants.DepthIndex.DefaultUnit), WitsmlLog.WITSML_INDEX_TYPE_DATE_TIME => log.StartDateTimeIndex == null && string.IsNullOrEmpty(customIndexValue) ? null : new DateTimeIndex(DateTime.Parse(customIndexValue.NullIfEmpty() ?? log.StartDateTimeIndex, @@ -77,7 +77,7 @@ public static Index End(WitsmlLog log, string customIndexValue = "") : new DepthIndex( double.Parse(customIndexValue.IsNumeric() ? customIndexValue : log.EndIndex.Value, CultureInfo.InvariantCulture), - log.EndIndex?.Uom ?? "m"), + log.EndIndex?.Uom ?? CommonConstants.DepthIndex.DefaultUnit), WitsmlLog.WITSML_INDEX_TYPE_DATE_TIME => log.EndDateTimeIndex == null && string.IsNullOrEmpty(customIndexValue) ? null : new DateTimeIndex(DateTime.Parse(customIndexValue.NullIfEmpty() ?? log.EndDateTimeIndex, diff --git a/Src/Witsml/Data/Curves/Point.cs b/Src/Witsml/Data/Curves/Point.cs index f7d6444dc..7a4af9f6f 100644 --- a/Src/Witsml/Data/Curves/Point.cs +++ b/Src/Witsml/Data/Curves/Point.cs @@ -11,7 +11,7 @@ public class Point public Point(string commaSeparated) { - string[] values = commaSeparated.Split(","); + string[] values = commaSeparated.Split(CommonConstants.DataSeparator); Index = DateTimeIndex.TryParseISODate(values.First(), out DateTimeIndex witsmlDateTime) ? witsmlDateTime : new DepthIndex(double.Parse(values.First(), CultureInfo.InvariantCulture)); @@ -26,7 +26,10 @@ public string GetValueAsString() public int GetValueAsInt() { - return Value is DoubleValue value ? (int)value.Get() : throw new InvalidCastException("Unable to cast String values to integers"); + return Value is DoubleValue value + ? (int)value.Get() + : throw new InvalidCastException( + "Unable to cast String values to integers"); } public double GetValueAsDouble() diff --git a/Src/Witsml/Data/Curves/Row.cs b/Src/Witsml/Data/Curves/Row.cs index d287afa0c..f21b18efe 100644 --- a/Src/Witsml/Data/Curves/Row.cs +++ b/Src/Witsml/Data/Curves/Row.cs @@ -11,7 +11,7 @@ public class Row public Row(string commaSeparated) { - string[] row = commaSeparated.Split(","); + string[] row = commaSeparated.Split(CommonConstants.DataSeparator); Index = DateTimeIndex.TryParseISODate(row.First(), out DateTimeIndex witsmlDateTime) ? witsmlDateTime : new DepthIndex(double.Parse(row.First(), CultureInfo.InvariantCulture)); diff --git a/Src/Witsml/Data/Curves/TimeSpanIndex.cs b/Src/Witsml/Data/Curves/TimeSpanIndex.cs index 8c6e9556a..1578ef154 100644 --- a/Src/Witsml/Data/Curves/TimeSpanIndex.cs +++ b/Src/Witsml/Data/Curves/TimeSpanIndex.cs @@ -8,8 +8,6 @@ namespace Witsml.Data.Curves; /// public class TimeSpanIndex : Index { - private const string TimeSpanPattern = @"hh\:mm\:ss"; - public TimeSpan Value { get; } public TimeSpanIndex(TimeSpan value) @@ -36,7 +34,7 @@ public override int CompareTo(Index that) public override string GetValueAsString() { - return Value.ToString(TimeSpanPattern, CultureInfo.InvariantCulture); + return Value.ToString(CommonConstants.TimeSpanIndex.Pattern, CultureInfo.InvariantCulture); } public override bool IsContinuous(Index that) diff --git a/Src/Witsml/Data/Curves/Unit.cs b/Src/Witsml/Data/Curves/Unit.cs index e15f59be0..c3418df3e 100644 --- a/Src/Witsml/Data/Curves/Unit.cs +++ b/Src/Witsml/Data/Curves/Unit.cs @@ -4,8 +4,7 @@ public class Unit { private readonly string _unitCode; - public static readonly Unit NoUnit = new(""); - public static readonly Unit TimeUnit = new("s"); + public static readonly Unit TimeUnit = new(CommonConstants.Unit.Second); public Unit(string unitCode) { diff --git a/Src/Witsml/Data/Measures/Measure.cs b/Src/Witsml/Data/Measures/Measure.cs index 134b2b204..6903abc66 100644 --- a/Src/Witsml/Data/Measures/Measure.cs +++ b/Src/Witsml/Data/Measures/Measure.cs @@ -11,8 +11,8 @@ public class Measure { return new() { - Uom = "", - Value = "" + Uom = string.Empty, + Value = string.Empty }; } } diff --git a/Src/Witsml/Data/Measures/WitsmlMeasureWithDatum.cs b/Src/Witsml/Data/Measures/WitsmlMeasureWithDatum.cs index 9bcc20c16..d06e48da8 100644 --- a/Src/Witsml/Data/Measures/WitsmlMeasureWithDatum.cs +++ b/Src/Witsml/Data/Measures/WitsmlMeasureWithDatum.cs @@ -10,9 +10,9 @@ public static WitsmlMeasureWithDatum ToFetch() { return new() { - Uom = "", - Value = "", - Datum = "" + Uom = string.Empty, + Value = string.Empty, + Datum = string.Empty }; } } diff --git a/Src/Witsml/Data/Tubular/WitsmlHoleOpener.cs b/Src/Witsml/Data/Tubular/WitsmlHoleOpener.cs index 1c6744242..57ba255ab 100644 --- a/Src/Witsml/Data/Tubular/WitsmlHoleOpener.cs +++ b/Src/Witsml/Data/Tubular/WitsmlHoleOpener.cs @@ -1,3 +1,4 @@ +using System.Globalization; using System.Xml; using System.Xml.Serialization; @@ -15,7 +16,7 @@ public class WitsmlHoleOpener [XmlElement("numCutter")] public string NumCutterText { - get => NumCutter.HasValue ? XmlConvert.ToString(NumCutter.Value) : null; + get => NumCutter?.ToString(CultureInfo.InvariantCulture); set => NumCutter = string.IsNullOrEmpty(value) ? default(int?) : int.Parse(value); } diff --git a/Src/Witsml/Data/Tubular/WitsmlMotor.cs b/Src/Witsml/Data/Tubular/WitsmlMotor.cs index 2b9d971e2..b12479cf1 100644 --- a/Src/Witsml/Data/Tubular/WitsmlMotor.cs +++ b/Src/Witsml/Data/Tubular/WitsmlMotor.cs @@ -16,7 +16,7 @@ public class WitsmlMotor [XmlElement("presLossFact")] public string PresLossFactText { - get => PresLossFact.HasValue ? XmlConvert.ToString(PresLossFact.Value) : null; + get => PresLossFact?.ToString(CultureInfo.InvariantCulture); set => PresLossFact = string.IsNullOrEmpty(value) ? default(double?) : double.Parse(value, CultureInfo.InvariantCulture); } @@ -37,7 +37,7 @@ public string PresLossFactText [XmlElement("lobesRotor")] public string LobesRotorText { - get => LobesRotor.HasValue ? XmlConvert.ToString(LobesRotor.Value) : null; + get => LobesRotor?.ToString(CultureInfo.InvariantCulture); set => LobesRotor = string.IsNullOrEmpty(value) ? default(int?) : int.Parse(value); } @@ -46,7 +46,7 @@ public string LobesRotorText [XmlElement("lobesStator")] public string LobesStatorText { - get => LobesStator.HasValue ? XmlConvert.ToString(LobesStator.Value) : null; + get => LobesStator?.ToString(CultureInfo.InvariantCulture); set => LobesStator = string.IsNullOrEmpty(value) ? default(int?) : int.Parse(value); } @@ -61,7 +61,7 @@ public string LobesStatorText [XmlElement("rotorCatcher")] public string RotorCatcherText { - get => RotorCatcher.HasValue ? XmlConvert.ToString(RotorCatcher.Value) : null; + get => RotorCatcher?.ToString(CultureInfo.InvariantCulture); set => RotorCatcher = string.IsNullOrEmpty(value) ? default(bool?) : bool.Parse(value); } @@ -70,7 +70,7 @@ public string RotorCatcherText [XmlElement("dumpValve")] public string DumpValveText { - get => DumpValve.HasValue ? XmlConvert.ToString(DumpValve.Value) : null; + get => DumpValve?.ToString(CultureInfo.InvariantCulture); set => DumpValve = string.IsNullOrEmpty(value) ? default(bool?) : bool.Parse(value); } @@ -82,7 +82,7 @@ public string DumpValveText [XmlElement("rotatable")] public string RotatableText { - get => Rotatable.HasValue ? XmlConvert.ToString(Rotatable.Value) : null; + get => Rotatable?.ToString(CultureInfo.InvariantCulture); set => Rotatable = string.IsNullOrEmpty(value) ? default(bool?) : bool.Parse(value); } diff --git a/Src/Witsml/Data/Tubular/WitsmlNozzle.cs b/Src/Witsml/Data/Tubular/WitsmlNozzle.cs index adb7b1022..d19f6a294 100644 --- a/Src/Witsml/Data/Tubular/WitsmlNozzle.cs +++ b/Src/Witsml/Data/Tubular/WitsmlNozzle.cs @@ -1,3 +1,4 @@ +using System.Globalization; using System.Xml; using System.Xml.Serialization; @@ -15,7 +16,7 @@ public class WitsmlNozzle [XmlElement("index")] public string IndexText { - get => Index.HasValue ? XmlConvert.ToString(Index.Value) : null; + get => Index?.ToString(CultureInfo.InvariantCulture); set => Index = string.IsNullOrEmpty(value) ? default(int?) : int.Parse(value); } diff --git a/Src/Witsml/Data/Tubular/WitsmlRotarySteerableTool.cs b/Src/Witsml/Data/Tubular/WitsmlRotarySteerableTool.cs index 921a2fefd..3994a553e 100644 --- a/Src/Witsml/Data/Tubular/WitsmlRotarySteerableTool.cs +++ b/Src/Witsml/Data/Tubular/WitsmlRotarySteerableTool.cs @@ -50,7 +50,7 @@ public class WitsmlRotarySteerableTool [XmlElement("pressLossFact")] public string PressLossFactText { - get => PressLossFact.HasValue ? XmlConvert.ToString(PressLossFact.Value) : null; + get => PressLossFact?.ToString(CultureInfo.InvariantCulture); set => PressLossFact = string.IsNullOrEmpty(value) ? default(double?) : double.Parse(value, CultureInfo.InvariantCulture); } @@ -59,7 +59,7 @@ public string PressLossFactText [XmlElement("padCount")] public string PadCountText { - get => PadCount.HasValue ? XmlConvert.ToString(PadCount.Value) : null; + get => PadCount?.ToString(CultureInfo.InvariantCulture); set => PadCount = string.IsNullOrEmpty(value) ? default(int?) : int.Parse(value); } diff --git a/Src/Witsml/Data/Tubular/WitsmlStabilizer.cs b/Src/Witsml/Data/Tubular/WitsmlStabilizer.cs index 17ea1f36c..0b239c8ed 100644 --- a/Src/Witsml/Data/Tubular/WitsmlStabilizer.cs +++ b/Src/Witsml/Data/Tubular/WitsmlStabilizer.cs @@ -34,7 +34,7 @@ public class WitsmlStabilizer [XmlElement("factFric")] public string FactFricText { - get => FactFric.HasValue ? XmlConvert.ToString(FactFric.Value) : null; + get => FactFric?.ToString(CultureInfo.InvariantCulture); set => FactFric = string.IsNullOrEmpty(value) ? default(double?) : double.Parse(value, CultureInfo.InvariantCulture); } diff --git a/Src/Witsml/Data/Tubular/WitsmlTubular.cs b/Src/Witsml/Data/Tubular/WitsmlTubular.cs index 4d82a80ca..a22768e49 100644 --- a/Src/Witsml/Data/Tubular/WitsmlTubular.cs +++ b/Src/Witsml/Data/Tubular/WitsmlTubular.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Globalization; using System.Xml; using System.Xml.Serialization; @@ -25,7 +26,7 @@ public override WitsmlTubulars AsItemInWitsmlList() [XmlElement("valveFloat")] public string ValveFloatText { - get => ValveFloat.HasValue ? XmlConvert.ToString(ValveFloat.Value) : null; + get => ValveFloat?.ToString(CultureInfo.InvariantCulture); set => ValveFloat = string.IsNullOrEmpty(value) ? default(bool?) : bool.Parse(value); } @@ -34,7 +35,7 @@ public string ValveFloatText [XmlElement("sourceNuclear")] public string SourceNuclearText { - get => SourceNuclear.HasValue ? XmlConvert.ToString(SourceNuclear.Value) : null; + get => SourceNuclear?.ToString(CultureInfo.InvariantCulture); set => SourceNuclear = string.IsNullOrEmpty(value) ? default(bool?) : bool.Parse(value); } diff --git a/Src/Witsml/Data/Tubular/WitsmlTubularComponent.cs b/Src/Witsml/Data/Tubular/WitsmlTubularComponent.cs index 9c7cf8af4..e561244f6 100644 --- a/Src/Witsml/Data/Tubular/WitsmlTubularComponent.cs +++ b/Src/Witsml/Data/Tubular/WitsmlTubularComponent.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Globalization; using System.Xml; using System.Xml.Serialization; @@ -19,7 +20,7 @@ public class WitsmlTubularComponent [XmlElement("sequence")] public string SequenceText { - get => Sequence.HasValue ? XmlConvert.ToString(Sequence.Value) : null; + get => Sequence?.ToString(CultureInfo.InvariantCulture); set => Sequence = string.IsNullOrEmpty(value) ? default(int?) : int.Parse(value); } @@ -46,7 +47,7 @@ public string SequenceText [XmlElement("numJointStand")] public string NumJointStandText { - get => NumJointStand.HasValue ? XmlConvert.ToString(NumJointStand.Value) : null; + get => NumJointStand?.ToString(CultureInfo.InvariantCulture); set => NumJointStand = string.IsNullOrEmpty(value) ? default(int?) : int.Parse(value); } diff --git a/Src/Witsml/Data/WitsmlBitRecord.cs b/Src/Witsml/Data/WitsmlBitRecord.cs index 08ca9ee54..b3428e60c 100644 --- a/Src/Witsml/Data/WitsmlBitRecord.cs +++ b/Src/Witsml/Data/WitsmlBitRecord.cs @@ -1,3 +1,4 @@ +using System.Globalization; using System.Xml; using System.Xml.Serialization; @@ -42,7 +43,7 @@ public class WitsmlBitRecord [XmlElement("condInitInner")] public string CondInitInnerText { - get => CondInitInner.HasValue ? XmlConvert.ToString(CondInitInner.Value) : null; + get => CondInitInner?.ToString(CultureInfo.InvariantCulture); set => CondInitInner = string.IsNullOrEmpty(value) ? default(int?) : int.Parse(value); } @@ -51,7 +52,7 @@ public string CondInitInnerText [XmlElement("condInitOuter")] public string CondInitOuterText { - get => CondInitOuter.HasValue ? XmlConvert.ToString(CondInitOuter.Value) : null; + get => CondInitOuter?.ToString(CultureInfo.InvariantCulture); set => CondInitOuter = string.IsNullOrEmpty(value) ? default(int?) : int.Parse(value); } @@ -78,7 +79,7 @@ public string CondInitOuterText [XmlElement("condFinalInner")] public string CondFinalInnerText { - get => CondFinalInner.HasValue ? XmlConvert.ToString(CondFinalInner.Value) : null; + get => CondFinalInner?.ToString(CultureInfo.InvariantCulture); set => CondFinalInner = string.IsNullOrEmpty(value) ? default(int?) : int.Parse(value); } @@ -87,7 +88,7 @@ public string CondFinalInnerText [XmlElement("condFinalOuter")] public string CondFinalOuterText { - get => CondFinalOuter.HasValue ? XmlConvert.ToString(CondFinalOuter.Value) : null; + get => CondFinalOuter?.ToString(CultureInfo.InvariantCulture); set => CondFinalOuter = string.IsNullOrEmpty(value) ? default(int?) : int.Parse(value); } diff --git a/Src/Witsml/Data/WitsmlCustomData.cs b/Src/Witsml/Data/WitsmlCustomData.cs index 12d095795..82ea8722c 100644 --- a/Src/Witsml/Data/WitsmlCustomData.cs +++ b/Src/Witsml/Data/WitsmlCustomData.cs @@ -21,7 +21,7 @@ public XmlElement[] AllElements { _allElements = value; // System.Text.Json does not support serializing XML documents so we serialize the contents verbatim for now - Verbatim = string.Join("", value.Select(element => element.OuterXml)); + Verbatim = string.Join(string.Empty, value.Select(element => element.OuterXml)); } } diff --git a/Src/Witsml/Data/WitsmlData.cs b/Src/Witsml/Data/WitsmlData.cs index f7298cca3..a6dcd2c64 100644 --- a/Src/Witsml/Data/WitsmlData.cs +++ b/Src/Witsml/Data/WitsmlData.cs @@ -7,7 +7,7 @@ namespace Witsml.Data public class WitsmlData : IWitsmlQueryType { [XmlText] - public string Data { get; set; } = ""; + public string Data { get; set; } = string.Empty; public Point GetPoint() { diff --git a/Src/Witsml/Data/WitsmlExtensionValue.cs b/Src/Witsml/Data/WitsmlExtensionValue.cs index 3ab0e87db..533ff066e 100644 --- a/Src/Witsml/Data/WitsmlExtensionValue.cs +++ b/Src/Witsml/Data/WitsmlExtensionValue.cs @@ -5,9 +5,9 @@ namespace Witsml.Data public class WitsmlExtensionValue { [XmlAttribute("uom")] - public string Uom { get; set; } = ""; + public string Uom { get; set; } = string.Empty; [XmlText] - public string Value { get; set; } = ""; + public string Value { get; set; } = string.Empty; } } diff --git a/Src/Witsml/Data/WitsmlIndex.cs b/Src/Witsml/Data/WitsmlIndex.cs index 391b1bfed..33cdc35b7 100644 --- a/Src/Witsml/Data/WitsmlIndex.cs +++ b/Src/Witsml/Data/WitsmlIndex.cs @@ -7,10 +7,10 @@ namespace Witsml.Data public class WitsmlIndex { [XmlAttribute("uom")] - public string Uom { get; set; } = ""; + public string Uom { get; set; } = string.Empty; [XmlText] - public string Value { get; set; } = ""; + public string Value { get; set; } = string.Empty; public WitsmlIndex() { } diff --git a/Src/Witsml/Data/WitsmlLocation.cs b/Src/Witsml/Data/WitsmlLocation.cs index dd9c6074d..b6b6c9704 100644 --- a/Src/Witsml/Data/WitsmlLocation.cs +++ b/Src/Witsml/Data/WitsmlLocation.cs @@ -1,3 +1,4 @@ +using System.Globalization; using System.Xml; using System.Xml.Serialization; @@ -24,7 +25,7 @@ public class WitsmlLocation [XmlElement("original")] public string OriginalText { - get => Original.HasValue ? XmlConvert.ToString(Original.Value) : null; + get => Original?.ToString(CultureInfo.InvariantCulture); set => Original = !string.IsNullOrEmpty(value) ? bool.Parse(value) : default(bool?); } [XmlElement("description")] public string Description { get; set; } diff --git a/Src/Witsml/Data/WitsmlTrajectory.cs b/Src/Witsml/Data/WitsmlTrajectory.cs index c0dbf79d4..84894696c 100644 --- a/Src/Witsml/Data/WitsmlTrajectory.cs +++ b/Src/Witsml/Data/WitsmlTrajectory.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Globalization; using System.Xml; using System.Xml.Serialization; @@ -22,7 +23,7 @@ public override WitsmlTrajectories AsItemInWitsmlList() [XmlElement("objectGrowing")] public string ObjectGrowingText { - get => ObjectGrowing.HasValue ? XmlConvert.ToString(ObjectGrowing.Value) : null; + get => ObjectGrowing?.ToString(CultureInfo.InvariantCulture); set => ObjectGrowing = !string.IsNullOrEmpty(value) ? bool.Parse(value) : default(bool?); } diff --git a/Src/Witsml/Data/WitsmlTrajectoryStation.cs b/Src/Witsml/Data/WitsmlTrajectoryStation.cs index 5f11474d5..758de59fd 100644 --- a/Src/Witsml/Data/WitsmlTrajectoryStation.cs +++ b/Src/Witsml/Data/WitsmlTrajectoryStation.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Globalization; using System.Xml; using System.Xml.Serialization; @@ -40,7 +41,7 @@ public class WitsmlTrajectoryStation [XmlElement("magXAxialCorUsed")] public string MagXAxialCorUsedText { - get => MagXAxialCorUsed.HasValue ? XmlConvert.ToString(MagXAxialCorUsed.Value) : null; + get => MagXAxialCorUsed?.ToString(CultureInfo.InvariantCulture); set => MagXAxialCorUsed = !string.IsNullOrEmpty(value) ? bool.Parse(value) : default(bool?); } @@ -49,7 +50,7 @@ public string MagXAxialCorUsedText [XmlElement("sagCorUsed")] public string SagCorUsedText { - get => SagCorUsed.HasValue ? XmlConvert.ToString(SagCorUsed.Value) : null; + get => SagCorUsed?.ToString(CultureInfo.InvariantCulture); set => SagCorUsed = !string.IsNullOrEmpty(value) ? bool.Parse(value) : default(bool?); } @@ -58,7 +59,7 @@ public string SagCorUsedText [XmlElement("magDrlstrCorUsed")] public string MagDrlstrCorUsedText { - get => MagDrlstrCorUsed.HasValue ? XmlConvert.ToString(MagDrlstrCorUsed.Value) : null; + get => MagDrlstrCorUsed?.ToString(CultureInfo.InvariantCulture); set => MagDrlstrCorUsed = !string.IsNullOrEmpty(value) ? bool.Parse(value) : default(bool?); } @@ -67,7 +68,7 @@ public string MagDrlstrCorUsedText [XmlElement("infieldRefCorUsed")] public string InfieldRefCorUsedText { - get => InfieldRefCorUsed.HasValue ? XmlConvert.ToString(InfieldRefCorUsed.Value) : null; + get => InfieldRefCorUsed?.ToString(CultureInfo.InvariantCulture); set => InfieldRefCorUsed = !string.IsNullOrEmpty(value) ? bool.Parse(value) : default(bool?); } @@ -76,7 +77,7 @@ public string InfieldRefCorUsedText [XmlElement("interpolatedInfieldRefCorUsed")] public string InterpolatedInfieldRefCorUsedText { - get => InterpolatedInfieldRefCorUsed.HasValue ? XmlConvert.ToString(InterpolatedInfieldRefCorUsed.Value) : null; + get => InterpolatedInfieldRefCorUsed?.ToString(CultureInfo.InvariantCulture); set => InterpolatedInfieldRefCorUsed = !string.IsNullOrEmpty(value) ? bool.Parse(value) : default(bool?); } @@ -85,7 +86,7 @@ public string InterpolatedInfieldRefCorUsedText [XmlElement("inHoleRefCorUsed")] public string InHoleRefCorUsedText { - get => InHoleRefCorUsed.HasValue ? XmlConvert.ToString(InHoleRefCorUsed.Value) : null; + get => InHoleRefCorUsed?.ToString(CultureInfo.InvariantCulture); set => InHoleRefCorUsed = !string.IsNullOrEmpty(value) ? bool.Parse(value) : default(bool?); } @@ -95,7 +96,7 @@ public string InHoleRefCorUsedText [XmlElement("axialMagInterferenceCorUsed")] public string AxialMagInterferenceCorUsedText { - get => AxialMagInterferenceCorUsed.HasValue ? XmlConvert.ToString(AxialMagInterferenceCorUsed.Value) : null; + get => AxialMagInterferenceCorUsed?.ToString(CultureInfo.InvariantCulture); set => AxialMagInterferenceCorUsed = !string.IsNullOrEmpty(value) ? bool.Parse(value) : default(bool?); } @@ -104,7 +105,7 @@ public string AxialMagInterferenceCorUsedText [XmlElement("cosagCorUsed")] public string CosagCorUsedText { - get => CosagCorUsed.HasValue ? XmlConvert.ToString(CosagCorUsed.Value) : null; + get => CosagCorUsed?.ToString(CultureInfo.InvariantCulture); set => CosagCorUsed = !string.IsNullOrEmpty(value) ? bool.Parse(value) : default(bool?); } @@ -113,7 +114,7 @@ public string CosagCorUsedText [XmlElement("MSACorUsed")] public string MsaCorUsedText { - get => MsaCorUsed.HasValue ? XmlConvert.ToString(MsaCorUsed.Value) : null; + get => MsaCorUsed?.ToString(CultureInfo.InvariantCulture); set => MsaCorUsed = !string.IsNullOrEmpty(value) ? bool.Parse(value) : default(bool?); } diff --git a/Src/Witsml/Extensions/DateTimeExtensions.cs b/Src/Witsml/Extensions/DateTimeExtensions.cs index 6d70244b2..d0e4ebd91 100644 --- a/Src/Witsml/Extensions/DateTimeExtensions.cs +++ b/Src/Witsml/Extensions/DateTimeExtensions.cs @@ -9,7 +9,7 @@ public static class DateTimeExtensions { public static string ToISODateTimeString(this DateTime dateTime) { - return dateTime.ToUniversalTime().ToString(DateTimeIndex.IsoPattern, CultureInfo.InvariantCulture); + return dateTime.ToUniversalTime().ToString(CommonConstants.DateTimeIndex.IsoPattern, CultureInfo.InvariantCulture); } } } diff --git a/Src/Witsml/Extensions/WitsmlLogExtensions.cs b/Src/Witsml/Extensions/WitsmlLogExtensions.cs index b5a8dd54f..335b0950d 100644 --- a/Src/Witsml/Extensions/WitsmlLogExtensions.cs +++ b/Src/Witsml/Extensions/WitsmlLogExtensions.cs @@ -8,14 +8,14 @@ public static string GetStartIndexAsString(this WitsmlLog witsmlLog) { return witsmlLog.StartIndex == null && string.IsNullOrEmpty(witsmlLog.StartDateTimeIndex) ? null - : string.Equals(witsmlLog.IndexType, WitsmlLog.WITSML_INDEX_TYPE_MD, System.StringComparison.Ordinal) ? witsmlLog.StartIndex != null ? witsmlLog.StartIndex.ToString() : "" : witsmlLog.StartDateTimeIndex; + : string.Equals(witsmlLog.IndexType, WitsmlLog.WITSML_INDEX_TYPE_MD, System.StringComparison.Ordinal) ? witsmlLog.StartIndex != null ? witsmlLog.StartIndex.ToString() : string.Empty : witsmlLog.StartDateTimeIndex; } public static string GetEndIndexAsString(this WitsmlLog witsmlLog) { return witsmlLog.EndIndex == null && string.IsNullOrEmpty(witsmlLog.EndDateTimeIndex) ? null - : string.Equals(witsmlLog.IndexType, WitsmlLog.WITSML_INDEX_TYPE_MD, System.StringComparison.Ordinal) ? witsmlLog.EndIndex != null ? witsmlLog.EndIndex.ToString() : "" : witsmlLog.EndDateTimeIndex; + : string.Equals(witsmlLog.IndexType, WitsmlLog.WITSML_INDEX_TYPE_MD, System.StringComparison.Ordinal) ? witsmlLog.EndIndex != null ? witsmlLog.EndIndex.ToString() : string.Empty : witsmlLog.EndDateTimeIndex; } diff --git a/Src/Witsml/WitsmlClient.cs b/Src/Witsml/WitsmlClient.cs index 635a3d0a6..e4c50bc66 100644 --- a/Src/Witsml/WitsmlClient.cs +++ b/Src/Witsml/WitsmlClient.cs @@ -46,7 +46,7 @@ public WitsmlClient(string hostname, string username, string password, WitsmlCli options.Hostname = hostname; options.Credentials = new WitsmlCredentials(username, password); options.ClientCapabilities = clientCapabilities; - options.RequestTimeOut = requestTimeout ?? TimeSpan.FromMinutes(1); + options.RequestTimeOut = requestTimeout ?? TimeSpan.FromSeconds(CommonConstants.DefaultClientRequestTimeOut); options.LogQueries = logQueries; }) { } @@ -263,7 +263,7 @@ public async Task AddToStoreAsync(string query, OptionsIn optionsIn = nu WMLS_AddToStoreRequest request = new() { WMLtypeIn = type, - OptionsIn = optionsIn?.GetKeywords() ?? "", + OptionsIn = optionsIn?.GetKeywords() ?? string.Empty, XMLin = query, CapabilitiesIn = _clientCapabilities }; @@ -317,7 +317,7 @@ public async Task UpdateInStoreAsync(string query, OptionsIn optionsIn = WMLS_UpdateInStoreRequest request = new() { WMLtypeIn = type, - OptionsIn = optionsIn?.GetKeywords() ?? "", + OptionsIn = optionsIn?.GetKeywords() ?? string.Empty, XMLin = query, CapabilitiesIn = _clientCapabilities }; @@ -371,7 +371,7 @@ public async Task DeleteFromStoreAsync(string query, OptionsIn optionsIn WMLS_DeleteFromStoreRequest request = new() { WMLtypeIn = type, - OptionsIn = optionsIn?.GetKeywords() ?? "", + OptionsIn = optionsIn?.GetKeywords() ?? string.Empty, QueryIn = query, CapabilitiesIn = _clientCapabilities }; @@ -396,7 +396,7 @@ public async Task TestConnectionAsync() } // Spec requires a comma-seperated list of supported versions without spaces - var versions = response.Result.Split(','); + var versions = response.Result.Split(CommonConstants.DataSeparator); if (versions.All(v => v != "1.4.1.1")) throw new Exception("Error while testing connection: Server does not indicate support for WITSML 1.4.1.1"); diff --git a/Src/Witsml/WitsmlClientOptions.cs b/Src/Witsml/WitsmlClientOptions.cs index 46961eee4..76cb8b46f 100644 --- a/Src/Witsml/WitsmlClientOptions.cs +++ b/Src/Witsml/WitsmlClientOptions.cs @@ -31,7 +31,7 @@ public class WitsmlClientOptions /// /// The timeout interval to be used when communicating with the WITSML server. Default is 00:01:00 minutes /// - public TimeSpan RequestTimeOut { get; set; } = TimeSpan.FromMinutes(1); + public TimeSpan RequestTimeOut { get; set; } = TimeSpan.FromSeconds(CommonConstants.DefaultClientRequestTimeOut); /// /// Enable logging all queries to a file (queries.log) in the current directory diff --git a/Src/Witsml/Xml/Serializer.cs b/Src/Witsml/Xml/Serializer.cs index fe11aacc5..f28f0e6fb 100644 --- a/Src/Witsml/Xml/Serializer.cs +++ b/Src/Witsml/Xml/Serializer.cs @@ -16,7 +16,7 @@ public static string Serialize(T item, Boolean indentXml = false) using var writer = XmlWriter.Create(textWriter, settings); var namespaces = new XmlSerializerNamespaces(); - namespaces.Add("", "http://www.witsml.org/schemas/1series"); + namespaces.Add(string.Empty, "http://www.witsml.org/schemas/1series"); var serializer = new XmlSerializer(item.GetType()); serializer.Serialize(writer, item, namespaces); diff --git a/Src/WitsmlExplorer.Api/Extensions/BuilderExtensions.cs b/Src/WitsmlExplorer.Api/Extensions/BuilderExtensions.cs index be06df27b..bb4c0e05e 100644 --- a/Src/WitsmlExplorer.Api/Extensions/BuilderExtensions.cs +++ b/Src/WitsmlExplorer.Api/Extensions/BuilderExtensions.cs @@ -5,6 +5,8 @@ using Microsoft.Extensions.Configuration; +using Witsml; + using WitsmlExplorer.Api.Configuration; using WitsmlExplorer.Api.Services; @@ -24,7 +26,7 @@ public static IConfigurationBuilder AddAzureWitsmlServerCreds(this Configuration new DefaultAzureCredential(), new AzureKeyVaultConfigurationOptions() { - ReloadInterval = TimeSpan.FromMinutes(15) + ReloadInterval = TimeSpan.FromMinutes(CommonConstants.DefaultReloadInterval) }); } return configuration; diff --git a/Src/WitsmlExplorer.Api/Query/LogQueries.cs b/Src/WitsmlExplorer.Api/Query/LogQueries.cs index 42aeef82c..0c71eccfe 100644 --- a/Src/WitsmlExplorer.Api/Query/LogQueries.cs +++ b/Src/WitsmlExplorer.Api/Query/LogQueries.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; +using Witsml; using Witsml.Data; using Witsml.Data.Curves; using Witsml.Extensions; @@ -82,7 +83,7 @@ public static WitsmlLogs GetLogContent( LogCurveInfo = new List(), LogData = new WitsmlLogData { - MnemonicList = string.Join(",", mnemonics) + MnemonicList = string.Join(CommonConstants.DataSeparator, mnemonics) } }; diff --git a/Src/WitsmlExplorer.Api/Query/QueryHelper.cs b/Src/WitsmlExplorer.Api/Query/QueryHelper.cs index af4296234..cb839e1cd 100644 --- a/Src/WitsmlExplorer.Api/Query/QueryHelper.cs +++ b/Src/WitsmlExplorer.Api/Query/QueryHelper.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.Reflection; +using Witsml; + using WitsmlExplorer.Api.Extensions; namespace WitsmlExplorer.Api.Query @@ -37,9 +39,9 @@ public static T AddPropertiesToObject(T obj, IList properties, IList< public static T AddPropertyToObject(T obj, string property, object propertyValue = null) { string childProperty = null; - if (property.Contains('.')) + if (property.Contains(CommonConstants.PropertySeparator)) { - var propertyParts = property.Split(".", 2); + var propertyParts = property.Split(CommonConstants.PropertySeparator, 2); property = propertyParts[0]; childProperty = propertyParts[1]; } @@ -95,7 +97,7 @@ private static object GetOrCreateInstanceOfProperty(object obj, PropertyInfo pro /// The value of the specified property. public static object GetPropertyFromObject(object obj, string property) { - var propertyParts = property.Split("."); + var propertyParts = property.Split(CommonConstants.PropertySeparator); foreach (var propertyPart in propertyParts) { obj = obj?.GetType().GetProperty(propertyPart.CapitalizeFirstLetter())?.GetValue(obj, null); diff --git a/Src/WitsmlExplorer.Api/Services/LogDataReader.cs b/Src/WitsmlExplorer.Api/Services/LogDataReader.cs index 2f4035dd3..7f6096fe6 100644 --- a/Src/WitsmlExplorer.Api/Services/LogDataReader.cs +++ b/Src/WitsmlExplorer.Api/Services/LogDataReader.cs @@ -140,7 +140,7 @@ private async Task FetchNextBatch() } } - string index = sourceLogData.Data.Last().Data.Split(",")[0]; + string index = sourceLogData.Data.Last().Data.Split(CommonConstants.DataSeparator)[0]; _startIndex = _indexType == WitsmlLog.WITSML_INDEX_TYPE_MD ? new DepthIndex(double.Parse(index, CultureInfo.InvariantCulture), ((DepthIndex)_endIndex).Uom) : new DateTimeIndex(DateTime.Parse(index, CultureInfo.InvariantCulture)); diff --git a/Src/WitsmlExplorer.Api/Services/LogObjectService.cs b/Src/WitsmlExplorer.Api/Services/LogObjectService.cs index 96563b7d8..7dc749ef3 100644 --- a/Src/WitsmlExplorer.Api/Services/LogObjectService.cs +++ b/Src/WitsmlExplorer.Api/Services/LogObjectService.cs @@ -5,6 +5,7 @@ using Microsoft.IdentityModel.Tokens; +using Witsml; using Witsml.Data; using Witsml.Extensions; using Witsml.ServiceReference; @@ -181,8 +182,8 @@ public async Task ReadLogData(string wellUid, string wellboreUid, strin } } - string[] witsmlLogMnemonics = witsmlLog.LogData.MnemonicList.Split(","); - string[] witsmlLogUnits = witsmlLog.LogData.UnitList.Split(","); + string[] witsmlLogMnemonics = witsmlLog.LogData.MnemonicList.Split(CommonConstants.DataSeparator); + string[] witsmlLogUnits = witsmlLog.LogData.UnitList.Split(CommonConstants.DataSeparator); return new LogData { @@ -197,10 +198,10 @@ public async Task ReadLogData(string wellUid, string wellboreUid, strin private static ICollection> GetDataDictionary(WitsmlLogData logData) { List> result = new(); - string[] mnemonics = logData.MnemonicList.Split(","); + string[] mnemonics = logData.MnemonicList.Split(CommonConstants.DataSeparator); foreach (string valueRow in logData.Data.Select(d => d.Data)) { - var keyValuePairs = valueRow.Split(",").Select((value, index) => new { index, value }).ToList(); + var keyValuePairs = valueRow.Split(CommonConstants.DataSeparator).Select((value, index) => new { index, value }).ToList(); if (keyValuePairs.Count > mnemonics.Length) { throw new WitsmlResultParsingException($"Unable to parse log data due to unexpected amount of commas in row {result.Count + 1}. Expected {mnemonics.Length} got {keyValuePairs.Count}.", (int)HttpStatusCode.InternalServerError); diff --git a/Src/WitsmlExplorer.Api/Services/WitsmlClientProvider.cs b/Src/WitsmlExplorer.Api/Services/WitsmlClientProvider.cs index c4d35671b..8b233d571 100644 --- a/Src/WitsmlExplorer.Api/Services/WitsmlClientProvider.cs +++ b/Src/WitsmlExplorer.Api/Services/WitsmlClientProvider.cs @@ -79,7 +79,7 @@ public IWitsmlClient GetClient() options.Credentials = new WitsmlCredentials(_targetCreds.UserId, _targetCreds.Password); options.ClientCapabilities = _clientCapabilities; options.LogQueries = _logQueries; - options.RequestTimeOut = TimeSpan.FromSeconds(90); + options.RequestTimeOut = TimeSpan.FromSeconds(CommonConstants.DefaultClientRequestTimeOut); }) : null; } @@ -98,7 +98,7 @@ public IWitsmlClient GetSourceClient() options.Credentials = new WitsmlCredentials(_sourceCreds.UserId, _sourceCreds.Password); options.ClientCapabilities = _clientCapabilities; options.LogQueries = _logQueries; - options.RequestTimeOut = TimeSpan.FromSeconds(90); + options.RequestTimeOut = TimeSpan.FromSeconds(CommonConstants.DefaultClientRequestTimeOut); }) : null; } diff --git a/Src/WitsmlExplorer.Api/Workers/CheckLogHeaderWorker.cs b/Src/WitsmlExplorer.Api/Workers/CheckLogHeaderWorker.cs index 9b2f42a53..4988078b1 100644 --- a/Src/WitsmlExplorer.Api/Workers/CheckLogHeaderWorker.cs +++ b/Src/WitsmlExplorer.Api/Workers/CheckLogHeaderWorker.cs @@ -6,6 +6,7 @@ using Microsoft.Extensions.Logging; using Microsoft.IdentityModel.Tokens; +using Witsml; using Witsml.Data; using Witsml.ServiceReference; @@ -82,8 +83,8 @@ public CheckLogHeaderWorker(ILogger logger, IWitsmlClientProv WitsmlLog headerResultLog = (WitsmlLog)headerResult.Objects.First(); string headerEndIndex = isDepthLog ? headerResultLog.EndIndex.Value : headerResultLog.EndDateTimeIndex; string headerStartIndex = isDepthLog ? headerResultLog.StartIndex.Value : headerResultLog.StartDateTimeIndex; - Dictionary headerStartValues = headerResultLog.LogCurveInfo.ToDictionary(l => l.Mnemonic, l => (isDepthLog ? l.MinIndex?.Value : l.MinDateTimeIndex) ?? ""); - Dictionary headerEndValues = headerResultLog.LogCurveInfo.ToDictionary(l => l.Mnemonic, l => (isDepthLog ? l.MaxIndex?.Value : l.MaxDateTimeIndex) ?? ""); + Dictionary headerStartValues = headerResultLog.LogCurveInfo.ToDictionary(l => l.Mnemonic, l => (isDepthLog ? l.MinIndex?.Value : l.MinDateTimeIndex) ?? string.Empty); + Dictionary headerEndValues = headerResultLog.LogCurveInfo.ToDictionary(l => l.Mnemonic, l => (isDepthLog ? l.MaxIndex?.Value : l.MaxDateTimeIndex) ?? string.Empty); return (headerStartValues, headerEndValues, headerStartIndex, headerEndIndex, headerResultLog.IndexCurve.Value); } @@ -102,16 +103,16 @@ public CheckLogHeaderWorker(ILogger logger, IWitsmlClientProv { return null; } - var endResultLogData = dataEndResultLog.LogData.Data?.Select(data => data.Data.Split(",")).ToList(); - string[] startResultLogData = dataStartResultLog.LogData.Data?.FirstOrDefault()?.Data.Split(","); + var endResultLogData = dataEndResultLog.LogData.Data?.Select(data => data.Data.Split(CommonConstants.DataSeparator)).ToList(); + string[] startResultLogData = dataStartResultLog.LogData.Data?.FirstOrDefault()?.Data.Split(CommonConstants.DataSeparator); if (startResultLogData.IsNullOrEmpty() || endResultLogData.IsNullOrEmpty()) { return null; } - IEnumerable dataStartIndexes = startResultLogData.Select(data => data == "" ? "" : startResultLogData[0]); + IEnumerable dataStartIndexes = startResultLogData.Select(data => data == String.Empty ? String.Empty : startResultLogData[0]); IEnumerable dataEndIndexes = ExtractColumnIndexes(endResultLogData); - string[] startMnemonics = dataStartResultLog.LogData.MnemonicList?.Split(","); - string[] endMnemonics = dataEndResultLog.LogData.MnemonicList?.Split(","); + string[] startMnemonics = dataStartResultLog.LogData.MnemonicList?.Split(CommonConstants.DataSeparator); + string[] endMnemonics = dataEndResultLog.LogData.MnemonicList?.Split(CommonConstants.DataSeparator); if (startMnemonics == null || endMnemonics == null) { return null; @@ -128,7 +129,7 @@ public CheckLogHeaderWorker(ILogger logger, IWitsmlClientProv private async Task> AddStartIndexForMissingMnemonics(string wellUid, string wellboreUid, string logUid, Dictionary dataStartValues, string[] startMnemonics, string[] endMnemonics, string indexCurve) { string[] missingMnemonics = endMnemonics.Where(mnemonic => !startMnemonics.Contains(mnemonic)) - .Concat(dataStartValues.Where((entry) => entry.Value == "").Select((entry) => entry.Key)).Distinct().ToArray(); + .Concat(dataStartValues.Where((entry) => entry.Value == string.Empty).Select((entry) => entry.Key)).Distinct().ToArray(); if (missingMnemonics.Any()) { IEnumerable missingIndexQueries = missingMnemonics.Select(mnemonic => LogQueries.GetLogContent(wellUid, wellboreUid, logUid, null, new List() { indexCurve, mnemonic }, null, null)); @@ -136,7 +137,7 @@ private async Task> AddStartIndexForMissingMnemonics( List> missingDataResults = missingIndexQueries.Select(query => GetTargetWitsmlClientOrThrow().GetFromStoreNullableAsync(query, new OptionsIn(ReturnElements.DataOnly, MaxReturnNodes: 1))).ToList(); await Task.WhenAll(missingDataResults); IEnumerable missingLogs = missingDataResults.Select(r => (WitsmlLog)r.Result.Objects.First()); - IEnumerable missingDataIndexes = missingLogs.Select(l => l.LogData?.Data?.FirstOrDefault()?.Data?.Split(",")?[0] ?? ""); + IEnumerable missingDataIndexes = missingLogs.Select(l => l.LogData?.Data?.FirstOrDefault()?.Data?.Split(CommonConstants.DataSeparator)?[0] ?? string.Empty); // Insert the indexes from the missing mnemonics to the original dict. missingDataIndexes .Select((value, index) => new { mnemonic = missingMnemonics[index], value }) diff --git a/Src/WitsmlExplorer.Api/Workers/CompareLogDataWorker.cs b/Src/WitsmlExplorer.Api/Workers/CompareLogDataWorker.cs index 81562f654..91e74f284 100644 --- a/Src/WitsmlExplorer.Api/Workers/CompareLogDataWorker.cs +++ b/Src/WitsmlExplorer.Api/Workers/CompareLogDataWorker.cs @@ -141,7 +141,7 @@ private async Task AddUnsharedMnemonicData(ServerType serverType, IWitsmlClient { if (_compareLogDataReportItems.Count >= MaxMismatchesLimit) break; - var data = dataRow.Split(','); + var data = dataRow.Split(CommonConstants.DataSeparator); var index = data.First(); var value = data.Last(); @@ -342,7 +342,7 @@ private List SortIndexes(List indexes) private Dictionary WitsmlLogDataToDictionary(WitsmlLogData logData) { - return logData.Data?.ToDictionary(row => row.Data.Split(',').First(), row => row.Data.Split(',').Last()); + return logData.Data?.ToDictionary(row => row.Data.Split(CommonConstants.DataSeparator).First(), row => row.Data.Split(CommonConstants.DataSeparator).Last()); } private void VerifyLogs(WitsmlLog sourceLog, WitsmlLog targetLog) diff --git a/Src/WitsmlExplorer.Api/Workers/Copy/CopyLogDataWorker.cs b/Src/WitsmlExplorer.Api/Workers/Copy/CopyLogDataWorker.cs index c99f42395..797f9cf47 100644 --- a/Src/WitsmlExplorer.Api/Workers/Copy/CopyLogDataWorker.cs +++ b/Src/WitsmlExplorer.Api/Workers/Copy/CopyLogDataWorker.cs @@ -218,7 +218,7 @@ private async Task CopyLogDataWithoutDuplicates(WitsmlLog sourceLog, double targetIndex = double.MinValue; foreach (WitsmlData row in data) { - string[] split = row.Data.Split(","); + string[] split = row.Data.Split(CommonConstants.DataSeparator); lastSourceRowIndex = StringHelpers.ToDouble(split[0]); double nextTargetIndex = Math.Round(lastSourceRowIndex, targetDepthLogDecimals, MidpointRounding.AwayFromZero); if (Math.Abs(targetIndex - nextTargetIndex) > difference) @@ -263,14 +263,14 @@ private static WitsmlData CollateData(List oldRows, double index) { for (int j = 0; j < oldRows.Count; j++) { - if (oldRows[j][i] != "") + if (oldRows[j][i] != string.Empty) { newRow[i] = oldRows[j][i]; break; } } } - return new() { Data = index.ToString(CultureInfo.InvariantCulture) + "," + string.Join(",", newRow) }; + return new() { Data = index.ToString(CultureInfo.InvariantCulture) + CommonConstants.DataSeparator + string.Join(CommonConstants.DataSeparator, newRow) }; } private async Task VerifyTargetHasRequiredLogCurveInfos(WitsmlLog sourceLog, IEnumerable sourceMnemonics, WitsmlLog targetLog) @@ -294,7 +294,7 @@ private async Task VerifyTargetHasRequiredLogCurveInfos(WitsmlLog sourceLog, IEn QueryResult result = await GetTargetWitsmlClientOrThrow().UpdateInStoreAsync(query); if (!result.IsSuccessful) { - string newMnemonics = string.Join(",", newLogCurveInfos.Select(lci => lci.Mnemonic)); + string newMnemonics = string.Join(CommonConstants.DataSeparator, newLogCurveInfos.Select(lci => lci.Mnemonic)); Logger.LogError("Failed to update LogCurveInfo for wellbore during copy data. Mnemonics: {Mnemonics}. " + "Target: UidWell: {TargetWellUid}, UidWellbore: {TargetWellboreUid}, Uid: {TargetLogUid}. ", newMnemonics, targetLog.UidWell, targetLog.UidWellbore, targetLog.Uid); @@ -304,7 +304,7 @@ private async Task VerifyTargetHasRequiredLogCurveInfos(WitsmlLog sourceLog, IEn private static WitsmlLogs CreateCopyQuery(WitsmlLog targetLog, WitsmlLogData logData) { - logData.MnemonicList = targetLog.IndexCurve.Value + logData.MnemonicList[logData.MnemonicList.IndexOf(",", StringComparison.InvariantCulture)..]; + logData.MnemonicList = targetLog.IndexCurve.Value + logData.MnemonicList[logData.MnemonicList.IndexOf(CommonConstants.DataSeparator, StringComparison.InvariantCulture)..]; return new() { Logs = new List { diff --git a/Src/WitsmlExplorer.Api/Workers/ImportLogDataWorker.cs b/Src/WitsmlExplorer.Api/Workers/ImportLogDataWorker.cs index 5ffba644e..b177684d0 100644 --- a/Src/WitsmlExplorer.Api/Workers/ImportLogDataWorker.cs +++ b/Src/WitsmlExplorer.Api/Workers/ImportLogDataWorker.cs @@ -100,7 +100,7 @@ private static IEnumerable CreateImportQueries(ImportLogDataJob job, { return job.DataRows .Where(d => d.Count() > 1) - .Select(row => new WitsmlData { Data = string.Join(',', row) }) + .Select(row => new WitsmlData { Data = string.Join(CommonConstants.DataSeparator, row) }) .Chunk(chunkSize) .Select(logData => new WitsmlLogs { @@ -114,8 +114,8 @@ private static IEnumerable CreateImportQueries(ImportLogDataJob job, LogData = new WitsmlLogData { Data = logData.ToList(), - MnemonicList = string.Join(',', job.Mnemonics), - UnitList = string.Join(',', job.Units) + MnemonicList = string.Join(CommonConstants.DataSeparator, job.Mnemonics), + UnitList = string.Join(CommonConstants.DataSeparator, job.Units) } } }, @@ -136,7 +136,7 @@ private static WitsmlLogs CreateAddMnemonicsQuery(ImportLogDataJob job, WitsmlLo .Select(i => new WitsmlLogCurveInfo { Mnemonic = job.Mnemonics.ElementAt(i), - Unit = string.IsNullOrEmpty(job.Units.ElementAt(i)) ? "unitless" : job.Units.ElementAt(i), // Can't updateInStore with an empty unit + Unit = string.IsNullOrEmpty(job.Units.ElementAt(i)) ? CommonConstants.Unit.Unitless : job.Units.ElementAt(i), // Can't updateInStore with an empty unit Uid = job.Mnemonics.ElementAt(i), TypeLogData = WitsmlLogCurveInfo.LogDataTypeDouble }).ToList(), diff --git a/Src/WitsmlExplorer.Api/Workers/SpliceLogsWorker.cs b/Src/WitsmlExplorer.Api/Workers/SpliceLogsWorker.cs index e6e423c30..19fcc063f 100644 --- a/Src/WitsmlExplorer.Api/Workers/SpliceLogsWorker.cs +++ b/Src/WitsmlExplorer.Api/Workers/SpliceLogsWorker.cs @@ -42,8 +42,8 @@ public SpliceLogsWorker(ILogger logger, IWitsmlClientProvider wit WitsmlLogData newLogData = new() { - MnemonicList = string.Join(",", newLogHeader.LogCurveInfo.Select(lci => lci.Mnemonic)), - UnitList = string.Join(",", newLogHeader.LogCurveInfo.Select(lci => lci.Unit)), + MnemonicList = string.Join(CommonConstants.DataSeparator, newLogHeader.LogCurveInfo.Select(lci => lci.Mnemonic)), + UnitList = string.Join(CommonConstants.DataSeparator, newLogHeader.LogCurveInfo.Select(lci => lci.Unit)), Data = new() // Will be populated in the loop below }; @@ -90,30 +90,30 @@ private static void VerifyLogHeaders(WitsmlLogs logHeaders) private static WitsmlLogData SpliceLogDataForCurve(WitsmlLogData primaryData, WitsmlLogData secondaryData, string mnemonic, bool isDepthLog) { - int mnemonicIndex = primaryData.MnemonicList.Split(',').ToList().FindIndex(m => m == mnemonic); - Dictionary primaryDict = primaryData.Data?.ToDictionary(row => row.Data.Split(',')[0], row => row.Data) ?? new(); + int mnemonicIndex = primaryData.MnemonicList.Split(CommonConstants.DataSeparator).ToList().FindIndex(m => m == mnemonic); + Dictionary primaryDict = primaryData.Data?.ToDictionary(row => row.Data.Split(CommonConstants.DataSeparator)[0], row => row.Data) ?? new(); string startIndex = null; string endIndex = null; if (primaryDict.Any()) { - var firstElementForCurve = primaryDict.FirstOrDefault(x => x.Value.Split(',')[mnemonicIndex] != ""); + var firstElementForCurve = primaryDict.FirstOrDefault(x => x.Value.Split(CommonConstants.DataSeparator)[mnemonicIndex] != string.Empty); startIndex = firstElementForCurve.Equals(default(KeyValuePair)) ? null : firstElementForCurve.Key; - var lastElementForCurve = primaryDict.LastOrDefault(x => x.Value.Split(',')[mnemonicIndex] != ""); + var lastElementForCurve = primaryDict.LastOrDefault(x => x.Value.Split(CommonConstants.DataSeparator)[mnemonicIndex] != string.Empty); endIndex = lastElementForCurve.Equals(default(KeyValuePair)) ? null : lastElementForCurve.Key; } foreach (var dataRow in secondaryData.Data.Select(row => row.Data)) { - var rowIndex = dataRow.Split(',').First(); + var rowIndex = dataRow.Split(CommonConstants.DataSeparator).First(); if ((startIndex == null && endIndex == null) || isDepthLog && (StringHelpers.ToDouble(rowIndex) < StringHelpers.ToDouble(startIndex) || StringHelpers.ToDouble(rowIndex) > StringHelpers.ToDouble(endIndex)) || !isDepthLog && (DateTime.Parse(rowIndex) < DateTime.Parse(startIndex) || DateTime.Parse(rowIndex) > DateTime.Parse(endIndex))) { - var newCellValue = dataRow.Split(',').Last(); - var currentRowValue = (primaryDict.GetValueOrDefault(rowIndex)?.Split(',') ?? Enumerable.Repeat("", primaryData.MnemonicList.Split(',').Length)).ToList(); + var newCellValue = dataRow.Split(CommonConstants.DataSeparator).Last(); + var currentRowValue = (primaryDict.GetValueOrDefault(rowIndex)?.Split(CommonConstants.DataSeparator) ?? Enumerable.Repeat("", primaryData.MnemonicList.Split(CommonConstants.DataSeparator).Length)).ToList(); currentRowValue[0] = rowIndex; currentRowValue[mnemonicIndex] = newCellValue; - primaryDict[rowIndex] = string.Join(",", currentRowValue); + primaryDict[rowIndex] = string.Join(CommonConstants.DataSeparator, currentRowValue); } } diff --git a/Tests/WitsmlExplorer.Api.Tests/Services/ObjectServiceTests.cs b/Tests/WitsmlExplorer.Api.Tests/Services/ObjectServiceTests.cs index 71f1792ce..a268ba67e 100644 --- a/Tests/WitsmlExplorer.Api.Tests/Services/ObjectServiceTests.cs +++ b/Tests/WitsmlExplorer.Api.Tests/Services/ObjectServiceTests.cs @@ -64,7 +64,7 @@ public async Task GetObjectsIdOnly_TwoLogs_BothReturned() It.Is((queryIn) => queryIn.Objects.First().UidWell == uidWell && queryIn.Objects.First().UidWellbore == uidWellbore && - queryIn.Objects.First().Uid == "" && + queryIn.Objects.First().Uid == string.Empty && queryIn.TypeName == new WitsmlLogs().TypeName ), It.Is((ops) => ops.ReturnElements == ReturnElements.IdOnly))) @@ -112,7 +112,7 @@ public async Task GetObjectsIdOnly_NoObjectsFound_EmptyList() It.Is((queryIn) => queryIn.Objects.First().UidWell == uidWell && queryIn.Objects.First().UidWellbore == uidWellbore && - queryIn.Objects.First().Uid == "" && + queryIn.Objects.First().Uid == string.Empty && queryIn.TypeName == new WitsmlMessages().TypeName ), It.Is((ops) => ops.ReturnElements == ReturnElements.IdOnly))) diff --git a/Tests/WitsmlExplorer.Api.Tests/Workers/AnalyzeGapWorkerTests.cs b/Tests/WitsmlExplorer.Api.Tests/Workers/AnalyzeGapWorkerTests.cs index 435225eeb..0e6f6e805 100644 --- a/Tests/WitsmlExplorer.Api.Tests/Workers/AnalyzeGapWorkerTests.cs +++ b/Tests/WitsmlExplorer.Api.Tests/Workers/AnalyzeGapWorkerTests.cs @@ -209,8 +209,8 @@ private static WitsmlLogs GetTestWitsmlLogs(WitsmlLogData logData, bool isDepthL UidWell = WellUid, UidWellbore = WellboreUid, Uid = LogUid, - StartIndex = new WitsmlIndex(new DepthIndex(startIndex, "m")), - EndIndex = new WitsmlIndex(new DepthIndex(endIndex, "m")), + StartIndex = new WitsmlIndex(new DepthIndex(startIndex, CommonConstants.Unit.Meter)), + EndIndex = new WitsmlIndex(new DepthIndex(endIndex, CommonConstants.Unit.Meter)), StartDateTimeIndex = startDateTimeIndex, EndDateTimeIndex = endDateTimeIndex, IndexCurve = new WitsmlIndexCurve() { Value = "Depth" }, @@ -222,24 +222,24 @@ private static WitsmlLogs GetTestWitsmlLogs(WitsmlLogData logData, bool isDepthL new WitsmlLogCurveInfo() { Mnemonic = "Depth", - MinIndex = new WitsmlIndex(new DepthIndex(minIndex, "m")), - MaxIndex = new WitsmlIndex(new DepthIndex(maxIndex, "m")), + MinIndex = new WitsmlIndex(new DepthIndex(minIndex, CommonConstants.Unit.Meter)), + MaxIndex = new WitsmlIndex(new DepthIndex(maxIndex, CommonConstants.Unit.Meter)), MinDateTimeIndex = minDateTimeIndex, MaxDateTimeIndex = maxDateTimeIndex, }, new WitsmlLogCurveInfo() { Mnemonic = "BPOS", - MinIndex = new WitsmlIndex(new DepthIndex(minIndex, "m")), - MaxIndex = new WitsmlIndex(new DepthIndex(maxIndex, "m")), + MinIndex = new WitsmlIndex(new DepthIndex(minIndex, CommonConstants.Unit.Meter)), + MaxIndex = new WitsmlIndex(new DepthIndex(maxIndex, CommonConstants.Unit.Meter)), MinDateTimeIndex = minDateTimeIndex, MaxDateTimeIndex = maxDateTimeIndex }, new WitsmlLogCurveInfo() { Mnemonic = "SPM1", - MinIndex = new WitsmlIndex(new DepthIndex(minIndex, "m")), - MaxIndex = new WitsmlIndex(new DepthIndex(maxIndex, "m")), + MinIndex = new WitsmlIndex(new DepthIndex(minIndex, CommonConstants.Unit.Meter)), + MaxIndex = new WitsmlIndex(new DepthIndex(maxIndex, CommonConstants.Unit.Meter)), MinDateTimeIndex = minDateTimeIndex, MaxDateTimeIndex = maxDateTimeIndex }, diff --git a/Tests/WitsmlExplorer.Api.Tests/Workers/CheckLogHeaderWorkerTests.cs b/Tests/WitsmlExplorer.Api.Tests/Workers/CheckLogHeaderWorkerTests.cs index 018dd79dc..3ff9201d7 100644 --- a/Tests/WitsmlExplorer.Api.Tests/Workers/CheckLogHeaderWorkerTests.cs +++ b/Tests/WitsmlExplorer.Api.Tests/Workers/CheckLogHeaderWorkerTests.cs @@ -232,7 +232,7 @@ private static void SetupClient(Mock witsmlClient, string indexTy { if (options.MaxReturnNodes == 1) { - if (logs.Logs[0].LogData.MnemonicList == "") + if (logs.Logs[0].LogData.MnemonicList == string.Empty) { return Task.FromResult(GetTestLogDataFirstRow(indexType)); } diff --git a/Tests/WitsmlExplorer.Api.Tests/Workers/CompareLogDataWorker.Tests.cs b/Tests/WitsmlExplorer.Api.Tests/Workers/CompareLogDataWorker.Tests.cs index a0dbfa76e..2cc35ef6d 100644 --- a/Tests/WitsmlExplorer.Api.Tests/Workers/CompareLogDataWorker.Tests.cs +++ b/Tests/WitsmlExplorer.Api.Tests/Workers/CompareLogDataWorker.Tests.cs @@ -72,7 +72,7 @@ public async Task CompareLogDataWorker_EqualDepthLogs_ReturnsZeroReportItems() IndexType = indexType, StartIndex = "0", EndIndex = "1", - LogCurveInfo = new() { ("IndexCurve", "m"), ("Curve1", "Unit1") }, + LogCurveInfo = new() { ("IndexCurve", CommonConstants.Unit.Meter), ("Curve1", "Unit1") }, Data = new() { "0,0", "1,0" } }; @@ -81,7 +81,7 @@ public async Task CompareLogDataWorker_EqualDepthLogs_ReturnsZeroReportItems() IndexType = indexType, StartIndex = "0", EndIndex = "1", - LogCurveInfo = new() { ("IndexCurve", "m"), ("Curve1", "Unit1") }, + LogCurveInfo = new() { ("IndexCurve", CommonConstants.Unit.Meter), ("Curve1", "Unit1") }, Data = new() { "0,0", "1,0" } }; @@ -136,7 +136,7 @@ public async Task CompareLogDataWorker_MismatchInSharedIndexDepthLogs_ReturnsMis IndexType = indexType, StartIndex = "0", EndIndex = "2", - LogCurveInfo = new() { ("IndexCurve", "m"), ("Curve1", "Unit1") }, + LogCurveInfo = new() { ("IndexCurve", CommonConstants.Unit.Meter), ("Curve1", "Unit1") }, Data = new() { "0,0", "1,0", "2,0" } }; @@ -145,7 +145,7 @@ public async Task CompareLogDataWorker_MismatchInSharedIndexDepthLogs_ReturnsMis IndexType = indexType, StartIndex = "0", EndIndex = "2", - LogCurveInfo = new() { ("IndexCurve", "m"), ("Curve1", "Unit1") }, + LogCurveInfo = new() { ("IndexCurve", CommonConstants.Unit.Meter), ("Curve1", "Unit1") }, Data = new() { "0,0", "1,99", "2,0" } }; @@ -212,7 +212,7 @@ public async Task CompareLogData_DifferentNumberOfMnemonicsDepthLogs_ReturnsMism IndexType = indexType, StartIndex = "0", EndIndex = "1", - LogCurveInfo = new() { ("IndexCurve", "m"), ("Curve1", "Unit1") }, + LogCurveInfo = new() { ("IndexCurve", CommonConstants.Unit.Meter), ("Curve1", "Unit1") }, Data = new() { "0,0", "1,0" } }; @@ -221,7 +221,7 @@ public async Task CompareLogData_DifferentNumberOfMnemonicsDepthLogs_ReturnsMism IndexType = indexType, StartIndex = "0", EndIndex = "1", - LogCurveInfo = new() { ("IndexCurve", "m"), ("Curve1", "Unit1"), ("Curve2", "Unit2") }, + LogCurveInfo = new() { ("IndexCurve", CommonConstants.Unit.Meter), ("Curve1", "Unit1"), ("Curve2", "Unit2") }, Data = new() { "0,0,0", "1,0,0" } }; @@ -300,7 +300,7 @@ public async Task CompareLogData_DifferentIndexRangeDepthLogs_ReturnsMismatchedR IndexType = indexType, StartIndex = "0", EndIndex = "1", - LogCurveInfo = new() { ("IndexCurve", "m"), ("Curve1", "Unit1") }, + LogCurveInfo = new() { ("IndexCurve", CommonConstants.Unit.Meter), ("Curve1", "Unit1") }, Data = new() { "0,0", "1,0" } }; @@ -309,7 +309,7 @@ public async Task CompareLogData_DifferentIndexRangeDepthLogs_ReturnsMismatchedR IndexType = indexType, StartIndex = "0", EndIndex = "2", - LogCurveInfo = new() { ("IndexCurve", "m"), ("Curve1", "Unit1") }, + LogCurveInfo = new() { ("IndexCurve", CommonConstants.Unit.Meter), ("Curve1", "Unit1") }, Data = new() { "0,0", "1,0", "2,0" } }; @@ -376,7 +376,7 @@ public async Task CompareLogDataWorker_MissingDataDepthLogs_ReturnsZeroReportIte IndexType = indexType, StartIndex = "0", EndIndex = "1", - LogCurveInfo = new() { ("IndexCurve", "m"), ("Curve1", "Unit1") }, + LogCurveInfo = new() { ("IndexCurve", CommonConstants.Unit.Meter), ("Curve1", "Unit1") }, Data = new() { "0,0", "1,0" } }; @@ -385,7 +385,7 @@ public async Task CompareLogDataWorker_MissingDataDepthLogs_ReturnsZeroReportIte IndexType = indexType, StartIndex = "0", EndIndex = "1", - LogCurveInfo = new() { ("IndexCurve", "m"), ("Curve1", "Unit1") }, + LogCurveInfo = new() { ("IndexCurve", CommonConstants.Unit.Meter), ("Curve1", "Unit1") }, Data = new() { "0,", "1," } }; @@ -468,7 +468,7 @@ public async Task CompareLogData_UnequalServerDecimalsDepthLogs_ReturnsMismatche IndexType = indexType, StartIndex = "0.01", EndIndex = "0.03", - LogCurveInfo = new() { ("IndexCurve", "m"), ("Curve1", "Unit1") }, + LogCurveInfo = new() { ("IndexCurve", CommonConstants.Unit.Meter), ("Curve1", "Unit1") }, Data = new() { "0.01,11", "0.02,22", "0.03,33" } }; @@ -477,7 +477,7 @@ public async Task CompareLogData_UnequalServerDecimalsDepthLogs_ReturnsMismatche IndexType = indexType, StartIndex = "0.01", EndIndex = "0.03", - LogCurveInfo = new() { ("IndexCurve", "m"), ("Curve1", "Unit1") }, + LogCurveInfo = new() { ("IndexCurve", CommonConstants.Unit.Meter), ("Curve1", "Unit1") }, Data = new() { "0.012,11", "0.016,99", "0.028,33" } }; @@ -507,7 +507,7 @@ public async Task CompareLogData_UnequalServerDecimalsDepthLogsServerDecimalsFli IndexType = indexType, StartIndex = "0.01", EndIndex = "0.03", - LogCurveInfo = new() { ("IndexCurve", "m"), ("Curve1", "Unit1") }, + LogCurveInfo = new() { ("IndexCurve", CommonConstants.Unit.Meter), ("Curve1", "Unit1") }, Data = new() { "0.012,11", "0.016,99", "0.028,33" } }; @@ -516,7 +516,7 @@ public async Task CompareLogData_UnequalServerDecimalsDepthLogsServerDecimalsFli IndexType = indexType, StartIndex = "0.01", EndIndex = "0.03", - LogCurveInfo = new() { ("IndexCurve", "m"), ("Curve1", "Unit1") }, + LogCurveInfo = new() { ("IndexCurve", CommonConstants.Unit.Meter), ("Curve1", "Unit1") }, Data = new() { "0.01,11", "0.02,22", "0.03,33" } }; @@ -548,7 +548,7 @@ public async Task CompareLogData_UnequalServerDecimalsExcludeIndexDuplicatesDept IndexType = indexType, StartIndex = "0.01", EndIndex = "0.01", - LogCurveInfo = new() { ("IndexCurve", "m"), ("Curve1", "Unit1") }, + LogCurveInfo = new() { ("IndexCurve", CommonConstants.Unit.Meter), ("Curve1", "Unit1") }, Data = new() { "0.01,11" } }; @@ -557,7 +557,7 @@ public async Task CompareLogData_UnequalServerDecimalsExcludeIndexDuplicatesDept IndexType = indexType, StartIndex = "0.011", EndIndex = "0.0013", - LogCurveInfo = new() { ("IndexCurve", "m"), ("Curve1", "Unit1") }, + LogCurveInfo = new() { ("IndexCurve", CommonConstants.Unit.Meter), ("Curve1", "Unit1") }, Data = new() { "0.011,11", "0.012,99", "0.013,11" } }; @@ -580,7 +580,7 @@ public async Task CompareLogData_UnequalServerDecimalsIndexIncludeDuplicatesDept IndexType = indexType, StartIndex = "0.01", EndIndex = "0.01", - LogCurveInfo = new() { ("IndexCurve", "m"), ("Curve1", "Unit1") }, + LogCurveInfo = new() { ("IndexCurve", CommonConstants.Unit.Meter), ("Curve1", "Unit1") }, Data = new() { "0.01,11" } }; @@ -589,7 +589,7 @@ public async Task CompareLogData_UnequalServerDecimalsIndexIncludeDuplicatesDept IndexType = indexType, StartIndex = "0.011", EndIndex = "0.0013", - LogCurveInfo = new() { ("IndexCurve", "m"), ("Curve1", "Unit1") }, + LogCurveInfo = new() { ("IndexCurve", CommonConstants.Unit.Meter), ("Curve1", "Unit1") }, Data = new() { "0.011,11", "0.012,99", "0.013,11" } }; @@ -636,7 +636,7 @@ public async Task CompareLogData_UnequalServerDecimalsUnsharedIndexesDepthLogs_R IndexType = indexType, StartIndex = "0.00", EndIndex = "0.02", - LogCurveInfo = new() { ("IndexCurve", "m"), ("Curve1", "Unit1") }, + LogCurveInfo = new() { ("IndexCurve", CommonConstants.Unit.Meter), ("Curve1", "Unit1") }, Data = new() { "0.00,00", "0.01,11", "0.02,22" } }; @@ -645,7 +645,7 @@ public async Task CompareLogData_UnequalServerDecimalsUnsharedIndexesDepthLogs_R IndexType = indexType, StartIndex = "0.010", EndIndex = "0.030", - LogCurveInfo = new() { ("IndexCurve", "m"), ("Curve1", "Unit1") }, + LogCurveInfo = new() { ("IndexCurve", CommonConstants.Unit.Meter), ("Curve1", "Unit1") }, Data = new() { "0.010,11", "0.020,22", "0.030,33" } }; @@ -705,13 +705,13 @@ private void SetupClient(Mock witsmlClient, WitsmlLogs logHeaders string uid = logs.Logs.First().Uid; WitsmlLog log = logData.Logs.Find(l => l.Uid == uid); IEnumerable data = log.LogData.Data.Select(d => d.Data); - string mnemonic = logs.Logs.First().LogData.MnemonicList.Split(',')[1]; - int mnemonicIndex = log.LogData.MnemonicList.Split(',').ToList().FindIndex(m => m == mnemonic); + string mnemonic = logs.Logs.FirstOrDefault()?.LogData.MnemonicList.Split(CommonConstants.DataSeparator)[1]; + int mnemonicIndex = log.LogData.MnemonicList.Split(CommonConstants.DataSeparator).ToList().FindIndex(m => m == mnemonic); List dataForCurve = new List(); foreach (string dataRow in data) { - string index = dataRow.Split(',')[0]; - string mnemonicData = dataRow.Split(',')[mnemonicIndex]; + string index = dataRow.Split(CommonConstants.DataSeparator)[0]; + string mnemonicData = dataRow.Split(CommonConstants.DataSeparator)[mnemonicIndex]; if (!string.IsNullOrEmpty(mnemonicData)) { dataForCurve.Add($"{index},{mnemonicData}"); @@ -758,12 +758,12 @@ private void SetupWorker(int sourceDepthLogDecimals, int targetDepthLogDecimals) private WitsmlLogs CreateSampleLogData(string wellUid, string wellboreUid, string logUid, TestLog log) { - string mnemonicsList = ""; - string unitList = ""; + string mnemonicsList = string.Empty; + string unitList = string.Empty; foreach ((string, string) mnemonic in log.LogCurveInfo) { - mnemonicsList += mnemonic.Item1 + ","; - unitList += mnemonic.Item2 + ","; + mnemonicsList += mnemonic.Item1 + CommonConstants.DataSeparator; + unitList += mnemonic.Item2 + CommonConstants.DataSeparator; } // Remove last "," in mnemonic list and unit list @@ -804,9 +804,9 @@ private WitsmlLogs CreateSampleLogHeaders(string wellUid, string wellboreUid, st UidWellbore = wellboreUid, Direction = WitsmlLog.WITSML_DIRECTION_INCREASING, IndexType = log.IndexType, - StartIndex = isDepthLog ? new WitsmlIndex() { Value = log.StartIndex, Uom = "m" } : null, + StartIndex = isDepthLog ? new WitsmlIndex() { Value = log.StartIndex, Uom = CommonConstants.Unit.Meter } : null, StartDateTimeIndex = isDepthLog ? null : log.StartIndex, - EndIndex = isDepthLog ? new WitsmlIndex() { Value = log.EndIndex, Uom = "m" } : null, + EndIndex = isDepthLog ? new WitsmlIndex() { Value = log.EndIndex, Uom = CommonConstants.Unit.Meter } : null, EndDateTimeIndex = isDepthLog ? null : log.EndIndex, IndexCurve = new WitsmlIndexCurve() { Value = "IndexCurve" }, LogCurveInfo = GetLogCurveInfo(log.IndexType, log.StartIndex, log.EndIndex, log.LogCurveInfo) @@ -817,9 +817,9 @@ private WitsmlLogs CreateSampleLogHeaders(string wellUid, string wellboreUid, st private List GetLogCurveInfo(string indexType, string startIndex, string endIndex, List<(string, string)> logCurveInfo) { var isDepthLog = indexType == WitsmlLog.WITSML_INDEX_TYPE_MD; - var minIndex = isDepthLog ? new WitsmlIndex() { Value = startIndex, Uom = "m" } : null; + var minIndex = isDepthLog ? new WitsmlIndex() { Value = startIndex, Uom = CommonConstants.Unit.Meter } : null; var minDateTimeIndex = isDepthLog ? null : startIndex; - var maxIndex = isDepthLog ? new WitsmlIndex() { Value = endIndex, Uom = "m" } : null; + var maxIndex = isDepthLog ? new WitsmlIndex() { Value = endIndex, Uom = CommonConstants.Unit.Meter } : null; var maxDateTimeIndex = isDepthLog ? null : endIndex; var curveInfo = logCurveInfo.Select(mnemonic => new WitsmlLogCurveInfo { diff --git a/Tests/WitsmlExplorer.Api.Tests/Workers/CopyLogDataWorkerTests.cs b/Tests/WitsmlExplorer.Api.Tests/Workers/CopyLogDataWorkerTests.cs index bfeb8aa13..a95d9330b 100644 --- a/Tests/WitsmlExplorer.Api.Tests/Workers/CopyLogDataWorkerTests.cs +++ b/Tests/WitsmlExplorer.Api.Tests/Workers/CopyLogDataWorkerTests.cs @@ -76,7 +76,7 @@ public async Task CopyLogData_TimeIndexed() await _worker.Execute(job); - Assert.Equal(string.Join(",", SourceMnemonics[WitsmlLog.WITSML_INDEX_TYPE_DATE_TIME]), updatedLogs.First().Logs.First().LogData.MnemonicList); + Assert.Equal(string.Join(CommonConstants.DataSeparator, SourceMnemonics[WitsmlLog.WITSML_INDEX_TYPE_DATE_TIME]), updatedLogs.First().Logs.First().LogData.MnemonicList); Assert.Equal(5, updatedLogs.First().Logs.First().LogData.Data.Count); } @@ -92,7 +92,7 @@ public async Task CopyLogData_DepthIndexed() await _worker.Execute(job); - Assert.Equal(string.Join(",", SourceMnemonics[WitsmlLog.WITSML_INDEX_TYPE_MD]), updatedLogs.First().Logs.First().LogData.MnemonicList); + Assert.Equal(string.Join(CommonConstants.DataSeparator, SourceMnemonics[WitsmlLog.WITSML_INDEX_TYPE_MD]), updatedLogs.First().Logs.First().LogData.MnemonicList); Assert.Equal(5, updatedLogs.First().Logs.First().LogData.Data.Count); } @@ -110,7 +110,7 @@ public async Task CopyLogData_DepthIndexed_Decreasing() await _worker.Execute(job); - Assert.Equal(string.Join(",", SourceMnemonics[WitsmlLog.WITSML_INDEX_TYPE_MD]), updatedLogs.First().Logs.First().LogData.MnemonicList); + Assert.Equal(string.Join(CommonConstants.DataSeparator, SourceMnemonics[WitsmlLog.WITSML_INDEX_TYPE_MD]), updatedLogs.First().Logs.First().LogData.MnemonicList); Assert.Equal(5, updatedLogs.First().Logs.First().LogData.Data.Count); } @@ -136,8 +136,8 @@ public async Task CopyLogData_DepthIndexed_SelectedMnemonics() await _worker.Execute(job); Assert.NotNull(query); - string[] queriedMnemonics = query.Logs.First().LogData.MnemonicList.Split(","); - string[] copiedMnemonics = updatedLogs.Last().Logs.First().LogData.MnemonicList.Split(","); + string[] queriedMnemonics = query.Logs.First().LogData.MnemonicList.Split(CommonConstants.DataSeparator); + string[] copiedMnemonics = updatedLogs.Last().Logs.First().LogData.MnemonicList.Split(CommonConstants.DataSeparator); Assert.Equal(job.Source.ComponentUids, queriedMnemonics); Assert.Equal(job.Source.ComponentUids, copiedMnemonics); } @@ -166,8 +166,8 @@ public async Task CopyLogData_DepthIndexed_AddsIndexMnemonicIfNotIncludedInJob() await _worker.Execute(job); Assert.NotNull(query); - string[] queriedMnemonics = query.Logs.First().LogData.MnemonicList.Split(","); - string[] copiedMnemonics = updatedLogs.Last().Logs.First().LogData.MnemonicList.Split(","); + string[] queriedMnemonics = query.Logs.First().LogData.MnemonicList.Split(CommonConstants.DataSeparator); + string[] copiedMnemonics = updatedLogs.Last().Logs.First().LogData.MnemonicList.Split(CommonConstants.DataSeparator); Assert.Contains(indexMnemonic, queriedMnemonics); Assert.Contains(indexMnemonic, copiedMnemonics); } diff --git a/Tests/WitsmlExplorer.Api.Tests/Workers/CopyLogWorkerTests.cs b/Tests/WitsmlExplorer.Api.Tests/Workers/CopyLogWorkerTests.cs index 6d2b6dbf8..8f8f8031c 100644 --- a/Tests/WitsmlExplorer.Api.Tests/Workers/CopyLogWorkerTests.cs +++ b/Tests/WitsmlExplorer.Api.Tests/Workers/CopyLogWorkerTests.cs @@ -104,7 +104,7 @@ public async Task Execute_ErrorOnCopyLogData_ReasonInWorkingResult() const string errorReason = "test"; CopyTestsUtils.SetupAddInStoreAsync(_witsmlClient); _copyLogDataWorker.Setup(worker => worker.Execute(It.IsAny())) - .ReturnsAsync((new WorkerResult(null, false, "", errorReason), null)); + .ReturnsAsync((new WorkerResult(null, false, string.Empty, errorReason), null)); (WorkerResult Result, RefreshAction) copyTask = await _copyLogWorker.Execute(copyLogJob); diff --git a/Tests/WitsmlExplorer.Api.Tests/Workers/CountLogDataRowWorkerTest.cs b/Tests/WitsmlExplorer.Api.Tests/Workers/CountLogDataRowWorkerTest.cs index 6d80e3b5f..b6e5616ce 100644 --- a/Tests/WitsmlExplorer.Api.Tests/Workers/CountLogDataRowWorkerTest.cs +++ b/Tests/WitsmlExplorer.Api.Tests/Workers/CountLogDataRowWorkerTest.cs @@ -174,8 +174,8 @@ private static WitsmlLogs GetTestWitsmlLogs(WitsmlLogData logData, bool isDepthL UidWell = WellUid, UidWellbore = WellboreUid, Uid = LogUid, - StartIndex = new WitsmlIndex(new DepthIndex(startIndex, "m")), - EndIndex = new WitsmlIndex(new DepthIndex(endIndex, "m")), + StartIndex = new WitsmlIndex(new DepthIndex(startIndex, CommonConstants.Unit.Meter)), + EndIndex = new WitsmlIndex(new DepthIndex(endIndex, CommonConstants.Unit.Meter)), StartDateTimeIndex = startDateTimeIndex, EndDateTimeIndex = endDateTimeIndex, IndexCurve = new WitsmlIndexCurve() { Value = isDepthLog ? IndexCurveDepth : IndexCurveTime }, diff --git a/Tests/WitsmlExplorer.Api.Tests/Workers/CreateLogWorkerTests.cs b/Tests/WitsmlExplorer.Api.Tests/Workers/CreateLogWorkerTests.cs index 6ee8f704b..1be31ff3b 100644 --- a/Tests/WitsmlExplorer.Api.Tests/Workers/CreateLogWorkerTests.cs +++ b/Tests/WitsmlExplorer.Api.Tests/Workers/CreateLogWorkerTests.cs @@ -67,7 +67,7 @@ public async Task CreateDepthIndexedLog_OK() Assert.Equal(WellName, createdLog.NameWell); WitsmlLogCurveInfo indexLogCurve = createdLog.LogCurveInfo.First(); Assert.Equal("Depth", indexLogCurve.Mnemonic); - Assert.Equal("m", indexLogCurve.Unit); + Assert.Equal(CommonConstants.Unit.Meter, indexLogCurve.Unit); } [Fact] @@ -94,7 +94,7 @@ public async Task CreateTimeIndexedLog_OK() Assert.Equal(WellName, createdLog.NameWell); WitsmlLogCurveInfo indexLogCurve = createdLog.LogCurveInfo.First(); Assert.Equal("Time", indexLogCurve.Mnemonic); - Assert.Equal("s", indexLogCurve.Unit); + Assert.Equal(CommonConstants.Unit.Second, indexLogCurve.Unit); } [Fact] @@ -112,7 +112,7 @@ public async Task CreateTimeIndexedLog_UseTimeAsIndexIfUnknown() WitsmlLog createdLog = createdLogs.First().Logs.First(); WitsmlLogCurveInfo indexLogCurve = createdLog.LogCurveInfo.First(); Assert.Equal("Time", indexLogCurve.Mnemonic); - Assert.Equal("s", indexLogCurve.Unit); + Assert.Equal(CommonConstants.Unit.Second, indexLogCurve.Unit); } private static CreateLogJob CreateJobTemplate(string indexCurve = "Depth") diff --git a/Tests/WitsmlExplorer.Api.Tests/Workers/CreateRigWorkerTests.cs b/Tests/WitsmlExplorer.Api.Tests/Workers/CreateRigWorkerTests.cs index dcb38d3e1..7ebdff046 100644 --- a/Tests/WitsmlExplorer.Api.Tests/Workers/CreateRigWorkerTests.cs +++ b/Tests/WitsmlExplorer.Api.Tests/Workers/CreateRigWorkerTests.cs @@ -52,7 +52,7 @@ public async Task CreateRig_Execute_MissingUid_InvalidOperationException() CreateRigJob job = CreateJobTemplate(uid: null); InvalidOperationException exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("Uid cannot be empty", exception.Message); - job = CreateJobTemplate(uid: ""); + job = CreateJobTemplate(uid: string.Empty); exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("Uid cannot be empty", exception.Message); _witsmlClient.Verify(client => client.AddToStoreAsync(It.IsAny()), Times.Never); @@ -64,7 +64,7 @@ public async Task CreateRig_Execute_MissingName_InvalidOperationException() CreateRigJob job = CreateJobTemplate(name: null); InvalidOperationException exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("Name cannot be empty", exception.Message); - job = CreateJobTemplate(name: ""); + job = CreateJobTemplate(name: string.Empty); exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("Name cannot be empty", exception.Message); _witsmlClient.Verify(client => client.AddToStoreAsync(It.IsAny()), Times.Never); diff --git a/Tests/WitsmlExplorer.Api.Tests/Workers/CreateTrajectoryWorkerTests.cs b/Tests/WitsmlExplorer.Api.Tests/Workers/CreateTrajectoryWorkerTests.cs index ffc854d57..e4d044de4 100644 --- a/Tests/WitsmlExplorer.Api.Tests/Workers/CreateTrajectoryWorkerTests.cs +++ b/Tests/WitsmlExplorer.Api.Tests/Workers/CreateTrajectoryWorkerTests.cs @@ -64,7 +64,7 @@ public async Task CreateTrajectory_Execute_MissingName_InvalidOperationException var job = CreateJobTemplate(name: null); InvalidOperationException exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("Name cannot be empty", exception.Message); - job = CreateJobTemplate(name: ""); + job = CreateJobTemplate(name: string.Empty); exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("Name cannot be empty", exception.Message); _witsmlClient.Verify(client => client.AddToStoreAsync(It.IsAny()), Times.Never); diff --git a/Tests/WitsmlExplorer.Api.Tests/Workers/CreateWellWorkerTests.cs b/Tests/WitsmlExplorer.Api.Tests/Workers/CreateWellWorkerTests.cs index 63691e2c4..4c210e904 100644 --- a/Tests/WitsmlExplorer.Api.Tests/Workers/CreateWellWorkerTests.cs +++ b/Tests/WitsmlExplorer.Api.Tests/Workers/CreateWellWorkerTests.cs @@ -51,7 +51,7 @@ public async Task MissingUid_Execute_ThrowsException() CreateWellJob job = CreateJobTemplate(null); InvalidOperationException exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("Uid cannot be empty", exception.Message); - job = CreateJobTemplate(""); + job = CreateJobTemplate(string.Empty); exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("Uid cannot be empty", exception.Message); _witsmlClient.Verify(client => client.AddToStoreAsync(It.IsAny()), Times.Never); @@ -63,7 +63,7 @@ public async Task MissingName_Execute_ThrowsException() CreateWellJob job = CreateJobTemplate(name: null); InvalidOperationException exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("Name cannot be empty", exception.Message); - job = CreateJobTemplate(name: ""); + job = CreateJobTemplate(name: string.Empty); exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("Name cannot be empty", exception.Message); _witsmlClient.Verify(client => client.AddToStoreAsync(It.IsAny()), Times.Never); @@ -75,7 +75,7 @@ public async Task MissingTimeZone_Execute_ThrowsException() CreateWellJob job = CreateJobTemplate(timeZone: null); InvalidOperationException exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("TimeZone cannot be empty", exception.Message); - job = CreateJobTemplate(timeZone: ""); + job = CreateJobTemplate(timeZone: string.Empty); exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("TimeZone cannot be empty", exception.Message); _witsmlClient.Verify(client => client.AddToStoreAsync(It.IsAny()), Times.Never); diff --git a/Tests/WitsmlExplorer.Api.Tests/Workers/CreateWellboreWorkerTests.cs b/Tests/WitsmlExplorer.Api.Tests/Workers/CreateWellboreWorkerTests.cs index 34e013fce..7e1c38f39 100644 --- a/Tests/WitsmlExplorer.Api.Tests/Workers/CreateWellboreWorkerTests.cs +++ b/Tests/WitsmlExplorer.Api.Tests/Workers/CreateWellboreWorkerTests.cs @@ -48,7 +48,7 @@ public async Task MissingUid_Execute_ThrowsException() CreateWellboreJob job = CreateJobTemplate(null); InvalidOperationException exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("Uid cannot be empty", exception.Message); - job = CreateJobTemplate(""); + job = CreateJobTemplate(string.Empty); exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("Uid cannot be empty", exception.Message); _witsmlClient.Verify(client => client.AddToStoreAsync(It.IsAny()), Times.Never); @@ -60,7 +60,7 @@ public async Task MissingName_Execute_ThrowsException() CreateWellboreJob job = CreateJobTemplate(name: null); InvalidOperationException exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("Name cannot be empty", exception.Message); - job = CreateJobTemplate(name: ""); + job = CreateJobTemplate(name: string.Empty); exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("Name cannot be empty", exception.Message); _witsmlClient.Verify(client => client.AddToStoreAsync(It.IsAny()), Times.Never); @@ -72,7 +72,7 @@ public async Task MissingWellUid_Execute_ThrowsException() CreateWellboreJob job = CreateJobTemplate(wellUid: null); InvalidOperationException exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("WellUid cannot be empty", exception.Message); - job = CreateJobTemplate(wellUid: ""); + job = CreateJobTemplate(wellUid: string.Empty); exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("WellUid cannot be empty", exception.Message); _witsmlClient.Verify(client => client.AddToStoreAsync(It.IsAny()), Times.Never); @@ -84,7 +84,7 @@ public async Task MissingWellName_Execute_ThrowsException() CreateWellboreJob job = CreateJobTemplate(wellName: null); InvalidOperationException exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("WellName cannot be empty", exception.Message); - job = CreateJobTemplate(wellName: ""); + job = CreateJobTemplate(wellName: string.Empty); exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("WellName cannot be empty", exception.Message); _witsmlClient.Verify(client => client.AddToStoreAsync(It.IsAny()), Times.Never); diff --git a/Tests/WitsmlExplorer.Api.Tests/Workers/ImportLogDataWorkerTests.cs b/Tests/WitsmlExplorer.Api.Tests/Workers/ImportLogDataWorkerTests.cs index 8779394c2..b0e26b117 100644 --- a/Tests/WitsmlExplorer.Api.Tests/Workers/ImportLogDataWorkerTests.cs +++ b/Tests/WitsmlExplorer.Api.Tests/Workers/ImportLogDataWorkerTests.cs @@ -59,17 +59,17 @@ public async Task ImportDepthLogData() new WitsmlLogCurveInfo { Mnemonic="Depth", - Unit="m" + Unit = CommonConstants.Unit.Meter }, new WitsmlLogCurveInfo { Mnemonic="mnemo1", - Unit="unitless" + Unit = CommonConstants.Unit.Unitless }, new WitsmlLogCurveInfo { Mnemonic="mnemo2", - Unit="unitless" + Unit = CommonConstants.Unit.Unitless } } } @@ -108,12 +108,12 @@ public async Task ImportTimeLogData() new WitsmlLogCurveInfo { Mnemonic="mnemo1", - Unit="unitless" + Unit = CommonConstants.Unit.Unitless }, new WitsmlLogCurveInfo { Mnemonic="mnemo2", - Unit="unitless" + Unit = CommonConstants.Unit.Unitless } } } @@ -144,7 +144,7 @@ public async Task ImportLogDataRequiresExistingLog() private static ImportLogDataJob CreateDepthJobTemplate() { List mnemonics = new() { "Depth", "mnemo1", "mnemo2" }; - List units = new() { "m", "unitless", "unitless" }; + List units = new() { CommonConstants.Unit.Meter, CommonConstants.Unit.Unitless, CommonConstants.Unit.Unitless }; ICollection> dataRows = new List> { new List { "1", "something", "something2" }, @@ -168,7 +168,7 @@ private static ImportLogDataJob CreateDepthJobTemplate() private static ImportLogDataJob CreateTimeJobTemplate() { List mnemonics = new() { "Time", "mnemo1", "mnemo2" }; - List units = new() { "date time", "unitless", "unitless" }; + List units = new() { "date time", CommonConstants.Unit.Unitless, CommonConstants.Unit.Unitless }; ICollection> dataRows = new List> { new List { "2018-01-21T12:24:30.000Z", "something", "something2" }, diff --git a/Tests/WitsmlExplorer.Api.Tests/Workers/LogUtils.cs b/Tests/WitsmlExplorer.Api.Tests/Workers/LogUtils.cs index 4ed119f47..fb0428e58 100644 --- a/Tests/WitsmlExplorer.Api.Tests/Workers/LogUtils.cs +++ b/Tests/WitsmlExplorer.Api.Tests/Workers/LogUtils.cs @@ -243,15 +243,15 @@ public static WitsmlLogs GetTargetLogs(string indexType) { Uid = "Depth", Mnemonic = "Depth", - MinIndex = new WitsmlIndex(new DepthIndex(-999.25)), - MaxIndex = new WitsmlIndex(new DepthIndex(-999.25)) + MinIndex = new WitsmlIndex(new DepthIndex(CommonConstants.DepthIndex.NullValue)), + MaxIndex = new WitsmlIndex(new DepthIndex(CommonConstants.DepthIndex.NullValue)) }, WitsmlLog.WITSML_INDEX_TYPE_DATE_TIME => new WitsmlLogCurveInfo { Uid = "Time", Mnemonic = "Time", - MinDateTimeIndex = "1900-01-01T00:00:00.000Z", - MaxDateTimeIndex = "1900-01-01T00:00:00.000Z" + MinDateTimeIndex = CommonConstants.DateTimeIndex.NullValue, + MaxDateTimeIndex = CommonConstants.DateTimeIndex.NullValue }, _ => null }; @@ -268,12 +268,12 @@ public static WitsmlLogs GetTargetLogs(string indexType) switch (indexType) { case WitsmlLog.WITSML_INDEX_TYPE_MD: - witsmlLog.StartIndex = new WitsmlIndex(new DepthIndex(DepthIndex.NullValue)); - witsmlLog.EndIndex = new WitsmlIndex(new DepthIndex(DepthIndex.NullValue)); + witsmlLog.StartIndex = new WitsmlIndex(new DepthIndex(CommonConstants.DepthIndex.NullValue)); + witsmlLog.EndIndex = new WitsmlIndex(new DepthIndex(CommonConstants.DepthIndex.NullValue)); break; case WitsmlLog.WITSML_INDEX_TYPE_DATE_TIME: - witsmlLog.StartDateTimeIndex = DateTimeIndex.NullValue; - witsmlLog.EndDateTimeIndex = DateTimeIndex.NullValue; + witsmlLog.StartDateTimeIndex = CommonConstants.DateTimeIndex.NullValue; + witsmlLog.EndDateTimeIndex = CommonConstants.DateTimeIndex.NullValue; break; default: break; @@ -401,8 +401,8 @@ public static void SetupGetDepthIndexed(Mock witsmlClient, Func { - new() { Uid = "Depth", Mnemonic = "Depth", Unit = "m" }, - new() { Uid = "Mnemonic1", Mnemonic = "Mnemonic1", Unit = "m" }, - new() { Uid = "Mnemonic2", Mnemonic = "Mnemonic2", Unit = "ft" } + new() { Uid = "Depth", Mnemonic = "Depth", Unit = CommonConstants.Unit.Meter }, + new() { Uid = "Mnemonic1", Mnemonic = "Mnemonic1", Unit = CommonConstants.Unit.Meter }, + new() { Uid = "Mnemonic2", Mnemonic = "Mnemonic2", Unit = CommonConstants.Unit.Feet } } } } diff --git a/Tests/WitsmlExplorer.Api.Tests/Workers/ModifyLogObjectWorkerTests.cs b/Tests/WitsmlExplorer.Api.Tests/Workers/ModifyLogObjectWorkerTests.cs index 2527c2b30..81be7b1a8 100644 --- a/Tests/WitsmlExplorer.Api.Tests/Workers/ModifyLogObjectWorkerTests.cs +++ b/Tests/WitsmlExplorer.Api.Tests/Workers/ModifyLogObjectWorkerTests.cs @@ -61,7 +61,7 @@ public async Task RenameLogObject() public async Task RenameLogObject_EmptyName_ThrowsException() { ModifyObjectOnWellboreJob job = CreateJobTemplate(); - job.Object.Name = ""; + job.Object.Name = string.Empty; var (workerResult, _) = await _worker.Execute(job); diff --git a/Tests/WitsmlExplorer.Api.Tests/Workers/ModifyTrajectoryWorkerTests.cs b/Tests/WitsmlExplorer.Api.Tests/Workers/ModifyTrajectoryWorkerTests.cs index 6fc84704d..86a0832a6 100644 --- a/Tests/WitsmlExplorer.Api.Tests/Workers/ModifyTrajectoryWorkerTests.cs +++ b/Tests/WitsmlExplorer.Api.Tests/Workers/ModifyTrajectoryWorkerTests.cs @@ -63,7 +63,7 @@ public async Task ModifyTrajectory_ValidResults() public async Task RenameTrajectory_EmptyName_ThrowsException() { var expectedMessage = "Name cannot be empty"; - ModifyObjectOnWellboreJob job = CreateJobTemplate(TrajectoryUid, ""); + ModifyObjectOnWellboreJob job = CreateJobTemplate(TrajectoryUid, string.Empty); var (workerResult, _) = await _worker.Execute(job); diff --git a/Tests/WitsmlExplorer.Api.Tests/Workers/ModifyTubularComponentWorkerTests.cs b/Tests/WitsmlExplorer.Api.Tests/Workers/ModifyTubularComponentWorkerTests.cs index b64d6c547..6dc55dd99 100644 --- a/Tests/WitsmlExplorer.Api.Tests/Workers/ModifyTubularComponentWorkerTests.cs +++ b/Tests/WitsmlExplorer.Api.Tests/Workers/ModifyTubularComponentWorkerTests.cs @@ -45,7 +45,7 @@ public async Task Update_Id() { const int expectedValue = 10; ModifyTubularComponentJob job = CreateJobTemplate(); - job.TubularComponent.Id = new Measure.LengthMeasure { Value = expectedValue, Uom = "ft" }; + job.TubularComponent.Id = new Measure.LengthMeasure { Value = expectedValue, Uom = CommonConstants.Unit.Feet }; List updatedTubulars = await MockJob(job); WitsmlLengthMeasure id = updatedTubulars.First().Tubulars.First().TubularComponents.First().Id; decimal actual = decimal.Parse(id.Value); @@ -58,7 +58,7 @@ public async Task Update_Od() { const int expectedValue = 10; ModifyTubularComponentJob job = CreateJobTemplate(); - job.TubularComponent.Od = new Measure.LengthMeasure { Value = expectedValue, Uom = "ft" }; + job.TubularComponent.Od = new Measure.LengthMeasure { Value = expectedValue, Uom = CommonConstants.Unit.Feet }; List updatedTubulars = await MockJob(job); WitsmlLengthMeasure od = updatedTubulars.First().Tubulars.First().TubularComponents.First().Od; decimal actual = decimal.Parse(od.Value); @@ -71,7 +71,7 @@ public async Task Update_Len() { const int expectedValue = 10; ModifyTubularComponentJob job = CreateJobTemplate(); - job.TubularComponent.Len = new Measure.LengthMeasure { Value = expectedValue, Uom = "ft" }; + job.TubularComponent.Len = new Measure.LengthMeasure { Value = expectedValue, Uom = CommonConstants.Unit.Feet }; List updatedTubulars = await MockJob(job); WitsmlLengthMeasure len = updatedTubulars.First().Tubulars.First().TubularComponents.First().Len; decimal actual = decimal.Parse(len.Value); diff --git a/Tests/WitsmlExplorer.Api.Tests/Workers/ModifyTubularWorkerTests.cs b/Tests/WitsmlExplorer.Api.Tests/Workers/ModifyTubularWorkerTests.cs index fcf208517..37c101e4c 100644 --- a/Tests/WitsmlExplorer.Api.Tests/Workers/ModifyTubularWorkerTests.cs +++ b/Tests/WitsmlExplorer.Api.Tests/Workers/ModifyTubularWorkerTests.cs @@ -61,7 +61,7 @@ public async Task RenameTubular() [Fact] public async Task RenameTubular_EmptyName_ThrowsException() { - ModifyObjectOnWellboreJob job = CreateJobTemplate(TubularUid, ""); + ModifyObjectOnWellboreJob job = CreateJobTemplate(TubularUid, string.Empty); var (workerResult, _) = await _worker.Execute(job); diff --git a/Tests/WitsmlExplorer.Api.Tests/Workers/ModifyWellWorkerTests.cs b/Tests/WitsmlExplorer.Api.Tests/Workers/ModifyWellWorkerTests.cs index cede34947..586015079 100644 --- a/Tests/WitsmlExplorer.Api.Tests/Workers/ModifyWellWorkerTests.cs +++ b/Tests/WitsmlExplorer.Api.Tests/Workers/ModifyWellWorkerTests.cs @@ -58,7 +58,7 @@ public async Task RenameWell() [Fact] public async Task RenameWell_EmptyName_ThrowsException() { - ModifyWellJob job = CreateJobTemplate(WellUid, ""); + ModifyWellJob job = CreateJobTemplate(WellUid, string.Empty); InvalidOperationException exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("Name cannot be empty", exception.Message); diff --git a/Tests/WitsmlExplorer.Api.Tests/Workers/ModifyWellboreWorkerTests.cs b/Tests/WitsmlExplorer.Api.Tests/Workers/ModifyWellboreWorkerTests.cs index 7a3264b2c..e09477af8 100644 --- a/Tests/WitsmlExplorer.Api.Tests/Workers/ModifyWellboreWorkerTests.cs +++ b/Tests/WitsmlExplorer.Api.Tests/Workers/ModifyWellboreWorkerTests.cs @@ -63,7 +63,7 @@ public async Task RenameWellbore() public async Task RenameWellbore_EmptyName_ThrowsException() { ModifyWellboreJob job = CreateJobTemplate(); - job.Wellbore.Name = ""; + job.Wellbore.Name = string.Empty; InvalidOperationException exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("Name cannot be empty", exception.Message); @@ -76,7 +76,7 @@ public async Task Update_Md() { const int expectedValue = 10; ModifyWellboreJob job = CreateJobTemplate(); - job.Wellbore.Md = new Measure.LengthMeasure { Value = expectedValue, Uom = "ft" }; + job.Wellbore.Md = new Measure.LengthMeasure { Value = expectedValue, Uom = CommonConstants.Unit.Feet }; List updatedWellbores = new(); _witsmlClient.Setup(client => @@ -95,7 +95,7 @@ public async Task Update_Md() public async Task Update_Md_ThrowsException() { ModifyWellboreJob job = CreateJobTemplate(); - job.Wellbore.Md = new Measure.LengthMeasure { Value = 10, Uom = "" }; + job.Wellbore.Md = new Measure.LengthMeasure { Value = 10, Uom = string.Empty }; InvalidOperationException exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("unit of measure for Md cannot be empty", exception.Message); @@ -108,7 +108,7 @@ public async Task Update_Tvd() { const int expectedValue = 20; ModifyWellboreJob job = CreateJobTemplate(); - job.Wellbore.Tvd = new Measure.LengthMeasure { Value = expectedValue, Uom = "ft" }; + job.Wellbore.Tvd = new Measure.LengthMeasure { Value = expectedValue, Uom = CommonConstants.Unit.Feet }; List updatedWellbores = new(); _witsmlClient.Setup(client => @@ -127,7 +127,7 @@ public async Task Update_Tvd() public async Task Update_Tvd_ThrowsException() { ModifyWellboreJob job = CreateJobTemplate(); - job.Wellbore.Tvd = new Measure.LengthMeasure { Value = 10, Uom = "" }; + job.Wellbore.Tvd = new Measure.LengthMeasure { Value = 10, Uom = string.Empty }; InvalidOperationException exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("unit of measure for Tvd cannot be empty", exception.Message); @@ -140,7 +140,7 @@ public async Task Update_MdKickoff() { const int expectedValue = 10; ModifyWellboreJob job = CreateJobTemplate(); - job.Wellbore.MdKickoff = new Measure.LengthMeasure { Value = expectedValue, Uom = "ft" }; + job.Wellbore.MdKickoff = new Measure.LengthMeasure { Value = expectedValue, Uom = CommonConstants.Unit.Feet }; List updatedWellbores = new(); _witsmlClient.Setup(client => @@ -159,7 +159,7 @@ public async Task Update_MdKickoff() public async Task Update_MdKickoff_ThrowsException() { ModifyWellboreJob job = CreateJobTemplate(); - job.Wellbore.MdKickoff = new Measure.LengthMeasure { Value = 10, Uom = "" }; + job.Wellbore.MdKickoff = new Measure.LengthMeasure { Value = 10, Uom = string.Empty }; InvalidOperationException exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("unit of measure for MdKickoff cannot be empty", exception.Message); @@ -172,7 +172,7 @@ public async Task Update_TvdKickoff() { const int expectedValue = 20; ModifyWellboreJob job = CreateJobTemplate(); - job.Wellbore.TvdKickoff = new Measure.LengthMeasure { Value = expectedValue, Uom = "ft" }; + job.Wellbore.TvdKickoff = new Measure.LengthMeasure { Value = expectedValue, Uom = CommonConstants.Unit.Feet }; List updatedWellbores = new(); _witsmlClient.Setup(client => @@ -191,7 +191,7 @@ public async Task Update_TvdKickoff() public async Task Update_TvdKickoff_ThrowsException() { ModifyWellboreJob job = CreateJobTemplate(); - job.Wellbore.TvdKickoff = new Measure.LengthMeasure { Value = 10, Uom = "" }; + job.Wellbore.TvdKickoff = new Measure.LengthMeasure { Value = 10, Uom = string.Empty }; InvalidOperationException exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("unit of measure for TvdKickoff cannot be empty", exception.Message); @@ -204,7 +204,7 @@ public async Task Update_MdPlanned() { const int expectedValue = 10; ModifyWellboreJob job = CreateJobTemplate(); - job.Wellbore.MdPlanned = new Measure.LengthMeasure { Value = expectedValue, Uom = "ft" }; + job.Wellbore.MdPlanned = new Measure.LengthMeasure { Value = expectedValue, Uom = CommonConstants.Unit.Feet }; List updatedWellbores = new(); _witsmlClient.Setup(client => @@ -223,7 +223,7 @@ public async Task Update_MdPlanned() public async Task Update_MdPlanned_ThrowsException() { ModifyWellboreJob job = CreateJobTemplate(); - job.Wellbore.MdPlanned = new Measure.LengthMeasure { Value = 10, Uom = "" }; + job.Wellbore.MdPlanned = new Measure.LengthMeasure { Value = 10, Uom = string.Empty }; InvalidOperationException exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("unit of measure for MdPlanned cannot be empty", exception.Message); @@ -236,7 +236,7 @@ public async Task Update_TvdPlanned() { const int expectedValue = 20; ModifyWellboreJob job = CreateJobTemplate(); - job.Wellbore.TvdPlanned = new Measure.LengthMeasure { Value = expectedValue, Uom = "ft" }; + job.Wellbore.TvdPlanned = new Measure.LengthMeasure { Value = expectedValue, Uom = CommonConstants.Unit.Feet }; List updatedWellbores = new(); _witsmlClient.Setup(client => @@ -255,7 +255,7 @@ public async Task Update_TvdPlanned() public async Task Update_TvdPlanned_ThrowsException() { ModifyWellboreJob job = CreateJobTemplate(); - job.Wellbore.TvdPlanned = new Measure.LengthMeasure { Value = 10, Uom = "" }; + job.Wellbore.TvdPlanned = new Measure.LengthMeasure { Value = 10, Uom = string.Empty }; InvalidOperationException exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("unit of measure for TvdPlanned cannot be empty", exception.Message); @@ -268,7 +268,7 @@ public async Task Update_MdSubSeaPlanned() { const int expectedValue = 10; ModifyWellboreJob job = CreateJobTemplate(); - job.Wellbore.MdSubSeaPlanned = new Measure.LengthMeasure { Value = expectedValue, Uom = "ft" }; + job.Wellbore.MdSubSeaPlanned = new Measure.LengthMeasure { Value = expectedValue, Uom = CommonConstants.Unit.Feet }; List updatedWellbores = new(); _witsmlClient.Setup(client => @@ -287,7 +287,7 @@ public async Task Update_MdSubSeaPlanned() public async Task Update_MdSubSeaPlanned_ThrowsException() { ModifyWellboreJob job = CreateJobTemplate(); - job.Wellbore.MdSubSeaPlanned = new Measure.LengthMeasure { Value = 10, Uom = "" }; + job.Wellbore.MdSubSeaPlanned = new Measure.LengthMeasure { Value = 10, Uom = string.Empty }; InvalidOperationException exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("unit of measure for MdSubSeaPlanned cannot be empty", exception.Message); @@ -300,7 +300,7 @@ public async Task Update_TvdSubSeaPlanned() { const int expectedValue = 20; ModifyWellboreJob job = CreateJobTemplate(); - job.Wellbore.TvdSubSeaPlanned = new Measure.LengthMeasure { Value = expectedValue, Uom = "ft" }; + job.Wellbore.TvdSubSeaPlanned = new Measure.LengthMeasure { Value = expectedValue, Uom = CommonConstants.Unit.Feet }; List updatedWellbores = new(); _witsmlClient.Setup(client => @@ -319,7 +319,7 @@ public async Task Update_TvdSubSeaPlanned() public async Task Update_TvdSubSeaPlanned_ThrowsException() { ModifyWellboreJob job = CreateJobTemplate(); - job.Wellbore.TvdSubSeaPlanned = new Measure.LengthMeasure { Value = 10, Uom = "" }; + job.Wellbore.TvdSubSeaPlanned = new Measure.LengthMeasure { Value = 10, Uom = string.Empty }; InvalidOperationException exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("unit of measure for TvdSubSeaPlanned cannot be empty", exception.Message); @@ -351,7 +351,7 @@ public async Task Update_DayTarget() public async Task Update_DayTarget_ThrowsException() { ModifyWellboreJob job = CreateJobTemplate(); - job.Wellbore.DayTarget = new Measure.DayMeasure { Value = 10, Uom = "" }; + job.Wellbore.DayTarget = new Measure.DayMeasure { Value = 10, Uom = string.Empty }; InvalidOperationException exception = await Assert.ThrowsAsync(() => _worker.Execute(job)); Assert.Equal("unit of measure for DayTarget cannot be empty", exception.Message); diff --git a/Tests/WitsmlExplorer.Api.Tests/Workers/SpliceLogsWorkerTests.cs b/Tests/WitsmlExplorer.Api.Tests/Workers/SpliceLogsWorkerTests.cs index 7dacc187f..f5dda8109 100644 --- a/Tests/WitsmlExplorer.Api.Tests/Workers/SpliceLogsWorkerTests.cs +++ b/Tests/WitsmlExplorer.Api.Tests/Workers/SpliceLogsWorkerTests.cs @@ -104,8 +104,8 @@ public async Task Execute_OnlyOverlap_KeepsFirst(string indexType) WitsmlLogData newLogData = newLogDataHeader.LogData; IEnumerable newLogHeaderMnemonics = newLogHeader.LogCurveInfo.Select(lci => lci.Mnemonic); IEnumerable newLogHeaderUnits = newLogHeader.LogCurveInfo.Select(lci => lci.Unit); - IEnumerable newLogDataMnemonics = newLogData.MnemonicList.Split(','); - IEnumerable newLogDataUnits = newLogData.UnitList.Split(','); + IEnumerable newLogDataMnemonics = newLogData.MnemonicList.Split(CommonConstants.DataSeparator); + IEnumerable newLogDataUnits = newLogData.UnitList.Split(CommonConstants.DataSeparator); IEnumerable expectedData = logData.Logs.First().LogData.Data.Select(d => d.Data); IEnumerable newLogDataData = newLogData.Data.Select(d => d.Data); @@ -139,8 +139,8 @@ public async Task Execute_NoOverlap_KeepsBoth(string indexType) WitsmlLogData newLogData = newLogDataHeader.LogData; IEnumerable newLogHeaderMnemonics = newLogHeader.LogCurveInfo.Select(lci => lci.Mnemonic); IEnumerable newLogHeaderUnits = newLogHeader.LogCurveInfo.Select(lci => lci.Unit); - IEnumerable newLogDataMnemonics = newLogData.MnemonicList.Split(','); - IEnumerable newLogDataUnits = newLogData.UnitList.Split(','); + IEnumerable newLogDataMnemonics = newLogData.MnemonicList.Split(CommonConstants.DataSeparator); + IEnumerable newLogDataUnits = newLogData.UnitList.Split(CommonConstants.DataSeparator); IEnumerable expectedDataFirst5Rows = logData.Logs.First().LogData.Data.Select(d => d.Data); IEnumerable expectedDataLast5Rows = logData.Logs.Last().LogData.Data.Select(d => d.Data); IEnumerable newLogDataData = newLogData.Data.Select(d => d.Data); @@ -176,8 +176,8 @@ public async Task Execute_SomeOverlap_KeepsFirstOnOverlap(string indexType) WitsmlLogData newLogData = newLogDataHeader.LogData; IEnumerable newLogHeaderMnemonics = newLogHeader.LogCurveInfo.Select(lci => lci.Mnemonic); IEnumerable newLogHeaderUnits = newLogHeader.LogCurveInfo.Select(lci => lci.Unit); - IEnumerable newLogDataMnemonics = newLogData.MnemonicList.Split(','); - IEnumerable newLogDataUnits = newLogData.UnitList.Split(','); + IEnumerable newLogDataMnemonics = newLogData.MnemonicList.Split(CommonConstants.DataSeparator); + IEnumerable newLogDataUnits = newLogData.UnitList.Split(CommonConstants.DataSeparator); IEnumerable expectedDataFirst10Rows = logData.Logs.First().LogData.Data.Select(d => d.Data); IEnumerable expectedDataLast5Rows = logData.Logs.Last().LogData.Data.Select(d => d.Data).TakeLast(5); IEnumerable newLogDataData = newLogData.Data.Select(d => d.Data); @@ -213,8 +213,8 @@ public async Task Execute_ManyLogs_NoOverlap_KeepsFirstAll(string indexType) WitsmlLogData newLogData = newLogDataHeader.LogData; IEnumerable newLogHeaderMnemonics = newLogHeader.LogCurveInfo.Select(lci => lci.Mnemonic); IEnumerable newLogHeaderUnits = newLogHeader.LogCurveInfo.Select(lci => lci.Unit); - IEnumerable newLogDataMnemonics = newLogData.MnemonicList.Split(','); - IEnumerable newLogDataUnits = newLogData.UnitList.Split(','); + IEnumerable newLogDataMnemonics = newLogData.MnemonicList.Split(CommonConstants.DataSeparator); + IEnumerable newLogDataUnits = newLogData.UnitList.Split(CommonConstants.DataSeparator); IEnumerable newLogDataData = newLogData.Data.Select(d => d.Data); Assert.Equal(expectedMnemonics, newLogHeaderMnemonics); @@ -241,9 +241,9 @@ public async Task Execute_SomeCurvesOverlap_KeepsFirstCurveOnOverlap(string inde var (job, logHeaders, logData) = SetupTest(logUids, indexType, startIndexNum, endIndexNum, (log) => capturedLogHeader = log, (log) => capturedLogData = log); - var data = logData.Logs.First().LogData.Data.Last().Data.Split(','); - data[1] = ""; - logData.Logs.First().LogData.Data.Last().Data = string.Join(',', data); + var data = logData.Logs.First().LogData.Data.Last().Data.Split(CommonConstants.DataSeparator); + data[1] = string.Empty; + logData.Logs.First().LogData.Data.Last().Data = string.Join(CommonConstants.DataSeparator, data); var expectedMnemonics = logHeaders.Logs.First().LogCurveInfo.Select(lci => lci.Mnemonic); var expectedUnits = logHeaders.Logs.First().LogCurveInfo.Select(lci => lci.Unit); @@ -255,15 +255,15 @@ public async Task Execute_SomeCurvesOverlap_KeepsFirstCurveOnOverlap(string inde WitsmlLogData newLogData = newLogDataHeader.LogData; IEnumerable newLogHeaderMnemonics = newLogHeader.LogCurveInfo.Select(lci => lci.Mnemonic); IEnumerable newLogHeaderUnits = newLogHeader.LogCurveInfo.Select(lci => lci.Unit); - IEnumerable newLogDataMnemonics = newLogData.MnemonicList.Split(','); - IEnumerable newLogDataUnits = newLogData.UnitList.Split(','); + IEnumerable newLogDataMnemonics = newLogData.MnemonicList.Split(CommonConstants.DataSeparator); + IEnumerable newLogDataUnits = newLogData.UnitList.Split(CommonConstants.DataSeparator); IEnumerable expectedDataFirst8Rows = logData.Logs.First().LogData.Data.Select(d => d.Data).Take(8); IEnumerable expectedDataLast5Rows = logData.Logs.Last().LogData.Data.Select(d => d.Data).TakeLast(5); IEnumerable newLogDataData = newLogData.Data.Select(d => d.Data); - var log1Value = logData.Logs.First().LogData.Data.Select(d => d.Data).ToArray().Last().Split(','); - var log2Value = logData.Logs.Last().LogData.Data.Select(d => d.Data).ToArray().First().Split(','); + var log1Value = logData.Logs.First().LogData.Data.Select(d => d.Data).ToArray().Last().Split(CommonConstants.DataSeparator); + var log2Value = logData.Logs.Last().LogData.Data.Select(d => d.Data).ToArray().First().Split(CommonConstants.DataSeparator); log1Value[1] = log2Value[1]; - string expectedDataRow10 = string.Join(',', log1Value); + string expectedDataRow10 = string.Join(CommonConstants.DataSeparator, log1Value); Assert.Equal(expectedMnemonics, newLogHeaderMnemonics); Assert.Equal(expectedUnits, newLogHeaderUnits); @@ -292,9 +292,9 @@ public async Task Execute_NewCurve_AddsNewCurve(string indexType) { Mnemonic = "ExtraCurve", Unit = "Unit3", - MinIndex = isDepthLog ? new WitsmlIndex() { Value = "0", Uom = "m" } : null, + MinIndex = isDepthLog ? new WitsmlIndex() { Value = "0", Uom = CommonConstants.Unit.Meter } : null, MinDateTimeIndex = isDepthLog ? null : _baseDateTime.ToISODateTimeString(), - MaxIndex = isDepthLog ? new WitsmlIndex() { Value = "10", Uom = "m" } : null, + MaxIndex = isDepthLog ? new WitsmlIndex() { Value = "10", Uom = CommonConstants.Unit.Meter } : null, MaxDateTimeIndex = isDepthLog ? null : _baseDateTime.AddMinutes(10).ToISODateTimeString() }); @@ -315,12 +315,12 @@ public async Task Execute_NewCurve_AddsNewCurve(string indexType) WitsmlLogData newLogData = newLogDataHeader.LogData; IEnumerable newLogHeaderMnemonics = newLogHeader.LogCurveInfo.Select(lci => lci.Mnemonic); IEnumerable newLogHeaderUnits = newLogHeader.LogCurveInfo.Select(lci => lci.Unit); - IEnumerable newLogDataMnemonics = newLogData.MnemonicList.Split(','); - IEnumerable newLogDataUnits = newLogData.UnitList.Split(','); + IEnumerable newLogDataMnemonics = newLogData.MnemonicList.Split(CommonConstants.DataSeparator); + IEnumerable newLogDataUnits = newLogData.UnitList.Split(CommonConstants.DataSeparator); IEnumerable expectedDataExceptLastMnemonic = logData.Logs.First().LogData.Data.Select(d => d.Data); - IEnumerable expectedDataLastMnemonic = logData.Logs.Last().LogData.Data.Select(d => d.Data.Split(',').Last()); - IEnumerable newLogDataWithoutLastMnemonic = newLogData.Data.Select(d => string.Join(',', d.Data.Split(',').SkipLast(1))); - IEnumerable newLogDataLastMnemonic = newLogData.Data.Select(d => d.Data.Split(',').Last()); + IEnumerable expectedDataLastMnemonic = logData.Logs.Last().LogData.Data.Select(d => d.Data.Split(CommonConstants.DataSeparator).Last()); + IEnumerable newLogDataWithoutLastMnemonic = newLogData.Data.Select(d => string.Join(CommonConstants.DataSeparator, d.Data.Split(CommonConstants.DataSeparator).SkipLast(1))); + IEnumerable newLogDataLastMnemonic = newLogData.Data.Select(d => d.Data.Split(CommonConstants.DataSeparator).Last()); Assert.Equal(expectedMnemonics, newLogHeaderMnemonics); Assert.Equal(expectedUnits, newLogHeaderUnits); @@ -381,7 +381,7 @@ public async Task Execute_DifferentIndexCurveNames_HasCorrectHeader(string index // When Log Curve Info varies between logs, the Log Curve Info of the last log is prioritized. Assert.Equal("IndexCurve2", newLogHeader.IndexCurve.Value); Assert.Equal("IndexCurve2", newLogHeader.LogCurveInfo.First().Mnemonic); - Assert.Equal("IndexCurve2", newLogDataHeader.LogData.MnemonicList.Split(',')[0]); + Assert.Equal("IndexCurve2", newLogDataHeader.LogData.MnemonicList.Split(CommonConstants.DataSeparator)[0]); } private (SpliceLogsJob, WitsmlLogs, WitsmlLogs) SetupTest(string[] logUids, string indexType, int[] startIndexNum, int[] endIndexNum, Action logHeaderCallback, Action logDataCallback, string[] indexCurves = null) @@ -424,9 +424,9 @@ private WitsmlLogs CreateSampleLogHeaders(string[] logUids, string indexType, in UidWellbore = _wellboreUid, Direction = WitsmlLog.WITSML_DIRECTION_INCREASING, IndexType = indexType, - StartIndex = isDepthLog ? new WitsmlIndex() { Value = startIndexNum[i].ToString(), Uom = "m" } : null, + StartIndex = isDepthLog ? new WitsmlIndex() { Value = startIndexNum[i].ToString(), Uom = CommonConstants.Unit.Meter } : null, StartDateTimeIndex = isDepthLog ? null : _baseDateTime.AddMinutes(startIndexNum[i]).ToISODateTimeString(), - EndIndex = isDepthLog ? new WitsmlIndex() { Value = (endIndexNum[i]).ToString(), Uom = "m" } : null, + EndIndex = isDepthLog ? new WitsmlIndex() { Value = (endIndexNum[i]).ToString(), Uom = CommonConstants.Unit.Meter } : null, EndDateTimeIndex = isDepthLog ? null : _baseDateTime.AddMinutes(endIndexNum[i]).ToISODateTimeString(), IndexCurve = new WitsmlIndexCurve() { Value = indexCurves != null ? indexCurves[i] : "IndexCurve" }, LogCurveInfo = GetLogCurveInfo(logUids, uid, indexType, startIndexNum, endIndexNum, indexCurves) @@ -467,16 +467,16 @@ private List GetLogCurveInfo(string[] logUids, string uid, s { var uidNum = logUids.ToList().FindIndex(i => i == uid); var isDepthLog = indexType == WitsmlLog.WITSML_INDEX_TYPE_MD; - var minIndex = isDepthLog ? new WitsmlIndex() { Value = startIndexNum[uidNum].ToString(), Uom = "m" } : null; + var minIndex = isDepthLog ? new WitsmlIndex() { Value = startIndexNum[uidNum].ToString(), Uom = CommonConstants.Unit.Meter } : null; var minDateTimeIndex = isDepthLog ? null : _baseDateTime.AddMinutes(startIndexNum[uidNum]).ToISODateTimeString(); - var maxIndex = isDepthLog ? new WitsmlIndex() { Value = (endIndexNum[uidNum]).ToString(), Uom = "m" } : null; + var maxIndex = isDepthLog ? new WitsmlIndex() { Value = (endIndexNum[uidNum]).ToString(), Uom = CommonConstants.Unit.Meter } : null; var maxDateTimeIndex = isDepthLog ? null : _baseDateTime.AddMinutes(endIndexNum[uidNum]).ToISODateTimeString(); return new() { new WitsmlLogCurveInfo { Mnemonic = indexCurves != null ? indexCurves[uidNum] : "IndexCurve", - Unit = isDepthLog ? "m" : "DateTime", + Unit = isDepthLog ? CommonConstants.Unit.Meter : "DateTime", MinIndex = minIndex, MinDateTimeIndex = minDateTimeIndex, MaxIndex = maxIndex, @@ -524,9 +524,9 @@ private void SetupClient(Mock witsmlClient, WitsmlLogs logHeaders string uid = logs.Logs.First().Uid; WitsmlLog log = logData.Logs.Find(l => l.Uid == uid); IEnumerable data = log.LogData.Data.Select(d => d.Data); - string mnemonic = logs.Logs.First().LogData.MnemonicList.Split(',')[1]; - int mnemonicIndex = log.LogData.MnemonicList.Split(',').ToList().FindIndex(m => m == mnemonic); - IEnumerable dataForCurve = data.Select(dataRow => $"{dataRow.Split(',')[0]},{dataRow.Split(',')[mnemonicIndex]}"); + string mnemonic = logs.Logs.First().LogData.MnemonicList.Split(CommonConstants.DataSeparator)[1]; + int mnemonicIndex = log.LogData.MnemonicList.Split(CommonConstants.DataSeparator).ToList().FindIndex(m => m == mnemonic); + IEnumerable dataForCurve = data.Select(dataRow => $"{dataRow.Split(CommonConstants.DataSeparator)[0]},{dataRow.Split(CommonConstants.DataSeparator)[mnemonicIndex]}"); WitsmlLogs newLogData = new() { Logs = new WitsmlLog() diff --git a/Tests/WitsmlExplorer.IntegrationTests/Api/Workers/CopyLogWorkerTests.cs b/Tests/WitsmlExplorer.IntegrationTests/Api/Workers/CopyLogWorkerTests.cs index be0417a8d..a0843ccb6 100644 --- a/Tests/WitsmlExplorer.IntegrationTests/Api/Workers/CopyLogWorkerTests.cs +++ b/Tests/WitsmlExplorer.IntegrationTests/Api/Workers/CopyLogWorkerTests.cs @@ -118,10 +118,10 @@ await _deleteLogsWorker.Execute( { LogData sourceLogData = await _logObjectService.ReadLogData(sourceReference.WellUid, sourceReference.WellboreUid, logUid, - new List(sourceLog.LogData.MnemonicList.Split(",")), currentIndex.Equals(Index.Start(sourceLog)), + new List(sourceLog.LogData.MnemonicList.Split(CommonConstants.DataSeparator)), currentIndex.Equals(Index.Start(sourceLog)), currentIndex.GetValueAsString(), endIndex.ToString()); LogData targetLogData = await _logObjectService.ReadLogData(targetReference.WellUid, targetReference.WellboreUid, logUid, - new List(targetLog.LogData.MnemonicList.Split(",")), currentIndex.Equals(Index.Start(targetLog)), + new List(targetLog.LogData.MnemonicList.Split(CommonConstants.DataSeparator)), currentIndex.Equals(Index.Start(targetLog)), currentIndex.GetValueAsString(), endIndex.ToString()); Assert.Equal(sourceLogData.EndIndex, targetLogData.EndIndex); From bfe35990aa98c2b0835b0240969066622ac26c71 Mon Sep 17 00:00:00 2001 From: jaroslavbliznak Date: Wed, 13 Dec 2023 08:31:58 +0100 Subject: [PATCH 2/2] FIX-2045 Rename constants --- Src/Witsml/CommonConstants.cs | 4 ++-- Src/Witsml/WitsmlClient.cs | 2 +- Src/Witsml/WitsmlClientOptions.cs | 2 +- Src/WitsmlExplorer.Api/Extensions/BuilderExtensions.cs | 2 +- Src/WitsmlExplorer.Api/Services/WitsmlClientProvider.cs | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Src/Witsml/CommonConstants.cs b/Src/Witsml/CommonConstants.cs index 7eb93c2ea..615ddc1dd 100644 --- a/Src/Witsml/CommonConstants.cs +++ b/Src/Witsml/CommonConstants.cs @@ -9,8 +9,8 @@ public static class CommonConstants public const string DataSeparator = ","; public const string PropertySeparator = "."; public const string NewLine = "\n"; - public const int DefaultClientRequestTimeOut = 90; - public const int DefaultReloadInterval = 15; + public const int DefaultClientRequestTimeOutSeconds = 90; + public const int DefaultReloadIntervalMinutes = 15; public static class DepthIndex { diff --git a/Src/Witsml/WitsmlClient.cs b/Src/Witsml/WitsmlClient.cs index e4c50bc66..aac505f51 100644 --- a/Src/Witsml/WitsmlClient.cs +++ b/Src/Witsml/WitsmlClient.cs @@ -46,7 +46,7 @@ public WitsmlClient(string hostname, string username, string password, WitsmlCli options.Hostname = hostname; options.Credentials = new WitsmlCredentials(username, password); options.ClientCapabilities = clientCapabilities; - options.RequestTimeOut = requestTimeout ?? TimeSpan.FromSeconds(CommonConstants.DefaultClientRequestTimeOut); + options.RequestTimeOut = requestTimeout ?? TimeSpan.FromSeconds(CommonConstants.DefaultClientRequestTimeOutSeconds); options.LogQueries = logQueries; }) { } diff --git a/Src/Witsml/WitsmlClientOptions.cs b/Src/Witsml/WitsmlClientOptions.cs index 76cb8b46f..ce9b4fbe3 100644 --- a/Src/Witsml/WitsmlClientOptions.cs +++ b/Src/Witsml/WitsmlClientOptions.cs @@ -31,7 +31,7 @@ public class WitsmlClientOptions /// /// The timeout interval to be used when communicating with the WITSML server. Default is 00:01:00 minutes /// - public TimeSpan RequestTimeOut { get; set; } = TimeSpan.FromSeconds(CommonConstants.DefaultClientRequestTimeOut); + public TimeSpan RequestTimeOut { get; set; } = TimeSpan.FromSeconds(CommonConstants.DefaultClientRequestTimeOutSeconds); /// /// Enable logging all queries to a file (queries.log) in the current directory diff --git a/Src/WitsmlExplorer.Api/Extensions/BuilderExtensions.cs b/Src/WitsmlExplorer.Api/Extensions/BuilderExtensions.cs index bb4c0e05e..8ab0c4bc7 100644 --- a/Src/WitsmlExplorer.Api/Extensions/BuilderExtensions.cs +++ b/Src/WitsmlExplorer.Api/Extensions/BuilderExtensions.cs @@ -26,7 +26,7 @@ public static IConfigurationBuilder AddAzureWitsmlServerCreds(this Configuration new DefaultAzureCredential(), new AzureKeyVaultConfigurationOptions() { - ReloadInterval = TimeSpan.FromMinutes(CommonConstants.DefaultReloadInterval) + ReloadInterval = TimeSpan.FromMinutes(CommonConstants.DefaultReloadIntervalMinutes) }); } return configuration; diff --git a/Src/WitsmlExplorer.Api/Services/WitsmlClientProvider.cs b/Src/WitsmlExplorer.Api/Services/WitsmlClientProvider.cs index 8b233d571..548262534 100644 --- a/Src/WitsmlExplorer.Api/Services/WitsmlClientProvider.cs +++ b/Src/WitsmlExplorer.Api/Services/WitsmlClientProvider.cs @@ -79,7 +79,7 @@ public IWitsmlClient GetClient() options.Credentials = new WitsmlCredentials(_targetCreds.UserId, _targetCreds.Password); options.ClientCapabilities = _clientCapabilities; options.LogQueries = _logQueries; - options.RequestTimeOut = TimeSpan.FromSeconds(CommonConstants.DefaultClientRequestTimeOut); + options.RequestTimeOut = TimeSpan.FromSeconds(CommonConstants.DefaultClientRequestTimeOutSeconds); }) : null; } @@ -98,7 +98,7 @@ public IWitsmlClient GetSourceClient() options.Credentials = new WitsmlCredentials(_sourceCreds.UserId, _sourceCreds.Password); options.ClientCapabilities = _clientCapabilities; options.LogQueries = _logQueries; - options.RequestTimeOut = TimeSpan.FromSeconds(CommonConstants.DefaultClientRequestTimeOut); + options.RequestTimeOut = TimeSpan.FromSeconds(CommonConstants.DefaultClientRequestTimeOutSeconds); }) : null; }