Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / ndp / fx / src / DataWeb / Client / System / Data / Services / Client / DataServiceRequest.cs / 1 / DataServiceRequest.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // //// query request object // //--------------------------------------------------------------------- namespace System.Data.Services.Client { using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; #if !ASTORIA_LIGHT // Data.Services http stack using System.Net; #else using System.Data.Services.Http; #endif using System.Xml; ///non-generic placeholder for generic implementation public abstract class DataServiceRequest { ///internal constructor so that only our assembly can provide an implementation internal DataServiceRequest() { } ///Element Type public abstract Type ElementType { get; } ///Gets the URI for a the query public abstract Uri RequestUri { get; } ///Gets the URI for a the query ///a string with the URI public override string ToString() { return this.RequestUri.ToString(); } ////// get an enumerable materializes the objects the response /// ///element type /// context /// reader /// elementType ///an enumerable internal static object CreateMaterializer(DataServiceContext context, XmlReader reader, Type elementType) { Debug.Assert(null == elementType, "non-null elementType with strongly typed create delegate"); return new MaterializeAtom.MaterializeAtomT (context, reader); } /// /// get an enumerable materializes the objects the response /// ///element type /// context /// contentType /// method to get http response stream ///an enumerable internal static IEnumerableMaterialize (DataServiceContext context, string contentType, Func response) { Func create = CreateMaterializer ; return (IEnumerable )context.GetMaterializer(null, contentType, response, create); } /// /// Creates a instance of strongly typed DataServiceRequest with the given element type. /// /// element type for the DataServiceRequest. /// constructor parameter. ///returns the strongly typed DataServiceRequest instance. internal static DataServiceRequest GetInstance(Type elementType, Uri requestUri) { Type genericType = typeof(DataServiceRequest<>).MakeGenericType(elementType); return (DataServiceRequest)Activator.CreateInstance(genericType, new object[] { requestUri }); } #if !ASTORIA_LIGHT // Synchronous methods not available ////// execute uri and materialize result /// ///element type /// context /// uri to execute ///enumerable of results internal IEnumerableExecute (DataServiceContext context, Uri requestUri) { Debug.Assert(null != context, "context is null"); IEnumerable result = null; QueryAsyncResult response = null; try { DataServiceRequest serviceRequest = new DataServiceRequest (requestUri); HttpWebRequest request = context.CreateRequest(requestUri, XmlConstants.HttpMethodGet, false, null); response = new QueryAsyncResult(this, "Execute", serviceRequest, request, null, null); response.Execute(null); if (HttpStatusCode.NoContent != response.StatusCode) { result = Materialize (context, response.ContentType, response.GetResponseStream); } return (IEnumerable )response.GetResponse(result, typeof(TElement)); } catch (InvalidOperationException ex) { QueryOperationResponse operationResponse = response.GetResponse(result, typeof(TElement)); if (null != operationResponse) { operationResponse.Error = ex; throw new DataServiceQueryException(Strings.DataServiceException_GeneralError, ex, operationResponse); } throw; } } #endif /// enumerable list of materialized objects from stream without having to know T /// context /// contentType /// function to get response stream ///see summary internal abstract System.Collections.IEnumerable Materialize(DataServiceContext context, string contentType, Funcresponse); /// /// Begins an asynchronous request to an Internet resource. /// /// source of execute (DataServiceQuery or DataServiceContext /// context /// The AsyncCallback delegate. /// The state object for this request. ///An IAsyncResult that references the asynchronous request for a response. internal IAsyncResult BeginExecute(object source, DataServiceContext context, AsyncCallback callback, object state) { Debug.Assert(null != context, "context is null"); HttpWebRequest request = context.CreateRequest(this.RequestUri, XmlConstants.HttpMethodGet, false, null); QueryAsyncResult result = new QueryAsyncResult(source, "Execute", this, request, callback, state); result.BeginExecute(null); return result; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // //// query request object // //--------------------------------------------------------------------- namespace System.Data.Services.Client { using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; #if !ASTORIA_LIGHT // Data.Services http stack using System.Net; #else using System.Data.Services.Http; #endif using System.Xml; ///non-generic placeholder for generic implementation public abstract class DataServiceRequest { ///internal constructor so that only our assembly can provide an implementation internal DataServiceRequest() { } ///Element Type public abstract Type ElementType { get; } ///Gets the URI for a the query public abstract Uri RequestUri { get; } ///Gets the URI for a the query ///a string with the URI public override string ToString() { return this.RequestUri.ToString(); } ////// get an enumerable materializes the objects the response /// ///element type /// context /// reader /// elementType ///an enumerable internal static object CreateMaterializer(DataServiceContext context, XmlReader reader, Type elementType) { Debug.Assert(null == elementType, "non-null elementType with strongly typed create delegate"); return new MaterializeAtom.MaterializeAtomT (context, reader); } /// /// get an enumerable materializes the objects the response /// ///element type /// context /// contentType /// method to get http response stream ///an enumerable internal static IEnumerableMaterialize (DataServiceContext context, string contentType, Func response) { Func create = CreateMaterializer ; return (IEnumerable )context.GetMaterializer(null, contentType, response, create); } /// /// Creates a instance of strongly typed DataServiceRequest with the given element type. /// /// element type for the DataServiceRequest. /// constructor parameter. ///returns the strongly typed DataServiceRequest instance. internal static DataServiceRequest GetInstance(Type elementType, Uri requestUri) { Type genericType = typeof(DataServiceRequest<>).MakeGenericType(elementType); return (DataServiceRequest)Activator.CreateInstance(genericType, new object[] { requestUri }); } #if !ASTORIA_LIGHT // Synchronous methods not available ////// execute uri and materialize result /// ///element type /// context /// uri to execute ///enumerable of results internal IEnumerableExecute (DataServiceContext context, Uri requestUri) { Debug.Assert(null != context, "context is null"); IEnumerable result = null; QueryAsyncResult response = null; try { DataServiceRequest serviceRequest = new DataServiceRequest (requestUri); HttpWebRequest request = context.CreateRequest(requestUri, XmlConstants.HttpMethodGet, false, null); response = new QueryAsyncResult(this, "Execute", serviceRequest, request, null, null); response.Execute(null); if (HttpStatusCode.NoContent != response.StatusCode) { result = Materialize (context, response.ContentType, response.GetResponseStream); } return (IEnumerable )response.GetResponse(result, typeof(TElement)); } catch (InvalidOperationException ex) { QueryOperationResponse operationResponse = response.GetResponse(result, typeof(TElement)); if (null != operationResponse) { operationResponse.Error = ex; throw new DataServiceQueryException(Strings.DataServiceException_GeneralError, ex, operationResponse); } throw; } } #endif /// enumerable list of materialized objects from stream without having to know T /// context /// contentType /// function to get response stream ///see summary internal abstract System.Collections.IEnumerable Materialize(DataServiceContext context, string contentType, Funcresponse); /// /// Begins an asynchronous request to an Internet resource. /// /// source of execute (DataServiceQuery or DataServiceContext /// context /// The AsyncCallback delegate. /// The state object for this request. ///An IAsyncResult that references the asynchronous request for a response. internal IAsyncResult BeginExecute(object source, DataServiceContext context, AsyncCallback callback, object state) { Debug.Assert(null != context, "context is null"); HttpWebRequest request = context.CreateRequest(this.RequestUri, XmlConstants.HttpMethodGet, false, null); QueryAsyncResult result = new QueryAsyncResult(source, "Execute", this, request, callback, state); result.BeginExecute(null); return result; } } } // 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
- _NTAuthentication.cs
- AdvancedBindingPropertyDescriptor.cs
- ImageBrush.cs
- FixedPage.cs
- Convert.cs
- BitmapCodecInfoInternal.cs
- DesignTimeParseData.cs
- FactoryGenerator.cs
- WpfWebRequestHelper.cs
- AppDomainProtocolHandler.cs
- AnnotationResource.cs
- WebCategoryAttribute.cs
- GradientSpreadMethodValidation.cs
- ProcessHostFactoryHelper.cs
- InternalControlCollection.cs
- EditingMode.cs
- WeakKeyDictionary.cs
- HtmlToClrEventProxy.cs
- Operand.cs
- IconHelper.cs
- TreeNodeStyle.cs
- XmlObjectSerializerReadContext.cs
- BaseDataBoundControl.cs
- ServiceContractViewControl.Designer.cs
- DataContext.cs
- VisualCollection.cs
- DataGridViewCheckBoxColumn.cs
- MexTcpBindingCollectionElement.cs
- IndicShape.cs
- BufferedWebEventProvider.cs
- Win32Native.cs
- BaseDataList.cs
- AgileSafeNativeMemoryHandle.cs
- GridViewPageEventArgs.cs
- ToolStripDropTargetManager.cs
- QuaternionRotation3D.cs
- FlowStep.cs
- Style.cs
- AtlasWeb.Designer.cs
- XmlSchemaInclude.cs
- ConfigurationValidatorBase.cs
- RadialGradientBrush.cs
- ProgressBar.cs
- InvariantComparer.cs
- SynchronizingStream.cs
- VectorAnimation.cs
- MultiTrigger.cs
- ScriptResourceInfo.cs
- UITypeEditor.cs
- NamespaceCollection.cs
- WeakReferenceList.cs
- Queue.cs
- TopClause.cs
- OutputCacheModule.cs
- NegotiationTokenAuthenticatorStateCache.cs
- ToolBar.cs
- InkCanvas.cs
- ModuleConfigurationInfo.cs
- DataServiceQueryException.cs
- ProfileService.cs
- WorkflowQueue.cs
- XmlSchemaIdentityConstraint.cs
- TextBoxAutoCompleteSourceConverter.cs
- Point3DCollection.cs
- PersistenceException.cs
- MenuItemBinding.cs
- Rijndael.cs
- LoggedException.cs
- ContentFileHelper.cs
- SendMailErrorEventArgs.cs
- SafeRightsManagementHandle.cs
- RSAPKCS1SignatureDeformatter.cs
- WebPartTransformerAttribute.cs
- SslStream.cs
- JsonGlobals.cs
- RichTextBox.cs
- LayoutExceptionEventArgs.cs
- ConsumerConnectionPointCollection.cs
- GetRecipientListRequest.cs
- ReaderOutput.cs
- NavigatorOutput.cs
- XmlILAnnotation.cs
- SessionEndingEventArgs.cs
- UnauthorizedAccessException.cs
- TypeLibConverter.cs
- Ray3DHitTestResult.cs
- InputScopeManager.cs
- HostProtectionPermission.cs
- TextBoxRenderer.cs
- ManagementEventArgs.cs
- XmlSchemaSimpleTypeList.cs
- QueryRewriter.cs
- VectorAnimationBase.cs
- WebPartAddingEventArgs.cs
- NumericPagerField.cs
- DataGridViewRowStateChangedEventArgs.cs
- RayMeshGeometry3DHitTestResult.cs
- StructuredTypeInfo.cs
- SineEase.cs
- AssociatedControlConverter.cs