Files
2020-09-12 16:11:43 +02:00

243 lines
8.2 KiB
C#

using Step.Model.DatabaseModels;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Step.Model.DTOModels.ToolModels
{
public class DTONewNcFamilyModel
{
[Required]
public string Name { get; set; }
[Required]
public byte ToolType { get; set; }
[Required]
public byte RightSize { get; set; }
[Required]
public byte LeftSize { get; set; }
[Required]
public byte TcpTable { get; set; }
[Required]
public byte Gamma { get; set; }
[Required]
public byte RotationType { get; set; }
[Required]
public bool Cooling { get; set; }
[Required]
public bool Cooling1 { get; set; }
[Required]
public bool Cooling2 { get; set; }
[Required]
public bool Cooling3 { get; set; }
[Required]
public bool Cooling4 { get; set; }
[Required]
public bool Cooling5 { get; set; }
[Required]
public bool Cooling6 { get; set; }
[Required]
public bool Cooling7 { get; set; }
[Required]
public int MaxSpeed { get; set; }
[Required]
public byte MaxLoad { get; set; }
[Required]
public byte MinLoadPctAutoload { get; set; }
[Required]
public byte MaxLoadPctAutoload { get; set; }
[Required]
public byte DynamicCompensation { get; set; }
[Required]
public byte MinLoadDynamicCompensation { get; set; }
[Required]
public byte MaxLoadDynamicCompensation { get; set; }
[Required]
public byte LifeType { get; set; }
[Required]
public int NominalLife { get; set; }
[Required]
public int ReviveDelta { get; set; }
public static explicit operator DTONewNcFamilyModel(DbNcFamilyModel obj)
{
// Get bit values
BitArray coolingByte = new BitArray(new byte[] { obj.CoolingByte });
bool[] bits = new bool[8];
coolingByte.CopyTo(bits, 0);
return new DTONcFamilyModel()
{
Id = obj.FamilyId,
Name = obj.Name,
ToolType = obj.ToolType,
RightSize = obj.RightSize,
LeftSize = obj.LeftSize,
TcpTable = obj.TcpTable,
Gamma = obj.Gamma,
RotationType = obj.RotationType,
Cooling = bits[0],
Cooling1 = bits[1],
Cooling2 = bits[2],
Cooling3 = bits[3],
Cooling4 = bits[4],
Cooling5 = bits[5],
Cooling6 = bits[6],
Cooling7 = bits[7],
MaxSpeed = obj.MaxSpeed,
MaxLoad = obj.MaxLoad,
MinLoadDynamicCompensation = obj.MinLoadDynamicCompensation,
MaxLoadDynamicCompensation = obj.MaxLoadDynamicCompensation,
MaxLoadPctAutoload = obj.MaxLoadPctAutoload,
MinLoadPctAutoload = obj.MinLoadPctAutoload,
DynamicCompensation = obj.DynamicCompensation,
LifeType = obj.LifeType,
NominalLife = obj.NominalLife,
ReviveDelta = obj.ReviveDelta
};
}
public static explicit operator DbNcFamilyModel(DTONewNcFamilyModel obj)
{
// Prepare status byte
bool[] result = new bool[8] { obj.Cooling, obj.Cooling1, obj.Cooling2, obj.Cooling3, obj.Cooling4, obj.Cooling5, obj.Cooling6, obj.Cooling7 };
byte coolingByte = ConvertArrayToByte(result);
return new DbNcFamilyModel()
{
Name = obj.Name,
ToolType = obj.ToolType,
RightSize = obj.RightSize,
LeftSize = obj.LeftSize,
TcpTable = obj.TcpTable,
Gamma = obj.Gamma,
RotationType = obj.RotationType,
CoolingByte = coolingByte,
MaxSpeed = obj.MaxSpeed,
MaxLoad = obj.MaxLoad,
MinLoadDynamicCompensation = obj.MinLoadDynamicCompensation,
MaxLoadDynamicCompensation = obj.MaxLoadDynamicCompensation,
MaxLoadPctAutoload = obj.MaxLoadPctAutoload,
MinLoadPctAutoload = obj.MinLoadPctAutoload,
DynamicCompensation = obj.DynamicCompensation,
LifeType = obj.LifeType,
NominalLife = obj.NominalLife,
ReviveDelta = obj.ReviveDelta,
};
}
protected static byte ConvertArrayToByte(bool[] bits)
{
BitArray bitField = new BitArray(bits); //BitArray takes a bool[]
byte[] bytes = new byte[1];
bitField.CopyTo(bytes, 0);
return bytes[0];
}
}
public class DTONcFamilyModel : DTONewNcFamilyModel
{
public short Id { get; set; }
public List<DTONcToolModel> ChildTools { get; set; }
public static explicit operator DTONcFamilyModel(DbNcFamilyModel obj)
{
List<DTONcToolModel> tools = new List<DTONcToolModel>();
if (obj.Tools != null)
foreach (DbNcToolModel tool in obj.Tools)
{
tools.Add((DTONcToolModel)tool);
}
// Get bit values
BitArray coolingByte = new BitArray(new byte[] { obj.CoolingByte });
bool[] bits = new bool[8];
coolingByte.CopyTo(bits, 0);
return new DTONcFamilyModel()
{
Id = obj.FamilyId,
Name = obj.Name,
ToolType = obj.ToolType,
RightSize = obj.RightSize,
LeftSize = obj.LeftSize,
TcpTable = obj.TcpTable,
Gamma = obj.Gamma,
RotationType = obj.RotationType,
Cooling = bits[0],
Cooling1 = bits[1],
Cooling2 = bits[2],
Cooling3 = bits[3],
Cooling4 = bits[4],
Cooling5 = bits[5],
Cooling6 = bits[6],
Cooling7 = bits[7],
MaxSpeed = obj.MaxSpeed,
MaxLoad = obj.MaxLoad,
MinLoadDynamicCompensation = obj.MinLoadDynamicCompensation,
MaxLoadDynamicCompensation = obj.MaxLoadDynamicCompensation,
MaxLoadPctAutoload = obj.MaxLoadPctAutoload,
MinLoadPctAutoload = obj.MinLoadPctAutoload,
DynamicCompensation = obj.DynamicCompensation,
LifeType = obj.LifeType,
NominalLife = obj.NominalLife,
ReviveDelta = obj.ReviveDelta,
ChildTools = tools
};
}
public static explicit operator DbNcFamilyModel(DTONcFamilyModel obj)
{
// Prepare status byte
bool[] result = new bool[8] { obj.Cooling, obj.Cooling1, obj.Cooling2, obj.Cooling3, obj.Cooling4, obj.Cooling5, obj.Cooling6, obj.Cooling7 };
byte coolingByte = ConvertArrayToByte(result);
return new DbNcFamilyModel()
{
FamilyId = obj.Id,
Name = obj.Name,
ToolType = obj.ToolType,
RightSize = obj.RightSize,
LeftSize = obj.LeftSize,
TcpTable = obj.TcpTable,
Gamma = obj.Gamma,
RotationType = obj.RotationType,
CoolingByte = coolingByte,
MaxSpeed = obj.MaxSpeed,
MaxLoad = obj.MaxLoad,
MinLoadDynamicCompensation = obj.MinLoadDynamicCompensation,
MaxLoadDynamicCompensation = obj.MaxLoadDynamicCompensation,
MaxLoadPctAutoload = obj.MaxLoadPctAutoload,
MinLoadPctAutoload = obj.MinLoadPctAutoload,
DynamicCompensation = obj.DynamicCompensation,
LifeType = obj.LifeType,
NominalLife = obj.NominalLife,
ReviveDelta = obj.ReviveDelta,
};
}
}
}