/// <summary>
        /// Override this method to handle a find operation.
        /// </summary>
        /// <param name="findRequestContext">The find request context 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 OnBeginFind(FindRequestContext findRequestContext, AsyncCallback callback, object state)
        {
            if (findRequestContext == null)
            {
                throw new ArgumentNullException("findRequestContext");
            }

            Console.WriteLine("Find request for contract {0}", findRequestContext.Criteria.ContractTypeNames.FirstOrDefault());

            // query to find the matching endpoints
            var query = from service in cache
                        where findRequestContext.Criteria.IsMatch(service)
                        select service;

            // collection to contain the results of the query
            var matchingEndpoints = new Collection <EndpointDiscoveryMetadata>();

            // execute the query and add the matching endpoints
            foreach (EndpointDiscoveryMetadata metadata in query)
            {
                matchingEndpoints.Add(metadata);
                findRequestContext.AddMatchingEndpoint(metadata);
            }

            return(new FindAsyncResult(matchingEndpoints, callback, state));
        }
        void MatchFromOnlineService(FindRequestContext findRequestContext)
        {
            lock (this._onlineServices)
            {
                string foundId = findRequestContext.Criteria.Extensions.FirstOrDefault(x =>
                                                                                       x.Name.LocalName == "Id")?.Value;
                if (foundId != null)
                {
                    EndpointDiscoveryMetadata endpointMetadata = this._onlineServices[foundId];

                    if (!findRequestContext.Criteria.IsMatch(endpointMetadata))
                    {
                        return;
                    }

                    findRequestContext.AddMatchingEndpoint(endpointMetadata);
                }
                else
                {
                    foreach (EndpointDiscoveryMetadata endpointMetadata in this._onlineServices.Values)
                    {
                        if (!findRequestContext.Criteria.IsMatch(endpointMetadata))
                        {
                            continue;
                        }

                        int countdown = findRequestContext.Criteria.Extensions.Count;
                        foreach (XElement elem in findRequestContext.Criteria.Extensions)
                        {
                            if (endpointMetadata.Extensions.All(x =>
                                                                x.Name.LocalName == elem.Name.LocalName && x.Value != elem.Value))
                            {
                                break;
                            }

                            countdown--;
                        }

                        if (countdown == 0)
                        {
                            findRequestContext.AddMatchingEndpoint(endpointMetadata);
                        }
                    }
                }
            }
        }
Exemple #3
0
 /// <summary>
 /// Matches from online service.
 /// </summary>
 /// <param name="findRequestContext">The find request context.</param>
 public void MatchFromOnlineService(FindRequestContext findRequestContext)
 {
     foreach (var metadata in _onlineServices.Values
              .Where(data => findRequestContext.Criteria.IsMatch(data)))
     {
         findRequestContext.AddMatchingEndpoint(metadata);
     }
 }
Exemple #4
0
 public virtual void FindService(FindRequestContext findRequestContext)
 {
     foreach (var metadata in services.Values)
     {
         if (findRequestContext.Criteria.IsMatch(metadata))
         {
             findRequestContext.AddMatchingEndpoint(metadata);
         }
     }
 }
 public virtual void FindEndpoints(FindRequestContext findRequestContext)
 {
     using (@lock.ForReading())
     {
         foreach (var endpoint in MatchTargets(findRequestContext.Criteria))
         {
             findRequestContext.AddMatchingEndpoint(endpoint);
         }
     }
 }
Exemple #6
0
 void Find(FindRequestContext context)
 {
     TextWriter.Null.WriteLine("Find operation: " + context);
     foreach (var edm in endpoints)
     {
         if (context.Criteria.IsMatch(edm))
         {
             context.AddMatchingEndpoint(edm);
         }
     }
 }
        protected override IAsyncResult OnBeginFind(FindRequestContext findRequestContext, AsyncCallback callback, object state)
        {
            // Implements an OR matching that adds an endpoint if any of its scopes match any of the scopes in FindCriteria
            if (findRequestContext.Criteria.ScopeMatchBy.Equals(customScopeMatchBy))
            {
                foreach (EndpointDiscoveryMetadata endpointDiscoveryMetadata in this.publishedEndpoints)
                {
                    bool endpointAdded = false;

                    foreach (Uri findCriteriaScope in findRequestContext.Criteria.Scopes)
                    {
                        if (endpointAdded)
                        {
                            break;
                        }

                        foreach (Uri serviceEndpointScope in endpointDiscoveryMetadata.Scopes)
                        {
                            if (serviceEndpointScope.Equals(findCriteriaScope))
                            {
                                findRequestContext.AddMatchingEndpoint(endpointDiscoveryMetadata);
                                endpointAdded = true;
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                foreach (EndpointDiscoveryMetadata endpointDiscoveryMetadata in this.publishedEndpoints)
                {
                    if (findRequestContext.Criteria.IsMatch(endpointDiscoveryMetadata))
                    {
                        findRequestContext.AddMatchingEndpoint(endpointDiscoveryMetadata);
                    }
                }
            }

            return(new FindAsyncResult(callback, state));
        }
Exemple #8
0
        //Find(Probe)
        protected override IAsyncResult OnBeginFind(FindRequestContext findRequestContext, AsyncCallback callback, object state)
        {
            var endpoints = from item in this.Endpoints
                            where findRequestContext.Criteria.IsMatch(item.Value)
                            select item.Value;

            foreach (var item in endpoints)
            {
                findRequestContext.AddMatchingEndpoint(item);
            }
            return(new DiscoveryAsyncResult(callback, state));
        }
Exemple #9
0
 void MatchFromOnlineService(FindRequestContext findRequestContext)
 {
     lock (this.onlineServices)
     {
         foreach (EndpointDiscoveryMetadata endpointDiscoveryMetadata in this.onlineServices.Values)
         {
             if (findRequestContext.Criteria.IsMatch(endpointDiscoveryMetadata))
             {
                 findRequestContext.AddMatchingEndpoint(endpointDiscoveryMetadata);
             }
         }
     }
 }
Exemple #10
0
        /// <summary>
        /// Encontra os serviços que conferem os requisitos inseridos
        /// </summary>
        /// <param name="findRequestContext"></param>
        public void MatchFromOnlineService(FindRequestContext findRequestContext)
        {
            lock (this.onlineServices)
            {
                foreach (EndpointDiscoveryMetadata endpointDiscoveryMetadata in this.onlineServices.Values)
                {
                    if (findRequestContext.Criteria.IsMatch(endpointDiscoveryMetadata))
                    {
                        if (PrintDiscoveryMetadata != null)
                        {
                            PrintDiscoveryMetadata(endpointDiscoveryMetadata, "Assigned", this.onlineServices.Count);
                        }

                        findRequestContext.AddMatchingEndpoint(endpointDiscoveryMetadata);
                    }
                }
            }
        }
    void Find(FindRequestContext context)
    {
/*
 * var oc = OperationContext.Current;
 * var ch = oc.GetCallbackChannel<IClientChannel> ();
 * Console.Error.WriteLine ("!!! {0} {1} {2} {3}", ch.Extensions.Count, ch.InputSession, ch.RemoteAddress, ch.GetType ());
 */
        Console.Error.WriteLine("Find operation: " + context);
        foreach (var edm in endpoints)
        {
            if (context.Criteria.IsMatch(edm))
            {
                Console.Error.WriteLine("Match: " + edm);
                context.AddMatchingEndpoint(edm);
            }
            else
            {
                Console.Error.WriteLine("Mismatch.");
            }
        }
    }