mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-02-16 05:04:48 +00:00
Merged in feature/json2.4.1 (pull request #15)
Feature/json2.4.1 Approved-by: Neil Dorin <ndorin@pepperdash.com>
This commit is contained in:
@@ -13,6 +13,7 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
public const ushort BoolValueChange = 1;
|
public const ushort BoolValueChange = 1;
|
||||||
public const ushort UshortValueChange = 101;
|
public const ushort UshortValueChange = 101;
|
||||||
public const ushort StringValueChange = 201;
|
public const ushort StringValueChange = 201;
|
||||||
|
public const ushort FullPathToArrayChange = 202;
|
||||||
}
|
}
|
||||||
|
|
||||||
//**************************************************************************************************//
|
//**************************************************************************************************//
|
||||||
|
|||||||
@@ -11,10 +11,19 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
public class JsonToSimplArrayLookupChild : JsonToSimplChildObjectBase
|
public class JsonToSimplArrayLookupChild : JsonToSimplChildObjectBase
|
||||||
{
|
{
|
||||||
public string SearchPropertyName { get; set; }
|
public string SearchPropertyName { get; set; }
|
||||||
public string SearchPropertyValue { get; set; }
|
public string SearchPropertyValue { get; set; }
|
||||||
|
|
||||||
int ArrayIndex;
|
int ArrayIndex;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// For <2.4.1 array lookups
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="file"></param>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="pathPrefix"></param>
|
||||||
|
/// <param name="pathSuffix"></param>
|
||||||
|
/// <param name="searchPropertyName"></param>
|
||||||
|
/// <param name="searchPropertyValue"></param>
|
||||||
public void Initialize(string file, string key, string pathPrefix, string pathSuffix,
|
public void Initialize(string file, string key, string pathPrefix, string pathSuffix,
|
||||||
string searchPropertyName, string searchPropertyValue)
|
string searchPropertyName, string searchPropertyValue)
|
||||||
{
|
{
|
||||||
@@ -24,6 +33,28 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// For newer >=2.4.1 array lookups.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="file"></param>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="pathPrefix"></param>
|
||||||
|
/// <param name="pathAppend"></param>
|
||||||
|
/// <param name="pathSuffix"></param>
|
||||||
|
/// <param name="searchPropertyName"></param>
|
||||||
|
/// <param name="searchPropertyValue"></param>
|
||||||
|
public void InitializeWithAppend(string file, string key, string pathPrefix, string pathAppend,
|
||||||
|
string pathSuffix, string searchPropertyName, string searchPropertyValue)
|
||||||
|
{
|
||||||
|
string pathPrefixWithAppend = (pathPrefix != null ? pathPrefix : "") + GetPathAppend(pathAppend);
|
||||||
|
base.Initialize(file, key, pathPrefixWithAppend, pathSuffix);
|
||||||
|
|
||||||
|
SearchPropertyName = searchPropertyName;
|
||||||
|
SearchPropertyValue = searchPropertyValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//PathPrefix+ArrayName+[x]+path+PathSuffix
|
//PathPrefix+ArrayName+[x]+path+PathSuffix
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@@ -32,9 +63,10 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
protected override string GetFullPath(string path)
|
protected override string GetFullPath(string path)
|
||||||
{
|
{
|
||||||
return string.Format("{0}[{1}].{2}{3}",
|
return string.Format("{0}[{1}].{2}{3}",
|
||||||
PathPrefix == null ? "" : PathPrefix,
|
PathPrefix == null ? "" : PathPrefix,
|
||||||
ArrayIndex, path,
|
ArrayIndex,
|
||||||
|
path,
|
||||||
PathSuffix == null ? "" : PathSuffix);
|
PathSuffix == null ? "" : PathSuffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,6 +76,30 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
base.ProcessAll();
|
base.ProcessAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provides the path append for GetFullPath
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
string GetPathAppend(string a)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(a))
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
if (a.StartsWith("."))
|
||||||
|
{
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return "." + a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
bool FindInArray()
|
bool FindInArray()
|
||||||
{
|
{
|
||||||
if (Master == null)
|
if (Master == null)
|
||||||
@@ -51,41 +107,45 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
if (Master.JsonObject == null)
|
if (Master.JsonObject == null)
|
||||||
throw new InvalidOperationException("Cannot do operations before master JSON has read");
|
throw new InvalidOperationException("Cannot do operations before master JSON has read");
|
||||||
if (PathPrefix == null)
|
if (PathPrefix == null)
|
||||||
throw new InvalidOperationException("Cannot do operations before PathPrefix is set");
|
throw new InvalidOperationException("Cannot do operations before PathPrefix is set");
|
||||||
|
|
||||||
var token = Master.JsonObject.SelectToken(PathPrefix);
|
|
||||||
if (token is JArray)
|
var token = Master.JsonObject.SelectToken(PathPrefix);
|
||||||
{
|
if (token is JArray)
|
||||||
var array = token as JArray;
|
{
|
||||||
try
|
var array = token as JArray;
|
||||||
{
|
try
|
||||||
var item = array.FirstOrDefault(o =>
|
{
|
||||||
{
|
var item = array.FirstOrDefault(o =>
|
||||||
var prop = o[SearchPropertyName];
|
{
|
||||||
return prop != null && prop.Value<string>()
|
var prop = o[SearchPropertyName];
|
||||||
.Equals(SearchPropertyValue, StringComparison.OrdinalIgnoreCase);
|
return prop != null && prop.Value<string>()
|
||||||
});
|
.Equals(SearchPropertyValue, StringComparison.OrdinalIgnoreCase);
|
||||||
if (item == null)
|
});
|
||||||
{
|
if (item == null)
|
||||||
Debug.Console(1, "JSON Child[{0}] Array '{1}' '{2}={3}' not found: ", Key,
|
{
|
||||||
PathPrefix, SearchPropertyName, SearchPropertyValue);
|
Debug.Console(1, "JSON Child[{0}] Array '{1}' '{2}={3}' not found: ", Key,
|
||||||
this.LinkedToObject = false;
|
PathPrefix, SearchPropertyName, SearchPropertyValue);
|
||||||
return false;
|
this.LinkedToObject = false;
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
this.LinkedToObject = true;
|
|
||||||
ArrayIndex = array.IndexOf(item);
|
this.LinkedToObject = true;
|
||||||
Debug.Console(1, "JSON Child[{0}] Found array match at index {1}", Key, ArrayIndex);
|
ArrayIndex = array.IndexOf(item);
|
||||||
return true;
|
OnStringChange(string.Format("{0}[{1}]", PathPrefix, ArrayIndex), 0, JsonToSimplConstants.FullPathToArrayChange);
|
||||||
}
|
Debug.Console(1, "JSON Child[{0}] Found array match at index {1}", Key, ArrayIndex);
|
||||||
catch (Exception e)
|
return true;
|
||||||
{
|
}
|
||||||
Debug.Console(1, "JSON Child[{0}] Array '{1}' lookup error: '{2}={3}'\r{4}", Key,
|
catch (Exception e)
|
||||||
PathPrefix, SearchPropertyName, SearchPropertyValue, e);
|
{
|
||||||
}
|
Debug.Console(1, "JSON Child[{0}] Array '{1}' lookup error: '{2}={3}'\r{4}", Key,
|
||||||
|
PathPrefix, SearchPropertyName, SearchPropertyValue, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Console(1, "JSON Child[{0}] Path '{1}' is not an array", Key, PathPrefix);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
Debug.Console(1, "JSON Child[{0}] Path '{1}' is not an array", Key, PathPrefix);
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
/// This will be prepended to all paths to allow path swapping or for more organized
|
/// This will be prepended to all paths to allow path swapping or for more organized
|
||||||
/// sub-paths
|
/// sub-paths
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string PathPrefix { get; protected set; }
|
public string PathPrefix { get; protected set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is added to the end of all paths
|
/// This is added to the end of all paths
|
||||||
@@ -285,7 +285,7 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
protected virtual string GetFullPath(string path)
|
protected virtual string GetFullPath(string path)
|
||||||
{
|
{
|
||||||
return (PathPrefix != null ? PathPrefix : "") +
|
return (PathPrefix != null ? PathPrefix : "") +
|
||||||
path + (PathSuffix != null ? PathSuffix : "");
|
path + (PathSuffix != null ? PathSuffix : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helpers for events
|
// Helpers for events
|
||||||
|
|||||||
@@ -106,10 +106,10 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
/// <param name="child"></param>
|
/// <param name="child"></param>
|
||||||
public void AddChild(JsonToSimplChildObjectBase child)
|
public void AddChild(JsonToSimplChildObjectBase child)
|
||||||
{
|
{
|
||||||
if (Children.Contains(child)) {
|
if (!Children.Contains(child))
|
||||||
Children.Remove(child);
|
{
|
||||||
}
|
Children.Add(child);
|
||||||
Children.Add(child);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -4,4 +4,4 @@
|
|||||||
[assembly: AssemblyCompany("")]
|
[assembly: AssemblyCompany("")]
|
||||||
[assembly: AssemblyProduct("Pepperdash_Core")]
|
[assembly: AssemblyProduct("Pepperdash_Core")]
|
||||||
[assembly: AssemblyCopyright("Copyright © PepperDash 2019")]
|
[assembly: AssemblyCopyright("Copyright © PepperDash 2019")]
|
||||||
[assembly: AssemblyVersion("1.0.20.*")]
|
[assembly: AssemblyVersion("1.0.21.*")]
|
||||||
|
|||||||
Reference in New Issue
Block a user