#region service contract implementation
// IDiscoveryProxyContract11
+
+ FindRequestContext find_context;
+
IAsyncResult IDiscoveryProxyContract11.BeginFind (MessageContracts11.FindRequest message, AsyncCallback callback, object state)
{
- return OnBeginFind (new DefaultFindRequestContext (message.Body.ToFindCriteria ()), callback, 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);
- throw new NotImplementedException ();
+ 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)
// IDiscoveryProxyContractApril2005
IAsyncResult IDiscoveryProxyContractApril2005.BeginFind (MessageContractsApril2005.FindRequest message, AsyncCallback callback, object state)
{
- return OnBeginFind (new DefaultFindRequestContext (message.Body.ToFindCriteria ()), callback, 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);
- throw new NotImplementedException ();
+ 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)
// IDiscoveryProxyContractCD1
IAsyncResult IDiscoveryProxyContractCD1.BeginFind (MessageContractsCD1.FindRequest message, AsyncCallback callback, object state)
{
- return OnBeginFind (new DefaultFindRequestContext (message.Body.ToFindCriteria ()), callback, 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);
- throw new NotImplementedException ();
+ 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)
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
public Uri ScopeMatchBy { get; set; }
public Collection<Uri> Scopes { get; private set; }
- [MonoTODO]
+ [MonoTODO ("find out conformant behavior, and implement remaining bits")]
public bool IsMatch (EndpointDiscoveryMetadata endpointDiscoveryMetadata)
{
- throw new NotImplementedException ();
+ var edm = endpointDiscoveryMetadata;
+ if (edm == null)
+ throw new ArgumentNullException ("endpointDiscoveryMetadata");
+ if (edm.ContractTypeNames.Count > 0) {
+ bool match = false;
+ foreach (var qn in edm.ContractTypeNames)
+ if (ContractTypeNames.Contains (qn))
+ match = true;
+ if (!match)
+ return false;
+ }
+ if (edm.Scopes.Count > 0) {
+ bool match = false;
+ foreach (var scope in edm.Scopes) {
+ if (ScopeMatchBy == null || ScopeMatchBy.Equals (ScopeMatchByPrefix)) {
+ if (Scopes.Contains (scope))
+ match = true;
+ } else if (ScopeMatchBy.Equals (ScopeMatchByExact)) {
+ if (Scopes.Any (s => s.AbsoluteUri == scope.AbsoluteUri))
+ match = true;
+ }
+ else if (ScopeMatchBy.Equals (ScopeMatchByUuid))
+ throw new NotImplementedException ();
+ else if (ScopeMatchBy.Equals (ScopeMatchByNone))
+ throw new NotImplementedException ();
+ else if (ScopeMatchBy.Equals (ScopeMatchByLdap))
+ throw new NotImplementedException ();
+ else
+ throw new InvalidOperationException (String.Format ("Unexpected ScopeMatchBy value: {0}", ScopeMatchBy));
+ }
+ if (!match)
+ return false;
+ }
+ if (Extensions.Count > 0)
+ throw new NotImplementedException ();
+
+ return true;
}
internal static FindCriteria ReadXml (XmlReader reader, DiscoveryVersion version)
if (criteria == null)
throw new ArgumentNullException ("criteria");
Criteria = criteria;
+ Endpoints = new Collection<EndpointDiscoveryMetadata> ();
}
public FindCriteria Criteria { get; private set; }
- [MonoTODO]
+ internal Collection<EndpointDiscoveryMetadata> Endpoints { get; private set; }
+
public void AddMatchingEndpoint (EndpointDiscoveryMetadata matchingEndpoint)
{
+ if (matchingEndpoint == null)
+ throw new ArgumentNullException ("matchingEndpoint");
OnAddMatchingEndpoint (matchingEndpoint);
}
- [MonoTODO]
protected virtual void OnAddMatchingEndpoint (EndpointDiscoveryMetadata matchingEndpoint)
{
- throw new NotImplementedException ();
+ if (matchingEndpoint == null)
+ throw new ArgumentNullException ("matchingEndpoint");
+ Endpoints.Add (matchingEndpoint);
}
}