Пример #1
0
        // [HttpGet]
        // [Route("api/forge/bim360/account/{accountId}/project/{projectId}/locations")]
        // public async Task<IActionResult> GetBIM360LocationsAsync(string accountId, string projectId, [FromQuery] bool buildTree = false)
        // {
        //     IRestResponse locsResponse = await GetLocationsAsync(accountId, projectId);
        //     var locations = JsonConvert.DeserializeObject<PaginatedLocations>(locsResponse.Content);

        //     if (buildTree == false)
        //     {
        //         return Ok(locations.Results);
        //     }
        //     else
        //     {
        //         var root = locations.Results.FirstOrDefault();
        //         var tree = Location.BuildTree(locations.Results, root.Id);
        //         return Ok(tree);
        //     }
        // }

        private async Task <string> GetContainerIdAsync(string accountId, string projectId, ContainerType type)
        {
            Credentials credentials = await Credentials.FromSessionAsync(base.Request.Cookies, Response.Cookies);

            ProjectsApi projectsApi = new ProjectsApi();

            projectsApi.Configuration.AccessToken = credentials.TokenInternal;
            var project = await projectsApi.GetProjectAsync(accountId, projectId);

            var    relationships = project.data.relationships;
            string containerId   = string.Empty;

            var result = relationships.Dictionary;

            foreach (var relation in result)
            {
                string name = relation.Key;
                if (name != type.Value)
                {
                    continue;
                }

                var data = relation.Value.data;
                if (data == null || !data.type.Contains(type.Value))
                {
                    continue;
                }

                containerId = data.id;
            }

            return(containerId);
        }
        public async Task <JObject> GetUserProfileAsync()
        {
            Credentials credentials = await Credentials.FromSessionAsync(Request.Cookies, Response.Cookies);

            if (credentials == null)
            {
                return(null);
            }

            // the API SDK
            UserProfileApi userApi = new UserProfileApi();

            userApi.Configuration.AccessToken = credentials.TokenInternal;


            // get the user profile
            dynamic userProfile = await userApi.GetUserProfileAsync();

            // prepare a response with name & picture
            dynamic response = new JObject();

            response.name    = string.Format("{0} {1}", userProfile.firstName, userProfile.lastName);
            response.picture = userProfile.profileImages.sizeX40;
            return(response);
        }
Пример #3
0
        private async Task <Asset> GetAssetsBySearchTextAsync(string projectId, string text)
        {
            Credentials credentials = await Credentials.FromSessionAsync(base.Request.Cookies, Response.Cookies);

            if (credentials == null)
            {
                throw new InvalidOperationException("Failed to refresh access token");
            }

            RestClient  client  = new RestClient(BASE_URL);
            RestRequest request = new RestRequest("/bim360/assets/v2/projects/{project_id}/assets", RestSharp.Method.GET);

            request.AddParameter("project_id", projectId.Replace("b.", string.Empty), ParameterType.UrlSegment);
            request.AddParameter("includeCustomAttributes", true, ParameterType.QueryString);
            request.AddParameter("filter[searchText]", text, ParameterType.QueryString);
            request.AddHeader("Authorization", "Bearer " + credentials.TokenInternal);

            IRestResponse assetsResponse = await client.ExecuteTaskAsync(request);

            var assets = JsonConvert.DeserializeObject <PaginatedAssets>(assetsResponse.Content);

            if (assets.Results == null || assets.Results.Count <= 0)
            {
                return(null);
            }

            return(assets.Results.FirstOrDefault());
        }
Пример #4
0
        private async Task <IRestResponse> GetAssetsAsync(string projectId, string cursorState, Nullable <int> pageLimit = null)
        {
            Credentials credentials = await Credentials.FromSessionAsync(base.Request.Cookies, Response.Cookies);

            if (credentials == null)
            {
                throw new InvalidOperationException("Failed to refresh access token");
            }

            RestClient  client  = new RestClient(BASE_URL);
            RestRequest request = new RestRequest("/bim360/assets/v2/projects/{project_id}/assets", RestSharp.Method.GET);

            request.AddParameter("project_id", projectId.Replace("b.", string.Empty), ParameterType.UrlSegment);
            request.AddParameter("includeCustomAttributes", true, ParameterType.QueryString);
            request.AddParameter("sort", "categoryId asc,clientAssetId asc", ParameterType.QueryString);
            request.AddHeader("Authorization", "Bearer " + credentials.TokenInternal);

            if (!string.IsNullOrWhiteSpace(cursorState))
            {
                request.AddParameter("cursorState", cursorState, ParameterType.QueryString);
            }

            if (pageLimit != null && pageLimit.HasValue)
            {
                request.AddParameter("limit", pageLimit.Value, ParameterType.QueryString);
            }

            return(await client.ExecuteTaskAsync(request));
        }
Пример #5
0
        private async Task <IRestResponse> GetIssueTypesAsync(string containerId)
        {
            Credentials credentials = await Credentials.FromSessionAsync(base.Request.Cookies, Response.Cookies);

            RestClient  client  = new RestClient(BASE_URL);
            RestRequest request = new RestRequest("/issues/v1/containers/{container_id}/ng-issue-types?include=subtypes", RestSharp.Method.GET);

            request.AddParameter("container_id", containerId, ParameterType.UrlSegment);
            request.AddHeader("Authorization", "Bearer " + credentials.TokenInternal);
            request.AddHeader("Content-Type", "application/vnd.api+json");

            return(await client.ExecuteTaskAsync(request));
        }
Пример #6
0
        private async Task <IRestResponse> PostIssuesAsync(string containerId, string resource, JObject data)
        {
            Credentials credentials = await Credentials.FromSessionAsync(base.Request.Cookies, Response.Cookies);

            RestClient  client  = new RestClient(BASE_URL);
            RestRequest request = new RestRequest("/issues/v1/containers/{container_id}/{resource}", RestSharp.Method.POST);

            request.AddParameter("container_id", containerId, ParameterType.UrlSegment);
            request.AddParameter("resource", resource, ParameterType.UrlSegment);
            request.AddHeader("Authorization", "Bearer " + credentials.TokenInternal);
            request.AddHeader("Content-Type", "application/vnd.api+json");
            request.AddParameter("text/json", Newtonsoft.Json.JsonConvert.SerializeObject(data), ParameterType.RequestBody);

            return(await client.ExecuteTaskAsync(request));
        }
Пример #7
0
        private async Task <IRestResponse> GetIssuesAsync(string containerId, string resource, string urn)
        {
            Credentials credentials = await Credentials.FromSessionAsync(base.Request.Cookies, Response.Cookies);

            urn = Encoding.UTF8.GetString(Convert.FromBase64String(urn));

            RestClient  client  = new RestClient(BASE_URL);
            RestRequest request = new RestRequest("/issues/v1/containers/{container_id}/{resource}?filter[target_urn]={urn}", RestSharp.Method.GET);

            request.AddParameter("container_id", containerId, ParameterType.UrlSegment);
            request.AddParameter("urn", urn, ParameterType.UrlSegment);
            request.AddParameter("resource", resource, ParameterType.UrlSegment);
            request.AddHeader("Authorization", "Bearer " + credentials.TokenInternal);
            return(await client.ExecuteTaskAsync(request));
        }
        public async Task <AccessToken> GetPublicTokenAsync()
        {
            Credentials credentials = await Credentials.FromSessionAsync(Request.Cookies, Response.Cookies);

            if (credentials == null)
            {
                base.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return(new AccessToken());
            }

            // return the public (viewables:read) access token
            return(new AccessToken()
            {
                access_token = credentials.TokenPublic,
                expires_in = (int)credentials.ExpiresAt.Subtract(DateTime.Now).TotalSeconds
            });
        }
Пример #9
0
        private async Task <Asset> GetAssetsByExtIdAsync(string projectId, string id)
        {
            Credentials credentials = await Credentials.FromSessionAsync(base.Request.Cookies, Response.Cookies);

            if (credentials == null)
            {
                throw new InvalidOperationException("Failed to refresh access token");
            }

            var attrDefsResponse = await GetCustomAttributeDefsAsync(projectId.Replace("b.", string.Empty), null, 100);

            var attrDefs       = JsonConvert.DeserializeObject <PaginatedAssetCustomAttributes>(attrDefsResponse.Content);
            var attrDefMapping = attrDefs.Results.ToDictionary(d => d.DisplayName, d => d);
            var extIdAttr      = attrDefs.Results.First(attr => attr.DisplayName.ToLower().Contains("External Id".ToLower()));

            if (extIdAttr == null)
            {
                throw new InvalidOperationException("Failed to get CustomAttribute called `External Id`");
            }

            RestClient  client  = new RestClient(BASE_URL);
            RestRequest request = new RestRequest("/bim360/assets/v2/projects/{project_id}/assets", RestSharp.Method.GET);

            request.AddParameter("project_id", projectId.Replace("b.", string.Empty), ParameterType.UrlSegment);
            request.AddParameter("includeCustomAttributes", true, ParameterType.QueryString);

            var attrFilter = string.Format("filter[customAttributes][{0}]", extIdAttr.Name);

            request.AddParameter(attrFilter, id, ParameterType.QueryString);
            request.AddHeader("Authorization", "Bearer " + credentials.TokenInternal);

            IRestResponse assetsResponse = await client.ExecuteTaskAsync(request);

            var assets = JsonConvert.DeserializeObject <PaginatedAssets>(assetsResponse.Content);

            if (assets.Results == null || assets.Results.Count <= 0)
            {
                return(null);
            }

            return(assets.Results.FirstOrDefault());
        }
Пример #10
0
        public async Task <dynamic> GetContainerAsync(string href)
        {
            string[] idParams  = href.Split('/');
            string   projectId = idParams[idParams.Length - 1];
            string   hubId     = idParams[idParams.Length - 3];

            Credentials credentials = await Credentials.FromSessionAsync(base.Request.Cookies, Response.Cookies);

            ProjectsApi projectsApi = new ProjectsApi();

            projectsApi.Configuration.AccessToken = credentials.TokenInternal;
            var project = await projectsApi.GetProjectAsync(hubId, projectId);

            var issues = project.data.relationships.issues.data;

            if (issues.type != "issueContainerId")
            {
                return(null);
            }
            return(new { ContainerId = issues["id"], HubId = hubId });
        }
Пример #11
0
        private async Task <IRestResponse> GetAssetStatusessAsync(string projectId, string cursorState, Nullable <int> pageLimit = null)
        {
            Credentials credentials = await Credentials.FromSessionAsync(base.Request.Cookies, Response.Cookies);

            RestClient  client  = new RestClient(BASE_URL);
            RestRequest request = new RestRequest("/bim360/assets/v1/projects/{project_id}/status-step-sets", RestSharp.Method.GET);

            request.AddParameter("project_id", projectId.Replace("b.", string.Empty), ParameterType.UrlSegment);
            request.AddHeader("Authorization", "Bearer " + credentials.TokenInternal);

            if (!string.IsNullOrWhiteSpace(cursorState))
            {
                request.AddParameter("cursorState", cursorState, ParameterType.QueryString);
            }

            if (pageLimit != null && pageLimit.HasValue)
            {
                request.AddParameter("limit", pageLimit.Value, ParameterType.QueryString);
            }

            return(await client.ExecuteTaskAsync(request));
        }