diff --git a/examples/Windows Inventory/inventory.ps1 b/examples/Windows Inventory/inventory.ps1 index 3af1604..818dd2d 100644 --- a/examples/Windows Inventory/inventory.ps1 +++ b/examples/Windows Inventory/inventory.ps1 @@ -196,7 +196,7 @@ getinv -Name "Printer" -WMIClass "Win32_Printer" -Properties @("DeviceID","Capab $user = Get-LocalUser | Select-Object Description, Enabled, UserMayChangePassword, PasswordRequired, Name, @{N = '@PasswordLastSet'; E = {[System.DateTime](($_.PasswordLastSet).ToUniversalTime())}}, @{N = 'id'; E = {$_.SID}} | Sort-Object -Property Name $object | Add-Member -MemberType NoteProperty -Name "LocalUsers" -Value ($user) -$locAdmin = Get-LocalGroupMember -SID S-1-5-32-544 | Select-Object @{N = 'Name'; E = {$_.Name.Replace($($env:Computername) + "\", "")}}, PrincipalSource, ObjectClass | Sort-Object -Property Name +$locAdmin = Get-LocalGroupMember -SID S-1-5-32-544 | Select-Object @{N = 'Name'; E = {$_.Name.Replace($($env:Computername) + "\", "")}}, ObjectClass, @{Name = 'id'; Expression = {$_.SID.Value}} | Sort-Object -Property Name $object | Add-Member -MemberType NoteProperty -Name "LocalAdmins" -Value ($locAdmin) $locGroup = Get-LocalGroup | Select-Object Description, Name, PrincipalSource, ObjectClass, @{N = 'id'; E = {$_.SID}} | Sort-Object -Property Name diff --git a/source/JainDBTest/JainDBTest.csproj b/source/JainDBTest/JainDBTest.csproj index 800ff74..b08b5c9 100644 --- a/source/JainDBTest/JainDBTest.csproj +++ b/source/JainDBTest/JainDBTest.csproj @@ -1,7 +1,7 @@ - netcoreapp2.0 + netcoreapp2.1 false @@ -11,7 +11,7 @@ - + diff --git a/source/JainDBTest/UnitTest1.cs b/source/JainDBTest/UnitTest1.cs index 4356a9f..59e4832 100644 --- a/source/JainDBTest/UnitTest1.cs +++ b/source/JainDBTest/UnitTest1.cs @@ -72,7 +72,7 @@ public void Test_Query() { Console.WriteLine("Query data..."); jDB.UseFileStore = true; - int i = jDB.Query("obj1", "", "").Count(); + int i = jDB.QueryAsync("obj1", "", "", "").Result.Count(); Assert.IsTrue(i > 0); } diff --git a/source/jaindb/Controllers/HomeController.cs b/source/jaindb/Controllers/HomeController.cs index f7f0ea8..a46c9b1 100644 --- a/source/jaindb/Controllers/HomeController.cs +++ b/source/jaindb/Controllers/HomeController.cs @@ -291,7 +291,7 @@ public JArray Query() //string sUri = Microsoft.AspNetCore.Http.Extensions.UriHelper.GetDisplayUrl(Request); var query = QueryHelpers.ParseQuery(sQuery); - return jDB.Query(string.Join(";", query.Where(t => string.IsNullOrEmpty(t.Value)).Select(t => t.Key).ToList()), query.FirstOrDefault(t => t.Key.ToLower() == "$select").Value, query.FirstOrDefault(t => t.Key.ToLower() == "$exclude").Value, query.FirstOrDefault(t => t.Key.ToLower() == "$where").Value); + return jDB.QueryAsync(string.Join(";", query.Where(t => string.IsNullOrEmpty(t.Value)).Select(t => t.Key).ToList()), query.FirstOrDefault(t => t.Key.ToLower() == "$select").Value, query.FirstOrDefault(t => t.Key.ToLower() == "$exclude").Value, query.FirstOrDefault(t => t.Key.ToLower() == "$where").Value).Result; } return null; } diff --git a/source/jaindb/Dockerfile b/source/jaindb/Dockerfile index b3c8eef..feec308 100644 --- a/source/jaindb/Dockerfile +++ b/source/jaindb/Dockerfile @@ -1,4 +1,4 @@ -FROM microsoft/aspnetcore +FROM microsoft/dotnet:2.1-aspnetcore-runtime ARG source WORKDIR /app EXPOSE 5000:5000/tcp @@ -13,7 +13,7 @@ RUN rm -f -r /app/wwwroot/bin #RUN apt-get install -y make gcc wget #RUN apt-get install -y --no-install-recommends ca-certificates #RUN mkdir -p /app/wwwroot/redis -#RUN wget -O redis.tar.gz http://download.redis.io/releases/redis-4.0.11.tar.gz +#RUN wget -O redis.tar.gz http://download.redis.io/releases/redis-5.0.0.tar.gz #RUN tar -xzf redis.tar.gz -C /app/wwwroot/redis --strip-components=1 #RUN grep -q '^#define CONFIG_DEFAULT_PROTECTED_MODE 1$' /app/wwwroot/redis/src/server.h @@ -31,7 +31,7 @@ RUN rm -f -r /app/wwwroot/bin #RUN cp /app/wwwroot/redis/src/redis-cli /app/wwwroot/bin #RUN cp /app/wwwroot/redis/src/redis-sentinel /app/wwwroot/bin #RUN cp /app/wwwroot/redis/src/redis-server /app/wwwroot/bin -#RUN rm -r /app/wwwroot/redis +##RUN rm -r /app/wwwroot/redis ENV localURL "http://localhost" diff --git a/source/jaindb/JainDB_Logo.ico b/source/jaindb/JainDB_Logo.ico new file mode 100644 index 0000000..9d41976 Binary files /dev/null and b/source/jaindb/JainDB_Logo.ico differ diff --git a/source/jaindb/jaindb.cs b/source/jaindb/jaindb.cs index 1c28988..e774814 100644 --- a/source/jaindb/jaindb.cs +++ b/source/jaindb/jaindb.cs @@ -53,6 +53,7 @@ public enum hashType { MD5, SHA2_256 } //Implemented Hash types public static bool UseCosmosDB; public static bool UseRedis; public static bool UseFileStore; + public static string FilePath = "wwwroot"; public static bool UseRethinkDB; internal static string databaseId; @@ -106,7 +107,7 @@ public static string LookupID(string name, string value) try { //Check in MemoryCache - if (_cache.TryGetValue("ID-" + name + value, out sResult)) + if (_cache.TryGetValue("ID-" + name.ToLower() + value.ToLower(), out sResult)) { return sResult; } @@ -120,7 +121,7 @@ public static string LookupID(string name, string value) if (!string.IsNullOrEmpty(sResult)) { var cacheEntryOptions = new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromSeconds(60)); //cache ID for 1min - _cache.Set("ID-" + name + value, sResult, cacheEntryOptions); + _cache.Set("ID-" + name.ToLower() + value.ToLower(), sResult, cacheEntryOptions); } return sResult; @@ -129,13 +130,13 @@ public static string LookupID(string name, string value) if (UseFileStore || UseCosmosDB) { - sResult = File.ReadAllText("wwwroot\\" + "_Key" + "\\" + name.TrimStart('#', '@') + "\\" + value + ".json"); + sResult = File.ReadAllText(Path.Combine(FilePath, "_Key" + "\\" + name.TrimStart('#', '@') + "\\" + value + ".json")); //Cache result in Memory if (!string.IsNullOrEmpty(sResult)) { var cacheEntryOptions = new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromSeconds(300)); //cache ID for 5min - _cache.Set("ID-" + name + value, sResult, cacheEntryOptions); + _cache.Set("ID-" + name.ToLower() + value.ToLower(), sResult, cacheEntryOptions); } return sResult; @@ -171,7 +172,7 @@ public static void WriteHash(ref JToken oRoot, ref JObject oStatic, string Colle { ((JObject)oClass).Add("##hash", sHash); if (!UseCosmosDB) - WriteHashAsync(sHash, oRoot.ToString(Formatting.None), Collection); + WriteHashAsync(sHash, oRoot.ToString(Formatting.None), Collection).ConfigureAwait(false); else { //No need to save hashes when using CosmosDB @@ -391,8 +392,9 @@ public static bool WriteHash(string Hash, string Data, string Collection) Hash = Hash.Replace(sChar.ToString(), ""); } - if (!Directory.Exists("wwwroot\\" + Collection)) - Directory.CreateDirectory("wwwroot\\" + Collection); + string sCol = Path.Combine(FilePath, Collection); + if (!Directory.Exists(sCol)) + Directory.CreateDirectory(sCol); switch (Collection.ToLower()) { @@ -403,8 +405,8 @@ public static bool WriteHash(string Hash, string Data, string Collection) string sID = jObj["#id"].ToString(); - if (!Directory.Exists("wwwroot\\" + "_Key")) - Directory.CreateDirectory("wwwroot\\" + "_Key"); + if (!Directory.Exists(Path.Combine(FilePath, "_Key"))) + Directory.CreateDirectory(Path.Combine(FilePath, "_Key")); //Store KeyNames foreach (JProperty oSub in jObj.Properties()) @@ -419,7 +421,7 @@ public static bool WriteHash(string Hash, string Data, string Collection) { if (oSubSub.ToString() != sID) { - string sDir = "wwwroot\\" + "_Key" + "\\" + oSub.Name.ToLower().TrimStart('#'); + string sDir = Path.Combine(FilePath, "_Key" + "\\" + oSub.Name.ToLower().TrimStart('#')); //Remove invalid Characters in Path foreach (var sChar in Path.GetInvalidPathChars()) @@ -445,7 +447,7 @@ public static bool WriteHash(string Hash, string Data, string Collection) { try { - string sDir = "wwwroot\\" + "_Key" + "\\" + oSub.Name.ToLower().TrimStart('#'); + string sDir = Path.Combine(FilePath, "_Key" + "\\" + oSub.Name.ToLower().TrimStart('#')); //Remove invalid Characters in Path foreach (var sChar in Path.GetInvalidPathChars()) @@ -467,23 +469,23 @@ public static bool WriteHash(string Hash, string Data, string Collection) lock (locker) //only one write operation { - File.WriteAllText("wwwroot\\" + Collection + "\\" + Hash + ".json", Data); + File.WriteAllText(Path.Combine(FilePath, Collection + "\\" + Hash + ".json"), Data); } break; case "chain": lock (locker) //only one write operation { - File.WriteAllText("wwwroot\\" + Collection + "\\" + Hash + ".json", Data); + File.WriteAllText(Path.Combine(FilePath, Collection + "\\" + Hash + ".json"), Data); } break; default: - if (!File.Exists("wwwroot\\" + Collection + "\\" + Hash + ".json")) //We do not have to create the same hash file twice... + if (!File.Exists(Path.Combine(FilePath, Collection + "\\" + Hash + ".json"))) //We do not have to create the same hash file twice... { lock (locker) //only one write operation { - File.WriteAllText("wwwroot\\" + Collection + "\\" + Hash + ".json", Data); + File.WriteAllText(Path.Combine(FilePath, Collection + "\\" + Hash + ".json"), Data); } } break; @@ -494,14 +496,14 @@ public static bool WriteHash(string Hash, string Data, string Collection) } catch (Exception ex) { - if (!Directory.Exists("wwwroot\\" + Collection)) - Directory.CreateDirectory("wwwroot\\" + Collection); + if (!Directory.Exists(Path.Combine(FilePath, Collection))) + Directory.CreateDirectory(Path.Combine(FilePath, Collection)); - if (!File.Exists("wwwroot\\" + Collection + "\\" + Hash + ".json")) //We do not have to create the same hash file twice... + if (!File.Exists(Path.Combine(FilePath, Collection + "\\" + Hash + ".json"))) //We do not have to create the same hash file twice... { lock (locker) //only one write operation { - File.WriteAllText("wwwroot\\" + Collection + "\\" + Hash + ".json", Data); + File.WriteAllText(Path.Combine(FilePath, Collection + "\\" + Hash + ".json"), Data); } } @@ -556,10 +558,10 @@ public static string ReadHash(string Hash, string Collection) case "_full": return cache0.StringGet(Hash); - case "chain": + case "_chain": return cache3.StringGet(Hash); - case "assets": + case "_assets": return cache4.StringGet(Hash); default: @@ -624,11 +626,11 @@ public static string ReadHash(string Hash, string Collection) Hash = Hash.Replace(sChar.ToString(), ""); } - sResult = File.ReadAllText("wwwroot\\" + Coll2 + "\\" + Hash + ".json"); + sResult = File.ReadAllText(Path.Combine(FilePath, Coll2 + "\\" + Hash + ".json")); #if DEBUG //Check if hashes are valid... - if (Collection.ToLower() != "_full" && Collection.ToLower() != "chain") + if (Collection.ToLower() != "_full" && Collection.ToLower() != "_chain" && Collection.ToLower() != "_assets") { var jData = JObject.Parse(sResult); /*if (jData["#id"] != null) @@ -701,7 +703,7 @@ public static string ReadHash(string Hash, string Collection) public static Blockchain GetChain(string DeviceID) { Blockchain oChain; - string sData = ReadHash(DeviceID, "Chain"); + string sData = ReadHash(DeviceID, "_Chain"); if (string.IsNullOrEmpty(sData)) { oChain = new Blockchain("", "root", 0); @@ -887,9 +889,9 @@ public static string UploadFull(string JSON, string DeviceID, string blockType = } if (!UseCosmosDB) - WriteHashAsync(DeviceID, JsonConvert.SerializeObject(oChain), "Chain"); + WriteHashAsync(DeviceID, JsonConvert.SerializeObject(oChain), "_Chain").ConfigureAwait(false); else - WriteHashAsync(DeviceID, JsonConvert.SerializeObject(oChain), "Chain").Wait(); + WriteHashAsync(DeviceID, JsonConvert.SerializeObject(oChain), "_Chain").Wait(); //Add missing attributes @@ -917,9 +919,9 @@ public static string UploadFull(string JSON, string DeviceID, string blockType = if (!UseCosmosDB) { if (blockType == BlockType) - WriteHashAsync(DeviceID, jTemp.ToString(Formatting.None), "_Full"); + WriteHashAsync(DeviceID, jTemp.ToString(Formatting.None), "_Full").ConfigureAwait(false); else - WriteHashAsync(DeviceID + "_" + blockType, jTemp.ToString(Formatting.None), "_Full"); + WriteHashAsync(DeviceID + "_" + blockType, jTemp.ToString(Formatting.None), "_Full").ConfigureAwait(false); } else { @@ -937,9 +939,9 @@ public static string UploadFull(string JSON, string DeviceID, string blockType = if (!UseCosmosDB) { if (blockType == BlockType) - WriteHashAsync(sResult, oStatic.ToString(Newtonsoft.Json.Formatting.None), "Assets"); + WriteHashAsync(sResult, oStatic.ToString(Newtonsoft.Json.Formatting.None), "_Assets").ConfigureAwait(false); else - WriteHashAsync(sResult + "_" + blockType, oStatic.ToString(Newtonsoft.Json.Formatting.None), "Assets"); + WriteHashAsync(sResult + "_" + blockType, oStatic.ToString(Newtonsoft.Json.Formatting.None), "_Assets").ConfigureAwait(false); } else { @@ -1220,7 +1222,7 @@ public static JObject GetHistory(string DeviceID, string blockType = "") try { - string sChain = ReadHash(DeviceID, "Chain"); + string sChain = ReadHash(DeviceID, "_Chain"); var oChain = JsonConvert.DeserializeObject(sChain); foreach (block oBlock in oChain.Chain.Where(t => t.blocktype == blockType)) { @@ -1244,6 +1246,58 @@ public static JObject GetHistory(string DeviceID, string blockType = "") return jResult; } + public static JArray GetJHistory(string DeviceID, string blockType = "") + { + string sResult = ""; + + try + { + //Check in MemoryCache + if (_cache.TryGetValue("HIST - " + DeviceID + " - " + blockType, out sResult)) + { + //Try to get value from Memory + if (!string.IsNullOrEmpty(sResult)) + { + return JArray.Parse(sResult); + } + } + } + catch { } + + JArray jResult = new JArray(); + + if (string.IsNullOrEmpty(blockType)) + blockType = BlockType; + + try + { + string sChain = ReadHash(DeviceID, "_Chain"); + var oChain = JsonConvert.DeserializeObject(sChain); + foreach (block oBlock in oChain.Chain.Where(t => t.blocktype == blockType)) + { + try + { + JObject jTemp = new JObject(); + jTemp.Add("index", oBlock.index); + jTemp.Add("timestamp", new DateTime(oBlock.timestamp).ToUniversalTime()); + jTemp.Add("type", ""); + jResult.Add(jTemp); + } + catch { } + } + + //Cache result in Memory + if (!string.IsNullOrEmpty(sResult)) + { + var cacheEntryOptions = new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromSeconds(60)); //cache ID for 60s + _cache.Set("HIST - " + DeviceID + " - " + blockType, jResult.ToString(Formatting.None), cacheEntryOptions); + } + } + catch { } + + return jResult; + } + public static JObject GetRaw(string RawID, string path = "") { JObject jResult = new JObject(); @@ -1488,7 +1542,7 @@ public static List Search(string searchkey, string KeyID = "#id") return lNames.Union(lNames).ToList(); } - public static JArray Query(string paths, string select, string exclude, string where = "") + public static async Task QueryAsync(string paths, string select, string exclude, string where) { paths = System.Net.WebUtility.UrlDecode(paths); select = System.Net.WebUtility.UrlDecode(select); @@ -1515,7 +1569,7 @@ public static JArray Query(string paths, string select, string exclude, string w DateTime dStart = DateTime.Now; //JObject lRes = new JObject(); JArray aRes = new JArray(); - List lLatestHash = GetAllChainsAsync().Result; + List lLatestHash = await GetAllChainsAsync(); foreach (string sHash in lLatestHash) { bool foundData = false; @@ -1858,7 +1912,7 @@ public static JArray QueryAll(string paths, string select, string exclude) if (UseFileStore) { - foreach (var oFile in new DirectoryInfo("wwwroot/Assets").GetFiles("*.json")) + foreach (var oFile in new DirectoryInfo(Path.Combine(FilePath, "_Assets")).GetFiles("*.json")) { bool foundData = false; JObject jObj = GetRaw(File.ReadAllText(oFile.FullName), paths); @@ -2031,7 +2085,7 @@ public static JArray GetChanges(TimeSpan age, int changeType = -1) { Change oRes = new Change(); oRes.id = sID; - var jObj = JObject.Parse(ReadHash(sID, "Chain")); + var jObj = JObject.Parse(ReadHash(sID, "_Chain")); oRes.lastChange = new DateTime(jObj["Chain"].Last["timestamp"].Value()); if(DateTime.Now.Subtract(oRes.lastChange) > age) { @@ -2101,7 +2155,7 @@ public static async Task> GetAllChainsAsync() if (UseFileStore) { - foreach (var oFile in new DirectoryInfo("wwwroot/Chain").GetFiles("*.json")) + foreach (var oFile in new DirectoryInfo(Path.Combine(FilePath, "_Chain")).GetFiles("*.json")) { lResult.Add(System.IO.Path.GetFileNameWithoutExtension(oFile.Name)); } @@ -2343,7 +2397,7 @@ public static bool Export(string URL, string RemoveObjects) { try { - var jObj = JObject.Parse(ReadHash(sID, "Chain")); + var jObj = JObject.Parse(ReadHash(sID, "_Chain")); foreach (var sBlock in jObj.SelectTokens("Chain[*].data")) { try @@ -2351,7 +2405,7 @@ public static bool Export(string URL, string RemoveObjects) string sBlockID = sBlock.Value(); if (!string.IsNullOrEmpty(sBlockID)) { - var jBlock = GetRaw(ReadHash(sBlockID, "Assets")); + var jBlock = GetRaw(ReadHash(sBlockID, "_Assets")); jBlock.Remove("#id"); //old Version of jainDB //jBlock.Remove("_date"); jBlock.Remove("_index"); @@ -2425,421 +2479,6 @@ public static string UploadToREST(string URL, string content) return ""; } - /* - public static string GetFull(Blockchain oChain, int Index = -1) - { - try - { - block lBlock = null; - if (Index == -1) - { - lBlock = oChain.GetLastBlock(); - } - else - { - lBlock = oChain.GetBlock(Index); - } - - int index = lBlock.index; - DateTime dInvDate = new DateTime(lBlock.timestamp); - string InvHash = lBlock.data; - string sData = ReadHash(InvHash, "Assets"); - if (!string.IsNullOrEmpty(sData)) - { - JObject oInv = JObject.Parse(sData); - oInv.Add(new JProperty("_index", index)); - oInv.Add(new JProperty("_inventoryDate", dInvDate)); - oInv.Add(new JProperty("_hash", InvHash)); - JSort(oInv); - - //Load hashed values - foreach (JProperty oTok in oInv.Descendants().Where(t => t.Type == JTokenType.Property && ((JProperty)t).Name.StartsWith("##hash")).ToList()) - { - string sH = oTok.Value.ToString(); - string sRoot = oTok.Path.Split('.')[0].Split('[')[0]; - string sObj = ReadHash(sH, sRoot); - if (!string.IsNullOrEmpty(sObj)) - { - var jStatic = JObject.Parse(sObj); - oTok.Parent.Merge(jStatic); - oTok.Remove(); - } - } - - return oInv.ToString(); - } - } - catch { } - - return ""; - } - public static string ByteArrayToString(byte[] input) - { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < input.Length; i++) - { - sb.Append(input[i].ToString("X2")); - } - return sb.ToString(); - } - - public static byte[] StringToByteArray(String hex) - { - int NumberChars = hex.Length; - byte[] bytes = new byte[NumberChars / 2]; - for (int i = 0; i < NumberChars; i += 2) - bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16); - return bytes; - } - public static string LookupID(string query) - { - try - { - if (UseRedis) - { - var cache1 = RedisConnectorHelper.Connection.GetDatabase(1); - return cache1.StringGet(query.TrimStart('?').Split('&')[0].Replace("=", "/")); - } - } - catch { } - - return ""; - } - - public static async Task> FindLatestPathAsync(string path) - { - List lResult = new List(); - try - { - if (UseRedis) - { - var tFind = await FindHashOnContentAsync(path); - - tFind.AsParallel().ForAll(t => - { - foreach (string sName in FindLatestRawWithHash(new List() { t }, "#Name")) - { - lResult.Add(sName); - } - }); - } - } - catch { } - - return lResult; - } - - public static string sTopic2Json(string Topic = "*") - { - var cache = RedisConnectorHelper.Connection.GetDatabase(); - var server = RedisConnectorHelper.Connection.GetServer("localhost", 6379); - - List lRes = new List(); - var keys = server.Keys(pattern: Topic); - //var sResult = cache.StringGet("BIOS/*"); - foreach (var key in keys) - { - key.ToString(); - var sVal = cache.StringGet(key); - lRes.Add(key.ToString() + ";" + sVal); - } - - return Topic2Json(lRes.ToArray()); - try - { - string[] aFile = File.ReadAllLines("wwwroot\\test.json"); - return Topic2Json(aFile); - } - catch { } - - return ""; - } - - public static string Topic2Json(string Topic) - { - return Topic2Json(Topic.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries)); - } - public static string Topic2Json(string[] Topic) - { - try - { - List lSource = Topic.OrderBy(t => t, new TopicComparer()).ToList(); - - JObject ORes = new JObject(); - foreach (string sLine in lSource) - { - string sTopic = sLine.Split(';')[0]; - string sValue = sLine.Split(';')[1]; - bool bMerge = true; - - string sPath = ""; - - //Convert Topic to JPath - sPath = Topic2JPath(sTopic); - - - JObject O = new JObject(); - string sFullPath = sPath; - foreach (string sItem in sPath.Split('.').Reverse()) - { - bool bArray = false; - if (sItem.EndsWith("]")) - bArray = true; - - if (O.Count == 0) - { - if (!bArray) - { - O.Add(sItem, sValue); - } - else - { - JArray A = new JArray(); - A.Add(sValue); - O.Add(sItem.Split('[')[0], A); - //JObject OA = new JObject(); - //OA.Add(A); - //O = OA; - } - sFullPath = sFullPath.Substring(0, (sFullPath.Length - sItem.Length)).TrimEnd('.'); - } - else - { - if (!bArray) - { - if (O.SelectToken(sFullPath) == null) - { - JObject N = new JObject(); - N.Add(sItem, O); - O = N; - sFullPath = sFullPath.Substring(0, (sFullPath.Length - sItem.Length)).TrimEnd('.'); - } - } - else - { - if (ORes.SelectToken(sFullPath) == null) - { - JArray A = new JArray(); - A.Add(O); - - JObject N = new JObject(); - N.Add(sItem.Split('[')[0], A); - - O = N; - sFullPath = sFullPath.Substring(0, (sFullPath.Length - sItem.Length)).TrimEnd('.'); - } - else - { - var oT = ORes.SelectToken(sFullPath); - ((JObject)oT).Add(O.First); - bMerge = false; - } - } - } - - } - - if (bMerge) - { - ORes.Merge(O); - } - else - { - bMerge = true; - } - } - - string sJ = ORes.ToString(); - return sJ; - } - catch - { } - - return ""; - } - - public static List Json2Topic(JObject JSON, string ID = "") - { - if (!string.IsNullOrEmpty(ID)) - { - if (!ID.EndsWith("/")) - ID += "/"; - } - List sResult = new List(); - - foreach (var x in JSON) - { - try - { - string name = x.Key; - if (x.Value.Count() > 0) - { - if (x.Value.Type != JTokenType.Array) - { - if (x.Value.Type == JTokenType.Object) - sResult.AddRange(Json2Topic(x.Value as JObject, ID)); - else - { - foreach (var oVal in x.Value) - { - if (!string.IsNullOrEmpty(oVal.ToString())) - { - sResult.Add(ID + JSON.Path + "/" + name + ";" + oVal.ToString()); - } - } - } - } - else - { - int i = 0; - foreach (var oVal in x.Value) - { - if (oVal.Type == JTokenType.Object) - { - sResult.AddRange(Json2Topic(oVal as JObject, ID)); - } - else - { - if (!string.IsNullOrEmpty(oVal.ToString())) - { - sResult.Add(ID + JSON.Path + "/" + name + "/[" + i + "];" + oVal.ToString()); - i++; - } - } - } - } - } - else - { - if (!string.IsNullOrEmpty(JSON.Path)) - { - if (!string.IsNullOrEmpty(x.Value.ToString())) - { - sResult.Add(ID + JSON.Path.Replace("[", "/[") + "/" + name + ";" + x.Value.ToString()); - } - } - } - } - catch - { } - } - - var cache = RedisConnectorHelper.Connection.GetDatabase(); - foreach (string s in sResult) - { - cache.StringSet(s.Split(';')[0], s.Split(';')[1]); - } - - return sResult; - } - - public static List GetLatestRawAsync() - { - List lResult = new List(); - try - { - if (UseRedis) - { - var cache4 = RedisConnectorHelper.Connection.GetDatabase(4); - foreach (string sRawID in GetLatestBlocksAsync().Result) - { - Task.Run(() => - { - cache4.StringGet(sRawID); - }); - } - } - } - catch { } - - return lResult; - } - */ - - /*public static bool WriteHash(string Hash, string Data, string Collection) -{ -try -{ - if (!Directory.Exists("wwwroot\\" + Collection)) - Directory.CreateDirectory("wwwroot\\" + Collection); - - if (!File.Exists("wwwroot\\" + Collection + "\\" + Hash + ".json")) //We do not have to create the same hash file twice... - { - lock (locker) //only one write operation - { - File.WriteAllText("wwwroot\\" + Collection + "\\" + Hash + ".json", Data); - } - } - - return true; -} -catch { } - -return false; -}*/ - - /*public static void WriteJ(JObject JSON) - { - //IList keys = JSON.Properties().Select(p => p.Name).ToList(); - //keys.ToString(); - - foreach (var x in JSON) - { - try - { - string name = x.Key; - if (x.Value.Count() > 0) - { - if (x.Value.Type != JTokenType.Array) - { - if(x.Value.Type == JTokenType.Object) - WriteJ(x.Value as JObject); - else - { - foreach(var oVal in x.Value) - { - if (!string.IsNullOrEmpty(oVal.ToString())) - { - File.AppendAllText("wwwroot\\test.json", JSON.Path + "/" + name + ";" + oVal.ToString() + "" + Environment.NewLine); - } - } - } - } - else - { - int i = 0; - foreach (var oVal in x.Value) - { - if (oVal.Type == JTokenType.Object) - { - WriteJ(oVal as JObject); - } - else - { - if (!string.IsNullOrEmpty(oVal.ToString())) - { - File.AppendAllText("wwwroot\\test.json", JSON.Path + "/" + name + "/[" + i + "];" + oVal.ToString() + Environment.NewLine); - i++; - } - } - } - } - } - else - { - if (!string.IsNullOrEmpty(JSON.Path)) - { - if (!string.IsNullOrEmpty(x.Value.ToString())) - { - File.AppendAllText("wwwroot\\test.json", JSON.Path.Replace("[", "/[") + "/" + name + ";" + x.Value.ToString() + Environment.NewLine); - } - } - } - } - catch - { } - } - }*/ public static void JSort(JObject jObj, bool deep = false) { diff --git a/source/jaindb/jaindb.csproj b/source/jaindb/jaindb.csproj index 3f8ee68..abe4b7f 100644 --- a/source/jaindb/jaindb.csproj +++ b/source/jaindb/jaindb.csproj @@ -1,7 +1,7 @@ - netcoreapp2.0 + netcoreapp2.1 ..\docker-compose.dcproj jaindb false @@ -12,11 +12,12 @@ https://github.com/rzander/jaindb https://github.com/rzander/jaindb blockchain json - 1.0.0 - 1.0.0.75 - 1.0.0.75 - jaindb.Program + 1.0.1 + 1.0.1.76 + 1.0.1.76 + fcfd6c0a-e53c-46cb-8a9d-b786c0579861 + JainDB_Logo.ico @@ -55,21 +56,21 @@ - - + + - + - + - +