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); } }