コード例 #1
0
        /// <summary>
        /// Invokes the specified service method.
        /// </summary>
        /// <param name="method">The method to be invoked.</param>
        /// <exception cref="ArgumentNullException"><paramref name="method"/> is a null
        /// reference.</exception>
        private TResult _Invoke <TResult>(Func <TService, TResult> method)
        {
            CodeContract.RequiresNotNull("method", method);

            var invocationWrapper = new RetriableInvocationWrapper(
                MAX_RETRY_COUNT,
                _PrepareRetry,
                _TranslateException);

            var result = default(TResult);

            invocationWrapper.Invoke(() =>
            {
                try
                {
                    using (var connection = _connectionPool.AcquireConnection())
                    {
                        result = method(connection.Client);
                    }
                }
                catch (Exception ex)
                {
                    if (!_exceptionHandler.HandleException(ex, _serviceTitle))
                    {
                        throw;
                    }
                }
            });

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Checks if the specified url points to the load balancing service.
        /// </summary>
        /// <param name="serviceUrl">Url to check for service presence.</param>
        /// <returns>true if and only if the <paramref name="serviceUrl"/>
        /// points to the load balancing service.</returns>
        public static bool HasLoadBalanceService(string serviceUrl)
        {
            var hasService = false;

            try
            {
                var metadataUri = new Uri(serviceUrl + "?wsdl");
                var mexClient   = new MetadataExchangeClient(
                    metadataUri,
                    MetadataExchangeClientMode.HttpGet);
                var metadataRetrievalWrapper = new RetriableInvocationWrapper(
                    MAX_RETRY_COUNT,
                    _PrepareForRetry);
                var metaDocs = metadataRetrievalWrapper.Invoke(
                    () => mexClient.GetMetadata());
                var importer  = new WsdlImporter(metaDocs);
                var contracts = importer.ImportAllContracts();
                foreach (var contract in contracts)
                {
                    if (string.Equals(
                            contract.Name,
                            LOAD_BALANCE_SERVICE_CONTRACT_NAME,
                            StringComparison.InvariantCulture))
                    {
                        hasService = true;
                        break;
                    }
                }
            }
            catch (InvalidOperationException e)
            {
                Logger.Warning(e);
            }
            catch (Exception e)
            {
                if (!ServiceHelper.IsCommunicationError(e))
                {
                    throw;
                }

                Logger.Warning(e);
            }

            return(hasService);
        }
コード例 #3
0
        /// <summary>
        /// Sends REST request to the specified url.
        /// </summary>
        /// <typeparam name="T">The type of the request result.</typeparam>
        /// <param name="context">The reference to the rest request context object.</param>
        /// <param name="url">The url to send request to.</param>
        /// <param name="query">The query to be sent.</param>
        /// <param name="opt">The reference to the request sending options.</param>
        /// <returns>Result of the specified REST request.</returns>
        /// <exception cref="T:ESRI.ArcLogistics.Routing.RestException">error was
        /// returned by the REST API.</exception>
        /// <exception cref="T:ESRI.ArcLogistics.CommunicationException">failed
        /// to communicate with the REST service at the specified url.</exception>
        /// <exception cref="T:System.ArgumentNullException">Any of
        /// <paramref name="context"/>, <paramref name="url"/>,
        /// <paramref name="query"/> or <paramref name="opt"/> arguments is a null
        /// reference.</exception>
        public T SendRequest <T>(
            IRestRequestContext context,
            string url,
            string query,
            HttpRequestOptions opt)
        {
            Debug.Assert(context != null);
            Debug.Assert(!string.IsNullOrEmpty(url));
            Debug.Assert(!string.IsNullOrEmpty(query));
            Debug.Assert(opt != null);

            var sendRequestWrapper = new RetriableInvocationWrapper(
                MAX_RETRY_COUNT,
                (e) => _PrepareRetry(context, e),
                (e) => _TranslateException(context, e));

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            return(sendRequestWrapper.Invoke(() =>
            {
                var timeout = opt.Timeout - stopwatch.ElapsedMilliseconds;
                timeout = Math.Max(timeout, 0);
                opt.Timeout = (int)timeout;

                var response = _SendRequest <T>(
                    context,
                    url,
                    query,
                    opt);
                RestHelper.ValidateResponse(response);

                return response;
            }));
        }
コード例 #4
0
        /// <summary>
        /// Checks if the specified url points to the load balancing service.
        /// </summary>
        /// <param name="serviceUrl">Url to check for service presence.</param>
        /// <returns>true if and only if the <paramref name="serviceUrl"/>
        /// points to the load balancing service.</returns>
        public static bool HasLoadBalanceService(string serviceUrl)
        {
            var hasService = false;

            try
            {
                var metadataUri = new Uri(serviceUrl + "?wsdl");
                var mexClient = new MetadataExchangeClient(
                    metadataUri,
                    MetadataExchangeClientMode.HttpGet);
                var metadataRetrievalWrapper = new RetriableInvocationWrapper(
                    MAX_RETRY_COUNT,
                    _PrepareForRetry);
                var metaDocs = metadataRetrievalWrapper.Invoke(
                    () => mexClient.GetMetadata());
                var importer = new WsdlImporter(metaDocs);
                var contracts = importer.ImportAllContracts();
                foreach (var contract in contracts)
                {
                    if (string.Equals(
                        contract.Name,
                        LOAD_BALANCE_SERVICE_CONTRACT_NAME,
                        StringComparison.InvariantCulture))
                    {
                        hasService = true;
                        break;
                    }
                }
            }
            catch (InvalidOperationException e)
            {
                Logger.Warning(e);
            }
            catch (Exception e)
            {
                if (!ServiceHelper.IsCommunicationError(e))
                {
                    throw;
                }

                Logger.Warning(e);
            }

            return hasService;
        }