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");
        }
        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");
        }
Beispiel #3
0
        private static void ReadXlsxFileIntoList()
        {
            Console.WriteLine("ProcessInputXlsxFile".PadRight(30, '.') + "ReadXLSXFileIntoList() -- started");
            StaticVariable.ConsoleOutput.Add("ProcessInputXlsxFile".PadRight(30, '.') + "ReadXLSXFileIntoList() -- started");
            StaticVariable.ProgressDetails.Add(Environment.NewLine + "ProcessInputXlsxFile::ReadXLSXFileIntoList()");
            StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "Any line containing 'DefaultXX' will be ignored, as will all headers");
            string[]      worksheetsTypes   = { Constants.Duration, Constants.Capped, Constants.Pulse };
            List <string> workSheetsNotUsed = new List <string>();
            List <string> discardedLines    = new List <string>();
            List <string> workSheetsUsed    = new List <string>();

            SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook(StaticVariable.InputFile);

            foreach (string wksheet in worksheetsTypes)
            {
                try
                {
                    SpreadsheetGear.IWorksheet worksheet = workbook.Worksheets[wksheet];
                    SpreadsheetGear.IRange     cells     = worksheet.Cells;
                    workSheetsUsed.Add(wksheet);
                }
                catch (Exception)
                {
                    workSheetsNotUsed.Add(wksheet);
                }
            }

            foreach (string wksheet in workSheetsUsed)
            {
                SpreadsheetGear.IWorksheet worksheet = workbook.Worksheets[wksheet];
                SpreadsheetGear.IRange     cells     = worksheet.Cells;
                var currentColumn = 0;
                for (currentColumn = 0; currentColumn < cells.ColumnCount; currentColumn++)
                {
                    if (cells[0, currentColumn].Text.ToUpper().Equals(Constants.FinalColumnName))
                    {
                        currentColumn++;
                        break;
                    }
                }
                var maximumNumberOfColumns = currentColumn;

                try
                {
                    foreach (SpreadsheetGear.IRange row in worksheet.UsedRange.Rows)
                    {
                        StringBuilder sb = new StringBuilder();
                        for (int i = 0; i < maximumNumberOfColumns; i++)
                        {
                            sb.Append(row[0, i].Value + "\t"); //0.0400 being chopped to 0.04.
                        }
                        string sAdjustSb = sb.ToString().TrimEnd('\t');

                        if (sAdjustSb.Contains(";") && !DiscardHeaderLine(sAdjustSb))
                        {
                            discardedLines.Add("- " + sAdjustSb.Substring(0, sAdjustSb.IndexOf('\t')));
                        }
                        else if (!string.IsNullOrEmpty(sAdjustSb) && !DiscardHeaderLine(sAdjustSb))
                        {
                            ValidateData.CheckForCommasInLine(sAdjustSb);
                            StaticVariable.InputXlsxFileDetails.Add(ValidateData.CapitaliseWord(sAdjustSb));
                        }
                    }
                }
                catch (Exception e)
                {
                    StaticVariable.ProgressDetails.Add(Environment.NewLine + "ProcessInputXlsxFile::ReadXLSXFileIntoList()");
                    StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "Error in reading in XLSX line into list. Is there any data? ");
                    StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + e.Message);
                }
            }
            workbook.Close();
            if (workSheetsNotUsed.Any())
            {
                StaticVariable.ProgressDetails.Add(Environment.NewLine + "ProcessInputXlsxFile::ReadXLSXFileIntoList()");
                foreach (var entry in workSheetsNotUsed)
                {
                    StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + entry + " rates are not being used. Delete this worksheet");
                }
            }
            foreach (var entry in workSheetsUsed)
            {
                StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + entry + " rates are being used. ");
            }
            if (discardedLines.Any())
            {
                StaticVariable.ProgressDetails.Add(Environment.NewLine + "ProcessInputXlsxFile::ReadXLSXFileIntoList()");
                StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + "Customer destinations discarded.");
                discardedLines.Sort();
                foreach (var entry in discardedLines)
                {
                    StaticVariable.ProgressDetails.Add(Constants.FiveSpacesPadding + entry);
                }
            }
            StaticVariable.ProgressDetails.Add(Environment.NewLine + "ProcessInputXlsxFile".PadRight(30, '.') + "ReadXLSXFileIntoList()-- completed");
            Console.WriteLine("ProcessInputXlsxFile".PadRight(30, '.') + "ReadXLSXFileIntoList() -- finished");
            StaticVariable.ConsoleOutput.Add("ProcessInputXlsxFile".PadRight(30, '.') + "ReadXLSXFileIntoList() -- finished");
        }