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); }
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); } }
public static void WriteBatchRequest(BatchRequest batchRequest, StringWriter writer) { //--batchresponse_aa2a62c3-d5f4-447e-9302-d31f062b02f7 //Content-Type: multipart/mixed; boundary=changesetresponse_1837899f-f0ce-447e-a980-d2596a561051 string batchBoundary = "batch_" + batchRequest.Identifier; foreach (BatchChangeset changeset in batchRequest.Changesets) { string setBoundary = "changeset_" + changeset.Identifier; writer.Write("--"); writer.WriteLine(batchBoundary); writer.WriteLine("Content-Type: " + RequestUtil.RandomizeContentTypeCapitalization("multipart/mixed; boundary=" + setBoundary)); writer.WriteLine(); foreach (AstoriaRequest request in changeset) { writer.Write("--"); writer.WriteLine(setBoundary); WriteBatchRequestFragment(request, writer); } writer.Write("--"); writer.Write(setBoundary); writer.WriteLine("--"); } foreach (AstoriaRequest request in batchRequest.Requests) { // TODO: newline? writer.Write("--"); writer.WriteLine(batchBoundary); // TODO: newline? WriteBatchRequestFragment(request, writer); } writer.Write("--"); writer.Write(batchBoundary); writer.WriteLine("--"); }
public static void WriteBatchRequestFragment(AstoriaRequest request, StringWriter writer) { // assume boundary has been written //Content-Type: application/http //Content-Transfer-Encoding:binary writer.WriteLine("Content-Type: " + RequestUtil.RandomizeContentTypeCapitalization("application/http")); writer.WriteLine("Content-Transfer-Encoding:binary"); writer.WriteLine(); //GET {uri} HTTP/1.1 //Content-Type: application/atom+xml;type=entry //Content-Length: ### string uri; if (request.UseRelativeUri) { uri = request.RelativeUri; } else { uri = request.URI; } writer.WriteLine("{0} {1} HTTP/1.1", request.Verb.ToString().ToUpper(), Uri.EscapeUriString(uri)); foreach (KeyValuePair <string, string> header in request.Headers) { writer.WriteLine("{0}: {1}", header.Key, header.Value); } writer.WriteLine(); if (request.Payload != null) { writer.WriteLine(request.Payload); } }
private void CreateEntryElement(KeyedResourceInstance keyedResourceInstance, XmlNode parentNode) { currentResource = keyedResourceInstance; XmlElement entryElement = CreateBasicEntryElement(keyedResourceInstance, parentNode); //string relativeParentKey = null; //Add the Id if there is one if (this.RequestVerb != RequestVerb.Post) { if (keyedResourceInstance.ResourceInstanceKey != null) { XmlElement idNode = CreateIdElement(keyedResourceInstance); entryElement.AppendChild(idNode); } } ResourceType type = Workspace.ServiceContainer.ResourceTypes.Single(rt => rt.Name == keyedResourceInstance.TypeName); XmlElement propertiesNode = CreateDataWebMetadataElement("properties"); IEnumerable <ResourceInstanceProperty> properties = keyedResourceInstance.Properties; if (this.RequestVerb == RequestVerb.Post && keyedResourceInstance.ResourceInstanceKey != null) { properties = keyedResourceInstance.ResourceInstanceKey.KeyProperties.Union(properties); } foreach (ResourceInstanceProperty property in properties) { if (property is ResourceInstanceSimpleProperty) { ResourceInstanceSimpleProperty simpleResourceProperty = property as ResourceInstanceSimpleProperty; VisitResourceInstanceSimpleProperty(simpleResourceProperty, propertiesNode); } else if (property is ResourceInstanceComplexProperty) { ResourceInstanceComplexProperty complexResourceProperty = property as ResourceInstanceComplexProperty; if (complexResourceProperty.ComplexResourceInstance == null) { VisitResourceInstanceComplexProperty(complexResourceProperty, propertiesNode); } else { VisitResourceInstanceComplexProperty(complexResourceProperty, propertiesNode); } } else if (property is ResourceInstanceNavProperty) { ResourceInstanceNavProperty navigationProperty = property as ResourceInstanceNavProperty; VisitResourceNavigationProperty(navigationProperty, entryElement); } } if (propertiesNode.ChildNodes.Count > 0) { if (!type.Facets.HasStream) { XmlElement contentNode = CreateAtomElement("content"); XmlAttribute contentTypeAttribute = CreateAtomAttribute("type"); contentTypeAttribute.Value = RequestUtil.RandomizeContentTypeCapitalization("application/xml"); contentNode.Attributes.Append(contentTypeAttribute); contentNode.AppendChild(propertiesNode); entryElement.AppendChild(contentNode); } else { entryElement.AppendChild(propertiesNode); } } if (EntryElementCallback != null) { EntryElementCallback(entryElement); } }