Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.ServiceModel.Discovery / System / ServiceModel / Discovery / ProbeRequestResponseAsyncResult.cs / 1305376 / ProbeRequestResponseAsyncResult.cs
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//---------------------------------------------------------------
namespace System.ServiceModel.Discovery
{
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Runtime;
abstract class ProbeRequestResponseAsyncResult : AsyncResult
{
readonly IDiscoveryServiceImplementation discoveryServiceImpl;
readonly FindRequestResponseContext findRequest;
readonly DiscoveryOperationContext context;
static AsyncCompletion onOnFindCompletedCallback = new AsyncCompletion(OnOnFindCompleted);
bool isFindCompleted;
[Fx.Tag.SynchronizationObject]
object findCompletedLock;
[SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
protected ProbeRequestResponseAsyncResult(
TProbeMessage probeMessage,
IDiscoveryServiceImplementation discoveryServiceImpl,
AsyncCallback callback,
object state)
: base(callback, state)
{
Fx.Assert(probeMessage != null, "The probeMessage must be non null.");
Fx.Assert(discoveryServiceImpl != null, "The discoveryServiceImpl must be non null.");
this.discoveryServiceImpl = discoveryServiceImpl;
this.findCompletedLock = new object();
if (!this.Validate(probeMessage))
{
this.Complete(true);
return;
}
else
{
this.context = new DiscoveryOperationContext(OperationContext.Current);
this.findRequest = new FindRequestResponseContext(this.GetFindCriteria(probeMessage), this);
if (this.ProcessFindRequest())
{
this.Complete(true);
return;
}
}
}
protected virtual bool Validate(TProbeMessage probeMessage)
{
return (DiscoveryService.EnsureMessageId() &&
this.ValidateContent(probeMessage) &&
this.EnsureNotDuplicate());
}
protected abstract bool ValidateContent(TProbeMessage probeMessage);
protected abstract FindCriteria GetFindCriteria(TProbeMessage probeMessage);
protected abstract TResponseMessage GetProbeResponse(
DiscoveryMessageSequence discoveryMessageSequence,
Collection matchingEndpoints);
protected TResponseMessage End()
{
this.context.AddressRequestResponseMessage(OperationContext.Current);
return this.GetProbeResponse(
this.discoveryServiceImpl.GetNextMessageSequence(),
this.findRequest.MatchingEndpoints);
}
static bool OnOnFindCompleted(IAsyncResult result)
{
ProbeRequestResponseAsyncResult thisPtr =
(ProbeRequestResponseAsyncResult)result.AsyncState;
lock (thisPtr.findCompletedLock)
{
thisPtr.isFindCompleted = true;
}
thisPtr.discoveryServiceImpl.EndFind(result);
return true;
}
bool ProcessFindRequest()
{
IAsyncResult result = this.discoveryServiceImpl.BeginFind(
this.findRequest,
this.PrepareAsyncCompletion(onOnFindCompletedCallback),
this);
return (result.CompletedSynchronously && OnOnFindCompleted(result));
}
bool EnsureNotDuplicate()
{
bool isDuplicate = this.discoveryServiceImpl.IsDuplicate(OperationContext.Current.IncomingMessageHeaders.MessageId);
if (isDuplicate && TD.DuplicateDiscoveryMessageIsEnabled())
{
TD.DuplicateDiscoveryMessage(
ProtocolStrings.TracingStrings.Probe,
OperationContext.Current.IncomingMessageHeaders.MessageId.ToString());
}
return !isDuplicate;
}
class FindRequestResponseContext : FindRequestContext
{
Collection matchingEndpoints;
readonly ProbeRequestResponseAsyncResult probeRequestResponseAsyncResult;
public FindRequestResponseContext(
FindCriteria criteria,
ProbeRequestResponseAsyncResult probeRequestResponseAsyncResult)
: base(criteria)
{
this.matchingEndpoints = new Collection();
this.probeRequestResponseAsyncResult = probeRequestResponseAsyncResult;
}
public Collection MatchingEndpoints
{
get
{
return this.matchingEndpoints;
}
}
protected override void OnAddMatchingEndpoint(EndpointDiscoveryMetadata matchingEndpoint)
{
lock (this.probeRequestResponseAsyncResult.findCompletedLock)
{
if (this.probeRequestResponseAsyncResult.isFindCompleted)
{
throw FxTrace.Exception.AsError(
new InvalidOperationException(SR.DiscoveryCannotAddMatchingEndpoint));
}
else
{
this.matchingEndpoints.Add(matchingEndpoint);
}
}
}
}
}
}
// 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
- WebPageTraceListener.cs
- ImageAttributes.cs
- StreamGeometry.cs
- EdmToObjectNamespaceMap.cs
- PageAsyncTaskManager.cs
- ServiceCredentials.cs
- Type.cs
- RelationshipSet.cs
- Bold.cs
- SplitterDesigner.cs
- TraceHandler.cs
- ControlAdapter.cs
- Win32.cs
- EnumMember.cs
- PrintingPermissionAttribute.cs
- ProgressBar.cs
- ArrayTypeMismatchException.cs
- TraceData.cs
- VectorValueSerializer.cs
- SqlFacetAttribute.cs
- altserialization.cs
- SqlBooleanizer.cs
- ConnectionManagementElement.cs
- XPathAncestorQuery.cs
- XmlStringTable.cs
- NullRuntimeConfig.cs
- HybridObjectCache.cs
- GrammarBuilder.cs
- _NTAuthentication.cs
- FrameSecurityDescriptor.cs
- DataSetUtil.cs
- ScrollData.cs
- GetLedgerRequest.cs
- WebResponse.cs
- SystemNetworkInterface.cs
- WebPartConnectionCollection.cs
- UInt32.cs
- CoreChannel.cs
- GetPageCompletedEventArgs.cs
- ResourceReader.cs
- ScriptControl.cs
- TextClipboardData.cs
- KeyInstance.cs
- RecordConverter.cs
- WindowsRegion.cs
- ProgressBar.cs
- RowUpdatedEventArgs.cs
- updatecommandorderer.cs
- SqlServer2KCompatibilityAnnotation.cs
- CoreChannel.cs
- XmlConvert.cs
- ToolStripItemClickedEventArgs.cs
- Viewport3DAutomationPeer.cs
- URLIdentityPermission.cs
- GenericPrincipal.cs
- WebSysDisplayNameAttribute.cs
- Main.cs
- StreamResourceInfo.cs
- TaiwanLunisolarCalendar.cs
- XmlSignificantWhitespace.cs
- CacheVirtualItemsEvent.cs
- ContextQuery.cs
- ValidatedControlConverter.cs
- DataBoundControl.cs
- TypeSchema.cs
- InfiniteIntConverter.cs
- ObjectFactoryCodeDomTreeGenerator.cs
- SystemMulticastIPAddressInformation.cs
- AttributeUsageAttribute.cs
- CodeTypeReferenceExpression.cs
- TextAction.cs
- XmlNamedNodeMap.cs
- DataContractSerializerElement.cs
- ConstructorExpr.cs
- PageBuildProvider.cs
- sqlcontext.cs
- WebScriptServiceHost.cs
- ReaderWriterLockSlim.cs
- StandardBindingElement.cs
- StringArrayConverter.cs
- Utility.cs
- PropertyChangedEventArgs.cs
- StdValidatorsAndConverters.cs
- NumberSubstitution.cs
- SafeLibraryHandle.cs
- IdentitySection.cs
- MissingManifestResourceException.cs
- SqlCacheDependency.cs
- MeshGeometry3D.cs
- SiteMembershipCondition.cs
- HttpBindingExtension.cs
- TemplateManager.cs
- XmlSigningNodeWriter.cs
- NullToBooleanConverter.cs
- InvalidDataException.cs
- SecUtil.cs
- SchemaUtility.cs
- TextEndOfLine.cs
- Soap.cs
- WebPartAuthorizationEventArgs.cs