diff --git a/Autodesk.PackageBuilder.Tests/Addin/InventorAddInsBuilder_Tests.cs b/Autodesk.PackageBuilder.Tests/Addin/InventorAddInsBuilder_Tests.cs new file mode 100644 index 0000000..b41f063 --- /dev/null +++ b/Autodesk.PackageBuilder.Tests/Addin/InventorAddInsBuilder_Tests.cs @@ -0,0 +1,168 @@ +using Autodesk.PackageBuilder.Tests.Utils; +using NUnit.Framework; +using System; + +namespace Autodesk.PackageBuilder.Tests.Addin +{ + public class InventorAddInsBuilder_Tests + { + InventorAddInsBuilder builder; + [SetUp] + public void Setup() + { + builder = BuilderUtils.Build(); + } + + [Test] + public void Build_InventorAddIn() + { + builder.AssertElement("AddIn"); + } + + [TestCase("Standard")] + [TestCase("NotStandard")] + public void Build_Create(string type) + { + builder.AddIn.Create(type); + builder.AssertElementAttribute("AddIn", "Type", type); + } + + [Test] + public void Build_Create_Empty() + { + string type = "Standard"; + builder.AddIn.Create(); + builder.AssertElementAttribute("AddIn", "Type", type); + } + + [TestCase("Value")] + [TestCase("PropertyValue")] + public void Build_Create_AddInId(string value) + { + builder.AddIn.Create() + .ClassId(value) + .ClientId(value) + .DisplayName(value) + .Description(value) + .Assembly(value); + + builder.AssertElement("ClassId", value); + builder.AssertElement("ClientId", value); + builder.AssertElement("DisplayName", value); + builder.AssertElement("Description", value); + builder.AssertElement("Assembly", value); + + builder.AssertNotElement("LoadAutomatically"); + builder.AssertNotElement("LoadBehavior"); + builder.AssertNotElement("UserUnloadable"); + builder.AssertNotElement("Hidden"); + } + + [TestCase("Value", 0)] + [TestCase("PropertyValue", 1)] + public void Build_Create_AddInId_Load(string value, int i) + { + builder.AddIn.Create() + .ClassId(value) + .ClientId(value) + .DisplayName(value) + .Description(value) + .Assembly(value) + .LoadAutomatically(i) + .LoadBehavior(i) + .UserUnloadable(i) + .Hidden(i); + + builder.AssertElement("ClassId", value); + builder.AssertElement("ClientId", value); + builder.AssertElement("DisplayName", value); + builder.AssertElement("Description", value); + builder.AssertElement("Assembly", value); + + builder.AssertElement("LoadAutomatically", i); + builder.AssertElement("LoadBehavior", i); + builder.AssertElement("UserUnloadable", i); + builder.AssertElement("Hidden", i); + } + + [TestCase(28, "28..")] + [TestCase(29, "29..")] + public void Build_Create_AddInId_SupportedSoftwareVersionEqualTo(int version, string expected) + { + builder.AddIn.Create() + .SupportedSoftwareVersion(version); + + builder.AssertElement("SupportedSoftwareVersionEqualTo", expected); + builder.AssertNotElement("SupportedSoftwareVersionGreaterThan"); + builder.AssertNotElement("SupportedSoftwareVersionLessThan"); + } + + [TestCase(25, "24..")] // Inventor 2021+ + [TestCase(28, "27..")] // Inventor 2024+ + [TestCase(29, "28..")] // Inventor 2025+ + public void Build_Create_AddInId_SupportedSoftwareVersionGreaterThan(int version, string expected) + { + builder.AddIn.Create() + .SupportedSoftwareVersion(version, 0); + + builder.AssertElement("SupportedSoftwareVersionGreaterThan", expected); + builder.AssertNotElement("SupportedSoftwareVersionLessThan"); + builder.AssertNotElement("SupportedSoftwareVersionEqualTo"); + } + + [TestCase(25, "24..", 28, "29..")] // Inventor 2021+ to 2024- + [TestCase(25, "24..", 28, "28..", true)] // Inventor 2021+ to 2024- (not include 2024) + [TestCase(29, "28..", 30, "31..")] // Inventor 2025+ to 2026- + [TestCase(29, "28..", 30, "30..", true)] // Inventor 2025+ to 2026- (not include 2026) + public void Build_Create_AddInId_SupportedSoftwareVersionGreaterAndLessThan(int minVersion, string minExpected, int maxVersion, string maxExpected, bool maxVersionMinusOne = false) + { + builder.AddIn.Create() + .SupportedSoftwareVersion(minVersion, maxVersion, maxVersionMinusOne); + + builder.AssertElement("SupportedSoftwareVersionGreaterThan", minExpected); + builder.AssertElement("SupportedSoftwareVersionLessThan", maxExpected); + builder.AssertNotElement("SupportedSoftwareVersionEqualTo"); + } + + [Test] + public void Build_InventorAddIns_DemoClass() + { + var builder = BuilderUtils.Build(); + var content = builder.ToString(); + Console.WriteLine(builder.ToString()); + Assert.AreEqual(DemoAddinBuilder.Expected, content, $"Expected: {DemoAddinBuilder.Expected}\nContent: {content}"); + } + + public class DemoAddinBuilder : InventorAddInsBuilder + { + public static string Expected => """" + + + {11111111-2222-3333-4444-55555555555F} + {11111111-2222-3333-4444-55555555555F} + InventorAddIn + InventorAddIn + InventorAddIn.dll + 0 + 0 + 24.. + 29.. + + """"; + public DemoAddinBuilder() + { + var classId = new Guid("11111111-2222-3333-4444-55555555555F"); + AddIn.Create() + .ClassId(classId) + .ClientId(classId) + .DisplayName("InventorAddIn") + .Description("InventorAddIn") + .Assembly("InventorAddIn.dll") + .LoadBehavior(0) + .UserUnloadable(0) + .SupportedSoftwareVersionGreaterThan("24..") + .SupportedSoftwareVersionLessThan("29.."); + } + } + } +} \ No newline at end of file diff --git a/Autodesk.PackageBuilder.Tests/Application/PackageContentsBuilder_AutoCAD_Tests.cs b/Autodesk.PackageBuilder.Tests/Application/PackageContentsBuilder_AutoCAD_Tests.cs new file mode 100644 index 0000000..4d13664 --- /dev/null +++ b/Autodesk.PackageBuilder.Tests/Application/PackageContentsBuilder_AutoCAD_Tests.cs @@ -0,0 +1,134 @@ +using NUnit.Framework; +using Autodesk.PackageBuilder.Extensible.AutoCAD; +using System; +using System.Linq; + +namespace Autodesk.PackageBuilder.Tests.Application +{ + public class PackageContentsBuilder_AutoCAD_Tests + { + [Test] + public void Build_PackageBuilder_AutoCADClass() + { + var builder = BuilderUtils.Build(); + var content = builder.ToString(); +#if NET6_0 + if (AutoCADPackageBuilder.Expected.Equals(content) == false) + Assert.Ignore("Not equal, order not match in version net6.0 for some reason..."); +#endif + Assert.AreEqual(AutoCADPackageBuilder.Expected, content, $"Expected: {AutoCADPackageBuilder.Expected}\nContent: {content}"); + } + + public class AutoCADPackageBuilder : PackageContentsBuilder + { + public static string Expected => """" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + """"; + public AutoCADPackageBuilder() + { + var commends = new[] { "CommandOpen", "CommandClose" }; + var commandGroup = "Group"; + + ApplicationPackage + .Create() + .AutoCADApplication() + .Name("AutoCADAddin") + .AppVersion("1.0.0"); + + CompanyDetails + .Create("Company Name") + .Url("url") + .Email("email"); + + Components + .CreateEntry("AutoCAD 21.0") + .OS("Win64") + .Platform("AutoCAD*") + .SeriesMin("R21.0") + .SeriesMax("R21.0") + .AppDescription("AutoCAD Addin for 2017 version") + .AppName("AutoCADAddin") + .ModuleName(@"./Contents/2017/AutoCADAddin.dll") + .Commands(); + + Components + .CreateEntry("AutoCAD 22.0") + .AutoCADPlatform("22.0") + .AppDescription("AutoCAD Addin for 2018 version") + .AppName("AutoCADAddin") + .ModuleName(@"./Contents/2018/AutoCADAddin.dll") + .CommandGroups(commandGroup, commends); + + Components + .CreateEntry("AutoCAD 23.0") + .AutoCADPlatform("23.0", "23.1") + .AppDescription("AutoCAD Addin for 2019 and 2020 versions") + .AppName("AutoCADAddin") + .ModuleName(@"./Contents/2019/AutoCADAddin.dll") + .LoadOnAppearance(false) + .Commands(commends); + + Components + .CreateEntry("AutoCAD 24.0") + .AutoCADPlatform("24.0", "25.0", true) + .AppDescription("AutoCAD Addin for 2021 to 2024 versions") + .AppName("AutoCADAddin") + .ModuleName(@"./Contents/2021/AutoCADAddin.dll") + .LoadOnAppearance() + .Commands(commends); + + Components + .CreateEntry("AutoCAD 25.0") + .AutoCADPlatform("25.0", null) + .AppDescription("AutoCAD Addin for 2025 and later versions") + .AppName("AutoCADAddin") + .ModuleName(@"./Contents/2025/AutoCADAddin.dll") + .LoadOnAppearance() + .Commands(commends.LastOrDefault()); + + } + } + } +} \ No newline at end of file diff --git a/Autodesk.PackageBuilder.Tests/Application/PackageContentsBuilder_Inventor_Tests.cs b/Autodesk.PackageBuilder.Tests/Application/PackageContentsBuilder_Inventor_Tests.cs new file mode 100644 index 0000000..c7d0eaf --- /dev/null +++ b/Autodesk.PackageBuilder.Tests/Application/PackageContentsBuilder_Inventor_Tests.cs @@ -0,0 +1,62 @@ +using NUnit.Framework; + +namespace Autodesk.PackageBuilder.Tests.Application +{ + public class PackageContentsBuilder_Inventor_Tests + { + [Test] + public void Build_PackageBuilder_InventorClass() + { + var builder = BuilderUtils.Build(); + var content = builder.ToString(); +#if NET6_0 + if (InventorPackageBuilder.Expected.Equals(content) == false) + Assert.Ignore("Not equal, order not match in version net6.0 for some reason..."); +#endif + Assert.AreEqual(InventorPackageBuilder.Expected, content, $"Expected: {InventorPackageBuilder.Expected}\nContent: {content}"); + } + + public class InventorPackageBuilder : PackageContentsBuilder + { + public static string Expected => """" + + + + + + + + + + + + + """"; + public InventorPackageBuilder() + { + ApplicationPackage + .Create() + .InventorApplication() + .Name("InventorAddin") + .AppVersion("1.0.0"); + + CompanyDetails + .Create("Company Name") + .Url("url") + .Email("email"); + + Components + .CreateEntry("Inventor 2024") + .InventorPlatform(25, 29, true) + .AppName("InventorAddin") + .ModuleName(@"./Contents/2024/InventorAddin.addin"); + + Components + .CreateEntry("Inventor 2025") + .InventorPlatform(29, 0) + .AppName("InventorAddin") + .ModuleName(@"./Contents/2025/InventorAddin.addin"); + } + } + } +} \ No newline at end of file diff --git a/Autodesk.PackageBuilder.Tests/Application/PackageContentsBuilder_Max3ds_Tests.cs b/Autodesk.PackageBuilder.Tests/Application/PackageContentsBuilder_Max3ds_Tests.cs new file mode 100644 index 0000000..4e03fbf --- /dev/null +++ b/Autodesk.PackageBuilder.Tests/Application/PackageContentsBuilder_Max3ds_Tests.cs @@ -0,0 +1,62 @@ +using NUnit.Framework; + +namespace Autodesk.PackageBuilder.Tests.Application +{ + public class PackageContentsBuilder_Max3ds_Tests + { + [Test] + public void Build_PackageBuilder_Max3ds_Class() + { + var builder = BuilderUtils.Build(); + var content = builder.ToString(); +#if NET6_0 + if (Max3dsPackageBuilder.Expected.Equals(content) == false) + Assert.Ignore("Not equal, order not match in version net6.0 for some reason..."); +#endif + Assert.AreEqual(Max3dsPackageBuilder.Expected, content, $"Expected: {Max3dsPackageBuilder.Expected}\nContent: {content}"); + } + + public class Max3dsPackageBuilder : PackageContentsBuilder + { + public static string Expected => """" + + + + + + + + + + + + + """"; + public Max3dsPackageBuilder() + { + ApplicationPackage + .Create() + .Max3dsApplication() + .Name("Max3dsAddin") + .AppVersion("1.0.0"); + + CompanyDetails + .Create("Company Name") + .Url("url") + .Email("email"); + + Components + .CreateEntry("Max3ds 2024") + .Max3dsPlatform(2024) + .AppName("Max3dsAddin") + .ModuleName(@"./Contents/2024/Max3dsAddin.dll"); + + Components + .CreateEntry("Max3ds 2025") + .Max3dsPlatform(2025) + .AppName("Max3dsAddin") + .ModuleName(@"./Contents/2025/Max3dsAddin.dll"); + } + } + } +} \ No newline at end of file diff --git a/Autodesk.PackageBuilder.Tests/Application/PackageContentsBuilder_Maya_Tests.cs b/Autodesk.PackageBuilder.Tests/Application/PackageContentsBuilder_Maya_Tests.cs new file mode 100644 index 0000000..846365b --- /dev/null +++ b/Autodesk.PackageBuilder.Tests/Application/PackageContentsBuilder_Maya_Tests.cs @@ -0,0 +1,63 @@ +using NUnit.Framework; + +namespace Autodesk.PackageBuilder.Tests.Application +{ + public class PackageContentsBuilder_Maya_Tests + { + [Test] + public void Build_PackageBuilder_Maya_Class() + { + var builder = BuilderUtils.Build(); + var content = builder.ToString(); +#if NET6_0 + if (MayaPackageBuilder.Expected.Equals(content) == false) + Assert.Ignore("Not equal, order not match in version net6.0 for some reason..."); +#endif + Assert.AreEqual(MayaPackageBuilder.Expected, content, $"Expected: {MayaPackageBuilder.Expected}\nContent: {content}"); + } + + public class MayaPackageBuilder : PackageContentsBuilder + { + public static string Expected => """" + + + + + + + + + + + + + """"; + + public MayaPackageBuilder() + { + ApplicationPackage + .Create() + .MayaApplication() + .Name("MayaAddin") + .AppVersion("1.0.0"); + + CompanyDetails + .Create("Company Name") + .Url("url") + .Email("email"); + + Components + .CreateEntry("Maya 2024") + .MayaPlatform(2024) + .AppName("MayaAddin") + .ModuleName(@"./Contents/2024/MayaAddin.dll"); + + Components + .CreateEntry("Maya 2025") + .MayaPlatform(2025) + .AppName("MayaAddin") + .ModuleName(@"./Contents/2025/MayaAddin.dll"); + } + } + } +} \ No newline at end of file diff --git a/Autodesk.PackageBuilder.Tests/Application/PackageContentsBuilder_Navisworks_Tests.cs b/Autodesk.PackageBuilder.Tests/Application/PackageContentsBuilder_Navisworks_Tests.cs new file mode 100644 index 0000000..86a122e --- /dev/null +++ b/Autodesk.PackageBuilder.Tests/Application/PackageContentsBuilder_Navisworks_Tests.cs @@ -0,0 +1,63 @@ +using NUnit.Framework; + +namespace Autodesk.PackageBuilder.Tests.Application +{ + public class PackageContentsBuilder_Navisworks_Tests + { + [Test] + public void Build_PackageBuilder_NavisworksClass() + { + var builder = BuilderUtils.Build(); + var content = builder.ToString(); +#if NET6_0 + if (NavisworksPackageBuilder.Expected.Equals(content) == false) + Assert.Ignore("Not equal, order not match in version net6.0 for some reason..."); +#endif + Assert.AreEqual(NavisworksPackageBuilder.Expected, content, $"Expected: {NavisworksPackageBuilder.Expected}\nContent: {content}"); + } + + public class NavisworksPackageBuilder : PackageContentsBuilder + { + public static string Expected => """" + + + + + + + + + + + + + """"; + + public NavisworksPackageBuilder() + { + ApplicationPackage + .Create() + .AutodeskProduct("Navisworks") + .Name("NavisworksAddin") + .AppVersion("1.0.0"); + + CompanyDetails + .Create("Company Name") + .Url("url") + .Email("email"); + + Components + .CreateEntry("Navisworks 2024") + .NavisworksPlatform(19, 22, true) + .AppName("NavisworksAddin") + .ModuleName(@"./Contents/2024/NavisworksAddin.dll"); + + Components + .CreateEntry("Navisworks 2025") + .NavisworksPlatform(22, 0) + .AppName("NavisworksAddin") + .ModuleName(@"./Contents/2025/NavisworksAddin.dll"); + } + } + } +} \ No newline at end of file diff --git a/Autodesk.PackageBuilder.Tests/Application/PackageContentsBuilder_Revit_Tests.cs b/Autodesk.PackageBuilder.Tests/Application/PackageContentsBuilder_Revit_Tests.cs new file mode 100644 index 0000000..30128d9 --- /dev/null +++ b/Autodesk.PackageBuilder.Tests/Application/PackageContentsBuilder_Revit_Tests.cs @@ -0,0 +1,65 @@ +using NUnit.Framework; + +namespace Autodesk.PackageBuilder.Tests.Application +{ + public class PackageContentsBuilder_Revit_Tests + { + [Test] + public void Build_PackageBuilder_RevitClass() + { + var builder = BuilderUtils.Build(); + var content = builder.ToString(); +#if NET6_0 + if (RevitPackageBuilder.Expected.Equals(content) == false) + Assert.Ignore("Not equal, order not match in version net6.0 for some reason..."); +#endif + Assert.AreEqual(RevitPackageBuilder.Expected, content, $"Expected: {RevitPackageBuilder.Expected}\nContent: {content}"); + } + + public class RevitPackageBuilder : PackageContentsBuilder + { + public static string Expected => """" + + + + + + + + + + + + + """"; + public RevitPackageBuilder() + { + ApplicationPackage + .Create() + .RevitApplication() + .Name("RevitAddin") + .AppVersion("1.0.0"); + + CompanyDetails + .Create("Company Name") + .Url("url") + .Email("email"); + + Components + .CreateEntry("Revit 2021") + .OS("Win64") + .Platform("Revit") + .SeriesMin("R2021") + .SeriesMax("R2021") + .AppName("RevitAddin") + .ModuleName(@"./Contents/2021/RevitAddin.addin"); + + Components + .CreateEntry("Revit 2022") + .RevitPlatform(2022) + .AppName("RevitAddin") + .ModuleName(@"./Contents/2022/RevitAddin.addin"); + } + } + } +} \ No newline at end of file diff --git a/Autodesk.PackageBuilder.Tests/Application/PackageContentsBuilder_Tests.cs b/Autodesk.PackageBuilder.Tests/Application/PackageContentsBuilder_Tests.cs index b246ecc..758998a 100644 --- a/Autodesk.PackageBuilder.Tests/Application/PackageContentsBuilder_Tests.cs +++ b/Autodesk.PackageBuilder.Tests/Application/PackageContentsBuilder_Tests.cs @@ -70,14 +70,15 @@ public void Build_ApplicationPackage_Attribute(string value) builder.AssertAttribute("OnlineDocumentation", value); } - [Test] - public void Build_ApplicationPackage_Attribute_AppVersion() + [TestCase("1.2.3")] + [TestCase("1.2.3.4")] + public void Build_ApplicationPackage_Attribute_AppVersion(string versionString) { - var version = new Version(1, 2, 3, 4); + var version = new Version(versionString); builder.ApplicationPackage.Create() .AppVersion(version); - builder.AssertAttribute("AppVersion", version); + builder.AssertAttribute("AppVersion", version.ToString(3)); } [Test] @@ -87,7 +88,17 @@ public void Build_ApplicationPackage_Attribute_ProductCode() builder.ApplicationPackage.Create() .ProductCode(guid); - builder.AssertAttribute("ProductCode", guid); + builder.AssertAttribute("ProductCode", guid.ToString("B").ToUpperInvariant()); + } + + [Test] + public void Build_ApplicationPackage_Attribute_UpdaterCode() + { + var guid = Guid.NewGuid(); + builder.ApplicationPackage.Create() + .UpgradeCode(guid); + + builder.AssertAttribute("UpgradeCode", guid.ToString("B").ToUpperInvariant()); } [TestCase("Name")] @@ -159,64 +170,5 @@ public void Build_Components_CreateEntry_Attribute(string value) builder.AssertAttribute("Version", value); builder.AssertAttribute("AppDescription", value); } - - [Test] - public void Build_PackageBuilder_DemoClass() - { - var builder = BuilderUtils.Build(); - var content = builder.ToString(); -#if NET6_0 - if (DemoPackageBuilder.Expected.Equals(content) == false) - Assert.Ignore("Not equal, order not match in version net6.0 for some reason..."); -#endif - Assert.AreEqual(DemoPackageBuilder.Expected, content, $"Expected: {DemoPackageBuilder.Expected}\nContent: {content}"); - } - - public class DemoPackageBuilder : PackageContentsBuilder - { - public static string Expected => """" - - - - - - - - - - - - - """"; - public DemoPackageBuilder() - { - ApplicationPackage - .Create() - .AutodeskProduct(AutodeskProducts.Revit) - .Name("RevitAddin") - .AppVersion("1.0.0") - .ProductType(ProductTypes.Application); - - CompanyDetails - .Create("Company Name") - .Url("url") - .Email("email"); - - Components - .CreateEntry("Revit 2021") - .OS("Win64") - .Platform("Revit") - .SeriesMin("R2021") - .SeriesMax("R2021") - .AppName("RevitAddin") - .ModuleName(@"./Contents/2021/RevitAddin.addin"); - - Components - .CreateEntry("Revit 2022") - .RevitPlatform(2022) - .AppName("RevitAddin") - .ModuleName(@"./Contents/2022/RevitAddin.addin"); - } - } } } \ No newline at end of file diff --git a/Autodesk.PackageBuilder.Tests/Autodesk.PackageBuilder.Tests.csproj b/Autodesk.PackageBuilder.Tests/Autodesk.PackageBuilder.Tests.csproj index 8c77bdb..e3e9840 100644 --- a/Autodesk.PackageBuilder.Tests/Autodesk.PackageBuilder.Tests.csproj +++ b/Autodesk.PackageBuilder.Tests/Autodesk.PackageBuilder.Tests.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/Autodesk.PackageBuilder.Tests/Data/DataBuild_Tests.cs b/Autodesk.PackageBuilder.Tests/Data/DataBuild_Tests.cs new file mode 100644 index 0000000..3a6b9e2 --- /dev/null +++ b/Autodesk.PackageBuilder.Tests/Data/DataBuild_Tests.cs @@ -0,0 +1,109 @@ +using Autodesk.PackageBuilder.Model.Application; +using Autodesk.PackageBuilder.Tests.Utils; +using NUnit.Framework; +using System; +using System.Xml.Serialization; + +namespace Autodesk.PackageBuilder.Tests.Data +{ + public class DataBuild_Tests + { + PackageContentsBuilder builder; + [SetUp] + public void Setup() + { + builder = BuilderUtils.Build(); + } + + [TestCase("Test", "Test")] + [TestCase("Name", "Value")] + public void DataBuilder_CreateAttribute(string name, object value) + { + var applicationPackageBuilder = builder.ApplicationPackage.Create(); + applicationPackageBuilder.DataBuilder.CreateAttribute(name, value); + + // Console.WriteLine(builder.ToString()); + + builder.AssertAttribute(name, value); + } + + [TestCase("Test", "Test")] + [TestCase("Name", "Value")] + public void DataBuilder_CreateElement(string name, object value) + { + var applicationPackageBuilder = builder.ApplicationPackage.Create(); + applicationPackageBuilder.DataBuilder.CreateElement(name, value); + + // Console.WriteLine(builder.ToString()); + + builder.AssertElement(name, value); + } + + [TestCase(3)] + [TestCase(5)] + public void Build_CreateComponentEntry(int length) + { + for (int i = 0; i < length; i++) + { + var componentsBuilder = builder.Components.CreateEntry($"Description {i}"); + + componentsBuilder.DataBuilder.CreateElement("Element", i); + componentsBuilder.DataBuilder.CreateAttribute("Attribute", i); + + } + // Console.WriteLine(builder.ToString()); + + for (int i = 0; i < length; i++) + { + builder.AssertElement("Element", i); + builder.AssertElementAttribute("ComponentEntry", "Attribute", i); + } + } + + [Test] + public void Build_CustomExtensibleData() + { + var builder = BuilderUtils.Build(builder => + { + var custom = new CustomElement() + { + Name = "Name", + Value = "Value" + }; + + var componentRevit2021 = builder.Components + .CreateEntry("Revit 2021"); + + componentRevit2021.DataBuilder.CreateAttribute("Attribute", true); + componentRevit2021.DataBuilder.CreateElement("Element", true); + componentRevit2021.DataBuilder.CreateElement("CustomElement", custom); + }); + + var result = builder.ToString(); + // Console.WriteLine(result); + + Assert.AreEqual(Expected, result, $"Expected: {Expected}\nContent: {result}"); + } + + public class CustomElement : ExtensibleData + { + [XmlAttribute] + public string Name { get; set; } + [XmlElement] + public string Value { get; set; } + } + + public static string Expected => """" + + + + + true + + Value + + + + """"; + } +} \ No newline at end of file diff --git a/Autodesk.PackageBuilder.Tests/Utils/AssertBuilderUtils.cs b/Autodesk.PackageBuilder.Tests/Utils/AssertBuilderUtils.cs index 0171145..67bdde6 100644 --- a/Autodesk.PackageBuilder.Tests/Utils/AssertBuilderUtils.cs +++ b/Autodesk.PackageBuilder.Tests/Utils/AssertBuilderUtils.cs @@ -30,6 +30,18 @@ public static void AssertElement(this IBuilder builder, string element, object v Assert.IsTrue(content.Contains(elementValue), $"The string '{elementValue}' is not found in '{content}'"); } + /// + /// Asserts that the specified is not present in the builder's content. + /// + /// The builder instance to check. + /// The name of the element to verify absence of. + public static void AssertNotElement(this IBuilder builder, string element) + { + var content = builder.ToString(); + var elementValue = ElementStart(element); + Assert.IsFalse(content.Contains(elementValue), $"The string '{elementValue}' is found in '{content}'"); + } + /// /// Assert with '=""'. /// diff --git a/Autodesk.PackageBuilder.sln b/Autodesk.PackageBuilder.sln index ad09bca..ac56445 100644 --- a/Autodesk.PackageBuilder.sln +++ b/Autodesk.PackageBuilder.sln @@ -10,6 +10,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Project", "Project", "{F7162A81-C306-4E55-B881-86FFF09FBD5B}" ProjectSection(SolutionItems) = preProject CHANGELOG.md = CHANGELOG.md + Directory.Build.props = Directory.Build.props README.md = README.md EndProjectSection EndProject diff --git a/Autodesk.PackageBuilder/Autodesk.PackageBuilder.csproj b/Autodesk.PackageBuilder/Autodesk.PackageBuilder.csproj index 0919422..cecf716 100644 --- a/Autodesk.PackageBuilder/Autodesk.PackageBuilder.csproj +++ b/Autodesk.PackageBuilder/Autodesk.PackageBuilder.csproj @@ -6,10 +6,6 @@ latest - - 1.0.6 - - ricaun Luiz Henrique Cassettari @@ -35,6 +31,9 @@ $(OutputPath)\$(AssemblyName).xml + true + snupkg + portable false diff --git a/Autodesk.PackageBuilder/Builder/Abstractions/Addin/IAddInEntryBuilder.cs b/Autodesk.PackageBuilder/Builder/Abstractions/Addin/IAddInEntryBuilder.cs deleted file mode 100644 index c38a8b1..0000000 --- a/Autodesk.PackageBuilder/Builder/Abstractions/Addin/IAddInEntryBuilder.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Autodesk.PackageBuilder -{ - public interface IAddInEntryBuilder - { - AddInEntryBuilder CreateEntry(string type = "Application"); - } -} \ No newline at end of file diff --git a/Autodesk.PackageBuilder/Builder/Abstractions/Addin/IInventorAddInEntryBuilder.cs b/Autodesk.PackageBuilder/Builder/Abstractions/Addin/IInventorAddInEntryBuilder.cs new file mode 100644 index 0000000..374aa37 --- /dev/null +++ b/Autodesk.PackageBuilder/Builder/Abstractions/Addin/IInventorAddInEntryBuilder.cs @@ -0,0 +1,20 @@ +namespace Autodesk.PackageBuilder; + +/// +/// Defines a builder interface for constructing instances +/// for Autodesk Inventor add-in packaging. +/// +public interface IInventorAddInEntryBuilder +{ + /// + /// Creates a new instance with the specified add-in type. + /// + /// + /// The type of the add-in to create (e.g., "Standard" or "Application"). + /// Defaults to "Standard" if not specified. + /// + /// + /// An instance for further configuration. + /// + InventorAddInEntryBuilder Create(string type = "Standard"); +} \ No newline at end of file diff --git a/Autodesk.PackageBuilder/Builder/Abstractions/Addin/IRevitAddInEntryBuilder.cs b/Autodesk.PackageBuilder/Builder/Abstractions/Addin/IRevitAddInEntryBuilder.cs new file mode 100644 index 0000000..728fda8 --- /dev/null +++ b/Autodesk.PackageBuilder/Builder/Abstractions/Addin/IRevitAddInEntryBuilder.cs @@ -0,0 +1,17 @@ +namespace Autodesk.PackageBuilder +{ + /// + /// Defines a builder interface for creating add-in entry configurations. + /// + public interface IRevitAddInEntryBuilder + { + /// + /// Creates a new add-in entry with the specified type. + /// + /// The type of the add-in entry. Defaults to "Application". + /// + /// An instance for further configuration of the add-in entry. + /// + RevitAddInEntryBuilder CreateEntry(string type = "Application"); + } +} \ No newline at end of file diff --git a/Autodesk.PackageBuilder/Builder/Abstractions/Application/IApplicationPackageBuilder.cs b/Autodesk.PackageBuilder/Builder/Abstractions/Application/IApplicationPackageBuilder.cs index 08dadeb..821f4bc 100644 --- a/Autodesk.PackageBuilder/Builder/Abstractions/Application/IApplicationPackageBuilder.cs +++ b/Autodesk.PackageBuilder/Builder/Abstractions/Application/IApplicationPackageBuilder.cs @@ -1,7 +1,15 @@ namespace Autodesk.PackageBuilder { + /// + /// Defines a builder interface for creating instances. + /// public interface IApplicationPackageBuilder { + /// + /// Creates a new instance with the specified schema version. + /// + /// The schema version to use for the application package. Defaults to "1.0". + /// An instance initialized with the given schema version. ApplicationPackageBuilder Create(string schemaVersion = "1.0"); } } \ No newline at end of file diff --git a/Autodesk.PackageBuilder/Builder/Abstractions/Application/ICompanyDetailsBuilder.cs b/Autodesk.PackageBuilder/Builder/Abstractions/Application/ICompanyDetailsBuilder.cs index 5fae227..473c84c 100644 --- a/Autodesk.PackageBuilder/Builder/Abstractions/Application/ICompanyDetailsBuilder.cs +++ b/Autodesk.PackageBuilder/Builder/Abstractions/Application/ICompanyDetailsBuilder.cs @@ -1,7 +1,17 @@ namespace Autodesk.PackageBuilder { + /// + /// Defines a builder interface for creating instances. + /// public interface ICompanyDetailsBuilder { + /// + /// Creates a new for the specified company name. + /// + /// The name of the company. + /// + /// A instance initialized with the specified company name. + /// CompanyDetailsBuilder Create(string name); } } \ No newline at end of file diff --git a/Autodesk.PackageBuilder/Builder/Abstractions/Application/IComponentsEntryBuilder.cs b/Autodesk.PackageBuilder/Builder/Abstractions/Application/IComponentsEntryBuilder.cs index a61b02b..ff740cb 100644 --- a/Autodesk.PackageBuilder/Builder/Abstractions/Application/IComponentsEntryBuilder.cs +++ b/Autodesk.PackageBuilder/Builder/Abstractions/Application/IComponentsEntryBuilder.cs @@ -1,7 +1,15 @@ namespace Autodesk.PackageBuilder { + /// + /// Defines a builder interface for creating entries. + /// public interface IComponentsEntryBuilder { + /// + /// Creates a new entry with the specified description. + /// + /// The description for the components entry. + /// A instance for further configuration. ComponentsBuilder CreateEntry(string description); } } \ No newline at end of file diff --git a/Autodesk.PackageBuilder/Builder/Abstractions/BuilderBase.cs b/Autodesk.PackageBuilder/Builder/Abstractions/BuilderBase.cs index 02994e0..00d7ec0 100644 --- a/Autodesk.PackageBuilder/Builder/Abstractions/BuilderBase.cs +++ b/Autodesk.PackageBuilder/Builder/Abstractions/BuilderBase.cs @@ -1,6 +1,7 @@ namespace Autodesk.PackageBuilder { using System; + using System.Linq; using System.Runtime.CompilerServices; /// /// BuilderBase @@ -9,55 +10,60 @@ /// public abstract class BuilderBase where TBuilder : class - where TData : new() + where TData : ExtensibleData, new() { /// /// Data /// protected TData Data { get; set; } - + /// + /// DataBuilder + /// + public DataBuilderBase DataBuilder => new(Data); /// /// SetNewPropertyValue /// /// /// - /// + /// /// - protected TBuilder SetNewPropertyValue(object value, [CallerMemberName] string name = null) where T : new() + protected TBuilder SetNewPropertyValue(object value, [CallerMemberName] string propertyName = null) where T : new() { - return SetNewPropertyValue(Data, name, value); + return SetNewPropertyValue(Data, propertyName, value); } - private TBuilder SetNewPropertyValue(object instance, string method, object value) where T : new() + internal T GetNewPropertyValue(object instance) where T : new() { - var data = new T(); - var name = data.GetType().Name; - var type = instance.GetType(); - var property = type.GetProperty(name) ?? + var property = type.GetProperties().FirstOrDefault(e=>e.PropertyType == typeof(T)) ?? throw new NullReferenceException( - $"Property '{name}' in class {type.Name} not found"); + $"Property with type '{typeof(T)}' in class {type.Name} not found"); if (property.GetValue(instance) == null) - property.SetValue(instance, data); + property.SetValue(instance, new T()); - return SetPropertyValue(property.GetValue(instance), method, value); + return (T)property.GetValue(instance); + } + + private TBuilder SetNewPropertyValue(object instance, string propertyName, object value) where T : new() + { + var data = GetNewPropertyValue(instance); + return SetPropertyValue(data, propertyName, value); } /// /// SetPropertyValue /// /// - /// + /// /// - protected TBuilder SetPropertyValue(object value, [CallerMemberName] string name = null) + protected TBuilder SetPropertyValue(object value, [CallerMemberName] string propertyName = null) { - return SetPropertyValue(Data, name, value); + return SetPropertyValue(Data, propertyName, value); } - private TBuilder SetPropertyValue(object instance, string method, object value) + private TBuilder SetPropertyValue(object instance, string propertyName, object value) { - var propertyName = method; var type = instance.GetType(); var property = type.GetProperty(propertyName) ?? throw new NullReferenceException( diff --git a/Autodesk.PackageBuilder/Builder/Abstractions/DataBuilderBase.cs b/Autodesk.PackageBuilder/Builder/Abstractions/DataBuilderBase.cs new file mode 100644 index 0000000..1f78e4f --- /dev/null +++ b/Autodesk.PackageBuilder/Builder/Abstractions/DataBuilderBase.cs @@ -0,0 +1,110 @@ +namespace Autodesk.PackageBuilder +{ + /// + /// Provides a base builder for constructing and manipulating objects. + /// + /// + /// This builder offers a fluent API for creating and modifying attributes and elements + /// within a instance. It supports both direct manipulation of the + /// underlying data model and creation of nested elements or attributes using generic overloads. + /// + public class DataBuilderBase : SingleBuilderBase + { + /// + /// Initializes a new instance of the class with the specified model. + /// + /// The instance to wrap and build upon. + public DataBuilderBase(ExtensibleData model) + { + SetDataInternal(model); + } + + /// + /// Creates a new data attribute with the specified name and value in the underlying . + /// + /// The name of the attribute to create. + /// The value of the attribute. + /// The current instance for method chaining. + public DataBuilderBase CreateAttribute(string name, object value) + { + Data.CreateDataAttribute(name, value); + return this; + } + + /// + /// Creates a new data element with the specified name and returns a builder for the new element. + /// + /// The name of the data element to create. + /// A new instance for the created data element. + public DataBuilderBase CreateElement(string name) + { + return new DataBuilderBase(Data.CreateDataElement(name)); + } + + /// + /// Creates a new data element with the specified name and value in the underlying . + /// + /// The name of the data element to create. + /// + /// The value to associate with the new data element. If the value is a , it will be used to create a nested element. + /// Otherwise, the value will be set directly. + /// + /// + /// A new instance for the created data element if is a ; otherwise, null. + /// + public DataBuilderBase CreateElement(string name, object value) + { + if (value is ExtensibleData extensibleData) + return new DataBuilderBase(Data.CreateDataElement(name, extensibleData)); + + Data.CreateDataElement(name, value); + return null; + } + + /// + /// Creates a new data attribute with the specified name and value in a new instance of derived from . + /// + /// The type of to use for creating the attribute. Must have a parameterless constructor. + /// The name of the attribute to create. + /// The value of the attribute. + /// The current instance for method chaining. + public DataBuilderBase CreateAttribute(string name, object value) where T : ExtensibleData, new() + { + var data = GetNewPropertyValue(Data); + data.CreateDataAttribute(name, value); + return this; + } + + /// + /// Creates a new data element with the specified name in a new instance of derived from . + /// + /// The type of to use for creating the element. Must have a parameterless constructor. + /// The name of the data element to create. + /// A new instance for the created data element. + public DataBuilderBase CreateElement(string name) where T : ExtensibleData, new() + { + var data = GetNewPropertyValue(Data); + return new DataBuilderBase(data.CreateDataElement(name)); + } + + /// + /// Creates a new data element with the specified name and value in a new instance of derived from . + /// + /// The type of to use for creating the element. Must have a parameterless constructor. + /// The name of the data element to create. + /// The value to associate with the new data element. If the value is a , it will be used to create a nested element. + /// + /// A new instance for the created data element if is a ; otherwise, null. + /// + public DataBuilderBase CreateElement(string name, object value) where T : ExtensibleData, new() + { + var data = GetNewPropertyValue(Data); + + if (value is ExtensibleData extensibleData) + return new DataBuilderBase(data.CreateDataElement(name, extensibleData)); + + data.CreateDataElement(name, value); + return null; + } + } +} \ No newline at end of file diff --git a/Autodesk.PackageBuilder/Builder/Abstractions/ListBuilderBase.cs b/Autodesk.PackageBuilder/Builder/Abstractions/ListBuilderBase.cs index 7dc95e9..4c0ab36 100644 --- a/Autodesk.PackageBuilder/Builder/Abstractions/ListBuilderBase.cs +++ b/Autodesk.PackageBuilder/Builder/Abstractions/ListBuilderBase.cs @@ -8,7 +8,7 @@ /// public abstract class ListBuilderBase : BuilderBase where TBuilder : class - where TData : new() + where TData : ExtensibleData, new() { private List _entryList; diff --git a/Autodesk.PackageBuilder/Builder/Abstractions/SingleBuilderBase.cs b/Autodesk.PackageBuilder/Builder/Abstractions/SingleBuilderBase.cs index b85d023..58ba552 100644 --- a/Autodesk.PackageBuilder/Builder/Abstractions/SingleBuilderBase.cs +++ b/Autodesk.PackageBuilder/Builder/Abstractions/SingleBuilderBase.cs @@ -7,7 +7,7 @@ /// public abstract class SingleBuilderBase : BuilderBase where TBuilder : class - where TData : new() + where TData : ExtensibleData, new() { /// /// SetDataInternal diff --git a/Autodesk.PackageBuilder/Builder/Addin/AddInEntryBuilder.cs b/Autodesk.PackageBuilder/Builder/Addin/AddInEntryBuilder.cs deleted file mode 100644 index 6aa7f82..0000000 --- a/Autodesk.PackageBuilder/Builder/Addin/AddInEntryBuilder.cs +++ /dev/null @@ -1,29 +0,0 @@ -namespace Autodesk.PackageBuilder -{ - using Model.Addin; - using System.Collections.Generic; - public class AddInEntryBuilder : ListBuilderBase, IAddInEntryBuilder - { - public AddInEntryBuilder(List models) - { - SetDataInternal(models); - } - - public AddInEntryBuilder CreateEntry(string type) - { - CreateEntryInternal(); - Type(type); - return this; - } - - private AddInEntryBuilder Type(string value) => SetPropertyValue(value); - public AddInEntryBuilder Name(string value) => SetPropertyValue(value); - public AddInEntryBuilder Assembly(string value) => SetPropertyValue(value); - public AddInEntryBuilder AddInId(string value) => SetPropertyValue(value); - public AddInEntryBuilder FullClassName(string value) => SetPropertyValue(value); - public AddInEntryBuilder VendorId(string value) => SetPropertyValue(value); - public AddInEntryBuilder VendorDescription(string value) => SetPropertyValue(value); - [System.Obsolete("This method does not have a Property 'AllowLoadingIntoExistingSession' in class AddInModel, will be removed in a future version.")] - internal AddInEntryBuilder AllowLoadingIntoExistingSession(bool value) => SetPropertyValue(value); - } -} \ No newline at end of file diff --git a/Autodesk.PackageBuilder/Builder/Addin/InventorAddInEntryBuilder.cs b/Autodesk.PackageBuilder/Builder/Addin/InventorAddInEntryBuilder.cs new file mode 100644 index 0000000..157c9d1 --- /dev/null +++ b/Autodesk.PackageBuilder/Builder/Addin/InventorAddInEntryBuilder.cs @@ -0,0 +1,144 @@ +namespace Autodesk.PackageBuilder; + +using Model.Addin; +using System; + +/// +/// Provides a builder for constructing entries for Autodesk Inventor packaging. +/// +public class InventorAddInEntryBuilder : SingleBuilderBase, IInventorAddInEntryBuilder +{ + /// + /// Initializes a new instance of the class with the specified model. + /// + /// The model to initialize the builder with. + public InventorAddInEntryBuilder(InventorAddIn model) + { + SetDataInternal(model); + } + + /// + /// Sets the type of the add-in and returns the builder instance. + /// + /// The type of the add-in (e.g., "Standard" or "Application"). + /// The current instance. + public InventorAddInEntryBuilder Create(string type) + { + return Type(type); + } + + /// + /// Sets the type of the add-in and returns the builder instance. + /// + /// The type value to set. + /// The current instance. + private InventorAddInEntryBuilder Type(string value) => SetPropertyValue(value); + + /// + /// Sets the COM class ID (GUID) of the add-in and returns the builder instance. + /// + /// The class ID as a string. + /// The current instance. + public InventorAddInEntryBuilder ClassId(string value) => SetPropertyValue(value); + + /// + /// Sets the COM class ID (GUID) of the add-in and returns the builder instance. + /// The GUID will be formatted with uppercase letters and braces, e.g. "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}". + /// + /// The class ID as a . + /// The current instance. + public InventorAddInEntryBuilder ClassId(Guid value) => ClassId(value.ToStringBraces()); + + /// + /// Sets the client ID (GUID) of the add-in and returns the builder instance. + /// + /// The client ID as a string. + /// The current instance. + public InventorAddInEntryBuilder ClientId(string value) => SetPropertyValue(value); + + /// + /// Sets the client ID (GUID) of the add-in and returns the builder instance. + /// The GUID will be formatted with uppercase letters and braces, e.g. "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}". + /// + /// The client ID as a . + /// The current instance. + public InventorAddInEntryBuilder ClientId(Guid value) => ClientId(value.ToStringBraces()); + + /// + /// Sets the display name of the add-in and returns the builder instance. + /// + /// The display name to set. + /// The current instance. + public InventorAddInEntryBuilder DisplayName(string value) => SetPropertyValue(value); + + /// + /// Sets the description of the add-in and returns the builder instance. + /// + /// The description to set. + /// The current instance. + public InventorAddInEntryBuilder Description(string value) => SetPropertyValue(value); + + /// + /// Sets the assembly path of the add-in and returns the builder instance. + /// + /// The assembly path to set. + /// The current instance. + public InventorAddInEntryBuilder Assembly(string value) => SetPropertyValue(value); + + /// + /// Sets whether the add-in should load automatically and returns the builder instance. + /// + /// 1 to load automatically, 0 otherwise. + /// The current instance. + public InventorAddInEntryBuilder LoadAutomatically(int? value) => SetPropertyValue(value); + + /// + /// Sets the load behavior of the add-in and returns the builder instance. + /// + /// The load behavior value to set. + /// The current instance. + public InventorAddInEntryBuilder LoadBehavior(int? value) => SetPropertyValue(value); + + /// + /// Sets whether the add-in can be unloaded by the user and returns the builder instance. + /// + /// 1 if user can unload, 0 otherwise. + /// The current instance. + public InventorAddInEntryBuilder UserUnloadable(int? value) => SetPropertyValue(value); + + /// + /// Sets whether the add-in is hidden in the Add-in Manager and returns the builder instance. + /// + /// 1 if hidden, 0 otherwise. + /// The current instance. + public InventorAddInEntryBuilder Hidden(int? value) => SetPropertyValue(value); + + /// + /// Sets the exact Inventor version this add-in supports and returns the builder instance. + /// + /// The version string to set. + /// The current instance. + public InventorAddInEntryBuilder SupportedSoftwareVersionEqualTo(string value) => SetPropertyValue(value); + + /// + /// Sets the minimum Inventor version (exclusive) this add-in supports and returns the builder instance. + /// + /// The version string to set. + /// The current instance. + public InventorAddInEntryBuilder SupportedSoftwareVersionGreaterThan(string value) => SetPropertyValue(value); + + /// + /// Sets the maximum Inventor version (exclusive) this add-in supports and returns the builder instance. + /// + /// The version string to set. + /// The current instance. + public InventorAddInEntryBuilder SupportedSoftwareVersionLessThan(string value) => SetPropertyValue(value); + + /// + /// Sets the Inventor version this add-in does not support and returns the builder instance. + /// + /// The version string to set. + /// The current instance. + public InventorAddInEntryBuilder SupportedSoftwareVersionNotEqualTo(string value) => SetPropertyValue(value); + +} \ No newline at end of file diff --git a/Autodesk.PackageBuilder/Builder/Addin/RevitAddInEntryBuilder.cs b/Autodesk.PackageBuilder/Builder/Addin/RevitAddInEntryBuilder.cs new file mode 100644 index 0000000..588c624 --- /dev/null +++ b/Autodesk.PackageBuilder/Builder/Addin/RevitAddInEntryBuilder.cs @@ -0,0 +1,80 @@ +namespace Autodesk.PackageBuilder +{ + using Model.Addin; + using System.Collections.Generic; + /// + /// Provides a builder for creating and configuring entries. + /// + public class RevitAddInEntryBuilder : ListBuilderBase, IRevitAddInEntryBuilder + { + /// + /// Initializes a new instance of the class with the specified list of objects. + /// + /// The list of objects to initialize the builder with. + public RevitAddInEntryBuilder(List models) + { + SetDataInternal(models); + } + + /// + /// Creates a new add-in entry and sets its type. + /// + /// The type of the add-in entry (e.g., "Application"). + /// The current instance for method chaining. + public RevitAddInEntryBuilder CreateEntry(string type) + { + CreateEntryInternal(); + Type(type); + return this; + } + + /// + /// Sets the property for the current entry. + /// + /// The type value to set. + /// The current instance for method chaining. + private RevitAddInEntryBuilder Type(string value) => SetPropertyValue(value); + + /// + /// Sets the property for the current entry. + /// + /// The name value to set. + /// The current instance for method chaining. + public RevitAddInEntryBuilder Name(string value) => SetPropertyValue(value); + + /// + /// Sets the property for the current entry. + /// + /// The assembly value to set. + /// The current instance for method chaining. + public RevitAddInEntryBuilder Assembly(string value) => SetPropertyValue(value); + + /// + /// Sets the property for the current entry. + /// + /// The add-in ID value to set. + /// The current instance for method chaining. + public RevitAddInEntryBuilder AddInId(string value) => SetPropertyValue(value); + + /// + /// Sets the property for the current entry. + /// + /// The fully qualified class name to set. + /// The current instance for method chaining. + public RevitAddInEntryBuilder FullClassName(string value) => SetPropertyValue(value); + + /// + /// Sets the property for the current entry. + /// + /// The vendor ID value to set. + /// The current instance for method chaining. + public RevitAddInEntryBuilder VendorId(string value) => SetPropertyValue(value); + + /// + /// Sets the property for the current entry. + /// + /// The vendor description value to set. + /// The current instance for method chaining. + public RevitAddInEntryBuilder VendorDescription(string value) => SetPropertyValue(value); + } +} \ No newline at end of file diff --git a/Autodesk.PackageBuilder/Builder/Addin/RevitAddInsEntryBuilder.cs b/Autodesk.PackageBuilder/Builder/Addin/RevitAddInsEntryBuilder.cs index 73a4c58..aad32a4 100644 --- a/Autodesk.PackageBuilder/Builder/Addin/RevitAddInsEntryBuilder.cs +++ b/Autodesk.PackageBuilder/Builder/Addin/RevitAddInsEntryBuilder.cs @@ -1,8 +1,15 @@ namespace Autodesk.PackageBuilder { using Model.Addin; + /// + /// Provides a builder for entries, enabling fluent construction and configuration of Revit add-in collections. + /// public class RevitAddInsEntryBuilder : SingleBuilderBase { + /// + /// Initializes a new instance of the class with the specified model. + /// + /// The model to initialize the builder with. public RevitAddInsEntryBuilder(RevitAddIns model) { SetDataInternal(model); diff --git a/Autodesk.PackageBuilder/Builder/Application/ApplicationPackageBuilder.cs b/Autodesk.PackageBuilder/Builder/Application/ApplicationPackageBuilder.cs index 566c0b5..615f7c3 100644 --- a/Autodesk.PackageBuilder/Builder/Application/ApplicationPackageBuilder.cs +++ b/Autodesk.PackageBuilder/Builder/Application/ApplicationPackageBuilder.cs @@ -3,30 +3,150 @@ using Model.Application; using System; + /// + /// Provides a builder for constructing instances with a fluent API. + /// public class ApplicationPackageBuilder : SingleBuilderBase, IApplicationPackageBuilder { + /// + /// Initializes a new instance of the class with the specified data. + /// + /// The application package data to initialize the builder with. public ApplicationPackageBuilder(ApplicationPackage applicationPackage) { SetDataInternal(applicationPackage); } - public ApplicationPackageBuilder Create( - string schemaVersion) + + /// + /// Creates a new instance with the specified schema version. + /// + /// The schema version to set for the application package. + /// The instance for chaining. + public ApplicationPackageBuilder Create(string schemaVersion) { return SchemaVersion(schemaVersion); } + + /// + /// Sets the schema version for the application package. + /// + /// The schema version value. + /// The instance for chaining. private ApplicationPackageBuilder SchemaVersion(string value) => SetPropertyValue(value); + + /// + /// Sets the name of the application package. + /// + /// The name value. + /// The instance for chaining. public ApplicationPackageBuilder Name(string value) => SetPropertyValue(value); + + /// + /// Sets the Autodesk product associated with the application package. + /// + /// The Autodesk product value. + /// The instance for chaining. public ApplicationPackageBuilder AutodeskProduct(string value) => SetPropertyValue(value); + + /// + /// Sets the description of the application package. + /// + /// The description value. + /// The instance for chaining. public ApplicationPackageBuilder Description(string value) => SetPropertyValue(value); + + /// + /// Sets the application version as a string. + /// + /// The application version value. + /// The instance for chaining. public ApplicationPackageBuilder AppVersion(string value) => SetPropertyValue(value); - public ApplicationPackageBuilder AppVersion(Version value) => SetPropertyValue(value.ToString()); + + /// + /// Sets the application version using a object. + /// The version is formatted as a string with up to three components (major.minor.build), e.g. "1.2.3". + /// + /// The application version as a . + /// The instance for chaining. + public ApplicationPackageBuilder AppVersion(Version value) => SetPropertyValue(value.ToString(3)); + + /// + /// Sets the user-friendly version string for the application package. + /// + /// The friendly version value. + /// The instance for chaining. public ApplicationPackageBuilder FriendlyVersion(string value) => SetPropertyValue(value); + + /// + /// Sets the product type of the application package. + /// + /// The product type value. + /// The instance for chaining. public ApplicationPackageBuilder ProductType(string value) => SetPropertyValue(value); + + /// + /// Sets the product code of the application package as a string. + /// + /// The product code value. + /// The instance for chaining. public ApplicationPackageBuilder ProductCode(string value) => SetPropertyValue(value); - public ApplicationPackageBuilder ProductCode(Guid value) => SetPropertyValue(value.ToString()); + + /// + /// Sets the product code of the application package using a . + /// The GUID will be formatted with uppercase letters and braces, e.g. "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}". + /// + /// The product code as a . + /// The instance for chaining. + public ApplicationPackageBuilder ProductCode(Guid value) => SetPropertyValue(value.ToStringBraces()); + + /// + /// Sets the application namespace associated with the application package. + /// + /// The application namespace value. + /// The instance for chaining. + public ApplicationPackageBuilder AppNameSpace(string value) => SetPropertyValue(value); + + /// + /// Sets the upgrade code of the application package as a string. + /// + /// The upgrade code value. + /// The instance for chaining. + public ApplicationPackageBuilder UpgradeCode(string value) => SetPropertyValue(value); + + /// + /// Sets the upgrade code of the application package using a . + /// The GUID will be formatted with uppercase letters and braces, e.g. "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}". + /// + /// The upgrade code as a . + /// The instance for chaining. + public ApplicationPackageBuilder UpgradeCode(Guid value) => UpgradeCode(value.ToStringBraces()); + + /// + /// Sets the author of the application package. + /// + /// The author value. + /// The instance for chaining. public ApplicationPackageBuilder Author(string value) => SetPropertyValue(value); + + /// + /// Sets the help file associated with the application package. + /// + /// The help file value. + /// The instance for chaining. public ApplicationPackageBuilder HelpFile(string value) => SetPropertyValue(value); + + /// + /// Sets the supported locales for the application package. + /// + /// The supported locales value. + /// The instance for chaining. public ApplicationPackageBuilder SupportedLocales(string value) => SetPropertyValue(value); + + /// + /// Sets the URL to the online documentation for the application package. + /// + /// The online documentation URL. + /// The instance for chaining. public ApplicationPackageBuilder OnlineDocumentation(string value) => SetPropertyValue(value); } diff --git a/Autodesk.PackageBuilder/Builder/Application/CompanyDetailsBuilder.cs b/Autodesk.PackageBuilder/Builder/Application/CompanyDetailsBuilder.cs index 8ef681f..2d03cfa 100644 --- a/Autodesk.PackageBuilder/Builder/Application/CompanyDetailsBuilder.cs +++ b/Autodesk.PackageBuilder/Builder/Application/CompanyDetailsBuilder.cs @@ -1,20 +1,49 @@ namespace Autodesk.PackageBuilder { using Model.Application; + /// + /// Provides a builder for constructing instances. + /// public class CompanyDetailsBuilder : SingleBuilderBase, ICompanyDetailsBuilder { + /// + /// Initializes a new instance of the class with the specified data. + /// + /// The instance to initialize the builder with. public CompanyDetailsBuilder(CompanyDetails companyDetails) { SetDataInternal(companyDetails); } + /// + /// Creates a new and sets the company name. + /// + /// The name of the company. + /// The current instance with the specified name set. public CompanyDetailsBuilder Create(string name) { return Name(name); } + /// + /// Sets the name of the company. + /// + /// The company name. + /// The current instance. private CompanyDetailsBuilder Name(string value) => SetPropertyValue(value); + + /// + /// Sets the URL of the company. + /// + /// The company URL. + /// The current instance. public CompanyDetailsBuilder Url(string value) => SetPropertyValue(value); + + /// + /// Sets the email address of the company. + /// + /// The company email address. + /// The current instance. public CompanyDetailsBuilder Email(string value) => SetPropertyValue(value); } diff --git a/Autodesk.PackageBuilder/Builder/Application/ComponentsBuilder.cs b/Autodesk.PackageBuilder/Builder/Application/ComponentsBuilder.cs index 40489ca..ebd246e 100644 --- a/Autodesk.PackageBuilder/Builder/Application/ComponentsBuilder.cs +++ b/Autodesk.PackageBuilder/Builder/Application/ComponentsBuilder.cs @@ -2,13 +2,25 @@ { using Model.Application; using System.Collections.Generic; + /// + /// Provides a builder for creating and configuring entries. + /// public class ComponentsBuilder : ListBuilderBase, IComponentsEntryBuilder { + /// + /// Initializes a new instance of the class with the specified components list. + /// + /// The list of to initialize the builder with. public ComponentsBuilder(List components) { SetDataInternal(components); } + /// + /// Creates a new entry with the specified description. + /// + /// The description for the components entry. + /// The current instance for further configuration. public ComponentsBuilder CreateEntry(string description) { CreateEntryInternal(); @@ -16,14 +28,67 @@ public ComponentsBuilder CreateEntry(string description) return this; } + /// + /// Sets the description for the current entry. + /// + /// The description value. + /// The current instance. private ComponentsBuilder Description(string value) => SetPropertyValue(value); + + /// + /// Sets the operating system requirement for the current entry. + /// + /// The operating system value. + /// The current instance. public ComponentsBuilder OS(string value) => SetNewPropertyValue(value); + + /// + /// Sets the platform requirement for the current entry. + /// + /// The platform value. + /// The current instance. public ComponentsBuilder Platform(string value) => SetNewPropertyValue(value); + + /// + /// Sets the minimum supported series version for the current entry. + /// + /// The minimum series version value. + /// The current instance. public ComponentsBuilder SeriesMin(string value) => SetNewPropertyValue(value); + + /// + /// Sets the maximum supported series version for the current entry. + /// + /// The maximum series version value. + /// The current instance. public ComponentsBuilder SeriesMax(string value) => SetNewPropertyValue(value); + + /// + /// Sets the application name for the current in the entry. + /// + /// The application name value. + /// The current instance. public ComponentsBuilder AppName(string value) => SetNewPropertyValue(value); + + /// + /// Sets the module name for the current in the entry. + /// + /// The module name value. + /// The current instance. public ComponentsBuilder ModuleName(string value) => SetNewPropertyValue(value); + + /// + /// Sets the version for the current in the entry. + /// + /// The version value. + /// The current instance. public ComponentsBuilder Version(string value) => SetNewPropertyValue(value); + + /// + /// Sets the application description for the current in the entry. + /// + /// The application description value. + /// The current instance. public ComponentsBuilder AppDescription(string value) => SetNewPropertyValue(value); } diff --git a/Autodesk.PackageBuilder/Builder/GuidExtension.cs b/Autodesk.PackageBuilder/Builder/GuidExtension.cs new file mode 100644 index 0000000..218db71 --- /dev/null +++ b/Autodesk.PackageBuilder/Builder/GuidExtension.cs @@ -0,0 +1,21 @@ +using System; + +namespace Autodesk.PackageBuilder; + +/// +/// Provides extension methods for the structure. +/// +internal static class GuidExtension +{ + /// + /// Converts a to its string representation in "B" format (enclosed in braces) and upper case. + /// + /// The to convert. + /// + /// A string representation of the GUID in "B" format (e.g., "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}") and upper case. + /// + public static string ToStringBraces(this Guid guid) + { + return guid.ToString("B").ToUpperInvariant(); + } +} diff --git a/Autodesk.PackageBuilder/Builder/InventorAddInsBuilder.cs b/Autodesk.PackageBuilder/Builder/InventorAddInsBuilder.cs new file mode 100644 index 0000000..8d48cee --- /dev/null +++ b/Autodesk.PackageBuilder/Builder/InventorAddInsBuilder.cs @@ -0,0 +1,52 @@ +namespace Autodesk.PackageBuilder; + +using Model.Addin; + +/// +/// Provides a builder for creating and serializing Autodesk Inventor Add-In definitions. +/// +public class InventorAddInsBuilder : IBuilder +{ + /// + /// The Inventor Add-In model instance being built. + /// + private readonly InventorAddIn inventorAddIns; + + /// + /// The builder for configuring Inventor Add-In entry properties. + /// + private readonly InventorAddInEntryBuilder _inventorAddInsEntryBuilder; + + /// + /// Gets the entry builder for configuring the Inventor Add-In. + /// + public IInventorAddInEntryBuilder AddIn => _inventorAddInsEntryBuilder; + + /// + /// Initializes a new instance of the class. + /// + public InventorAddInsBuilder() + { + inventorAddIns = new InventorAddIn(); + _inventorAddInsEntryBuilder = new InventorAddInEntryBuilder(inventorAddIns); + } + + /// + /// Serializes the Inventor Add-In definition to a file at the specified path with a ".addin" extension. + /// + /// The file path where the add-in definition will be saved. + /// The full path to the serialized add-in file. + public string Build(string path) + { + return inventorAddIns.SerializeFile(path, ".addin"); + } + + /// + /// Serializes the Inventor Add-In definition to an XML string. + /// + /// The XML representation of the add-in definition. + public override string ToString() + { + return inventorAddIns.SerializeObject(); + } +} \ No newline at end of file diff --git a/Autodesk.PackageBuilder/Builder/PackageContentsBuilder.cs b/Autodesk.PackageBuilder/Builder/PackageContentsBuilder.cs index b540322..c8b9cb4 100644 --- a/Autodesk.PackageBuilder/Builder/PackageContentsBuilder.cs +++ b/Autodesk.PackageBuilder/Builder/PackageContentsBuilder.cs @@ -2,6 +2,10 @@ { using Model.Application; + /// + /// Provides a builder for constructing and serializing an Autodesk application package, + /// including application metadata, company details, and components. + /// public class PackageContentsBuilder : IBuilder { private readonly ApplicationPackage applicationPackage; @@ -10,12 +14,24 @@ public class PackageContentsBuilder : IBuilder private readonly CompanyDetailsBuilder _companyDetailsBuilder; private readonly ComponentsBuilder _components; + /// + /// Gets the builder for configuring the application package metadata. + /// public IApplicationPackageBuilder ApplicationPackage => _applicationPackage; + /// + /// Gets the builder for configuring the company details. + /// public ICompanyDetailsBuilder CompanyDetails => _companyDetailsBuilder; + /// + /// Gets the builder for configuring the components entries. + /// public IComponentsEntryBuilder Components => _components; + /// + /// Initializes a new instance of the class. + /// public PackageContentsBuilder() { applicationPackage = new ApplicationPackage(); @@ -25,15 +41,19 @@ public PackageContentsBuilder() } /// - /// Build and serialize the PackageContents.xml file. + /// Builds and serializes the PackageContents.xml file to the specified path. /// - /// - /// + /// The directory path where the XML file will be saved. + /// The full file path of the generated PackageContents.xml file. public string Build(string path) { return applicationPackage.SerializeFile(path, "PackageContents.xml"); } + /// + /// Returns the XML string representation of the application package. + /// + /// A string containing the serialized XML of the application package. public override string ToString() { return applicationPackage.SerializeObject(); diff --git a/Autodesk.PackageBuilder/Builder/RevitAddInsBuilder.cs b/Autodesk.PackageBuilder/Builder/RevitAddInsBuilder.cs index 32a8361..0172000 100644 --- a/Autodesk.PackageBuilder/Builder/RevitAddInsBuilder.cs +++ b/Autodesk.PackageBuilder/Builder/RevitAddInsBuilder.cs @@ -1,36 +1,55 @@ namespace Autodesk.PackageBuilder { using Model.Addin; + /// + /// Provides a builder for creating and serializing Revit add-in configuration files (.addin). + /// public class RevitAddInsBuilder : IBuilder { + /// + /// The instance representing the collection of add-in entries. + /// private readonly RevitAddIns revitAddIns; + /// + /// The builder for configuring the entry. + /// private readonly RevitAddInsEntryBuilder _revitAddInsEntryBuilder; - private readonly AddInEntryBuilder _addInEntryBuilder; - public IAddInEntryBuilder AddIn => _addInEntryBuilder; + /// + /// The builder for configuring individual add-in entries. + /// + private readonly RevitAddInEntryBuilder _addInEntryBuilder; + /// + /// Gets the builder for creating and configuring add-in entries. + /// + public IRevitAddInEntryBuilder AddIn => _addInEntryBuilder; + + /// + /// Initializes a new instance of the class. + /// public RevitAddInsBuilder() { revitAddIns = new RevitAddIns(); _revitAddInsEntryBuilder = new RevitAddInsEntryBuilder(revitAddIns); - _addInEntryBuilder = new AddInEntryBuilder(revitAddIns.AddIn); + _addInEntryBuilder = new RevitAddInEntryBuilder(revitAddIns.AddIn); } /// - /// Build and serialize the .addin file. + /// Builds and serializes the Revit add-in configuration to a .addin file at the specified path. /// - /// - /// + /// The file path where the .addin file will be saved. + /// The full path to the serialized .addin file. public string Build(string path) { return revitAddIns.SerializeFile(path, ".addin"); } /// - /// Serialize the RevitAddIns object. + /// Serializes the object to its XML string representation. /// - /// + /// A string containing the XML representation of the Revit add-ins configuration. public override string ToString() { return revitAddIns.SerializeObject(); diff --git a/Autodesk.PackageBuilder/Constants/AutodeskProducts.cs b/Autodesk.PackageBuilder/Constants/AutodeskProducts.cs index 00f227b..360799b 100644 --- a/Autodesk.PackageBuilder/Constants/AutodeskProducts.cs +++ b/Autodesk.PackageBuilder/Constants/AutodeskProducts.cs @@ -1,10 +1,38 @@ namespace Autodesk.PackageBuilder { + /// + /// Provides constant product names for supported Autodesk products. + /// public static class AutodeskProducts { + /// + /// The product name for Autodesk Revit. + /// public const string Revit = "Revit"; + + /// + /// The product name for Autodesk AutoCAD. + /// public const string AutoCAD = "AutoCAD"; + + /// + /// The product name for Autodesk Inventor. + /// + public const string Inventor = "Inventor"; + + /// + /// The product name for Autodesk 3ds Max. + /// + public const string Max3ds = "3ds Max"; + + /// + /// The product name for Autodesk Maya. + /// public const string Maya = "Maya"; + + /// + /// The product name for Autodesk Navisworks. + /// public const string Navisworks = "Navisworks"; } diff --git a/Autodesk.PackageBuilder/Constants/ProductTypes.cs b/Autodesk.PackageBuilder/Constants/ProductTypes.cs index a53a2b4..304f7df 100644 --- a/Autodesk.PackageBuilder/Constants/ProductTypes.cs +++ b/Autodesk.PackageBuilder/Constants/ProductTypes.cs @@ -1,8 +1,18 @@ namespace Autodesk.PackageBuilder { + /// + /// Provides constant values for different product types supported by the package builder. + /// public static class ProductTypes { + /// + /// Represents the product type for applications. + /// public const string Application = "Application"; + + /// + /// Represents the product type for content packages. + /// public const string Content = "Content"; } diff --git a/Autodesk.PackageBuilder/Extensible/AutoCAD/AutoCADExtensibleData.cs b/Autodesk.PackageBuilder/Extensible/AutoCAD/AutoCADExtensibleData.cs new file mode 100644 index 0000000..344bb47 --- /dev/null +++ b/Autodesk.PackageBuilder/Extensible/AutoCAD/AutoCADExtensibleData.cs @@ -0,0 +1,117 @@ +using Autodesk.PackageBuilder.Model.Application; +using System.Collections.Generic; +using System.Linq; +using System.Xml.Serialization; + +namespace Autodesk.PackageBuilder.Extensible.AutoCAD; + +/// +/// Provides extension methods for configuring AutoCAD-specific extensible data on instances. +/// +/// +/// For more information, see the AutoCAD Developer Documentation: +/// https://help.autodesk.com/view/OARX/2025/ENU/?guid=GUID-3C25E517-8660-4BB7-9447-2310462EF06F +/// +public static partial class AutoCADExtensibleData +{ + /// + /// Sets the LoadOnAppearance attribute for the current in the entry. + /// + /// The instance to configure. + /// A value indicating whether the component should load on appearance. + /// The current instance for further configuration. + /// + /// LoadOnAppearance. Load when the product detects the application bundle in one of the ApplicationPlugins folders, thereby supporting instant load on installation with no need to restart the AutoCAD-based product. The parameter behaves the same way as LoadOnAutoCADStartup except the load context is relevant to when an application is installed while the product is running, for instance if installed via the Autodesk App Store website. + /// + public static ComponentsBuilder LoadOnAppearance(this ComponentsBuilder componentsBuilder, bool value = true) + { + componentsBuilder.DataBuilder.CreateAttribute("LoadOnAppearance", value); + return componentsBuilder; + } + + /// + /// Adds command definitions to the current in the entry. + /// + /// The instance to configure. + /// An array of command names to add as both global and local commands. + /// The current instance for further configuration. + public static ComponentsBuilder Commands(this ComponentsBuilder componentsBuilder, params string[] globalLocalCommands) + { + return componentsBuilder.CommandGroups(string.Empty, globalLocalCommands); + } + + /// + /// Adds command definitions to the current in the entry, optionally grouping them. + /// + /// The instance to configure. + /// The group name for the commands, or an empty string for no group. + /// An array of command names to add as both global and local commands. + /// The current instance for further configuration. + public static ComponentsBuilder CommandGroups(this ComponentsBuilder componentsBuilder, string groupName, params string[] globalLocalCommands) + { + if (globalLocalCommands is null) + return componentsBuilder; + + if (!globalLocalCommands.Any()) + return componentsBuilder; + + var autoCADCommands = new AutoCADCommands(); + + if (!string.IsNullOrWhiteSpace(groupName)) + { + autoCADCommands.GroupName = groupName; + } + + foreach (var globalLocalCommand in globalLocalCommands) + { + if (string.IsNullOrWhiteSpace(globalLocalCommand)) continue; + + autoCADCommands.Commands.Add( + new AutoCADCommand + { + Global = globalLocalCommand, + Local = globalLocalCommand + }); + } + + componentsBuilder.DataBuilder.CreateElement("Commands", autoCADCommands); + + return componentsBuilder; + } + + /// + /// Represents a collection of AutoCAD command definitions, optionally grouped by a name. + /// + public class AutoCADCommands : ExtensibleData + { + /// + /// Gets or sets the group name for the commands. If not specified, commands are not grouped. + /// + [XmlAttribute("GroupName")] + public string GroupName { get; set; } + + /// + /// Gets or sets the list of AutoCAD command definitions. + /// + [XmlElement("Command")] + public List Commands { get; set; } = new List(); + } + + /// + /// Represents a single AutoCAD command definition with global and local names. + /// + public class AutoCADCommand : ExtensibleData + { + /// + /// Gets or sets the global name of the command. + /// + [XmlAttribute("Global")] + public string Global { get; set; } + + /// + /// Gets or sets the local name of the command. + /// + [XmlAttribute("Local")] + public string Local { get; set; } + } +} diff --git a/Autodesk.PackageBuilder/Model/Addin/AddInApplication.cs b/Autodesk.PackageBuilder/Model/Addin/AddInApplication.cs deleted file mode 100644 index 702a624..0000000 --- a/Autodesk.PackageBuilder/Model/Addin/AddInApplication.cs +++ /dev/null @@ -1,31 +0,0 @@ -namespace Autodesk.PackageBuilder.Model.Addin -{ - using System.Xml; - using System.Xml.Serialization; - public class AddInApplication - { - [XmlAttribute] - public string Type { get; set; } - - [XmlElement] - public string Name { get; set; } - - [XmlElement] - public string Assembly { get; set; } - - [XmlElement] - public string AddInId { get; set; } - - [XmlElement] - public string FullClassName { get; set; } - - [XmlElement] - public string VendorId { get; set; } - - [XmlElement] - public string VendorDescription { get; set; } - - [XmlElement] - public bool AllowLoadingIntoExistingSession { get; set; } = true; - } -} diff --git a/Autodesk.PackageBuilder/Model/Addin/AddInModel.cs b/Autodesk.PackageBuilder/Model/Addin/AddInModel.cs deleted file mode 100644 index 8db7965..0000000 --- a/Autodesk.PackageBuilder/Model/Addin/AddInModel.cs +++ /dev/null @@ -1,28 +0,0 @@ -namespace Autodesk.PackageBuilder.Model.Addin -{ - using System.Xml; - using System.Xml.Serialization; - public class AddInModel - { - [XmlAttribute] - public string Type { get; set; } - - [XmlElement] - public string Name { get; set; } - - [XmlElement] - public string Assembly { get; set; } - - [XmlElement] - public string AddInId { get; set; } - - [XmlElement] - public string FullClassName { get; set; } - - [XmlElement] - public string VendorId { get; set; } - - [XmlElement] - public string VendorDescription { get; set; } - } -} diff --git a/Autodesk.PackageBuilder/Model/Addin/InventorAddIn.cs b/Autodesk.PackageBuilder/Model/Addin/InventorAddIn.cs new file mode 100644 index 0000000..da707f1 --- /dev/null +++ b/Autodesk.PackageBuilder/Model/Addin/InventorAddIn.cs @@ -0,0 +1,138 @@ +namespace Autodesk.PackageBuilder.Model.Addin; + +using System; +using System.Xml; +using System.Xml.Serialization; + +/// +/// Represents an Inventor Add-In definition for Autodesk Inventor packaging. +/// +/// +/// For more information, see the Inventor Developer Documentation: +/// https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=GUID-52422162-1784-4E8F-B495-CDB7BE9987AB +/// +[Serializable] +[XmlRoot("AddIn")] +public class InventorAddIn : ExtensibleData, IPackageSerializable +{ + /// + /// Gets or sets the type of the add-in. Typically "Standard" or "Application". + /// + [XmlAttribute] + public string Type { get; set; } + + /// + /// Gets or sets the COM class ID (GUID) of the add-in. + /// + [XmlElement] + public string ClassId { get; set; } + + /// + /// Gets or sets the client ID (GUID) of the add-in. + /// + [XmlElement] + public string ClientId { get; set; } + + /// + /// Gets or sets the display name of the add-in as shown in Inventor. + /// + [XmlElement] + public string DisplayName { get; set; } + + /// + /// Gets or sets the description of the add-in. + /// + [XmlElement] + public string Description { get; set; } + + /// + /// Gets or sets the path to the add-in assembly (DLL). + /// + [XmlElement] + public string Assembly { get; set; } + + /// + /// (Optional) Specifies whether the add-in should be allowed to load automatically as per the load behaviors defined by the add-in. + /// + /// + /// + /// This option can be specified using one of the following values: + /// 0 - The add-in needs to be manually loaded using the add-in manager. + /// 1 - The add-in can be loaded automatically as per the load behaviors defined by the add-in. + /// Assumed to be 1 if this value is not specified. (add-in loads automatically) + /// + /// + [XmlElement] + public int? LoadAutomatically { get; set; } + + /// + /// (Optional) Specifies when the add-in should be loaded in Inventor. This is important for better startup performance. + /// + /// + /// + /// This option can be specified using one of the following values: + /// 0 - Load immediately on startup (not recommended) + /// 1 - Load when any document is opened + /// 1 - Load when a part document is opened (same as previous) + /// 2 - Load when an assembly document is opened + /// 3 - Load when a presentation document is opened + /// 4 - Load when a drawing document is opened + /// 10 - Load only on demand, either through the API or using the Add-In Manager. + /// Assumed to be 0 if this value is not specified. (add-in loads immediately on startup) + /// + /// + [XmlElement] + public int? LoadBehavior { get; set; } + + /// + /// (Optional) Specifies whether the add-in can be unloaded by the user using the Add-In Manager. + /// + /// + /// + /// This option can be specified using one of the following values: + /// 0 - The add-in cannot be unloaded by the user. + /// 1 - The add-in can be unloaded by the user. + /// Assumed to be 1 if this value is not specified. (add-in is unloadable by user) + /// + /// + [XmlElement] + public int? UserUnloadable { get; set; } + + /// + /// Specifies whether the add-in should be hidden in the Add-in Manager’s list of add-ins. + /// + /// + /// + /// This option can be specified using one of the following values: + /// 0 - The add-in is visible in the Add-in Manager. + /// 1 - The add-in is hidden in the Add-in Manager. + /// Assumed to be 0 if this value is not specified. (add-in is visible) + /// + /// + [XmlElement] + public int? Hidden { get; set; } + + /// + /// Gets or sets the exact Inventor version this add-in supports. + /// + [XmlElement] + public string SupportedSoftwareVersionEqualTo { get; set; } + + /// + /// Gets or sets the minimum Inventor version (exclusive) this add-in supports. + /// + [XmlElement] + public string SupportedSoftwareVersionGreaterThan { get; set; } + + /// + /// Gets or sets the maximum Inventor version (exclusive) this add-in supports. + /// + [XmlElement] + public string SupportedSoftwareVersionLessThan { get; set; } + + /// + /// Gets or sets the Inventor version this add-in does not support. + /// + [XmlElement] + public string SupportedSoftwareVersionNotEqualTo { get; set; } +} \ No newline at end of file diff --git a/Autodesk.PackageBuilder/Model/Addin/RevitAddInData.cs b/Autodesk.PackageBuilder/Model/Addin/RevitAddInData.cs new file mode 100644 index 0000000..1207cfa --- /dev/null +++ b/Autodesk.PackageBuilder/Model/Addin/RevitAddInData.cs @@ -0,0 +1,52 @@ +namespace Autodesk.PackageBuilder.Model.Addin +{ + using System.Xml; + using System.Xml.Serialization; + /// + /// Represents an add-in model for Autodesk Package Builder, containing metadata for an add-in. + /// + public class RevitAddInData : ExtensibleData + { + /// + /// Gets or sets the type of the add-in. + /// + [XmlAttribute] + public string Type { get; set; } + + /// + /// Gets or sets the name of the add-in. + /// + [XmlElement] + public string Name { get; set; } + + /// + /// Gets or sets the assembly file name or path for the add-in. + /// + [XmlElement] + public string Assembly { get; set; } + + /// + /// Gets or sets the unique identifier for the add-in. + /// + [XmlElement] + public string AddInId { get; set; } + + /// + /// Gets or sets the fully qualified class name that implements the add-in. + /// + [XmlElement] + public string FullClassName { get; set; } + + /// + /// Gets or sets the vendor identifier for the add-in. + /// + [XmlElement] + public string VendorId { get; set; } + + /// + /// Gets or sets the vendor description for the add-in. + /// + [XmlElement] + public string VendorDescription { get; set; } + } +} diff --git a/Autodesk.PackageBuilder/Model/Addin/RevitAddIns.cs b/Autodesk.PackageBuilder/Model/Addin/RevitAddIns.cs index 1118023..a1e11f8 100644 --- a/Autodesk.PackageBuilder/Model/Addin/RevitAddIns.cs +++ b/Autodesk.PackageBuilder/Model/Addin/RevitAddIns.cs @@ -4,10 +4,16 @@ using System.Collections.Generic; using System.Xml; using System.Xml.Serialization; + /// + /// Represents a collection of Revit add-in definitions for XML serialization. + /// [Serializable] - public class RevitAddIns : IPackageSerializable + public class RevitAddIns : ExtensibleData, IPackageSerializable { + /// + /// Gets or sets the list of Revit add-in models. + /// [XmlElement] - public List AddIn { get; set; } = new List(); + public List AddIn { get; set; } = new List(); } } \ No newline at end of file diff --git a/Autodesk.PackageBuilder/Model/Application/ApplicationPackage.cs b/Autodesk.PackageBuilder/Model/Application/ApplicationPackage.cs index ad137c9..7b9ac4b 100644 --- a/Autodesk.PackageBuilder/Model/Application/ApplicationPackage.cs +++ b/Autodesk.PackageBuilder/Model/Application/ApplicationPackage.cs @@ -4,48 +4,111 @@ using System.Collections.Generic; using System.Xml; using System.Xml.Serialization; + /// + /// Represents an application package with metadata and components for XML serialization. + /// [Serializable] - public class ApplicationPackage : IPackageSerializable + public class ApplicationPackage : ExtensibleData, IPackageSerializable { + /// + /// Gets or sets the schema version of the application package. + /// [XmlAttribute] public string SchemaVersion { get; set; } + /// + /// Gets or sets the Autodesk product associated with this package. + /// [XmlAttribute] public string AutodeskProduct { get; set; } + /// + /// Gets or sets the name of the application package. + /// [XmlAttribute] public string Name { get; set; } + /// + /// Gets or sets the description of the application package. + /// [XmlAttribute] public string Description { get; set; } + /// + /// Gets or sets the application version. + /// [XmlAttribute] public string AppVersion { get; set; } + /// + /// Gets or sets the user-friendly version string. + /// [XmlAttribute] public string FriendlyVersion { get; set; } + /// + /// Gets or sets the product type of the application package. + /// [XmlAttribute] public string ProductType { get; set; } + /// + /// Gets or sets the product code of the application package. + /// [XmlAttribute] public string ProductCode { get; set; } + /// + /// Gets or sets the application namespace associated with the application package. + /// + /// + /// The is used in the 'apps.autodesk.com' to identify the application package for upgrades. + /// + [XmlAttribute] + public string AppNameSpace { get; set; } + + /// + /// Gets or sets the upgrade code of the application package. + /// + /// + /// The is used in the 'apps.autodesk.com' to identify the application package for upgrades. + /// + [XmlAttribute] + public string UpgradeCode { get; set; } + + /// + /// Gets or sets the author of the application package. + /// [XmlAttribute] public string Author { get; set; } + /// + /// Gets or sets the help file associated with the application package. + /// [XmlAttribute] public string HelpFile { get; set; } + /// + /// Gets or sets the supported locales for the application package. + /// [XmlAttribute] public string SupportedLocales { get; set; } + /// + /// Gets or sets the URL to the online documentation. + /// [XmlAttribute] public string OnlineDocumentation { get; set; } + /// + /// Gets or sets the company details associated with the application package. + /// [XmlElement] public CompanyDetails CompanyDetails { get; set; } = new CompanyDetails(); + /// + /// Gets or sets the list of components included in the application package. + /// [XmlElement] public List Components { get; set; } = new List(); } diff --git a/Autodesk.PackageBuilder/Model/Application/CompanyDetails.cs b/Autodesk.PackageBuilder/Model/Application/CompanyDetails.cs index 7c97a9f..8a80b9d 100644 --- a/Autodesk.PackageBuilder/Model/Application/CompanyDetails.cs +++ b/Autodesk.PackageBuilder/Model/Application/CompanyDetails.cs @@ -2,21 +2,44 @@ { using System.Xml; using System.Xml.Serialization; - public class CompanyDetails + /// + /// Represents company information including name, URL, and optional email address. + /// + public class CompanyDetails : ExtensibleData { + /// + /// Initializes a new instance of the class. + /// public CompanyDetails() { } + + /// + /// Initializes a new instance of the class with the specified name, URL, and optional email. + /// + /// The name of the company. + /// The URL of the company. + /// The email address of the company (optional). public CompanyDetails(string name, string url, string email = null) { Name = name; Url = url; Email = email; } + + /// + /// Gets or sets the name of the company. + /// [XmlAttribute] public string Name { get; set; } + /// + /// Gets or sets the URL of the company. + /// [XmlAttribute] public string Url { get; set; } + /// + /// Gets or sets the email address of the company. + /// [XmlAttribute] public string Email { get; set; } } diff --git a/Autodesk.PackageBuilder/Model/Application/ComponentEntry.cs b/Autodesk.PackageBuilder/Model/Application/ComponentEntry.cs index f19889c..0a62fd1 100644 --- a/Autodesk.PackageBuilder/Model/Application/ComponentEntry.cs +++ b/Autodesk.PackageBuilder/Model/Application/ComponentEntry.cs @@ -2,9 +2,23 @@ { using System.Xml; using System.Xml.Serialization; - public class ComponentEntry + /// + /// Represents an application component entry with metadata for XML serialization. + /// + public class ComponentEntry : ExtensibleData { + /// + /// Initializes a new instance of the class. + /// public ComponentEntry() { } + + /// + /// Initializes a new instance of the class with the specified parameters. + /// + /// The name of the application. + /// The name of the module. + /// The version of the component (optional). + /// The description of the application (optional). public ComponentEntry(string appName, string moduleName, string version = null, string appDescription = null) { AppName = appName; @@ -12,15 +26,28 @@ public ComponentEntry(string appName, string moduleName, string version = null, Version = version; AppDescription = appDescription; } + + /// + /// Gets or sets the name of the application. + /// [XmlAttribute] public string AppName { get; set; } + /// + /// Gets or sets the name of the module. + /// [XmlAttribute] public string ModuleName { get; set; } + /// + /// Gets or sets the version of the component. + /// [XmlAttribute] public string Version { get; set; } + /// + /// Gets or sets the description of the application. + /// [XmlAttribute] public string AppDescription { get; set; } } diff --git a/Autodesk.PackageBuilder/Model/Application/Components.cs b/Autodesk.PackageBuilder/Model/Application/Components.cs index 4dfccbe..6b414da 100644 --- a/Autodesk.PackageBuilder/Model/Application/Components.cs +++ b/Autodesk.PackageBuilder/Model/Application/Components.cs @@ -2,14 +2,26 @@ { using System.Xml; using System.Xml.Serialization; - public class Components + /// + /// Represents a collection of application components, including runtime requirements and a component entry. + /// + public class Components : ExtensibleData { + /// + /// Gets or sets the description of the components. + /// [XmlAttribute] public string Description { get; set; } + /// + /// Gets or sets the runtime requirements for the components. + /// [XmlElement] public RuntimeRequirements RuntimeRequirements { get; set; } + /// + /// Gets or sets the component entry associated with the components. + /// [XmlElement] public ComponentEntry ComponentEntry { get; set; } } diff --git a/Autodesk.PackageBuilder/Model/Application/RuntimeRequirements.cs b/Autodesk.PackageBuilder/Model/Application/RuntimeRequirements.cs index 508b862..f5cadbd 100644 --- a/Autodesk.PackageBuilder/Model/Application/RuntimeRequirements.cs +++ b/Autodesk.PackageBuilder/Model/Application/RuntimeRequirements.cs @@ -2,12 +2,25 @@ { using System.Xml; using System.Xml.Serialization; - public class RuntimeRequirements + /// + /// Represents the runtime requirements for an application, including operating system, platform, and supported series range. + /// + public class RuntimeRequirements : ExtensibleData { + /// + /// Initializes a new instance of the class. + /// public RuntimeRequirements() { - } + + /// + /// Initializes a new instance of the class with the specified parameters. + /// + /// The operating system required. + /// The platform required. + /// The minimum supported series version. + /// The maximum supported series version. public RuntimeRequirements(string os, string platform, string seriesMin, string seriesMax) { OS = os; @@ -16,15 +29,27 @@ public RuntimeRequirements(string os, string platform, string seriesMin, string SeriesMax = seriesMax; } + /// + /// Gets or sets the required operating system. + /// [XmlAttribute] public string OS { get; set; } + /// + /// Gets or sets the required platform. + /// [XmlAttribute] public string Platform { get; set; } + /// + /// Gets or sets the minimum supported series version. + /// [XmlAttribute] public string SeriesMin { get; set; } + /// + /// Gets or sets the maximum supported series version. + /// [XmlAttribute] public string SeriesMax { get; set; } } diff --git a/Autodesk.PackageBuilder/Model/Data/ExtensibleData.cs b/Autodesk.PackageBuilder/Model/Data/ExtensibleData.cs new file mode 100644 index 0000000..c489e3d --- /dev/null +++ b/Autodesk.PackageBuilder/Model/Data/ExtensibleData.cs @@ -0,0 +1,126 @@ +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Xml; +using System.Xml.Schema; +using System.Xml.Serialization; + +namespace Autodesk.PackageBuilder; +/// +/// Represents a base class for XML-serializable data models, supporting dynamic attributes and elements. +/// +public class ExtensibleData : IXmlSerializable +{ + /// + /// Gets the auxiliary dictionary for storing additional attributes and elements. + /// The key is the name, and the value is a tuple containing the value and a flag indicating if it is an element. + /// + internal Dictionary Auxiliary { get; } = new(); + + /// + /// This method is reserved and should not be used. When implementing the IXmlSerializable interface, you should return null from this method. + /// + /// Always returns null. + public XmlSchema GetSchema() => null; + + /// + /// Reads the XML representation of the object. Not implemented. + /// + /// The stream from which the object is deserialized. + /// Always thrown. + public void ReadXml(XmlReader reader) => throw new System.NotImplementedException(); + + /// + /// Writes the XML representation of the object, including properties and auxiliary attributes/elements. + /// + /// The stream to which the object is serialized. + public void WriteXml(XmlWriter writer) + { + var properties = this.GetType().GetProperties() + .OrderBy(x => x.MetadataToken) + .Where(p => p.GetCustomAttributes(typeof(XmlIgnoreAttribute), true).Length == 0) + .ToList(); + + var propertiesElements = properties + .Where(p => p.GetCustomAttributes(typeof(XmlElementAttribute), true).Length > 0) + .ToList(); + + var propertiesAttributes = properties + .Where(p => p.GetCustomAttributes(typeof(XmlElementAttribute), true).Length == 0) + .ToList(); + + // Write property attributes as XML attributes + foreach (var p in propertiesAttributes) + { + var attributeName = p.GetCustomAttribute()?.AttributeName; + var name = string.IsNullOrWhiteSpace(attributeName) ? p.Name : attributeName; + + var value = p.GetValue(this); + if (value != null) + { + writer.WriteAttributeString(name, value.ToString()); + } + } + + // Write auxiliary attributes + foreach (var kvp in Auxiliary) + { + if (!kvp.Value.IsElement) + { + writer.WriteAttributeString(kvp.Key, kvp.Value.Value.ToString()); + } + } + + var namespaces = new XmlSerializerNamespaces(); + namespaces.Add(string.Empty, string.Empty); + + // Write property elements as XML elements + foreach (var p in propertiesElements) + { + var value = p.GetValue(this); + if (value != null) + { + var elementName = p.GetCustomAttribute()?.ElementName; + var name = string.IsNullOrWhiteSpace(elementName) ? p.Name : elementName; + if (value is IEnumerable collection && value is not string) + { + foreach (var item in collection) + { + var itemSerializer = new XmlSerializer(item.GetType(), new XmlRootAttribute(name)); + itemSerializer.Serialize(writer, item, namespaces); + } + continue; + } + + var elementSerializer = new XmlSerializer(value.GetType(), new XmlRootAttribute(name)); + elementSerializer.Serialize(writer, value, namespaces); + } + } + + // Write auxiliary elements + foreach (var kvp in Auxiliary) + { + if (kvp.Value.IsElement) + { + var value = kvp.Value.Value; + if (value != null) + { + var elementName = value.GetType().GetCustomAttribute()?.ElementName; + var name = string.IsNullOrWhiteSpace(elementName) ? kvp.Key : elementName; + if (value is IEnumerable collection && value is not string) + { + foreach (var item in collection) + { + var itemSerializer = new XmlSerializer(item.GetType(), new XmlRootAttribute(name)); + itemSerializer.Serialize(writer, item, namespaces); + } + continue; + } + var elementSerializer = new XmlSerializer(value.GetType(), new XmlRootAttribute(name)); + elementSerializer.Serialize(writer, value, namespaces); + } + } + } + } +} \ No newline at end of file diff --git a/Autodesk.PackageBuilder/Model/Data/ExtensibleDataExtension.cs b/Autodesk.PackageBuilder/Model/Data/ExtensibleDataExtension.cs new file mode 100644 index 0000000..d7a0ab7 --- /dev/null +++ b/Autodesk.PackageBuilder/Model/Data/ExtensibleDataExtension.cs @@ -0,0 +1,48 @@ +namespace Autodesk.PackageBuilder; + +/// +/// Provides extension methods for the class to add dynamic attributes and elements. +/// +public static class ExtensibleDataExtension +{ + /// + /// Adds an attribute to the model. + /// + /// A type derived from . + /// The model to which the attribute will be added. + /// The name of the attribute. + /// The value of the attribute. + /// The modified model instance. + public static T CreateDataAttribute(this T model, string name, object value) where T : ExtensibleData + { + model.Auxiliary.Add(name, (value, false)); + return model; + } + + /// + /// Adds a new entry element with the specified name to the model. + /// + /// A type derived from . + /// The model to which the entry element will be added. + /// The name of the entry element. + /// The newly created entry element. + public static ExtensibleData CreateDataElement(this T model, string name) where T : ExtensibleData + { + return model.CreateDataElement(name, new ExtensibleData()); + } + + /// + /// Adds a new entry element with the specified name and value to the model. + /// + /// A type derived from . + /// The type of the entry element value. + /// The model to which the entry element will be added. + /// The name of the entry element. + /// The value of the entry element. + /// The entry element value. + public static TElement CreateDataElement(this T model, string name, TElement value) where T : ExtensibleData + { + model.Auxiliary.Add(name, (value, true)); + return value; + } +} diff --git a/Autodesk.PackageBuilder/Utils/AutoCADUtils.cs b/Autodesk.PackageBuilder/Utils/AutoCADUtils.cs new file mode 100644 index 0000000..eed3078 --- /dev/null +++ b/Autodesk.PackageBuilder/Utils/AutoCADUtils.cs @@ -0,0 +1,218 @@ +using System; + +namespace Autodesk.PackageBuilder; + +/// +/// Provides utility extension methods for configuring AutoCAD-specific application packages and components. +/// +/// +/// For more information, see the AutoCAD Developer Documentation: +/// https://help.autodesk.com/view/OARX/2025/ENU/?guid=GUID-BC76355D-682B-46ED-B9B7-66C95EEF2BD0 +/// +public static class AutoCADUtils +{ + /// + /// The default operating system for AutoCAD application packages (Windows 64-bit). + /// + public const string Os = "Win64"; + /// + /// The default platform string for all AutoCAD-based products ("AutoCAD*"). + /// + public const string Platform = "AutoCAD*"; // AutoCAD* - All AutoCAD-based products + + /// + /// Configures the for an AutoCAD application package. + /// + /// The application package builder instance. + /// The instance for chaining. + public static ApplicationPackageBuilder AutoCADApplication(this ApplicationPackageBuilder applicationPackageBuilder) + { + return applicationPackageBuilder + .ProductType(ProductTypes.Application) + .AutodeskProduct(AutodeskProducts.AutoCAD); + } + + /// + /// Configures the for the specified AutoCAD version on Windows 64-bit. + /// + /// The components builder instance. + /// The AutoCAD version as a string (e.g., "24.0"). + /// The instance for chaining. + /// + /// This overload parses the version string and delegates to the overload. + /// + public static ComponentsBuilder AutoCADPlatform(this ComponentsBuilder componentsBuilder, string autoCADVersion) + { + if (Version.TryParse(autoCADVersion, out var version)) + { + return componentsBuilder.AutoCADPlatform(version); + } + throw new ArgumentException($"Invalid AutoCAD version format: {autoCADVersion}", nameof(autoCADVersion)); + } + + /// + /// Configures the for the specified AutoCAD version on Windows 64-bit. + /// + /// The components builder instance. + /// The AutoCAD version. + /// The instance for chaining. + /// + /// The platform is set to "AutoCAD*" to include all AutoCAD-based products. + /// + public static ComponentsBuilder AutoCADPlatform(this ComponentsBuilder componentsBuilder, Version autoCADVersion) + { + return componentsBuilder.AutoCADPlatform(Os, Platform, autoCADVersion); + } + + /// + /// Configures the for the specified OS, platform, and AutoCAD version. + /// + /// The components builder instance. + /// The operating system (e.g., "Win64"). + /// The platform (e.g., "AutoCAD*"). + /// The AutoCAD version as a string (e.g., "24.0"). + /// The instance for chaining. + /// Thrown if is not a valid version string. + /// + /// This overload parses the version string and delegates to the overload. + /// + public static ComponentsBuilder AutoCADPlatform(this ComponentsBuilder componentsBuilder, string os, string platform, string autoCADVersion) + { + if (Version.TryParse(autoCADVersion, out var version)) + { + return componentsBuilder.AutoCADPlatform(os, platform, version); + } + throw new ArgumentException($"Invalid AutoCAD version format: {autoCADVersion}", nameof(autoCADVersion)); + } + + /// + /// Configures the for the specified OS, platform, and AutoCAD version. + /// + /// The components builder instance. + /// The operating system (e.g., "Win64"). + /// The platform (e.g., "AutoCAD*"). + /// The AutoCAD version. + /// The instance for chaining. + /// + /// For more information, see the AutoCAD Developer Documentation: + /// https://help.autodesk.com/view/OARX/2024/ENU/?guid=GUID-1591CA01-EF87-48CD-952B-772FE26037F1 + /// + public static ComponentsBuilder AutoCADPlatform(this ComponentsBuilder componentsBuilder, string os, string platform, Version autoCADVersion) + { + return componentsBuilder.AutoCADPlatform(os, platform, autoCADVersion, autoCADVersion); + } + + /// + /// Configures the for a range of AutoCAD versions on Windows 64-bit. + /// + /// The components builder instance. + /// The minimum AutoCAD version as a string (e.g., "24.0"). + /// The maximum AutoCAD version as a string (e.g., "25.0"). + /// + /// If true, sets the maximum version to one less than . + /// + /// The instance for chaining. + /// + /// Thrown if is not a valid version string. + /// + /// + /// This overload parses the version strings and delegates to the overload. + /// + public static ComponentsBuilder AutoCADPlatform(this ComponentsBuilder componentsBuilder, string minVersion, string maxVersion, bool maxVersionMinusOne = false) + { + if (Version.TryParse(minVersion, out var version)) + { + Version.TryParse(maxVersion, out var versionMax); + return componentsBuilder.AutoCADPlatform(version, versionMax, maxVersionMinusOne); + } + throw new ArgumentException($"Invalid AutoCAD version format: {minVersion}", nameof(minVersion)); + } + + /// + /// Configures the for a range of AutoCAD versions on Windows 64-bit. + /// + /// The components builder instance. + /// The minimum AutoCAD version. + /// The maximum AutoCAD version. + /// If true, sets the maximum version to one less than . + /// The instance for chaining. + /// + /// The platform is set to "AutoCAD*" to include all AutoCAD-based products. + /// + public static ComponentsBuilder AutoCADPlatform(this ComponentsBuilder componentsBuilder, Version minVersion, Version maxVersion, bool maxVersionMinusOne = false) + { + return componentsBuilder.AutoCADPlatform(Os, Platform, minVersion, maxVersion, maxVersionMinusOne); + } + + /// + /// Configures the for the specified OS, platform, and AutoCAD version range. + /// + /// The components builder instance. + /// The operating system (e.g., "Win64"). + /// The platform (e.g., "AutoCAD*"). + /// The minimum AutoCAD version as a string (e.g., "24.0"). + /// The maximum AutoCAD version as a string (e.g., "25.0"). + /// + /// If true, sets the maximum version to one less than . + /// + /// The instance for chaining. + /// + /// Thrown if is not a valid version string. + /// + /// + /// This overload parses the version strings and delegates to the overload. + /// + public static ComponentsBuilder AutoCADPlatform(this ComponentsBuilder componentsBuilder, string os, string platform, string minVersion, string maxVersion, bool maxVersionMinusOne = false) + { + if (Version.TryParse(minVersion, out var version)) + { + Version.TryParse(maxVersion, out var versionMax); + return componentsBuilder.AutoCADPlatform(os, platform, version, versionMax, maxVersionMinusOne); + } + throw new ArgumentException($"Invalid AutoCAD version format: {minVersion}", nameof(minVersion)); + } + + /// + /// Configures the for a range of AutoCAD versions, with options for OS, platform, and version range. + /// + /// The components builder instance. + /// The operating system (e.g., "Win64"). + /// The platform (e.g., "AutoCAD*"). + /// The minimum AutoCAD version. + /// The maximum AutoCAD version. + /// If true, sets the maximum version to one less than . + /// The instance for chaining. + /// + /// For more information, see the AutoCAD Developer Documentation: + /// https://help.autodesk.com/view/OARX/2024/ENU/?guid=GUID-1591CA01-EF87-48CD-952B-772FE26037F1 + /// + public static ComponentsBuilder AutoCADPlatform(this ComponentsBuilder componentsBuilder, string os, string platform, Version minVersion, Version maxVersion, bool maxVersionMinusOne = false) + { + var minVersionString = "R" + minVersion.ToString(2); + var maxVersionString = "R" + maxVersion?.ToString(2); + + componentsBuilder + .OS(os) + .Platform(platform) + .SeriesMin(minVersionString); + + if (maxVersion is null) + return componentsBuilder; + + componentsBuilder.SeriesMax(maxVersionString); + + if (minVersionString == maxVersionString) + return componentsBuilder; + + if (maxVersionMinusOne) + { + var maxVersionMinus = maxVersion.Minor == 0 ? + new Version(maxVersion.Major - 1, 9) : + new Version(maxVersion.Major, maxVersion.Minor - 1); + + componentsBuilder.SeriesMax("R" + maxVersionMinus.ToString(2)); + } + + return componentsBuilder; + } +} diff --git a/Autodesk.PackageBuilder/Utils/BuilderUtils.cs b/Autodesk.PackageBuilder/Utils/BuilderUtils.cs index 98ebc8a..c07f4c9 100644 --- a/Autodesk.PackageBuilder/Utils/BuilderUtils.cs +++ b/Autodesk.PackageBuilder/Utils/BuilderUtils.cs @@ -19,7 +19,7 @@ public static TBuilder Build() } /// - /// Create a new instance of the type and . + /// Create a new instance of the type and . /// /// /// @@ -33,7 +33,7 @@ public static TBuilder Build(string path) } /// - /// Create a new instance of the type, the instance, and . + /// Create a new instance of the type, the instance, and . /// /// /// @@ -46,7 +46,7 @@ public static TBuilder Build(string path, Action config) } /// - /// Create a new instance of the type, the instance, and . + /// Create a new instance of the type, the instance, and . /// /// /// diff --git a/Autodesk.PackageBuilder/Utils/InventorUtils.cs b/Autodesk.PackageBuilder/Utils/InventorUtils.cs new file mode 100644 index 0000000..76e6c96 --- /dev/null +++ b/Autodesk.PackageBuilder/Utils/InventorUtils.cs @@ -0,0 +1,263 @@ +using System; + +namespace Autodesk.PackageBuilder; + +/// +/// Provides utility extension methods for configuring Inventor-specific application packages and components. +/// +/// +/// For more information, see the Inventor Developer Documentation: +/// https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=GUID-52422162-1784-4E8F-B495-CDB7BE9987AB +/// +public static class InventorUtils +{ + /// + /// The default operating system for Inventor application packages (Windows 64-bit). + /// + public const string Os = "Win64"; + + /// + /// The default platform string for all Inventor-based products ("Inventor"). + /// + public const string Platform = "Inventor"; + + /// + /// Configures the for an Inventor application package. + /// + /// The application package builder instance. + /// + /// The instance for chaining, configured for Inventor. + /// + public static ApplicationPackageBuilder InventorApplication(this ApplicationPackageBuilder applicationPackageBuilder) + { + return applicationPackageBuilder + .ProductType(ProductTypes.Application) + .AutodeskProduct(AutodeskProducts.Inventor); + } + + /// + /// Configures the for the default Inventor platform and operating system. + /// + /// The components builder instance. + /// + /// The instance for chaining, configured for Inventor's default OS and platform. + /// + public static ComponentsBuilder InventorPlatform(this ComponentsBuilder componentsBuilder) + { + return componentsBuilder + .OS(Os) + .Platform(Platform); + } + + /// + /// Configures the for a specified operating system and platform. + /// + /// The components builder instance. + /// The operating system to set. + /// The platform to set. + /// + /// The instance for chaining, configured for the specified OS and platform. + /// + public static ComponentsBuilder InventorPlatform(this ComponentsBuilder componentsBuilder, string os, string platform) + { + return componentsBuilder + .OS(os) + .Platform(platform); + } + + /// + /// Configures the for the default Inventor platform and operating system, + /// and restricts the supported internal Inventor version range using integer major versions. + /// + /// The instance to configure. + /// The minimum supported internal Inventor version as an integer (e.g., 25 for Inventor 2021). + /// The maximum supported internal Inventor version as an integer. + /// + /// If true, the maximum version is treated as inclusive (i.e., less than or equal to ). + /// If false (default), the maximum version is exclusive (i.e., less than minus one). + /// + /// + /// The instance for chaining, configured for Inventor's default OS, platform, and version range. + /// + public static ComponentsBuilder InventorPlatform(this ComponentsBuilder componentsBuilder, int minInternalVersion, int maxInternalVersion, bool maxVersionMinusOne = false) + { + return componentsBuilder.InventorPlatform(new Version(minInternalVersion, 0), new Version(maxInternalVersion, 0), maxVersionMinusOne); + } + + /// + /// Configures the for the default Inventor platform and operating system, + /// and restricts the supported internal Inventor version range. + /// + /// The instance to configure. + /// The minimum supported internal Inventor version as a (e.g., 25 for Inventor 2021). + /// The maximum supported internal Inventor version as a . + /// + /// If true, the maximum version is treated as inclusive (i.e., less than or equal to ). + /// If false (default), the maximum version is exclusive (i.e., less than minus one). + /// + /// + /// The instance for chaining, configured for Inventor's default OS, platform, and version range. + /// + public static ComponentsBuilder InventorPlatform(this ComponentsBuilder componentsBuilder, Version minVersion, Version maxVersion, bool maxVersionMinusOne = false) + { + return componentsBuilder.InventorPlatform(Os, Platform, minVersion, maxVersion, maxVersionMinusOne); + } + + /// + /// Configures the for a specified operating system, platform, and Inventor version range. + /// + /// The instance to configure. + /// The operating system to set (e.g., "Win64"). + /// The platform to set (e.g., "Inventor"). + /// The minimum supported internal Inventor version as a (e.g., 25 for Inventor 2021). + /// The maximum supported internal Inventor version as a . If null or major is 0, no upper bound is set. + /// + /// If true, the maximum version is treated as inclusive (i.e., less than or equal to ). + /// If false (default), the maximum version is exclusive (i.e., less than minus one). + /// + /// + /// The instance for chaining, configured for the specified OS, platform, and version range. + /// + public static ComponentsBuilder InventorPlatform(this ComponentsBuilder componentsBuilder, string os, string platform, Version minVersion, Version maxVersion, bool maxVersionMinusOne = false) + { + var minVersionString = minVersion.ToIrMajorString(); + var maxVersionString = maxVersion?.ToIrMajorString(); + + componentsBuilder + .OS(os) + .Platform(platform) + .SeriesMin(minVersionString); + + if (minVersionString == maxVersionString) + { + return componentsBuilder + .SeriesMax(maxVersionString); + } + + if (maxVersion is null || maxVersion.Major == 0) + return componentsBuilder; + + if (maxVersionMinusOne) + { + maxVersionString = maxVersion.ToIrMajorString(-1); + } + + return componentsBuilder + .SeriesMax(maxVersionString); + } + + /// + /// Configures the supported Inventor software version for the add-in entry builder using an integer major version. + /// + /// The instance to configure. + /// The major version of Inventor to support. + /// + /// The instance for chaining, configured with the specified supported software version. + /// + public static InventorAddInEntryBuilder SupportedSoftwareVersion(this InventorAddInEntryBuilder builder, int version) + { + return builder.SupportedSoftwareVersion(new Version(version, 0)); + } + + /// + /// Configures the supported Inventor software version for the add-in entry builder using a object. + /// + /// The instance to configure. + /// The of Inventor to support. + /// + /// The instance for chaining, configured with the specified supported software version. + /// + public static InventorAddInEntryBuilder SupportedSoftwareVersion(this InventorAddInEntryBuilder builder, Version version) + { + return builder.SupportedSoftwareVersion(version, version); + } + + /// + /// Configures the supported Inventor software version range for the add-in entry builder using integer major versions. + /// + /// The instance to configure. + /// The minimum supported major version (inclusive if equal to , otherwise exclusive). + /// + /// The maximum supported major version (exclusive by default, or inclusive if is true). + /// + /// + /// If true, the maximum version is treated as inclusive (i.e., less than or equal to ). + /// If false (default), the maximum version is exclusive (i.e., less than plus one). + /// + /// + /// The instance for chaining, configured with the specified supported software version range. + /// + public static InventorAddInEntryBuilder SupportedSoftwareVersion(this InventorAddInEntryBuilder builder, int minVersion, int maxVersion, bool maxVersionMinusOne = false) + { + return builder.SupportedSoftwareVersion(new Version(minVersion, 0), new Version(maxVersion, 0), maxVersionMinusOne); + } + + /// + /// Configures the supported Inventor software version range for the add-in entry builder. + /// + /// The instance to configure. + /// The minimum supported (inclusive if equal to , otherwise exclusive). + /// + /// The maximum supported (exclusive by default, or inclusive if is true). + /// If null, no upper bound is set. + /// + /// + /// If true, the maximum version is treated as inclusive (i.e., less than or equal to ). + /// If false (default), the maximum version is exclusive (i.e., less than plus one). + /// + /// + /// The instance for chaining, configured with the specified supported software version range. + /// + public static InventorAddInEntryBuilder SupportedSoftwareVersion(this InventorAddInEntryBuilder builder, Version minVersion, Version maxVersion, bool maxVersionMinusOne = false) + { + var minVersionString = minVersion.ToMajorString(); + var maxVersionString = maxVersion?.ToMajorString(); + + if (minVersionString == maxVersionString) + { + return builder.SupportedSoftwareVersionEqualTo(minVersionString); + } + + var greaterVersionString = minVersion.ToMajorString(-1); + builder.SupportedSoftwareVersionGreaterThan(greaterVersionString); + + if (maxVersion is null || maxVersion.Major == 0) + return builder; + + var lessVersionString = maxVersion.ToMajorString(1); + if (maxVersionMinusOne) + { + lessVersionString = maxVersionString; + } + + builder.SupportedSoftwareVersionLessThan(lessVersionString); + + return builder; + } + + + /// + /// Converts a object to a string containing only its major version followed by two dots. + /// + /// The instance to convert. + /// An optional value to add to the major version before converting to string. + /// + /// A string in the format "{major}..", where {major} is the major version number of the specified plus . + /// Returns null if is null. + /// + private static string ToMajorString(this Version version, int majorPlus = 0) + { + if (version is null) + return null; + + return $"{version.Major + majorPlus}.."; + } + + private static string ToIrMajorString(this Version version, int majorPlus = 0) + { + if (version is null) + return null; + + return $"Ir{version.Major + majorPlus}"; + } +} diff --git a/Autodesk.PackageBuilder/Utils/Max3dsUtils.cs b/Autodesk.PackageBuilder/Utils/Max3dsUtils.cs new file mode 100644 index 0000000..6b22549 --- /dev/null +++ b/Autodesk.PackageBuilder/Utils/Max3dsUtils.cs @@ -0,0 +1,91 @@ +namespace Autodesk.PackageBuilder; + +/// +/// Provides utility extension methods for configuring 3ds Max-specific application packages and components. +/// +/// +/// For more information, see the 3ds Max Developer Documentation: +/// https://help.autodesk.com/view/3DSMAX/2019/ENU/?guid=__developer_writing_plug_ins_packaging_plugins_packagexml_example_html +/// +public static class Max3dsUtils +{ + /// + /// The default operating system for 3ds Max application packages (Windows 64-bit). + /// + public const string Os = "Win64"; + + /// + /// The default platform string for all 3ds Max-based products ("3ds Max"). + /// + public const string Platform = "3ds Max"; + + /// + /// Configures the for a 3ds Max application package. + /// + /// The application package builder instance. + /// + /// The instance for chaining, configured for 3ds Max. + /// + public static ApplicationPackageBuilder Max3dsApplication(this ApplicationPackageBuilder applicationPackageBuilder) + { + return applicationPackageBuilder + .ProductType(ProductTypes.Application) + .AutodeskProduct(AutodeskProducts.Max3ds); + } + + /// + /// Configures the for the default 3ds Max platform and operating system, + /// targeting a specific 3ds Max version. + /// + /// The components builder instance. + /// The 3ds Max version to target. + /// + /// The instance for chaining, configured for the specified 3ds Max version. + /// + public static ComponentsBuilder Max3dsPlatform(this ComponentsBuilder componentsBuilder, int version) + { + return componentsBuilder.Max3dsPlatform(version, version); + } + + /// + /// Configures the for the default 3ds Max platform and operating system. + /// + /// The components builder instance. + /// The minimum supported 3ds Max version. If less than or equal to 0, the minimum version is not set. + /// The maximum supported 3ds Max version. If less than or equal to 0, the maximum version is not set. + /// + /// The instance for chaining, configured for 3ds Max's default OS and platform. + /// + public static ComponentsBuilder Max3dsPlatform(this ComponentsBuilder componentsBuilder, int minVersion, int maxVersion) + { + return componentsBuilder.Max3dsPlatform(Os, Platform, minVersion, maxVersion); + } + + /// + /// Configures the for a specified operating system, platform, and 3ds Max version range. + /// + /// The components builder instance. + /// The operating system to set (e.g., "Win64"). + /// The platform to set (e.g., "3ds Max"). + /// The minimum supported 3ds Max version. If less than or equal to 0, the minimum version is not set. + /// The maximum supported 3ds Max version. If less than or equal to 0, the maximum version is not set. + /// + /// The instance for chaining, configured for the specified OS, platform, and version range. + /// + public static ComponentsBuilder Max3dsPlatform(this ComponentsBuilder componentsBuilder, string os, string platform, int minVersion, int maxVersion) + { + componentsBuilder.OS(os) + .Platform(platform); + + if (minVersion > 0) + { + componentsBuilder.SeriesMin(minVersion.ToString()); + } + if (maxVersion > 0) + { + componentsBuilder.SeriesMax(maxVersion.ToString()); + } + + return componentsBuilder; + } +} diff --git a/Autodesk.PackageBuilder/Utils/MayaUtils.cs b/Autodesk.PackageBuilder/Utils/MayaUtils.cs new file mode 100644 index 0000000..eba8ac5 --- /dev/null +++ b/Autodesk.PackageBuilder/Utils/MayaUtils.cs @@ -0,0 +1,91 @@ +namespace Autodesk.PackageBuilder; + +/// +/// Provides utility extension methods for configuring Maya-specific application packages and components. +/// +/// +/// For more information, see the Maya Developer Documentation: +/// https://help.autodesk.com/view/MAYAUL/2024/ENU/?guid=Maya_SDK_Distributing_Maya_Plug_ins_DistributingViaTheAppStore_html +/// +public static class MayaUtils +{ + /// + /// The default operating system for Maya application packages (Windows 64-bit). + /// + public const string Os = "Win64"; + + /// + /// The default platform string for all Maya-based products ("Maya"). + /// + public const string Platform = "Maya"; + + /// + /// Configures the for a Maya application package. + /// + /// The application package builder instance. + /// + /// The instance for chaining, configured for Maya. + /// + public static ApplicationPackageBuilder MayaApplication(this ApplicationPackageBuilder applicationPackageBuilder) + { + return applicationPackageBuilder + .ProductType(ProductTypes.Application) + .AutodeskProduct(AutodeskProducts.Maya); + } + + /// + /// Configures the for the default Maya platform and operating system, + /// targeting a specific Maya version. + /// + /// The components builder instance. + /// The Maya version to target. + /// + /// The instance for chaining, configured for the specified Maya version. + /// + public static ComponentsBuilder MayaPlatform(this ComponentsBuilder componentsBuilder, int version) + { + return componentsBuilder.MayaPlatform(version, version); + } + + /// + /// Configures the for the default Maya platform and operating system. + /// + /// The components builder instance. + /// The minimum supported Maya version. If less than or equal to 0, the minimum version is not set. + /// The maximum supported Maya version. If less than or equal to 0, the maximum version is not set. + /// + /// The instance for chaining, configured for Maya's default OS and platform. + /// + public static ComponentsBuilder MayaPlatform(this ComponentsBuilder componentsBuilder, int minVersion, int maxVersion) + { + return componentsBuilder.MayaPlatform(Os, Platform, minVersion, maxVersion); + } + + /// + /// Configures the for a specified operating system, platform, and Maya version range. + /// + /// The components builder instance. + /// The operating system to set (e.g., "Win64"). + /// The platform to set (e.g., "Maya"). + /// The minimum supported Maya version. If less than or equal to 0, the minimum version is not set. + /// The maximum supported Maya version. If less than or equal to 0, the maximum version is not set. + /// + /// The instance for chaining, configured for the specified OS, platform, and version range. + /// + public static ComponentsBuilder MayaPlatform(this ComponentsBuilder componentsBuilder, string os, string platform, int minVersion, int maxVersion) + { + componentsBuilder.OS(os) + .Platform(platform); + + if (minVersion > 0) + { + componentsBuilder.SeriesMin(minVersion.ToString()); + } + if (maxVersion > 0) + { + componentsBuilder.SeriesMax(maxVersion.ToString()); + } + + return componentsBuilder; + } +} diff --git a/Autodesk.PackageBuilder/Utils/NavisworksUtils.cs b/Autodesk.PackageBuilder/Utils/NavisworksUtils.cs new file mode 100644 index 0000000..b34e261 --- /dev/null +++ b/Autodesk.PackageBuilder/Utils/NavisworksUtils.cs @@ -0,0 +1,169 @@ +using System; + +namespace Autodesk.PackageBuilder; + +/// +/// Provides utility extension methods for configuring Navisworks-specific application packages and components. +/// +/// +/// For more information, see the Navisworks Developer Documentation: +/// https://aps.autodesk.com/developer/overview/navisworks +/// https://adndevblog.typepad.com/aec/navisworks/ +/// +public static class NavisworksUtils +{ + /// + /// The default operating system for Navisworks application packages (Windows 64-bit). + /// + public const string Os = "Win64"; + + /// + /// The default platform string for all Navisworks-based products ("NAVMAN|NAVSIM"). + /// + public const string Platform = "NAVMAN|NAVSIM"; + + /// + /// Configures the for a Navisworks application package. + /// + /// The application package builder instance. + /// + /// The instance for chaining, configured for Navisworks. + /// + public static ApplicationPackageBuilder NavisworksApplication(this ApplicationPackageBuilder applicationPackageBuilder) + { + return applicationPackageBuilder + .ProductType(ProductTypes.Application) + .AutodeskProduct(AutodeskProducts.Navisworks); + } + + /// + /// Configures the for the default Navisworks platform and operating system. + /// + /// The components builder instance. + /// + /// The instance for chaining, configured for Navisworks's default OS and platform. + /// + public static ComponentsBuilder NavisworksPlatform(this ComponentsBuilder componentsBuilder) + { + return componentsBuilder + .OS(Os) + .Platform(Platform); + } + + /// + /// Configures the for a specified operating system and platform. + /// + /// The components builder instance. + /// The operating system to set. + /// The platform to set. + /// + /// The instance for chaining, configured for the specified OS and platform. + /// + public static ComponentsBuilder NavisworksPlatform(this ComponentsBuilder componentsBuilder, string os, string platform) + { + return componentsBuilder + .OS(os) + .Platform(platform); + } + + /// + /// Configures the for the default Navisworks platform and operating system, + /// and restricts the supported internal Navisworks version range using integer major versions. + /// + /// The instance to configure. + /// The minimum supported internal Navisworks version as an integer. + /// The maximum supported internal Navisworks version as an integer. + /// + /// If true, the maximum version is treated as inclusive (i.e., less than or equal to ). + /// If false (default), the maximum version is exclusive (i.e., less than minus one). + /// + /// + /// The instance for chaining, configured for Navisworks's default OS, platform, and version range. + /// + public static ComponentsBuilder NavisworksPlatform(this ComponentsBuilder componentsBuilder, int minInternalVersion, int maxInternalVersion, bool maxVersionMinusOne = false) + { + return componentsBuilder.NavisworksPlatform(new Version(minInternalVersion, 0), new Version(maxInternalVersion, 0), maxVersionMinusOne); + } + + /// + /// Configures the for the default Navisworks platform and operating system, + /// and restricts the supported internal Navisworks version range. + /// + /// The instance to configure. + /// The minimum supported internal Navisworks version as a . + /// The maximum supported internal Navisworks version as a . + /// + /// If true, the maximum version is treated as inclusive (i.e., less than or equal to ). + /// If false (default), the maximum version is exclusive (i.e., less than minus one). + /// + /// + /// The instance for chaining, configured for Navisworks's default OS, platform, and version range. + /// + public static ComponentsBuilder NavisworksPlatform(this ComponentsBuilder componentsBuilder, Version minVersion, Version maxVersion, bool maxVersionMinusOne = false) + { + return componentsBuilder.NavisworksPlatform(Os, Platform, minVersion, maxVersion, maxVersionMinusOne); + } + + /// + /// Configures the for a specified operating system, platform, and Navisworks version range. + /// + /// The instance to configure. + /// The operating system to set (e.g., "Win64"). + /// The platform to set (e.g., "NAVMAN|NAVSIM"). + /// The minimum supported internal Navisworks version as a . + /// The maximum supported internal Navisworks version as a . If null or major is 0, no upper bound is set. + /// + /// If true, the maximum version is treated as inclusive (i.e., less than or equal to ). + /// If false (default), the maximum version is exclusive (i.e., less than minus one). + /// + /// + /// The instance for chaining, configured for the specified OS, platform, and version range. + /// + public static ComponentsBuilder NavisworksPlatform(this ComponentsBuilder componentsBuilder, string os, string platform, Version minVersion, Version maxVersion, bool maxVersionMinusOne = false) + { + var minVersionString = minVersion.ToNavisworksMajorString(); + var maxVersionString = maxVersion?.ToNavisworksMajorString(); + + componentsBuilder + .OS(os) + .Platform(platform) + .SeriesMin(minVersionString); + + if (minVersionString == maxVersionString) + { + return componentsBuilder + .SeriesMax(maxVersionString); + } + + if (maxVersion is null || maxVersion.Major == 0) + return componentsBuilder; + + if (maxVersionMinusOne) + { + maxVersionString = maxVersion.ToNavisworksMajorString(-1); + } + + return componentsBuilder + .SeriesMax(maxVersionString); + } + + + /// + /// Converts a object to a Navisworks major version string (e.g., "Nw21"). + /// + /// The instance to convert. + /// + /// An optional integer to add to the major version. Defaults to 0. + /// Use negative values to decrement the major version (e.g., for exclusive upper bounds). + /// + /// + /// A string in the format "Nw{major}", or null if is null. + /// + private static string ToNavisworksMajorString(this Version version, int majorPlus = 0) + { + if (version is null) + return null; + + return $"Nw{version.Major + majorPlus}"; + } +} diff --git a/Autodesk.PackageBuilder/Utils/RevitUtils.cs b/Autodesk.PackageBuilder/Utils/RevitUtils.cs index 4b1f239..95a4a58 100644 --- a/Autodesk.PackageBuilder/Utils/RevitUtils.cs +++ b/Autodesk.PackageBuilder/Utils/RevitUtils.cs @@ -1,36 +1,104 @@ -namespace Autodesk.PackageBuilder +namespace Autodesk.PackageBuilder; + +/// +/// Provides extension methods for configuring and for Autodesk Revit. +/// +public static class RevitUtils { /// - /// RevitUtils + /// The default operating system value for Revit components ("Win64"). + /// + public const string Os = "Win64"; + /// + /// The default platform value for Revit components ("Revit"). + /// + public const string Platform = "Revit"; + + /// + /// Configures the for Autodesk Revit as an application product type. + /// + /// The instance to configure. + /// + /// The configured instance with + /// as the product type and + /// as the Autodesk product. + /// + public static ApplicationPackageBuilder RevitApplication(this ApplicationPackageBuilder applicationPackageBuilder) + { + return applicationPackageBuilder + .ProductType(ProductTypes.Application) + .AutodeskProduct(AutodeskProducts.Revit); + } + + /// + /// Configures the for the specified Revit version, using "Win64" as the OS and "Revit" as the platform. + /// + /// The instance to configure. + /// The Revit version (e.g., 2024). + /// + /// The configured instance with the specified Revit version, "Win64" OS, and "Revit" platform. + /// + public static ComponentsBuilder RevitPlatform(this ComponentsBuilder componentsBuilder, int version) + { + return componentsBuilder.RevitPlatform(version, version); + } + + /// + /// Configures the for the specified minimum and maximum Revit versions, + /// using "Win64" as the OS and "Revit" as the platform. + /// + /// The instance to configure. + /// The minimum Revit version (e.g., 2023). + /// The maximum Revit version (e.g., 2024). + /// + /// The configured instance with the specified minimum and maximum Revit versions, + /// "Win64" OS, and "Revit" platform. + /// + public static ComponentsBuilder RevitPlatform(this ComponentsBuilder componentsBuilder, int minVersion, int maxVersion) + { + return componentsBuilder.RevitPlatform(Os, Platform, minVersion, maxVersion); + } + + /// + /// Configures the for the specified OS, platform, and Revit version. /// - public static class RevitUtils + /// The instance to configure. + /// The operating system (e.g., "Win64"). + /// The platform (e.g., "Revit"). + /// The Revit version (e.g., 2024). + /// + /// The configured instance with the specified OS, platform, and Revit version. + /// /// + public static ComponentsBuilder RevitPlatform(this ComponentsBuilder componentsBuilder, string os, string platform, int version) { - /// - /// Set AutodeskProduct to and ProductType to . - /// - /// - /// - public static ApplicationPackageBuilder RevitApplication(this ApplicationPackageBuilder applicationPackageBuilder) + return componentsBuilder.RevitPlatform(os, platform, version, version); + } + + /// + /// Configures the for the specified operating system, platform, and Revit version range. + /// + /// The instance to configure. + /// The operating system requirement (e.g., "Win64"). + /// The platform requirement (e.g., "Revit"). + /// The minimum supported Revit version (e.g., 2023). + /// The maximum supported Revit version (e.g., 2024). + /// + /// The configured instance with the specified OS, platform, and Revit version range. + /// + public static ComponentsBuilder RevitPlatform(this ComponentsBuilder componentsBuilder, string os, string platform, int minVersion, int maxVersion) + { + componentsBuilder.OS(os) + .Platform(platform); + + if (minVersion > 0) { - return applicationPackageBuilder - .ProductType(ProductTypes.Application) - .AutodeskProduct(AutodeskProducts.Revit); + componentsBuilder.SeriesMin("R" + minVersion.ToString()); } - - /// - /// Set Win64 / Revit / R / R - /// - /// - /// - /// - public static ComponentsBuilder RevitPlatform(this ComponentsBuilder componentsBuilder, int revitVersion) + if (maxVersion > 0) { - return componentsBuilder - .OS("Win64") - .Platform("Revit") - .SeriesMin("R" + revitVersion) - .SeriesMax("R" + revitVersion); + componentsBuilder.SeriesMax("R" + maxVersion.ToString()); } - } + return componentsBuilder; + } } \ No newline at end of file diff --git a/Build/.nuke/build.schema.json b/Build/.nuke/build.schema.json index a0854f5..087e3b4 100644 --- a/Build/.nuke/build.schema.json +++ b/Build/.nuke/build.schema.json @@ -1,65 +1,70 @@ { "$schema": "http://json-schema.org/draft-04/schema#", - "$ref": "#/definitions/build", - "title": "Build Schema", "definitions": { - "build": { - "type": "object", + "Host": { + "type": "string", + "enum": [ + "AppVeyor", + "AzurePipelines", + "Bamboo", + "Bitbucket", + "Bitrise", + "GitHubActions", + "GitLab", + "Jenkins", + "Rider", + "SpaceAutomation", + "TeamCity", + "Terminal", + "TravisCI", + "VisualStudio", + "VSCode" + ] + }, + "ExecutableTarget": { + "type": "string", + "enum": [ + "Build", + "Clean", + "Compile", + "CompileExample", + "GitPreRelease", + "GitRelease", + "Pack", + "PrePack", + "Release", + "Sign", + "Test" + ] + }, + "Verbosity": { + "type": "string", + "description": "", + "enum": [ + "Verbose", + "Normal", + "Minimal", + "Quiet" + ] + }, + "NukeBuild": { "properties": { "Continue": { "type": "boolean", "description": "Indicates to continue a previously failed build attempt" }, - "Folder": { - "type": "string" - }, - "GitHubToken": { - "type": "string", - "default": "Secrets must be entered via 'nuke :secrets [profile]'" - }, "Help": { "type": "boolean", "description": "Shows the help text for this build assembly" }, "Host": { - "type": "string", "description": "Host for execution. Default is 'automatic'", - "enum": [ - "AppVeyor", - "AzurePipelines", - "Bamboo", - "Bitbucket", - "Bitrise", - "GitHubActions", - "GitLab", - "Jenkins", - "Rider", - "SpaceAutomation", - "TeamCity", - "Terminal", - "TravisCI", - "VisualStudio", - "VSCode" - ] - }, - "MainName": { - "type": "string" - }, - "Name": { - "type": "string" + "$ref": "#/definitions/Host" }, "NoLogo": { "type": "boolean", "description": "Disables displaying the NUKE logo" }, - "NugetApiKey": { - "type": "string", - "default": "Secrets must be entered via 'nuke :secrets [profile]'" - }, - "NugetApiUrl": { - "type": "string", - "default": "Secrets must be entered via 'nuke :secrets [profile]'" - }, "Partition": { "type": "string", "description": "Partition to use on CI" @@ -75,6 +80,64 @@ "type": "string" } }, + "Root": { + "type": "string", + "description": "Root directory during build execution" + }, + "Skip": { + "type": "array", + "description": "List of targets to be skipped. Empty list skips all dependencies", + "items": { + "$ref": "#/definitions/ExecutableTarget" + } + }, + "Target": { + "type": "array", + "description": "List of targets to be invoked. Default is '{default_target}'", + "items": { + "$ref": "#/definitions/ExecutableTarget" + } + }, + "Verbosity": { + "description": "Logging verbosity during build execution. Default is 'Normal'", + "$ref": "#/definitions/Verbosity" + } + } + } + }, + "allOf": [ + { + "properties": { + "EnableForkedRepository": { + "type": "boolean" + }, + "Folder": { + "type": "string" + }, + "GitHubToken": { + "type": "string", + "default": "Secrets must be entered via 'nuke :secrets [profile]'" + }, + "MainName": { + "type": "string" + }, + "Name": { + "type": "string" + }, + "NuGetApiKey": { + "type": "string", + "default": "Secrets must be entered via 'nuke :secrets [profile]'" + }, + "NuGetApiUrl": { + "type": "string", + "default": "Secrets must be entered via 'nuke :secrets [profile]'" + }, + "PreReleaseFilter": { + "type": "array", + "items": { + "type": "string" + } + }, "ReleaseExample": { "type": "boolean" }, @@ -84,10 +147,6 @@ "ReleaseNameVersion": { "type": "boolean" }, - "Root": { - "type": "string", - "description": "Root directory during build execution" - }, "SignFile": { "type": "string", "default": "Secrets must be entered via 'nuke :secrets [profile]'" @@ -96,46 +155,10 @@ "type": "string", "default": "Secrets must be entered via 'nuke :secrets [profile]'" }, - "Skip": { - "type": "array", - "description": "List of targets to be skipped. Empty list skips all dependencies", - "items": { - "type": "string", - "enum": [ - "Build", - "Clean", - "Compile", - "CompileExample", - "GitRelease", - "Pack", - "Release", - "Sign", - "Test" - ] - } - }, "Solution": { "type": "string", "description": "Path to a solution file that is automatically loaded" }, - "Target": { - "type": "array", - "description": "List of targets to be invoked. Default is '{default_target}'", - "items": { - "type": "string", - "enum": [ - "Build", - "Clean", - "Compile", - "CompileExample", - "GitRelease", - "Pack", - "Release", - "Sign", - "Test" - ] - } - }, "TestBuildStopWhenFailed": { "type": "boolean" }, @@ -145,17 +168,13 @@ "TestResults": { "type": "boolean" }, - "Verbosity": { - "type": "string", - "description": "Logging verbosity during build execution. Default is 'Normal'", - "enum": [ - "Minimal", - "Normal", - "Quiet", - "Verbose" - ] + "UnlistNuGet": { + "type": "boolean" } } + }, + { + "$ref": "#/definitions/NukeBuild" } - } + ] } diff --git a/Build/Build.cs b/Build/Build.cs index fb1c8e4..f146e43 100644 --- a/Build/Build.cs +++ b/Build/Build.cs @@ -3,7 +3,7 @@ using ricaun.Nuke; using ricaun.Nuke.Components; -partial class Build : NukeBuild, IPublishPack, ICompileExample, ITest +partial class Build : NukeBuild, IPublishPack, IPrePack, ICompileExample, ITest { public static int Main() => Execute(x => x.From().Build); } \ No newline at end of file diff --git a/Build/Build.csproj b/Build/Build.csproj index dba3b7f..595a26b 100644 --- a/Build/Build.csproj +++ b/Build/Build.csproj @@ -1,7 +1,7 @@  Exe - net6.0 + net8.0 CS0649;CS0169 . diff --git a/CHANGELOG.md b/CHANGELOG.md index 072e7d3..06dd369 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,42 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [2.0.0] / 2025-05-16 - 2025-06-05 +### Features +- Support `AutoCAD` bundle. +- Support `Inventor` bundle and add-in. +- Support `3ds Max` bundle. +- Support `Maya` bundle. +- Support `Navisworks` bundle. +- Support custom `Element` and `Attribute`. +- Add `IncludeSymbols` to support `SymbolPackageFormat`. +### PackageBuilder +- Add `ExtensibleData` with custom `IXmlSerializable`. +- Add `ExtensibleDataExtension` with `CreateEntryElement` and `CreateAttribute`. +- Add `DataBuilderBase` and `DataBuilderBaseExtension`. +- Add `AutoCADUtils` to support `AutoCADApplication` and `AutoCADPlatform`. +- Add `AutoCADExtensibleData` to support `LoadOnAppearance` and `Commands`. +- Add `AutoCADCommands` and `AutoCADCommand` in `AutoCADExtensibleData`. +- Add `InventorUtils` to support `InventorApplication` and `InventorPlatform`. +- Rename `AddInEntryBuilder` to `RevitAddInEntryBuilder`. +- Add `IInventorAddInEntryBuilder`, `InventorAddInEntryBuilder` and `InventorAddIn`. +- Update `InventorUtils` to have `SupportedSoftwareVersion` extension method. +- Add `Max3dsUtils` to support `Max3dsApplication` and `Max3dsPlatform`. +- Update `InventorUtils` to use `SeriesMin/SeriesMax` for `App Store` only. +- Add `MayaUtils` to support `MayaApplication` and `MayaPlatform`. +- Add `NavisworksUtils` to support `NavisworksApplication` and `NavisworksPlatform`. +- Add `AppNameSpace` and `UpgradeCode` to `PackageBuilder`. +- Update `ProductCode` and `UpgradeCode` to convert `Guid` to `ToStringBraces`. +- Update `AppVersion` to convert `Version` to `ToString(3)`. +### Tests +- Add `DataBuild_Tests` to test `DataBuilder` +- Add `PackageContentsBuilder_AutoCAD_Tests` and `PackageContentsBuilder_Revit_Tests`. +- Add `InventorAddInsBuilder_Tests` to test `InventorAddInEntryBuilder`. +- Add `PackageContentsBuilder_Inventor_Tests` to test `InventorUtils`. +- Add `PackageContentsBuilder_Max3ds_Tests` to test `Max3dsUtils`. +- Add `PackageContentsBuilder_Maya_Tests` to test `MayaUtils`. +- Add `PackageContentsBuilder_Navisworks_Tests` to test `NavisworksUtils`. + ## [1.0.6] / 2023-11-24 - 2023-12-06 ### Features - `Tests` project. @@ -56,6 +92,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - First Release [vNext]: ../../compare/1.0.0...HEAD +[2.0.0]: ../../compare/1.0.6...1.2.0 [1.0.6]: ../../compare/1.0.5...1.0.6 [1.0.5]: ../../compare/1.0.4...1.0.5 [1.0.4]: ../../compare/1.0.3...1.0.4 diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..8de2310 --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,5 @@ + + + 2.0.0 + + \ No newline at end of file diff --git a/README.md b/README.md index 32e3f23..f4b72ca 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,40 @@ # Autodesk.PackageBuilder -This package is intended to build Autodesk `PackageContent.xml` and `RevitAddin.addin` using C# fluent API. - -[![Autodesk](https://img.shields.io/badge/Autodesk-black?logo=autodesk&logoColor=white)](../..) -[![Revit](https://img.shields.io/badge/Revit-black.svg)](../..) - -[![Visual Studio 2022](https://img.shields.io/badge/Visual%20Studio-2022-blue)](../..) +[![Autodesk](https://img.shields.io/badge/Autodesk-black?logo=autodesk&logoColor=white)](https://github.com/ricaun-io/Autodesk.PackageBuilder) +[![AutoCAD](https://img.shields.io/badge/AutoCAD-E51050.svg)](https://github.com/ricaun-io/Autodesk.PackageBuilder) +[![Revit](https://img.shields.io/badge/Revit-186BFF.svg)](https://github.com/ricaun-io/Autodesk.PackageBuilder) +[![3ds Max](https://img.shields.io/badge/3ds%20Max-37A5CC.svg)](https://github.com/ricaun-io/Autodesk.PackageBuilder) +[![Inventor](https://img.shields.io/badge/Inventor-DBAE03.svg)](https://github.com/ricaun-io/Autodesk.PackageBuilder) +[![Maya](https://img.shields.io/badge/Maya-37A5CC.svg)](https://github.com/ricaun-io/Autodesk.PackageBuilder) +[![Navisworks](https://img.shields.io/badge/Navisworks-186BFF.svg)](https://github.com/ricaun-io/Autodesk.PackageBuilder) + + +[![Visual Studio 2022](https://img.shields.io/badge/Visual%20Studio-2022-blue)](https://github.com/ricaun-io/Autodesk.PackageBuilder) [![Nuke](https://img.shields.io/badge/Nuke-Build-blue)](https://nuke.build/) [![License MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE) -[![Build](../../actions/workflows/Build.yml/badge.svg)](../../actions) +[![Build](https://github.com/ricaun-io/Autodesk.PackageBuilder/actions/workflows/Build.yml/badge.svg)](https://github.com/ricaun-io/Autodesk.PackageBuilder/actions) [![Release](https://img.shields.io/nuget/v/Autodesk.PackageBuilder?logo=nuget&label=release&color=blue)](https://www.nuget.org/packages/Autodesk.PackageBuilder) +This package is intended to build Autodesk `PackageContent.xml` and `RevitAddin.addin/InventorAddin.addin` using C# fluent API. + +## Autodesk Product Version Table + +| Product | RuntimeRequirements::SeriesMin/SeriesMax | RuntimeRequirements::Platform | +|--------------|------------------------------------------|--------------------------------------| +| AutoCAD | R24.0 (2021), R23.1 (2020), R23.0 (2019) | AutoCAD* | +| Revit | R2021, R2020, R2019, R2018, R2017 | Revit | +| Maya | 2021, 2020, 2019, 2018, ... | Maya | +| 3ds Max | 2021, 2020, 2019, 2018, ... | 3ds Max|3ds Max Design | +| Inventor | (version is taken from add-in manifest) | Inventor | +| Navisworks | Nw18 (2021), Nw17 (2020), Nw16 (2019) | NAVMAN|NAVSIM | +| Vault | V2021, V2020, V2019, ... | Vault | +| Fusion 360 | (No version, leave empty) | Fusion 360 | + +* [AppBundle: Autodesk Products - 2020](https://www.autodesk.com/autodesk-university/class/AppBundle-Cross-Distribution-Autodesk-Products-App-Store-and-Forge-2020) + ## Examples ### Create PackageContents.xml @@ -216,14 +240,88 @@ BuilderUtils.Build(builder => {...}, "RevitAddin.addin"); BuilderUtils.Build(builder => {...}).Build("RevitAddin.addin"); ``` +### Not implemented Attribute and Element + +If the `Attribute` or `Element` is not implemented, you can use `DataBuilder` to access the methods `CreateAttribute` and `CreateElement`. + +```C# +var builder = BuilderUtils.Build(builder => +{ + builder.Components + .CreateEntry("Revit 2021") + .DataBuilder.CreateAttribute("Attribute", "Value"); + + builder.Components + .CreateEntry("Revit 2022") + .DataBuilder.CreateElement("Element", "Value"); + + builder.Components + .CreateEntry("Revit 2023") + .DataBuilder.CreateAttribute("Attribute", "Value"); + + builder.Components + .CreateEntry("Revit 2024") + .DataBuilder.CreateElement("Element", "Value"); +}); +``` + +#### Create custom Element/Attribute + +The class `ExtensibleData` could be used to create custom `Element`. +```C# +public class CustomElement : ExtensibleData +{ + [XmlAttribute] + public string Name { get; set; } + [XmlElement] + public string Value { get; set; } +} +``` + +The `ExtensibleData` uses a `XmlSerializer` to serialize the object. +Use the `DataBuilder` to access the methods `CreateElement` and `CreateAttribute` to create custom elements or attributes. + +```C# +var builder = BuilderUtils.Build(builder => +{ + var custom = new CustomElement() + { + Name = "Name", + Value = "Value" + }; + + var componentRevit2021 = builder.Components + .CreateEntry("Revit 2021"); + + componentRevit2021.DataBuilder.CreateAttribute("Attribute", true); + componentRevit2021.DataBuilder.CreateElement("Element", true); + componentRevit2021.DataBuilder.CreateElement("CustomElement", custom); +}); +``` + +This is the result of the above code: + +```xml + + + + + true + + Value + + + +``` + ## Package Inspiration / Reference -This package was inspared by [InnoSetup.ScriptBuilder](https://github.com/ReactiveBIM/InnoSetup.ScriptBuilder) package. +This package was inspired by [InnoSetup.ScriptBuilder](https://github.com/ReactiveBIM/InnoSetup.ScriptBuilder) package. ## License -This package is [licensed](LICENSE) under the [MIT Licence](https://en.wikipedia.org/wiki/MIT_License). +This package is [licensed](LICENSE) under the [MIT License](https://en.wikipedia.org/wiki/MIT_License). --- -Do you like this package? Please [star this project on GitHub](../../stargazers)! +Do you like this package? Please [star this project on GitHub](https://github.com/ricaun-io/Autodesk.PackageBuilder/stargazers)! diff --git a/build.cmd b/build.cmd new file mode 100644 index 0000000..07d4307 --- /dev/null +++ b/build.cmd @@ -0,0 +1,3 @@ +cd .\Build\ +call build.cmd %* +timeout 15 \ No newline at end of file