/// <summary> /// Does the ops command. /// </summary> /// <param name="container">The container.</param> /// <param name="query">The query.</param> /// <returns>A <see cref="CommerceCommandSingle"/></returns> public static CommerceCommandSingle DoOpsCommand(this Container container, DataServiceActionQuerySingle <CommerceCommandSingle> query) { var response = query.GetValueAsync().Result; var commandResponse = response; return(commandResponse); }
/// <summary> /// Does the ops command. /// </summary> /// <param name="container">The container.</param> /// <param name="query">The query.</param> /// <returns>A <see cref="CommerceCommandSingle"/></returns> public static CommerceCommandSingle DoOpsCommand(this Container container, DataServiceActionQuerySingle <CommerceCommandSingle> query) { Console.WriteLine(" ================ OPS COMMAND ================="); Console.WriteLine(" {query.RequestUri}"); try { var response = query.GetValueAsync().Result; var commandResponse = response; return(commandResponse); } catch (DataServiceQueryException ex) { Proxy.WriteColoredLine(ConsoleColor.Red, $"Exception {ex.InnerException.Message} on GetValue:{query.RequestUri}"); throw; } catch (AggregateException ex) { Proxy.WriteColoredLine(ConsoleColor.Red, $"Exception {ex.InnerException.Message} on GetValue:{query.RequestUri}"); throw; } catch (Exception ex) { Proxy.WriteColoredLine(ConsoleColor.Red, $"Unknown Exception {ex.Message} GetValue:{query.RequestUri}"); throw; } }
private void CallPlaceOrderFromActionQuery(Order order) { try { var query = new DataServiceActionQuerySingle <Order>(dsc, "http://service-root/Customers(0)/Microsoft.Test.OData.Services.ODataWCFService.PlaceOrder", new BodyOperationParameter("order", order)); query.GetValue(); } catch (InvalidOperationException ex) { // Ignore the exception thrown by Single() as no actual response is provided. if (ex.Message != "Sequence contains no elements") { throw; } } }
/// <summary> /// Sends a query expecting a CommandResponse back. /// </summary> /// <typeparam name="T">The type.</typeparam> /// <param name="query">The query.</param> /// <returns>A value</returns> public static CommerceCommand DoCommand <T>(DataServiceActionQuerySingle <T> query) { try { var response = query.GetValueAsync().Result; var commandResponse = response as CommerceCommand; if (commandResponse == null) { return(null); } LogInfo($" <.><.> DoCommand<T>: {query.RequestUri}"); WritePerf(commandResponse.Models.ToList()); if (commandResponse.ResponseCode.Equals("Ok", StringComparison.OrdinalIgnoreCase)) { return(commandResponse); } foreach (var message in commandResponse.Messages.Where(m => !m.Code.Equals("Information", StringComparison.OrdinalIgnoreCase))) { LogError($"DoCommand Failed:{message.Text}", typeof(Proxy)); } return(commandResponse); } catch (DataServiceQueryException ex) { LogError($"Exception {ex.InnerException.Message} on DoCommand:{query.RequestUri}", typeof(Proxy)); throw; } catch (AggregateException ex) { foreach (var e in ex.InnerExceptions) { LogError($"Exception {e.GetType()}: {e.Message} on DoCommand:{query.RequestUri}", typeof(Proxy)); } throw; } catch (Exception ex) { LogError($"Exception {ex.GetType()}: {ex.Message} on DoCommand:{query.RequestUri}", typeof(Proxy)); throw; } }
/// <summary> /// Gets the value. /// </summary> /// <typeparam name="T">The type.</typeparam> /// <param name="query">The query.</param> /// <returns>A value</returns> public static T GetValue <T>(DataServiceActionQuerySingle <T> query) { var watch = new Stopwatch(); watch.Start(); try { var result = query.GetValueAsync().Result; watch.Stop(); LogInfo($" <.><.> GetActionValue<T>: {query.RequestUri}: {watch.ElapsedMilliseconds}ms"); return(result); } catch (DataServiceQueryException ex) { LogError($"Exception {ex.InnerException.Message} on GetValue:{query.RequestUri}", typeof(Proxy)); throw; } catch (AggregateException ex) { foreach (var e in ex.InnerExceptions) { if (e is DataServiceClientException dataserviceClientException) { LogError($"Client Exception {dataserviceClientException.StatusCode} - {dataserviceClientException.Message} on GetValue:{query.RequestUri}", typeof(Proxy)); } else { LogError($"Exception {e.GetType()}: {e.Message} on GetValue:{query.RequestUri}", typeof(Proxy)); } } throw; } catch (Exception ex) { LogError($"Exception {ex.GetType()}: {ex.Message} GetValue:{query.RequestUri}", typeof(Proxy)); throw; } }
/// <summary> /// Gets the value. /// </summary> /// <typeparam name="T">The type.</typeparam> /// <param name="query">The query.</param> /// <returns>A value</returns> public static T GetValue <T>(DataServiceActionQuerySingle <T> query) { var watch = new Stopwatch(); watch.Start(); try { var result = query.GetValueAsync().Result; watch.Stop(); Console.WriteLine($" <.><.> GetActionValue<T>: {query.RequestUri}: {watch.ElapsedMilliseconds}ms"); return(result); } catch (DataServiceQueryException ex) { WriteColoredLine(ConsoleColor.Red, $"Exception {ex.InnerException.Message} on GetValue:{query.RequestUri}"); throw; } catch (AggregateException ex) { if (ex.InnerException is DataServiceQueryException) { var queryException = ex.InnerException as DataServiceQueryException; var realException = queryException.InnerException as DataServiceClientException; WriteColoredLine(ConsoleColor.Red, $"Client Exception {realException.StatusCode} - {realException.Message} on GetValue:{query.RequestUri}"); throw realException; } WriteColoredLine(ConsoleColor.Red, $"Aggregate Exception {ex.InnerException.Message} on GetValue:{query.RequestUri}"); throw; } catch (Exception ex) { WriteColoredLine(ConsoleColor.Red, $"Unknown Exception {ex.Message} GetValue:{query.RequestUri}"); throw; } }
/// <summary> /// Sends a query expecting a CommandResponse back. /// </summary> /// <typeparam name="T">The type.</typeparam> /// <param name="query">The query.</param> /// <returns>A value</returns> public static CommerceCommand DoCommand <T>(DataServiceActionQuerySingle <T> query) { Console.WriteLine($" ================ COMMAND ================="); Console.WriteLine($" {query.RequestUri}"); try { var response = query.GetValueAsync().Result; var commandResponse = response as CommerceCommand; if (commandResponse != null) { WritePerf(commandResponse.Models.ToList()); if (commandResponse.ResponseCode != "Ok") { WriteColoredLine(ConsoleColor.Red, $"DoCommand Failed:{commandResponse.Messages.FirstOrDefault(m => m.Code.Equals("Error") || m.Code.Equals("Warning"))?.Text}"); } } return(commandResponse); } catch (DataServiceQueryException ex) { WriteColoredLine(ConsoleColor.Red, $"Exception {ex.InnerException.Message} on GetValue:{query.RequestUri}"); throw; } catch (AggregateException ex) { WriteColoredLine(ConsoleColor.Red, $"Exception {ex.InnerException.Message} on GetValue:{query.RequestUri}"); throw; } catch (Exception ex) { WriteColoredLine(ConsoleColor.Red, $"Unknown Exception {ex.Message} GetValue:{query.RequestUri}"); throw; } }
/// <summary> /// Does the ops command. /// </summary> /// <param name="container">The container.</param> /// <param name="query">The query.</param> /// <returns>A <see cref="CommerceCommandSingle"/></returns> public static CommerceCommandSingle DoOpsCommand(this Container container, DataServiceActionQuerySingle <CommerceCommandSingle> query) { Condition.Requires(query, nameof(query)).IsNotNull(); return(query.GetValue()); }
private void CallPlaceOrderFromActionQuery(Order order) { try { var query = new DataServiceActionQuerySingle<Order>(dsc, "http://service-root/Customers(0)/Microsoft.Test.OData.Services.ODataWCFService.PlaceOrder", new BodyOperationParameter("order", order)); query.GetValue(); } catch (InvalidOperationException ex) { // Ignore the exception thrown by Single() as no actual response is provided. if (ex.Message != "Sequence contains no elements") { throw; } } }