Example #1
0
        public IDictionary <string, string> GetModels(Dictionary <string, string> ourFiles, string modelsNamespace)
        {
            // FIXME - add proxys support

            var hch = new HttpClientHandler();

            //hch.Proxy = new WebProxy("path.to.proxy", 8888);
            //hch.UseProxy = true;

            using (var client = new HttpClient(hch))
            {
                SetBaseAddress(client, _url);
                Authorize(client);

                var data = new GetModelsData
                {
                    Namespace     = modelsNamespace,
                    ClientVersion = ApiVersion.Current.Version,
                    MinServerVersionSupportingClient = ApiVersion.Current.MinServerVersionSupportingClient,
                    Files = ourFiles
                };

                var result = client.PostAsync(_url + ApiControllerUrl + nameof(ModelsBuilderApiController.GetModels),
                                              data, _formatter).Result;

                // this is not providing enough details in case of an error - do our own reporting
                //result.EnsureSuccessStatusCode();
                EnsureSuccess(result);

                var genFiles = result.Content.ReadAsAsync <IDictionary <string, string> >(_formatters).Result;
                return(genFiles);
            }
        }
        [ApiBasicAuthFilter("developer")] // have to use our own, non-cookie-based, auth
        public HttpResponseMessage GetModels(GetModelsData data)
        {
            if (!UmbracoConfig.For.ModelsBuilder().ApiServer)
            {
                return(Request.CreateResponse(HttpStatusCode.Forbidden, "API server does not want to talk to you."));
            }

            if (!ModelState.IsValid || data == null || !data.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid data."));
            }

            var checkResult = CheckVersion(data.ClientVersion, data.MinServerVersionSupportingClient);

            if (!checkResult.Success)
            {
                return(checkResult.Result);
            }

            var models = ApiHelper.GetModels(_umbracoServices, data.Namespace, data.Files);

            return(Request.CreateResponse(HttpStatusCode.OK, models, Configuration.Formatters.JsonFormatter));
        }