Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / ndp / fx / src / DataWeb / Server / System / Data / Services / Serializers / BatchWriter.cs / 1 / BatchWriter.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // //// Provides a base class for DataWeb services. // // // @owner [....] //--------------------------------------------------------------------- namespace System.Data.Services.Serializers { #region Namespaces. using System; using System.Diagnostics; using System.IO; #endregion Namespaces. ////// Static helper class to write responses for batch requests /// internal static class BatchWriter { ////// Writes the start of the changeset response /// /// writer to which the response needs to be written /// batch boundary /// changeset boundary internal static void WriteStartBatchBoundary(StreamWriter writer, string batchBoundary, string changesetBoundary) { WriterStartBoundary(writer, batchBoundary); writer.WriteLine( "{0}: {1}; {2}={3}", XmlConstants.HttpContentType, XmlConstants.MimeMultiPartMixed, XmlConstants.HttpMultipartBoundary, changesetBoundary); writer.WriteLine(); // NewLine to seperate the header from message } ///Write the boundary and header information. /// writer to which the response needs to be written /// host containing the value of the response headers /// boundary string that needs to be written internal static void WriteBoundaryAndHeaders(StreamWriter writer, IDataServiceHost host, string boundary) { Debug.Assert(writer != null, "writer != null"); Debug.Assert(host != null, "host != null"); Debug.Assert(boundary != null, "boundary != null"); WriterStartBoundary(writer, boundary); // First write the headers to indicate that the payload below is a http request WriteHeaderValue(writer, XmlConstants.HttpContentType, XmlConstants.MimeApplicationHttp); WriteHeaderValue(writer, XmlConstants.HttpContentTransferEncoding, XmlConstants.BatchRequestContentTransferEncoding); writer.WriteLine(); // NewLine to seperate the batch headers from http headers // In error cases, we create a dummy host, which has no request header information. // Hence we need to handle the case here. writer.WriteLine("{0} {1} {2}", XmlConstants.HttpVersionInBatching, host.ResponseStatusCode, WebUtil.GetStatusCodeText(host.ResponseStatusCode)); BatchServiceHost batch = (BatchServiceHost)host; if (null != batch.ContentId) { WriteHeaderValue(writer, XmlConstants.HttpContentID, batch.ContentId); } WriteHeaderValue(writer, XmlConstants.HttpContentType, host.ResponseContentType); WriteHeaderValue(writer, XmlConstants.HttpResponseCacheControl, host.ResponseCacheControl); WriteHeaderValue(writer, XmlConstants.HttpResponseETag, host.ResponseETag); WriteHeaderValue(writer, XmlConstants.HttpResponseLocation, host.ResponseLocation); WriteHeaderValue(writer, XmlConstants.HttpDataServiceVersion, host.ResponseVersion); BatchServiceHost batchHost = host as BatchServiceHost; Debug.Assert(batchHost != null, "batchHost != null -- only batch host currently supported."); WriteHeaderValue(writer, XmlConstants.HttpResponseAllow, batchHost.ResponseAllowHeader); writer.WriteLine(); // NewLine to seperate the header from message } ////// Write the end boundary /// /// writer to which the response needs to be written /// end boundary string. internal static void WriteEndBoundary(StreamWriter writer, string boundary) { writer.WriteLine("--{0}--", boundary); } ////// Write the start boundary /// /// writer to which the response needs to be written /// boundary string. private static void WriterStartBoundary(StreamWriter writer, string boundary) { writer.WriteLine("--{0}", boundary); } ////// Write the header name and value /// /// writer to which the response needs to be written /// name of the header whose value needs to be written. /// value of the header that needs to be written. private static void WriteHeaderValue(StreamWriter writer, string headerName, object headerValue) { if (headerValue != null) { string text = Convert.ToString(headerValue, System.Globalization.CultureInfo.InvariantCulture); if (!String.IsNullOrEmpty(text)) { writer.WriteLine("{0}: {1}", headerName, text); } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // //// Provides a base class for DataWeb services. // // // @owner [....] //--------------------------------------------------------------------- namespace System.Data.Services.Serializers { #region Namespaces. using System; using System.Diagnostics; using System.IO; #endregion Namespaces. ////// Static helper class to write responses for batch requests /// internal static class BatchWriter { ////// Writes the start of the changeset response /// /// writer to which the response needs to be written /// batch boundary /// changeset boundary internal static void WriteStartBatchBoundary(StreamWriter writer, string batchBoundary, string changesetBoundary) { WriterStartBoundary(writer, batchBoundary); writer.WriteLine( "{0}: {1}; {2}={3}", XmlConstants.HttpContentType, XmlConstants.MimeMultiPartMixed, XmlConstants.HttpMultipartBoundary, changesetBoundary); writer.WriteLine(); // NewLine to seperate the header from message } ///Write the boundary and header information. /// writer to which the response needs to be written /// host containing the value of the response headers /// boundary string that needs to be written internal static void WriteBoundaryAndHeaders(StreamWriter writer, IDataServiceHost host, string boundary) { Debug.Assert(writer != null, "writer != null"); Debug.Assert(host != null, "host != null"); Debug.Assert(boundary != null, "boundary != null"); WriterStartBoundary(writer, boundary); // First write the headers to indicate that the payload below is a http request WriteHeaderValue(writer, XmlConstants.HttpContentType, XmlConstants.MimeApplicationHttp); WriteHeaderValue(writer, XmlConstants.HttpContentTransferEncoding, XmlConstants.BatchRequestContentTransferEncoding); writer.WriteLine(); // NewLine to seperate the batch headers from http headers // In error cases, we create a dummy host, which has no request header information. // Hence we need to handle the case here. writer.WriteLine("{0} {1} {2}", XmlConstants.HttpVersionInBatching, host.ResponseStatusCode, WebUtil.GetStatusCodeText(host.ResponseStatusCode)); BatchServiceHost batch = (BatchServiceHost)host; if (null != batch.ContentId) { WriteHeaderValue(writer, XmlConstants.HttpContentID, batch.ContentId); } WriteHeaderValue(writer, XmlConstants.HttpContentType, host.ResponseContentType); WriteHeaderValue(writer, XmlConstants.HttpResponseCacheControl, host.ResponseCacheControl); WriteHeaderValue(writer, XmlConstants.HttpResponseETag, host.ResponseETag); WriteHeaderValue(writer, XmlConstants.HttpResponseLocation, host.ResponseLocation); WriteHeaderValue(writer, XmlConstants.HttpDataServiceVersion, host.ResponseVersion); BatchServiceHost batchHost = host as BatchServiceHost; Debug.Assert(batchHost != null, "batchHost != null -- only batch host currently supported."); WriteHeaderValue(writer, XmlConstants.HttpResponseAllow, batchHost.ResponseAllowHeader); writer.WriteLine(); // NewLine to seperate the header from message } ////// Write the end boundary /// /// writer to which the response needs to be written /// end boundary string. internal static void WriteEndBoundary(StreamWriter writer, string boundary) { writer.WriteLine("--{0}--", boundary); } ////// Write the start boundary /// /// writer to which the response needs to be written /// boundary string. private static void WriterStartBoundary(StreamWriter writer, string boundary) { writer.WriteLine("--{0}", boundary); } ////// Write the header name and value /// /// writer to which the response needs to be written /// name of the header whose value needs to be written. /// value of the header that needs to be written. private static void WriteHeaderValue(StreamWriter writer, string headerName, object headerValue) { if (headerValue != null) { string text = Convert.ToString(headerValue, System.Globalization.CultureInfo.InvariantCulture); if (!String.IsNullOrEmpty(text)) { writer.WriteLine("{0}: {1}", headerName, text); } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- _TLSstream.cs
- ProfileParameter.cs
- OleStrCAMarshaler.cs
- FontUnitConverter.cs
- ObjectQuery.cs
- DataServiceResponse.cs
- PersonalizablePropertyEntry.cs
- RepeaterCommandEventArgs.cs
- TemplatedMailWebEventProvider.cs
- ClosableStream.cs
- ListViewTableCell.cs
- FileDialog_Vista_Interop.cs
- TypefaceMetricsCache.cs
- StorageEntityTypeMapping.cs
- HashSetEqualityComparer.cs
- CharConverter.cs
- RouteItem.cs
- ActivityTrace.cs
- MultiDataTrigger.cs
- Header.cs
- COM2ExtendedBrowsingHandler.cs
- DataRelationCollection.cs
- SqlSupersetValidator.cs
- ObjectMaterializedEventArgs.cs
- ColorAnimationBase.cs
- AttributeProviderAttribute.cs
- SystemResourceHost.cs
- ReadOnlyPermissionSet.cs
- WebConfigurationFileMap.cs
- MobileResource.cs
- PrintingPermissionAttribute.cs
- CryptoStream.cs
- ZipIOCentralDirectoryFileHeader.cs
- BrowserPolicyValidator.cs
- Operator.cs
- DataGridViewHeaderCell.cs
- MethodCallTranslator.cs
- DoubleAnimationUsingPath.cs
- CodeGenerationManager.cs
- URLString.cs
- DbExpressionVisitor_TResultType.cs
- StylusCaptureWithinProperty.cs
- UrlPath.cs
- BaseUriHelper.cs
- DefaultBinder.cs
- ZeroOpNode.cs
- AutomationPeer.cs
- Popup.cs
- FrameworkObject.cs
- LogEntryHeaderDeserializer.cs
- BitmapEffectvisualstate.cs
- HtmlControlDesigner.cs
- DBPropSet.cs
- CustomErrorCollection.cs
- HyperLinkField.cs
- OdbcConnectionStringbuilder.cs
- DocumentPage.cs
- HeaderUtility.cs
- SqlWebEventProvider.cs
- ExecutionEngineException.cs
- InProcStateClientManager.cs
- Property.cs
- DataGridViewRowStateChangedEventArgs.cs
- KeyConstraint.cs
- QueryUtil.cs
- ProcessHost.cs
- Calendar.cs
- PropertyChangeTracker.cs
- BamlResourceDeserializer.cs
- FieldNameLookup.cs
- StateManagedCollection.cs
- EntityClassGenerator.cs
- AuthStoreRoleProvider.cs
- TopClause.cs
- ToolStripPanelDesigner.cs
- ValidationHelper.cs
- DomNameTable.cs
- GridViewPageEventArgs.cs
- SmuggledIUnknown.cs
- Exceptions.cs
- ValidationErrorCollection.cs
- ThreadExceptionDialog.cs
- MetadataPropertyAttribute.cs
- _NestedSingleAsyncResult.cs
- CompilerErrorCollection.cs
- ForceCopyBuildProvider.cs
- VisualStyleTypesAndProperties.cs
- PropertyEntry.cs
- InheritedPropertyChangedEventArgs.cs
- PackageRelationship.cs
- Keywords.cs
- NativeMethods.cs
- ProjectedSlot.cs
- BindStream.cs
- NeutralResourcesLanguageAttribute.cs
- ISCIIEncoding.cs
- LayoutInformation.cs
- MessageBox.cs
- SqlRemoveConstantOrderBy.cs
- JsonByteArrayDataContract.cs