Esempio n. 1
0
        public ActionResult Return([FromBody] PayloadAsync payload)
        {
            var    a    = payload.Payload;
            var    b    = (JsonElement)payload.Payload;
            string json = b.ToString();

            Client.Complete(payload.CorrelationId, json);

            return(new JsonResult(new { Success = true }));
        }
Esempio n. 2
0
        internal static void Process(Object o)
        {
            PayloadAsync payload = o as PayloadAsync;

            if (payload == null)
            {
                throw new PayloadNullException();
            }

            if (ArgillaSettings.Current.MessageReceivedHandler == null)
            {
                throw new CallbackNullException();
            }

            string jsonArgument = CustomJsonSerializer.Serialize(payload.Payload);

            logger.Info(String.Format("Json argument: {0}", jsonArgument));



            MethodInfo methodInfo = ArgillaSettings.Current.MessageReceivedHandler;

            ParameterInfo[] pis        = methodInfo.GetParameters();
            ParameterInfo   argumentPI = pis[0];
            Type            t          = pis[0].ParameterType;

            object argument = CustomJsonSerializer.Deserialize(jsonArgument, t);
            object a        = ArgillaSettings.Current.MessageReceivedHandler.Invoke(null, new[] { argument });

            payload.Payload = a;

            string json = CustomJsonSerializer.Serialize(payload);

            logger.Info(String.Format("Json: {0}", json));

            string result = HttpHelper.Post(payload.UrlCallback, json);

            logger.Info(String.Format("Result: {0}", result));
        }
Esempio n. 3
0
        /// <summary>
        /// Invoke an asynchronous service with the specified payload. The method call return immediately. When the service return the response this will be used as argumento of the callback.
        /// </summary>
        /// <typeparam name="T">the payload type.</typeparam>
        /// <param name="serviceName">The name of the service.</param>
        /// <param name="payload">The payload used for invoke the service.</param>
        /// <param name="action">The callback invoked when the response arrive from the service.</param>
        public static void Invoke <T>(string serviceName, T payload, Action <Object> action)
        {
            if (!Host.IsStarted)
            {
                throw new HostNotStartedException();
            }

            if (ArgillaSettings.Current.Node == null)
            {
                throw new NodeNotConfiguredException();
            }

            string correlationId = Guid.NewGuid().ToString();

            pending.Add(correlationId, new PendingRequest()
            {
                Action = action
            });

            logger.Debug(String.Format("Correlation ID: {0}", correlationId));

            PayloadAsync payloadAsync = new PayloadAsync()
            {
                CorrelationId = correlationId.ToString(),
                Payload       = payload,
                UrlCallback   = ArgillaSettings.Current.Node.Return
            };

            string json = CustomJsonSerializer.Serialize(payloadAsync);

            Exception lastException = null;

            try
            {
                Endpoint endpoint = GetFreeEndpoint(serviceName);

                string jsonResult = HttpHelper.Post(endpoint.EndpointAsync, json);

                lastException = null;
            }
            catch
            {
                ResolveResponse resolveResponse = Resolve(serviceName);

                foreach (Endpoint endpoint in resolveResponse.Endpoints)
                {
                    try
                    {
                        string jsonResult = HttpHelper.Post(endpoint.EndpointAsync, json);

                        logger.Debug(String.Format("Json result: {0}", jsonResult));

                        lastException = null;

                        break;
                    }
                    catch (Exception e)
                    {
                        lastException = e;
                    }
                }
            }

            if (lastException != null)
            {
                logger.Error(lastException, lastException.Message);

                throw lastException;
            }
        }
Esempio n. 4
0
        public ActionResult CallbackAsync([FromBody] PayloadAsync payload)
        {
            ThreadPool.QueueUserWorkItem(BackgroundProcessor.Process, payload);

            return(new JsonResult(new { Success = true }));
        }