Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / Framework / System / Windows / Documents / PageContentAsyncResult.cs / 1 / PageContentAsyncResult.cs
//----------------------------------------------------------------------------
//
// Copyright (C) 2004 by Microsoft Corporation. All rights reserved.
//
//
// Description:
// Implements the PageContentAsyncResult
//
// History:
// 02/25/2004 - Zhenbin Xu (ZhenbinX) - Created.
//
//
//---------------------------------------------------------------------------
namespace System.Windows.Documents
{
using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Threading;
using System.Threading;
using MS.Internal;
using MS.Internal.AppModel;
using MS.Internal.Utility;
using MS.Internal.Navigation;
using MS.Utility;
using System.Reflection;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Net;
using System.IO.Packaging;
///
/// IAsyncResult for GetPageAsync. This item is passed around and queued up during various
/// phase of async call.
///
internal sealed class PageContentAsyncResult : IAsyncResult
{
//-------------------------------------------------------------------
//
// Internal enum
//
//---------------------------------------------------------------------
internal enum GetPageStatus
{
Loading,
Cancelled,
Finished
}
//--------------------------------------------------------------------
//
// Ctor
//
//---------------------------------------------------------------------
#region Ctor
internal PageContentAsyncResult(AsyncCallback callback, object state, Dispatcher dispatcher, Uri baseUri, Uri source, FixedPage child)
{
this._dispatcher = dispatcher;
this._isCompleted = false;
this._completedSynchronously = false;
this._callback = callback;
this._asyncState = state;
this._getpageStatus = GetPageStatus.Loading;
this._child = child;
this._baseUri = baseUri;
Debug.Assert(source == null || source.IsAbsoluteUri);
this._source = source;
}
#endregion Ctor
//--------------------------------------------------------------------
//
// Public Methods
//
//----------------------------------------------------------------------
//-------------------------------------------------------------------
//
// Public Properties
//
//----------------------------------------------------------------------
#region IAsyncResult
//---------------------------------------------------------------------
///
/// Gets a user-defined object that contains information about
/// this GetPageAsync call
///
public object AsyncState
{
get { return _asyncState; }
}
//---------------------------------------------------------------------
///
/// Gets a WaitHandle that is used to wait for the asynchrounus
/// GetPageAsync to complete. We are not providing WaitHandle
/// since this can be called on the main UIThread.
///
public WaitHandle AsyncWaitHandle
{
get { Debug.Assert(false); return null; }
}
//---------------------------------------------------------------------
///
/// Gets an indication of whether the asynchronous GetPage
/// completed synchronously.
///
public bool CompletedSynchronously
{
get { return _completedSynchronously; }
}
//----------------------------------------------------------------------
///
/// Gets an indication whether the asynchronous GetPage has finished
///
public bool IsCompleted
{
get { return _isCompleted; }
}
#endregion IAsyncResult
//-------------------------------------------------------------------
//
// Internal Methods
//
//----------------------------------------------------------------------
#region DispatcherOperationCallback
//----------------------------------------------------------------------
internal object Dispatch(object arg)
{
if (this._exception != null)
{
// force finish if there was any exception
this._getpageStatus = GetPageStatus.Finished;
}
switch (this._getpageStatus)
{
case GetPageStatus.Loading:
try
{
if (this._child != null)
{
this._completedSynchronously = true;
this._result = this._child;
_getpageStatus = GetPageStatus.Finished;
goto case GetPageStatus.Finished;
}
//
// Note if _source == null, exception will
// be thrown.
//
Stream responseStream = null;
object o = null;
WebResponse response = WpfWebRequestHelper.CreateRequestAndGetResponse(this._source);
responseStream = response.GetResponseStream();
ParserContext pc = new ParserContext();
pc.BaseUri = this._source;
XpsValidatingLoader loader = new XpsValidatingLoader();
o = loader.Load(responseStream, _baseUri, pc, new ContentType(response.ContentType));
if (o == null)
{
throw new ApplicationException(SR.Get(SRID.PageContentUnsupportedMimeType));
}
_result = o as FixedPage;
if (_result == null)
{
throw new ApplicationException(SR.Get(SRID.PageContentUnsupportedPageType, o.GetType()));
}
if (_result.IsInitialized)
{
responseStream.Close();
}
else
{
_pendingStream = responseStream;
_result.Initialized += new EventHandler(_OnPaserFinished);
}
_getpageStatus = GetPageStatus.Finished;
}
catch (ApplicationException e)
{
this._exception = e;
}
goto case GetPageStatus.Finished;
case GetPageStatus.Cancelled:
// do nothing
goto case GetPageStatus.Finished;
case GetPageStatus.Finished:
_isCompleted = true;
if (_callback != null)
{
_callback(this);
}
break;
}
return null;
}
#endregion DispatcherOperationCallback
//-----------------------------------------------------------------
internal void Cancel()
{
_getpageStatus = GetPageStatus.Cancelled;
//
}
internal void Wait()
{
_dispatcherOperation.Wait();
}
//--------------------------------------------------------------------
//
// Internal Properties
//
//---------------------------------------------------------------------
#region Internal Properties
//---------------------------------------------------------------------
internal Exception Exception
{
get { return _exception; }
}
//-----------------------------------------------------------------
internal bool IsCancelled
{
get { return _getpageStatus == GetPageStatus.Cancelled; }
}
internal DispatcherOperation DispatcherOperation
{
set { _dispatcherOperation = value; }
}
//------------------------------------------------------------------
internal FixedPage Result
{
get { return _result; }
}
#endregion Internal Properties
//-------------------------------------------------------------------
//
// Private Methods
//
//----------------------------------------------------------------------
#region Private Methods
private void _OnPaserFinished(object sender, EventArgs args)
{
if (_pendingStream != null)
{
_pendingStream.Close();
_pendingStream = null;
}
}
#endregion Private Methods
//--------------------------------------------------------------------
//
// Private Fields
//
//---------------------------------------------------------------------
#region Private
private object _asyncState;
private bool _isCompleted;
private bool _completedSynchronously;
private AsyncCallback _callback;
private Exception _exception;
private GetPageStatus _getpageStatus;
private Uri _baseUri;
private Uri _source;
private FixedPage _child;
private Dispatcher _dispatcher;
private FixedPage _result;
private Stream _pendingStream;
private DispatcherOperation _dispatcherOperation;
#endregion Private
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------
//
// Copyright (C) 2004 by Microsoft Corporation. All rights reserved.
//
//
// Description:
// Implements the PageContentAsyncResult
//
// History:
// 02/25/2004 - Zhenbin Xu (ZhenbinX) - Created.
//
//
//---------------------------------------------------------------------------
namespace System.Windows.Documents
{
using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Threading;
using System.Threading;
using MS.Internal;
using MS.Internal.AppModel;
using MS.Internal.Utility;
using MS.Internal.Navigation;
using MS.Utility;
using System.Reflection;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Net;
using System.IO.Packaging;
///
/// IAsyncResult for GetPageAsync. This item is passed around and queued up during various
/// phase of async call.
///
internal sealed class PageContentAsyncResult : IAsyncResult
{
//-------------------------------------------------------------------
//
// Internal enum
//
//---------------------------------------------------------------------
internal enum GetPageStatus
{
Loading,
Cancelled,
Finished
}
//--------------------------------------------------------------------
//
// Ctor
//
//---------------------------------------------------------------------
#region Ctor
internal PageContentAsyncResult(AsyncCallback callback, object state, Dispatcher dispatcher, Uri baseUri, Uri source, FixedPage child)
{
this._dispatcher = dispatcher;
this._isCompleted = false;
this._completedSynchronously = false;
this._callback = callback;
this._asyncState = state;
this._getpageStatus = GetPageStatus.Loading;
this._child = child;
this._baseUri = baseUri;
Debug.Assert(source == null || source.IsAbsoluteUri);
this._source = source;
}
#endregion Ctor
//--------------------------------------------------------------------
//
// Public Methods
//
//----------------------------------------------------------------------
//-------------------------------------------------------------------
//
// Public Properties
//
//----------------------------------------------------------------------
#region IAsyncResult
//---------------------------------------------------------------------
///
/// Gets a user-defined object that contains information about
/// this GetPageAsync call
///
public object AsyncState
{
get { return _asyncState; }
}
//---------------------------------------------------------------------
///
/// Gets a WaitHandle that is used to wait for the asynchrounus
/// GetPageAsync to complete. We are not providing WaitHandle
/// since this can be called on the main UIThread.
///
public WaitHandle AsyncWaitHandle
{
get { Debug.Assert(false); return null; }
}
//---------------------------------------------------------------------
///
/// Gets an indication of whether the asynchronous GetPage
/// completed synchronously.
///
public bool CompletedSynchronously
{
get { return _completedSynchronously; }
}
//----------------------------------------------------------------------
///
/// Gets an indication whether the asynchronous GetPage has finished
///
public bool IsCompleted
{
get { return _isCompleted; }
}
#endregion IAsyncResult
//-------------------------------------------------------------------
//
// Internal Methods
//
//----------------------------------------------------------------------
#region DispatcherOperationCallback
//----------------------------------------------------------------------
internal object Dispatch(object arg)
{
if (this._exception != null)
{
// force finish if there was any exception
this._getpageStatus = GetPageStatus.Finished;
}
switch (this._getpageStatus)
{
case GetPageStatus.Loading:
try
{
if (this._child != null)
{
this._completedSynchronously = true;
this._result = this._child;
_getpageStatus = GetPageStatus.Finished;
goto case GetPageStatus.Finished;
}
//
// Note if _source == null, exception will
// be thrown.
//
Stream responseStream = null;
object o = null;
WebResponse response = WpfWebRequestHelper.CreateRequestAndGetResponse(this._source);
responseStream = response.GetResponseStream();
ParserContext pc = new ParserContext();
pc.BaseUri = this._source;
XpsValidatingLoader loader = new XpsValidatingLoader();
o = loader.Load(responseStream, _baseUri, pc, new ContentType(response.ContentType));
if (o == null)
{
throw new ApplicationException(SR.Get(SRID.PageContentUnsupportedMimeType));
}
_result = o as FixedPage;
if (_result == null)
{
throw new ApplicationException(SR.Get(SRID.PageContentUnsupportedPageType, o.GetType()));
}
if (_result.IsInitialized)
{
responseStream.Close();
}
else
{
_pendingStream = responseStream;
_result.Initialized += new EventHandler(_OnPaserFinished);
}
_getpageStatus = GetPageStatus.Finished;
}
catch (ApplicationException e)
{
this._exception = e;
}
goto case GetPageStatus.Finished;
case GetPageStatus.Cancelled:
// do nothing
goto case GetPageStatus.Finished;
case GetPageStatus.Finished:
_isCompleted = true;
if (_callback != null)
{
_callback(this);
}
break;
}
return null;
}
#endregion DispatcherOperationCallback
//-----------------------------------------------------------------
internal void Cancel()
{
_getpageStatus = GetPageStatus.Cancelled;
//
}
internal void Wait()
{
_dispatcherOperation.Wait();
}
//--------------------------------------------------------------------
//
// Internal Properties
//
//---------------------------------------------------------------------
#region Internal Properties
//---------------------------------------------------------------------
internal Exception Exception
{
get { return _exception; }
}
//-----------------------------------------------------------------
internal bool IsCancelled
{
get { return _getpageStatus == GetPageStatus.Cancelled; }
}
internal DispatcherOperation DispatcherOperation
{
set { _dispatcherOperation = value; }
}
//------------------------------------------------------------------
internal FixedPage Result
{
get { return _result; }
}
#endregion Internal Properties
//-------------------------------------------------------------------
//
// Private Methods
//
//----------------------------------------------------------------------
#region Private Methods
private void _OnPaserFinished(object sender, EventArgs args)
{
if (_pendingStream != null)
{
_pendingStream.Close();
_pendingStream = null;
}
}
#endregion Private Methods
//--------------------------------------------------------------------
//
// Private Fields
//
//---------------------------------------------------------------------
#region Private
private object _asyncState;
private bool _isCompleted;
private bool _completedSynchronously;
private AsyncCallback _callback;
private Exception _exception;
private GetPageStatus _getpageStatus;
private Uri _baseUri;
private Uri _source;
private FixedPage _child;
private Dispatcher _dispatcher;
private FixedPage _result;
private Stream _pendingStream;
private DispatcherOperation _dispatcherOperation;
#endregion Private
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SQLCharsStorage.cs
- GeometryDrawing.cs
- TypeBuilder.cs
- IpcManager.cs
- FreezableCollection.cs
- EntityWithChangeTrackerStrategy.cs
- OverrideMode.cs
- ProxySimple.cs
- SqlConnection.cs
- FlagsAttribute.cs
- IIS7WorkerRequest.cs
- Expression.cs
- TextTreeObjectNode.cs
- BindableTemplateBuilder.cs
- PlatformCulture.cs
- MasterPageBuildProvider.cs
- QuaternionKeyFrameCollection.cs
- IsolatedStorageFileStream.cs
- MenuEventArgs.cs
- StoreContentChangedEventArgs.cs
- DistributedTransactionPermission.cs
- XmlSchemaIdentityConstraint.cs
- __FastResourceComparer.cs
- MediaPlayer.cs
- UnsafeNativeMethods.cs
- Form.cs
- ColorConverter.cs
- SQLRoleProvider.cs
- DataList.cs
- XmlTextReader.cs
- EastAsianLunisolarCalendar.cs
- CellTreeNode.cs
- SQLInt64.cs
- OdbcDataReader.cs
- TabControl.cs
- HwndProxyElementProvider.cs
- ConditionedDesigner.cs
- PerfCounters.cs
- PointValueSerializer.cs
- HttpBrowserCapabilitiesBase.cs
- SerializationException.cs
- PropertySet.cs
- ValidationResults.cs
- TextParentUndoUnit.cs
- SqlNodeAnnotations.cs
- PartialCachingAttribute.cs
- AnnotationMap.cs
- TabControlDesigner.cs
- InputBinding.cs
- Quad.cs
- CultureSpecificStringDictionary.cs
- FileSystemWatcher.cs
- EncoderExceptionFallback.cs
- CodeTypeMember.cs
- TransportManager.cs
- DirectoryLocalQuery.cs
- UDPClient.cs
- SendSecurityHeader.cs
- filewebresponse.cs
- WindowHideOrCloseTracker.cs
- ConnectionsZone.cs
- TemplateBuilder.cs
- Encoder.cs
- ReferencedAssemblyResolver.cs
- SendingRequestEventArgs.cs
- CopyAttributesAction.cs
- ScriptControlManager.cs
- TimelineCollection.cs
- KeyEventArgs.cs
- WebPartCancelEventArgs.cs
- ProcessDesigner.cs
- WebException.cs
- TableAdapterManagerMethodGenerator.cs
- HostProtectionPermission.cs
- InputLangChangeRequestEvent.cs
- Int16Animation.cs
- RightsManagementEncryptionTransform.cs
- ComponentResourceManager.cs
- DbMetaDataColumnNames.cs
- SchemaManager.cs
- TextBoxView.cs
- TrackingExtract.cs
- DataGridViewRowHeightInfoNeededEventArgs.cs
- EdmMember.cs
- CodeDirectionExpression.cs
- PathGradientBrush.cs
- WebControlsSection.cs
- SmiGettersStream.cs
- PrintPageEvent.cs
- CodeSnippetTypeMember.cs
- IBuiltInEvidence.cs
- MexBindingBindingCollectionElement.cs
- CFGGrammar.cs
- TemplatedEditableDesignerRegion.cs
- InheritanceContextHelper.cs
- ImageMapEventArgs.cs
- CoreChannel.cs
- CaseInsensitiveOrdinalStringComparer.cs
- WorkflowApplicationAbortedException.cs
- BrushValueSerializer.cs