/// <summary>
        /// </summary>
        /// <param name="day"></param>
        /// <param name="failureTypes">
        /// 0 for unexpected shutdown,
        /// 1 for short non-responding,
        /// 2 for hardware failures,
        /// 3 for connection problems
        /// </param>
        /// <param name="deviceId"></param>
        /// <param name="times"></param>
        /// <param name="devices"></param>
        /// <returns></returns>
        public static List <string> FindDevicesFailedBeforeDateObsolete(
            int day,
            int month,
            int year,
            int[] failureTypes,
            int[] deviceId,
            object[][] times,
            List <Dictionary <string, object> > devices)
        {
            // refactored code
            // prepare for new function
            // cast day+month+year to DateTime
            DateTime obsoleteDate = new DateTime(year, month, day);
            // cast device dict list to List<Device>
            List <Device> castedDevices = new List <Device>();

            castedDevices = devices.Select(s => Common.DeviceDictToDeviceClass(s)).ToList();
            if (failureTypes.Length != times.Length || failureTypes.Length != deviceId.Length || times.Length != deviceId.Length)
            {
                throw new Exception($"Length of failures list, length of failure dates list and length of failed deviceIds is not equal ({failureTypes.Length}, {times.Length}, {deviceId.Length})");
            }
            if (!times.All(s => s.Length == 3 && s.All(f => f is int)))
            {
                throw new Exception($"\"times is invalid\" ");
            }
            List <Failure> castedFailures = failureTypes.Select((s, i) => new Failure()
            {
                FailureType = (FailureType)failureTypes[i],
                Date        = new DateTime((int)times[i][2], (int)times[i][1], (int)times[i][0]),
                DeviceId    = deviceId[i]
            }).ToList();
            var newRes = ReportMaker.FindDevicesFailedBeforeDate(obsoleteDate, castedFailures, castedDevices);

            return(newRes);
        }
Пример #2
0
        public void NoDevices()
        {
            var result = ReportMaker.FindDevicesFailedBeforeDate(
                new DateTime(2010, 5, 10),
                new List <FailureType>(),
                new List <DateTime>(),
                new List <Device>());

            CollectionAssert.IsEmpty(result);
        }
Пример #3
0
        public void NoDevices()
        {
            var result = ReportMaker.FindDevicesFailedBeforeDateObsolete(
                10, 5, 2010,
                new int[] { },
                new int[] { },
                new object[][] { },
                new List <Dictionary <string, object> >());

            CollectionAssert.IsEmpty(result);
        }
Пример #4
0
        // нет устройств
        public void NoDevices()
        {
            // Поиск устройств с ошибкой до установленной даты

            var result = ReportMaker.FindDevicesFailedBeforeDateObsolete(
                10, 5, 2010,
                new int[] { },
                new int[] { },
                new object[][] { },
                new List <Dictionary <string, object> >());

            CollectionAssert.IsEmpty(result);
        }
Пример #5
0
        public void FilterSingleDevice()
        {
            var lD = new List <Device>
            {
                new Device
                {
                    DeviceId = 0,
                    Name     = "0"
                },
                new Device
                {
                    DeviceId = 1,
                    Name     = "1"
                },
                new Device
                {
                    DeviceId = 2,
                    Name     = "2"
                },
                new Device
                {
                    DeviceId = 3,
                    Name     = "3"
                },
            };
            var result = ReportMaker.FindDevicesFailedBeforeDate(
                new DateTime(2010, 5, 10),
                new List <FailureType> {
                FailureType.unexpected,
                FailureType.nonResponding,
                FailureType.hardware,
                FailureType.connection
            },
                new List <DateTime>
            {
                new DateTime(2010, 4, 9),
                new DateTime(2010, 4, 9),
                new DateTime(2010, 5, 11),
                new DateTime(2010, 4, 9),
            }, lD
                );

            CollectionAssert.AreEqual(new[] { "0" }, result);
        }
Пример #6
0
        public void FilterManyDevices()
        {
            var lD = new List <Device>
            {
                new Device
                {
                    DeviceId = 0,
                    Name     = "Device A"
                },
                new Device
                {
                    DeviceId = 1,
                    Name     = "Device B"
                },
                new Device
                {
                    DeviceId = 2,
                    Name     = "Device C"
                },
                new Device
                {
                    DeviceId = 3,
                    Name     = "Device D"
                },
            };
            var result = ReportMaker.FindDevicesFailedBeforeDate(
                new DateTime(2010, 5, 10),
                new List <FailureType> {
                FailureType.unexpected,
                FailureType.nonResponding,
                FailureType.unexpected,
                FailureType.hardware
            },
                new List <DateTime>
            {
                new DateTime(2010, 5, 9),
                new DateTime(2009, 6, 1),
                new DateTime(2010, 5, 9),
                new DateTime(2010, 5, 19)
            }, lD);

            CollectionAssert.AreEqual(new[] { "Device A", "Device C" }, result);
        }
Пример #7
0
        public void FilterManyDevices()
        {
            var result = ReportMaker.FindDevicesFailedBeforeDateObsolete(
                10,
                5,
                2010,
                new[] { 0, 1, 0, 2 },
                new[] { 0, 1, 2, 3 },
                new[]
            {
                new object[] { 9, 5, 2010 },
                new object[] { 1, 6, 2009 },
                new object[] { 9, 5, 2010 },
                new object[] { 19, 5, 2010 }
            },
                new List <Dictionary <string, object> >
            {
                new Dictionary <string, object>
                {
                    ["DeviceId"] = 0,
                    ["Name"]     = "Device A"
                },
                new Dictionary <string, object>
                {
                    ["DeviceId"] = 1,
                    ["Name"]     = "Device B"
                },
                new Dictionary <string, object>
                {
                    ["DeviceId"] = 2,
                    ["Name"]     = "Device C"
                },
                new Dictionary <string, object>
                {
                    ["DeviceId"] = 3,
                    ["Name"]     = "Device D"
                },
            });

            CollectionAssert.AreEqual(new[] { "Device A", "Device C" }, result);
            System.Console.Read();
        }
Пример #8
0
        public void FilterSingleDevice()
        {
            var result = ReportMaker.FindDevicesFailedBeforeDateObsolete(
                10,
                5,
                2010,
                new[] { 0, 1, 2, 3 },
                new[] { 0, 1, 2, 3 },
                new[]
            {
                new object[] { 9, 4, 2010 },
                new object[] { 9, 4, 2010 },
                new object[] { 11, 5, 2010 },
                new object[] { 9, 4, 2010 }
            },
                new List <Dictionary <string, object> >
            {
                new Dictionary <string, object>
                {
                    ["DeviceId"] = 0,
                    ["Name"]     = "0"
                },
                new Dictionary <string, object>
                {
                    ["DeviceId"] = 1,
                    ["Name"]     = "1"
                },
                new Dictionary <string, object>
                {
                    ["DeviceId"] = 2,
                    ["Name"]     = "2"
                },
                new Dictionary <string, object>
                {
                    ["DeviceId"] = 3,
                    ["Name"]     = "3"
                },
            });

            CollectionAssert.AreEqual(new[] { "0" }, result);
            System.Console.Read();
        }