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 / BatchServiceHost.cs / 1 / BatchServiceHost.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // //// Provides an internal implementation for IDataServiceHost to keep track of states // for batch operations // // // @owner [....] //--------------------------------------------------------------------- namespace System.Data.Services { #region Namespaces. using System; using System.Collections.Specialized; using System.Diagnostics; using System.IO; using System.Web; #endregion Namespaces. ////// Keeps track of the request and response headers for each /// operation in the batch /// internal class BatchServiceHost : IDataServiceHost { #region Private fields. ///Response separator string. private readonly string boundary; ///Request headers. private readonly CachedRequestParams requestParams; ///Request Stream. private readonly Stream requestStream; ///Content Id for this operation. private readonly string contentId; ///Output writer. private readonly StreamWriter writer; ///List of query parameters as specified in the request uri. private NameValueCollection queryParameters; ///The value for the 'Allow' response header. private string responseAllowHeader; ///Value of the response Cache-Control header. private string responseCacheControl; ///Value of the response Content-Type header. private string responseContentType; ///Value of the response ETag header. private string responseETag; ///Value of the response Location header. private string responseLocation; ///Value of the response StatusCode header. private int responseStatusCode; ///The value for the DataServiceVersion response header. private string responseVersion; #endregion Private fields. #region Constructors. ////// Initializes a new dummy host for the batch request. /// This host represents a single operation in the batch. /// /// cached request headers. /// Request stream (possibly null, eg for a DELETE operation). /// content id for the given operation host. /// Response separator string. /// Output writer. internal BatchServiceHost(CachedRequestParams requestParams, Stream requestStream, string contentId, string boundary, StreamWriter writer) { Debug.Assert(requestParams != null, "requestParams != null"); Debug.Assert(boundary != null, "boundary != null"); Debug.Assert(writer != null, "writer != null"); this.requestParams = requestParams; this.requestStream = requestStream; this.contentId = contentId; this.boundary = boundary; this.writer = writer; } ////// Initializes a host for error scenarios - something to which we can write the response header values /// and write them to the underlying stream. /// /// Response separator string. /// Output writer. internal BatchServiceHost(string boundary, StreamWriter writer) { Debug.Assert(boundary != null, "boundary != null"); Debug.Assert(writer != null, "writer != null"); this.boundary = boundary; this.writer = writer; } #endregion Constructors. #region Properties. ///Gets the absolute URI to the resource upon which to apply the request. Uri IDataServiceHost.AbsoluteRequestUri { get { if (this.requestParams != null) { return this.requestParams.AbsoluteRequestUri; } return null; } } ///Gets the absolute URI to the service. Uri IDataServiceHost.AbsoluteServiceUri { get { if (this.requestParams != null) { return this.requestParams.AbsoluteServiceUri; } return null; } } ////// Gets the character set encoding that the client requested, /// possibly null. /// string IDataServiceHost.RequestAccept { get { if (this.requestParams != null) { return this.requestParams.Accept; } return null; } } ////// Gets the character set encoding that the client requested, /// possibly null. /// string IDataServiceHost.RequestAcceptCharSet { get { if (this.requestParams != null) { return this.requestParams.AcceptCharset; } return null; } } ///Gets the HTTP MIME type of the input stream. string IDataServiceHost.RequestContentType { get { if (this.requestParams != null) { return this.requestParams.ContentType; } return null; } } ////// Gets the HTTP data transfer method (such as GET, POST, or HEAD) used by the client. /// string IDataServiceHost.RequestHttpMethod { get { if (this.requestParams != null) { return this.requestParams.HttpMethod; } return null; } } ///Gets the value of the If-Match header from the request made string IDataServiceHost.RequestIfMatch { get { if (this.requestParams != null) { return this.requestParams.IfMatch; } return null; } } ///Gets the value of the If-None-Match header from the request made string IDataServiceHost.RequestIfNoneMatch { get { if (this.requestParams != null) { return this.requestParams.IfNoneMatch; } return null; } } ///Gets the value for the MaxDataServiceVersion request header. string IDataServiceHost.RequestMaxVersion { get { if (this.requestParams != null) { return this.requestParams.MaxVersion; } return null; } } ///Gets the value for the DataServiceVersion request header. string IDataServiceHost.RequestVersion { get { if (this.requestParams != null) { return this.requestParams.Version; } return null; } } ///Gets or sets the Cache-Control header on the response. string IDataServiceHost.ResponseCacheControl { get { return this.responseCacheControl; } set { this.responseCacheControl = value; } } ///Gets or sets the HTTP MIME type of the output stream. string IDataServiceHost.ResponseContentType { get { return this.responseContentType; } set { this.responseContentType = value; } } ///Gets/Sets the value of the ETag header on the outgoing response string IDataServiceHost.ResponseETag { get { return this.responseETag; } set { this.responseETag = value; } } ///Gets or sets the Location header on the response. string IDataServiceHost.ResponseLocation { get { return this.responseLocation; } set { this.responseLocation = value; } } ////// Gets/Sets the status code for the request made. /// int IDataServiceHost.ResponseStatusCode { get { return this.responseStatusCode; } set { this.responseStatusCode = value; } } ////// Gets the Stream IDataServiceHost.ResponseStream { get { // There is a batch stream for writing requests for batch operations. // Hence this method should never be called. throw Error.NotSupported(); } } ///to be written to send a response /// to the client. /// Gets or sets the value for the DataServiceVersion response header. string IDataServiceHost.ResponseVersion { get { return this.responseVersion; } set { this.responseVersion = value; } } ////// Gets the Stream IDataServiceHost.RequestStream { [DebuggerStepThrough] get { return this.requestStream; } } ///from which the request data can be read from /// to the client. /// Response separator string. internal string BoundaryString { get { return this.boundary; } } ///returns all the cached request headers internal CachedRequestParams RequestParams { get { return this.requestParams; } } ///The value for the 'Allow' response header. internal string ResponseAllowHeader { get { return this.responseAllowHeader; } } ////// Gets/Sets the content id as specified in the batch request. /// This same value is written out in the response headers also to allow mapping requests on the client. /// internal string ContentId { get { return this.contentId; } } ///Output writer. internal StreamWriter Writer { get { return this.writer; } } #endregion Properties. #region Methods. ///Gets the value for the specified item in the request query string. /// Item to return. ////// The value for the specified item in the request query string; /// null if string IDataServiceHost.GetQueryStringItem(string item) { this.GetUriAndQueryParameters(); string[] result = this.queryParameters.GetValues(item); if (result == null || result.Length == 0) { return null; } else if (result.Length == 1) { return result[0]; } else { throw DataServiceException.CreateBadRequestError( Strings.DataServiceHost_MoreThanOneQueryParameterSpecifiedWithTheGivenName(item, this.requestParams.AbsoluteRequestUri)); } } ///is not found. /// Method to handle a data service exception during processing. /// Exception handling description. void IDataServiceHost.ProcessException(HandleExceptionArgs args) { // This would typically set headers on the host. Debug.Assert(args != null, "args != null"); Debug.Assert(WebUtil.IsCatchableExceptionType(args.Exception), "WebUtil.IsCatchableExceptionType(args.Exception)"); this.responseStatusCode = args.ResponseStatusCode; this.responseContentType = args.ResponseContentType; this.responseAllowHeader = args.ResponseAllowHeader; // Only write the headers if the response is not written if (!args.ResponseWritten) { System.Data.Services.Serializers.BatchWriter.WriteBoundaryAndHeaders(this.writer, this, this.boundary); } } ////// Given the request uri, parse the uri and query parameters and cache them /// private void GetUriAndQueryParameters() { if (this.queryParameters == null) { Debug.Assert(this.queryParameters == null, "this.queryParameters == null"); this.queryParameters = HttpUtility.ParseQueryString(this.requestParams.AbsoluteRequestUri.Query); } } #endregion Methods. } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // //// Provides an internal implementation for IDataServiceHost to keep track of states // for batch operations // // // @owner [....] //--------------------------------------------------------------------- namespace System.Data.Services { #region Namespaces. using System; using System.Collections.Specialized; using System.Diagnostics; using System.IO; using System.Web; #endregion Namespaces. ////// Keeps track of the request and response headers for each /// operation in the batch /// internal class BatchServiceHost : IDataServiceHost { #region Private fields. ///Response separator string. private readonly string boundary; ///Request headers. private readonly CachedRequestParams requestParams; ///Request Stream. private readonly Stream requestStream; ///Content Id for this operation. private readonly string contentId; ///Output writer. private readonly StreamWriter writer; ///List of query parameters as specified in the request uri. private NameValueCollection queryParameters; ///The value for the 'Allow' response header. private string responseAllowHeader; ///Value of the response Cache-Control header. private string responseCacheControl; ///Value of the response Content-Type header. private string responseContentType; ///Value of the response ETag header. private string responseETag; ///Value of the response Location header. private string responseLocation; ///Value of the response StatusCode header. private int responseStatusCode; ///The value for the DataServiceVersion response header. private string responseVersion; #endregion Private fields. #region Constructors. ////// Initializes a new dummy host for the batch request. /// This host represents a single operation in the batch. /// /// cached request headers. /// Request stream (possibly null, eg for a DELETE operation). /// content id for the given operation host. /// Response separator string. /// Output writer. internal BatchServiceHost(CachedRequestParams requestParams, Stream requestStream, string contentId, string boundary, StreamWriter writer) { Debug.Assert(requestParams != null, "requestParams != null"); Debug.Assert(boundary != null, "boundary != null"); Debug.Assert(writer != null, "writer != null"); this.requestParams = requestParams; this.requestStream = requestStream; this.contentId = contentId; this.boundary = boundary; this.writer = writer; } ////// Initializes a host for error scenarios - something to which we can write the response header values /// and write them to the underlying stream. /// /// Response separator string. /// Output writer. internal BatchServiceHost(string boundary, StreamWriter writer) { Debug.Assert(boundary != null, "boundary != null"); Debug.Assert(writer != null, "writer != null"); this.boundary = boundary; this.writer = writer; } #endregion Constructors. #region Properties. ///Gets the absolute URI to the resource upon which to apply the request. Uri IDataServiceHost.AbsoluteRequestUri { get { if (this.requestParams != null) { return this.requestParams.AbsoluteRequestUri; } return null; } } ///Gets the absolute URI to the service. Uri IDataServiceHost.AbsoluteServiceUri { get { if (this.requestParams != null) { return this.requestParams.AbsoluteServiceUri; } return null; } } ////// Gets the character set encoding that the client requested, /// possibly null. /// string IDataServiceHost.RequestAccept { get { if (this.requestParams != null) { return this.requestParams.Accept; } return null; } } ////// Gets the character set encoding that the client requested, /// possibly null. /// string IDataServiceHost.RequestAcceptCharSet { get { if (this.requestParams != null) { return this.requestParams.AcceptCharset; } return null; } } ///Gets the HTTP MIME type of the input stream. string IDataServiceHost.RequestContentType { get { if (this.requestParams != null) { return this.requestParams.ContentType; } return null; } } ////// Gets the HTTP data transfer method (such as GET, POST, or HEAD) used by the client. /// string IDataServiceHost.RequestHttpMethod { get { if (this.requestParams != null) { return this.requestParams.HttpMethod; } return null; } } ///Gets the value of the If-Match header from the request made string IDataServiceHost.RequestIfMatch { get { if (this.requestParams != null) { return this.requestParams.IfMatch; } return null; } } ///Gets the value of the If-None-Match header from the request made string IDataServiceHost.RequestIfNoneMatch { get { if (this.requestParams != null) { return this.requestParams.IfNoneMatch; } return null; } } ///Gets the value for the MaxDataServiceVersion request header. string IDataServiceHost.RequestMaxVersion { get { if (this.requestParams != null) { return this.requestParams.MaxVersion; } return null; } } ///Gets the value for the DataServiceVersion request header. string IDataServiceHost.RequestVersion { get { if (this.requestParams != null) { return this.requestParams.Version; } return null; } } ///Gets or sets the Cache-Control header on the response. string IDataServiceHost.ResponseCacheControl { get { return this.responseCacheControl; } set { this.responseCacheControl = value; } } ///Gets or sets the HTTP MIME type of the output stream. string IDataServiceHost.ResponseContentType { get { return this.responseContentType; } set { this.responseContentType = value; } } ///Gets/Sets the value of the ETag header on the outgoing response string IDataServiceHost.ResponseETag { get { return this.responseETag; } set { this.responseETag = value; } } ///Gets or sets the Location header on the response. string IDataServiceHost.ResponseLocation { get { return this.responseLocation; } set { this.responseLocation = value; } } ////// Gets/Sets the status code for the request made. /// int IDataServiceHost.ResponseStatusCode { get { return this.responseStatusCode; } set { this.responseStatusCode = value; } } ////// Gets the Stream IDataServiceHost.ResponseStream { get { // There is a batch stream for writing requests for batch operations. // Hence this method should never be called. throw Error.NotSupported(); } } ///to be written to send a response /// to the client. /// Gets or sets the value for the DataServiceVersion response header. string IDataServiceHost.ResponseVersion { get { return this.responseVersion; } set { this.responseVersion = value; } } ////// Gets the Stream IDataServiceHost.RequestStream { [DebuggerStepThrough] get { return this.requestStream; } } ///from which the request data can be read from /// to the client. /// Response separator string. internal string BoundaryString { get { return this.boundary; } } ///returns all the cached request headers internal CachedRequestParams RequestParams { get { return this.requestParams; } } ///The value for the 'Allow' response header. internal string ResponseAllowHeader { get { return this.responseAllowHeader; } } ////// Gets/Sets the content id as specified in the batch request. /// This same value is written out in the response headers also to allow mapping requests on the client. /// internal string ContentId { get { return this.contentId; } } ///Output writer. internal StreamWriter Writer { get { return this.writer; } } #endregion Properties. #region Methods. ///Gets the value for the specified item in the request query string. /// Item to return. ////// The value for the specified item in the request query string; /// null if string IDataServiceHost.GetQueryStringItem(string item) { this.GetUriAndQueryParameters(); string[] result = this.queryParameters.GetValues(item); if (result == null || result.Length == 0) { return null; } else if (result.Length == 1) { return result[0]; } else { throw DataServiceException.CreateBadRequestError( Strings.DataServiceHost_MoreThanOneQueryParameterSpecifiedWithTheGivenName(item, this.requestParams.AbsoluteRequestUri)); } } ///is not found. /// Method to handle a data service exception during processing. /// Exception handling description. void IDataServiceHost.ProcessException(HandleExceptionArgs args) { // This would typically set headers on the host. Debug.Assert(args != null, "args != null"); Debug.Assert(WebUtil.IsCatchableExceptionType(args.Exception), "WebUtil.IsCatchableExceptionType(args.Exception)"); this.responseStatusCode = args.ResponseStatusCode; this.responseContentType = args.ResponseContentType; this.responseAllowHeader = args.ResponseAllowHeader; // Only write the headers if the response is not written if (!args.ResponseWritten) { System.Data.Services.Serializers.BatchWriter.WriteBoundaryAndHeaders(this.writer, this, this.boundary); } } ////// Given the request uri, parse the uri and query parameters and cache them /// private void GetUriAndQueryParameters() { if (this.queryParameters == null) { Debug.Assert(this.queryParameters == null, "this.queryParameters == null"); this.queryParameters = HttpUtility.ParseQueryString(this.requestParams.AbsoluteRequestUri.Query); } } #endregion Methods. } } // 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
- TreeWalkHelper.cs
- MessageQueuePermissionEntryCollection.cs
- Main.cs
- CodeConstructor.cs
- DataRowView.cs
- DataGridViewAddColumnDialog.cs
- WebPartConnectionsConnectVerb.cs
- DbException.cs
- EdgeProfileValidation.cs
- XNodeSchemaApplier.cs
- ProviderException.cs
- VoiceInfo.cs
- ConfigurationValues.cs
- DataSpaceManager.cs
- CodeSubDirectory.cs
- Journaling.cs
- RequestUriProcessor.cs
- SettingsSection.cs
- MatcherBuilder.cs
- PKCS1MaskGenerationMethod.cs
- RequestCache.cs
- Propagator.JoinPropagator.JoinPredicateVisitor.cs
- BeginStoryboard.cs
- StatusStrip.cs
- TraceContextEventArgs.cs
- IUnknownConstantAttribute.cs
- _DigestClient.cs
- BindingCollection.cs
- MimeTypeMapper.cs
- RedBlackList.cs
- OdbcReferenceCollection.cs
- DropShadowBitmapEffect.cs
- UpnEndpointIdentityExtension.cs
- FontStyles.cs
- ErrorEventArgs.cs
- AliasedExpr.cs
- StreamReader.cs
- ActiveXSite.cs
- DispatcherHooks.cs
- WorkflowEventArgs.cs
- SqlDataSourceCommandEventArgs.cs
- ObjectSerializerFactory.cs
- SessionEndingCancelEventArgs.cs
- LinqDataView.cs
- ServicePointManagerElement.cs
- MDIWindowDialog.cs
- MatrixTransform3D.cs
- SoapHeaderAttribute.cs
- BufferBuilder.cs
- CompModSwitches.cs
- GPPOINT.cs
- Restrictions.cs
- EventHandlerService.cs
- initElementDictionary.cs
- webclient.cs
- TimeoutValidationAttribute.cs
- UpDownBase.cs
- DataGridViewCellPaintingEventArgs.cs
- LinkConverter.cs
- LongPath.cs
- DataGridViewSortCompareEventArgs.cs
- XmlnsCache.cs
- WebDescriptionAttribute.cs
- StringFormat.cs
- JavaScriptString.cs
- DbProviderFactory.cs
- InkCanvasSelection.cs
- WindowsFormsSynchronizationContext.cs
- JournalEntryListConverter.cs
- CollectionViewProxy.cs
- WeakEventManager.cs
- Html32TextWriter.cs
- nulltextnavigator.cs
- DataColumnPropertyDescriptor.cs
- CryptoStream.cs
- PackageStore.cs
- SelectionService.cs
- BufferedGraphicsContext.cs
- ExeConfigurationFileMap.cs
- ListViewUpdateEventArgs.cs
- EnumUnknown.cs
- GridViewSortEventArgs.cs
- MenuItem.cs
- DiffuseMaterial.cs
- DataMisalignedException.cs
- DynamicDocumentPaginator.cs
- OAVariantLib.cs
- ByteStack.cs
- PlatformNotSupportedException.cs
- FrameworkElementFactoryMarkupObject.cs
- StringPropertyBuilder.cs
- SQLByte.cs
- DesignTimeTemplateParser.cs
- ControllableStoryboardAction.cs
- PriorityQueue.cs
- UidManager.cs
- FilePrompt.cs
- LinkDesigner.cs
- SHA384.cs
- WebControl.cs