-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Looping in range testing and option to show only changes
- Loading branch information
Showing
6 changed files
with
288 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
namespace DCSInsight.JSON | ||
{ | ||
[Serializable] | ||
public class DCSAPI | ||
{ | ||
/// <summary> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.IO; | ||
using Newtonsoft.Json; | ||
|
||
namespace DCSInsight.Misc | ||
{ | ||
using TextBox = System.Windows.Controls.TextBox; | ||
|
||
public static class Extensions | ||
{ | ||
/// <summary> | ||
/// Perform a deep Copy of the object, using Json as a serialization method. NOTE: Private members are not cloned using this method. | ||
/// </summary> | ||
/// <typeparam name="T">The type of object being copied.</typeparam> | ||
/// <param name="source">The object instance to copy.</param> | ||
/// <returns>The copied object.</returns> | ||
public static T CloneJson<T>(this T source) | ||
{ | ||
//Note to devs: Use Newtonsoft.Json to clone the object, not System.Text.Json; because there are a lot of Newtonsoft.Json [JsonIgnore] attributes that are ignored | ||
//by the System.Text.Json serializer. This could lead to recursive serialization of unwanted properties that raises an exception. | ||
|
||
if (!typeof(T).IsSerializable) | ||
{ | ||
throw new ArgumentException($"DeepClone error. The type must be serializable"); | ||
} | ||
|
||
//Following line fixes "Could not create an instance of type xxx Type is an interface or abstract class and cannot be instantiated." | ||
//when deep cloning IKeyPressInfo from AddKeySequence(string description, SortedList<int, IKeyPressInfo> keySequence) | ||
var settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto }; | ||
|
||
var jsonString = JsonConvert.SerializeObject(source, settings); | ||
return JsonConvert.DeserializeObject<T>(jsonString, settings); | ||
} | ||
|
||
/// <summary> | ||
/// US Culture used. Decimal separator is '.' | ||
/// </summary> | ||
public static bool ValidateDouble(this TextBox textBox) | ||
{ | ||
if (string.IsNullOrEmpty(textBox.Text)) | ||
{ | ||
return true; | ||
} | ||
|
||
return double.TryParse(textBox.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out _); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Text; | ||
using DCSInsight.JSON; | ||
|
||
namespace DCSInsight.Misc | ||
{ | ||
internal class ResultComparator | ||
{ | ||
private readonly DCSAPI _dcsApi; | ||
private bool _resultHasChanged; | ||
private object _lockObject = new(); | ||
|
||
public ResultComparator(DCSAPI dcsApi) | ||
{ | ||
_dcsApi = dcsApi; | ||
_dcsApi.Result = int.MinValue.ToString(); // Set so that first value will be listed in the results. | ||
} | ||
|
||
public bool IsMatch(DCSAPI dcsApi) | ||
{ | ||
try | ||
{ | ||
lock (_lockObject) | ||
{ | ||
if (dcsApi.Parameters.Count != _dcsApi.Parameters.Count) return false; | ||
|
||
for (var i = 0; i < _dcsApi.ParamCount; i++) | ||
{ | ||
if (_dcsApi.Parameters[i].Value != dcsApi.Parameters[i].Value) | ||
{ | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Common.ShowErrorMessageBox(ex); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/// <summary> | ||
/// Returns true if result is different since previous check | ||
/// </summary> | ||
/// <param name="dcsApi"></param> | ||
/// <returns></returns> | ||
public bool SetResult(DCSAPI dcsApi) | ||
{ | ||
try | ||
{ | ||
lock (_lockObject) | ||
{ | ||
if (!IsMatch(dcsApi)) | ||
{ | ||
throw new Exception("SetResult() : This is not the matching DCSAPI."); | ||
} | ||
|
||
if (dcsApi.Result != _dcsApi.Result) | ||
{ | ||
_dcsApi.Result = dcsApi.Result; | ||
_resultHasChanged = true; | ||
return true; | ||
} | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Common.ShowErrorMessageBox(ex); | ||
} | ||
|
||
_resultHasChanged = false; | ||
return false; | ||
} | ||
|
||
public string GetResultString() | ||
{ | ||
lock (_lockObject) | ||
{ | ||
var currentTestString = new StringBuilder(); | ||
|
||
foreach (var dcsApiParameter in _dcsApi.Parameters) | ||
{ | ||
currentTestString.Append($"{dcsApiParameter.ParameterName} [{dcsApiParameter.Value}], "); | ||
} | ||
|
||
currentTestString.Append($" result : {_dcsApi.Result}\n"); | ||
|
||
return currentTestString.ToString(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.