Ejemplo n.º 1
0
        private void ProcessResult(
            string projectName,
            string recipeName,
            IRestResponse <List <ResultItem> > resp,
            List <string> AoiList,
            string token,
            IRestClient client)
        {
            Jarvis.Logger.Info(resp.ResponseUri.ToString());
            var layername = string.Empty;
            var aoi       = ConvertAoisToGeometryCollection(AoiList);

            if (resp.Data != null)
            {
                if (resp.Data.Count == 0)
                {
                    this.Invoke((MethodInvoker)(() =>
                    {
                        this.loadingCircle.Visible = false;
                        this.loadingCircle.Active = false;
                        MessageBox.Show("No data results");
                        return;
                    }));
                }

                // since there can be multiple query ids its good to check to make sure we don't end up pulling duplicate results.
                var usedQueries = new HashSet <string>();
                foreach (var item in resp.Data)
                {
                    // if the recipe names don't match move on to the next
                    if (!recipeName.Equals(item.recipeName, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    layername = string.Format("{0}|{1}", projectName, item.recipeName);

                    var idahoIds = this.GetIds(resp.Data);

                    this.Invoke((MethodInvoker)(() => { GbdxHelper.AddIdahoWms(idahoIds, layername, this.token); }));

                    if (!string.IsNullOrEmpty(aoi) && !string.IsNullOrEmpty(layername))
                    {
                        if (usedQueries.Contains(item.properties.query_string))
                        {
                            continue;
                        }

                        usedQueries.Add(item.properties.query_string);
                        this.GetGeometries(item.properties.query_string, token, aoi, client, layername);
                    }
                }
            }
            this.Invoke((MethodInvoker)(() =>
            {
                this.loadingCircle.Visible = false;
                this.loadingCircle.Active = false;
            }));
        }
        private void GetSources(int applicationState, int attempts = 0)
        {
            var client = new RestClient(GbdxHelper.GetEndpointBase(Settings.Default));

            var addressUrl = "/insight-vector/api/shape/sources";

            var request = new RestRequest(addressUrl, Method.POST);

            request.AddHeader("Authorization", "Bearer " + this.token);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", this.Aoi, ParameterType.RequestBody);

            client.ExecuteAsync <SourceTypeResponseObject>(
                request,
                resp => this.ProcessSources(resp, applicationState, attempts));
        }
        private void GetPages(TreeNode node, string pageId, int applicationState, string currentCount, string layerName, StreamWriter fileStreamWriter, int attempts = 0)
        {
            var client  = new RestClient(GbdxHelper.GetEndpointBase(Settings.Default));
            var request = new RestRequest("/insight-vector/api/esri/paging", Method.POST);

            request.AddHeader("Authorization", "Bearer " + this.token);
            request.AddHeader("Content-Type", "application/json");

            request.AddParameter("ttl", "5m");
            request.AddParameter("fields", "attributes");
            request.AddParameter("pagingId", pageId);

            attempts++;
            client.ExecuteAsync <PagedData2>(
                request,
                resp => this.ProcessPage(node, resp, applicationState, currentCount, pageId, layerName, fileStreamWriter, attempts));
        }
        //private void UpdateStatus(TreeNode node, )

        private void GetPagingId(TreeNode node, int applicationState, int attempts = 0)
        {
            var sourceNode   = (VectorIndexSourceNode)node.Parent.Parent;
            var geometryNode = (VectorIndexGeometryNode)node.Parent;
            var typeNode     = (VectorIndexTypeNode)node;

            var addressUrl = string.Empty;

            if (string.IsNullOrEmpty(this.query))
            {
                addressUrl = string.Format(
                    "/insight-vector/api/shape/{0}/{1}/{2}/paging",
                    sourceNode.Source.Name,
                    geometryNode.GeometryType.Name,
                    typeNode.Type.Name);
            }
            else
            {
                addressUrl = string.Format(
                    "/insight-vector/api/shape/query/{0}/{1}/paging?q={2}",
                    geometryNode.GeometryType.Name,
                    typeNode.Type.Name,
                    this.query);
            }

            var client = new RestClient(GbdxHelper.GetEndpointBase(Settings.Default));


            RuntimeInfo arcRuntimeInfo = RuntimeManager.ActiveRuntime;

            client.UserAgent += arcRuntimeInfo.Product + " " + arcRuntimeInfo.Version;
            var request = new RestRequest(addressUrl, Method.POST);

            request.AddHeader("Authorization", "Bearer " + this.token);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", this.Aoi, ParameterType.RequestBody);

            attempts++;
            client.ExecuteAsync <PagedData2>(request, resp => this.ProcessPagingId(resp, attempts, node, applicationState));
        }
        private void GetTypes(TreeNode geometryNode, int applicationState, int attempts = 0)
        {
            geometryNode.Text  = geometryNode.Text.Replace(GbdxResources.Source_ErrorMessage, string.Empty);
            geometryNode.Text += GbdxResources.SearchingText;

            var sourceNode = (VectorIndexSourceNode)geometryNode.Parent;
            var geomNode   = (VectorIndexGeometryNode)geometryNode;

            var client        = new RestClient(GbdxHelper.GetEndpointBase(Settings.Default));
            var addressString = string.Empty;

            if (string.IsNullOrEmpty(this.query))
            {
                addressString = string.Format(
                    "/insight-vector/api/shape/{0}/{1}/types",
                    sourceNode.Source.Name,
                    geomNode.GeometryType.Name);
            }
            else
            {
                addressString = string.Format(
                    "/insight-vector/api/shape/query/{0}/types?q={1}",
                    geomNode.GeometryType.Name,
                    this.query);
            }

            var request = new RestRequest(addressString, Method.POST);

            request.AddHeader("Authorization", "Bearer " + this.token);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", this.Aoi, ParameterType.RequestBody);
            attempts++;
            client.ExecuteAsync <SourceTypeResponseObject>(
                request,
                resp => this.ProcessGetTypesResponse(resp, geometryNode, applicationState, attempts));
        }
        private void GetGeometries(VectorIndexSourceNode source, int applicationState, int attempts = 0)
        {
            var client     = new RestClient(GbdxHelper.GetEndpointBase(Settings.Default));
            var addressUrl = string.Empty;

            if (string.IsNullOrEmpty(this.query))
            {
                addressUrl = string.Format("/insight-vector/api/shape/{0}/geometries", source.Source.Name);
            }
            else
            {
                addressUrl = "/insight-vector/api/shape/query/geometries?q=" + this.query;
            }

            var request = new RestRequest(addressUrl, Method.POST);

            request.AddHeader("Authorization", "Bearer  " + this.token);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", this.Aoi, ParameterType.RequestBody);
            attempts++;
            client.ExecuteAsync <SourceTypeResponseObject>(
                request,
                resp => this.ProcessGeometries(resp, source, applicationState, attempts));
        }