コード例 #1
0
        public async Task <JObject> 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);
            }
            JObject res = new JObject();

            res.Add("container", JObject.Parse(issues.ToString()));
            res.Add("project", JObject.Parse(project.data.ToString()));
            return(res);
        }
コード例 #2
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);
        }
コード例 #3
0
        private async Task <IList <jsTreeNode> > GetProjectContents(string href)
        {
            IList <jsTreeNode> nodes       = new List <jsTreeNode>();
            ProjectsApi        projectsApi = new ProjectsApi();

            projectsApi.Configuration.AccessToken = Credentials.TokenInternal;
            string[] idParams  = href.Split('/');
            string   hubId     = idParams[idParams.Length - 3];
            string   projectId = idParams[idParams.Length - 1];
            var      project   = await projectsApi.GetProjectAsync(hubId, projectId);

            var rootFolderHref = project.data.relationships.rootFolder.meta.link.href;

            return(await GetFolderCountents(rootFolderHref));
        }
コード例 #4
0
        public async Task <string> GetContainer(string userAccessToken, string hubId, string projectId)
        {
            ProjectsApi projectsApi = new ProjectsApi();

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

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

            if (issues.type != "issueContainerId")
            {
                return(null);
            }
            return(issues.id.ToString());
        }
コード例 #5
0
        public static async Task <string> GetContainerAsync(Credentials credentials, string hubId, string projectId)
        {
            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(issues["id"]);
        }
コード例 #6
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 });
        }
        public async Task <Object> UploadObject()//[FromBody]UploadObjectModel obj)
        {
            // basic input validation
            HttpRequest req = HttpContext.Current.Request;

            if (string.IsNullOrWhiteSpace(req.Params["href"]))
            {
                throw new System.Exception("Folder href parameter was not provided.");
            }

            if (req.Files.Count != 1)
            {
                throw new System.Exception("Missing file to upload"); // for now, let's support just 1 file at a time
            }
            string href = req.Params["href"];

            string[] idParams  = href.Split('/');
            string   folderId  = string.Empty;
            string   projectId = string.Empty;

            ProjectsApi projectApi = new ProjectsApi();

            projectApi.Configuration.AccessToken = AccessToken;

            switch (idParams[idParams.Length - 2])
            {
            case "projects":
                // need the root folder of this project
                var project = await projectApi.GetProjectAsync(idParams[idParams.Length - 3], idParams[idParams.Length - 1]);

                var rootFolderHref = project.data.relationships.rootFolder.data.id;

                folderId  = rootFolderHref;
                projectId = idParams[idParams.Length - 1];
                break;

            case "folders":
                folderId  = idParams[idParams.Length - 1];
                projectId = idParams[idParams.Length - 3];
                break;
            }
            HttpPostedFile file = req.Files[0];

            // save the file on the server
            var fileSavePath = Path.Combine(HttpContext.Current.Server.MapPath("~/App_Data"), file.FileName);

            file.SaveAs(fileSavePath);

            StorageRelationshipsTargetData       storageRelData = new StorageRelationshipsTargetData(StorageRelationshipsTargetData.TypeEnum.Folders, folderId);
            CreateStorageDataRelationshipsTarget storageTarget  = new CreateStorageDataRelationshipsTarget(storageRelData);
            CreateStorageDataRelationships       storageRel     = new CreateStorageDataRelationships(storageTarget);
            BaseAttributesExtensionObject        attributes     = new BaseAttributesExtensionObject(string.Empty, string.Empty, new JsonApiLink(string.Empty), null);
            CreateStorageDataAttributes          storageAtt     = new CreateStorageDataAttributes(file.FileName, attributes);
            CreateStorageData storageData = new CreateStorageData(CreateStorageData.TypeEnum.Objects, storageAtt, storageRel);
            CreateStorage     storage     = new CreateStorage(new JsonApiVersionJsonapi(JsonApiVersionJsonapi.VersionEnum._0), storageData);

            dynamic storageCreated = await projectApi.PostStorageAsync(projectId, storage);

            string[] storageIdParams = ((string)storageCreated.data.id).Split('/');
            var      objectName      = storageIdParams[storageIdParams.Length - 1];

            string[] bucketIdParams = storageIdParams[storageIdParams.Length - 2].Split(':');
            var      bucketKey      = bucketIdParams[bucketIdParams.Length - 1];

            // upload the file/object
            ObjectsApi objects = new ObjectsApi();

            objects.Configuration.AccessToken = AccessToken;
            dynamic uploadedObj;

            using (StreamReader streamReader = new StreamReader(fileSavePath))
            {
                uploadedObj = await objects.UploadObjectAsync(bucketKey,
                                                              objectName, (int)streamReader.BaseStream.Length, streamReader.BaseStream,
                                                              "application/octet-stream");
            }

            string type = string.Format(":autodesk.{0}:File", (href.IndexOf("projects/b.") > 0 ? "bim360" : "core"));

            CreateItem item = new CreateItem(new JsonApiVersionJsonapi(JsonApiVersionJsonapi.VersionEnum._0),
                                             new CreateItemData(CreateItemData.TypeEnum.Items,
                                                                new CreateItemDataAttributes(file.FileName,
                                                                                             new BaseAttributesExtensionObject("items" + type, "1.0", new JsonApiLink(string.Empty))),
                                                                new CreateItemDataRelationships(
                                                                    new CreateItemDataRelationshipsTip(
                                                                        new CreateItemDataRelationshipsTipData(CreateItemDataRelationshipsTipData.TypeEnum.Versions, CreateItemDataRelationshipsTipData.IdEnum._1)),
                                                                    new CreateStorageDataRelationshipsTarget(
                                                                        new StorageRelationshipsTargetData(StorageRelationshipsTargetData.TypeEnum.Folders, folderId)))),
                                             new System.Collections.Generic.List <CreateItemIncluded>()
            {
                new CreateItemIncluded(CreateItemIncluded.TypeEnum.Versions, CreateItemIncluded.IdEnum._1,
                                       new CreateStorageDataAttributes(file.FileName, new BaseAttributesExtensionObject("versions" + type, "1.0", new JsonApiLink(string.Empty))),
                                       new CreateItemRelationships(
                                           new CreateItemRelationshipsStorage(
                                               new CreateItemRelationshipsStorageData(CreateItemRelationshipsStorageData.TypeEnum.Objects, storageCreated.data.id))))
            }
                                             );

            ItemsApi itemsApi = new ItemsApi();

            itemsApi.Configuration.AccessToken = AccessToken;
            dynamic newItem = itemsApi.PostItem(projectId, item);

            // cleanup
            File.Delete(fileSavePath);

            return(uploadedObj);
        }