Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("running....");

            ProcessRequiredFiles.GetDatasetsData(args);
            ProcessInputXlsxFile.ParseInputXlsxFileIntoCustomerDetailsRecord();
            ValidateData.PreRegExMatchValidateCustomerDetailsRecord();
            StaticVariable.CustomerDetailsDataRecord.Clear();
            ProcessInputXlsxFile.MatchInputXlsxFileWithRegEx(StaticVariable.InputXlsxFileDetails);
            Prefixes.ProcessPrefixesData();
            ValidateData.PostRegExMatchValidateCustomerDetailsRecord();
            Prefixes.ValidatePrefixesData();
            ValidateData.DisplayMissingDetails();

            RearrangeCompletedFiles.CreateCategoryMatrix();
            RearrangeCompletedFiles.WriteToV6TwbXlsxFile();
            RearrangeCompletedFiles.WriteOutV5Tc2Files();
            RearrangeCompletedFiles.CopyOutputXlsxFileToV6OpUtilFolder(StaticVariable.MoveOutputSpreadSheetToV6TwbFolder);
            RearrangeCompletedFiles.WriteInputXLSXFileDetailsToFinalFolder();
            ErrorProcessing.CreateAndWriteToRegExMatchedLog();


            //ValidateData.TestMethod();
            StaticVariable.ProgressDetails.Add(Environment.NewLine + "........finished");
            StaticVariable.ConsoleOutput.Add(Environment.NewLine + "........finished");
            ErrorProcessing.OutputToLogs(StaticVariable.ProgressDetails, StaticVariable.DirectoryName + @"\" + Constants.ProgressLog);
            ErrorProcessing.OutputToLogs(StaticVariable.ConsoleOutput, StaticVariable.DirectoryName + @"\" + Constants.ConsoleErrorLog);
            ErrorProcessing.OutputConsoleLog();
            Console.WriteLine("oxo....");
            MessageBox.Show("oxo");
            Environment.Exit(Constants.KillProgram);
        }
Ejemplo n.º 2
0
        private static void ReadPrefixesIntoList(string folder, string message)
        {
            Console.WriteLine("Prefixes".PadRight(30, '.') + "ReadPrefixesIntoList( " + message + " ) -- started");
            StaticVariable.ConsoleOutput.Add("Prefixes".PadRight(30, '.') + "ReadPrefixesIntoList( " + message + " ) -- started");
            const string iniExtensionSearch = @"*ini";

            string[] folders      = Directory.GetFiles(folder, iniExtensionSearch);
            string   tableName    = string.Empty;
            string   prefixName   = string.Empty;
            string   prefixNumber = string.Empty;

            foreach (string token in folders)
            {
                try
                {
                    using (StreamReader oSr = new StreamReader(File.OpenRead(token), Encoding.Unicode))
                    {
                        while (!oSr.EndOfStream)
                        {
                            string line = oSr.ReadLine();
                            if (!string.IsNullOrEmpty(line) && !line.StartsWith(";"))
                            {
                                if (line.ToUpper().Contains("TABLE NAME="))
                                {
                                    string[] lines = line.Split('=');
                                    tableName = StaticVariable.CountryCodeValue + "_" + lines[1];
                                }
                                if (line.Contains(','))
                                {
                                    string[] lines = line.Split(',');
                                    prefixName   = lines[0].Trim();
                                    prefixNumber = lines[1].Trim();
                                }
                                if (!string.IsNullOrEmpty(tableName) && !string.IsNullOrEmpty(prefixName))
                                {
                                    StaticVariable.PrefixNumbersFromIniFiles.Add(tableName + "\t" + prefixNumber + "\t" + ValidateData.CapitaliseWord(prefixName));
                                }
                            }
                        }
                        oSr.Close();
                        tableName    = string.Empty;
                        prefixName   = string.Empty;
                        prefixNumber = string.Empty;
                    }
                }
                catch (Exception e)
                {
                    StaticVariable.ProgressDetails.Add("Prefixes::CombinePrefixes()");
                    StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + message + ": Problem adding prefixes to PrefixNumbersDataRecord.");
                    StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + e.Message);
                    ErrorProcessing.StopProcessDueToFatalErrorOutputToLog();
                }
            }
            StaticVariable.PrefixNumbersFromIniFiles.Sort();
            StaticVariable.PrefixNumbersFromIniFiles = StaticVariable.PrefixNumbersFromIniFiles.Distinct().ToList();
            StaticVariable.ConsoleOutput.Add("Prefixes".PadRight(30, '.') + "ReadPrefixesIntoList( " + message + " ) -- finished");
            Console.WriteLine("Prefixes".PadRight(30, '.') + "ReadPrefixesIntoList( " + message + " ) -- finished");
        }
Ejemplo n.º 3
0
        private static void AddToCustomerDetailsDataRecordList(List <string> lst)
        {
            Console.WriteLine("ProcessInputXlsxFile".PadRight(30, '.') + "AddToPreRegExDataRecordList() -- started");
            StaticVariable.ConsoleOutput.Add("ProcessInputXlsxFile".PadRight(30, '.') + "AddToPreRegExDataRecordList() -- started");
            const string undefinedStandardInfo = "undefinedStandardBand\tundefinedStandardName\tundefinedStandardDestination\t";

            foreach (string token in lst)
            {
                try
                {
                    StaticVariable.CustomerDetailsDataRecord.Add(new DataRecord(undefinedStandardInfo + token));
                }
                catch (Exception e)
                {
                    StaticVariable.ProgressDetails.Add("ProcessInputXlsxFile::AddToPreRegExDataRecordList()");
                    StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "Problem adding list to DataRecord");
                    StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + e.Message);
                    ErrorProcessing.StopProcessDueToFatalErrorOutputToLog();
                }
            }
            Console.WriteLine("ProcessInputXlsxFile".PadRight(30, '.') + "AddToPreRegExDataRecordList() -- finished");
            StaticVariable.ConsoleOutput.Add("ProcessInputXlsxFile".PadRight(30, '.') + "AddToPreRegExDataRecordList() -- finished");
        }
Ejemplo n.º 4
0
 public DataRecord(string line)
 {
     try
     {
         string[] ary = line.Split('\t');
         StdBand                          = ary[0].Trim();
         StdPrefixName                    = ary[1].Trim();
         StdPrefixDescription             = ary[2].Trim();
         CustomerPrefixName               = ary[3].Trim();
         CustomerFirstInitialRate         = ary[4].Trim();
         CustomerFirstSubseqRate          = ary[5].Trim();
         CustomerSecondInitialRate        = ary[6].Trim();
         CustomerSecondSubseqRate         = ary[7].Trim();
         CustomerThirdInitialRate         = ary[8].Trim();
         CustomerThirdSubseqRate          = ary[9].Trim();
         CustomerFourthInitialRate        = ary[10].Trim();
         CustomerFourthSubseqRate         = ary[11].Trim();
         CustomerMinCharge                = ary[12].Trim();
         CustomerConnectionCost           = ary[13].Trim();
         CustomerUsingGroupBands          = ary[14].Trim();
         CustomerGroupBand                = ary[15].Trim();
         CustomerGroupBandDescription     = ary[16].Trim();
         CustomerTableName                = ary[17].Trim();
         CustomerDestinationType          = ary[18].Trim();
         CustomerRounding                 = ValidateData.AdjustRoundingValue(ary[19]).Trim();
         CustomerTimeScheme               = ary[20].Trim();
         CustomerUsingCustomerNames       = ary[21].Trim();
         CustomerInitialIntervalLength    = ary[22].Trim();
         CustomerSubsequentIntervalLength = ary[23].Trim();
         CustomerMinimumIntervals         = ary[24].Trim();
         CustomerIntervalsAtInitialCost   = ary[25].Trim();
         CustomerMinimumTime              = ary[26].Trim();
         CustomerDialTime                 = ary[27].Trim();
         CustomerAllSchemes               = ary[28].Trim();
         CustomerMultiLevelEnabled        = ary[29].Trim();
         CustomerMinDigits                = ary[30].Trim();
         CustomerCutOff1Cost              = ary[31].Trim();
         CustomerCutOff2Duration          = ary[32].Trim();
         ChargingType                     = ary[33].Trim();
     }
     catch (IndexOutOfRangeException i)
     {
         StaticVariable.ConsoleOutput.Add("DataRecord".PadRight(30, '.') + "DataRecord() -- started");
         StaticVariable.ProgressDetails.Add(Environment.NewLine + "DataRecord::DataRecord()");
         StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + i.Message);
         StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "Is there any data?");
         Console.WriteLine("DataRecord: The Index is out of bounds");
         Console.WriteLine(i.Message);
         ErrorProcessing.StopProcessDueToFatalErrorOutputToLog();
     }
     catch (Exception e)
     {
         StaticVariable.ConsoleOutput.Add("DataRecord".PadRight(30, '.') + "DataRecord() -- started");
         StaticVariable.ProgressDetails.Add(Environment.NewLine + "DataRecord::DataRecord()");
         StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "problem with creating the DataRecord");
         StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + e.Message);
         Console.WriteLine("DataRecord: problem with creating the DataRecord");
         Console.WriteLine(e.Message);
         ErrorProcessing.StopProcessDueToFatalErrorOutputToLog();
     }
 }
Ejemplo n.º 5
0
        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");
        }
Ejemplo n.º 6
0
        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");
        }
Ejemplo n.º 7
0
        public static void MatchInputXlsxFileWithRegEx(List <string> listToUse)
        {
            Console.WriteLine("ProcessInputXlsxFile".PadRight(30, '.') + "MatchInputXlsxFileWithRegEx() -- started");
            StaticVariable.ConsoleOutput.Add("ProcessInputXlsxFile".PadRight(30, '.') + "MatchInputXlsxFileWithRegEx() -- started");
            string    destinationName           = string.Empty;
            var       tmpList                   = new List <string>();
            const int destination               = 0;
            int       uniqueBandCounter         = 100;
            Timer     newTimer                  = new System.Timers.Timer(10000); // 2 sec interval
            string    regExAlphanumeric         = @"[0-9|a-z|A-Z]";
            string    regExExtraSpaces          = "\x0020{2,}";
            string    regExNull                 = "\x0000";
            string    regExNoise                = @"\(|\)|( -|- )|\,|'";
            Regex     regExRemoveNull           = new Regex(regExNull, RegexOptions.Multiline);
            Regex     regExRemoveNoise          = new Regex(regExNoise, RegexOptions.Compiled);
            Regex     regExRemoveExtraSpaces    = new Regex(regExExtraSpaces, RegexOptions.Compiled);
            Regex     regExCheckForAlphanumeric = new Regex(regExAlphanumeric, RegexOptions.Compiled);

            foreach (string tok in listToUse)
            {
                var found = false;
                if (!tok.StartsWith(";"))
                {
                    string[] aryLine;
                    try
                    {
                        aryLine         = tok.Split('\t');
                        destinationName = aryLine[destination].Trim();
                        destinationName = regExRemoveNoise.Replace(destinationName, " ");
                        destinationName = regExRemoveExtraSpaces.Replace(destinationName, " ");
                    }
                    catch (Exception e)
                    {
                        StaticVariable.ProgressDetails.Add("ParseInputFile::MatchInputXlsxFileWithRegEx()");
                        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)
                    {
                        aryLine = regexExpression.Split(new char[] { '\t' });
                        string regExPattern      = aryLine[0];
                        string regExBand         = aryLine[1].Trim();
                        string regexStandardName = aryLine[2].Trim();
                        string regExDescription  = aryLine[3].Trim();

                        try
                        {
                            var regExCountry = new Regex(regExPattern, RegexOptions.IgnoreCase);
                            if (regExCountry.IsMatch(destinationName))
                            {
                                newTimer.Elapsed  += new ElapsedEventHandler(OnTimedEvent);
                                newTimer.AutoReset = true;
                                newTimer.Enabled   = true;
                                found = true;

                                StaticVariable.CustomerDetailsDataRecord.Add(new DataRecord(regExBand + "\t" + regexStandardName + "\t" + regExDescription + "\t" + tok));
                                // for debugging
                                //StaticVariable.ProgressDetails.Add("ParseInputFile::MatchInputXlsxFileWithRegEx()  -- Debugging only");
                                //StaticVariable.ProgressDetails.Add(regExBand + "\tMatchInputXlsxFileWithRegEx()\t" + regExDescription + "\t" + tok);
                            }
                        }
                        catch (Exception e)
                        {
                            StaticVariable.ProgressDetails.Add(Environment.NewLine + "ProcessInputXlsxFile::MatchInputXlsxFileWithRegEx()");
                            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)
                {
                    tmpList.Add("^" + destinationName.Replace(" ", ".").TrimEnd(' ') + "\tU" + uniqueBandCounter + "\t" + destinationName + "\t" + destinationName.PadRight(20, ' ').Substring(0, 20));
                    uniqueBandCounter++;
                }
            }
            if (tmpList.Count > 0)
            {
                StaticVariable.ProgressDetails.Add(Environment.NewLine + "ProcessInputXlsxFile::MatchInputXlsxFileWithRegEx()");
                StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "Destinations without regex");
                tmpList.Sort();
                foreach (string s in tmpList)
                {
                    StaticVariable.ProgressDetails.Add(s);
                }
                ErrorProcessing.StopProcessDueToFatalErrorOutputToLog();
            }
            newTimer.Enabled = false;
            Console.WriteLine("ProcessInputXlsxFile".PadRight(30, '.') + "MatchInputXlsxFileWithRegEx() -- finished");
            StaticVariable.ConsoleOutput.Add("ProcessInputXlsxFile".PadRight(30, '.') + "MatchInputXlsxFileWithRegEx() -- finished");
        }