Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@ -0,0 +1,289 @@
//
// Author: Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2009,2010 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.Xml;
namespace System.ServiceModel.Discovery
{
public sealed class AnnouncementClient : ICommunicationObject, IDisposable
{
internal interface IAnnouncementCommon
{
IAsyncResult BeginAnnounceOnline (EndpointDiscoveryMetadata metadata, DiscoveryMessageSequence sequence, AsyncCallback callback, object state);
void EndAnnounceOnline (IAsyncResult result);
IAsyncResult BeginAnnounceOffline (EndpointDiscoveryMetadata metadata, DiscoveryMessageSequence sequence, AsyncCallback callback, object state);
void EndAnnounceOffline (IAsyncResult result);
}
public AnnouncementClient ()
: this (String.Empty)
{
}
public AnnouncementClient (AnnouncementEndpoint announcementEndpoint)
{
if (announcementEndpoint == null)
throw new ArgumentNullException ("announcementEndpoint");
MessageSequenceGenerator = new DiscoveryMessageSequenceGenerator ();
client = Activator.CreateInstance (announcementEndpoint.DiscoveryVersion.AnnouncementClientType, new object [] {announcementEndpoint});
}
public AnnouncementClient (string endpointConfigurationName)
{
throw new NotImplementedException ();
}
public DiscoveryMessageSequenceGenerator MessageSequenceGenerator { get; set; }
// FIXME: make it dynamic (dmcs crashes for now)
object client;
public ChannelFactory ChannelFactory {
get { return (ChannelFactory) client.GetType ().GetProperty ("ChannelFactory").GetValue (client, null); }
}
public ClientCredentials ClientCredentials {
get { return ChannelFactory.Credentials; }
}
public ServiceEndpoint Endpoint {
get { return ChannelFactory.Endpoint; }
}
public IClientChannel InnerChannel {
get { return (IClientChannel) client.GetType ().GetProperty ("InnerChannel").GetValue (client, null); }
}
CommunicationState State {
get { return ((ICommunicationObject) this).State; }
}
CommunicationState ICommunicationObject.State {
get { return ((ICommunicationObject) client).State; }
}
public event EventHandler<AsyncCompletedEventArgs> AnnounceOfflineCompleted;
public event EventHandler<AsyncCompletedEventArgs> AnnounceOnlineCompleted;
event EventHandler ICommunicationObject.Closed {
add { InnerChannel.Closed += value; }
remove { InnerChannel.Closed -= value; }
}
event EventHandler ICommunicationObject.Closing {
add { InnerChannel.Closing += value; }
remove { InnerChannel.Closing -= value; }
}
event EventHandler ICommunicationObject.Faulted {
add { InnerChannel.Faulted += value; }
remove { InnerChannel.Faulted -= value; }
}
event EventHandler ICommunicationObject.Opened {
add { InnerChannel.Opened += value; }
remove { InnerChannel.Opened -= value; }
}
event EventHandler ICommunicationObject.Opening {
add { InnerChannel.Opening += value; }
remove { InnerChannel.Opening -= value; }
}
// open/close
public void Open ()
{
((ICommunicationObject) this).Open ();
}
public void Close ()
{
((ICommunicationObject) this).Close ();
}
// sync
public void AnnounceOffline (EndpointDiscoveryMetadata discoveryMetadata)
{
EndAnnounceOffline (BeginAnnounceOffline (discoveryMetadata, null, null));
}
public void AnnounceOnline (EndpointDiscoveryMetadata discoveryMetadata)
{
EndAnnounceOnline (BeginAnnounceOnline (discoveryMetadata, null, null));
}
// async
public void AnnounceOfflineAsync (EndpointDiscoveryMetadata discoveryMetadata)
{
AnnounceOfflineAsync (discoveryMetadata, null);
}
public void AnnounceOfflineAsync (EndpointDiscoveryMetadata discoveryMetadata, object userState)
{
AsyncCallback cb = delegate (IAsyncResult result) {
try {
EndAnnounceOffline (result);
} catch (Exception ex) {
OnAnnounceOfflineCompleted (new AsyncCompletedEventArgs (ex, false, result.AsyncState));
} finally {
OnAnnounceOfflineCompleted (new AsyncCompletedEventArgs (null, false, result.AsyncState));
}
};
BeginAnnounceOffline (discoveryMetadata, cb, userState);
}
void OnAnnounceOfflineCompleted (AsyncCompletedEventArgs args)
{
if (AnnounceOfflineCompleted != null)
AnnounceOfflineCompleted (this, args);
}
public void AnnounceOnlineAsync (EndpointDiscoveryMetadata discoveryMetadata)
{
AnnounceOnlineAsync (discoveryMetadata, null);
}
public void AnnounceOnlineAsync (EndpointDiscoveryMetadata discoveryMetadata, object userState)
{
AsyncCallback cb = delegate (IAsyncResult result) {
try {
EndAnnounceOnline (result);
} catch (Exception ex) {
OnAnnounceOnlineCompleted (new AsyncCompletedEventArgs (ex, false, result.AsyncState));
} finally {
OnAnnounceOnlineCompleted (new AsyncCompletedEventArgs (null, false, result.AsyncState));
}
};
BeginAnnounceOnline (discoveryMetadata, cb, userState);
}
void OnAnnounceOnlineCompleted (AsyncCompletedEventArgs args)
{
if (AnnounceOnlineCompleted != null)
AnnounceOnlineCompleted (this, args);
}
// begin/end
public IAsyncResult BeginAnnounceOffline (EndpointDiscoveryMetadata discoveryMetadata, AsyncCallback callback, object state)
{
using (var ocs = new OperationContextScope (InnerChannel)) {
OperationContext.Current.OutgoingMessageHeaders.MessageId = new UniqueId ();
return ((IAnnouncementCommon) client).BeginAnnounceOffline (discoveryMetadata, MessageSequenceGenerator.Next (), callback, state);
}
}
public IAsyncResult BeginAnnounceOnline (EndpointDiscoveryMetadata discoveryMetadata, AsyncCallback callback, object state)
{
using (var ocs = new OperationContextScope (InnerChannel)) {
OperationContext.Current.OutgoingMessageHeaders.MessageId = new UniqueId ();
return ((IAnnouncementCommon) client).BeginAnnounceOnline (discoveryMetadata, MessageSequenceGenerator.Next (), callback, state);
}
}
public void EndAnnounceOffline (IAsyncResult result)
{
((IAnnouncementCommon) client).EndAnnounceOffline (result);
}
public void EndAnnounceOnline (IAsyncResult result)
{
((IAnnouncementCommon) client).EndAnnounceOnline (result);
}
// explicit interface impl.
void ICommunicationObject.Open ()
{
InnerChannel.Open ();
}
void ICommunicationObject.Open (TimeSpan timeout)
{
InnerChannel.Open (timeout);
}
void ICommunicationObject.Close ()
{
if (State == CommunicationState.Opened)
InnerChannel.Close ();
}
void ICommunicationObject.Close (TimeSpan timeout)
{
if (State == CommunicationState.Opened)
InnerChannel.Close (timeout);
}
IAsyncResult ICommunicationObject.BeginOpen (AsyncCallback callback, object state)
{
return InnerChannel.BeginOpen (callback, state);
}
IAsyncResult ICommunicationObject.BeginOpen (TimeSpan timeout, AsyncCallback callback, object state)
{
return InnerChannel.BeginOpen (timeout, callback, state);
}
IAsyncResult ICommunicationObject.BeginClose (AsyncCallback callback, object state)
{
return InnerChannel.BeginClose (callback, state);
}
IAsyncResult ICommunicationObject.BeginClose (TimeSpan timeout, AsyncCallback callback, object state)
{
return InnerChannel.BeginClose (timeout, callback, state);
}
void ICommunicationObject.EndOpen (IAsyncResult result)
{
InnerChannel.EndOpen (result);
}
void ICommunicationObject.EndClose (IAsyncResult result)
{
InnerChannel.EndClose (result);
}
void ICommunicationObject.Abort ()
{
if (State != CommunicationState.Closed) {
InnerChannel.Abort ();
ChannelFactory.Abort ();
}
}
void IDisposable.Dispose ()
{
Close ();
}
}
}

View File

@ -0,0 +1,74 @@
//
// Author: Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2009 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
namespace System.ServiceModel.Discovery
{
public class AnnouncementEndpoint : ServiceEndpoint
{
public AnnouncementEndpoint ()
: this (DiscoveryVersion.WSDiscovery11)
{
}
public AnnouncementEndpoint (DiscoveryVersion discoveryVersion)
: this (discoveryVersion, null, null)
{
if (discoveryVersion == null)
throw new ArgumentNullException ("discoveryVersion");
DiscoveryVersion = discoveryVersion;
IsSystemEndpoint = true;
}
public AnnouncementEndpoint (Binding binding, EndpointAddress address)
: this (DiscoveryVersion.WSDiscovery11, binding, address)
{
}
public AnnouncementEndpoint (DiscoveryVersion discoveryVersion, Binding binding, EndpointAddress address)
: base (GetContract (discoveryVersion), binding, address)
{
DiscoveryVersion = discoveryVersion;
}
static ContractDescription GetContract (DiscoveryVersion discoveryVersion)
{
if (discoveryVersion == null)
throw new ArgumentNullException ("discoveryVersion");
return ContractDescription.GetContract (discoveryVersion.AnnouncementContractType);
}
public DiscoveryVersion DiscoveryVersion { get; private set; }
public TimeSpan MaxAnnouncementDelay { get; set; }
}
}

View File

@ -0,0 +1,46 @@
//
// Author: Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2009 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
namespace System.ServiceModel.Discovery
{
public class AnnouncementEventArgs : EventArgs
{
internal AnnouncementEventArgs (EndpointDiscoveryMetadata metadata, DiscoveryMessageSequence queue)
{
EndpointDiscoveryMetadata = metadata;
MessageSequence = queue;
}
public EndpointDiscoveryMetadata EndpointDiscoveryMetadata { get; private set; }
public DiscoveryMessageSequence MessageSequence { get; private set; }
}
}

View File

@ -0,0 +1,223 @@
//
// Author: Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2009,2010 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Discovery.Version11;
using System.ServiceModel.Discovery.VersionApril2005;
using System.ServiceModel.Discovery.VersionCD1;
using System.Threading;
namespace System.ServiceModel.Discovery
{
// To be usable as ServiceType, it must implement contract interfaces.
// However, there is no public interfaces, so they must be internal.
[ServiceBehavior (InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)]
public class AnnouncementService : IAnnouncementContract11, IAnnouncementContractApril2005, IAnnouncementContractCD1
{
public AnnouncementService ()
: this (0)
{
}
public AnnouncementService (int duplicateMessageHistoryLength)
{
}
public event EventHandler<AnnouncementEventArgs> OfflineAnnouncementReceived;
public event EventHandler<AnnouncementEventArgs> OnlineAnnouncementReceived;
Action<object,AnnouncementEventArgs> online, offline;
protected virtual IAsyncResult OnBeginOfflineAnnouncement (DiscoveryMessageSequence messageSequence, EndpointDiscoveryMetadata endpointDiscoveryMetadata, AsyncCallback callback, object state)
{
// FIXME: this is a workaround for (similar to) bug #633945.
switch (Environment.OSVersion.Platform) {
case PlatformID.Unix:
case PlatformID.MacOSX:
if (offline == null)
offline = new Action<object,AnnouncementEventArgs> (OfflineAnnouncementReceived ?? delegate {});
return offline.BeginInvoke (this, new AnnouncementEventArgs (endpointDiscoveryMetadata, messageSequence), callback, state);
default:
if (OfflineAnnouncementReceived != null)
OfflineAnnouncementReceived (this, new AnnouncementEventArgs (endpointDiscoveryMetadata, messageSequence));
var result = new TempAsyncResult (null, state);
if (callback != null)
callback (result);
return result;
}
}
protected virtual IAsyncResult OnBeginOnlineAnnouncement (DiscoveryMessageSequence messageSequence, EndpointDiscoveryMetadata endpointDiscoveryMetadata, AsyncCallback callback, object state)
{
// FIXME: this is a workaround for (similar to) bug #633945.
switch (Environment.OSVersion.Platform) {
case PlatformID.Unix:
case PlatformID.MacOSX:
if (online == null)
online = new Action<object,AnnouncementEventArgs> (OnlineAnnouncementReceived ?? delegate {});
return online.BeginInvoke (this, new AnnouncementEventArgs (endpointDiscoveryMetadata, messageSequence), callback, state);
default:
if (OnlineAnnouncementReceived != null)
OnlineAnnouncementReceived (this, new AnnouncementEventArgs (endpointDiscoveryMetadata, messageSequence));
var result = new TempAsyncResult (null, state);
if (callback != null)
callback (result);
return result;
}
}
protected virtual void OnEndOfflineAnnouncement (IAsyncResult result)
{
// FIXME: this is a workaround for (similar to) bug #633945.
switch (Environment.OSVersion.Platform) {
case PlatformID.Unix:
case PlatformID.MacOSX:
offline.EndInvoke (result);
break;
default:
// do nothing
break;
}
}
protected virtual void OnEndOnlineAnnouncement (IAsyncResult result)
{
// FIXME: this is a workaround for (similar to) bug #633945.
switch (Environment.OSVersion.Platform) {
case PlatformID.Unix:
case PlatformID.MacOSX:
online.EndInvoke (result);
break;
default:
// do nothing
break;
}
}
// BeginOnlineAnnouncement
IAsyncResult IAnnouncementContract11.BeginOnlineAnnouncement (MessageContracts11.OnlineAnnouncement msg, AsyncCallback callback, object state)
{
var msq = msg.MessageSequence != null ? msg.MessageSequence.ToDiscoveryMessageSequence () : null;
var edm = msg.EndpointDiscoveryMetadata != null ? msg.EndpointDiscoveryMetadata.ToEndpointDiscoveryMetadata () : null;
return OnBeginOnlineAnnouncement (msq, edm, callback, state);
}
IAsyncResult IAnnouncementContractApril2005.BeginOnlineAnnouncement (MessageContractsApril2005.OnlineAnnouncement msg, AsyncCallback callback, object state)
{
var msq = msg.MessageSequence != null ? msg.MessageSequence.ToDiscoveryMessageSequence () : null;
var edm = msg.EndpointDiscoveryMetadata != null ? msg.EndpointDiscoveryMetadata.ToEndpointDiscoveryMetadata () : null;
return OnBeginOnlineAnnouncement (msq, edm, callback, state);
}
IAsyncResult IAnnouncementContractCD1.BeginOnlineAnnouncement (MessageContractsCD1.OnlineAnnouncement msg, AsyncCallback callback, object state)
{
var msq = msg.MessageSequence != null ? msg.MessageSequence.ToDiscoveryMessageSequence () : null;
var edm = msg.EndpointDiscoveryMetadata != null ? msg.EndpointDiscoveryMetadata.ToEndpointDiscoveryMetadata () : null;
return OnBeginOnlineAnnouncement (msq, edm, callback, state);
}
// EndOnlineAnnouncement
void IAnnouncementContract11.EndOnlineAnnouncement (IAsyncResult result)
{
OnEndOnlineAnnouncement (result);
}
void IAnnouncementContractApril2005.EndOnlineAnnouncement (IAsyncResult result)
{
OnEndOnlineAnnouncement (result);
}
void IAnnouncementContractCD1.EndOnlineAnnouncement (IAsyncResult result)
{
OnEndOnlineAnnouncement (result);
}
// BeginOfflineAnnouncement
IAsyncResult IAnnouncementContract11.BeginOfflineAnnouncement (MessageContracts11.OfflineAnnouncement msg, AsyncCallback callback, object state)
{
var msq = msg.MessageSequence != null ? msg.MessageSequence.ToDiscoveryMessageSequence () : null;
var edm = msg.EndpointDiscoveryMetadata != null ? msg.EndpointDiscoveryMetadata.ToEndpointDiscoveryMetadata () : null;
return OnBeginOfflineAnnouncement (msq, edm, callback, state);
}
IAsyncResult IAnnouncementContractApril2005.BeginOfflineAnnouncement (MessageContractsApril2005.OfflineAnnouncement msg, AsyncCallback callback, object state)
{
var msq = msg.MessageSequence != null ? msg.MessageSequence.ToDiscoveryMessageSequence () : null;
var edm = msg.EndpointDiscoveryMetadata != null ? msg.EndpointDiscoveryMetadata.ToEndpointDiscoveryMetadata () : null;
return OnBeginOfflineAnnouncement (msq, edm, callback, state);
}
IAsyncResult IAnnouncementContractCD1.BeginOfflineAnnouncement (MessageContractsCD1.OfflineAnnouncement msg, AsyncCallback callback, object state)
{
var msq = msg.MessageSequence != null ? msg.MessageSequence.ToDiscoveryMessageSequence () : null;
var edm = msg.EndpointDiscoveryMetadata != null ? msg.EndpointDiscoveryMetadata.ToEndpointDiscoveryMetadata () : null;
return OnBeginOfflineAnnouncement (msq, edm, callback, state);
}
// EndOfflineAnnouncement
void IAnnouncementContract11.EndOfflineAnnouncement (IAsyncResult result)
{
OnEndOfflineAnnouncement (result);
}
void IAnnouncementContractApril2005.EndOfflineAnnouncement (IAsyncResult result)
{
OnEndOfflineAnnouncement (result);
}
void IAnnouncementContractCD1.EndOfflineAnnouncement (IAsyncResult result)
{
OnEndOfflineAnnouncement (result);
}
}
// FIXME: It is introduced for a workaround for (similar to) bug #633945. Remove this class and all of its usage once that bug gets fixed.
class TempAsyncResult : IAsyncResult
{
public TempAsyncResult (object returnValue, object state)
{
ReturnValue = returnValue;
AsyncState = state;
CompletedSynchronously = true;
IsCompleted = true;
AsyncWaitHandle = new ManualResetEvent (true);
}
public object ReturnValue { get; set; }
public object AsyncState { get; set; }
public bool CompletedSynchronously { get; set; }
public bool IsCompleted { get; set; }
public WaitHandle AsyncWaitHandle { get; set; }
}
}

View File

@ -0,0 +1,4 @@
2010-03-19 Atsushi Enomoto <atsushi@ximian.com>
* : initial checkin (mostly stubs).

View File

@ -0,0 +1,148 @@
//
// Author: Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2009,2010 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
namespace System.ServiceModel.Discovery
{
internal class DiscoveryChannelDispatcher : ChannelDispatcherBase
{
ServiceHostBase host;
AnnouncementClient client;
bool handle_announce_online;
public DiscoveryChannelDispatcher (AnnouncementEndpoint endpoint, bool handleAnnounceOnline)
{
// The argument endpoint is to indicate "destination".
// It is different from the destination indicated in
// "EndpointDiscoveryMetadata" argument in announcement messages sent by the "client".
this.client = new AnnouncementClient (endpoint);
this.handle_announce_online = handleAnnounceOnline;
}
public ICommunicationObject Communication {
get { return client; }
}
public override ServiceHostBase Host {
get { return host; }
}
public override IChannelListener Listener {
get { return null; }
}
// might be different value
protected internal override TimeSpan DefaultOpenTimeout {
get { return client.Endpoint.Binding.OpenTimeout; }
}
// might be different value
protected internal override TimeSpan DefaultCloseTimeout {
get { return client.Endpoint.Binding.CloseTimeout; }
}
protected internal override void Attach (ServiceHostBase host)
{
base.Attach (host);
this.host = host;
}
protected internal override void Detach (ServiceHostBase host)
{
base.Detach (host);
this.host = null;
}
protected override void OnOpen (TimeSpan timeout)
{
if (!handle_announce_online)
return; // Offline announcement is done by another DiscoveryChannelDispatcher
DateTime start = DateTime.Now;
Communication.Open (timeout);
// and call AnnouncementOnline().
var dx = host.Extensions.Find<DiscoveryServiceExtension> ();
// Published endpoints are added by DicoveryEndpointPublisherBehavior, which is added to each ServiceEndpoint in the primary (non-announcement) service.
if (dx != null) {
foreach (var edm in dx.PublishedEndpoints) {
client.InnerChannel.OperationTimeout = timeout - (DateTime.Now - start);
client.AnnounceOnline (edm);
}
}
}
protected override IAsyncResult OnBeginOpen (TimeSpan timeout, AsyncCallback callback, object state)
{
return Communication.BeginOpen (timeout, callback, state);
}
protected override void OnEndOpen (IAsyncResult result)
{
Communication.EndOpen (result);
}
protected override void OnClose (TimeSpan timeout)
{
if (handle_announce_online)
return; // Offline announcement is done by another DiscoveryChannelDispatcher
DateTime start = DateTime.Now;
// and call AnnouncementOnline().
var dx = host.Extensions.Find<DiscoveryServiceExtension> ();
// Published endpoints are added by DicoveryEndpointPublisherBehavior, which is added to each ServiceEndpoint in the primary (non-announcement) service.
if (dx != null) {
foreach (var edm in dx.PublishedEndpoints) {
client.InnerChannel.OperationTimeout = timeout - (DateTime.Now - start);
client.AnnounceOffline (edm);
}
}
// Then close the client.
Communication.Close (timeout - (DateTime.Now - start));
}
protected override IAsyncResult OnBeginClose (TimeSpan timeout, AsyncCallback callback, object state)
{
return Communication.BeginClose (timeout, callback, state);
}
protected override void OnEndClose (IAsyncResult result)
{
Communication.EndClose (result);
}
protected override void OnAbort ()
{
Communication.Abort ();
}
}
}

View File

@ -0,0 +1,90 @@
//
// Author: Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2009,2010 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
namespace System.ServiceModel.Discovery
{
internal class DiscoveryChannelFactory<TChannel> : ChannelFactoryBase<TChannel>
{
public DiscoveryChannelFactory (DiscoveryClientBindingElement source, BindingContext context)
{
Source = source;
this.inner = context.BuildInnerChannelFactory<TChannel> ();
}
IChannelFactory<TChannel> inner;
internal DiscoveryClientBindingElement Source { get; private set; }
internal IChannelFactory<TChannel> InnerFactory {
get { return inner; }
}
protected override void OnOpen (TimeSpan timeout)
{
inner.Open (timeout);
}
protected override void OnClose (TimeSpan timeout)
{
inner.Close (timeout);
}
protected override IAsyncResult OnBeginOpen (TimeSpan timeout, AsyncCallback callback, object state)
{
return inner.BeginOpen (timeout, callback, state);
}
protected override IAsyncResult OnBeginClose (TimeSpan timeout, AsyncCallback callback, object state)
{
return inner.BeginClose (timeout, callback, state);
}
protected override void OnEndOpen (IAsyncResult result)
{
inner.EndOpen (result);
}
protected override void OnEndClose (IAsyncResult result)
{
inner.EndClose (result);
}
protected override TChannel OnCreateChannel (EndpointAddress address, Uri via)
{
if (address == null)
throw new ArgumentNullException ("address");
if (address != DiscoveryClientBindingElement.DiscoveryEndpointAddress)
throw new ArgumentException ("Only DiscoveryEndpointAddress is expected as the argument EndpointAddress");
return (TChannel) (object) new DiscoveryChannel<TChannel> (this, address, via);
}
}
}

View File

@ -0,0 +1,290 @@
//
// Author: Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2009,2010 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
namespace System.ServiceModel.Discovery
{
public sealed class DiscoveryClient : ICommunicationObject, IDisposable
{
internal interface IDiscoveryCommon
{
IAsyncResult BeginFind (FindCriteria criteria, AsyncCallback callback, object state);
FindResponse EndFind (IAsyncResult result);
IAsyncResult BeginResolve (ResolveCriteria criteria, AsyncCallback callback, object state);
ResolveResponse EndResolve (IAsyncResult result);
}
public DiscoveryClient ()
: this (String.Empty)
{
}
public DiscoveryClient (DiscoveryEndpoint discoveryEndpoint)
{
if (discoveryEndpoint == null)
throw new ArgumentNullException ("discoveryEndpoint");
// create DiscoveryTargetClientXX for each version:
// Managed -> DiscoveryTargetClientType (request-reply)
// Adhoc -> DiscoveryProxyClientType (duplex)
if (discoveryEndpoint.DiscoveryMode == ServiceDiscoveryMode.Managed)
client = Activator.CreateInstance (discoveryEndpoint.DiscoveryVersion.DiscoveryProxyClientType, new object [] {discoveryEndpoint});
else
client = Activator.CreateInstance (discoveryEndpoint.DiscoveryVersion.DiscoveryTargetClientType, new object [] {discoveryEndpoint});
}
public DiscoveryClient (string endpointConfigurationName)
{
throw new NotImplementedException ();
}
// FIXME: make it dynamic (dmcs crashes for now)
object client;
public ChannelFactory ChannelFactory {
get { return (ChannelFactory) client.GetType ().GetProperty ("ChannelFactory").GetValue (client, null); }
}
public ClientCredentials ClientCredentials {
get { return ChannelFactory.Credentials; }
}
public ServiceEndpoint Endpoint {
get { return ChannelFactory.Endpoint; }
}
public IClientChannel InnerChannel {
get { return (IClientChannel) client.GetType ().GetProperty ("InnerChannel").GetValue (client, null); }
}
CommunicationState State {
get { return ((ICommunicationObject) this).State; }
}
CommunicationState ICommunicationObject.State {
get { return ((ICommunicationObject) client).State; }
}
public event EventHandler<FindCompletedEventArgs> FindCompleted;
public event EventHandler<FindProgressChangedEventArgs> FindProgressChanged;
public event EventHandler<AnnouncementEventArgs> ProxyAvailable;
public event EventHandler<ResolveCompletedEventArgs> ResolveCompleted;
event EventHandler ICommunicationObject.Closed {
add { InnerChannel.Closed += value; }
remove { InnerChannel.Closed -= value; }
}
event EventHandler ICommunicationObject.Closing {
add { InnerChannel.Closing += value; }
remove { InnerChannel.Closing -= value; }
}
event EventHandler ICommunicationObject.Faulted {
add { InnerChannel.Faulted += value; }
remove { InnerChannel.Faulted -= value; }
}
event EventHandler ICommunicationObject.Opened {
add { InnerChannel.Opened += value; }
remove { InnerChannel.Opened -= value; }
}
event EventHandler ICommunicationObject.Opening {
add { InnerChannel.Opening += value; }
remove { InnerChannel.Opening -= value; }
}
public void Open ()
{
((ICommunicationObject) this).Open ();
}
public void Close ()
{
((ICommunicationObject) this).Close ();
}
bool cancelled;
public void CancelAsync (object userState)
{
throw new NotImplementedException ();
}
// find
public FindResponse Find (FindCriteria criteria)
{
return EndFind (BeginFind (criteria, null, null));
}
public void FindAsync (FindCriteria criteria)
{
FindAsync (criteria, null);
}
public void FindAsync (FindCriteria criteria, object userState)
{
AsyncCallback cb = delegate (IAsyncResult result) {
FindResponse ret = null;
Exception error = null;
try {
ret = EndFind (result);
} catch (Exception ex) {
error = ex;
}
OnFindCompleted (new FindCompletedEventArgs (ret, error, cancelled, result.AsyncState));
};
cancelled = false;
BeginFind (criteria, cb, userState);
}
void OnFindCompleted (FindCompletedEventArgs args)
{
if (FindCompleted != null)
FindCompleted (this, args);
}
IAsyncResult BeginFind (FindCriteria criteria, AsyncCallback callback, object state)
{
return ((IDiscoveryCommon) client).BeginFind (criteria, callback, state);
}
FindResponse EndFind (IAsyncResult result)
{
return ((IDiscoveryCommon) client).EndFind (result);
}
// resolve
public ResolveResponse Resolve (ResolveCriteria criteria)
{
return EndResolve (BeginResolve (criteria, null, null));
}
public void ResolveAsync (ResolveCriteria criteria)
{
ResolveAsync (criteria, null);
}
public void ResolveAsync (ResolveCriteria criteria, object userState)
{
AsyncCallback cb = delegate (IAsyncResult result) {
ResolveResponse ret = null;
Exception error = null;
try {
ret = EndResolve (result);
} catch (Exception ex) {
error = ex;
}
OnResolveCompleted (new ResolveCompletedEventArgs (ret, error, cancelled, result.AsyncState));
};
cancelled = false;
BeginResolve (criteria, cb, userState);
}
void OnResolveCompleted (ResolveCompletedEventArgs args)
{
if (ResolveCompleted != null)
ResolveCompleted (this, args);
}
IAsyncResult BeginResolve (ResolveCriteria criteria, AsyncCallback callback, object state)
{
return ((IDiscoveryCommon) client).BeginResolve (criteria, callback, state);
}
ResolveResponse EndResolve (IAsyncResult result)
{
return ((IDiscoveryCommon) client).EndResolve (result);
}
// explicit interface impl.
void ICommunicationObject.Open ()
{
InnerChannel.Open ();
}
void ICommunicationObject.Open (TimeSpan timeout)
{
InnerChannel.Open (timeout);
}
void ICommunicationObject.Close ()
{
InnerChannel.Close ();
}
void ICommunicationObject.Close (TimeSpan timeout)
{
InnerChannel.Close (timeout);
}
IAsyncResult ICommunicationObject.BeginOpen (AsyncCallback callback, object state)
{
return InnerChannel.BeginOpen (callback, state);
}
IAsyncResult ICommunicationObject.BeginOpen (TimeSpan timeout, AsyncCallback callback, object state)
{
return InnerChannel.BeginOpen (timeout, callback, state);
}
IAsyncResult ICommunicationObject.BeginClose (AsyncCallback callback, object state)
{
return InnerChannel.BeginClose (callback, state);
}
IAsyncResult ICommunicationObject.BeginClose (TimeSpan timeout, AsyncCallback callback, object state)
{
return InnerChannel.BeginClose (timeout, callback, state);
}
void ICommunicationObject.EndOpen (IAsyncResult result)
{
InnerChannel.EndOpen (result);
}
void ICommunicationObject.EndClose (IAsyncResult result)
{
InnerChannel.EndClose (result);
}
void ICommunicationObject.Abort ()
{
InnerChannel.Abort ();
}
void IDisposable.Dispose ()
{
InnerChannel.Dispose ();
}
}
}

View File

@ -0,0 +1,93 @@
//
// Author: Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2009,2010 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
namespace System.ServiceModel.Discovery
{
public sealed class DiscoveryClientBindingElement : BindingElement
{
public static readonly EndpointAddress DiscoveryEndpointAddress = new EndpointAddress ("http://schemas.microsoft.com/discovery/dynamic");
public DiscoveryClientBindingElement ()
{
DiscoveryEndpointProvider = DiscoveryEndpointProvider.CreateDefault ();
FindCriteria = new FindCriteria (); // empty
}
public DiscoveryClientBindingElement (DiscoveryEndpointProvider discoveryEndpointProvider, FindCriteria findCriteria)
{
if (discoveryEndpointProvider == null)
throw new ArgumentNullException ("discoveryEndpointProvider");
if (findCriteria == null)
throw new ArgumentNullException ("findCriteria");
DiscoveryEndpointProvider = discoveryEndpointProvider;
FindCriteria = findCriteria;
}
public DiscoveryEndpointProvider DiscoveryEndpointProvider { get; set; }
public FindCriteria FindCriteria { get; set; }
public override IChannelFactory<TChannel> BuildChannelFactory<TChannel> (BindingContext context)
{
if (!(context.Binding.CreateBindingElements ().First () is DiscoveryClientBindingElement))
throw new InvalidOperationException ("DiscoveryClientBindingElement is expected at the top of the input binding elements in the BindingContext");
return new DiscoveryChannelFactory<TChannel> (this, context);
}
public override IChannelListener<TChannel> BuildChannelListener<TChannel> (BindingContext context)
{
throw new NotSupportedException ();
}
public override bool CanBuildChannelFactory<TChannel> (BindingContext context)
{
return context.CanBuildInnerChannelFactory<TChannel> ();
}
public override bool CanBuildChannelListener<TChannel> (BindingContext context)
{
return false;
}
public override BindingElement Clone ()
{
return new DiscoveryClientBindingElement (DiscoveryEndpointProvider, FindCriteria);
}
public override T GetProperty<T> (BindingContext context)
{
return context.GetInnerProperty<T> ();
}
}
}

View File

@ -0,0 +1,76 @@
//
// Author: Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2009 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
namespace System.ServiceModel.Discovery
{
public class DiscoveryEndpoint : ServiceEndpoint
{
public DiscoveryEndpoint ()
: this (null, null)
{
}
public DiscoveryEndpoint (Binding binding, EndpointAddress endpointAddress)
: this (DiscoveryVersion.WSDiscovery11, ServiceDiscoveryMode.Managed, binding, endpointAddress)
{
}
public DiscoveryEndpoint (DiscoveryVersion discoveryVersion, ServiceDiscoveryMode discoveryMode)
: this (discoveryVersion, discoveryMode, null, null)
{
}
public DiscoveryEndpoint (DiscoveryVersion discoveryVersion, ServiceDiscoveryMode discoveryMode, Binding binding, EndpointAddress endpointAddress)
: base (GetContract (discoveryVersion, discoveryMode), binding, endpointAddress)
{
DiscoveryVersion = discoveryVersion;
DiscoveryMode = discoveryMode;
IsSystemEndpoint = true;
}
static ContractDescription GetContract (DiscoveryVersion discoveryVersion, ServiceDiscoveryMode mode)
{
if (discoveryVersion == null)
throw new ArgumentNullException ("discoveryVersion");
// Provide different contract type for Adhoc mode and Managed mode, respectively.
if (mode == ServiceDiscoveryMode.Managed)
return ContractDescription.GetContract (discoveryVersion.DiscoveryProxyContractType);
else
return ContractDescription.GetContract (discoveryVersion.DiscoveryTargetContractType);
}
public ServiceDiscoveryMode DiscoveryMode { get; private set; }
public DiscoveryVersion DiscoveryVersion { get; private set; }
public TimeSpan MaxResponseDelay { get; set; }
}
}

View File

@ -0,0 +1,70 @@
//
// Author: Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2009 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Discovery.Udp;
namespace System.ServiceModel.Discovery
{
public abstract class DiscoveryEndpointProvider
{
internal static DiscoveryEndpointProvider CreateDefault ()
{
return new UdpDiscoveryEndpointProvider ();
}
public abstract DiscoveryEndpoint GetDiscoveryEndpoint ();
}
internal class SimpleDiscoveryEndpointProvider : DiscoveryEndpointProvider
{
public SimpleDiscoveryEndpointProvider (DiscoveryEndpoint value)
{
this.value = value;
}
DiscoveryEndpoint value;
public override DiscoveryEndpoint GetDiscoveryEndpoint ()
{
return value;
}
}
internal class UdpDiscoveryEndpointProvider : DiscoveryEndpointProvider
{
public override DiscoveryEndpoint GetDiscoveryEndpoint ()
{
var binding = new CustomBinding (new TextMessageEncodingBindingElement (), new UdpTransportBindingElement ());
// FIXME: Name might not be set here (but needs to be modified somewhere anyways).
return new UdpDiscoveryEndpoint () { Binding = binding };
}
}
}

View File

@ -0,0 +1,83 @@
//
// Author: Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2009,2010 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
namespace System.ServiceModel.Discovery
{
internal class DiscoveryEndpointPublisherBehavior : IEndpointBehavior
{
DiscoveryServiceExtension extension;
internal DiscoveryEndpointPublisherBehavior (DiscoveryServiceExtension extension)
{
this.extension = extension;
}
void IEndpointBehavior.AddBindingParameters (ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
{
if (endpoint == null)
throw new ArgumentNullException ("endpoint");
if (bindingParameters == null)
throw new ArgumentNullException ("bindingParameters");
}
void IEndpointBehavior.ApplyClientBehavior (ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
if (endpoint == null)
throw new ArgumentNullException ("endpoint");
if (clientRuntime == null)
throw new ArgumentNullException ("clientRuntime");
}
void IEndpointBehavior.ApplyDispatchBehavior (ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
{
// It is applied to the ServiceEndpoints in the ServiceHost which has ServiceDiscoveryBehavior as one of its service behaviors.
// That is, this target endpoint is an endpoint in the target service itself, not for "announcement service".
if (endpoint == null)
throw new ArgumentNullException ("endpoint");
if (endpointDispatcher == null)
throw new ArgumentNullException ("endpointDispatcher");
var edb = endpoint.Behaviors.Find<EndpointDiscoveryBehavior> ();
if (edb != null && !edb.Enabled)
return;
var edm = EndpointDiscoveryMetadata.FromServiceEndpoint (endpoint);
extension.PublishedInternalEndpoints.Add (edm);
}
void IEndpointBehavior.Validate (ServiceEndpoint endpoint)
{
if (endpoint == null)
throw new ArgumentNullException ("endpoint");
}
}
}

View File

@ -0,0 +1,132 @@
//
// Author: Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2009 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.Xml;
using System.Xml.Schema;
namespace System.ServiceModel.Discovery
{
public class DiscoveryMessageSequence : IComparable<DiscoveryMessageSequence>, IEquatable<DiscoveryMessageSequence>
{
internal DiscoveryMessageSequence (long instanceId, Uri sequenceId, long messageNumber)
{
InstanceId = instanceId;
SequenceId = sequenceId;
MessageNumber = messageNumber;
}
public long InstanceId { get; private set; }
public long MessageNumber { get; private set; }
public Uri SequenceId { get; private set; }
public bool CanCompareTo (DiscoveryMessageSequence other)
{
return other != null; // I cannot find any other conditions that return false.
}
public int CompareTo (DiscoveryMessageSequence other)
{
return CanCompareTo (other) ? GetHashCode () - other.GetHashCode () : -1;
}
public bool Equals (DiscoveryMessageSequence other)
{
if (other == null)
return false;
return InstanceId == other.InstanceId &&
(SequenceId == null && other.SequenceId == null || SequenceId.Equals (other.SequenceId)) &&
MessageNumber == other.MessageNumber;
}
public override bool Equals (object obj)
{
var s = obj as DiscoveryMessageSequence;
return s != null && Equals (s);
}
public override int GetHashCode ()
{
return (int) ((InstanceId * (SequenceId != null ? SequenceId.GetHashCode () : 1) << 17) + MessageNumber);
}
public override string ToString ()
{
return String.Format ("InstanceId={0}, SequenceId={1}, MessageNumber={2}", InstanceId, SequenceId, MessageNumber);
}
public static bool operator == (DiscoveryMessageSequence messageSequence1, DiscoveryMessageSequence messageSequence2)
{
return object.ReferenceEquals (messageSequence1, null) ? object.ReferenceEquals (messageSequence2, null) : messageSequence1.Equals (messageSequence2);
}
public static bool operator != (DiscoveryMessageSequence messageSequence1, DiscoveryMessageSequence messageSequence2)
{
return object.ReferenceEquals (messageSequence1, null) ? !object.ReferenceEquals (messageSequence2, null) : !messageSequence1.Equals (messageSequence2);
}
internal static DiscoveryMessageSequence ReadXml (XmlReader reader, DiscoveryVersion version)
{
if (reader == null)
throw new ArgumentNullException ("reader");
if (reader.LocalName != "AppSequence" || reader.NamespaceURI != version.Namespace)
throw new ArgumentException (String.Format ("AppSequenceType element in namespace '{0}' was expected. Got '{1}' element in '{2}' namespace", version.Namespace, reader.LocalName, reader.NamespaceURI));
var instId = reader.GetAttribute ("InstanceId");
var seqId = reader.GetAttribute ("SequenceId");
var msgno = reader.GetAttribute ("MessageNumber");
var source = new DiscoveryMessageSequence (instId != null ? XmlConvert.ToInt64 (instId) : 0, seqId != null ? new Uri (seqId, UriKind.RelativeOrAbsolute) : null, msgno != null ? XmlConvert.ToInt64 (msgno) : 0);
reader.Skip ();
return source;
}
internal void WriteXml (XmlWriter writer)
{
writer.WriteAttributeString ("InstanceId", XmlConvert.ToString (InstanceId));
if (SequenceId != null)
writer.WriteAttributeString ("SequenceId", SequenceId.ToString ());
writer.WriteAttributeString ("MessageNumber", XmlConvert.ToString (MessageNumber));
}
internal static XmlSchema BuildSchema (DiscoveryVersion version)
{
var schema = new XmlSchema () { TargetNamespace = version.Namespace };
var ccr = new XmlSchemaComplexContentRestriction ();
ccr.Attributes.Add (new XmlSchemaAttribute () { Name = "InstanceId", SchemaTypeName = new XmlQualifiedName ("unsignedInt", XmlSchema.Namespace), Use = XmlSchemaUse.Required });
ccr.Attributes.Add (new XmlSchemaAttribute () { Name = "SequenceId", SchemaTypeName = new XmlQualifiedName ("anyURI", XmlSchema.Namespace), Use = XmlSchemaUse.Optional });
ccr.Attributes.Add (new XmlSchemaAttribute () { Name = "MessageNumber", SchemaTypeName = new XmlQualifiedName ("unsignedInt", XmlSchema.Namespace), Use = XmlSchemaUse.Required });
var ct = new XmlSchemaComplexType () { Name = "AppSequenceType", ContentModel = new XmlSchemaComplexContent () { Content = ccr } };
schema.Items.Add (ct);
return schema;
}
}
}

View File

@ -0,0 +1,56 @@
//
// Author: Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2009 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
namespace System.ServiceModel.Discovery
{
public class DiscoveryMessageSequenceGenerator
{
public DiscoveryMessageSequenceGenerator ()
: this (AppDomain.CurrentDomain.Id, null) // not sure what should be used for instanceId; multiple instances share the same Id
{
}
public DiscoveryMessageSequenceGenerator (long instanceId, Uri sequenceId)
{
instance_id = instanceId;
sequence_id = sequenceId;
}
long instance_id, message_count;
Uri sequence_id;
public DiscoveryMessageSequence Next ()
{
return new DiscoveryMessageSequence (instance_id, sequence_id, ++message_count);
}
}
}

View File

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
namespace System.ServiceModel.Discovery
{
[MonoTODO]
public class DiscoveryOperationContextExtension : IExtension<OperationContext>
{
internal DiscoveryOperationContextExtension (DiscoveryEndpoint endpoint)
{
this.endpoint = endpoint;
}
DiscoveryEndpoint endpoint;
public ServiceDiscoveryMode DiscoveryMode {
get { return endpoint.DiscoveryMode; }
}
public DiscoveryVersion DiscoveryVersion {
get { return endpoint.DiscoveryVersion; }
}
public TimeSpan MaxResponseDelay {
get { return endpoint.MaxResponseDelay; }
internal set { endpoint.MaxResponseDelay = value; }
}
void IExtension<OperationContext>.Attach (OperationContext owner)
{
}
void IExtension<OperationContext>.Detach (OperationContext owner)
{
}
}
}

View File

@ -0,0 +1,234 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Discovery.Version11;
using System.ServiceModel.Discovery.VersionApril2005;
using System.ServiceModel.Discovery.VersionCD1;
namespace System.ServiceModel.Discovery
{
[MonoTODO]
public abstract class DiscoveryProxy : IDiscoveryProxyContract11, IDiscoveryProxyContractApril2005, IDiscoveryProxyContractCD1, IDiscoveryTargetContract11, IDiscoveryTargetContractApril2005, IDiscoveryTargetContractCD1
{
protected DiscoveryProxy ()
: this (new DiscoveryMessageSequenceGenerator ())
{
}
protected DiscoveryProxy (DiscoveryMessageSequenceGenerator messageSequenceGenerator)
: this (messageSequenceGenerator, 0)
{
}
protected DiscoveryProxy (DiscoveryMessageSequenceGenerator messageSequenceGenerator, int duplicateMessageHistoryLength)
{
}
internal DiscoveryMessageSequenceGenerator DiscoveryMessageSequenceGenerator { get; private set; }
internal int DuplicateMessageHistoryLength { get; private set; }
protected virtual IAsyncResult BeginShouldRedirectFind (FindCriteria resolveCriteria, AsyncCallback callback, Object state)
{
throw new NotImplementedException ();
}
protected virtual IAsyncResult BeginShouldRedirectResolve (ResolveCriteria findCriteria, AsyncCallback callback, Object state)
{
throw new NotImplementedException ();
}
protected virtual bool EndShouldRedirectFind (IAsyncResult result, out Collection<EndpointDiscoveryMetadata> redirectionEndpoints)
{
throw new NotImplementedException ();
}
protected virtual bool EndShouldRedirectResolve (IAsyncResult result, out Collection<EndpointDiscoveryMetadata> redirectionEndpoints)
{
throw new NotImplementedException ();
}
protected abstract IAsyncResult OnBeginFind (FindRequestContext findRequestContext, AsyncCallback callback, Object state);
protected abstract IAsyncResult OnBeginOfflineAnnouncement (DiscoveryMessageSequence messageSequence, EndpointDiscoveryMetadata endpointDiscoveryMetadata, AsyncCallback callback, Object state);
protected abstract IAsyncResult OnBeginOnlineAnnouncement (DiscoveryMessageSequence messageSequence, EndpointDiscoveryMetadata endpointDiscoveryMetadata, AsyncCallback callback, Object state);
protected abstract IAsyncResult OnBeginResolve (ResolveCriteria resolveCriteria, AsyncCallback callback, Object state);
protected abstract void OnEndFind (IAsyncResult result);
protected abstract void OnEndOfflineAnnouncement (IAsyncResult result);
protected abstract void OnEndOnlineAnnouncement (IAsyncResult result);
protected abstract EndpointDiscoveryMetadata OnEndResolve (IAsyncResult result);
#region service contract implementation
// IDiscoveryProxyContract11
IAsyncResult IDiscoveryProxyContract11.BeginFind (MessageContracts11.FindRequest message, AsyncCallback callback, object state)
{
return OnBeginFind (new DefaultFindRequestContext (message.Body.ToFindCriteria ()), callback, state);
}
MessageContracts11.FindResponse IDiscoveryProxyContract11.EndFind (IAsyncResult result)
{
OnEndFind (result);
throw new NotImplementedException ();
}
IAsyncResult IDiscoveryProxyContract11.BeginResolve (MessageContracts11.ResolveRequest message, AsyncCallback callback, object state)
{
return OnBeginResolve (message.Body.ToResolveCriteria (), callback, state);
}
MessageContracts11.ResolveResponse IDiscoveryProxyContract11.EndResolve (IAsyncResult result)
{
var ret = OnEndResolve (result);
return new MessageContracts11.ResolveResponse () { MessageSequence = new DiscoveryMessageSequence11 (DiscoveryMessageSequenceGenerator.Next ()), Body = new EndpointDiscoveryMetadata11 (ret) };
}
// IDiscoveryProxyContractApril2005
IAsyncResult IDiscoveryProxyContractApril2005.BeginFind (MessageContractsApril2005.FindRequest message, AsyncCallback callback, object state)
{
return OnBeginFind (new DefaultFindRequestContext (message.Body.ToFindCriteria ()), callback, state);
}
MessageContractsApril2005.FindResponse IDiscoveryProxyContractApril2005.EndFind (IAsyncResult result)
{
OnEndFind (result);
throw new NotImplementedException ();
}
IAsyncResult IDiscoveryProxyContractApril2005.BeginResolve (MessageContractsApril2005.ResolveRequest message, AsyncCallback callback, object state)
{
return OnBeginResolve (message.Body.ToResolveCriteria (), callback, state);
}
MessageContractsApril2005.ResolveResponse IDiscoveryProxyContractApril2005.EndResolve (IAsyncResult result)
{
var ret = OnEndResolve (result);
return new MessageContractsApril2005.ResolveResponse () { MessageSequence = new DiscoveryMessageSequenceApril2005 (DiscoveryMessageSequenceGenerator.Next ()), Body = new EndpointDiscoveryMetadataApril2005 (ret) };
}
// IDiscoveryProxyContractCD1
IAsyncResult IDiscoveryProxyContractCD1.BeginFind (MessageContractsCD1.FindRequest message, AsyncCallback callback, object state)
{
return OnBeginFind (new DefaultFindRequestContext (message.Body.ToFindCriteria ()), callback, state);
}
MessageContractsCD1.FindResponse IDiscoveryProxyContractCD1.EndFind (IAsyncResult result)
{
OnEndFind (result);
throw new NotImplementedException ();
}
IAsyncResult IDiscoveryProxyContractCD1.BeginResolve (MessageContractsCD1.ResolveRequest message, AsyncCallback callback, object state)
{
return OnBeginResolve (message.Body.ToResolveCriteria (), callback, state);
}
MessageContractsCD1.ResolveResponse IDiscoveryProxyContractCD1.EndResolve (IAsyncResult result)
{
var ret = OnEndResolve (result);
return new MessageContractsCD1.ResolveResponse () { MessageSequence = new DiscoveryMessageSequenceCD1 (DiscoveryMessageSequenceGenerator.Next ()), Body = new EndpointDiscoveryMetadataCD1 (ret) };
}
// IDiscoveryTargetContract11
IAsyncResult IDiscoveryTargetContract11.BeginFind (MessageContracts11.FindRequest message, AsyncCallback callback, object state)
{
return OnBeginFind (new DefaultFindRequestContext (message.Body.ToFindCriteria ()), callback, state);
}
void IDiscoveryTargetContract11.EndFind (IAsyncResult result)
{
OnEndFind (result);
}
IAsyncResult IDiscoveryTargetContract11.BeginResolve (MessageContracts11.ResolveRequest message, AsyncCallback callback, object state)
{
return OnBeginResolve (message.Body.ToResolveCriteria (), callback, state);
}
void IDiscoveryTargetContract11.EndResolve (IAsyncResult result)
{
OnEndResolve (result);
}
IAsyncResult IDiscoveryTargetContract11.BeginOnlineAnnouncement (MessageContracts11.OnlineAnnouncement msg, AsyncCallback callback, object state)
{
var edm = msg.EndpointDiscoveryMetadata != null ? msg.EndpointDiscoveryMetadata.ToEndpointDiscoveryMetadata () : null;
return OnBeginOnlineAnnouncement (DiscoveryMessageSequenceGenerator.Next (), edm, callback, state);
}
void IDiscoveryTargetContract11.EndOnlineAnnouncement (IAsyncResult result)
{
OnEndOnlineAnnouncement (result);
}
// IDiscoveryTargetContractApril2005
IAsyncResult IDiscoveryTargetContractApril2005.BeginFind (MessageContractsApril2005.FindRequest message, AsyncCallback callback, object state)
{
return OnBeginFind (new DefaultFindRequestContext (message.Body.ToFindCriteria ()), callback, state);
}
void IDiscoveryTargetContractApril2005.EndFind (IAsyncResult result)
{
OnEndFind (result);
}
IAsyncResult IDiscoveryTargetContractApril2005.BeginResolve (MessageContractsApril2005.ResolveRequest message, AsyncCallback callback, object state)
{
return OnBeginResolve (message.Body.ToResolveCriteria (), callback, state);
}
void IDiscoveryTargetContractApril2005.EndResolve (IAsyncResult result)
{
OnEndResolve (result);
}
IAsyncResult IDiscoveryTargetContractApril2005.BeginOnlineAnnouncement (MessageContractsApril2005.OnlineAnnouncement msg, AsyncCallback callback, object state)
{
var edm = msg.EndpointDiscoveryMetadata != null ? msg.EndpointDiscoveryMetadata.ToEndpointDiscoveryMetadata () : null;
return OnBeginOnlineAnnouncement (DiscoveryMessageSequenceGenerator.Next (), edm, callback, state);
}
void IDiscoveryTargetContractApril2005.EndOnlineAnnouncement (IAsyncResult result)
{
OnEndOnlineAnnouncement (result);
}
// IDiscoveryTargetContractCD1
IAsyncResult IDiscoveryTargetContractCD1.BeginFind (MessageContractsCD1.FindRequest message, AsyncCallback callback, object state)
{
return OnBeginFind (new DefaultFindRequestContext (message.Body.ToFindCriteria ()), callback, state);
}
void IDiscoveryTargetContractCD1.EndFind (IAsyncResult result)
{
OnEndFind (result);
}
IAsyncResult IDiscoveryTargetContractCD1.BeginResolve (MessageContractsCD1.ResolveRequest message, AsyncCallback callback, object state)
{
return OnBeginResolve (message.Body.ToResolveCriteria (), callback, state);
}
void IDiscoveryTargetContractCD1.EndResolve (IAsyncResult result)
{
OnEndResolve (result);
}
IAsyncResult IDiscoveryTargetContractCD1.BeginOnlineAnnouncement (MessageContractsCD1.OnlineAnnouncement msg, AsyncCallback callback, object state)
{
var edm = msg.EndpointDiscoveryMetadata != null ? msg.EndpointDiscoveryMetadata.ToEndpointDiscoveryMetadata () : null;
return OnBeginOnlineAnnouncement (DiscoveryMessageSequenceGenerator.Next (), edm, callback, state);
}
void IDiscoveryTargetContractCD1.EndOnlineAnnouncement (IAsyncResult result)
{
OnEndOnlineAnnouncement (result);
}
#endregion
}
}

View File

@ -0,0 +1,266 @@
//
// Author: Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2009,2010 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
namespace System.ServiceModel.Discovery
{
//* Strange, but this causes compiler error at DiscoveryClientBindingElement.
internal class DiscoveryChannel<TChannel> : DiscoveryChannelBase, IRequestSessionChannel, IDuplexSessionChannel
{
DiscoveryChannelFactory<TChannel> factory;
TChannel inner;
public DiscoveryChannel (DiscoveryChannelFactory<TChannel> factory, EndpointAddress address, Uri via)
: base (factory)
{
this.factory = factory;
RemoteAddress = address;
Via = via;
}
public EndpointAddress RemoteAddress { get; private set; }
public Uri Via { get; private set; }
public EndpointAddress LocalAddress {
get { return ((IDuplexSessionChannel) inner).LocalAddress; }
}
IDuplexSession ISessionChannel<IDuplexSession>.Session {
get { return ((IDuplexSessionChannel) inner).Session; }
}
IOutputSession ISessionChannel<IOutputSession>.Session {
get { return ((IOutputSessionChannel) inner).Session; }
}
Action<TimeSpan> open_delegate, close_delegate;
protected override IAsyncResult OnBeginClose (TimeSpan timeout, AsyncCallback callback, object state)
{
if (close_delegate == null)
close_delegate = new Action<TimeSpan> (OnClose);
return close_delegate.BeginInvoke (timeout, callback, state);
}
protected override void OnEndClose (IAsyncResult result)
{
close_delegate.EndInvoke (result);
}
protected override void OnAbort ()
{
if (inner != null) {
((IChannel) inner).Abort ();
inner = default (TChannel);
}
}
protected override void OnClose (TimeSpan timeout)
{
if (inner != null) {
((IChannel) inner).Close (timeout);
inner = default (TChannel);
}
}
protected override IAsyncResult OnBeginOpen (TimeSpan timeout, AsyncCallback callback, object state)
{
if (open_delegate == null)
open_delegate = new Action<TimeSpan> (OnOpen);
return open_delegate.BeginInvoke (timeout, callback, state);
}
protected override void OnEndOpen (IAsyncResult result)
{
open_delegate.EndInvoke (result);
}
protected override void OnOpen (TimeSpan timeout)
{
// FIXME: use timeout
DateTime start = DateTime.Now;
inner = CreateDiscoveryInnerChannel<TChannel> (factory);
((IChannel) inner).Open (timeout - (DateTime.Now - start));
}
public Message Request (Message msg)
{
return Request (msg, DefaultSendTimeout + DefaultReceiveTimeout);
}
public Message Request (Message msg, TimeSpan timeout)
{
return ((IRequestChannel) inner).Request (msg, timeout);
}
public IAsyncResult BeginRequest (Message msg, AsyncCallback callback, object state)
{
return BeginRequest (msg, DefaultSendTimeout + DefaultReceiveTimeout, callback, state);
}
public IAsyncResult BeginRequest (Message msg, TimeSpan timeout, AsyncCallback callback, object state)
{
return ((IRequestChannel) inner).BeginRequest (msg, timeout, callback, state);
}
public Message EndRequest (IAsyncResult result)
{
return ((IRequestChannel) inner).EndRequest (result);
}
public Message Receive ()
{
return Receive (DefaultReceiveTimeout);
}
public Message Receive (TimeSpan timeout)
{
return ((IInputChannel) inner).Receive (timeout);
}
public IAsyncResult BeginReceive (AsyncCallback callback, object state)
{
return BeginReceive (DefaultReceiveTimeout, callback, state);
}
public IAsyncResult BeginReceive (TimeSpan timeout, AsyncCallback callback, object state)
{
return ((IInputChannel) inner).BeginReceive (timeout, callback, state);
}
public Message EndReceive (IAsyncResult result)
{
return ((IInputChannel) inner).EndReceive (result);
}
public bool TryReceive (out Message msg)
{
return TryReceive (DefaultReceiveTimeout, out msg);
}
public bool TryReceive (TimeSpan timeout, out Message msg)
{
return ((IInputChannel) inner).TryReceive (timeout, out msg);
}
public IAsyncResult BeginTryReceive (TimeSpan timeout, AsyncCallback callback, object state)
{
return ((IInputChannel) inner).BeginTryReceive (timeout, callback, state);
}
public bool EndTryReceive (IAsyncResult result, out Message msg)
{
return ((IInputChannel) inner).EndTryReceive (result, out msg);
}
public bool WaitForMessage (TimeSpan timeout)
{
return ((IInputChannel) inner).WaitForMessage (timeout);
}
public IAsyncResult BeginWaitForMessage (TimeSpan timeout, AsyncCallback callback, object state)
{
return ((IInputChannel) inner).BeginWaitForMessage (timeout, callback, state);
}
public bool EndWaitForMessage (IAsyncResult result)
{
return ((IInputChannel) inner).EndWaitForMessage (result);
}
public void Send (Message msg)
{
Send (msg, DefaultSendTimeout);
}
public void Send (Message msg, TimeSpan timeout)
{
((IOutputChannel) inner).Send (msg, timeout);
}
public IAsyncResult BeginSend (Message msg, AsyncCallback callback, object state)
{
return BeginSend (msg, DefaultSendTimeout, callback, state);
}
public IAsyncResult BeginSend (Message msg, TimeSpan timeout, AsyncCallback callback, object state)
{
return ((IOutputChannel) inner).BeginSend (msg, timeout, callback, state);
}
public void EndSend (IAsyncResult result)
{
((IOutputChannel) inner).EndSend (result);
}
}
//*/
internal class DiscoveryRequestChannel : RequestChannelBase
{
public DiscoveryRequestChannel (DiscoveryChannelFactory<IRequestChannel> factory, EndpointAddress address, Uri via)
: base (factory, address, via)
{
this.factory = factory;
}
DiscoveryChannelFactory<IRequestChannel> factory;
IRequestChannel inner;
DiscoveryClient client;
protected override void OnOpen (TimeSpan timeout)
{
inner = CreateDiscoveryInnerChannel<IRequestChannel> (factory);
}
protected override void OnClose (TimeSpan timeout)
{
if (inner != null) {
inner.Close (timeout);
inner = null;
}
}
protected override void OnAbort ()
{
if (inner != null) {
inner.Abort ();
inner = null;
}
}
public override Message Request (Message input, TimeSpan timeout)
{
ThrowIfDisposedOrNotOpen ();
return inner.Request (input, timeout);
}
}
}

View File

@ -0,0 +1,371 @@
//
// Author: Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2009,2010 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Discovery.Version11;
using System.ServiceModel.Discovery.VersionApril2005;
using System.ServiceModel.Discovery.VersionCD1;
namespace System.ServiceModel.Discovery
{
public abstract class DiscoveryService : IDiscoveryProxyContract11, IDiscoveryProxyContractApril2005, IDiscoveryProxyContractCD1, IDiscoveryTargetContract11, IDiscoveryTargetContractApril2005, IDiscoveryTargetContractCD1
{
protected DiscoveryService ()
: this (new DiscoveryMessageSequenceGenerator ())
{
}
protected DiscoveryService (DiscoveryMessageSequenceGenerator discoveryMessageSequenceGenerator)
: this (discoveryMessageSequenceGenerator, 0)
{
}
protected DiscoveryService (DiscoveryMessageSequenceGenerator discoveryMessageSequenceGenerator, int duplicateMessageHistoryLength)
{
DiscoveryMessageSequenceGenerator = discoveryMessageSequenceGenerator;
DuplicateMessageHistoryLength = duplicateMessageHistoryLength;
}
internal DiscoveryMessageSequenceGenerator DiscoveryMessageSequenceGenerator { get; private set; }
internal int DuplicateMessageHistoryLength { get; private set; }
protected abstract IAsyncResult OnBeginFind (FindRequestContext findRequestContext, AsyncCallback callback, Object state);
protected abstract IAsyncResult OnBeginResolve (ResolveCriteria resolveCriteria, AsyncCallback callback, Object state);
protected abstract void OnEndFind (IAsyncResult result);
protected abstract EndpointDiscoveryMetadata OnEndResolve (IAsyncResult result);
#region service contract implementation
// IDiscoveryProxyContract11
FindRequestContext find_context;
IAsyncResult IDiscoveryProxyContract11.BeginFind (MessageContracts11.FindRequest message, AsyncCallback callback, object state)
{
if (find_context != null)
throw new InvalidOperationException ("Another async Find operation is ongoing");
find_context = new DefaultFindRequestContext (message.Body.ToFindCriteria ());
return OnBeginFind (find_context, callback, state);
}
MessageContracts11.FindResponse IDiscoveryProxyContract11.EndFind (IAsyncResult result)
{
OnEndFind (result);
return CreateFindResponse11 ();
}
MessageContracts11.FindResponse CreateFindResponse11 ()
{
var l = new MessageContracts11.FindResponse11 ();
foreach (var edm in find_context.Endpoints)
l.Add (new EndpointDiscoveryMetadata11 (edm));
find_context = null;
return new MessageContracts11.FindResponse () { Body = l };
}
IAsyncResult IDiscoveryProxyContract11.BeginResolve (MessageContracts11.ResolveRequest message, AsyncCallback callback, object state)
{
return OnBeginResolve (message.Body.ToResolveCriteria (), callback, state);
}
MessageContracts11.ResolveResponse IDiscoveryProxyContract11.EndResolve (IAsyncResult result)
{
var ret = OnEndResolve (result);
return new MessageContracts11.ResolveResponse () { MessageSequence = new DiscoveryMessageSequence11 (DiscoveryMessageSequenceGenerator.Next ()), Body = new EndpointDiscoveryMetadata11 (ret) };
}
// IDiscoveryProxyContractApril2005
IAsyncResult IDiscoveryProxyContractApril2005.BeginFind (MessageContractsApril2005.FindRequest message, AsyncCallback callback, object state)
{
if (find_context != null)
throw new InvalidOperationException ("Another async Find operation is ongoing");
find_context = new DefaultFindRequestContext (message.Body.ToFindCriteria ());
return OnBeginFind (find_context, callback, state);
}
MessageContractsApril2005.FindResponse IDiscoveryProxyContractApril2005.EndFind (IAsyncResult result)
{
OnEndFind (result);
return CreateFindResponseApril2005 ();
}
MessageContractsApril2005.FindResponse CreateFindResponseApril2005 ()
{
var l = new MessageContractsApril2005.FindResponseApril2005 ();
foreach (var edm in find_context.Endpoints)
l.Add (new EndpointDiscoveryMetadataApril2005 (edm));
find_context = null;
return new MessageContractsApril2005.FindResponse () { Body = l };
}
IAsyncResult IDiscoveryProxyContractApril2005.BeginResolve (MessageContractsApril2005.ResolveRequest message, AsyncCallback callback, object state)
{
return OnBeginResolve (message.Body.ToResolveCriteria (), callback, state);
}
MessageContractsApril2005.ResolveResponse IDiscoveryProxyContractApril2005.EndResolve (IAsyncResult result)
{
var ret = OnEndResolve (result);
return new MessageContractsApril2005.ResolveResponse () { MessageSequence = new DiscoveryMessageSequenceApril2005 (DiscoveryMessageSequenceGenerator.Next ()), Body = new EndpointDiscoveryMetadataApril2005 (ret) };
}
// IDiscoveryProxyContractCD1
IAsyncResult IDiscoveryProxyContractCD1.BeginFind (MessageContractsCD1.FindRequest message, AsyncCallback callback, object state)
{
if (find_context != null)
throw new InvalidOperationException ("Another async Find operation is ongoing");
find_context = new DefaultFindRequestContext (message.Body.ToFindCriteria ());
return OnBeginFind (find_context, callback, state);
}
MessageContractsCD1.FindResponse IDiscoveryProxyContractCD1.EndFind (IAsyncResult result)
{
OnEndFind (result);
return CreateFindResponseCD1 ();
}
MessageContractsCD1.FindResponse CreateFindResponseCD1 ()
{
var l = new MessageContractsCD1.FindResponseCD1 ();
foreach (var edm in find_context.Endpoints)
l.Add (new EndpointDiscoveryMetadataCD1 (edm));
find_context = null;
return new MessageContractsCD1.FindResponse () { Body = l };
}
IAsyncResult IDiscoveryProxyContractCD1.BeginResolve (MessageContractsCD1.ResolveRequest message, AsyncCallback callback, object state)
{
return OnBeginResolve (message.Body.ToResolveCriteria (), callback, state);
}
MessageContractsCD1.ResolveResponse IDiscoveryProxyContractCD1.EndResolve (IAsyncResult result)
{
var ret = OnEndResolve (result);
return new MessageContractsCD1.ResolveResponse () { MessageSequence = new DiscoveryMessageSequenceCD1 (DiscoveryMessageSequenceGenerator.Next ()), Body = new EndpointDiscoveryMetadataCD1 (ret) };
}
// IDiscoveryTargetContract11
IAsyncResult IDiscoveryTargetContract11.BeginFind (MessageContracts11.FindRequest message, AsyncCallback callback, object state)
{
find_context = new DefaultFindRequestContext (message.Body.ToFindCriteria ());
return OnBeginFind (new DefaultFindRequestContext (message.Body.ToFindCriteria ()), callback, state);
}
void IDiscoveryTargetContract11.EndFind (IAsyncResult result)
{
OnEndFind (result);
var cb = OperationContext.Current.GetCallbackChannel<IDiscoveryTargetCallbackContract11> ();
cb.ReplyFind (CreateFindResponse11 ());
}
IAsyncResult IDiscoveryTargetContract11.BeginResolve (MessageContracts11.ResolveRequest message, AsyncCallback callback, object state)
{
return OnBeginResolve (message.Body.ToResolveCriteria (), callback, state);
}
void IDiscoveryTargetContract11.EndResolve (IAsyncResult result)
{
OnEndResolve (result);
}
IAsyncResult IDiscoveryTargetContract11.BeginOnlineAnnouncement (MessageContracts11.OnlineAnnouncement message, AsyncCallback callback, object state)
{
// is it expected to be invoked??
throw new NotImplementedException ();
}
void IDiscoveryTargetContract11.EndOnlineAnnouncement (IAsyncResult result)
{
// is it expected to be invoked??
throw new NotImplementedException ();
}
// IDiscoveryTargetContractApril2005
IAsyncResult IDiscoveryTargetContractApril2005.BeginFind (MessageContractsApril2005.FindRequest message, AsyncCallback callback, object state)
{
find_context = new DefaultFindRequestContext (message.Body.ToFindCriteria ());
return OnBeginFind (new DefaultFindRequestContext (message.Body.ToFindCriteria ()), callback, state);
}
void IDiscoveryTargetContractApril2005.EndFind (IAsyncResult result)
{
OnEndFind (result);
var cb = OperationContext.Current.GetCallbackChannel<IDiscoveryTargetCallbackContractApril2005> ();
cb.ReplyFind (CreateFindResponseApril2005 ());
}
IAsyncResult IDiscoveryTargetContractApril2005.BeginResolve (MessageContractsApril2005.ResolveRequest message, AsyncCallback callback, object state)
{
return OnBeginResolve (message.Body.ToResolveCriteria (), callback, state);
}
void IDiscoveryTargetContractApril2005.EndResolve (IAsyncResult result)
{
OnEndResolve (result);
}
IAsyncResult IDiscoveryTargetContractApril2005.BeginOnlineAnnouncement (MessageContractsApril2005.OnlineAnnouncement message, AsyncCallback callback, object state)
{
// is it expected to be invoked??
throw new NotImplementedException ();
}
void IDiscoveryTargetContractApril2005.EndOnlineAnnouncement (IAsyncResult result)
{
// is it expected to be invoked??
throw new NotImplementedException ();
}
// IDiscoveryTargetContractCD1
IAsyncResult IDiscoveryTargetContractCD1.BeginFind (MessageContractsCD1.FindRequest message, AsyncCallback callback, object state)
{
find_context = new DefaultFindRequestContext (message.Body.ToFindCriteria ());
return OnBeginFind (new DefaultFindRequestContext (message.Body.ToFindCriteria ()), callback, state);
}
void IDiscoveryTargetContractCD1.EndFind (IAsyncResult result)
{
OnEndFind (result);
var cb = OperationContext.Current.GetCallbackChannel<IDiscoveryTargetCallbackContractCD1> ();
cb.ReplyFind (CreateFindResponseCD1 ());
}
IAsyncResult IDiscoveryTargetContractCD1.BeginResolve (MessageContractsCD1.ResolveRequest message, AsyncCallback callback, object state)
{
return OnBeginResolve (message.Body.ToResolveCriteria (), callback, state);
}
void IDiscoveryTargetContractCD1.EndResolve (IAsyncResult result)
{
OnEndResolve (result);
}
IAsyncResult IDiscoveryTargetContractCD1.BeginOnlineAnnouncement (MessageContractsCD1.OnlineAnnouncement message, AsyncCallback callback, object state)
{
// is it expected to be invoked??
throw new NotImplementedException ();
}
void IDiscoveryTargetContractCD1.EndOnlineAnnouncement (IAsyncResult result)
{
// is it expected to be invoked??
throw new NotImplementedException ();
}
#endregion
}
internal class DefaultDiscoveryService : DiscoveryService
{
Action<FindRequestContext> find_delegate;
Func<ResolveCriteria,EndpointDiscoveryMetadata> resolve_delegate;
protected override IAsyncResult OnBeginFind (FindRequestContext findRequestContext, AsyncCallback callback, object state)
{
// FIXME: this is a workaround for (similar to) bug #633945.
switch (Environment.OSVersion.Platform) {
case PlatformID.Unix:
case PlatformID.MacOSX:
if (find_delegate == null)
find_delegate = new Action<FindRequestContext> (Find);
return find_delegate.BeginInvoke (findRequestContext, callback, state);
default:
Find (findRequestContext);
var result = new TempAsyncResult (null, state);
if (callback != null)
callback (result);
return result;
}
}
protected override void OnEndFind (IAsyncResult result)
{
// FIXME: this is a workaround for (similar to) bug #633945.
switch (Environment.OSVersion.Platform) {
case PlatformID.Unix:
case PlatformID.MacOSX:
find_delegate.EndInvoke (result);
break;
default:
break;
}
var oc = OperationContext.Current;
var rmp = oc.IncomingMessageProperties [RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
if (rmp != null)
// FIXME: use appropriate port. Client does not listen at the sending port.
oc.OutgoingMessageProperties.Add (RemoteEndpointMessageProperty.Name, new RemoteEndpointMessageProperty (rmp.Address, rmp.Port));
}
protected override IAsyncResult OnBeginResolve (ResolveCriteria resolveCriteria, AsyncCallback callback, object state)
{
// FIXME: this is a workaround for (similar to) bug #633945.
switch (Environment.OSVersion.Platform) {
case PlatformID.Unix:
case PlatformID.MacOSX:
if (resolve_delegate == null)
resolve_delegate = new Func<ResolveCriteria,EndpointDiscoveryMetadata> (Resolve);
return resolve_delegate.BeginInvoke (resolveCriteria, callback, state);
default:
var ret = Resolve (resolveCriteria);
var result = new TempAsyncResult (ret, state);
if (callback != null)
callback (result);
return result;
}
}
protected override EndpointDiscoveryMetadata OnEndResolve (IAsyncResult result)
{
// FIXME: this is a workaround for (similar to) bug #633945.
switch (Environment.OSVersion.Platform) {
case PlatformID.Unix:
case PlatformID.MacOSX:
return resolve_delegate.EndInvoke (result);
default:
return (EndpointDiscoveryMetadata) ((TempAsyncResult) result).ReturnValue;
}
}
void Find (FindRequestContext context)
{
throw new NotImplementedException ();
}
EndpointDiscoveryMetadata Resolve (ResolveCriteria criteria)
{
throw new NotImplementedException ();
}
}
}

View File

@ -0,0 +1,73 @@
//
// Author: Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2009,2010 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
namespace System.ServiceModel.Discovery
{
// This class is for custom implementation.
// It is used by ServiceDiscoveryBehavior to find an extension of this
// type, to call GetDiscoveryService().
// See http://msdn.microsoft.com/en-us/library/system.servicemodel.discovery.discoveryserviceextension.aspx
public abstract class DiscoveryServiceExtension : IExtension<ServiceHostBase>
{
protected DiscoveryServiceExtension ()
{
PublishedInternalEndpoints = new Collection<EndpointDiscoveryMetadata> ();
PublishedEndpoints = new ReadOnlyCollection<EndpointDiscoveryMetadata> (PublishedInternalEndpoints);
}
internal Collection<EndpointDiscoveryMetadata> PublishedInternalEndpoints { get; private set; }
internal DiscoveryService Service { get; private set; }
public ReadOnlyCollection<EndpointDiscoveryMetadata> PublishedEndpoints { get; private set; }
protected abstract DiscoveryService GetDiscoveryService ();
void IExtension<ServiceHostBase>.Attach (ServiceHostBase owner)
{
// FIXME: use it somewhere
Service = GetDiscoveryService ();
}
void IExtension<ServiceHostBase>.Detach (ServiceHostBase owner)
{
}
internal class DefaultDiscoveryServiceExtension : DiscoveryServiceExtension
{
protected override DiscoveryService GetDiscoveryService ()
{
return new DefaultDiscoveryService ();
}
}
}
}

View File

@ -0,0 +1,141 @@
//
// Author: Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2009 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Discovery.Version11;
using System.ServiceModel.Discovery.VersionApril2005;
using System.ServiceModel.Discovery.VersionCD1;
namespace System.ServiceModel.Discovery
{
public sealed class DiscoveryVersion
{
internal const string Namespace11 = "http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01";
internal const string NamespaceApril2005 = "http://schemas.xmlsoap.org/ws/2005/04/discovery";
internal const string NamespaceCD1 = "http://docs.oasis-open.org/ws-dd/ns/discovery/2008/09";
static DiscoveryVersion ()
{
v11 = new DiscoveryVersion ("WSDiscovery11",
Namespace11,
"urn:docs-oasis-open-org:ws-dd:ns:discovery:2009:01",
MessageVersion.Soap12WSAddressing10,
typeof (Version11.IAnnouncementContract11),
typeof (AnnouncementClient11),
typeof (IDiscoveryProxyContract11),
typeof (DiscoveryProxyClient11),
typeof (IDiscoveryTargetContract11),
typeof (DiscoveryTargetClient11));
april2005 = new DiscoveryVersion ("WSDiscoveryApril2005",
NamespaceApril2005,
"urn:schemas-xmlsoap-org:ws:2005:04:discovery",
MessageVersion.Soap12WSAddressingAugust2004,
typeof (IAnnouncementContractApril2005),
typeof (AnnouncementClientApril2005),
typeof (IDiscoveryProxyContractApril2005),
typeof (DiscoveryProxyClientApril2005),
typeof (IDiscoveryTargetContractApril2005),
typeof (DiscoveryTargetClientApril2005));
cd1 = new DiscoveryVersion ("WSDiscoveryCD1",
NamespaceCD1,
"urn:docs-oasis-open-org:ws-dd:discovery:2008:09",
MessageVersion.Soap12WSAddressingAugust2004,
typeof (IAnnouncementContractCD1),
typeof (AnnouncementClientCD1),
typeof (IDiscoveryProxyContractCD1),
typeof (DiscoveryProxyClientCD1),
typeof (IDiscoveryTargetContractCD1),
typeof (DiscoveryTargetClientCD1));
}
static readonly DiscoveryVersion v11, april2005, cd1;
public static DiscoveryVersion WSDiscovery11 {
get { return v11; }
}
public static DiscoveryVersion WSDiscoveryApril2005 {
get { return april2005; }
}
public static DiscoveryVersion WSDiscoveryCD1 {
get { return cd1; }
}
public static DiscoveryVersion FromName (string name)
{
if (name == null)
throw new ArgumentNullException ("name");
switch (name) {
case "WSDiscovery11":
return v11;
case "WSDiscoveryApril2005":
return april2005;
case "WSDiscoveryCD1":
return cd1;
default:
throw new ArgumentOutOfRangeException (String.Format ("Invalid version name: {0}", name));
}
}
internal DiscoveryVersion (string name, string ns, string adhoc, MessageVersion version, Type announcementContractType, Type announcementClientType, Type discoveryProxyContractType, Type discoveryProxyClientType, Type discoveryTargetContractType, Type discoveryTargetClientType)
{
this.Name = name;
this.Namespace = ns;
AdhocAddress = new Uri (adhoc);
MessageVersion = version;
AnnouncementContractType = announcementContractType;
AnnouncementClientType = announcementClientType;
DiscoveryProxyContractType = discoveryProxyContractType;
DiscoveryProxyClientType = discoveryProxyClientType;
DiscoveryTargetContractType = discoveryTargetContractType;
DiscoveryTargetClientType = discoveryTargetClientType;
}
public Uri AdhocAddress { get; private set; }
public MessageVersion MessageVersion { get; private set; }
public string Name { get; private set; }
public string Namespace { get; private set; }
internal Type AnnouncementContractType { get; private set; }
internal Type AnnouncementClientType { get; private set; }
internal Type DiscoveryProxyContractType { get; private set; }
internal Type DiscoveryProxyClientType { get; private set; }
internal Type DiscoveryTargetContractType { get; private set; }
internal Type DiscoveryTargetClientType { get; private set; }
public override string ToString ()
{
return Name;
}
}
}

Some files were not shown because too many files have changed in this diff Show More