private static bool IsFailureBeforeDate(Failure failure, DateTime referenceDate) { return(Common.Earlier(GetObjectTimeFromDateTime(failure.Time), referenceDate.Day, referenceDate.Month, referenceDate.Year) == 1); }
/// <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) { var problematicDevices = new HashSet <int>(); for (int i = 0; i < failureTypes.Length; i++) { if (Common.IsFailureSerious(failureTypes[i]) == 1 && Common.Earlier(times[i], day, month, year) == 1) { problematicDevices.Add(deviceId[i]); } } var result = new List <string>(); foreach (var device in devices) { if (problematicDevices.Contains((int)device["DeviceId"])) { result.Add(device["Name"] as string); } } ////////////////////////////////////////////////////////////// DateTime currentDatetime = new DateTime(year, month, day); ////////////////////////////////////////////////////////////// List <Failure> failures = new List <Failure>(); for (int i = 0; i < failureTypes.Length; i++) { Failure currentFailure = new Failure ( (FailureTypes)failureTypes[i], deviceId[i], new DateTime(Convert.ToInt32(times[i][2]), Convert.ToInt32(times[i][1]), Convert.ToInt32(times[i][0])) ); failures.Add(currentFailure); } ////////////////////////////////////////////////////////////// List <Device> listOfDevices = new List <Device>(); for (int i = 0; i < devices.Count; i++) { Device currentDevice = new Device(Convert.ToInt32(devices[i].Values.First()), devices[i].Values.Last().ToString()); listOfDevices.Add(currentDevice); } ////////////////////////////////////////////////////////////// return(FindDevicesFailedBeforeDate(currentDatetime, failures, listOfDevices)); //List<string> resultX = new List<string>(); //for (int i = 0; i < failures.Count; i++) //{ // if (Failure.IsFailureSerious(Convert.ToInt32(failures[i].failure)) && failures[i].Earlier(currentDatetime)) // { // foreach (var item in listOfDevices) // { // if (item.ID == failures[i].device) // resultX.Add(item.Name); // } // } //} //return resultX; }