public MainWindow()
        {
            InitializeComponent();


            IList <DelimitedFileInfo> currentInventoryFileNames = new List <DelimitedFileInfo>()
            {
                new DelimitedFileInfo($"C:\\Users\\{userprofile}\\Downloads\\product.files.comparison\\products_shopify_inventory.latest.csv", "sku",
                                      "^\\w{4}\\d{8}")
            };

            IList <DelimitedFileInfo> oldInventoryFileNames = new List <DelimitedFileInfo>()
            {
                new DelimitedFileInfo($"C:\\Users\\{userprofile}\\Downloads\\product.files.comparison\\products_shopify_inventory.old.csv", "sku",
                                      "^\\w{4}\\d{8}")
            };

            DelimitedFile oldInventoryFile = new DelimitedFile();

            foreach (DelimitedFileInfo file in oldInventoryFileNames)
            {
                oldInventoryFile.LoadFileLines(file.FullName, HeaderNames,
                                               file.RegExLineIdentifierPattern, KeyName);
            }

            DelimitedFile newInventoryFile = new DelimitedFile();

            foreach (DelimitedFileInfo file in currentInventoryFileNames)
            {
                newInventoryFile.LoadFileLines(file.FullName, HeaderNames,
                                               file.RegExLineIdentifierPattern, KeyName);
            }

            IList <DelimitedFileRow> changedProductInventoryQts =
                DelimitedFile.Compare(oldInventoryFile, newInventoryFile);

            if (changedProductInventoryQts.Count > 0)
            {
                IList <DelimitedFileRow> inventoryRows = new List <DelimitedFileRow>();
                foreach (DelimitedFileRow data in changedProductInventoryQts)
                {
                    DelimitedFileColumn keyColumn = data[KeyName];
                    String keyNameValue           = DelimitedFile.GetKey(keyColumn.Value.ToString());
                    var    oldCSVData             = oldInventoryFile.GetRowByKeyName(keyNameValue); //.Query(csvData => csvData.GetColumnValue(KeyName) == data.GetColumnValue(KeyName)).FirstOrDefault();
                    var    newCSVData             = newInventoryFile.GetRowByKeyName(keyNameValue); //.Query(csvData => csvData.GetColumnValue(KeyName) == data.GetColumnValue(KeyName)).FirstOrDefault();

                    if (!(oldCSVData is null) && !(newCSVData is null))
                    {
                        DelimitedFileRow inventoryRow = new DelimitedFileRow();

                        inventoryRow.CreateColumn(KeyName, data.GetColumnValue(KeyName), true);
                        inventoryRow.CreateColumn("BEFORE", oldCSVData.GetColumnValue(QtyFieldName));
                        inventoryRow.CreateColumn("AFTER", newCSVData.GetColumnValue(QtyFieldName));
                        inventoryRows.Add(inventoryRow);
                    }
                }

                DelimitedFile changedInventoryQtysFile = new DelimitedFile();
                changedInventoryQtysFile.AddLines(inventoryRows);
                changedInventoryQtysFile.Save("sku,before,after", $"C:\\Users\\{userprofile}\\Downloads\\product.files.comparison\\changed.inventory.qtys.csv");
            }

            MessageBox.Show($"Completed Processing the Files and Found {changedProductInventoryQts.Count} Products that have changed inventory quantities SKUs.");

            Application.Current.Shutdown();
        }
        public void Generate()
        {
            IDictionary <String, String> mapper = new Dictionary <string, string>()
            {
                { "upc", "gtin" },
                { "brand", "brand" }
            };

            IList <DelimitedFileInfo> ProductFiles = new List <DelimitedFileInfo>()
            {
                new DelimitedFileInfo($"C:\\Users\\{userprofile}\\Downloads\\product.files.comparison\\products.csv", Name,
                                      "^\\w{4}\\d{8}")
            };

            IList <DelimitedFileInfo> GoogleFeedFiles = new List <DelimitedFileInfo>()
            {
                new DelimitedFileInfo($"C:\\Users\\{userprofile}\\Downloads\\products.tsv", KeyName,
                                      "")
            };

            DelimitedFile ProductsFile = new DelimitedFile();

            foreach (DelimitedFileInfo file in ProductFiles)
            {
                ProductsFile.LoadFileLines(file.FullName, ProductHeaderNames,
                                           file.RegExLineIdentifierPattern, Name);
            }

            DelimitedFile GoogleFeedFile = new DelimitedFile();

            foreach (DelimitedFileInfo file in GoogleFeedFiles)
            {
                GoogleFeedFile.LoadFileLines(file.FullName, GoogleHeaderNames,
                                             file.RegExLineIdentifierPattern, KeyName, '\t');
            }

            Console.WriteLine($"Missing Google Feed Titles from Products File.");
            foreach (String key in GoogleFeedFile.KeyNameToRowIndex.Keys)
            {
                if (ProductsFile.KeyNameToRowIndex.ContainsKey(key) == false)
                {
                    Console.WriteLine($"{key}");
                }
            }
            Console.WriteLine($"_____________________________________________________________________________________");

            #region Process the rows in the product file extracting
            //Brand and UPC data to add to the existing Google Feed
            //rows.
            int googleFeedProductRowsProcessed = 0;
            IList <DelimitedFileRow> googleContentFeedFileRows = new List <DelimitedFileRow>();
            foreach (DelimitedFileRow googleFeedFileRow in GoogleFeedFile)
            {
                DelimitedFileColumn keyColumn = googleFeedFileRow[KeyName];
                String           keyNameValue = DelimitedFile.GetKey(keyColumn.Value.ToString());
                DelimitedFileRow productRow   = ProductsFile.GetRowByKeyName(keyNameValue);//Query(x => x.GetColumnValue(Name) == keyColumn.Value);
                if (!(productRow is null))
                {
                    DelimitedFileRow currentProductFileRow = productRow;
                    googleFeedFileRow[Brand] = currentProductFileRow[Brand];
                    googleFeedFileRow.CreateColumn(GTIN, currentProductFileRow[UPC].Value.Value);
                    googleContentFeedFileRows.Add(googleFeedFileRow);
                    googleFeedProductRowsProcessed++;
                }
            }
            #endregion

            #region Extract the Headers from the first row
            var           columns     = googleContentFeedFileRows.First().Where(c => c.Name != null);
            StringBuilder headers     = new StringBuilder();
            int           columnIndex = 0;
            foreach (DelimitedFileColumn column in columns)
            {
                if (columnIndex == 0)
                {
                    headers.Append(column.Name);
                }
                else
                {
                    headers.Append(",").Append(column.Name);
                }
                columnIndex++;
            }
            #endregion

            #region Create new file for Google Feed Data
            //Add the updated rows to the new file and save.
            IList <DelimitedFile>    filesToSave = new List <DelimitedFile>();
            IList <DelimitedFileRow> rows        = new List <DelimitedFileRow>();
            int lastLineNumber = 0;
            foreach (DelimitedFileRow row in googleContentFeedFileRows)
            {
                if (lastLineNumber > 0 && lastLineNumber % 3500 == 0)
                {
                    DelimitedFile updatedGoogleFeedFile = new DelimitedFile();
                    filesToSave.Add(updatedGoogleFeedFile);
                    updatedGoogleFeedFile.AddLines(rows);
                    lastLineNumber = 0;
                    rows.Clear();
                }
                else
                {
                    rows.Add(row);
                }
                lastLineNumber++;
            }
            //Add remaining rows to a file.
            if (rows.Count > 0)
            {
                DelimitedFile updatedGoogleFeedFile = new DelimitedFile();
                filesToSave.Add(updatedGoogleFeedFile);
                updatedGoogleFeedFile.AddLines(rows);
                lastLineNumber = 0;
                rows.Clear();
            }
            #endregion

            #region Persist all files.
            int fileIdx = 0;
            foreach (DelimitedFile file in filesToSave)
            {
                file.Save(headers.ToString(), $"C:\\Users\\jwilsop1\\Downloads\\product.files.comparison\\google.feed.file_{fileIdx}.csv");
                fileIdx++;
            }
            #endregion

            Console.WriteLine($"Completed Processing the Product Files updating {googleFeedProductRowsProcessed} records in the Google Content Feed.");
            Console.ReadLine();
        }