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;
|
||||||
}
|
}
|
||||||
|
|
||||||
//**************************************************************************************************//
|
//**************************************************************************************************//
|
||||||
|
|||||||
@@ -15,6 +15,15 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
|
|
||||||
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>
|
||||||
///
|
///
|
||||||
@@ -34,7 +65,8 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
{
|
{
|
||||||
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)
|
||||||
@@ -53,6 +109,7 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
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);
|
var token = Master.JsonObject.SelectToken(PathPrefix);
|
||||||
if (token is JArray)
|
if (token is JArray)
|
||||||
{
|
{
|
||||||
@@ -75,6 +132,7 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
|
|
||||||
this.LinkedToObject = true;
|
this.LinkedToObject = true;
|
||||||
ArrayIndex = array.IndexOf(item);
|
ArrayIndex = array.IndexOf(item);
|
||||||
|
OnStringChange(string.Format("{0}[{1}]", PathPrefix, ArrayIndex), 0, JsonToSimplConstants.FullPathToArrayChange);
|
||||||
Debug.Console(1, "JSON Child[{0}] Found array match at index {1}", Key, ArrayIndex);
|
Debug.Console(1, "JSON Child[{0}] Found array match at index {1}", Key, ArrayIndex);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -85,7 +143,9 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
Debug.Console(1, "JSON Child[{0}] Path '{1}' is not an array", Key, PathPrefix);
|
Debug.Console(1, "JSON Child[{0}] Path '{1}' is not an array", Key, PathPrefix);
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,11 +106,11 @@ 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>
|
||||||
/// Called from the child to add changed or new values for saving
|
/// Called from the child to add changed or new values for saving
|
||||||
|
|||||||
@@ -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