Пример #1
0
        /// <summary>
        /// Find an endpoint access point for a given service and of a given use type.
        /// </summary>
        /// <param name="service">The service key or name.</param>
        /// <param name="useType">The use type of the access point</param>
        /// <returns>As access point.</returns>
        public static string FindAccessPointForService(ServiceIdentifier service, AccessPointUseType useType)
        {
            // Precondition.
            if (service == null)
            {
                throw new ArgumentNullException("service", Resources.ExcaptionInvalidServiceIdentifier);
            }

            // Precondition.
            if (string.IsNullOrWhiteSpace(service.Value))
            {
                throw new ArgumentException(Resources.ExceptionInvalidServiceIdentifierValue, "service");
            }

            ////////// Define pre-conditions.
            ////////Contract.Requires<ArgumentNullException>(service != null);
            ////////Contract.Requires<ArgumentException>(!string.IsNullOrWhiteSpace(service.Value));

            // The business service for the given service key or name.
            var businessService = GetBusinessService(service);

            // The binding template for the access point of the given use type for the given business service.
            var bindingTemplate = // Search for the binding template:
                                  // If no business service was found
                                  businessService == null
                    ?             // then indicate that no binding template is available:
                                  default(BindingTemplate)
                    :             // else search the business service for the first binding template for an access point of the required use type.
                                  (from template in businessService.BindingTemplates
                                   where
                                   string.Compare(
                                       template.AccessPoint.UseType,
                                       useType.ToString(),
                                       StringComparison.OrdinalIgnoreCase) == 0
                                   select template).FirstOrDefault();

            // Return the access point value for the given binding template:
            // If no binding template was found
            return(bindingTemplate == default(BindingTemplate)
                       ? // then indicate this
                   string.Empty
                       : // else return the access point value.
                   bindingTemplate.AccessPoint.Text);
        }
Пример #2
0
        /// <summary>
        /// Find an endpoint access point for a given service provided by a given business entity and of a given use type.
        /// </summary>
        /// <param name="provider">The provider key or name.</param>
        /// <param name="service">The service key or name.</param>
        /// <param name="useType">The use type of the access point</param>
        /// <returns>As access point.</returns>
        public static string FindAccessPointForService(ProviderIdentifier provider, ServiceIdentifier service, AccessPointUseType useType)
        {
            // Precondition.
            if (provider == null)
            {
                throw new ArgumentNullException("provider", Resources.ExceptionInvalidProviderIdentifier);
            }

            // Precondition.
            if (service == null)
            {
                throw new ArgumentNullException("service", Resources.ExcaptionInvalidServiceIdentifier);
            }

            // Precondition.
            if (string.IsNullOrWhiteSpace(provider.Value))
            {
                throw new ArgumentException(Resources.ExceptionInvalidServiceProviderIdentifierValue, "provider");
            }

            // Precondition.
            if (string.IsNullOrWhiteSpace(service.Value))
            {
                throw new ArgumentException(Resources.ExceptionInvalidServiceIdentifierValue, "service");
            }

            ////////// Define pre-conditions
            ////////Contract.Requires<ArgumentNullException>(provider != null);
            ////////Contract.Requires<ArgumentNullException>(service != null);
            ////////Contract.Requires<ArgumentException>(!string.IsNullOrWhiteSpace(provider.Value));
            ////////Contract.Requires<ArgumentException>(!string.IsNullOrWhiteSpace(service.Value));

            // The business entity for the given provider key or name.
            var businessEntity = GetBusinessEntity(provider);

            // The business service of the given name for the given provider.
            var businessService = // Search for the business service:
                                  // If no business entity was provided
                                  businessEntity == default(BusinessEntity)
                    ?             // then indicate that no business service is available:
                                  default(BusinessService)
                    :             // else treat the service value as a name and search for the first business service that has that name...
                                  (from bs in businessEntity.BusinessServices
                                   where
                                   bs.Names.SingleOrDefault(name => string.CompareOrdinal(name.Text, service.Value) == 0) != null
                                   select bs).FirstOrDefault()
                                  ?? // ...and if nothing is found, treat the service value as a key and search for
                                     //       the first business service that has that key.
                                  (from bs in businessEntity.BusinessServices
                                   where string.CompareOrdinal(bs.ServiceKey, service.Value) == 0
                                   select bs).FirstOrDefault();

            // The binding template for the access point of the given use type for the given business service.
            var bindingTemplate = // Get the binding template:
                                  // If no business service was found
                                  businessService == default(BusinessService)
                    ?             // then indicate that no binding template is available:
                                  default(BindingTemplate)
                    :             // else search the business service for the first binding template for an access point of the required use type.
                                  (from template in businessService.BindingTemplates
                                   where
                                   string.Compare(
                                       template.AccessPoint.UseType,
                                       useType.ToString(),
                                       StringComparison.OrdinalIgnoreCase) == 0
                                   select template).FirstOrDefault();

            // Return the access point value for the given binding template:
            // If no binding template was found
            return(bindingTemplate == default(BindingTemplate)
                       ? // then indicate this
                   string.Empty
                       : // else return the access point value.
                   bindingTemplate.AccessPoint.Text);
        }