Ejemplo n.º 1
0
        //---------------------------------------------------------------------
        // Constructs request to MR.
        //---------------------------------------------------------------------
        public static BlobsRequest MRR(Workspace w, SerializationFormatKind format, RequestVerb verb, string payload, HttpStatusCode expectedStatusCode, params string[] URI)
        {
            string       uri = URI.Length == 0 ? LastURI : URI[0];
            BlobsRequest rq  = new BlobsRequest(w, format, verb, uri, expectedStatusCode);

            // Specific request properties.
            rq.Format      = SerializationFormatKind.PlainText;
            rq.ContentType = "audio/mp3";
            rq.Accept      = (verb == RequestVerb.Get ? "*/*" : SerializationFormatKinds.ContentTypeFromKind(format));
            rq.Payload     = payload;

            // Append $value, if needed.
            if (uri.StartsWith("$") || uri.EndsWith(")"))
            {
                rq.URI += "/$value";

                // Expect dummy ETags from stream provider.
                byte[] hash = new System.Security.Cryptography.MD5CryptoServiceProvider().ComputeHash(System.Text.Encoding.ASCII.GetBytes(rq.URI));
                if ((hash[0] & 3) > 1)
                {
                    rq.ETagHeaderExpected = true;
                }
            }

            return(rq);
        }
Ejemplo n.º 2
0
        protected virtual void RefreshAccept()
        {
            ResourceProperty property    = GetPropertyFromQuery();
            bool             propertyUri = (property != null && !property.IsNavigation && !(property.Type is CollectionType));
            bool             valueUri    = URI_Internal.Contains("$value");
            bool             linksUri    = URI_Internal.Contains("$ref");

            if (valueUri)
            {
                Accept_Internal = null;
            }
            else if (this.MetadataOnly)
            {
                Accept_Internal = "*/*";
            }
            else if ((propertyUri || linksUri) && (Format == SerializationFormatKind.Atom || Format == SerializationFormatKind.Default))
            {
                Accept_Internal = "application/xml";
            }
            else if (Format == SerializationFormatKind.JSON)
            {
                Accept_Internal = ApplicationJson + ";odata.metadata=verbose";
            }
            else
            {
                Accept_Internal = SerializationFormatKinds.ContentTypeFromKind(Format);
            }

            Accept_Internal = RequestUtil.RandomizeContentTypeCapitalization(Accept_Internal);
        }
Ejemplo n.º 3
0
        //---------------------------------------------------------------------
        // Constructs request to MLE.
        //---------------------------------------------------------------------
        public static BlobsRequest MLE(Workspace w, SerializationFormatKind format, RequestVerb verb, BlobsPayload payload, HttpStatusCode expectedStatusCode, params string[] URI)
        {
            string       uri = URI.Length == 0 ? LastURI : URI[0];
            BlobsRequest rq  = new BlobsRequest(w, format, verb, uri, expectedStatusCode);

            // Specific request properties.
            rq.Format      = format;
            rq.ContentType = SerializationFormatKinds.ContentTypeFromKind(format);
            rq.Accept      = rq.ContentType;
            rq.Payload     = (payload != null ? payload.ToString() : null);

            return(rq);
        }
Ejemplo n.º 4
0
        protected virtual void RefreshContentType()
        {
            if (Payload == null && (Verb_Internal == RequestVerb.Get || Verb_Internal == RequestVerb.Delete))
            {
                ContentType_Internal = null;
            }
            else
            {
                ResourceProperty property    = GetPropertyFromQuery();
                bool             propertyUri = (property != null && !property.IsNavigation && !(property.Type is CollectionType));
                bool             valueUri    = URI_Internal.Contains("$value");
                bool             linksUri    = URI_Internal.Contains("$ref");

                if (propertyUri && !property.IsComplexType && valueUri)
                {
                    if (property.Type.ClrType == typeof(byte[]))
                    {
                        ContentType_Internal = SerializationFormatKinds.MimeApplicationOctetStream;
                    }
                    else
                    {
                        ContentType_Internal = SerializationFormatKinds.MimeTextPlain;
                    }
                }
                else if (propertyUri && !valueUri && (Format == SerializationFormatKind.Atom || Format == SerializationFormatKind.Default))
                {
                    ContentType_Internal = SerializationFormatKinds.MimeApplicationXml;
                }
                else if (linksUri && (Format == SerializationFormatKind.Atom || Format == SerializationFormatKind.Default))
                {
                    ContentType_Internal = "application/xml";
                }
                else if (Format == SerializationFormatKind.JSON)
                {
                    ContentType_Internal = ApplicationJson + ";odata.metadata=verbose";
                }
                else
                {
                    ContentType_Internal = SerializationFormatKinds.ContentTypeFromKind(Format);
                }

                ContentType_Internal = RequestUtil.RandomizeContentTypeCapitalization(ContentType_Internal);
            }
        }
Ejemplo n.º 5
0
        //---------------------------------------------------------------------
        // Constructs request with $ref. Assumes parent(*)/child URI format.
        //---------------------------------------------------------------------
        public static BlobsRequest LNK(Workspace w, SerializationFormatKind format, RequestVerb verb, string payload, HttpStatusCode expectedStatusCode, params string[] URI)
        {
            string       uri = (URI.Length == 0 ? LastURI : URI[0]);
            BlobsRequest rq  = new BlobsRequest(w, format, verb, uri, expectedStatusCode);

            // Specific request properties.
            rq.Format      = format;
            rq.ContentType = SerializationFormatKinds.ContentTypeFromKind(format == SerializationFormatKind.JSON ? SerializationFormatKind.JSON : SerializationFormatKind.PlainXml);
            rq.Accept      = rq.ContentType;

            // Adjust link in payload, if needed.
            if (!string.IsNullOrEmpty(payload))
            {
                rq.Payload = string.Format(format == SerializationFormatKind.JSON ?
                                           @"{{""odata.id"": ""{0}"" }}" :
                                           @"<ref xmlns='http://docs.oasis-open.org/odata/ns/metadata' id=""{0}"" />",
                                           payload);
            }

            return(rq);
        }