init
This commit is contained in:
@@ -0,0 +1,181 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using DTS.Common.Interface.GroupTemplate;
|
||||
using DTS.Common.Storage;
|
||||
using DTS.Common.Utilities.Logging;
|
||||
|
||||
// ReSharper disable CheckNamespace
|
||||
|
||||
namespace DTS.Common.ISO
|
||||
{
|
||||
/// <summary>
|
||||
/// this class is a wrapper for the group template per the db, it's supposed to be a lighter weight version of concept of a test object template, with no
|
||||
/// connection to UI, just serialization and structure
|
||||
/// </summary>
|
||||
public class TestObjectTemplate : ITestObjectTemplate
|
||||
{
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// name of the test object template, this could be a GUID in the case of embedded test object templates
|
||||
/// </summary>
|
||||
public string TemplateName { get; set; }
|
||||
/// <summary>
|
||||
/// a human readable name for the template, for an embedded template this is the original template name, for
|
||||
/// a non embedded template, this is the template name (embedded templates have guids for names)
|
||||
/// </summary>
|
||||
public string TemplateNameOrOriginalTemplateName => Embedded ? OriginalTemplateName : TemplateName;
|
||||
|
||||
/// <summary>
|
||||
/// the icon for the template
|
||||
/// </summary>
|
||||
public string Icon { get; set; }
|
||||
/// <summary>
|
||||
/// description for the template
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
/// <summary>
|
||||
/// whether this template is intended to only be used locally or not
|
||||
/// </summary>
|
||||
public bool LocalOnly { get; set; }
|
||||
/// <summary>
|
||||
/// the version number of this template [not currently used?]
|
||||
/// </summary>
|
||||
public int Version { get; set; }
|
||||
/// <summary>
|
||||
/// last person to modify this template
|
||||
/// </summary>
|
||||
public string LastModifiedBy { get; set; }
|
||||
/// <summary>
|
||||
/// when this template was last modified
|
||||
/// </summary>
|
||||
public DateTime LastModified { get; set; }
|
||||
/// <summary>
|
||||
/// a CRC32 for the template, but not currently used
|
||||
/// original idea was to allow us to not have to check changes in the template, just quickly calculate whether anything has changed
|
||||
/// </summary>
|
||||
public int CRC32 { get; set; }
|
||||
/// <summary>
|
||||
/// test object (iso meta field) for this template
|
||||
/// </summary>
|
||||
public string TestObject { get; set; }
|
||||
/// <summary>
|
||||
/// test object type (iso meta field) for this template, all channels are of this type ...
|
||||
/// </summary>
|
||||
public string TestObjectType { get; set; }
|
||||
/// <summary>
|
||||
/// unsure if this is still used, was originally used to build up templates from sub templates,
|
||||
/// so an ATD could be composed of leg, arm, head, etc
|
||||
/// </summary>
|
||||
public string TemplateParent { get; set; }
|
||||
/// <summary>
|
||||
/// unsure, I think this is whether the group is dynamically added or an existing
|
||||
/// </summary>
|
||||
public bool SysBuilt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// all channels for the template
|
||||
/// </summary>
|
||||
public TestObjectTemplateChannel[] Channels { get; set; }
|
||||
/// <summary>
|
||||
/// the original template name [if we are embedded we got a new name that was a guid, but we store the old name here for readability purposes]
|
||||
/// </summary>
|
||||
public string OriginalTemplateName { get; set; }
|
||||
/// <summary>
|
||||
/// whether this group is embedded in a test setup, or is a user created and living on it's own template
|
||||
/// </summary>
|
||||
public bool Embedded { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors and initializers
|
||||
|
||||
public bool IsISOMode()
|
||||
{
|
||||
return !(TestObjectType.Contains(Classes.GroupTemplates.Constants.NON_ISO_TESTOBJECT_CHANNEL_TYPE) ||
|
||||
TestObjectType.Contains(TestObjectTemplateChannel.NONISOCHANNELTYPE));
|
||||
}
|
||||
public TestObjectTemplate(string templateName, bool bLocalOnly)
|
||||
{
|
||||
Version = 1;
|
||||
TemplateName = templateName;
|
||||
LocalOnly = bLocalOnly;
|
||||
Channels = new TestObjectTemplateChannel[0];
|
||||
}
|
||||
public TestObjectTemplate(TestObjectTemplate copy, ref ISO13499FileDb db)
|
||||
{
|
||||
if (copy?.TemplateName != null)
|
||||
{
|
||||
TemplateName = copy.TemplateName;
|
||||
}
|
||||
if (copy == null) return;
|
||||
LocalOnly = copy.LocalOnly;
|
||||
CRC32 = copy.CRC32;
|
||||
Description = copy.Description;
|
||||
Embedded = copy.Embedded;
|
||||
OriginalTemplateName = copy.OriginalTemplateName;
|
||||
Icon = copy.Icon;
|
||||
LastModified = copy.LastModified;
|
||||
LastModifiedBy = copy.LastModifiedBy;
|
||||
LocalOnly = copy.LocalOnly;
|
||||
SysBuilt = copy.SysBuilt;
|
||||
TemplateParent = copy.TemplateParent;
|
||||
TestObject = copy.TestObject;
|
||||
TestObjectType = copy.TestObjectType;
|
||||
Version = copy.Version;
|
||||
var lookup = new Dictionary<string, bool>();
|
||||
var channels = new List<TestObjectTemplateChannel>();
|
||||
foreach (var c in copy.Channels)
|
||||
{
|
||||
var ch = new TestObjectTemplateChannel(c, this);
|
||||
ch.SetTemplate(this);
|
||||
channels.Add(ch);
|
||||
lookup[$"{c.Channel.Id}x{c.Channel.MMEChannelType}"] = true;
|
||||
}
|
||||
var possibleChannels = db.GetPossibleChannelsForType(TestObjectType);
|
||||
foreach (var pc in possibleChannels)
|
||||
{
|
||||
var key = $"{pc.Id}x{pc.MMEChannelType}";
|
||||
if (lookup.ContainsKey(key)) continue;
|
||||
lookup[key] = true;
|
||||
var ch = new TestObjectTemplateChannel(pc);
|
||||
ch.SetTemplate(this);
|
||||
channels.Insert(0, ch);
|
||||
}
|
||||
AssignOrders(channels);
|
||||
Channels = channels.ToArray();
|
||||
}
|
||||
|
||||
private void AssignOrders(List<TestObjectTemplateChannel> channels)
|
||||
{
|
||||
if (!channels.Any()) { return; }
|
||||
channels.Sort();
|
||||
var maxDisplayOrder = (from ch in channels select ch.DisplayOrder).Max();
|
||||
foreach (var ch in channels)
|
||||
{
|
||||
if (-1 == ch.DisplayOrder)
|
||||
{
|
||||
ch.DisplayOrder = ++maxDisplayOrder;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion Constructors And Initializers
|
||||
|
||||
|
||||
#region static functions
|
||||
|
||||
|
||||
public static TestObjectTemplate GetTemplate(ref ISO13499FileDb db, string name)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
public override string ToString()
|
||||
{
|
||||
return TemplateNameOrOriginalTemplateName;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user