private async Task <IList <TreeNode> > GetFolderContents(string href)
        {
            IList <TreeNode> nodes = new List <TreeNode>();

            string[] idParams  = href.Split('/');
            string   folderId  = idParams[idParams.Length - 1];
            string   projectId = idParams[idParams.Length - 3];

            FoldersApi folderApi = new FoldersApi();

            folderApi.Configuration.AccessToken = AccessToken;
            var folderContents = await folderApi.GetFolderContentsAsync(projectId, folderId);

            foreach (KeyValuePair <string, dynamic> folderContentItem in new DynamicDictionaryItems(folderContents.data))
            {
                string displayName = folderContentItem.Value.attributes.displayName;
                if (string.IsNullOrWhiteSpace(displayName))
                {
                    // BIM 360 related documents don't have displayName
                    // need to ask each one for a name
                    ItemsApi itemsApi = new ItemsApi();
                    itemsApi.Configuration.AccessToken = AccessToken;
                    dynamic item = await itemsApi.GetItemAsync(projectId, folderContentItem.Value.id);

                    displayName = item.included[0].attributes.displayName;
                }

                TreeNode itemNode = new TreeNode(folderContentItem.Value.links.self.href, displayName, (string)folderContentItem.Value.type, true);

                nodes.Add(itemNode);
            }

            return(nodes);
        }
        private async Task<IList<jsTreeNode>> GetItemVersions(string href)
        {
            IList<jsTreeNode> nodes = new List<jsTreeNode>();

            // the API SDK
            ItemsApi itemApi = new ItemsApi();
            itemApi.Configuration.AccessToken = Credentials.TokenInternal;

            // extract the projectId & itemId from the href
            string[] idParams = href.Split('/');
            string itemId = idParams[idParams.Length - 1];
            string projectId = idParams[idParams.Length - 3];

            var versions = await itemApi.GetItemVersionsAsync(projectId, itemId);
            foreach (KeyValuePair<string, dynamic> version in new DynamicDictionaryItems(versions.data))
            {
                DateTime versionDate = version.Value.attributes.lastModifiedTime;
                string verNum = version.Value.id.Split("=")[1];
                string userName = version.Value.attributes.lastModifiedUserName;

                string urn = string.Empty;
                try { urn = (string)version.Value.relationships.derivatives.data.id; }
                catch { urn = Base64Encode(version.Value.id); } // some BIM 360 versions don't have viewable

                jsTreeNode node = new jsTreeNode(
                    urn,
                    string.Format("v{0}: {1} by {2}", verNum, versionDate.ToString("dd/MM/yy HH:mm:ss"), userName),
                    "versions",
                    false);
                nodes.Add(node);
            }

            return nodes;
        }
示例#3
0
        private async Task GetItemVersionsAsync(Credentials credentials, string hubId, string folderUrn, string itemHref, PerformContext context)
        {
            await credentials.RefreshAsync();

            BackgroundJobClient metadataQueue = new BackgroundJobClient();
            IState state = new EnqueuedState("metadata");

            // the API SDK
            ItemsApi itemApi = new ItemsApi();

            itemApi.Configuration.AccessToken = credentials.TokenInternal;

            // extract the projectId & itemId from the href
            string[] idParams  = itemHref.Split('/');
            string   itemUrn   = idParams[idParams.Length - 1];
            string   projectId = idParams[idParams.Length - 3];

            var item = await itemApi.GetItemAsync(projectId, itemUrn);

            string versionUrn = (string)item.data.relationships.tip.data.id;
            string fileName   = (string)item.data.attributes.displayName;
            string extension  = fileName.Split(".").Last().ToLower();

            if (Config.SupportedFormats.IndexOf(extension) == -1)
            {
                return;
            }

            string absolutePath = string.Format("/manifest/_doc/{0}", ModelDerivativeController.Base64Encode(itemUrn));

            RestClient  client  = new RestClient(Config.ElasticSearchServer);
            RestRequest request = new RestRequest(absolutePath, RestSharp.Method.GET);

            if (!string.IsNullOrEmpty(Config.AWSKey) && !string.IsNullOrEmpty(Config.AWSSecret))
            {
                SortedDictionary <string, string> headers = AWS.Signature.SignatureHeader(
                    Amazon.RegionEndpoint.GetBySystemName(Config.AWSRegion),
                    new Uri(Config.ElasticSearchServer).Host,
                    "GET", string.Empty, absolutePath);
                foreach (var entry in headers)
                {
                    request.AddHeader(entry.Key, entry.Value);
                }
            }

            IRestResponse res = await client.ExecuteTaskAsync(request);

            if (res.StatusCode == HttpStatusCode.OK && Config.SkipAlreadyIndexed)
            {
                context.WriteLine(string.Format("{0}: already indexed, skip", fileName));
                System.Threading.Thread.Sleep(1000); // otherwise we'll reach the rate limit...
                return;
            }

            context.WriteLine(string.Format("{0}: {1}", fileName, versionUrn));

            await ModelDerivativeHub.NotifyFileFound(_hubContext, hubId);

            metadataQueue.Create(() => ProcessFile(credentials.UserId, hubId, projectId, folderUrn, itemUrn, versionUrn, fileName, null), state);
        }
示例#4
0
        public static void Mainext()
        {
            Configuration config = new Configuration();

            config.BasePath = "https://api.mercadolibre.com";
            // Configure OAuth2 access token for authorization: oAuth2AuthCode
            config.AccessToken = "YOUR_ACCESS_TOKEN";

            var apiInstance = new ItemsApi(config);
            var id          = "id_example";          // string |
            var accessToken = "accessToken_example"; // string |
            var item        = new Item();            // Item |

            try
            {
                // Update a Item.
                apiInstance.ItemsIdPut(id, accessToken, item);
            }
            catch (ApiException e)
            {
                Debug.Print("Exception when calling ItemsApi.ItemsIdPut: " + e.Message);
                Debug.Print("Status Code: " + e.ErrorCode);
                Debug.Print(e.StackTrace);
            }
        }
示例#5
0
        private async Task <IList <jsTreeNode> > GetItemVersions(string href)
        {
            List <jsTreeNode> nodes    = new List <jsTreeNode>();
            ItemsApi          itemsApi = new ItemsApi();

            itemsApi.Configuration.AccessToken = Credentials.TokenInternal;
            string[] idParams  = href.Split('/');
            string   itemId    = idParams[idParams.Length - 1];
            string   projectId = idParams[idParams.Length - 3];
            var      versions  = await itemsApi.GetItemVersionsAsync(projectId, itemId);

            foreach (KeyValuePair <string, dynamic> version in new DynamicDictionaryItems(versions.data))
            {
                DateTime versionDate = version.Value.attributes.lastModifiedTime;
                string   urn         = string.Empty;
                try
                {
                    urn = (string)version.Value.relationships.derivatives.data.id;
                }
                catch
                {
                    urn = "not_available";
                }
                jsTreeNode node = new jsTreeNode(urn, versionDate.ToString("dd/MM/yy HH:mm:ss"), "versions", false);
                nodes.Add(node);
            }
            return(nodes);
        }
        private async Task CreateItemVersion(string projectId, string folderId, string fileName, string storageId)
        {
            FoldersApi foldersApi     = new FoldersApi();
            var        folderContents = await foldersApi.GetFolderContentsAsync(projectId, folderId);

            var folderData = new DynamicDictionaryItems(folderContents.data);

            string itemId = string.Empty;

            foreach (KeyValuePair <string, dynamic> item in folderData)
            {
                if (item.Value.attributes.displayName == fileName)
                {
                    itemId = item.Value.id; // this means a file with same name is already there, so we'll create a new version
                }
            }
            if (string.IsNullOrWhiteSpace(itemId))
            {
                // create a new item
                BaseAttributesExtensionObject        baseAttribute                   = new BaseAttributesExtensionObject(projectId.StartsWith("a.") ? "items:autodesk.core:File" : "items:autodesk.bim360:File", "1.0");
                CreateItemDataAttributes             createItemAttributes            = new CreateItemDataAttributes(fileName, baseAttribute);
                CreateItemDataRelationshipsTipData   createItemRelationshipsTipData  = new CreateItemDataRelationshipsTipData(CreateItemDataRelationshipsTipData.TypeEnum.Versions, CreateItemDataRelationshipsTipData.IdEnum._1);
                CreateItemDataRelationshipsTip       createItemRelationshipsTip      = new CreateItemDataRelationshipsTip(createItemRelationshipsTipData);
                StorageRelationshipsTargetData       storageTargetData               = new StorageRelationshipsTargetData(StorageRelationshipsTargetData.TypeEnum.Folders, folderId);
                CreateStorageDataRelationshipsTarget createStorageRelationshipTarget = new CreateStorageDataRelationshipsTarget(storageTargetData);
                CreateItemDataRelationships          createItemDataRelationhips      = new CreateItemDataRelationships(createItemRelationshipsTip, createStorageRelationshipTarget);
                CreateItemData createItemData = new CreateItemData(CreateItemData.TypeEnum.Items, createItemAttributes, createItemDataRelationhips);
                BaseAttributesExtensionObject      baseAttExtensionObj = new BaseAttributesExtensionObject(projectId.StartsWith("a.") ? "versions:autodesk.core:File" : "versions:autodesk.bim360:File", "1.0");
                CreateStorageDataAttributes        storageDataAtt      = new CreateStorageDataAttributes(fileName, baseAttExtensionObj);
                CreateItemRelationshipsStorageData createItemRelationshipsStorageData = new CreateItemRelationshipsStorageData(CreateItemRelationshipsStorageData.TypeEnum.Objects, storageId);
                CreateItemRelationshipsStorage     createItemRelationshipsStorage     = new CreateItemRelationshipsStorage(createItemRelationshipsStorageData);
                CreateItemRelationships            createItemRelationship             = new CreateItemRelationships(createItemRelationshipsStorage);
                CreateItemIncluded includedVersion = new CreateItemIncluded(CreateItemIncluded.TypeEnum.Versions, CreateItemIncluded.IdEnum._1, storageDataAtt, createItemRelationship);
                CreateItem         createItem      = new CreateItem(new JsonApiVersionJsonapi(JsonApiVersionJsonapi.VersionEnum._0), createItemData, new List <CreateItemIncluded>()
                {
                    includedVersion
                });

                ItemsApi itemsApi = new ItemsApi();
                var      newItem  = await itemsApi.PostItemAsync(projectId, createItem);
            }
            else
            {
                // create a new version
                BaseAttributesExtensionObject          attExtensionObj              = new BaseAttributesExtensionObject(projectId.StartsWith("a.") ? "versions:autodesk.core:File" : "versions:autodesk.bim360:File", "1.0");
                CreateStorageDataAttributes            storageDataAtt               = new CreateStorageDataAttributes(fileName, attExtensionObj);
                CreateVersionDataRelationshipsItemData dataRelationshipsItemData    = new CreateVersionDataRelationshipsItemData(CreateVersionDataRelationshipsItemData.TypeEnum.Items, itemId);
                CreateVersionDataRelationshipsItem     dataRelationshipsItem        = new CreateVersionDataRelationshipsItem(dataRelationshipsItemData);
                CreateItemRelationshipsStorageData     itemRelationshipsStorageData = new CreateItemRelationshipsStorageData(CreateItemRelationshipsStorageData.TypeEnum.Objects, storageId);
                CreateItemRelationshipsStorage         itemRelationshipsStorage     = new CreateItemRelationshipsStorage(itemRelationshipsStorageData);
                CreateVersionDataRelationships         dataRelationships            = new CreateVersionDataRelationships(dataRelationshipsItem, itemRelationshipsStorage);
                CreateVersionData versionData    = new CreateVersionData(CreateVersionData.TypeEnum.Versions, storageDataAtt, dataRelationships);
                CreateVersion     newVersionData = new CreateVersion(new JsonApiVersionJsonapi(JsonApiVersionJsonapi.VersionEnum._0), versionData);

                VersionsApi versionsApis = new VersionsApi();
                dynamic     newVersion   = await versionsApis.PostVersionAsync(projectId, newVersionData);
            }
        }
示例#7
0
        public static void Mainext()
        {
            Configuration config = new Configuration();

            config.BasePath = "https://api.mercadolibre.com";
            // Configure OAuth2 access token for authorization: oAuth2AuthCode
            config.AccessToken = "YOUR_ACCESS_TOKEN";

            var apiInstance = new ItemsApi(config);
            var accessToken = "accessToken_example";  // string |
            // List<ItemPictures> pictures = new List<ItemPictures>();
            // pictures.Add(new ItemPictures() {
            //     Source = "https://http2.mlstatic.com/storage/developers-site-cms-admin/openapi/319968615067-mp3.jpg"});
            // List<AttributesValues> attrValues = new List<AttributesValues>();
            // attrValues.Add(new AttributesValues() {
            // Name = "8 GB",
            // });
            // List<Attributes> attributes = new List<Attributes>();
            // attributes.Add(new Attributes() {
            //     Id = "DATA_STORAGE_CAPACITY",
            //     Name = "Capacidad de almacenamiento de datos",
            //     ValueName = "8 GB",
            //     Values = attrValues,
            //     AttributeGroupId = "OTHERS",
            //     AttributeGroupName = "Otros",
            // });
            var item = new Item(
                // "Item de test - No Ofertar",
                // "MLA5991",
                // 350,
                // "ARS",
                // 12,
                // "buy_it_now",
                // "bronze",
                // "new",
                // "Item de Teste. Mercado Livre SDK",
                // "RXWn6kftTHY",
                // "12 month",
                // pictures,
                // atributtes
                ); // Item |

            try
            {
                // Create a Item.
                apiInstance.ItemsPost(accessToken, item);
            }
            catch (ApiException e)
            {
                Debug.Print("Exception when calling ItemsApi.ItemsPost: " + e.Message);
                Debug.Print("Status Code: " + e.ErrorCode);
                Debug.Print(e.StackTrace);
            }
        }
示例#8
0
        private async Task <dynamic> PreWorkNewVersion(string userAccessToken, string projectId, string versionId)
        {
            // get version
            VersionsApi versionApi = new VersionsApi();

            versionApi.Configuration.AccessToken = userAccessToken;
            dynamic versionItem = await versionApi.GetVersionItemAsync(projectId, versionId);

            // get item
            ItemsApi itemApi = new ItemsApi();

            itemApi.Configuration.AccessToken = userAccessToken;
            string  itemId = versionItem.data.id;
            dynamic item   = await itemApi.GetItemAsync(projectId, itemId);

            string folderId = item.data.relationships.parent.data.id;
            string fileName = item.data.attributes.displayName;

            // prepare storage
            ProjectsApi projectApi = new ProjectsApi();

            projectApi.Configuration.AccessToken = userAccessToken;
            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(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('/');
            string[] bucketKeyParams = storageIdParams[storageIdParams.Length - 2].Split(':');
            string   bucketKey       = bucketKeyParams[bucketKeyParams.Length - 1];
            string   objectName      = storageIdParams[storageIdParams.Length - 1];

            string uploadUrl = string.Format("https://developer.api.autodesk.com/oss/v2/buckets/{0}/objects/{1}", bucketKey, objectName);

            return(new StorageInfo
            {
                fileName = fileName,
                itemId = item.data.id,
                storageId = storageCreated.data.id,
                uploadUrl = uploadUrl
            });
        }
示例#9
0
        public async Task <string> GetFolderId(string projectId, string versionId, string userAccessToken)
        {
            VersionsApi versionApi = new VersionsApi();

            versionApi.Configuration.AccessToken = userAccessToken;
            dynamic versionItem = await versionApi.GetVersionItemAsync(projectId, versionId);

            string itemId = versionItem.data.id;

            ItemsApi itemApi = new ItemsApi();

            itemApi.Configuration.AccessToken = userAccessToken;
            dynamic item = await itemApi.GetItemAsync(projectId, itemId);

            string folderId = item.data.relationships.parent.data.id;;

            return(folderId);
        }
示例#10
0
        public static void Mainext()
        {
            Configuration config = new Configuration();

            config.BasePath = "https://api.mercadolibre.com";
            var apiInstance = new ItemsApi(config);
            var id          = "id_example"; // string |

            try
            {
                // Return a Item.
                apiInstance.ItemsIdGet(id);
                // To see output in console
                //Console.Write("Resultado get:" + apiInstance.ItemsIdGetWithHttpInfo(id).Data);
            }
            catch (ApiException e)
            {
                Debug.Print("Exception when calling ItemsApi.ItemsIdGet: " + e.Message);
                Debug.Print("Status Code: " + e.ErrorCode);
                Debug.Print(e.StackTrace);
            }
        }
示例#11
0
        public async Task <IList <Item> > GetItemVersionsAsync(string projectId, string itemId)
        {
            string sessionId, localId;

            if (!HeaderUtils.GetSessionLocalIDs(out sessionId, out localId))
            {
                return(null);
            }
            if (!await OAuthDB.IsSessionIdValid(sessionId, localId))
            {
                return(null);
            }
            string userAccessToken = await OAuthDB.GetAccessToken(sessionId, localId);

            IList <Item> versionsList = new List <Item>();

            ItemsApi itemsApi = new ItemsApi();

            itemsApi.Configuration.AccessToken = userAccessToken;
            var versions = await itemsApi.GetItemVersionsAsync(projectId, itemId);

            foreach (KeyValuePair <string, dynamic> version in new DynamicDictionaryItems(versions.data))
            {
                DateTime versionDate = version.Value.attributes.lastModifiedTime;

                string urn = string.Empty;
                try { urn = (string)version.Value.relationships.derivatives.data.id; }
                catch { urn = "not_available"; } // some BIM 360 versions don't have viewable

                Item itemNode = new Item("/versions/" + urn, versionDate.ToString("dd/MM/yy HH:mm:ss"), "versions");

                versionsList.Add(itemNode);
            }

            return(versionsList);
        }
示例#12
0
        private async Task <IList <jsTreeNode> > GetItemVersions(string href)
        {
            IList <jsTreeNode> nodes = new List <jsTreeNode>();

            // the API SDK
            ItemsApi itemApi = new ItemsApi();

            itemApi.Configuration.AccessToken = Credentials.TokenInternal;

            DerivativesApi derivativesApi = new DerivativesApi();

            derivativesApi.Configuration.AccessToken = Credentials.TokenInternal;

            // extract the projectId & itemId from the href
            string[] idParams  = href.Split('/');
            string   itemId    = idParams[idParams.Length - 1];
            string   projectId = idParams[idParams.Length - 3];

            var versions = await itemApi.GetItemVersionsAsync(projectId, itemId);

            foreach (KeyValuePair <string, dynamic> version in new DynamicDictionaryItems(versions.data))
            {
                DateTime versionDate = version.Value.attributes.lastModifiedTime;
                string   verId       = version.Value.id;
                string   verNum      = version.Value.id.Split("=")[1];
                string   userName    = version.Value.attributes.lastModifiedUserName;

                string urn = string.Empty;
                try {
                    urn = (string)version.Value.relationships.derivatives.data.id;

                    dynamic manifestData = await derivativesApi.GetManifestAsync(urn);

                    foreach (KeyValuePair <string, dynamic> manifestParam in new DynamicDictionaryItems(manifestData))
                    {
                        if (manifestParam.Key == "derivatives")
                        {
                            foreach (KeyValuePair <string, dynamic> manifestDerivativeParam in new DynamicDictionaryItems(manifestParam.Value[0]))
                            {
                                if (manifestDerivativeParam.Key == "children")
                                {
                                    foreach (KeyValuePair <string, dynamic> manifestDerivativeChildrenParam in new DynamicDictionaryItems(manifestDerivativeParam.Value))
                                    {
                                        string roomManifestStr = Convert.ToString(manifestDerivativeChildrenParam.Value);

                                        //string roomManifestStrJson = roomManifestStr.Substring(1, roomManifestStr.Length - 2);

                                        RoomManifestChildren deserializedRoomManifest = JsonConvert.DeserializeObject <RoomManifestChildren>(roomManifestStr);

                                        if (deserializedRoomManifest.Role == "3d" && deserializedRoomManifest.Status == ManifestChildren.StatusEnum.Success)
                                        {
                                            if (deserializedRoomManifest.PhaseNames != null)
                                            {
                                                jsTreeNode phaseNode = new jsTreeNode(
                                                    urn + '|' + deserializedRoomManifest.ViewableId + '/' + projectId + '/' + verId,
                                                    string.Format("v{0}: phase: {1}", verNum, deserializedRoomManifest.PhaseNames),
                                                    "versions",
                                                    false);

                                                nodes.Add(phaseNode);
                                            }
                                        }

                                        //foreach(RoomManifestChildren roomManifestChild in deserializedManifestChildren)
                                        //{
                                        //    if (roomManifestChild.Role == ManifestChildren.RoleEnum._3d && roomManifestChild.Status == ManifestChildren.StatusEnum.Success)
                                        //    {
                                        //        if (roomManifestChild.PhaseNames != null)
                                        //        {
                                        //            jsTreeNode phaseNode = new jsTreeNode(
                                        //                    urn + '|' + roomManifestChild.ViewableId + '/' + projectId + '/' + verId,
                                        //                    string.Format("v{0}: {1}", verNum, roomManifestChild.PhaseNames),
                                        //                    "versions",
                                        //                    false);

                                        //            nodes.Add(phaseNode);
                                        //        }
                                        //    }
                                        //}

                                        //if (manifestDerivativeChildParam.Key == "role" && manifestDerivativeChildParam.Value == "3d")
                                        //{
                                        //    if(manifestDerivativeChildParam.Key == "status" && manifestDerivativeChildParam.Value == "success")
                                        //    {
                                        //        if(manifestDerivativeChildParam.Key == "phaseNames")
                                        //        {
                                        //            jsTreeNode phaseNode = new jsTreeNode(
                                        //                urn + '|' + manifestDerivativeChildParam.Value.viewableID + '/' + projectId + '/' + verId,
                                        //                string.Format("v{0}: {1}", verNum, manifestDerivativeChildParam.Value),
                                        //                "versions",
                                        //                false);

                                        //            nodes.Add(phaseNode);
                                        //        }
                                        //    }
                                        //}
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex) {
                    string message = ex.Message;
                    urn = Base64Encode(version.Value.id);
                } // some BIM 360 versions don't have viewable

                jsTreeNode node = new jsTreeNode(
                    urn + '/' + projectId + '/' + verId,
                    string.Format("v{0}: {1} by {2}", verNum, versionDate.ToString("dd/MM/yy HH:mm:ss"), userName),
                    "versions",
                    false);
                nodes.Add(node);
            }



            return(nodes);
        }
示例#13
0
 public ItemsApiTests()
 {
     instance = new ItemsApi();
 }
示例#14
0
            public static async Task UploadAsync()
            {
                ProjectsApi projectsApi = new ProjectsApi();

                StorageRelationshipsTargetData       storageRelData = new StorageRelationshipsTargetData(StorageRelationshipsTargetData.TypeEnum.Folders, "urn:adsk.wipprod:fs.folder:co.OoAFTIjQTdCEF2HJUjee0g");
                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("test", attributes);
                CreateStorageData storageData    = new CreateStorageData(CreateStorageData.TypeEnum.Objects, storageAtt, storageRel);
                CreateStorage     storage        = new CreateStorage(new JsonApiVersionJsonapi(JsonApiVersionJsonapi.VersionEnum._0), storageData);
                dynamic           storageCreated = await projectsApi.PostStorageAsync("3b5c6352-cf34-41fd-a0e9-a5246d93bf55", storage);

                string[] storageIdParams = ((string)storageCreated.data.id).Split('/');
                string[] bucketKeyParams = storageIdParams[storageIdParams.Length - 2].Split(':');
                string   bucketKey       = bucketKeyParams[bucketKeyParams.Length - 1];
                string   objectName      = storageIdParams[storageIdParams.Length - 1];

                ObjectsApi objects = new ObjectsApi();

                objects.Configuration.AccessToken = token;

                long fileSize = (new FileInfo(@"C:\Users\joao.martins\Desktop\ESGOTO_R2.rvt")).Length;

                if (fileSize > 5 * 1024 * 1024)            // upload in chunks if > 5Mb
                {
                    long chunkSize      = 2 * 1024 * 1024; // 2 Mb
                    long numberOfChunks = (long)Math.Round((double)(fileSize / chunkSize)) + 1;

                    long start = 0;
                    chunkSize = (numberOfChunks > 1 ? chunkSize : fileSize);
                    long   end       = chunkSize;
                    string sessionId = Guid.NewGuid().ToString();

                    // upload one chunk at a time
                    using (BinaryReader reader = new BinaryReader(new FileStream(@"C:\Users\joao.martins\Desktop\ESGOTO_R2.rvt", FileMode.Open)))
                    {
                        for (int chunkIndex = 0; chunkIndex < numberOfChunks; chunkIndex++)
                        {
                            string range = string.Format("bytes {0}-{1}/{2}", start, end, fileSize);

                            long         numberOfBytes = chunkSize + 1;
                            byte[]       fileBytes     = new byte[numberOfBytes];
                            MemoryStream memoryStream  = new MemoryStream(fileBytes);
                            reader.BaseStream.Seek((int)start, SeekOrigin.Begin);
                            int count = reader.Read(fileBytes, 0, (int)numberOfBytes);
                            memoryStream.Write(fileBytes, 0, (int)numberOfBytes);
                            memoryStream.Position = 0;

                            await objects.UploadChunkAsync(bucketKey, objectName, (int)numberOfBytes, range, sessionId, memoryStream);

                            start     = end + 1;
                            chunkSize = ((start + chunkSize > fileSize) ? fileSize - start - 1 : chunkSize);
                            end       = start + chunkSize;
                        }
                    }
                }
                else // upload in a single call
                {
                    using (StreamReader streamReader = new StreamReader(@"C:\Users\joao.martins\Desktop\ESGOTO_R2.rvt"))
                    {
                        await objects.UploadObjectAsync(bucketKey, objectName, (int)streamReader.BaseStream.Length, streamReader.BaseStream, "application/octet-stream");
                    }
                }

                // check if file already exists...
                FoldersApi folderApi = new FoldersApi();

                folderApi.Configuration.AccessToken = token;
                var filesInFolder = await folderApi.GetFolderContentsAsync("3b5c6352-cf34-41fd-a0e9-a5246d93bf55", "urn:adsk.wipprod:fs.folder:co.OoAFTIjQTdCEF2HJUjee0g");

                string itemId = string.Empty;

                foreach (KeyValuePair <string, dynamic> item in new DynamicDictionaryItems(filesInFolder.data))
                {
                    if (item.Value.attributes.displayName == "test")
                    {
                        itemId = item.Value.id; // this means a file with same name is already there, so we'll create a new version
                    }
                }
                // now decide whether create a new item or new version
                if (string.IsNullOrWhiteSpace(itemId))
                {
                    // create a new item
                    BaseAttributesExtensionObject        baseAttribute                   = new BaseAttributesExtensionObject("3b5c6352-cf34-41fd-a0e9-a5246d93bf55".StartsWith("a.") ? "items:autodesk.core:File" : "items:autodesk.bim360:File", "1.0");
                    CreateItemDataAttributes             createItemAttributes            = new CreateItemDataAttributes("test", baseAttribute);
                    CreateItemDataRelationshipsTipData   createItemRelationshipsTipData  = new CreateItemDataRelationshipsTipData(CreateItemDataRelationshipsTipData.TypeEnum.Versions, CreateItemDataRelationshipsTipData.IdEnum._1);
                    CreateItemDataRelationshipsTip       createItemRelationshipsTip      = new CreateItemDataRelationshipsTip(createItemRelationshipsTipData);
                    StorageRelationshipsTargetData       storageTargetData               = new StorageRelationshipsTargetData(StorageRelationshipsTargetData.TypeEnum.Folders, "urn:adsk.wipprod:fs.folder:co.OoAFTIjQTdCEF2HJUjee0g");
                    CreateStorageDataRelationshipsTarget createStorageRelationshipTarget = new CreateStorageDataRelationshipsTarget(storageTargetData);
                    CreateItemDataRelationships          createItemDataRelationhips      = new CreateItemDataRelationships(createItemRelationshipsTip, createStorageRelationshipTarget);
                    CreateItemData createItemData = new CreateItemData(CreateItemData.TypeEnum.Items, createItemAttributes, createItemDataRelationhips);
                    BaseAttributesExtensionObject      baseAttExtensionObj = new BaseAttributesExtensionObject("3b5c6352-cf34-41fd-a0e9-a5246d93bf55".StartsWith("a.") ? "versions:autodesk.core:File" : "versions:autodesk.bim360:File", "1.0");
                    CreateStorageDataAttributes        storageDataAtt      = new CreateStorageDataAttributes("test", baseAttExtensionObj);
                    CreateItemRelationshipsStorageData createItemRelationshipsStorageData = new CreateItemRelationshipsStorageData(CreateItemRelationshipsStorageData.TypeEnum.Objects, storageCreated.data.id);
                    CreateItemRelationshipsStorage     createItemRelationshipsStorage     = new CreateItemRelationshipsStorage(createItemRelationshipsStorageData);
                    CreateItemRelationships            createItemRelationship             = new CreateItemRelationships(createItemRelationshipsStorage);
                    CreateItemIncluded includedVersion = new CreateItemIncluded(CreateItemIncluded.TypeEnum.Versions, CreateItemIncluded.IdEnum._1, storageDataAtt, createItemRelationship);
                    CreateItem         createItem      = new CreateItem(new JsonApiVersionJsonapi(JsonApiVersionJsonapi.VersionEnum._0), createItemData, new List <CreateItemIncluded>()
                    {
                        includedVersion
                    });

                    ItemsApi itemsApi = new ItemsApi();
                    itemsApi.Configuration.AccessToken = token;
                    var newItem = await itemsApi.PostItemAsync("3b5c6352-cf34-41fd-a0e9-a5246d93bf55", createItem);
                }
                else
                {
                    // create a new version
                    BaseAttributesExtensionObject          attExtensionObj              = new BaseAttributesExtensionObject("3b5c6352-cf34-41fd-a0e9-a5246d93bf55".StartsWith("a.") ? "versions:autodesk.core:File" : "versions:autodesk.bim360:File", "1.0");
                    CreateStorageDataAttributes            storageDataAtt               = new CreateStorageDataAttributes("test", attExtensionObj);
                    CreateVersionDataRelationshipsItemData dataRelationshipsItemData    = new CreateVersionDataRelationshipsItemData(CreateVersionDataRelationshipsItemData.TypeEnum.Items, itemId);
                    CreateVersionDataRelationshipsItem     dataRelationshipsItem        = new CreateVersionDataRelationshipsItem(dataRelationshipsItemData);
                    CreateItemRelationshipsStorageData     itemRelationshipsStorageData = new CreateItemRelationshipsStorageData(CreateItemRelationshipsStorageData.TypeEnum.Objects, storageCreated.data.id);
                    CreateItemRelationshipsStorage         itemRelationshipsStorage     = new CreateItemRelationshipsStorage(itemRelationshipsStorageData);
                    CreateVersionDataRelationships         dataRelationships            = new CreateVersionDataRelationships(dataRelationshipsItem, itemRelationshipsStorage);
                    CreateVersionData versionData    = new CreateVersionData(CreateVersionData.TypeEnum.Versions, storageDataAtt, dataRelationships);
                    CreateVersion     newVersionData = new CreateVersion(new JsonApiVersionJsonapi(JsonApiVersionJsonapi.VersionEnum._0), versionData);

                    VersionsApi versionsApis = new VersionsApi();
                    versionsApis.Configuration.AccessToken = token;
                    dynamic newVersion = await versionsApis.PostVersionAsync("3b5c6352-cf34-41fd-a0e9-a5246d93bf55", newVersionData);
                }
            }
示例#15
0
        public async Task <IActionResult> StartWorkItem([FromForm] StartWorkitemInput input)
        //public async Task<IActionResult> StartWorkItem(string id)
        {
            // OAuth token
            //
            Credentials credentials = await Credentials.FromSessionAsync(base.Request.Cookies, Response.Cookies);

            string id = $"https://developer.api.autodesk.com/data/v1/projects/b.9f77180c-7cd1-40d8-9d70-d80608dfdfd9/items/urn:adsk.wipprod:dm.lineage:SXwSwlsTT_GkrOQ3GXtDUA";
            // extract the projectId & itemId from the href
            ItemsApi itemApi = new ItemsApi();

            itemApi.Configuration.AccessToken = credentials.TokenInternal;
            string[] idParams  = id.Split('/');
            string   itemId    = idParams[idParams.Length - 1];
            string   projectId = idParams[idParams.Length - 3];
            dynamic  item      = await itemApi.GetItemAsync(projectId, itemId);

            List <int?> filterVersionNumber = new List <int?>()
            {
                1
            };
            var versions = await itemApi.GetItemVersionsAsync(projectId, itemId);

            string folderId        = item.data.relationships.parent.data.id;
            string displayFileName = item.data.attributes.displayName;
            string versionId       = null;

            foreach (KeyValuePair <string, dynamic> version in new DynamicDictionaryItems(versions.data))
            {
                DateTime versionDate = version.Value.attributes.lastModifiedTime;
                string   verNum      = version.Value.id.Split("=")[1];
                string   userName    = version.Value.attributes.lastModifiedUserName;
                versionId = version.Value.id;
                string urn = string.Empty;
                try { urn = (string)version.Value.relationships.derivatives.data.id; }
                catch { }
            }
            //

            // basic input validation
            JObject workItemData       = JObject.Parse(input.data);
            string  widthParam         = workItemData["width"].Value <string>();
            string  heigthParam        = workItemData["height"].Value <string>();
            string  activityName       = string.Format("{0}.{1}", NickName, workItemData["activityName"].Value <string>());
            string  browerConnectionId = workItemData["browerConnectionId"].Value <string>();

            // save the file on the server
            var fileSavePath = Path.Combine(_env.ContentRootPath, Path.GetFileName(input.inputFile.FileName));

            using (var stream = new FileStream(fileSavePath, FileMode.Create)) await input.inputFile.CopyToAsync(stream);



            // upload file to OSS Bucket
            // 1. ensure bucket existis
            string     bucketKey = NickName.ToLower() + "_designautomation";
            BucketsApi buckets   = new BucketsApi();

            buckets.Configuration.AccessToken = credentials.TokenInternal;
            try
            {
                PostBucketsPayload bucketPayload = new PostBucketsPayload(bucketKey, null, PostBucketsPayload.PolicyKeyEnum.Transient);
                await buckets.CreateBucketAsync(bucketPayload, "US");
            }
            catch { };                                                                                                                                         // in case bucket already exists
                                                                                                                                                               // 2. upload inputFile
            string     inputFileNameOSS = string.Format("{0}_input_{1}", DateTime.Now.ToString("yyyyMMddhhmmss"), Path.GetFileName(input.inputFile.FileName)); // avoid overriding
            ObjectsApi objects          = new ObjectsApi();

            objects.Configuration.AccessToken = credentials.TokenInternal;
            using (StreamReader streamReader = new StreamReader(fileSavePath))
                await objects.UploadObjectAsync(bucketKey, inputFileNameOSS, (int)streamReader.BaseStream.Length, streamReader.BaseStream, "application/octet-stream");
            System.IO.File.Delete(fileSavePath);// delete server copy

            // prepare workitem arguments
            // 1. input file
            XrefTreeArgument inputFileArgument = new XrefTreeArgument()
            {
                Url     = string.Format("https://developer.api.autodesk.com/oss/v2/buckets/{0}/objects/{1}", bucketKey, inputFileNameOSS),
                Headers = new Dictionary <string, string>()
                {
                    { "Authorization", "Bearer " + credentials.TokenInternal }
                }
            };
            //XrefTreeArgument inputFileArgument = BuildBIM360DownloadURL(oauth.access_token, projectId, versionId);
            // 2. input json
            dynamic inputJson = new JObject();

            inputJson.Width  = widthParam;
            inputJson.Height = heigthParam;
            XrefTreeArgument inputJsonArgument = new XrefTreeArgument()
            {
                Url = "data:application/json, " + ((JObject)inputJson).ToString(Formatting.None).Replace("\"", "'")
            };
            // 3. output file
            string           outputFileNameOSS  = string.Format("{0}_output_{1}", DateTime.Now.ToString("yyyyMMddhhmmss"), Path.GetFileName(input.inputFile.FileName)); // avoid overriding
            XrefTreeArgument outputFileArgument = new XrefTreeArgument()
            {
                Url     = string.Format("https://developer.api.autodesk.com/oss/v2/buckets/{0}/objects/{1}", bucketKey, outputFileNameOSS),
                Verb    = Verb.Put,
                Headers = new Dictionary <string, string>()
                {
                    { "Authorization", "Bearer " + credentials.TokenInternal }
                }
            };

            // prepare & submit workitem
            string   callbackUrl  = string.Format("{0}/api/forge/callback/designautomation?id={1}&outputFileName={2}", OAuthController.GetAppSetting("FORGE_WEBHOOK_URL"), browerConnectionId, outputFileNameOSS);
            WorkItem workItemSpec = new WorkItem()
            {
                ActivityId = activityName,
                Arguments  = new Dictionary <string, IArgument>()
                {
                    { "inputFile", inputFileArgument },
                    { "inputJson", inputJsonArgument },
                    { "outputFile", outputFileArgument },
                    { "onComplete", new XrefTreeArgument {
                          Verb = Verb.Post, Url = callbackUrl
                      } }
                }
            };
            WorkItemStatus workItemStatus = await _designAutomation.CreateWorkItemsAsync(workItemSpec);

            return(Ok(new { WorkItemId = workItemStatus.Id }));
        }
示例#16
0
 public void Init()
 {
     instance = new ItemsApi();
 }
示例#17
0
        /// <summary>
        /// Gets an instance of items API.
        /// </summary>
        /// <returns>ItemsApi object.</returns>
        public ItemsApi GetItemsApi()
        {
            var itemsApi = new ItemsApi(refresh_token, organisationId);

            return(itemsApi);
        }
示例#18
0
        //public async Task<IActionResult> Testing(string id)
        public async Task <IList <jsTreeNode> > Testing1(string id)
        {
            IList <jsTreeNode> nodes = new List <jsTreeNode>();
            // the API SDK
            Credentials credentials = await Credentials.FromSessionAsync(base.Request.Cookies, Response.Cookies);

            ItemsApi itemApi = new ItemsApi();

            itemApi.Configuration.AccessToken = credentials.TokenInternal;

            // extract the projectId & itemId from the href
            string[] idParams  = id.Split('/');
            string   itemId    = idParams[idParams.Length - 1];
            string   projectId = idParams[idParams.Length - 3];

            var versions = await itemApi.GetItemVersionsAsync(projectId, itemId);

            dynamic item = await itemApi.GetItemAsync(projectId, itemId);

            string folderId  = item.data.relationships.parent.data.id;
            string fileName  = item.data.attributes.displayName;
            string versionId = null;

            foreach (KeyValuePair <string, dynamic> version in new DynamicDictionaryItems(versions.data))
            {
                DateTime versionDate = version.Value.attributes.lastModifiedTime;
                string   verNum      = version.Value.id.Split("=")[1];
                string   userName    = version.Value.attributes.lastModifiedUserName;
                versionId = version.Value.id;
                string urn = string.Empty;
                try { urn = (string)version.Value.relationships.derivatives.data.id; }
                catch { }
            }
            // Prepare the DA input from BIM 360
            var input = await BuildBIM360DownloadURL(credentials.TokenInternal, projectId, versionId);

            //var output = await PreWorkNewVersion(credentials.TokenInternal, projectId, versionId);
            // Create a version for this new file
            // prepare storage
            ProjectsApi projectApis = new ProjectsApi();

            projectApis.Configuration.AccessToken = credentials.TokenInternal;
            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(fileName, attributes);
            CreateStorageData storageData    = new CreateStorageData(CreateStorageData.TypeEnum.Objects, storageAtt, storageRel);
            CreateStorage     storage        = new CreateStorage(new JsonApiVersionJsonapi(JsonApiVersionJsonapi.VersionEnum._0), storageData);
            dynamic           storageCreated = await projectApis.PostStorageAsync(projectId, storage);

            VersionsApi versionsApi = new VersionsApi();

            versionsApi.Configuration.AccessToken = credentials.TokenInternal;
            CreateVersion newVersionData = new CreateVersion
                                           (
                new JsonApiVersionJsonapi(JsonApiVersionJsonapi.VersionEnum._0),
                new CreateVersionData
                (
                    CreateVersionData.TypeEnum.Versions,
                    new CreateStorageDataAttributes
                    (
                        fileName,
                        new BaseAttributesExtensionObject
                        (
                            "versions:autodesk.bim360:File",
                            "1.0",
                            new JsonApiLink(string.Empty),
                            null
                        )
                    ),
                    new CreateVersionDataRelationships
                    (
                        new CreateVersionDataRelationshipsItem
                        (
                            new CreateVersionDataRelationshipsItemData
                            (
                                CreateVersionDataRelationshipsItemData.TypeEnum.Items,
                                itemId
                            )
                        ),
                        new CreateItemRelationshipsStorage
                        (
                            new CreateItemRelationshipsStorageData
                            (
                                CreateItemRelationshipsStorageData.TypeEnum.Objects,
                                storageCreated.data.id
                            )
                        )
                    )
                )
                                           );
            dynamic newVersion = await versionsApi.PostVersionAsync(projectId, newVersionData);

            return(nodes);
        }
示例#19
0
        //public async Task<IActionResult> Testing(string id)
        public async Task <IList <jsTreeNode> > Testing(string id)
        {
            IList <jsTreeNode> nodes = new List <jsTreeNode>();
            // the API SDK
            Credentials credentials = await Credentials.FromSessionAsync(base.Request.Cookies, Response.Cookies);

            ItemsApi itemApi = new ItemsApi();

            itemApi.Configuration.AccessToken = credentials.TokenInternal;

            // extract the projectId & itemId from the href
            string[] idParams  = id.Split('/');
            string   itemId    = idParams[idParams.Length - 1];
            string   projectId = idParams[idParams.Length - 3];

            var versions = await itemApi.GetItemVersionsAsync(projectId, itemId);

            dynamic item = await itemApi.GetItemAsync(projectId, itemId);

            string folderId        = item.data.relationships.parent.data.id;
            string displayFileName = item.data.attributes.displayName;
            string versionId       = null;

            foreach (KeyValuePair <string, dynamic> version in new DynamicDictionaryItems(versions.data))
            {
                DateTime versionDate = version.Value.attributes.lastModifiedTime;
                string   verNum      = version.Value.id.Split("=")[1];
                string   userName    = version.Value.attributes.lastModifiedUserName;
                versionId = version.Value.id;
                if (verNum == "1")
                {
                    break;
                }
                string urn = string.Empty;
                try { urn = (string)version.Value.relationships.derivatives.data.id; }
                catch { }
            }
            //get user id
            UserController user = new UserController();

            user.Credentials = credentials;
            dynamic userProfile = await user.GetUserProfileAsync();

            string userId = userProfile.id;
            //// Prepare the DA input from BIM 360
            //var input = await BuildBIM360DownloadURL(credentials.TokenInternal, projectId, versionId);
            //// Prepare the DA output to BIM 360
            //var storageInfo = await PreWorkNewVersion(credentials.TokenInternal, projectId, versionId);
            //string storageId = storageInfo.storageId;
            //string fileName = storageInfo.fileName;
            //try
            //{
            //    BackgroundJob.Schedule(() => PostProcessFile(credentials.TokenInternal, userId, projectId, itemId, storageId, fileName), TimeSpan.FromSeconds(1));
            //}
            //catch (Exception e) { }
            //
            StorageInfo info = await PreWorkNewVersion(credentials.TokenInternal, projectId, versionId);

            string callbackUrl = string.Format("{0}/api/forge/callback/designautomation/revit/{1}/{2}/{3}/{4}/{5}", Credentials.GetAppSetting("FORGE_WEBHOOK_URL"), userId, projectId, info.itemId.Base64Encode(), info.storageId.Base64Encode(), info.fileName.Base64Encode());

            WorkItem workItemSpec = new WorkItem()
            {
                ActivityId = ActivityFullName,
                Arguments  = new Dictionary <string, IArgument>()
                {
                    { "inputFile", await BuildBIM360DownloadURL(credentials.TokenInternal, projectId, versionId) },
                    { "outputFile", await BuildBIM360UploadURL(credentials.TokenInternal, info) },
                    { "onComplete", new XrefTreeArgument {
                          Verb = Verb.Post, Url = callbackUrl
                      } }
                }
            };
            WorkItemStatus workItemStatus = await _designAutomation.CreateWorkItemsAsync(workItemSpec);

            try
            {
                var storageInfo = await PreWorkNewVersion(credentials.TokenInternal, projectId, versionId);

                string storageId = storageInfo.storageId;
                string fileName  = storageInfo.fileName;
                BackgroundJob.Schedule(() => PostProcessFile(credentials.TokenInternal, userId, projectId, itemId, storageId, fileName), TimeSpan.FromSeconds(1));
            }
            catch (Exception e) { }

            //
            return(nodes);
        }
        private async void listItemVersions(MyTreeNode itemNode, bool isForDownload)
        {
            if (itemNode.nodeState == DownloadState.Downloaded ||
                itemNode.nodeState == DownloadState.Downloading)
            {
                if (isForDownload)
                {
                    startDownload((MyTreeNode)itemNode.FirstNode, null);
                }

                return;
            }

            try
            {
                var itemsApi = new ItemsApi();
                itemsApi.Configuration.AccessToken = logInInfo.accessToken;

                string[] idParams  = itemNode.id.Split('/');
                string   itemId    = idParams[idParams.Length - 1];
                string   projectId = idParams[idParams.Length - 3];

                setNodeState(itemNode, true);

                dynamic versions = null;
                while (versions == null)
                {
                    try
                    {
                        versions = await itemsApi.GetItemVersionsAsync(projectId, itemId);
                    }
                    catch (Exception ex)
                    {
                        Debug.Print("startDownload >> catch1 : " + ex.Message);
                        await Task.Delay(kTimeOutDelay);
                    }
                }

                foreach (KeyValuePair <string, dynamic> versionInfo in new DynamicDictionaryItems(versions.data))
                {
                    string nodeType    = versionInfo.Value.attributes.extension.type.EndsWith(":Folder") ? "folder" : "item";
                    string displayName = versionInfo.Value.attributes.displayName;
                    var    fileType    = "";
                    try
                    {
                        fileType = versionInfo.Value.attributes.fileType;
                        string str = "";
                    }
                    catch { }
                    Debug.Print(displayName + " fileType = " + fileType);
                    MyTreeNode versionNode = new MyTreeNode(
                        versionInfo.Value.links.self.href,
                        displayName + " (v" + versionInfo.Value.attributes.versionNumber + ")",
                        versionInfo.Value.attributes.extension.type,
                        fileType,
                        NodeType.Version
                        );
                    versionNode.nodeState = DownloadState.Downloaded;
                    addToTreeView(itemNode, versionNode);

                    // If it's for download then start downloading the latest version
                    // Note: latest version is first in the list
                    if (isForDownload)
                    {
                        startDownload(versionNode, null);
                        isForDownload = false;
                    }
                }
                setNodeState(itemNode, false);
            }
            catch (Exception ex)
            {
                itemNode.nodeState = DownloadState.Failed;
                // maybe we should do this: setNodeState
            }
        }
        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);
        }
示例#22
0
        public async Task <IActionResult> SubmitProject([FromForm] InputSubmit input)
        {
            string projectId = "b.014c6054-6da1-4ed8-b199-1975c07f608a";
            string folderId  = "urn:adsk.wipprod:fs.folder:co.1X3m8NAlRL-xNDQsXk_bxQ";

            Credentials credentials = await Credentials.FromDatabaseAsync(Utils.GetAppSetting("USERID"));

            dynamic token2lo = await OAuthController2L.GetInternalAsync();

            var fileSavePath = Path.Combine(_env.ContentRootPath, input.fileToUpload.FileName);

            using (var stream = new FileStream(fileSavePath, FileMode.Create))
                await input.fileToUpload.CopyToAsync(stream);

            // prepare storage
            ProjectsApi projectApi = new ProjectsApi();

            projectApi.Configuration.AccessToken = credentials.TokenInternal;
            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(input.fileToUpload.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('/');
            string[] bucketKeyParams = storageIdParams[storageIdParams.Length - 2].Split(':');
            string   bucketKey       = bucketKeyParams[bucketKeyParams.Length - 1];
            string   objectName      = storageIdParams[storageIdParams.Length - 1];

            // upload the file/object, which will create a new object
            ObjectsApi objects = new ObjectsApi();

            objects.Configuration.AccessToken = credentials.TokenInternal;

            // get file size
            long fileSize = (new FileInfo(fileSavePath)).Length;

            // decide if upload direct or resumable (by chunks)
            if (fileSize > UPLOAD_CHUNK_SIZE * 1024 * 1024) // upload in chunks
            {
                long chunkSize      = 2 * 1024 * 1024;      // 2 Mb
                long numberOfChunks = (long)Math.Round((double)(fileSize / chunkSize)) + 1;

                long start = 0;
                chunkSize = (numberOfChunks > 1 ? chunkSize : fileSize);
                long   end       = chunkSize;
                string sessionId = Guid.NewGuid().ToString();

                // upload one chunk at a time
                using (BinaryReader reader = new BinaryReader(new FileStream(fileSavePath, FileMode.Open)))
                {
                    for (int chunkIndex = 0; chunkIndex < numberOfChunks; chunkIndex++)
                    {
                        string range = string.Format("bytes {0}-{1}/{2}", start, end, fileSize);

                        long         numberOfBytes = chunkSize + 1;
                        byte[]       fileBytes     = new byte[numberOfBytes];
                        MemoryStream memoryStream  = new MemoryStream(fileBytes);
                        reader.BaseStream.Seek((int)start, SeekOrigin.Begin);
                        int count = reader.Read(fileBytes, 0, (int)numberOfBytes);
                        memoryStream.Write(fileBytes, 0, (int)numberOfBytes);
                        memoryStream.Position = 0;

                        await objects.UploadChunkAsync(bucketKey, objectName, (int)numberOfBytes, range, sessionId, memoryStream);

                        start     = end + 1;
                        chunkSize = ((start + chunkSize > fileSize) ? fileSize - start - 1 : chunkSize);
                        end       = start + chunkSize;
                    }
                }
            }
            else // upload in a single call
            {
                using (StreamReader streamReader = new StreamReader(fileSavePath))
                {
                    await objects.UploadObjectAsync(bucketKey, objectName, (int)streamReader.BaseStream.Length, streamReader.BaseStream, "application/octet-stream");
                }
            }

            // cleanup
            string fileName = input.fileToUpload.FileName;

            System.IO.File.Delete(fileSavePath);

            // check if file already exists...
            FoldersApi folderApi = new FoldersApi();

            folderApi.Configuration.AccessToken = credentials.TokenInternal;
            var filesInFolder = await folderApi.GetFolderContentsAsync(projectId, folderId);

            string itemId = string.Empty;

            foreach (KeyValuePair <string, dynamic> item in new DynamicDictionaryItems(filesInFolder.data))
            {
                if (item.Value.attributes.displayName == fileName)
                {
                    itemId = item.Value.id; // this means a file with same name is already there, so we'll create a new version
                }
            }
            // now decide whether create a new item or new version
            if (string.IsNullOrWhiteSpace(itemId))
            {
                // create a new item
                BaseAttributesExtensionObject        baseAttribute                   = new BaseAttributesExtensionObject(projectId.StartsWith("a.") ? "items:autodesk.core:File" : "items:autodesk.bim360:File", "1.0");
                CreateItemDataAttributes             createItemAttributes            = new CreateItemDataAttributes(fileName, baseAttribute);
                CreateItemDataRelationshipsTipData   createItemRelationshipsTipData  = new CreateItemDataRelationshipsTipData(CreateItemDataRelationshipsTipData.TypeEnum.Versions, CreateItemDataRelationshipsTipData.IdEnum._1);
                CreateItemDataRelationshipsTip       createItemRelationshipsTip      = new CreateItemDataRelationshipsTip(createItemRelationshipsTipData);
                StorageRelationshipsTargetData       storageTargetData               = new StorageRelationshipsTargetData(StorageRelationshipsTargetData.TypeEnum.Folders, folderId);
                CreateStorageDataRelationshipsTarget createStorageRelationshipTarget = new CreateStorageDataRelationshipsTarget(storageTargetData);
                CreateItemDataRelationships          createItemDataRelationhips      = new CreateItemDataRelationships(createItemRelationshipsTip, createStorageRelationshipTarget);
                CreateItemData createItemData = new CreateItemData(CreateItemData.TypeEnum.Items, createItemAttributes, createItemDataRelationhips);
                BaseAttributesExtensionObject      baseAttExtensionObj = new BaseAttributesExtensionObject(projectId.StartsWith("a.") ? "versions:autodesk.core:File" : "versions:autodesk.bim360:File", "1.0");
                CreateStorageDataAttributes        storageDataAtt      = new CreateStorageDataAttributes(fileName, baseAttExtensionObj);
                CreateItemRelationshipsStorageData createItemRelationshipsStorageData = new CreateItemRelationshipsStorageData(CreateItemRelationshipsStorageData.TypeEnum.Objects, storageCreated.data.id);
                CreateItemRelationshipsStorage     createItemRelationshipsStorage     = new CreateItemRelationshipsStorage(createItemRelationshipsStorageData);
                CreateItemRelationships            createItemRelationship             = new CreateItemRelationships(createItemRelationshipsStorage);
                CreateItemIncluded includedVersion = new CreateItemIncluded(CreateItemIncluded.TypeEnum.Versions, CreateItemIncluded.IdEnum._1, storageDataAtt, createItemRelationship);
                CreateItem         createItem      = new CreateItem(new JsonApiVersionJsonapi(JsonApiVersionJsonapi.VersionEnum._0), createItemData, new List <CreateItemIncluded>()
                {
                    includedVersion
                });

                ItemsApi itemsApi = new ItemsApi();
                itemsApi.Configuration.AccessToken = credentials.TokenInternal;
                var newItem = await itemsApi.PostItemAsync(projectId, createItem);

                itemId = newItem.data.id;
            }
            else
            {
                // create a new version
                BaseAttributesExtensionObject          attExtensionObj              = new BaseAttributesExtensionObject(projectId.StartsWith("a.") ? "versions:autodesk.core:File" : "versions:autodesk.bim360:File", "1.0");
                CreateStorageDataAttributes            storageDataAtt               = new CreateStorageDataAttributes(fileName, attExtensionObj);
                CreateVersionDataRelationshipsItemData dataRelationshipsItemData    = new CreateVersionDataRelationshipsItemData(CreateVersionDataRelationshipsItemData.TypeEnum.Items, itemId);
                CreateVersionDataRelationshipsItem     dataRelationshipsItem        = new CreateVersionDataRelationshipsItem(dataRelationshipsItemData);
                CreateItemRelationshipsStorageData     itemRelationshipsStorageData = new CreateItemRelationshipsStorageData(CreateItemRelationshipsStorageData.TypeEnum.Objects, storageCreated.data.id);
                CreateItemRelationshipsStorage         itemRelationshipsStorage     = new CreateItemRelationshipsStorage(itemRelationshipsStorageData);
                CreateVersionDataRelationships         dataRelationships            = new CreateVersionDataRelationships(dataRelationshipsItem, itemRelationshipsStorage);
                CreateVersionData versionData    = new CreateVersionData(CreateVersionData.TypeEnum.Versions, storageDataAtt, dataRelationships);
                CreateVersion     newVersionData = new CreateVersion(new JsonApiVersionJsonapi(JsonApiVersionJsonapi.VersionEnum._0), versionData);

                VersionsApi versionsApis = new VersionsApi();
                versionsApis.Configuration.AccessToken = credentials.TokenInternal;
                dynamic newVersion = await versionsApis.PostVersionAsync(projectId, newVersionData);
            }

            await NotificationDB.Register(itemId, input.phoneNumber);

            return(Ok());
        }
        //public async Task<dynamic> UploadObject([FromForm]UploadFile input)
        public async Task <dynamic> UploadObject(Stream input)//mb
        {
            // get the uploaded file and save on the server

            /*mb var fileSavePath = Path.Combine(_env.ContentRootPath, input.fileToUpload.FileName);
             * using (var stream = new FileStream(fileSavePath, FileMode.Create))
             *  await input.fileToUpload.CopyToAsync(stream); mb*/

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

            // extract projectId and folderId from folderHref

            /*mb string[] hrefParams = input.folderHref.Split("/");
             * string projectId = hrefParams[hrefParams.Length - 3];
             * string folderId = hrefParams[hrefParams.Length - 1]; mb*/
            string projectId = "3be23c1c-1383-440a-b395-ac5933f797a1";
            string folderId  = "urn:adsk.wipprod:fs.folder:co.-w2D5-voTQiB-6-aowONzg";
            string fileName  = "result.ifc";

            // prepare storage
            ProjectsApi projectApi = new ProjectsApi();

            projectApi.Configuration.AccessToken = Credentials.TokenInternal;
            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);
            //mb CreateStorageDataAttributes storageAtt = new CreateStorageDataAttributes(input.fileToUpload.FileName, attributes);
            CreateStorageDataAttributes storageAtt  = new CreateStorageDataAttributes(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('/');
            string[] bucketKeyParams = storageIdParams[storageIdParams.Length - 2].Split(':');
            string   bucketKey       = bucketKeyParams[bucketKeyParams.Length - 1];
            string   objectName      = storageIdParams[storageIdParams.Length - 1];

            // upload the file/object, which will create a new object
            ObjectsApi objects = new ObjectsApi();

            objects.Configuration.AccessToken = Credentials.TokenInternal;

            // get file size
            //mb long fileSize = (new FileInfo(fileSavePath)).Length;
            long fileSize = 10;

            // decide if upload direct or resumable (by chunks)
            if (fileSize > UPLOAD_CHUNK_SIZE * 1024 * 1024) // upload in chunks
            {
                /*mb long chunkSize = 2 * 1024 * 1024; // 2 Mb
                 * long numberOfChunks = (long)Math.Round((double)(fileSize / chunkSize)) + 1;
                 *
                 * long start = 0;
                 * chunkSize = (numberOfChunks > 1 ? chunkSize : fileSize);
                 * long end = chunkSize;
                 * string sessionId = Guid.NewGuid().ToString();
                 *
                 * // upload one chunk at a time
                 * using (BinaryReader reader = new BinaryReader(new FileStream(fileSavePath, FileMode.Open)))
                 * {
                 *  for (int chunkIndex = 0; chunkIndex < numberOfChunks; chunkIndex++)
                 *  {
                 *      string range = string.Format("bytes {0}-{1}/{2}", start, end, fileSize);
                 *
                 *      long numberOfBytes = chunkSize + 1;
                 *      byte[] fileBytes = new byte[numberOfBytes];
                 *      MemoryStream memoryStream = new MemoryStream(fileBytes);
                 *      reader.BaseStream.Seek((int)start, SeekOrigin.Begin);
                 *      int count = reader.Read(fileBytes, 0, (int)numberOfBytes);
                 *      memoryStream.Write(fileBytes, 0, (int)numberOfBytes);
                 *      memoryStream.Position = 0;
                 *
                 *      await objects.UploadChunkAsync(bucketKey, objectName, (int)numberOfBytes, range, sessionId, memoryStream);
                 *
                 *      start = end + 1;
                 *      chunkSize = ((start + chunkSize > fileSize) ? fileSize - start - 1 : chunkSize);
                 *      end = start + chunkSize;
                 *  }
                 * } mb*/
            }
            else // upload in a single call
            {
                /*mb using (StreamReader streamReader = new StreamReader(fileSavePath))
                 * {
                 *   await objects.UploadObjectAsync(bucketKey, objectName, (int)streamReader.BaseStream.Length, streamReader.BaseStream, "application/octet-stream");
                 * } mb*/
                await objects.UploadObjectAsync(bucketKey, objectName, (int)input.Length, input, "application/octet-stream");
            }

            // cleanup

            /*mb string fileName = input.fileToUpload.FileName;
             * System.IO.File.Delete(fileSavePath); mb*/

            // check if file already exists...
            FoldersApi folderApi = new FoldersApi();

            folderApi.Configuration.AccessToken = Credentials.TokenInternal;
            var filesInFolder = await folderApi.GetFolderContentsAsync(projectId, folderId);

            string itemId = string.Empty;

            foreach (KeyValuePair <string, dynamic> item in new DynamicDictionaryItems(filesInFolder.data))
            {
                if (item.Value.attributes.displayName == fileName)
                {
                    itemId = item.Value.id; // this means a file with same name is already there, so we'll create a new version
                }
            }
            // now decide whether create a new item or new version
            if (string.IsNullOrWhiteSpace(itemId))
            {
                // create a new item
                BaseAttributesExtensionObject        baseAttribute                   = new BaseAttributesExtensionObject(projectId.StartsWith("a.") ? "items:autodesk.core:File" : "items:autodesk.bim360:File", "1.0");
                CreateItemDataAttributes             createItemAttributes            = new CreateItemDataAttributes(fileName, baseAttribute);
                CreateItemDataRelationshipsTipData   createItemRelationshipsTipData  = new CreateItemDataRelationshipsTipData(CreateItemDataRelationshipsTipData.TypeEnum.Versions, CreateItemDataRelationshipsTipData.IdEnum._1);
                CreateItemDataRelationshipsTip       createItemRelationshipsTip      = new CreateItemDataRelationshipsTip(createItemRelationshipsTipData);
                StorageRelationshipsTargetData       storageTargetData               = new StorageRelationshipsTargetData(StorageRelationshipsTargetData.TypeEnum.Folders, folderId);
                CreateStorageDataRelationshipsTarget createStorageRelationshipTarget = new CreateStorageDataRelationshipsTarget(storageTargetData);
                CreateItemDataRelationships          createItemDataRelationhips      = new CreateItemDataRelationships(createItemRelationshipsTip, createStorageRelationshipTarget);
                CreateItemData createItemData = new CreateItemData(CreateItemData.TypeEnum.Items, createItemAttributes, createItemDataRelationhips);
                BaseAttributesExtensionObject      baseAttExtensionObj = new BaseAttributesExtensionObject(projectId.StartsWith("a.") ? "versions:autodesk.core:File" : "versions:autodesk.bim360:File", "1.0");
                CreateStorageDataAttributes        storageDataAtt      = new CreateStorageDataAttributes(fileName, baseAttExtensionObj);
                CreateItemRelationshipsStorageData createItemRelationshipsStorageData = new CreateItemRelationshipsStorageData(CreateItemRelationshipsStorageData.TypeEnum.Objects, storageCreated.data.id);
                CreateItemRelationshipsStorage     createItemRelationshipsStorage     = new CreateItemRelationshipsStorage(createItemRelationshipsStorageData);
                CreateItemRelationships            createItemRelationship             = new CreateItemRelationships(createItemRelationshipsStorage);
                CreateItemIncluded includedVersion = new CreateItemIncluded(CreateItemIncluded.TypeEnum.Versions, CreateItemIncluded.IdEnum._1, storageDataAtt, createItemRelationship);
                CreateItem         createItem      = new CreateItem(new JsonApiVersionJsonapi(JsonApiVersionJsonapi.VersionEnum._0), createItemData, new List <CreateItemIncluded>()
                {
                    includedVersion
                });

                ItemsApi itemsApi = new ItemsApi();
                itemsApi.Configuration.AccessToken = Credentials.TokenInternal;
                var newItem = await itemsApi.PostItemAsync(projectId, createItem);

                return(newItem);
            }
            else
            {
                // create a new version
                BaseAttributesExtensionObject          attExtensionObj              = new BaseAttributesExtensionObject(projectId.StartsWith("a.") ? "versions:autodesk.core:File" : "versions:autodesk.bim360:File", "1.0");
                CreateStorageDataAttributes            storageDataAtt               = new CreateStorageDataAttributes(fileName, attExtensionObj);
                CreateVersionDataRelationshipsItemData dataRelationshipsItemData    = new CreateVersionDataRelationshipsItemData(CreateVersionDataRelationshipsItemData.TypeEnum.Items, itemId);
                CreateVersionDataRelationshipsItem     dataRelationshipsItem        = new CreateVersionDataRelationshipsItem(dataRelationshipsItemData);
                CreateItemRelationshipsStorageData     itemRelationshipsStorageData = new CreateItemRelationshipsStorageData(CreateItemRelationshipsStorageData.TypeEnum.Objects, storageCreated.data.id);
                CreateItemRelationshipsStorage         itemRelationshipsStorage     = new CreateItemRelationshipsStorage(itemRelationshipsStorageData);
                CreateVersionDataRelationships         dataRelationships            = new CreateVersionDataRelationships(dataRelationshipsItem, itemRelationshipsStorage);
                CreateVersionData versionData    = new CreateVersionData(CreateVersionData.TypeEnum.Versions, storageDataAtt, dataRelationships);
                CreateVersion     newVersionData = new CreateVersion(new JsonApiVersionJsonapi(JsonApiVersionJsonapi.VersionEnum._0), versionData);

                VersionsApi versionsApis = new VersionsApi();
                versionsApis.Configuration.AccessToken = Credentials.TokenInternal;
                dynamic newVersion = await versionsApis.PostVersionAsync(projectId, newVersionData);

                return(newVersion);
            }
        }
示例#24
0
        /// <summary>
        ///     Gets an instance of items API.
        /// </summary>
        /// <returns>ItemsApi object.</returns>
        public ItemsApi GetItemsApi()
        {
            var itemsApi = new ItemsApi(authToken, organisationId);

            return(itemsApi);
        }