CadParamPluging/Common/TemplateSchemaDefinition.cs

68 lines
2.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
namespace CadParamPluging.Common
{
[Serializable]
public class TemplateSchemaDefinition
{
public string TemplateKey { get; set; }
public string ProjectType { get; set; }
public string DrawingType { get; set; }
public string SheetSize { get; set; }
public string Scale { get; set; }
public string DisplayName { get; set; }
public List<string> SelectedParamKeys { get; set; }
public string NoteTemplateText { get; set; }
public List<NotePlaceholderBinding> NoteBindings { get; set; }
public TemplateSchemaDefinition()
{
SelectedParamKeys = new List<string>();
NoteTemplateText = string.Empty;
NoteBindings = new List<NotePlaceholderBinding>();
}
public void Normalize()
{
ProjectType = (ProjectType ?? string.Empty).Trim();
DrawingType = (DrawingType ?? string.Empty).Trim();
SheetSize = (SheetSize ?? string.Empty).Trim();
Scale = (Scale ?? string.Empty).Trim();
DisplayName = (DisplayName ?? string.Empty).Trim();
NoteTemplateText = NoteTemplateText ?? string.Empty;
TemplateKey = TemplateKeyBuilder.Build(ProjectType, DrawingType, SheetSize, Scale);
if (SelectedParamKeys == null)
{
SelectedParamKeys = new List<string>();
}
SelectedParamKeys = SelectedParamKeys
.Where(s => !string.IsNullOrWhiteSpace(s))
.Select(s => s.Trim())
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
if (NoteBindings == null)
{
NoteBindings = new List<NotePlaceholderBinding>();
}
NoteBindings = NoteBindings
.Where(b => b != null && b.Index > 0 && !string.IsNullOrWhiteSpace(b.ParamKey))
.GroupBy(b => b.Index)
.Select(g => g.First())
.OrderBy(b => b.Index)
.ToList();
}
}
}