protected override IAsyncResult OnBeginResolve(ResolveCriteria resolveCriteria, AsyncCallback callback, object state)
 {
     return new CompletedAsyncResult<EndpointDiscoveryMetadata>(
         this.Match(resolveCriteria),
         callback,
         state);
 }
Exemplo n.º 2
0
		internal static ResolveCriteria ReadXml (XmlReader reader, DiscoveryVersion version)
		{
			if (reader == null)
				throw new ArgumentNullException ("reader");

			var ret = new ResolveCriteria ();

			reader.MoveToContent ();
			if (!reader.IsStartElement ("ResolveType", version.Namespace) || reader.IsEmptyElement)
				throw new XmlException ("Non-empty ResolveType element is expected");
			reader.ReadStartElement ("ResolveType", version.Namespace);

			// standard members
			reader.MoveToContent ();
			ret.Address = EndpointAddress.ReadFrom (version.MessageVersion.Addressing, reader);

			// non-standard members
			for (reader.MoveToContent (); !reader.EOF && reader.NodeType != XmlNodeType.EndElement; reader.MoveToContent ()) {
				if (reader.NamespaceURI == SerializationNS) {
					switch (reader.LocalName) {
					case "Duration":
						ret.Duration = (TimeSpan) reader.ReadElementContentAs (typeof (TimeSpan), null);
						break;
					}
				}
				else
					ret.Extensions.Add (XElement.Load (reader));
			}

			reader.ReadEndElement ();

			return ret;
		}
Exemplo n.º 3
0
 protected override IAsyncResult OnBeginResolve(ResolveCriteria resolveCriteria, AsyncCallback callback, object state)
 {
     return(new CompletedAsyncResult <EndpointDiscoveryMetadata>(
                this.Match(resolveCriteria),
                callback,
                state));
 }
        protected ResolveRequestResponseAsyncResult(
            TResolveMessage resolveMessage,
            IDiscoveryServiceImplementation discoveryServiceImpl,
            AsyncCallback callback,
            object state)
            : base(callback, state)
        {
            Fx.Assert(resolveMessage != null, "The resolveMessage must be non null.");
            Fx.Assert(discoveryServiceImpl != null, "The discoveryServiceImpl must be non null.");

            this.discoveryServiceImpl = discoveryServiceImpl;

            if (!this.Validate(resolveMessage))
            {
                this.Complete(true);
                return;
            }
            else
            {
                this.context         = new DiscoveryOperationContext(OperationContext.Current);
                this.resolveCriteria = this.GetResolveCriteria(resolveMessage);
                if (this.ProcessResolveRequest())
                {
                    this.Complete(true);
                    return;
                }
            }
        }
Exemplo n.º 5
0
        protected ResolveDuplexAsyncResult(TResolveMessage resolveMessage,
                                           IDiscoveryServiceImplementation discoveryServiceImpl,
                                           IMulticastSuppressionImplementation multicastSuppressionImpl,
                                           AsyncCallback callback,
                                           object state)
            : base(callback, state)
        {
            Fx.Assert(resolveMessage != null, "The resolveMessage must be non null.");
            Fx.Assert(discoveryServiceImpl != null, "The discoveryServiceImpl must be non null.");

            this.discoveryServiceImpl     = discoveryServiceImpl;
            this.multicastSuppressionImpl = multicastSuppressionImpl;

            if (!this.Validate(resolveMessage))
            {
                this.Complete(true);
                return;
            }
            else
            {
                this.context         = new DiscoveryOperationContext(OperationContext.Current);
                this.resolveCriteria = this.GetResolveCriteria(resolveMessage);
                this.timeoutHelper   = new TimeoutHelper(this.resolveCriteria.Duration);
                this.timeoutHelper.RemainingTime();
                this.Process();
            }
        }
        protected override IAsyncResult OnBeginResolve(ResolveCriteria resolveCriteria, AsyncCallback callback, object state)
        {
            Console.WriteLine("Received a Resolve request message. Forwarding the Resolve message.");

            // ResolveAsyncResult will forward the Resolve request
            return new ResolveAsyncResult(resolveCriteria, this.forwardingDiscoveryEndpoint, callback, state);
        }
 //Resolve
 protected override IAsyncResult OnBeginResolve(ResolveCriteria resolveCriteria, AsyncCallback callback, object state)
 {
     EndpointDiscoveryMetadata endpoint = null;
     if (this.Endpoints.ContainsKey(resolveCriteria.Address))
     {
         endpoint = this.Endpoints[resolveCriteria.Address];
     }
     return new DiscoveryAsyncResult(callback, endpoint);
 }
Exemplo n.º 8
0
        public virtual EndpointDiscoveryMetadata ResolveEndpoint(ResolveCriteria resolveCriteria)
        {
			foreach (var metadata in endpoints.Values)
            {
                if (resolveCriteria.Address == metadata.Address)
                {
                    return metadata;
                }
            }
            return null;
        }
 public virtual EndpointDiscoveryMetadata ResolveService(ResolveCriteria resolveCriteria)
 {
     foreach (EndpointDiscoveryMetadata metadata in services.Values)
     {
         if (resolveCriteria.Address == metadata.Address)
         {
             return metadata;
         }
     }
     return null;
 }
 public EndpointDiscoveryMetadata Match(ResolveCriteria criteria)
 {
     EndpointDiscoveryMetadata matchingEndpoint = null;
     _logger.Log("Matching " + criteria, LogLevel.Debug);
     foreach (var onlineService in _onlineServices.Values.Where(x => criteria.Address == x.Metadata.Address))
     {
         _logger.Log("...found " + criteria.Address, LogLevel.Debug);
         matchingEndpoint = onlineService.Metadata;
     }
     return matchingEndpoint;
 }
Exemplo n.º 11
0
        public ResolveAsyncResult(ResolveCriteria resolveCriteria, DiscoveryEndpoint forwardingDiscoveryEndpoint, AsyncCallback callback, object state)
            : base(callback, state)
        {
            this.resolveCriteria = resolveCriteria;

            this.discoveryClient = new DiscoveryClient(forwardingDiscoveryEndpoint);
            this.discoveryClient.ResolveCompleted += new EventHandler<ResolveCompletedEventArgs>(ResolveCompleted);

            // Forwards the Resolve request message
            this.discoveryClient.ResolveAsync(resolveCriteria);
        }
Exemplo n.º 12
0
        EndpointDiscoveryMetadata Match(ResolveCriteria criteria)
        {
            for (int i = 0; i < this.publishedEndpoints.Count; i++)
            {
                if (this.publishedEndpoints[i].Address.Equals(criteria.Address))
                {
                    return(this.publishedEndpoints[i]);
                }
            }

            return(null);
        }
        EndpointDiscoveryMetadata Match(ResolveCriteria criteria)
        {
            for (int i = 0; i < this.publishedEndpoints.Count; i++)
            {
                if (this.publishedEndpoints[i].Address.Equals(criteria.Address))
                {
                    return this.publishedEndpoints[i];
                }
            }

            return null;
        }
 public EndpointDiscoveryMetadata MatchFromOnlineService(ResolveCriteria criteria)
 {
     EndpointDiscoveryMetadata matchingEndpoint = null;
     lock (_onlineServices)
     {
         foreach (var endpointDiscoveryMetadata in _onlineServices.Values)
         {
             if (criteria.Address == endpointDiscoveryMetadata.Address)
             {
                 matchingEndpoint = endpointDiscoveryMetadata;
             }
         }
     }
     return matchingEndpoint;
 }
Exemplo n.º 15
0
        protected override IAsyncResult OnBeginResolve(ResolveCriteria resolveCriteria, AsyncCallback callback, object state)
        {
            EndpointDiscoveryMetadata matchingEndpoint = null;

            foreach (EndpointDiscoveryMetadata endpointDiscoveryMetadata in this.publishedEndpoints)
            {
                if (resolveCriteria.Address == endpointDiscoveryMetadata.Address)
                {
                    matchingEndpoint = endpointDiscoveryMetadata;
                    break;
                }
            }

            return new ResolveAsyncResult(matchingEndpoint, callback, state);
        }
Exemplo n.º 16
0
        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);
        }
Exemplo n.º 17
0
        internal static ResolveCriteria ReadXml(XmlReader reader, DiscoveryVersion version)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            var ret = new ResolveCriteria();

            reader.MoveToContent();
            if (!reader.IsStartElement("ResolveType", version.Namespace) || reader.IsEmptyElement)
            {
                throw new XmlException("Non-empty ResolveType element is expected");
            }
            reader.ReadStartElement("ResolveType", version.Namespace);

            // standard members
            reader.MoveToContent();
            ret.Address = EndpointAddress.ReadFrom(version.MessageVersion.Addressing, reader);

            // non-standard members
            for (reader.MoveToContent(); !reader.EOF && reader.NodeType != XmlNodeType.EndElement; reader.MoveToContent())
            {
                if (reader.NamespaceURI == SerializationNS)
                {
                    switch (reader.LocalName)
                    {
                    case "Duration":
                        ret.Duration = (TimeSpan)reader.ReadElementContentAs(typeof(TimeSpan), null);
                        break;
                    }
                }
                else
                {
                    ret.Extensions.Add(XElement.Load(reader));
                }
            }

            reader.ReadEndElement();

            return(ret);
        }
Exemplo n.º 18
0
        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 IAsyncResult OnBeginResolve(ResolveCriteria resolveCriteria, AsyncCallback callback, object state)
 {
     return response;
 }
Exemplo n.º 20
0
		protected abstract IAsyncResult OnBeginResolve (ResolveCriteria resolveCriteria, AsyncCallback callback, Object state);
 protected override IAsyncResult OnBeginResolve(ResolveCriteria resolveCriteria, AsyncCallback callback, Object state)
 {
     Console.Error.WriteLine("OnBeginResolve");
     throw new Exception("2");
 }
Exemplo n.º 22
0
        //-----------------------------------------------------
        //  Redirect Adhoc to Managed Resolve
        //-----------------------------------------------------

        #region ShouldRedirectResolve

        //
        // Summary:
        //     Override this method to allow the discovery proxy to send out multicast suppression
        //     messages when it receives a multicast resolve request.
        //
        // Parameters:
        //   findCriteria:
        //     The find criteria that describes the service to find.
        //
        //   callback:
        //     The callback delegate to call when the operation is completed.
        //
        //   state:
        //     The user-defined state data.
        //
        // Returns:
        //     A reference to the pending asynchronous operation.
        protected override IAsyncResult BeginShouldRedirectResolve(ResolveCriteria findCriteria, AsyncCallback callback, object state)
        {
            return(_resolveTaskFactory.Create(findCriteria).ToApm(callback, state));
        }
Exemplo n.º 23
0
		EndpointDiscoveryMetadata Resolve (ResolveCriteria criteria)
		{
			throw new NotImplementedException ();
		}
        // resolve

        public ResolveResponse Resolve(ResolveCriteria criteria)
        {
            return(EndResolve(BeginResolve(criteria, null, null)));
        }
Exemplo n.º 25
0
 IAsyncResult IMulticastSuppressionImplementation.BeginShouldRedirectResolve(ResolveCriteria resolveCriteria, AsyncCallback callback, object state)
 {
     return this.BeginShouldRedirectResolve(resolveCriteria, callback, state);
 }
Exemplo n.º 26
0
 protected virtual IAsyncResult BeginShouldRedirectResolve(ResolveCriteria findCriteria, AsyncCallback callback, object state)
 {
     return new CompletedAsyncResult<bool>(false, callback, state);
 }
Exemplo n.º 27
0
 IAsyncResult IDiscoveryServiceImplementation.BeginResolve(ResolveCriteria resolveCriteria, AsyncCallback callback, object state)
 {
     return this.OnBeginResolve(resolveCriteria, callback, state);
 }
 protected virtual IAsyncResult BeginShouldRedirectResolve(ResolveCriteria findCriteria, AsyncCallback callback, Object state)
 {
     throw new NotImplementedException();
 }
    /// <summary>
    /// Begins an asynchronous resolve operation with the specified criteria.
    /// </summary>
    /// <param name="discoveryClient">The discovery client.</param>
    /// <param name="criteria">The criteria for matching a service endpoint.</param>
    /// <returns>A Task that represents the asynchronous operation.</returns>
    public static Task<ResolveResponse> ResolveTaskAsync(
        this DiscoveryClient discoveryClient, ResolveCriteria criteria)
    {
        // Validate arguments
        if (discoveryClient == null) throw new ArgumentNullException("discoveryClient");

        // Create a TaskCompletionSource to represent the operation
        var tcs = new TaskCompletionSource<ResolveResponse>(discoveryClient);

        // Register a handler that will transfer completion results to the TCS Task
        EventHandler<ResolveCompletedEventArgs> completedHandler = null;
        completedHandler = (sender, e) => TaskServices.HandleEapCompletion(tcs, true, e, () => e.Result, () => discoveryClient.ResolveCompleted -= completedHandler);
        discoveryClient.ResolveCompleted += completedHandler;

        // Start the async operation.
        try { discoveryClient.ResolveAsync(criteria, tcs); }
        catch
        {
            discoveryClient.ResolveCompleted -= completedHandler;
            throw;
        }

        // Return the task to represent the asynchronous operation
        return tcs.Task;
    }
Exemplo n.º 30
0
 protected virtual IAsyncResult BeginShouldRedirectResolve(ResolveCriteria findCriteria, AsyncCallback callback, object state)
 {
     return(new CompletedAsyncResult <bool>(false, callback, state));
 }
Exemplo n.º 31
0
 IAsyncResult IMulticastSuppressionImplementation.BeginShouldRedirectResolve(ResolveCriteria resolveCriteria, AsyncCallback callback, object state)
 {
     return(this.BeginShouldRedirectResolve(resolveCriteria, callback, state));
 }
Exemplo n.º 32
0
		protected virtual IAsyncResult BeginShouldRedirectResolve (ResolveCriteria findCriteria, AsyncCallback callback, Object state)
		{
			throw new NotImplementedException ();
		}
 IAsyncResult BeginResolve(ResolveCriteria criteria, AsyncCallback callback, object state)
 {
     return(((IDiscoveryCommon)client).BeginResolve(criteria, callback, state));
 }
Exemplo n.º 34
0
 // OnBeginFind method is called when a Resolve request message is received by the Proxy
 protected override IAsyncResult OnBeginResolve(ResolveCriteria resolveCriteria, AsyncCallback callback,
     object state)
 {
     _logger.Log("OnBeginResolve()", LogLevel.Debug);
     return new OnResolveAsyncResult(_provider.Match(resolveCriteria), callback, state);
 }
Exemplo n.º 35
0
		public void ResolveAsync (ResolveCriteria criteria)
		{
			throw new NotImplementedException ();
		}
Exemplo n.º 36
0
		protected override IAsyncResult OnBeginResolve (ResolveCriteria resolveCriteria, AsyncCallback callback, Object state)
		{
			if (resolve_delegate == null)
				resolve_delegate = new Func<ResolveCriteria,EndpointDiscoveryMetadata> (Resolve);
			return resolve_delegate.BeginInvoke (resolveCriteria, callback, state);
		}
Exemplo n.º 37
0
		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;
			}
		}
Exemplo n.º 38
0
        //-----------------------------------------------------
        //  Resolve
        //-----------------------------------------------------

        #region Resolve

        /// <summary>
        /// Handles a resolve operation.
        /// </summary>
        /// <param name="resolveCriteria">The resolve criteria that describes the service to discover.</param>
        /// <param name="callback">The callback delegate to call when the operation is completed.</param>
        /// <param name="state">The user-defined state data.</param>
        /// <returns>A reference to the pending asynchronous operation.</returns>
        protected override IAsyncResult OnBeginResolve(ResolveCriteria resolveCriteria, AsyncCallback callback, object state)
        {
            return(_resolveTaskFactory.Create(resolveCriteria).ToApm(callback, state));
        }
Exemplo n.º 39
0
        /// <summary>
        /// Return a random EndpointDiscoveryMetadata out of the endpoints that match a criteria.
        /// The endpoint is chosen in random for load balancing 
        /// </summary>
        /// <param name="criteria"></param>
        /// <returns></returns>
        EndpointDiscoveryMetadata MatchFromOnlineService(ResolveCriteria criteria)
        {
            EndpointDiscoveryMetadata matchingEndpoint = null;
            Random rnd = new Random();
            lock (this.onlineServices)
            {
                List<EndpointDiscoveryMetadata> eplist = new List<EndpointDiscoveryMetadata>();

                foreach (EndpointDiscoveryMetadata endpointDiscoveryMetadata in this.onlineServices.Values)
                {
                    if (criteria.Address == endpointDiscoveryMetadata.Address)
                    {
                        eplist.Add(endpointDiscoveryMetadata);
                    }
                }
                //make sure the endpoints distribute randomaly 
                int index = rnd.Next(eplist.Count);
                matchingEndpoint = eplist.ToArray()[index];
            }

            return matchingEndpoint;
        }
Exemplo n.º 40
0
		protected override IAsyncResult OnBeginResolve(ResolveCriteria resolveCriteria, AsyncCallback callback, object state)
		{
			return new SynchronousResult(callback, state, implementation.ResolveEndpoint(resolveCriteria));
		}
 public void ResolveAsync(ResolveCriteria criteria)
 {
     ResolveAsync(criteria, null);
 }
Exemplo n.º 42
0
        public virtual EndpointDiscoveryMetadata ResolveEndpoint(ResolveCriteria resolveCriteria)
        {
			using (@lock.ForReading())
			{
				EndpointDiscoveryMetadata endpoint;
				return endpoints.TryGetValue(resolveCriteria.Address, out endpoint)
					? endpoint
					: null;
			}
        }
Exemplo n.º 43
0
 EndpointDiscoveryMetadata Resolve(ResolveCriteria criteria)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 44
0
		protected override IAsyncResult OnBeginResolve (ResolveCriteria resolveCriteria, AsyncCallback callback, Object state)
		{
			Console.Error.WriteLine ("OnBeginResolve");
			throw new Exception ("2");
		}
Exemplo n.º 45
0
 protected abstract IAsyncResult OnBeginResolve(ResolveCriteria resolveCriteria, AsyncCallback callback, Object state);
Exemplo n.º 46
0
		public void ResolveAsync (ResolveCriteria criteria, object userState)
		{
			throw new NotImplementedException ();
		}
Exemplo n.º 47
0
 IAsyncResult IDiscoveryServiceImplementation.BeginResolve(ResolveCriteria resolveCriteria, AsyncCallback callback, object state)
 {
     return(this.OnBeginResolve(resolveCriteria, callback, state));
 }
Exemplo n.º 48
0
 // OnBeginFind method is called when a Resolve request message is received by the Proxy
 protected override IAsyncResult OnBeginResolve(ResolveCriteria resolveCriteria, AsyncCallback callback, object state)
 {
     return new OnResolveAsyncResult(this.MatchFromOnlineService(resolveCriteria), callback, state);
 }
Exemplo n.º 49
0
		public ResolveResponse Resolve (ResolveCriteria criteria)
		{
			throw new NotImplementedException ();
		}