Exemple #1
0
        public GeocodeTransform(IContext context = null) : base(context, "object")
        {
            ProducesFields = true;

            if (IsMissingContext())
            {
                return;
            }

            if (IsMissing(Context.Operation.ApiKey))
            {
                return;
            }

            if (Context.Operation.Parameters.Any())
            {
                var lat = Context.Operation.Parameters.FirstOrDefault(p => p.Name.ToLower().In("lat", "latitude"));
                if (lat == null)
                {
                    Error("The google-geocode transform requires an output field named lat, or latitude.");
                    Run = false;
                    return;
                }
                if (lat.Type != "double")
                {
                    Error($"The google-geocode {lat.Name} field must be of type double.");
                    Run = false;
                    return;
                }

                var lon = Context.Operation.Parameters.FirstOrDefault(p => p.Name.ToLower().In("lon", "long", "longitude"));
                if (lon == null)
                {
                    Error("The google-geocode (geocode) transform requires an output field named lon, long, or longitude.");
                    Run = false;
                    return;
                }
                if (lon.Type != "double")
                {
                    Error($"The google-geocode {lon.Name} field must be of type double.");
                    Run = false;
                    return;
                }
            }
            else
            {
                Error("The google-geocode transform requires a collection of output fields; namely: latitude, longitude, and formattedaddress (optional).");
                Run = false;
                return;
            }

            _input  = SingleInputForMultipleOutput();
            _output = MultipleOutput();

            GoogleSigned.AssignAllServices(new GoogleSigned(Context.Operation.ApiKey));

            _originalConnectionLimit = ServicePointManager.DefaultConnectionLimit;
            ServicePointManager.DefaultConnectionLimit = 255;
            _rateGate        = new RateGate(Context.Operation.Limit, TimeSpan.FromMilliseconds(Context.Operation.Time));
            _componentFilter = new ComponentFilter {
                AdministrativeArea = Context.Operation.AdministrativeArea,
                Country            = Context.Operation.Country,
                Locality           = Context.Operation.Locality,
                PostalCode         = Context.Operation.PostalCode,
                Route = Context.Operation.Route
            };

            try {
                _service = new GeocodingService();
            } catch (Exception ex) {
                Run = false;
                Context.Error("Could not construct GeocodingService. {0}", ex.Message);
            }

            if (Run)
            {
                Context.Debug(() => "GeocodeTransform (google-geocode) is initialized and will run.");
            }
            else
            {
                Context.Debug(() => "GeocodeTransform (google-geocode) will not run due to setup issues.");
            }
        }
        public PlaceTransform(IContext context = null) : base(context, "object")
        {
            ProducesFields = true;

            if (IsMissingContext())
            {
                return;
            }

            if (IsMissing(Context.Operation.ApiKey))
            {
                return;
            }

            if (Context.Operation.Parameters.Any())
            {
                var place = Context.Operation.Parameters.FirstOrDefault(p => p.Name.ToLower().In("place", "placeid"));
                if (place == null)
                {
                    Error("The google-place transform requires an output field named 'place' or 'placeid'.");
                    Run = false;
                    return;
                }

                var lat = Context.Operation.Parameters.FirstOrDefault(p => p.Name.ToLower().In("lat", "latitude"));
                if (lat != null)
                {
                    if (lat.Type != "double")
                    {
                        Error($"The google-place {lat.Name} field must be of type double.");
                        Run = false;
                        return;
                    }
                }

                var lon = Context.Operation.Parameters.FirstOrDefault(p => p.Name.ToLower().In("lon", "long", "longitude"));
                if (lon != null)
                {
                    if (lon.Type != "double")
                    {
                        Error($"The google-place {lon.Name} field must be of type double.");
                        Run = false;
                        return;
                    }
                }
            }
            else
            {
                Error("The google-place transform requires a collection of output fields; namely: placeid, latitude (optional), longitude (optional), and formattedaddress (optional).");
                Run = false;
                return;
            }


            if (Run)
            {
                Context.Debug(() => "PlaceTransform (google-place) is initialized and will run.");
            }
            else
            {
                Context.Debug(() => "PlaceTransform (google-place) will not run due to setup issues.");
            }

            _input  = SingleInputForMultipleOutput();
            _output = MultipleOutput();

            GoogleSigned.AssignAllServices(new GoogleSigned(Context.Operation.ApiKey));

            _originalConnectionLimit = ServicePointManager.DefaultConnectionLimit;
            ServicePointManager.DefaultConnectionLimit = 255;
            _rateGate = new RateGate(Context.Operation.Limit, TimeSpan.FromMilliseconds(Context.Operation.Time));
        }