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());
        }
Ejemplo n.º 2
0
        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();
        }
Ejemplo n.º 4
0
 public AtomPayloadGenerator(PayloadGeneratorSettings settings)
     : base(settings)
 {
 }
Ejemplo n.º 5
0
 public JsonVerbosePayloadGenerator(PayloadGeneratorSettings settings)
     : base(settings)
 {
 }
Ejemplo n.º 6
0
 public JsonLightPayloadGenerator(PayloadGeneratorSettings settings)
     : base(settings)
 {
 }
Ejemplo n.º 7
0
        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;
        }
Ejemplo n.º 8
0
 protected PayloadGenerator(PayloadGeneratorSettings settings)
 {
     Assert.IsNotNull(settings, "PayloadGeneratorSettings must be non-null.");
     this.Settings = settings;
 }
Ejemplo n.º 9
0
 public AtomPayloadGenerator(PayloadGeneratorSettings settings)
     : base(settings)
 {
 }
Ejemplo n.º 10
0
 public JsonVerbosePayloadGenerator(PayloadGeneratorSettings settings)
     : base(settings)
 {
 }
Ejemplo n.º 11
0
 public JsonLightPayloadGenerator(PayloadGeneratorSettings settings)
     : base(settings)
 {
 }
Ejemplo n.º 12
0
 protected PayloadGenerator(PayloadGeneratorSettings settings)
 {
     Assert.IsNotNull(settings, "PayloadGeneratorSettings must be non-null.");
     this.Settings = settings;
 }