Files
LanMountainDesktop/airapp/LanMountainDesktop.AirAppSdk/AirAppComponentEditorContext.cs

72 lines
2.1 KiB
C#
Raw Normal View History

2026-08-11 23:03:55 +08:00
namespace LanMountainDesktop.AirAppSdk;
2026-03-14 22:45:09 +08:00
2026-08-11 23:03:55 +08:00
public sealed class AirAppComponentEditorContext
2026-03-14 22:45:09 +08:00
{
2026-08-11 23:03:55 +08:00
public AirAppComponentEditorContext(
AirAppManifest manifest,
2026-03-14 22:45:09 +08:00
string pluginDirectory,
string dataDirectory,
IServiceProvider services,
IReadOnlyDictionary<string, object?> properties,
string componentId,
string? placementId,
2026-08-11 23:03:55 +08:00
IAirAppSettingsService? pluginSettings,
2026-03-14 22:45:09 +08:00
IComponentEditorHostContext hostContext)
{
ArgumentNullException.ThrowIfNull(manifest);
ArgumentException.ThrowIfNullOrWhiteSpace(pluginDirectory);
ArgumentException.ThrowIfNullOrWhiteSpace(dataDirectory);
ArgumentException.ThrowIfNullOrWhiteSpace(componentId);
ArgumentNullException.ThrowIfNull(services);
ArgumentNullException.ThrowIfNull(properties);
ArgumentNullException.ThrowIfNull(hostContext);
Manifest = manifest;
2026-08-11 23:03:55 +08:00
AirAppDirectory = pluginDirectory;
2026-03-14 22:45:09 +08:00
DataDirectory = dataDirectory;
Services = services;
Properties = properties;
ComponentId = componentId.Trim();
PlacementId = string.IsNullOrWhiteSpace(placementId) ? null : placementId.Trim();
2026-08-11 23:03:55 +08:00
AirAppSettings = pluginSettings;
2026-03-14 22:45:09 +08:00
HostContext = hostContext;
}
2026-08-11 23:03:55 +08:00
public AirAppManifest Manifest { get; }
2026-03-14 22:45:09 +08:00
2026-08-11 23:03:55 +08:00
public string AirAppDirectory { get; }
2026-03-14 22:45:09 +08:00
public string DataDirectory { get; }
public IServiceProvider Services { get; }
public IReadOnlyDictionary<string, object?> Properties { get; }
public string ComponentId { get; }
public string? PlacementId { get; }
2026-08-11 23:03:55 +08:00
public IAirAppSettingsService? AirAppSettings { get; }
2026-03-14 22:45:09 +08:00
public IComponentEditorHostContext HostContext { get; }
public T? GetService<T>()
{
return (T?)Services.GetService(typeof(T));
}
public bool TryGetProperty<T>(string key, out T? value)
{
ArgumentException.ThrowIfNullOrWhiteSpace(key);
if (Properties.TryGetValue(key, out var rawValue) && rawValue is T typedValue)
{
value = typedValue;
return true;
}
value = default;
return false;
}
}