private static void RespondWithException(WriteResponse writeResponse, RestRequestException rre) { StringBuilder stringBuilder = new StringBuilder("{"); if (rre.RestErrorString != null) stringBuilder.AppendFormat("\"error\":\"{0}\",", (object) rre.RestErrorString); if (rre.RestErrorDescription != null) stringBuilder.AppendFormat("\"errordescription\":\"{0}\"", (object) rre.RestErrorDescription); stringBuilder.Append("}"); writeResponse(rre.HttpStatusCode, stringBuilder.ToString()); }
public void InjectToNS() { foreach (OrderInfo orderInfo in orderCreator.allOrderInfos) { if (!orderInfo.IsToInject()) { continue; } Console.WriteLine("---------------"); Console.WriteLine("Upsert Order #{0}", orderInfo.order_id); WriteResponse salesOrderResponse = nsConnector.UpsertRecord(orderInfo.sales_order); if (!IsWriteSucceed(salesOrderResponse)) { orderInfo.invalid_reason += "Upsert SO failed; "; failedUpsertOrders.Add(orderInfo); } if (orderInfo.invoice != null) { WriteResponse invoiceResponse = nsConnector.UpsertRecord(orderInfo.invoice); if (!IsWriteSucceed(invoiceResponse)) { orderInfo.invalid_reason += "Upsert Invoice failed; "; failedUpsertInvoices.Add(orderInfo); } } if (orderInfo.IsToCloseOrder()) // Close invalid order { // Get order and close line item orderInfo.sales_order_get = nsConnector.GetSalesOrder(orderInfo.sales_order.externalId); orderInfo.CreateClosedOrder(); salesOrderResponse = nsConnector.UpsertRecord(orderInfo.sales_order_close); if (!IsWriteSucceed(salesOrderResponse)) { orderInfo.invalid_reason += "Close SO failed; "; failedCloseOrders.Add(orderInfo); } } } Console.WriteLine("\n"); }
private static void CallSafely(Request request, string payload, WriteResponse writeResponse, Func<Request, JSONValue, JSONValue> method) { try { JSONValue jsonValue = (JSONValue) ((string) null); if (payload.Trim().Length == 0) { jsonValue = new JSONValue(); } else { try { jsonValue = new JSONParser(request.Payload).Parse(); } catch (JSONParseException ex) { Handler.ThrowInvalidJSONException(); } } writeResponse(HttpStatusCode.Ok, method(request, jsonValue).ToString()); } catch (JSONTypeException ex) { Handler.ThrowInvalidJSONException(); } catch (KeyNotFoundException ex) { Handler.RespondWithException(writeResponse, new RestRequestException() { HttpStatusCode = HttpStatusCode.BadRequest }); } catch (RestRequestException ex) { Handler.RespondWithException(writeResponse, ex); } catch (Exception ex) { Handler.RespondWithException(writeResponse, new RestRequestException() { HttpStatusCode = HttpStatusCode.InternalServerError, RestErrorString = "InternalServerError", RestErrorDescription = "Caught exception while fulfilling request: " + (object) ex }); } }
/// <summary> /// Invokes the Write service. /// </summary> public IServiceResponse Write(IServiceRequest incoming) { WriteResponse response = null; WriteRequest request = (WriteRequest)incoming; StatusCodeCollection results = null; DiagnosticInfoCollection diagnosticInfos = null; response = new WriteResponse(); response.ResponseHeader = ServerInstance.Write( request.RequestHeader, request.NodesToWrite, out results, out diagnosticInfos); response.Results = results; response.DiagnosticInfos = diagnosticInfos; return response; }
/// <summary> /// Initializes the message with a service fault. /// </summary> public WriteResponseMessage(ServiceFault ServiceFault) { this.WriteResponse = new WriteResponse(); if (ServiceFault != null) { this.WriteResponse.ResponseHeader = ServiceFault.ResponseHeader; } }
/// <summary> /// Initializes the message with the body. /// </summary> public WriteResponseMessage(WriteResponse WriteResponse) { this.WriteResponse = WriteResponse; }
/// <summary cref="IServiceMessage.CreateResponse" /> public object CreateResponse(IServiceResponse response) { WriteResponse body = response as WriteResponse; if (body == null) { body = new WriteResponse(); body.ResponseHeader = ((ServiceFault)response).ResponseHeader; } return new WriteResponseMessage(body); }
private void InvokeDelete(Request request, string payload, WriteResponse writeResponse) { Handler.CallSafely(request, payload, writeResponse, new Func<Request, JSONValue, JSONValue>(this.HandleDelete)); }