public async Task Execute() { var allFacilities = await _facilityDataService.GetAll(); var oldDevices = await _deviceDataService.GetAll(); foreach (var facility in allFacilities) { var dirInfo = new DirectoryInfo(facility.Path); var devices = dirInfo.GetDirectories() .Select(deviceInfo => new { deviceInfo, nameSplit = deviceInfo.Name.Split('_') }) .Where(d => d.nameSplit.Length == 4 && d.nameSplit[0] == "M" && int.TryParse(d.nameSplit[1], out _)) // check if the folder name has format of M_NR_NAME .Where(d => !_nameFilterList.Contains(d.deviceInfo.Name)) // check if folder name is in filter list .Select(d => new Device { Path = d.deviceInfo.FullName, Name = d.nameSplit[2], DeviceNumber = int.Parse(d.nameSplit[1]), Facility = facility }) .ToList(); var filteredList = devices.Where(s => oldDevices.All(os => os.Path != s.Path)).ToList(); facility.Devices = filteredList; await _facilityDataService.Update(facility.Id, facility); } }
public async Task Execute() { if (string.IsNullOrEmpty(_instructionFolderName)) { return; } var allDevices = await _deviceDataService.GetAll(); var oldInstructions = await _instructionDataService.GetAll(); foreach (var device in allDevices) { var instructionPath = Path.Join(device.Path, _instructionFolderName); var dirInfo = new DirectoryInfo(instructionPath); if (!dirInfo.Exists) { continue; } var instructions = dirInfo.GetFiles($"*.{Extension}") .Select(instructionInfo => new { instructionInfo, nameSplit = instructionInfo.Name.Replace($".{Extension}", "").Split('_') }) .Where(i => i.nameSplit.Length == 2 && DateTime.TryParse(i.nameSplit[1], out _)) // check if the folder name has format of USERNAME_DATE .Where(i => !_nameFilterList.Contains(i.instructionInfo .Name)) // check if folder name is in filter list .Select(i => { var newInstruction = new Instruction { Path = i.instructionInfo.FullName, CreatedAt = DateTime.Parse(i.nameSplit[1]), DeviceId = device.Id }; if (!Helper.IsValidEmail(i.nameSplit[0])) { newInstruction.OldInstructedString = i.nameSplit[0]; } return(newInstruction); }) .ToList(); var filteredList = instructions.Where(s => oldInstructions.All(os => os.Path != s.Path)).ToList(); await _instructionDataService.CreateAll(filteredList); //device.Instructions = filteredList; //await _deviceDataService.Update(device.Id, device); } }
public async Task Execute() { if (string.IsNullOrEmpty(_serviceReportFolderName)) { return; } var allDevices = await _deviceDataService.GetAll(); var oldInstructions = await _serviceReportDataService.GetAll(); foreach (var device in allDevices) { var serviceReportPath = Path.Join(device.Path, _serviceReportFolderName); var dirInfo = new DirectoryInfo(serviceReportPath); if (!dirInfo.Exists) { continue; } var serviceReports = dirInfo.GetFiles($"*.{Extension}") .Select(reportInfo => new { reportInfo, nameSplit = reportInfo.Name.Replace($".{Extension}", "").Split('_') }) .Where(i => i.nameSplit.Length == 3 && // check if the folder name has format of DEVICENAME_DATE_VALIDITY DateTime.TryParse(i.nameSplit[1], out _) && ServiceReport.StringValidityMap.ContainsKey(i.nameSplit[2])) .Where(i => !_nameFilterList.Contains(i.reportInfo.Name)) // check if folder name is in filter list .Select(i => new ServiceReport { Path = i.reportInfo.FullName, CreatedAt = DateTime.Parse(i.nameSplit[1]), Validity = ServiceReport.StringValidityMap[i.nameSplit[2]], Device = device }) .ToList(); var filteredList = serviceReports.Where(s => oldInstructions.All(os => os.Path != s.Path)).ToList(); device.ServiceReports = filteredList; await _deviceDataService.Update(device.Id, device); } }