private void CreateMeasureUnit(string rowData, DateTime timeStamp) { // only if any settings are available var setts = MeasureSettings.Where(x => x.IsReadyToUse && x.IsActive); if (rowData != null && setts.Any()) { MeasureSettingViewModel set = setts.FirstOrDefault(x => (x.UseContainsEvaluation ? rowData.Contains(x.StartCode) : x.StartCode == rowData) && x.MeasuredUnits.All(y => !y.IsRunning)); if (set != null) { string matchKey = null; if (set.UseKeyLockedMatch) { matchKey = Regex.Match(rowData, String.Format(MeasureSettingViewModel.KeyLockedPatternFormat, MeasureSettingViewModel.KeyLockedPattern)).Value; } set.MeasuredUnits.Add(new MeasuredUnitViewModel(set, matchKey) { StartTime = timeStamp, MeasureSetting = set }); } var setting = setts.FirstOrDefault(x => (x.UseContainsEvaluation ? rowData.Contains(x.StopCode) : x.StopCode == rowData) && x.MeasuredUnits.Any(y => y.IsRunning)); if (setting != null) { var unit = setting.MeasuredUnits.FirstOrDefault(x => x.IsRunning && (x.MeasureSetting.UseKeyLockedMatch ? Regex.IsMatch(rowData, String.Format(MeasureSettingViewModel.KeyLockedPatternFormat, $"({x.MatchKey})"), RegexOptions.IgnoreCase) : true)); if (unit != null) { unit.StopTime = timeStamp; } } } }
public MeasuredUnitViewModel(MeasureSettingViewModel setting, string matchKey = null) { MeasureSetting = setting; MatchKey = matchKey?.Replace("#", ""); }