Esempio n. 1
0
        public override void GetText(TextWriter writer, Dictionary<string, object> arguments, Scope context)
        {
            int width;
            if (arguments["width"] is decimal)
                width = Convert.ToInt32((decimal) arguments["width"]);
            else
                width = (int) arguments["width"];

            int height;
            if (arguments["height"] is decimal)
                height = Convert.ToInt32((decimal) arguments["height"]);
            else
                height = (int) arguments["height"];

            var imageFormat = new ImageFormat
            {
                Width = width,
                Height = height,
                Type = (string) arguments["format"]
            };

            var baseUrl = (string) arguments["baseUrl"];
            var url = _imageService.GetURL(new Uri(baseUrl), imageFormat);
            writer.Write(url.ToString());
        }
Esempio n. 2
0
        public Uri GetURL(Uri baseUri, ImageFormat format)
        {
            var client = new RestClient(_host);
            var request = new RestRequest("/");

            request.AddParameter("url", baseUri.ToString());
            request.AddParameter("width", format.Width);
            request.AddParameter("height", format.Height);
            request.AddParameter("format", format.Type);

            request.AddHeader("X-ApiKey", _apiKey);

            client.FollowRedirects = false;
            var response = client.Execute(request);
            if (response.StatusCode != HttpStatusCode.MovedPermanently)
                return baseUri;

            return new Uri((string) response.Headers.First(h => h.Name == "Location").Value);
        }
Esempio n. 3
0
 public Uri GetURL(Uri baseUri, ImageFormat format)
 {
     return baseUri;
 }