Пример #1
0
        public void TestServiceFarmLoadBalancerRegisterClientProxyMessageBus()
        {
            IServiceFarmLoadBalancer serviceFarmLoadBalancer = _erector.Container.Resolve <IServiceFarmLoadBalancer>();
            IClientProxy             clientProxy             = _erector.Container.Resolve <IClientProxy>();

            bool success = serviceFarmLoadBalancer.RegisterClientProxyMessageBus(clientProxy);

            Assert.IsTrue(success);
        }
Пример #2
0
        public void TestServiceFarmLoadBalancerSendServiceRequest()
        {
            IServiceFarmLoadBalancer serviceFarmLoadBalancer = _erector.Container.Resolve <IServiceFarmLoadBalancer>();
            IMarshaller          marshaller      = _erector.Container.Resolve <IMarshaller>();
            IChatMessageEnvelope requestEnvelope = GetValidChatMessageEnvelope();
            string requestPayload        = marshaller.MarshallPayloadJSON(requestEnvelope);
            string clientProxyOriginGUID = Guid.NewGuid().ToString();

            bool success = serviceFarmLoadBalancer.SendServiceRequest(clientProxyOriginGUID, requestPayload);

            Assert.IsTrue(success);
        }
Пример #3
0
        public async Task Invoke(HttpContext context)
        {
            if (context.Request.ContentType != _contentTypeJSON)
            {
                return;
            }

            context.Response.ContentType = _contentTypeJSON;
            string requestPayload  = String.Empty;
            string responsePayload = String.Empty;

            using (var reader = new StreamReader(context.Request.Body, System.Text.Encoding.UTF8))
            {
                requestPayload = reader.ReadToEnd();
            }

            using (IServiceFarmLoadBalancer serviceFarmLoadBalancer = (IServiceFarmLoadBalancer)context.RequestServices.GetService(typeof(IServiceFarmLoadBalancer)))
            {
                using (IClientProxy clientProxy = (IClientProxy)context.RequestServices.GetService(typeof(IClientProxy)))
                {
                    switch (context.Request.Method)
                    {
                    case "GET":
                        responsePayload = Get(requestPayload, serviceFarmLoadBalancer, clientProxy);
                        break;

                    case "PUT":
                        responsePayload = Put(requestPayload, serviceFarmLoadBalancer, clientProxy);
                        break;

                    case "POST":
                        responsePayload = Post(requestPayload, serviceFarmLoadBalancer, clientProxy);
                        break;

                    case "DELETE":
                        responsePayload = Delete(requestPayload, serviceFarmLoadBalancer, clientProxy);
                        break;

                    case "HEAD":
                        responsePayload = Head(requestPayload, serviceFarmLoadBalancer, clientProxy);
                        context.Response.ContentType   = _contentTypeJSON;
                        context.Response.ContentLength = System.Text.Encoding.UTF8.GetBytes(responsePayload).LongLength;
                        return;

                    default:
                        break;
                    }
                }
            }

            context.Response.ContentType = _contentTypeJSON;
            await context.Response.WriteAsync(responsePayload);
        }
Пример #4
0
        public string ProcessRequestInServiceFarm(string json, IServiceFarmLoadBalancer serviceFarmLoadBalancer, IClientProxy clientProxy)
        {
            serviceFarmLoadBalancer.RegisterClientProxyMessageBus(clientProxy);
            string response = String.Empty;
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

            if (serviceFarmLoadBalancer.SendServiceRequest(clientProxy.ServiceGUID, json))
            {
                response = clientProxy.PollMessageBus(cancellationTokenSource);
            }

            serviceFarmLoadBalancer.ReleaseClientProxyMessageBus(clientProxy);
            return(response);
        }
        public void TestRoutingWebServiceGET()
        {
            IMarshaller marshaller = _erector.Container.Resolve <IMarshaller>();
            IServiceFarmLoadBalancer serviceFarmLoadBalancer = _erector.Container.Resolve <IServiceFarmLoadBalancer>();
            IClientProxy             clientProxy             = _erector.Container.Resolve <IClientProxy>();
            IRoutingWebService       routingWebService       = new RoutingWebService(default(RequestDelegate));
            IChatMessageEnvelope     chatMessageEnvelope     = GetValidChatMessageEnvelope();

            chatMessageEnvelope.ServiceRoute = ChatServiceNames.GetNextChatMessageService;

            string requestEnvelope  = marshaller.MarshallPayloadJSON(chatMessageEnvelope);
            string responseEnvelope = routingWebService.Get(requestEnvelope, serviceFarmLoadBalancer, clientProxy);

            Assert.IsFalse(String.IsNullOrEmpty(responseEnvelope));
        }
Пример #6
0
        public async Task GetLatestChatMessages(string json)
        {
            string response = string.Empty;
            IServiceFarmLoadBalancer serviceFarmLoadBalancer = _erector.Container.Resolve <IServiceFarmLoadBalancer>();

            SharedInterfaces.Interfaces.Proxy.IClientProxy clientProxy = _erector.Container.Resolve <SharedInterfaces.Interfaces.Proxy.IClientProxy>();
            CancellationTokenSource cancellationTokenSource            = new CancellationTokenSource();

            serviceFarmLoadBalancer.RegisterClientProxyMessageBus(clientProxy);

            while (_isConnected)
            {
                if (serviceFarmLoadBalancer.SendServiceRequest(clientProxy.ServiceGUID, json))
                {
                    do
                    {
                        response = clientProxy.PollMessageBus(cancellationTokenSource);
                        await Clients.Caller.SendAsync("ReceiveLatestChatMessage", response);
                    }while (String.IsNullOrEmpty(response) == false);
                }
            }
        }
Пример #7
0
 public string Delete(string json, IServiceFarmLoadBalancer serviceFarmLoadBalancer, IClientProxy clientProxy)
 {
     //NOTE: Can do other processing of the request before and or after this call.
     return(ProcessRequestInServiceFarm(json, serviceFarmLoadBalancer, clientProxy));
 }