Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataWeb / Server / System / Data / Services / Serializers / BatchWriter.cs / 1305376 / 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.Collections.Generic; 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 /// content-id string that needs to be written /// boundary string that needs to be written internal static void WriteBoundaryAndHeaders(StreamWriter writer, IDataServiceHost2 host, string contentId, 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)); if (null != contentId) { WriteHeaderValue(writer, XmlConstants.HttpContentID, contentId); } System.Net.WebHeaderCollection responseHeaders = host.ResponseHeaders; foreach (string header in responseHeaders.AllKeys) { WriteHeaderValue(writer, header, responseHeaders[header]); } 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.Collections.Generic; 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 /// content-id string that needs to be written /// boundary string that needs to be written internal static void WriteBoundaryAndHeaders(StreamWriter writer, IDataServiceHost2 host, string contentId, 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)); if (null != contentId) { WriteHeaderValue(writer, XmlConstants.HttpContentID, contentId); } System.Net.WebHeaderCollection responseHeaders = host.ResponseHeaders; foreach (string header in responseHeaders.AllKeys) { WriteHeaderValue(writer, header, responseHeaders[header]); } 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
- TemplatedAdorner.cs
- IWorkflowDebuggerService.cs
- SystemDiagnosticsSection.cs
- Point3DAnimationBase.cs
- MaskedTextBox.cs
- EndpointBehaviorElementCollection.cs
- ZipIOZip64EndOfCentralDirectoryLocatorBlock.cs
- ZipIOExtraFieldZip64Element.cs
- AuthenticateEventArgs.cs
- SafeArrayRankMismatchException.cs
- DoubleSumAggregationOperator.cs
- DesignerSerializerAttribute.cs
- TransactionsSectionGroup.cs
- FamilyCollection.cs
- isolationinterop.cs
- HierarchicalDataBoundControlAdapter.cs
- OverlappedAsyncResult.cs
- OdbcTransaction.cs
- HttpPostLocalhostServerProtocol.cs
- ExpressionPrinter.cs
- Helper.cs
- UInt64.cs
- CachingHintValidation.cs
- XmlSchemaExternal.cs
- RoutedEvent.cs
- DocumentPageView.cs
- _TimerThread.cs
- BindingContext.cs
- XamlDesignerSerializationManager.cs
- ToolStrip.cs
- DispatchWrapper.cs
- SuppressIldasmAttribute.cs
- FormViewInsertEventArgs.cs
- ClientUriBehavior.cs
- PrintPreviewDialog.cs
- ItemCollection.cs
- MenuBase.cs
- DirectoryObjectSecurity.cs
- EmptyControlCollection.cs
- MenuItemBinding.cs
- ToolStripSystemRenderer.cs
- RectConverter.cs
- WindowPattern.cs
- RsaElement.cs
- HexParser.cs
- counter.cs
- StyleCollection.cs
- PackageController.cs
- AssociationEndMember.cs
- ActiveXHost.cs
- InstanceHandleConflictException.cs
- CssClassPropertyAttribute.cs
- TableItemProviderWrapper.cs
- UrlAuthFailedErrorFormatter.cs
- namescope.cs
- EntityExpressionVisitor.cs
- FrameworkContentElement.cs
- ObjectItemAttributeAssemblyLoader.cs
- FileLevelControlBuilderAttribute.cs
- InstanceDescriptor.cs
- ConfigurationManagerInternalFactory.cs
- XamlBrushSerializer.cs
- DiscoveryMessageSequenceCD1.cs
- SafeHandle.cs
- WebSysDisplayNameAttribute.cs
- EFTableProvider.cs
- UnaryExpression.cs
- ResourceSetExpression.cs
- DesignerMetadata.cs
- TextBoxBaseDesigner.cs
- QuaternionAnimationBase.cs
- DateBoldEvent.cs
- ExpressionBuilderCollection.cs
- COM2ExtendedBrowsingHandler.cs
- CultureInfoConverter.cs
- TypedServiceOperationListItem.cs
- DataGridHeadersVisibilityToVisibilityConverter.cs
- LinearGradientBrush.cs
- ServicePoint.cs
- Pair.cs
- ArrangedElementCollection.cs
- WhileDesigner.xaml.cs
- TemplatePropertyEntry.cs
- SrgsElement.cs
- recordstate.cs
- ParentQuery.cs
- IDictionary.cs
- SuppressMergeCheckAttribute.cs
- FastPropertyAccessor.cs
- PlaceHolder.cs
- HashLookup.cs
- Content.cs
- BamlBinaryWriter.cs
- EventSetterHandlerConverter.cs
- DecoderReplacementFallback.cs
- X500Name.cs
- QualificationDataAttribute.cs
- ObjectViewListener.cs
- TemplateControlCodeDomTreeGenerator.cs
- SignedXml.cs