public static async Task <IEnumerable <T> > Execute <T>(this IGraphClient client, TraversalQuery <GraphQuery, T> query) { var results = await client.Execute(query.ToString()); var resultList = new List <T>(); var objList = new List <object>(); foreach (var item in results) { objList.Add(item); } if (objList.Count == 0) { return(resultList); } if (objList[0].GetType().FullName == typeof(Newtonsoft.Json.Linq.JArray).FullName) { foreach (dynamic item in objList) { // item is Newtonsoft.Json.Linq.JArray resultList.Add(item.ToObject <T>()); } } else if (objList[0].GetType().FullName == typeof(Newtonsoft.Json.Linq.JObject).FullName) { foreach (dynamic item in objList) { // item is Newtonsoft.Json.Linq.JObject resultList.Add(item.ToObject <T>()); } } else { foreach (T item in objList) { resultList.Add(item); } } return(resultList); }
public static async Task Execute(this IGraphClient client, TerminalQuery <GraphQuery> query) { await client.Execute(query.ToString()); }
public async Task <IEnumerable> Execute(string query) { if (!PoolIsOpen) { throw new InvalidOperationException("Pool has not been opened"); } IGraphClient client = null; // Attempt to get a client from the pool await PoolSemaphore.WaitAsync(); try { if (ClientPool.Count > 0) { client = ClientPool[0]; ClientPool.Remove(client); } } finally { PoolSemaphore.Release(); } // Create a new client if one was not available if (client is null) { if (ClientFactory is null) { throw new Exception("Client factory has not been established"); } client = ClientFactory.Invoke(); if (client == null) { throw new Exception("Unable to create a client using the client factory"); } } IEnumerable result = null; for (int i = 0; i < NumRetries; i++) { try { result = await client.Execute(query); break; } catch (SocketException) { Trace.Write("Socket exception handled"); } } if (result is null) { throw new Exception("Could not execute query"); } // If the pool is closed, then exit if (!PoolIsOpen) { return(result); } // Return the client to the pool await PoolSemaphore.WaitAsync(); try { ClientPool.Add(client); } finally { PoolSemaphore.Release(); } return(result); }