private static void CheckForDestinationsWithoutPrefixes() { Console.WriteLine("Prefixes".PadRight(30, '.') + "DestinationsWithoutPrefixes() -- started"); StaticVariable.ConsoleOutput.Add("Prefixes".PadRight(30, '.') + "DestinationsWithoutPrefixes() -- started"); Dictionary <string, string> tableAndNames = new Dictionary <string, string>(); HashSet <string> sourceDestinations = ValidateData.GetSourceAndDestinationNames(); var queryMissingPrefixesAndTables = (from drm in StaticVariable.CustomerDetailsDataRecord orderby drm.StdPrefixName select new { drm.StdPrefixName, drm.CustomerTableName }).Distinct(); foreach (var entry in queryMissingPrefixesAndTables) { try { tableAndNames.Add(entry.StdPrefixName.ToUpper(), entry.StdPrefixName.PadRight(40) + " " + entry.CustomerTableName); } catch (Exception e) { StaticVariable.ProgressDetails.Add(Environment.NewLine + "Prefixes::DestinationsWithoutPrefixes()"); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "Error adding to tableAndNames dictionary"); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + e.Message); ErrorProcessing.StopProcessDueToFatalErrorOutputToLog(); } } var queryMissingPrefixes = from drm in StaticVariable.CustomerDetailsDataRecord orderby drm.StdPrefixName select drm.StdPrefixName.ToUpper(); var queryPrefixNames = (from pn in StaticVariable.PrefixNumbersRecord orderby pn.stdPrefixName select pn.stdPrefixName.ToUpper()).Distinct(); var missingPrefixes = queryMissingPrefixes.Except(queryPrefixNames).ToList(); missingPrefixes.Sort(); if (missingPrefixes.Any()) { StaticVariable.ProgressDetails.Add(Environment.NewLine + "Prefixes::DestinationsWithoutPrefixes()"); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "No Prefix Found or the prefix name does not match the Standard or customer name:"); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "Change the prefix name to match either the Standard or customer name:"); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "Or else the prefix for that name may not exist in the prefix table." + Environment.NewLine); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "Standard Name".PadRight(41, ' ') + "Table"); List <string> specificCountries = new List <string>(); foreach (var entry in missingPrefixes) { try { if (sourceDestinations.Contains(entry.ToUpper())) { continue; } if (StaticVariable.MissingCountryExceptions.Contains(entry.ToUpper())) { specificCountries.Add(entry.ToUpper()); } else { StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + ValidateData.CapitaliseWord(tableAndNames[entry.ToUpper()])); } } catch (Exception e) { StaticVariable.ProgressDetails.Add(Environment.NewLine + "Prefixes::DestinationsWithoutPrefixes()"); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "Error finding table name for prefix name"); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + e.Message); ErrorProcessing.StopProcessDueToFatalErrorOutputToLog(); } } if (specificCountries.Any()) { StaticVariable.ProgressDetails.Add(Environment.NewLine + "Prefixes::DestinationsWithoutPrefixes()"); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "These prefixes may exist in the prefix file."); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "If so change the prefix name to match the Xlsx name:"); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "Xlsx name:" + Environment.NewLine); foreach (var item in specificCountries) { try { var query = from db in StaticVariable.CustomerDetailsDataRecord where item.ToUpper().Equals(db.StdPrefixName.ToUpper()) select db.CustomerPrefixName; foreach (var name in query) { StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + ValidateData.CapitaliseWord(name)); } } catch (Exception e) { StaticVariable.ProgressDetails.Add(Environment.NewLine + "Prefixes::DestinationsWithoutPrefixes()"); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "Error adding specific countries - " + item); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + e.Message); ErrorProcessing.StopProcessDueToFatalErrorOutputToLog(); } } } } Console.WriteLine("Prefixes".PadRight(30, '.') + "DestinationsWithoutPrefixes() -- finished"); StaticVariable.ConsoleOutput.Add("Prefixes".PadRight(30, '.') + "DestinationsWithoutPrefixes() -- finished"); }
private static void MatchPrefixNamesWithRegEx(List <string> prefixesFromIniFiles) { Console.WriteLine("Prefixes".PadRight(30, '.') + "MatchPrefixNamesWithRegEx() -- started"); StaticVariable.ConsoleOutput.Add("Prefixes".PadRight(30, '.') + "MatchPrefixNamesWithRegEx() -- started"); const int prefixElement = 1; const int prefixNameElement = 2; const int tableElement = 0; Dictionary <string, string> prefixNamesMatchedMultipleTimes = new Dictionary <string, string>(); Dictionary <string, string> bandsMatched = new Dictionary <string, string>(); List <string> prefixNamesOnly = new List <string>(); string destinationName = string.Empty; string regExExtraSpaces = "\x0020{2,}"; string regExNoise = @"\(|\)|( -|- )|\,|'"; Timer newTimer = new System.Timers.Timer(10000); // 2 sec interval var dupeBandsForSamePrefixName = new List <string>(); var prefixNamesMatchedMoreThanOnce = new List <string>(); var prefixNamesNotMatchedByRegex = new List <string>(); Regex regExRemoveNoise = new Regex(regExNoise, RegexOptions.Compiled); Regex regExRemoveExtraSpaces = new Regex(regExExtraSpaces, RegexOptions.Compiled); var sourceDestinations = ValidateData.GetSourceAndDestinationNames(); foreach (var names in prefixesFromIniFiles) { string[] name = names.Split('\t'); if (sourceDestinations.Contains(name[prefixNameElement].ToUpper())) { continue; } prefixNamesOnly.Add(name[prefixNameElement]); } prefixNamesOnly = prefixNamesOnly.Distinct().ToList(); prefixNamesOnly.Sort(); foreach (string prefixName in prefixNamesOnly) { var found = false; try { destinationName = prefixName; destinationName = regExRemoveNoise.Replace(destinationName, " "); destinationName = regExRemoveExtraSpaces.Replace(destinationName, " "); } catch (Exception e) { StaticVariable.ProgressDetails.Add("Prefixes::MatchPrefixNamesWithRegEx()"); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "There may be a problem with the input destination"); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + e.Message); ErrorProcessing.StopProcessDueToFatalErrorOutputToLog(); } foreach (string regexExpression in StaticVariable.CombinedRegex) { string[] aryLine = regexExpression.Split(new char[] { '\t' }); string regExPattern = aryLine[0]; string regExBand = aryLine[1].Trim(); string regexStandardName = aryLine[2].Trim(); try { var regExCountry = new Regex(regExPattern, RegexOptions.IgnoreCase); if (StaticVariable.MissingCountryExceptions.Contains(destinationName.ToUpper())) { try { destinationName = StaticVariable.CountryExceptions[destinationName.ToUpper()]; } catch (Exception e) { StaticVariable.ProgressDetails.Add(Environment.NewLine + "Prefixes::MatchPrefixNamesWithRegEx()"); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "The prefix name was not found in the exceptions list"); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + e.Message); ErrorProcessing.StopProcessDueToFatalErrorOutputToLog(); } } if (regExCountry.IsMatch(destinationName)) { newTimer.Elapsed += OnTimedEvent; newTimer.AutoReset = true; newTimer.Enabled = true; found = true; try { bandsMatched.Add(regExBand, prefixName.PadRight(40) + "\t" + regExBand.PadRight(10) + "\t" + regexStandardName.PadRight(40)); } catch (Exception) { dupeBandsForSamePrefixName.Add(bandsMatched[regExBand] + " : " + prefixName); } try { prefixNamesMatchedMultipleTimes.Add(prefixName, prefixName.PadRight(40) + "\t" + regExBand.PadRight(10) + "\t" + regexStandardName.PadRight(40)); } catch (Exception) { prefixNamesMatchedMoreThanOnce.Add(prefixNamesMatchedMultipleTimes[prefixName] + " : " + regExBand.PadRight(10) + "\t" + regexStandardName); } StaticVariable.PrefixesMatchedByRegEx.Add(regExBand + "\t" + regexStandardName + "\t" + prefixName); } } catch (Exception e) { StaticVariable.ProgressDetails.Add(Environment.NewLine + "Prefixes::MatchPrefixNamesWithRegEx()"); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "There may be a problem with the regex"); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "Check if there are more than 1 international or domestic regex files"); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + e.Message); ErrorProcessing.StopProcessDueToFatalErrorOutputToLog(); } } if (!found) { prefixNamesNotMatchedByRegex.Add(destinationName); } } if (dupeBandsForSamePrefixName.Any()) { dupeBandsForSamePrefixName.Sort(); StaticVariable.ProgressDetails.Add(Environment.NewLine + "Prefixes::MatchPrefixNamesWithRegEx()"); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "The Band is assigned to more than one to Prefix Name."); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "The same Regex might be matching the 'First Matched Prefix Name' and the 'Subsequent Matched Prefix Name'."); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "The same Prefix name may be duplicated in other files (eg. satellite & international, if prefixes are supplied"); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "Are there two International ini or two mobile ini files. Delete the non required files." + Environment.NewLine); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "First Matched Prefix Name".PadRight(40) + "\tDuplicate Band".PadRight(10) + "\tStandard Name".PadRight(40) + " : Subsequent Matched Prefix Name"); foreach (var item in dupeBandsForSamePrefixName) { StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + item); } ErrorProcessing.StopProcessDueToFatalErrorOutputToLog(); } if (prefixNamesMatchedMoreThanOnce.Any()) { prefixNamesMatchedMoreThanOnce.Sort(); StaticVariable.ProgressDetails.Add(Environment.NewLine + "Prefixes::MatchPrefixNamesWithRegEx()"); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "Prefix Name assigned to more than one band"); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "E.g. If Inmarsat B. Add new entry to input Xlsx file and change to 'Inmarsat B Land' & 'Inmarsat B Maritime'. "); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "If prefixes were supplied you may need to delete these bands in RegEx file and add 'Inmarsat B' regex" + Environment.NewLine); StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "PrefixName".PadRight(40) + "\t" + "Band".PadRight(10) + "\t" + "Standard Name".PadRight(40) + " : Other Band".PadRight(10) + "\tStandard Prefix Name"); foreach (var item in prefixNamesMatchedMoreThanOnce) { StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + item); } ErrorProcessing.StopProcessDueToFatalErrorOutputToLog(); } //// /*if (prefixNamesNotMatchedByRegex.Any()) //Is this needed? * { * StaticVariable.ProgressDetails.Add(Environment.NewLine + "Prefixes::MatchPrefixNamesWithRegEx(). Is this needed?"); * StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "Prefixes without regex."); * prefixNamesNotMatchedByRegex.Sort(); * foreach (string entry in prefixNamesNotMatchedByRegex) * { * if(StaticVariable.CountryExceptions.Contains(entry.ToUpper())) * { * StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + entry); * } * } * ErrorProcessing.StopProcessDueToFatalErrorOutputToLog(); * }*/ ///// newTimer.Enabled = false; Console.WriteLine("Prefixes".PadRight(30, '.') + "MatchPrefixNamesWithRegEx() -- finished"); StaticVariable.ConsoleOutput.Add("Prefixes".PadRight(30, '.') + "MatchPrefixNamesWithRegEx() -- finished"); }