private static string getAllGDIDFormats(GDID gdid) { var sb = new StringBuilder(); // native sb.AppendLine(gdid.ToString()); // hex sb.AppendLine("0x" + gdid.ToHexString()); // BASE64 sb.AppendLine(Convert.ToBase64String(gdid.Bytes)); // Elink var link = new ELink(gdid); for (var cnt = 0; cnt <= ELink.VARIATIONS; cnt++) { sb.AppendLine(link.Encode((byte)cnt)); } // byte array sb.AppendLine("[" + string.Join(", ", gdid.Bytes) + "]"); return(sb.ToString()); }
private async Task <TreeNodeInfo> getNodeByPathSegment(TreePtr tree, GDID gParent, string pathSegment, DateTime asOfUtc, ICacheParams caching) { if (gParent.IsZero) { gParent = Constraints.G_VERY_ROOT_NODE; } var tblCache = s_CacheTableName[tree]; var keyCache = nameof(getNodeByPathSegment) + gParent.ToHexString() + (pathSegment ?? string.Empty) + asOfUtc.Ticks; var node = await m_Data.Cache.FetchThroughAsync( keyCache, tblCache, caching, async key => { var qry = new Query <TreeNodeInfo>("Tree.GetNodeInfo") { new Query.Param("tree", tree), new Query.Param("gparent", gParent), new Query.Param("psegment", pathSegment), new Query.Param("asof", asOfUtc) }; return(await m_Data.TreeLoadDocAsync(tree, qry)); } ).ConfigureAwait(false); return(node); }
public void Test_Values(uint era, ulong id) { var g = new GDID(era, id); var str = g.ToString(); var hex = g.ToHexString(); var g2 = GDID.Parse(str); var g3 = GDID.Parse(hex); Aver.AreEqual(g, g2); Aver.AreEqual(g, g3); Aver.AreEqual(g2, g3); Aver.AreObjectsEqual(g, g2); Aver.AreObjectsEqual(g, g3); Aver.AreObjectsEqual(g2, g3); Aver.IsTrue(g == g2); Aver.IsTrue(g == g3); Aver.IsTrue(g2 == g3); Aver.IsFalse(g != g3); Aver.IsFalse(g != g2); Aver.IsFalse(g2 != g3); Aver.AreEqual(g.GetHashCode(), g2.GetHashCode()); Aver.AreEqual(g.GetHashCode(), g3.GetHashCode()); Aver.AreEqual(g.GetDistributedStableHash(), g2.GetDistributedStableHash()); Aver.AreEqual(g.GetDistributedStableHash(), g3.GetDistributedStableHash()); var json = new { g }.ToJson(); "String: {0} \n Hex: {1} \n Json: {2} \n".SeeArgs(str, hex, json); var got = json.JsonToDataObject() as JsonDataMap; Aver.AreEqual(g, got["g"].AsGDID()); var buf = g.Bytes; var g4 = new GDID(buf); Aver.AreEqual(g, g4); var buf2 = new byte[128]; g.WriteIntoBuffer(buf2, 18); var g5 = new GDID(buf2, 18); Aver.AreEqual(g, g5); }
private async Task <IEnumerable <TreeNodeHeader> > getChildNodeListByGdid(TreePtr tree, GDID gdidAddress, DateTime asOfUtc, ICacheParams caching) { var tblCache = s_CacheTableName[tree]; var keyCache = nameof(getChildNodeListByGdid) + gdidAddress.ToHexString() + asOfUtc.Ticks; var nodes = await m_Data.Cache.FetchThroughAsync( keyCache, tblCache, caching, async key => { var qry = new Query <TreeNodeHeader>("Tree.GetChildNodeList") { new Query.Param("tree", tree), new Query.Param("gparent", gdidAddress), new Query.Param("asof", asOfUtc) }; return(await m_Data.TreeLoadEnumerableAsync(tree, qry)); } ).ConfigureAwait(false); return(nodes); }
private async Task <TreeNodeInfo> getNodeByGdid(HashSet <GDID> graph, TreePtr tree, GDID gNode, DateTime asOfUtc, ICacheParams caching) { var tblCache = s_CacheTableName[tree]; var keyCache = nameof(getNodeByGdid) + gNode.ToHexString() + asOfUtc.Ticks; var result = await m_Data.Cache.FetchThroughAsync( keyCache, tblCache, caching, async key => { if (!graph.Add(gNode)) { //circular reference var err = new ConfigException("Circular reference in config tree = `{0}`, gnode = `{1}`, asof = `{2}`".Args(tree, gNode, asOfUtc)); WriteLogFromHere(Log.MessageType.CatastrophicError, err.Message, err, pars: new { tree = tree.ToString(), gnode = gNode, asof = asOfUtc }.ToJson()); throw err; } //1 - fetch THIS level - rightmost part of the tree var qry = new Query <TreeNodeInfo>("Tree.GetNodeInfoByGdid") { new Query.Param("tree", tree), new Query.Param("gdid", gNode), new Query.Param("asof", asOfUtc) }; var node = await m_Data.TreeLoadDocAsync(tree, qry); if (node == null) { return(null); } //2 - if IAM ROOT, there is no parent for root node.EffectiveConfig = new ConfigVector(node.LevelConfig.Content);//Copy node.FullPath = Constraints.VERY_ROOT_PATH_SEGMENT; if (node.Gdid == Constraints.G_VERY_ROOT_NODE) { return(node); } //3 - Fetch parent of THIS TreeNodeInfo nodeParent = await getNodeByGdid(graph, tree, node.G_Parent, asOfUtc, caching).ConfigureAwait(false); if (nodeParent == null) { return(null); } //4 - calculate effective config var cfgNode = node.LevelConfig.Node.NonEmpty(nameof(node.LevelConfig)); var cfgParent = nodeParent.EffectiveConfig.Node.NonEmpty(nameof(nodeParent.EffectiveConfig)); var confResult = new MemoryConfiguration() { Application = this.App }; confResult.CreateFromNode(cfgParent); //inherit confResult.Root.OverrideBy(cfgNode); //override node.EffectiveConfig.Node = confResult.Root; node.FullPath = TreePath.Join(nodeParent.FullPath, node.PathSegment); //the security check is done post factum AFTER tree node full path is known return(node); } ).ConfigureAwait(false); if (result == null) { return(null); } App.Authorize(new TreePermission(TreeAccessLevel.Read, result.FullPathId)); return(result); }