Files
autodesk/Plant3D2026/P_Rec_Annot/src/PRecAnnot.Plant3D2026/LineNumberRuntimeConfiguration.cs
T

26 lines
1.2 KiB
C#

using PRecAnnot.Abstractions;
using PRecAnnot.Core;
namespace PRecAnnot.Plant3D2026;
internal sealed record LineNumberRuntimeConfiguration(LineNumberAnnotationSettings Annotations, AnnotateLineNumbersAssets Assets, LineConnectionAssets Connections);
internal static class LineNumberRuntimeConfigurationReader
{
public static LineNumberRuntimeConfiguration Read()
{
var annotationPath = RequiredLocalFile("P_REC_ANNOT_LINE_NUMBER_ANNOTATION_SETTINGS_PATH");
var drawingPath = RequiredLocalFile("P_REC_ANNOT_LINE_NUMBER_DRAWING_SETTINGS_PATH");
var drawingXml = File.ReadAllText(drawingPath);
return new(new LineNumberAnnotationSettingsLoader().Load(File.ReadAllText(annotationPath)), new AnnotateLineNumbersSettingsLoader().Load(drawingXml), new LineConnectionSettingsLoader().Load(drawingXml));
}
private static string RequiredLocalFile(string variable)
{
var path = Environment.GetEnvironmentVariable(variable);
if (string.IsNullOrWhiteSpace(path) || !Path.IsPathFullyQualified(path) || path.StartsWith("\\\\", StringComparison.Ordinal) || !File.Exists(path))
throw new InvalidOperationException($"LINE_NUMBER_CONFIGURATION_REQUIRED:{variable}");
return path;
}
}