/// <summary>
        /// Run the request against each Endpoint
        /// </summary>
        /// <typeparam name="TRes"></typeparam>
        /// <param name="request"></param>
        /// <param name="validate"></param>
        /// <param name="httpMethod"></param>
        public void SendToEachEndpoint <TRes>(object request, string httpMethod, Action <TRes> validate)
        {
            using (var xmlClient = new XmlServiceClient(BaseUrl))
                using (var jsonClient = new JsonServiceClient(BaseUrl))
                    using (var jsvClient = new JsvServiceClient(BaseUrl))
                    {
                        xmlClient.HttpMethod  = httpMethod;
                        jsonClient.HttpMethod = httpMethod;
                        jsvClient.HttpMethod  = httpMethod;

                        var xmlResponse = xmlClient.Send <TRes>(request);
                        if (validate != null)
                        {
                            validate(xmlResponse);
                        }

                        var jsonResponse = jsonClient.Send <TRes>(request);
                        if (validate != null)
                        {
                            validate(jsonResponse);
                        }

                        var jsvResponse = jsvClient.Send <TRes>(request);
                        if (validate != null)
                        {
                            validate(jsvResponse);
                        }
                    }
        }
Beispiel #2
0
        public static IServiceGateway ResolveBestFitClient(string baseUrl, Type requestType)
        {
            var restricts       = requestType.AllAttributes <RestrictAttribute>();
            var inSecureAllowed = restricts.All(t => t.HasAccessTo(RequestAttributes.InSecure)) || restricts.All(t => !t.HasAccessTo(RequestAttributes.Secure));

            if (!inSecureAllowed && baseUrl.StartsWith("http", StringComparison.InvariantCultureIgnoreCase))
            {
                baseUrl = baseUrl.Insert(4, "s"); //tack in the secure if required and not in base listening url
            }
            IServiceGateway gateway = null;

            if (requestType.HasJsonClientSupport())
            {
                gateway = new JsonServiceClient(baseUrl);
            }
            else if (requestType.HasJsvClientSupport())
            {
                gateway = new JsvServiceClient(baseUrl);
            }
            else if (requestType.HasXmlClientSupport())
            {
                gateway = new XmlServiceClient(baseUrl);
            }
            return(gateway ?? (IServiceGateway) new JsonServiceClient(baseUrl)); //default will be Json if logic doesn't figure it out
        }
        public void DeleteOnEachEndpoint <TRes>(string relativePathOrAbsoluteUri, Action <TRes> validate)
        {
            using (var xmlClient = new XmlServiceClient(BaseUrl))
                using (var jsonClient = new JsonServiceClient(BaseUrl))
                    using (var jsvClient = new JsvServiceClient(BaseUrl))
                    {
                        var xmlResponse = xmlClient.Delete <TRes>(relativePathOrAbsoluteUri);
                        if (validate != null)
                        {
                            validate(xmlResponse);
                        }

                        var jsonResponse = jsonClient.Delete <TRes>(relativePathOrAbsoluteUri);
                        if (validate != null)
                        {
                            validate(jsonResponse);
                        }

                        var jsvResponse = jsvClient.Delete <TRes>(relativePathOrAbsoluteUri);
                        if (validate != null)
                        {
                            validate(jsvResponse);
                        }
                    }
        }
        public void Does_cache_MemoryStream_HttpResult_Responses_preserving_ContentType()
        {
            CacheStream.Count = 0;
            var request = new CacheStream {
                Id = 1, Value = "foo"
            };

            var response = Config.ListeningOn.CombineWith(request.ToGetUrl())
                           .GetStringFromUrl(responseFilter: res =>
            {
                Assert.That(res.ContentType, Does.StartWith(MimeTypes.Jsv));
                Assert.That(res.Headers[HttpHeaders.CacheControl], Is.Null);
            })
                           .FromJsv <CacheStream>();

            Assert.That(CacheStream.Count, Is.EqualTo(1));
            AssertEquals(response, request);

            response = Config.ListeningOn.CombineWith(request.ToGetUrl())
                       .GetStringFromUrl(responseFilter: res =>
            {
                Assert.That(res.ContentType, Does.StartWith(MimeTypes.Jsv));
                Assert.That(res.Headers[HttpHeaders.CacheControl], Is.Null);
            })
                       .FromJsv <CacheStream>();

            Assert.That(CacheStream.Count, Is.EqualTo(1));
            AssertEquals(response, request);

            var client = new JsvServiceClient(Config.ListeningOn);

            response = client.Get <CacheStream>(request);
            Assert.That(CacheStream.Count, Is.EqualTo(1));
            AssertEquals(response, request);
        }
        public void Send <TRes>(object request, Action <TRes> validate)
        {
            using (var xmlClient = new XmlServiceClient(BaseUrl))
                using (var jsonClient = new JsonServiceClient(BaseUrl))
                    using (var jsvClient = new JsvServiceClient(BaseUrl))
                    {
                        var xmlResponse = xmlClient.Send <TRes>(request);
                        validate(xmlResponse);

                        var jsonResponse = jsonClient.Send <TRes>(request);
                        validate(jsonResponse);

                        var jsvResponse = jsvClient.Send <TRes>(request);
                        validate(jsvResponse);
                    }
        }
Beispiel #6
0
        public void Can_execute_with_CompressionDisabled()
        {
            var client = new JsvServiceClient(Config.ListeningOn)
            {
                DisableAutoCompression = true,
            };

            var result = client.Get <ServerCacheOnly>(new ServerCacheOnly {
                Value = "Hello"
            });

            Assert.That(result.Value, Is.EqualTo("Hello"));

            var response = client.Get(new HelloCache {
                Name = "World"
            });

            Assert.That(response.Result, Is.EqualTo("Hello, World!"));
        }
Beispiel #7
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            client = new JsvServiceClient("http://prodactive.co/api");

            manager = Manager.GetInstance(
                new SQLitePlatformAndroid(),
                client,
                System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal),"prodactive.db"));
            // Get our button from the layout resource,
            // and attach an event to it
            Button btnLogin = FindViewById<Button>(Resource.Id.btnLogin);
             txtUser = FindViewById<EditText>(Resource.Id.txtUser);
             txtPass = FindViewById<EditText>(Resource.Id.txtPass);
            //Anadir Servicio

            btnLogin.Click += btnLogin_Click;
        }
Beispiel #8
0
        }                                                          //= new JsvServiceClient("http://localhost:63957/");

        static MvcApplication()
        {
            ServiceClient = new JsvServiceClient("http://localhost:10050");//{ UserName = "******", Password = "******" };
            //  ServiceClient.AlwaysSendBasicAuthHeader = true;
        }