69 lines
2.2 KiB
C#
69 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using CadParamPluging.Domain.Models;
|
|
|
|
namespace CadParamPluging.Data
|
|
{
|
|
public class DefaultTemplateRepository : ITemplateRepository
|
|
{
|
|
private readonly List<TemplateDefinition> _templates;
|
|
|
|
public DefaultTemplateRepository()
|
|
{
|
|
_templates = new List<TemplateDefinition>
|
|
{
|
|
new TemplateDefinition
|
|
{
|
|
ProjectType = "结构",
|
|
DrawingType = "基础平面",
|
|
SheetSize = "A1",
|
|
Scale = "1:50",
|
|
FilePath = "C\\CadTemplates\\Stru_Base_A1_50.dwt",
|
|
Description = "结构基础平面 A1 1:50"
|
|
},
|
|
new TemplateDefinition
|
|
{
|
|
ProjectType = "示例",
|
|
DrawingType = "示例图",
|
|
SheetSize = "A3",
|
|
Scale = "1:100",
|
|
FilePath = "C\\CadTemplates\\Sample_A3_100.dwt",
|
|
Description = "示例模板 A3 1:100"
|
|
}
|
|
};
|
|
}
|
|
|
|
public TemplateDefinition FindTemplate(TemplateParams templateParams)
|
|
{
|
|
if (templateParams == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var matches = _templates.Where(t => Matches(t.ProjectType, templateParams.ProjectType)
|
|
&& Matches(t.DrawingType, templateParams.DrawingType)
|
|
&& Matches(t.SheetSize, templateParams.SheetSize)
|
|
&& Matches(t.Scale, templateParams.Scale))
|
|
.ToList();
|
|
|
|
if (matches.Count == 1)
|
|
{
|
|
return matches.First();
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
private static bool Matches(string source, string input)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(input))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return source != null && input != null && source.Equals(input, StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
}
|
|
}
|