init
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
using DTS.Common.Classes.DSP;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace DTS.Common.Classes.ClockSync
|
||||
{
|
||||
public class ClockSyncProfile : IClockSyncProfile
|
||||
{
|
||||
public int ProfileId { get; set; }
|
||||
public string ProfileName { get; set; }
|
||||
public string ProfileDesc { get; set; }
|
||||
public int DisplayOrder { get; set; }
|
||||
public bool Visible { get; set; }
|
||||
public DASRestriction[] FilterRestrictions { get; set; }
|
||||
public ClockSyncProfile() { }
|
||||
public ClockSyncProfile(int profileId, string profileName, string profileDesc, int displayOrder, bool visible, DASRestriction[] filterRestrictions)
|
||||
{
|
||||
Initialize(profileId, profileName, profileDesc, displayOrder, visible, filterRestrictions);
|
||||
}
|
||||
public ClockSyncProfile(ClockSyncProfileCollection.ClockSyncProfileDefaults defaults, DASRestriction[] restrictions)
|
||||
{
|
||||
GetProfileInfo(defaults, out var displayName, out var description, out var profileId, out var displayOrder, out var visible);
|
||||
Initialize(profileId, displayName, description, displayOrder, visible, restrictions);
|
||||
}
|
||||
private void Initialize(int profileId, string profileName, string profileDesc, int displayOrder, bool visible, DASRestriction[] filterRestrictions)
|
||||
{
|
||||
ProfileId = profileId;
|
||||
ProfileName = profileName;
|
||||
ProfileDesc = profileDesc;
|
||||
DisplayOrder = displayOrder;
|
||||
Visible = visible;
|
||||
FilterRestrictions = filterRestrictions;
|
||||
}
|
||||
private static void GetProfileInfo(ClockSyncProfileCollection.ClockSyncProfileDefaults profile, out string displayName, out string description, out int profileId,
|
||||
out int displayOrder, out bool visible)
|
||||
{
|
||||
profileId = (int)profile;
|
||||
|
||||
var enumType = typeof(ClockSyncProfileCollection.ClockSyncProfileDefaults);
|
||||
var memberInfos = enumType.GetMember(profile.ToString());
|
||||
var enumValueMemberInfo = Array.Find(memberInfos, m => m.DeclaringType == enumType);
|
||||
var valueAttributes = enumValueMemberInfo.GetCustomAttributes(typeof(DisplayAttribute), false);
|
||||
|
||||
description = ((DisplayAttribute)valueAttributes[0]).GetDescription();
|
||||
displayName = ((DisplayAttribute)valueAttributes[0]).GetName();
|
||||
displayOrder = ((DisplayAttribute)valueAttributes[0]).GetOrder() ?? int.MaxValue;
|
||||
|
||||
valueAttributes = enumValueMemberInfo.GetCustomAttributes(typeof(BrowsableAttribute), false);
|
||||
visible = ((BrowsableAttribute)valueAttributes[0]).Browsable;
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return ProfileName;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user