public JSONSchema(JsonElement root, bool isTopLevel) { if (root.ValueKind != JsonValueKind.Object) { throw new ArgumentException("Invalid Json Schema"); } ObjectEnumerator objectEnumerator = root.EnumerateObject(); while (objectEnumerator.MoveNext()) { JsonProperty current = objectEnumerator.Current; if (expectedJsonValueKinds.ContainsKey(current.Name) && expectedJsonValueKinds[current.Name].Contains(current.Value.ValueKind)) { settersDictionary[current.Name].Invoke(this, current.Value); } else { Console.WriteLine($"Invalid JSON Schema. {current.Name} is not a supported JsonSchema property"); } } if (isTopLevel) { ReplaceRefs(this, this); } }
/// <summary> /// Returns an enumerator that iterates the properties of an object. /// </summary> /// <returns> /// An <see cref="ObjectEnumerator"/> value that can be used to iterate /// through the object. /// </returns> /// <remarks> /// The enumerator will enumerate the properties in the order they are /// declared, and when an object has multiple definitions of a single /// property they will all individually be returned (each in the order /// they appear in the content). /// </remarks> public ObjectEnumerator GetEnumerator() { ObjectEnumerator ator = this; ator._curIdx = -1; return(ator); }
public IPooledEnumerable GetObjectsInRange( Point3D p, int range ) { if ( this == Map.Internal ) return NullEnumerable.Instance; return PooledEnumerable.Instantiate( ObjectEnumerator.Instantiate( this, new Rectangle2D( p.m_X - range, p.m_Y - range, range * 2 + 1, range * 2 + 1 ) ) ); }
public IPooledEnumerable GetObjectsInBounds( Rectangle2D bounds ) { if ( this == Map.Internal ) return NullEnumerable.Instance; return PooledEnumerable.Instantiate( ObjectEnumerator.Instantiate( this, bounds ) ); }
public IPooledEnumerable GetObjectsInRange( Point3D p ) { if ( this == Map.Internal ) return NullEnumerable.Instance; return PooledEnumerable.Instantiate( ObjectEnumerator.Instantiate( this, new Rectangle2D( p.m_X - 18, p.m_Y - 18, 37, 37 ) ) ); }
public bool MoveNext() { _MoveNextRow: // Is this the start of a new row? if (InitializeRow) { // Are we out of rows? if (!NameEnumerator.MoveNext()) { return(false); } // Get the new row. RowIndex++; ColumnIndex = -1; ObjectEnumerator = CurrentSource.GetEnumerator(); InitializeRow = false; } // Is this the last column? if (!ObjectEnumerator.MoveNext()) { // Attempt to get the next row. InitializeRow = true; goto _MoveNextRow; } Current = ObjectEnumerator.Current; ColumnIndex++; return(true); }
public static ObjectEnumerator Instantiate( Map map, Rectangle2D bounds ) { ObjectEnumerator e; if ( m_InstancePool.Count > 0 ) { e = m_InstancePool.Dequeue(); e.m_Map = map; e.m_Bounds = bounds; e.Reset(); } else { e = new ObjectEnumerator( map, bounds ); } return e; }
protected sealed override Object EvaluateCore( EvaluationContext context, out ResultMemory resultMemory) { resultMemory = null; var result = new StringBuilder(); var memory = new MemoryCounter(this, context.Options.MaxMemory); var current = Parameters[0].Evaluate(context); var ancestors = new Stack <ICollectionEnumerator>(); do { // Descend as much as possible while (true) { // Collection if (current.TryGetCollectionInterface(out Object collection)) { // Array if (collection is IReadOnlyArray array) { if (array.Count > 0) { // Write array start WriteArrayStart(result, memory, ancestors); // Move to first item var enumerator = new ArrayEnumerator(context, current, array); enumerator.MoveNext(); ancestors.Push(enumerator); current = enumerator.Current; } else { // Write empty array WriteEmptyArray(result, memory, ancestors); break; } } // Mapping else if (collection is IReadOnlyObject obj) { if (obj.Count > 0) { // Write mapping start WriteMappingStart(result, memory, ancestors); // Move to first pair var enumerator = new ObjectEnumerator(context, current, obj); enumerator.MoveNext(); ancestors.Push(enumerator); // Write mapping key WriteMappingKey(context, result, memory, enumerator.Current.Key, ancestors); // Move to mapping value current = enumerator.Current.Value; } else { // Write empty mapping WriteEmptyMapping(result, memory, ancestors); break; } } else { throw new NotSupportedException($"Unexpected type '{collection?.GetType().FullName}'"); } } // Not a collection else { // Write value WriteValue(context, result, memory, current, ancestors); break; } } // Next sibling or ancestor sibling do { if (ancestors.Count > 0) { var parent = ancestors.Peek(); // Parent array if (parent is ArrayEnumerator arrayEnumerator) { // Move to next item if (arrayEnumerator.MoveNext()) { current = arrayEnumerator.Current; break; } // Move to parent else { ancestors.Pop(); current = arrayEnumerator.Array; // Write array end WriteArrayEnd(result, memory, ancestors); } } // Parent mapping else if (parent is ObjectEnumerator objectEnumerator) { // Move to next pair if (objectEnumerator.MoveNext()) { // Write mapping key WriteMappingKey(context, result, memory, objectEnumerator.Current.Key, ancestors); // Move to mapping value current = objectEnumerator.Current.Value; break; } // Move to parent else { ancestors.Pop(); current = objectEnumerator.Object; // Write mapping end WriteMappingEnd(result, memory, ancestors); } } else { throw new NotSupportedException($"Unexpected type '{parent?.GetType().FullName}'"); } } else { current = null; } } while (current != null); } while (current != null); return(result.ToString()); }
public Dictionary <string, string> GetVerifiedAttributes(string invitation) { var result = new Dictionary <string, string>(); if (!test.withAgents) { var _key = "email"; var _value = invitation; result.Add(_key, _value); return(result); } //receive invitation var clientInvitee = new HttpClient(); string resultInvitee = clientInvitee.PostAsync(APIEndpoint + $"/connections/receive-invitation?auto_accept=true&alias=Prover", new StringContent(invitation)).Result.Content.ReadAsStringAsync().Result; var prover_connection_id = JsonDocument.Parse(resultInvitee). RootElement.GetProperty("connection_id").GetString(); //trust ping for completion var clientTrustPing = new HttpClient(); string resultTrustPing = clientTrustPing.PostAsync(APIEndpoint + $"/connections/{prover_connection_id}/send-ping", new StringContent("{}")).Result.Content.ReadAsStringAsync().Result; Console.WriteLine($"Invitation accepted, Provers Connection ID is '{resultInvitee}'"); //wait a little bit so that the connection is ready Thread.Sleep(1000); //verifier requests proof string proofReq = Utils.CreateProofRequest(prover_connection_id); JsonDocument.Parse(proofReq); var clientRequester = new HttpClient(); HttpResponseMessage httpresult = clientRequester. PostAsync(APIEndpoint + $"/present-proof-2.0/send-request", new StringContent(proofReq, Encoding.UTF8, "application/json")).Result; var resultJson = httpresult.Content.ReadAsStringAsync().Result; var requester_pres_ex_id = JsonDocument.Parse(resultJson). RootElement.GetProperty("pres_ex_id").ToString(); Console.WriteLine($"Proof requested [{requester_pres_ex_id}]"); //give prove time to respond Thread.Sleep(3000); //verifier verifies presentation HttpResponseMessage verifyPresentationResult = clientRequester. PostAsync(APIEndpoint + $"/present-proof-2.0/records/{requester_pres_ex_id}/verify-presentation", null).Result; if (verifyPresentationResult.IsSuccessStatusCode) { var jsonDoc = JsonDocument.Parse(verifyPresentationResult.Content.ReadAsStringAsync().Result); var verified = jsonDoc.RootElement.GetProperty("verified").GetString(); if (verified == "true") { ObjectEnumerator objEnum = jsonDoc.RootElement.GetProperty("by_format") .GetProperty("pres") .GetProperty("indy") .GetProperty("requested_proof") .GetProperty("revealed_attrs").EnumerateObject(); foreach (var item in objEnum) { var key = item.Name.Split('_')[1]; var value = item.Value.GetProperty("raw").ToString(); result.Add(key, value); } } } return(result); }
/// <summary> /// Gets objects in a radius around a point /// </summary> /// <param name="type">OBJECT_TYPE (0=item, 1=npc, 2=player)</param> /// <param name="x">origin X</param> /// <param name="y">origin Y</param> /// <param name="z">origin Z</param> /// <param name="radius">radius around origin</param> /// <param name="withDistance">Get an ObjectDistance enumerator</param> /// <returns>IEnumerable to be used with foreach</returns> protected IEnumerable GetInRadius(Zone.eGameObjectType type, int x, int y, int z, ushort radius, bool withDistance, bool ignoreZ) { // check if we are around borders of a zone Zone startingZone = GetZone(x, y); if (startingZone != null) { ArrayList res = startingZone.GetObjectsInRadius(type, x, y, z, radius, new ArrayList(), ignoreZ); uint sqRadius = (uint)radius * radius; foreach (var currentZone in m_zones) { if ((currentZone != startingZone) && (currentZone.TotalNumberOfObjects > 0) && CheckShortestDistance(currentZone, x, y, sqRadius)) { res = currentZone.GetObjectsInRadius(type, x, y, z, radius, res, ignoreZ); } } //Return required enumerator IEnumerable tmp = null; if (withDistance) { switch (type) { case Zone.eGameObjectType.ITEM: tmp = new ItemDistanceEnumerator(x, y, z, res); break; case Zone.eGameObjectType.NPC: tmp = new NPCDistanceEnumerator(x, y, z, res); break; case Zone.eGameObjectType.PLAYER: tmp = new PlayerDistanceEnumerator(x, y, z, res); break; case Zone.eGameObjectType.DOOR: tmp = new DoorDistanceEnumerator(x, y, z, res); break; default: tmp = new EmptyEnumerator(); break; } } else { tmp = new ObjectEnumerator(res); } return tmp; } else { if (log.IsDebugEnabled) { log.Error("GetInRadius starting zone is null for (" + type + ", " + x + ", " + y + ", " + z + ", " + radius + ") in Region ID=" + ID); } return new EmptyEnumerator(); } }
public static ObjectEnumerator Instantiate( Map map, Rectangle2D bounds ) { ObjectEnumerator e; if ( m_InstancePool.Count > 0 ) { e = (ObjectEnumerator)m_InstancePool.Dequeue(); e.m_Map = map; e.m_Bounds = bounds; e.Reset(); } else { e = new ObjectEnumerator( map, bounds ); } return e; }
private void CreateByJson(ObjectEnumerator obj, DynamicModel parent) { foreach (var item in obj) { DynamicModel model; switch (item.Value.ValueKind) { case JsonValueKind.Undefined: model = new DynamicModel(FieldType.String) { FdName = item.Name, FdValue = item.Value.GetString() }; parent.Set(model); break; case JsonValueKind.Object: model = new DynamicModel(FieldType.Object) { FdName = item.Name }; CreateByJson(item.Value.EnumerateObject(), model); parent.Set(model); break; case JsonValueKind.Array: model = new DynamicModel(FieldType.Array) { FdName = item.Name }; CreateByJson(item.Value.EnumerateArray(), model); parent.Set(model); break; case JsonValueKind.String: model = new DynamicModel(FieldType.String) { FdName = item.Name, FdValue = item.Value.GetString() }; parent.Set(model); break; case JsonValueKind.Number: model = new DynamicModel(FieldType.Decimal) { FdName = item.Name, FdValue = item.Value.GetInt32() }; parent.Set(model); break; case JsonValueKind.True: model = new DynamicModel(FieldType.Bool) { FdName = item.Name, FdValue = item.Value.GetBoolean() }; parent.Set(model); break; case JsonValueKind.False: model = new DynamicModel(FieldType.Bool) { FdName = item.Name, FdValue = item.Value.GetBoolean() }; parent.Set(model); break; case JsonValueKind.Null: model = new DynamicModel(FieldType.String) { FdName = item.Name, FdValue = null }; parent.Set(model); break; default: break; } } }
static async Task Main(string[] args) { XmlDocument doc = new XmlDocument(); Console.WriteLine(args[0]); FileStream fs = new FileStream(args[0], FileMode.Open, FileAccess.Read); doc.Load(fs); XmlNodeList nodes = doc.GetElementsByTagName("PackageReference"); for (int i = 0; i < nodes.Count; i++) { string packageName = nodes[i].Attributes.GetNamedItem("Include").Value; Console.WriteLine(packageName); Version packageVersion; if (nodes[i].Attributes.GetNamedItem("Version") != null) { Version.TryParse(nodes[i].Attributes.GetNamedItem("Version").Value, out packageVersion); List <Version> allTheVersions = new List <Version>(); HttpClient client = new HttpClient(); HttpResponseMessage message = await client.GetAsync($"https://api-v2v3search-0.nuget.org/search/query?q=packageid:{packageName.ToLowerInvariant()}&ignoreFilter=true"); string json = await message.Content.ReadAsStringAsync(); JsonDocument packageDoc = await System.Text.Json.JsonDocument.ParseAsync(await message.Content.ReadAsStreamAsync()); JsonElement root = packageDoc.RootElement; ObjectEnumerator oe = root.EnumerateObject(); while (oe.MoveNext()) { if (oe.Current.Name == "data") { ArrayEnumerator ae = oe.Current.Value.EnumerateArray(); while (ae.MoveNext()) { ObjectEnumerator re = ae.Current.EnumerateObject(); while (re.MoveNext()) { if (re.Current.Name == "Version") { Version v; if (Version.TryParse(re.Current.Value.GetString(), out v)) { allTheVersions.Add(v); } } } } var newerVersions = allTheVersions.Where(ver => ver.CompareTo(packageVersion) > 0); foreach (Version newerVersion in newerVersions) { Console.WriteLine($"{packageName} - {newerVersion}"); } } } } } }