From aadce9c910fe0cc4d879127e4f6689bcc6e2de7b Mon Sep 17 00:00:00 2001 From: Chuong Ho Date: Wed, 28 Feb 2024 13:42:19 +0800 Subject: [PATCH] add support BatchReportItemVersion --- APSToolkit/BIM360/BIM360.cs | 55 ++++++++++++++++++++++++++++++++++++ APSToolkitUnit/BIM360Test.cs | 9 ++++++ 2 files changed, 64 insertions(+) diff --git a/APSToolkit/BIM360/BIM360.cs b/APSToolkit/BIM360/BIM360.cs index 0f0b1cd..4eb558f 100644 --- a/APSToolkit/BIM360/BIM360.cs +++ b/APSToolkit/BIM360/BIM360.cs @@ -1734,6 +1734,61 @@ public void BatchExportAllRevitToExcelByFolder(string directory, string projectI { ExportRevitExcelRecursive(directory, projectId, folderId,isRecursive); } + + /// + /// Generates a report of item versions in a specified folder within a project. + /// + /// The unique identifier of the project. + /// The unique identifier of the folder within the project. + /// The file extension to filter items by. Default is ".rvt". + /// A boolean value indicating whether to recursively search subfolders. Default is false. + /// + /// A DataTable containing the report data. Each row represents an item in the folder (and subfolders if isRecursive is true), + /// and includes the project ID, folder ID, item ID, item name, and latest version number. + /// + public DataTable BatchReportItemVersion(string projectId, string folderId,string extenstion=".rvt",bool isRecursive =false) + { + DataTable dataTable = new DataTable(); + dataTable.Columns.Add("ProjectId", typeof(string)); + dataTable.Columns.Add("FolderId", typeof(string)); + dataTable.Columns.Add("ItemName", typeof(string)); + dataTable.Columns.Add("ItemId", typeof(string)); + dataTable.Columns.Add("LatestVersion", typeof(long)); + BatchReportItemVersionRecursive(projectId, folderId,extenstion,ref dataTable,isRecursive); + return dataTable; + } + private void BatchReportItemVersionRecursive(string projectId,string folderId,string extension, ref DataTable dt,bool isRecursive) + { + var foldersApi = new FoldersApi(); + // refresh token + string get2LeggedToken = Auth.Authentication.Get2LeggedToken().Result; + foldersApi.Configuration.AccessToken = get2LeggedToken; + dynamic result = foldersApi.GetFolderContentsAsync(projectId, folderId).Result; + get2LeggedToken = Auth.Authentication.Get2LeggedToken().Result; + foreach (KeyValuePair itemInfo in new DynamicDictionaryItems(result.data)) + { + string name = (string)itemInfo.Value.attributes.displayName; + string id = (string)itemInfo.Value.id; + if (itemInfo.Value.type == "items" && name.EndsWith(extension)) + { + dynamic? item = GetLatestVersionItem(get2LeggedToken, projectId, id); + string fileName = item?.attributes.displayName; + long versionNumber = item?.attributes.versionNumber; + string itemId = item?.relationships.item.data.id; + DataRow row = dt.NewRow(); + row["ProjectId"] = projectId; + row["FolderId"] = folderId; + row["ItemName"] = fileName??string.Empty; + row["ItemId"] = itemId??string.Empty; + row["LatestVersion"] = versionNumber; + dt.Rows.Add(row); + } + else if (itemInfo.Value.type == "folders" && isRecursive) + { + BatchReportItemVersionRecursive(projectId,id, extension,ref dt,isRecursive); + } + } + } public void BatchExportAllRevitToExcel(string token2Leg,string directory,string hubId,string projectId,bool isRecursive) { (string, string) projectFilesFolder = GetTopProjectFilesFolder(token2Leg, hubId, projectId); diff --git a/APSToolkitUnit/BIM360Test.cs b/APSToolkitUnit/BIM360Test.cs index 92d95f3..32234da 100644 --- a/APSToolkitUnit/BIM360Test.cs +++ b/APSToolkitUnit/BIM360Test.cs @@ -458,4 +458,13 @@ public void TestBatchExportAllRevitToExcelByFolder(string projectId,string folde } bim360.BatchExportAllRevitToExcelByFolder(directory, projectId,folderId,true); } + + [Test] + [TestCase("b.1f7aa830-c6ef-48be-8a2d-bd554779e74b","urn:adsk.wipprod:fs.folder:co.dEsE_6gCT6q0Kz7cRSGx0w")] + public void BatchReportItemVersionTest(string projectId,string folderId) + { + BIM360 bim360 = new BIM360(); + DataTable dataTable = bim360.BatchReportItemVersion(projectId,folderId,".rvt",true); + dataTable.ExportDataToExcel("result.xlsx"); + } } \ No newline at end of file