AutomatedTagging.Program.GetExcelRowsByUrl C# (CSharp) Method

GetExcelRowsByUrl() static private method

static private GetExcelRowsByUrl ( TermSetLookup>.Dictionary termSetsByInternalName ) : ExcelRow>.Dictionary
termSetsByInternalName TermSetLookup>.Dictionary
return ExcelRow>.Dictionary
        static Dictionary<string, ExcelRow> GetExcelRowsByUrl(Dictionary<string, TermSetLookup> termSetsByInternalName)
        {
            Dictionary<string, ExcelRow> excelRowsByUrl = new Dictionary<string, ExcelRow>(StringComparer.OrdinalIgnoreCase);

            Log("Reading AutomatedTagging.csv...");

            // Parse the input file
            using (StreamReader streamReader = new StreamReader("AutomatedTagging.csv"))
            {
                if (!streamReader.ReadLine().Contains("Filename"))
                    throw new InvalidOperationException("Invalid file format; header is missing");

                int lineNumber = 1;
                for (; ; )
                {
                    string line = streamReader.ReadLine();
                    ++lineNumber;
                    if (line == null)
                        break;

                    string[] csvValues = ParseCsvLine(line);
                    if (csvValues == null)
                        throw new InvalidOperationException("[line " + lineNumber + "]: Syntax error");

                    if (csvValues.Length < 1)
                        continue;

                    ExcelRow excelRow = new ExcelRow(csvValues[0], lineNumber);
                    for (int i = 2; i + 1 < csvValues.Length; )
                    {
                        string key = csvValues[i++].Trim();
                        if (key == "") break;

                        string value = csvValues[i++].Trim();
                        if (value == "") break;

                        TermSetLookup termSetLookup = termSetsByInternalName[key];
                        Guid termId = termSetLookup.GetTermId(value);

                        excelRow.Pairs.Add(new KeyValuePair<string, Guid>(termSetLookup.taxonomyField.InternalName, termId));
                    }

                    excelRowsByUrl.Add(excelRow.ListItemUrl, excelRow);
                }
            }
            return excelRowsByUrl;
        }