private void FillMigrateRule(string path) { var excelData = new ExcelReader().GetMatrixData(path, "migrate_rule"); if (excelData != null && excelData.GetLength(0) > 1 && excelData.GetLength(1) >= 5) { // row 0 = header for (int rowIndex = 1; rowIndex < excelData.GetLength(0); rowIndex++) { string name = excelData[rowIndex, 0]; var contentTypes = excelData[rowIndex, 1].Split(',').Select(x => x.Trim()).Where(x => !string.IsNullOrEmpty(x)).ToArray(); var extensions = excelData[rowIndex, 2].Split(',').Select(x => x.Trim()).Where(x => !string.IsNullOrEmpty(x)).ToArray(); var pattern = excelData[rowIndex, 3]; var targetPath = excelData[rowIndex, 4]; // valid if (string.IsNullOrEmpty(pattern) && extensions.Length == 0 && contentTypes.Length == 0) { // invalid rule } else if (string.IsNullOrEmpty(targetPath)) { // invalid target path } else { var rule = new ProcessRule(name, contentTypes, extensions, pattern, targetPath); _migrateRules.Add(rule); } } } }
private ProcessRule GetRuleWithMaxPriority(List <Tuple <ProcessRule, int> > potencionalRules) { int maxPriotity = 0; ProcessRule strongestRule = null; foreach (var ruleAndPriority in potencionalRules) { if (ruleAndPriority.Item2 > maxPriotity) { strongestRule = ruleAndPriority.Item1; maxPriotity = ruleAndPriority.Item2; } } return(strongestRule); }