Esempio n. 1
0
        /// <summary>
        /// Получает свойства из массива байт
        /// </summary>
        /// <param name="data"></param>
        /// <param name="serializedDataLength"></param>
        public static Threshold ConvertForComponentDirective(byte[] data)
        {
            var item = new Threshold();

            if (data == null)
            {
                data = new byte[SerializedDataLengthComponentDirective];
            }
            var serializedFirstPerformance = new byte[Lifelength.SerializedDataLength];

            Array.Copy(data, 0, serializedFirstPerformance, 0, Lifelength.SerializedDataLength);

            item.FirstPerformanceSinceNew = Lifelength.ConvertFromByteArray(serializedFirstPerformance);

            var serializedFirstNotification = new byte[Lifelength.SerializedDataLength];

            Array.Copy(data, Lifelength.SerializedDataLength, serializedFirstNotification, 0, Lifelength.SerializedDataLength);

            item.FirstNotification = Lifelength.ConvertFromByteArray(serializedFirstNotification);

            var serializedrepeatPerform = new byte[Lifelength.SerializedDataLength];

            Array.Copy(data, Lifelength.SerializedDataLength * 2, serializedrepeatPerform, 0, Lifelength.SerializedDataLength);

            item.RepeatInterval = Lifelength.ConvertFromByteArray(serializedrepeatPerform);

            var serializedNotification = new byte[Lifelength.SerializedDataLength];

            Array.Copy(data, Lifelength.SerializedDataLength * 3, serializedNotification, 0, Lifelength.SerializedDataLength);

            item.RepeatNotification = Lifelength.ConvertFromByteArray(serializedNotification);

            var serializedWarranty = new byte[Lifelength.SerializedDataLength];

            Array.Copy(data, Lifelength.SerializedDataLength * 4, serializedWarranty, 0, Lifelength.SerializedDataLength);

            item.Warranty = Lifelength.ConvertFromByteArray(serializedWarranty);

            var serializedWarrantyNotification = new byte[Lifelength.SerializedDataLength];

            Array.Copy(data, Lifelength.SerializedDataLength * 5, serializedWarrantyNotification, 0, Lifelength.SerializedDataLength);

            item.WarrantyNotification = Lifelength.ConvertFromByteArray(serializedWarrantyNotification);

            item.PerformRepeatedly = data[Lifelength.SerializedDataLength * 6] == 1;

            item.FirstPerformanceConditionType = data[Lifelength.SerializedDataLength * 6 + 1] == 1 ? ThresholdConditionType.WhicheverLater : ThresholdConditionType.WhicheverFirst;

            // если еще есть данные то рекурсивно считываем и его
            var dataIndex = SerializedDataLengthComponentDirective;
            var dataLeft  = data.Length - dataIndex;

            if (dataLeft >= sizeof(long))
            {
                var serializedEffectivityDate = new byte[sizeof(long)];
                Array.Copy(data, dataIndex, serializedEffectivityDate, 0, sizeof(long));

                item.EffectiveDate = new DateTime(DbTypes.Int64FromByteArray(serializedEffectivityDate, 0));
            }

            dataLeft  -= sizeof(long);
            dataIndex += sizeof(long);

            if (dataLeft >= Lifelength.SerializedDataLength)
            {
                var serializedRepeatNotificaction = new byte[Lifelength.SerializedDataLength];
                Array.Copy(data, dataIndex, serializedRepeatNotificaction, 0, Lifelength.SerializedDataLength);

                item.FirstPerformanceSinceEffectiveDate = Lifelength.ConvertFromByteArray(serializedRepeatNotificaction);
            }

            return(item);
        }
Esempio n. 2
0
        /// <summary>
        /// Получает свойства из массива байт
        /// </summary>
        /// <param name="data"></param>
        public static Threshold ConvertForDirective(byte[] data)
        {
            Threshold item = new Threshold();

            if (data == null)
            {
                data = new byte[SerializedDataLength];
            }
            byte[] serializedEffectivityDate = new byte[sizeof(long)];
            Array.Copy(data, 0, serializedEffectivityDate, 0, sizeof(long));

            item.EffectiveDate = new DateTime(DbTypes.Int64FromByteArray(serializedEffectivityDate, 0));

            byte[] serializedPerformSinceNew = new byte[Lifelength.SerializedDataLength];
            Array.Copy(data, sizeof(long), serializedPerformSinceNew, 0, Lifelength.SerializedDataLength);

            item.FirstPerformanceSinceNew = Lifelength.ConvertFromByteArray(serializedPerformSinceNew);

            byte[] serializedrepeatPerform = new byte[Lifelength.SerializedDataLength];
            Array.Copy(data, sizeof(long) + Lifelength.SerializedDataLength, serializedrepeatPerform, 0, Lifelength.SerializedDataLength);

            item.RepeatInterval = Lifelength.ConvertFromByteArray(serializedrepeatPerform);

            byte[] serializedNotification = new byte[Lifelength.SerializedDataLength];
            Array.Copy(data, sizeof(long) + Lifelength.SerializedDataLength * 2, serializedNotification, 0, Lifelength.SerializedDataLength);

            item.FirstNotification = Lifelength.ConvertFromByteArray(serializedNotification);

            item.PerformSinceNew           = data[sizeof(long) + Lifelength.SerializedDataLength * 3] == 1;
            item.PerformSinceEffectiveDate = data[sizeof(long) + Lifelength.SerializedDataLength * 3 + 1] == 1;
            item.PerformRepeatedly         = data[sizeof(long) + Lifelength.SerializedDataLength * 3 + 2] == 1;

            byte[] serializedSinceEffectivityLifelength = new byte[Lifelength.SerializedDataLength];
            Array.Copy(data, sizeof(long) + Lifelength.SerializedDataLength * 3 + 3, serializedSinceEffectivityLifelength, 0, Lifelength.SerializedDataLength);

            item.FirstPerformanceSinceEffectiveDate = Lifelength.ConvertFromByteArray(serializedSinceEffectivityLifelength);

            // если у нас еще есть данные то рекурсивно считываем и его
            int dataIndex = SerializedDataLength;
            int dataLeft  = data.Length - SerializedDataLength;

            if (dataLeft >= Lifelength.SerializedDataLength)
            {
                byte[] serializedRepeatNotificaction = new byte[Lifelength.SerializedDataLength];
                Array.Copy(data, sizeof(long) + Lifelength.SerializedDataLength * 4 + 3, serializedRepeatNotificaction, 0, Lifelength.SerializedDataLength);

                item.RepeatNotification = Lifelength.ConvertFromByteArray(serializedRepeatNotificaction);

                dataLeft  -= Lifelength.SerializedDataLength;
                dataIndex += Lifelength.SerializedDataLength;
            }

            if (dataLeft >= sizeof(byte))
            {
                item.FirstPerformanceConditionType = data[dataIndex] == 0
                                                                                                        ? ThresholdConditionType.WhicheverFirst
                                                                                                        : ThresholdConditionType.WhicheverLater;
                dataLeft  -= sizeof(byte);
                dataIndex += sizeof(byte);
            }

            if (dataLeft >= sizeof(byte))
            {
                item.RepeatPerformanceConditionType = data[dataIndex] == 0
                                                                                                        ? ThresholdConditionType.WhicheverFirst
                                                                                                        : ThresholdConditionType.WhicheverLater;
            }

            return(item);
        }