Example #1
0
 public HttpResponseHandler(
     IController controller,
     string action,
     string clientData,
     GetResponsePosition resetToBegin,
     int count,
     string clientId,
     IResponseServiceCallback callback,
     BrokerResponseServiceClient responseClient)
 {
     this.controller         = controller;
     this.action             = action;
     this.clientData         = clientData;
     this.resetToBegin       = resetToBegin;
     this.count              = count;
     this.clientId           = clientId;
     this.callback           = callback;
     this.responseClient     = responseClient;
     this.HttpResponseThread = new Thread(this.HttpGetResponseThread);
     this.HttpResponseThread.IsBackground = true;
     this.HttpResponseThread.Start();
 }
Example #2
0
                public AzureQueueResponseHandler(
                    AzureQueueProxy azureQueueProxy,
                    string action,
                    string clientData,
                    GetResponsePosition resetToBegin,
                    int count,
                    string clientId,
                    IResponseServiceCallback callback,
                    BrokerResponseServiceClient responseClient)
                {
                    this.action          = action;
                    this.clientData      = clientData;
                    this.resetToBegin    = resetToBegin;
                    this.count           = count;
                    this.clientId        = clientId;
                    this.callback        = callback;
                    this.responseClient  = responseClient;
                    this.azureQueueProxy = azureQueueProxy;

                    this.AzureQueueResponseThread = new Thread(new ThreadStart(this.GetResponseThread));

                    this.AzureQueueResponseThread.IsBackground = true;
                    this.AzureQueueResponseThread.Start();
                }
Example #3
0
        /// <summary>
        /// This factory class creates three different kinds of client. This method gathers the code of client creation
        /// and adds the retry logic. The retry can avoid transient connection error especially when connect to Azure.
        /// </summary>
        /// <param name="clientType">the type of the client</param>
        /// <returns>the client</returns>
        private ICommunicationObject CreateClientWithRetry(ClientType clientType)
        {
            ICommunicationObject client    = null;
            Exception            exception = null;

            try
            {
                exception = null;
                switch (clientType)
                {
                case ClientType.SendRequest:

                    if (this.brokerClientFactory == null)
                    {
                        BindingParameterCollection bindingParms      = new BindingParameterCollection();
                        ClientCredentials          clientCredentials = new ClientCredentials();
                        if (this.info.UseAad)
                        {
                            // Authentication will be taken care of by adding message header to request
                        }
                        else if (this.SetClientCredential(clientCredentials))
                        {
                            bindingParms.Add(clientCredentials);
                        }

                        this.brokerClientFactory = this.binding.BuildChannelFactory <IDuplexSessionChannel>(bindingParms);
                        this.brokerClientFactory.Open();
                    }

                    client = this.brokerClientFactory.CreateChannel(GenerateEndpointAddress(this.info.BrokerEpr, this.scheme, this.info.Secure, this.info.IsAadOrLocalUser));
                    break;

                case ClientType.GetResponse:

                    BrokerResponseServiceClient responseClient = new BrokerResponseServiceClient(
                        this.binding,
                        GenerateEndpointAddress(this.info.ResponseEpr, this.scheme, this.info.Secure, this.info.IsAadOrLocalUser),
                        new InstanceContext(this.ResponseCallback));
                    this.SetClientCredential(responseClient);


                    client = responseClient;
                    break;

                case ClientType.Controller:

                    BrokerControllerClient controllerClient = new BrokerControllerClient(
                        this.binding,
                        GenerateEndpointAddress(this.info.ControllerEpr, this.scheme, this.info.Secure, this.info.IsAadOrLocalUser));
                    this.SetClientCredential(controllerClient);

                    client = controllerClient;
                    break;

                default:
                    throw new NotSupportedException();
                }

                client.Open();
            }
            catch (Exception e)
            {
                if (this.brokerClientFactory != null)
                {
                    try
                    {
                        this.brokerClientFactory.Abort();
                        this.brokerClientFactory = null;
                    }
                    catch
                    {
                        // abandon the factory, swallow the exception
                    }
                }

                if (client != null)
                {
                    try
                    {
                        client.Abort();
                        client = null;
                    }
                    catch
                    {
                        // abandon the channel, swallow the exception
                    }
                }

                exception = e;
            }


            if (exception != null)
            {
                throw exception;
            }

            return(client);
        }