private static string GetLiteralValue(object value, ODataFormat format, PayloadGeneratorSettings settings) { JsonPayloadGenerator generator; if (format == ODataFormat.Json) { generator = new JsonLightPayloadGenerator(settings); } else { Assert.Fail("Format not supported by UriOperationParameterGenerator."); return null; } var payloadBuilder = value as PayloadBuilder; if (payloadBuilder != null) { return generator.GenerateLiteral(payloadBuilder); } var collectionBuilder = value as CollectionPropertyPayloadBuilder; if (collectionBuilder != null) { return generator.GenerateLiteral(collectionBuilder); } // Use the key syntax since that will give us single quotes and other formatting that is not used for literals as property values return JsonPrimitiveTypesUtil.PrimitiveToKeyString(value, value.GetType()); }
public static string Generate(PayloadBuilder payloadBuilder, ODataFormat format, PayloadGeneratorSettings settings = null) { if (settings == null) { settings = new PayloadGeneratorSettings(); } if (payloadBuilder == null) { return(null); } PayloadGenerator payloadGenerator = null; if (format == ODataFormat.Json) { payloadGenerator = new JsonLightPayloadGenerator(settings); } //else if (format == ODataFormat.Atom) //{ // payloadGenerator = new AtomPayloadGenerator(settings); //} else { Assert.Fail(String.Format("Payload generation not implemented for {0}", format)); } string payload; if (PayloadGenerator.IsEntityBindingPayload(payloadBuilder)) { payload = payloadGenerator.GenerateLinkPayload(payloadBuilder); } else { payload = payloadGenerator.Generate(payloadBuilder); } return(payload); }
internal static string Generate(OperationUriBuilder operationUriBuilder, ODataFormat format, PayloadGeneratorSettings settings) { var uriStringBuilder = new StringBuilder(); bool first = true; foreach (var parameter in operationUriBuilder.Parameters) { if (!first) { uriStringBuilder.Append(","); } string literalValue = GetLiteralValue(parameter.Value, format, settings); if (parameter.EscapeGeneratedValue) { literalValue = Uri.EscapeDataString(literalValue); } uriStringBuilder.Append(string.Format("{0}={1}", parameter.Name, literalValue)); first = false; } return uriStringBuilder.ToString(); }
public AtomPayloadGenerator(PayloadGeneratorSettings settings) : base(settings) { }
public JsonVerbosePayloadGenerator(PayloadGeneratorSettings settings) : base(settings) { }
public JsonLightPayloadGenerator(PayloadGeneratorSettings settings) : base(settings) { }
public static string Generate(PayloadBuilder payloadBuilder, ODataFormat format, PayloadGeneratorSettings settings = null) { if (settings == null) { settings = new PayloadGeneratorSettings(); } if (payloadBuilder == null) { return null; } PayloadGenerator payloadGenerator = null; if (format == ODataFormat.Json) { payloadGenerator = new JsonLightPayloadGenerator(settings); } else if (format == ODataFormat.Atom) { payloadGenerator = new AtomPayloadGenerator(settings); } else { Assert.Fail(String.Format("Payload generation not implemented for {0}", format)); } string payload; if (PayloadGenerator.IsEntityBindingPayload(payloadBuilder)) { payload = payloadGenerator.GenerateLinkPayload(payloadBuilder); } else { payload = payloadGenerator.Generate(payloadBuilder); } return payload; }
protected PayloadGenerator(PayloadGeneratorSettings settings) { Assert.IsNotNull(settings, "PayloadGeneratorSettings must be non-null."); this.Settings = settings; }