using System; using System.Collections.Generic; using System.Text; using DTS.Common.Utils; using DTS.DASLib.Command.SLICE; namespace DTS.Slice.Service { public class Attribute { protected enum AttributeInterface { Arm, Event, System, User } protected AttributeInterface Store { get; set; } protected AttributeTypes.AttributeDataTypes datatype; protected ushort key; protected object value; public const int MaxSingleAttributeSize = 500; public const int BulkAttributeStartNumber = 3000; //public AttributeStore Store { get { return _store; } } //public UInt16 StoreNumber { get { return _storenumber; } set { _storenumber = value; } } //public UInt16 Location { get { return _location; } set { _location = value; } } //public AttributeTypes.AttributeDataTypes DataType { get { return _datatype; } } //public string Description { get { return _description; } } //public byte TypeValue { get { return _typevalue; } } //protected byte[] Data { get { return _data; } set { _data = value; } } //public int Length { get { if (null == _data) return 0; else return _data.Length; } } protected Dictionary ByteArrayToDict(byte[] bytes) { // The dictionary will be transported as // pairs consisting of one byte + 8 bytes for the double byte k; double val; const int PairLength = sizeof(byte) + sizeof(double); int NumberOfPairs = bytes.Length / PairLength; int offset = 0; var dict = new Dictionary(NumberOfPairs); for (int idx = 0; idx < NumberOfPairs; idx++) { ByteConvertor.Convert(bytes, offset, out k); offset += sizeof(byte); ByteConvertor.Convert(bytes, offset, out val); offset += sizeof(double); dict.Add(k, val); } return dict; } protected byte[] DictToByteArray(Dictionary dict) { var NumberOfPairs = dict.Count; var byteArray = new byte[(sizeof(byte) + sizeof(double)) * NumberOfPairs]; int offset = 0; foreach (var pair in dict) { byteArray[offset] = pair.Key; offset += sizeof(byte); Array.Copy(ByteConvertor.ToByteArray(pair.Value), 0, byteArray, offset, sizeof(double)); offset += sizeof(double); } return byteArray; } protected Attribute() { } } }