private void InitBayeuxClient()
        {
            if (_isDisposed)
            {
                throw new ObjectDisposedException("Cannot create connection when disposed");
            }

            _logger.LogDebug("Initializing {name} ...", nameof(BayeuxClient));

            if (!_authenticationClient.IsAuthenticated)
            {
                Reauthenticate();
            }

            _tokenInfo = _authenticationClient.AuthenticationClient.AccessInfo;

            // Salesforce socket timeout during connection(CometD session) = 110 seconds
            var options = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase)
            {
                { ClientTransport.TIMEOUT_OPTION, _options.ReadTimeOut ?? ReadTimeOut },
                { ClientTransport.MAX_NETWORK_DELAY_OPTION, _options.ReadTimeOut ?? ReadTimeOut }
            };

            var headers = new NameValueCollection {
                { HttpRequestHeader.Authorization.ToString(), $"OAuth {_tokenInfo.AccessToken}" }
            };

            _clientTransport = new LongPollingTransport(options, headers);

            // only need the scheme and host, strip out the rest
            var serverUri = new Uri(_tokenInfo.InstanceUrl);
            var endpoint  = $"{serverUri.Scheme}://{serverUri.Host}{_options.CometDUri}";

            _bayeuxClient = new BayeuxClient(endpoint, _clientTransport);

            // adds logging and also raises an event to process reconnection to the server.
            _errorExtension = new ErrorExtension();
            _errorExtension.ConnectionError     += ErrorExtension_ConnectionError;
            _errorExtension.ConnectionException += ErrorExtension_ConnectionException;
            _errorExtension.ConnectionMessage   += ErrorExtension_ConnectionMessage;
            _bayeuxClient.AddExtension(_errorExtension);

            _replayIdExtension = new ReplayExtension();
            _bayeuxClient.AddExtension(_replayIdExtension);

            _logger.LogDebug("{name} initializing completed...", nameof(BayeuxClient));
        }
Beispiel #2
0
        /// <summary>
        /// Метод находит заявку по ее Id.
        /// </summary>
        /// <param name="id"></param>
        /// <returns>Номер заявки.</returns>
        async Task <object> GetRequestById(int id)
        {
            try {
                Request oRequest = await _db.Requests.Where(r => r.Id == id).FirstOrDefaultAsync();

                // Если заявка не найдена.
                if (oRequest == null)
                {
                    throw new ArgumentOutOfRangeException();
                }

                // Если заявка уже в работе, то не дает отправить в закупки.
                if (oRequest.Status.Equals(RequestStatus.REQ_STATUS_IN_WORK))
                {
                    ErrorExtension error = new ErrorExtension();
                    return(error.ThrowErrorReqNotWork());
                }
                return(oRequest.Number);
            }
            catch (ArgumentOutOfRangeException ex) {
                throw new ArgumentOutOfRangeException("Такой заявки не существует", ex.Message.ToString());
            }
        }