Files

132 lines
3.6 KiB
C#
Raw Permalink Normal View History

2025-09-04 09:53:20 +08:00
using System;
using System.IO;
using Autodesk.Revit.Attributes;
namespace AddInManager
{
public class AddinItem : IAddinNode
{
public AddinItem(AddinType type)
{
AddinType = type;
2026-01-02 11:14:44 +08:00
MClientId = Guid.NewGuid();
ClientIdString = MClientId.ToString();
MAssemblyPath = string.Empty;
2025-09-04 09:53:20 +08:00
AssemblyName = string.Empty;
FullClassName = string.Empty;
2026-01-02 11:14:44 +08:00
_mName = string.Empty;
2025-09-04 09:53:20 +08:00
Save = true;
VisibilityMode = VisibilityMode.AlwaysVisible;
}
public AddinItem(string assemblyPath, Guid clientId, string fullClassName, AddinType type, TransactionMode? transactionMode, RegenerationOption? regenerationOption, JournalingMode? journalingMode)
{
TransactionMode = transactionMode;
RegenerationMode = regenerationOption;
JournalingMode = journalingMode;
AddinType = type;
2026-01-02 11:14:44 +08:00
MAssemblyPath = assemblyPath;
AssemblyName = Path.GetFileName(MAssemblyPath);
MClientId = clientId;
2025-09-04 09:53:20 +08:00
ClientIdString = clientId.ToString();
FullClassName = fullClassName;
var num = fullClassName.LastIndexOf(".");
2026-01-02 11:14:44 +08:00
_mName = fullClassName.Substring(num + 1);
2025-09-04 09:53:20 +08:00
Save = true;
VisibilityMode = VisibilityMode.AlwaysVisible;
}
public void SaveToManifest()
{
2026-01-02 11:14:44 +08:00
var manifestFile = new ManifestFile($"{_mName}.addin");
2025-09-04 09:53:20 +08:00
if (AddinType == AddinType.Application)
{
manifestFile.Applications.Add(this);
}
else if (AddinType == AddinType.Command)
{
manifestFile.Commands.Add(this);
}
manifestFile.Save();
}
public AddinType AddinType { get; set; }
public string AssemblyPath
{
2026-01-02 11:14:44 +08:00
get => MAssemblyPath;
2025-09-04 09:53:20 +08:00
set
{
2026-01-02 11:14:44 +08:00
MAssemblyPath = value;
AssemblyName = Path.GetFileName(MAssemblyPath);
2025-09-04 09:53:20 +08:00
}
}
public string AssemblyName { get; set; }
public Guid ClientId
{
2026-01-02 11:14:44 +08:00
get => MClientId;
2025-09-04 09:53:20 +08:00
set
{
2026-01-02 11:14:44 +08:00
MClientId = value;
ClientIdString = MClientId.ToString();
2025-09-04 09:53:20 +08:00
}
}
protected internal string ClientIdString { get; set; }
public string FullClassName { get; set; }
public string Name
{
2026-01-02 11:14:44 +08:00
get => string.IsNullOrEmpty(_mName) ? "External Tool" : _mName;
2025-09-04 09:53:20 +08:00
set
{
if (!string.IsNullOrEmpty(value))
{
2026-01-02 11:14:44 +08:00
_mName = value;
2025-09-04 09:53:20 +08:00
return;
}
2026-01-02 11:14:44 +08:00
_mName = "External Tool";
2025-09-04 09:53:20 +08:00
}
}
public string Description
{
2026-01-02 11:14:44 +08:00
get => string.IsNullOrEmpty(field) ? "\"\"" : field;
2025-09-04 09:53:20 +08:00
set
{
if (string.IsNullOrEmpty(value))
{
2026-01-02 11:14:44 +08:00
field = "\"\"";
2025-09-04 09:53:20 +08:00
return;
}
2026-01-02 11:14:44 +08:00
field = value;
2025-09-04 09:53:20 +08:00
}
}
public VisibilityMode VisibilityMode { get; set; }
public bool Save { get; set; }
public bool Hidden { get; set; }
public TransactionMode? TransactionMode { get; set; }
public RegenerationOption? RegenerationMode { get; set; }
public JournalingMode? JournalingMode { get; set; }
public override string ToString()
{
2026-01-02 11:14:44 +08:00
return _mName;
2025-09-04 09:53:20 +08:00
}
2026-01-02 11:14:44 +08:00
protected string MAssemblyPath;
protected Guid MClientId;
private string _mName;
2025-09-04 09:53:20 +08:00
}
}