public static async Task <List <GeometryNode> > GetGeometryNode()
        {
            List <GeometryNode> nodeidResponse = new List <GeometryNode>();

            try
            {
                HttpClient client = await ArchesHttpClient.GetHttpClient();

                if ((DateTime.Now - StaticVariables.archesToken["timestamp"]).TotalSeconds > (StaticVariables.archesToken["expires_in"] - 300))
                {
                    StaticVariables.archesToken = await MainDockpaneView.RefreshToken(StaticVariables.myClientid);
                }

                client.DefaultRequestHeaders.Authorization =
                    new AuthenticationHeaderValue("Bearer", StaticVariables.archesToken["access_token"]);
                HttpResponseMessage response = await client.GetAsync(System.IO.Path.Combine(StaticVariables.archesInstanceURL, "api/nodes/?datatype=geojson-feature-collection&perms=write_nodegroup"));

                response.EnsureSuccessStatusCode();
                string responseBody = await response.Content.ReadAsStringAsync();

                var     serializer = new JavaScriptSerializer();
                dynamic results    = serializer.Deserialize <dynamic>(@responseBody);

                foreach (dynamic element in results)
                {
                    nodeidResponse.Add(new GeometryNode(element["resourcemodelname"], element["name"], element["nodeid"]));
                }
            }
            catch (HttpRequestException e)
            {
                System.ArgumentException argEx = new System.ArgumentException("The nodeid cannot be retrieved from the Arches server", e);
                throw argEx;
            }
            return(nodeidResponse);
        }
        private async Task <Dictionary <String, Boolean> > CheckInstancePermission(string resourceInstanceID)
        {
            Dictionary <String, Boolean> result = new Dictionary <String, Boolean>();

            try
            {
                HttpClient client = await ArchesHttpClient.GetHttpClient();

                if ((DateTime.Now - StaticVariables.archesToken["timestamp"]).TotalSeconds > (StaticVariables.archesToken["expires_in"] - 300))
                {
                    StaticVariables.archesToken = await MainDockpaneView.RefreshToken(StaticVariables.myClientid);
                }

                client.DefaultRequestHeaders.Authorization =
                    new AuthenticationHeaderValue("Bearer", StaticVariables.archesToken["access_token"]);
                var response = await client.GetAsync(System.IO.Path.Combine(StaticVariables.archesInstanceURL, string.Format("api/instance_permissions/?resourceinstanceid={0}", resourceInstanceID)));

                response.EnsureSuccessStatusCode();
                string responseBody = await response.Content.ReadAsStringAsync();

                var     serializer = new JavaScriptSerializer();
                dynamic results    = serializer.Deserialize <dynamic>(@responseBody);

                result.Add("read", results["read"]);
                result.Add("edit", results["edit"]);
                result.Add("delete", results["delete"]);
            }
            catch (HttpRequestException ex)
            {
                throw new System.ArgumentException(ex.Message, ex);
            }
            return(result);
        }
Example #3
0
        public static async Task <Dictionary <string, string> > SubmitToArches(string tileid, string nodeid, string esrijson, string geometryFormat, string submitOperation)
        {
            Dictionary <String, String> result = new Dictionary <String, String>();

            try
            {
                HttpClient client = await ArchesHttpClient.GetHttpClient();

                if ((DateTime.Now - StaticVariables.archesToken["timestamp"]).TotalSeconds > (StaticVariables.archesToken["expires_in"] - 300))
                {
                    StaticVariables.archesToken = await MainDockpaneView.RefreshToken(StaticVariables.myClientid);
                }

                var serializer    = new JavaScriptSerializer();
                var stringContent = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair <string, string>("tileid", tileid),
                    new KeyValuePair <string, string>("nodeid", nodeid),
                    new KeyValuePair <string, string>("data", esrijson),
                    new KeyValuePair <string, string>("format", geometryFormat),
                    new KeyValuePair <string, string>("operation", submitOperation),
                });

                client.DefaultRequestHeaders.Authorization =
                    new AuthenticationHeaderValue("Bearer", StaticVariables.archesToken["access_token"]);
                var response = await client.PostAsync(System.IO.Path.Combine(StaticVariables.archesInstanceURL, "api/node_value/"), stringContent);

                response.EnsureSuccessStatusCode();
                string responseBody = await response.Content.ReadAsStringAsync();

                dynamic responseJSON = serializer.Deserialize <dynamic>(@responseBody);

                if (responseJSON.ContainsKey("nodegroup_id"))
                {
                    result.Add("nodegroup_id", responseJSON["nodegroup_id"]);
                }
                if (responseJSON.ContainsKey("resourceinstance_id"))
                {
                    result.Add("resourceinstance_id", responseJSON["resourceinstance_id"]);
                }
                if (responseJSON.ContainsKey("tileid"))
                {
                    result.Add("tileid", responseJSON["tileid"]);
                }
            }
            catch (HttpRequestException ex)
            {
                throw new System.ArgumentException(ex.Message, ex);
            }
            return(result);
        }