public void Basic_Import_Test(string ris_filepath)
        {
            string path = GetNormalizedPathToRISTestFile(ris_filepath);

            ASSERT.FileExists(path);

            string ris_text = GetTestFileContent(path);

            Result rv = new Result();

            rv.lines_set = SplitMultipleRISLines(ris_text);
            foreach (List <string> lines in rv.lines_set)
            {
                RISRecord record = MapRISLinesToDictionary(lines);
                rv.records.Add(record);
                rv.bibtex_items.Add(record.ToBibTeX());
            }

            // Serialize the result to JSON for easier comparison via ApprovalTests->BeyondCompare (that's what I use for *decades* now)
            string json_out = JsonConvert.SerializeObject(rv, Newtonsoft.Json.Formatting.Indented).Replace("\r\n", "\n");

            //ApprovalTests.Approvals.VerifyJson(json_out);   --> becomes the code below:
            ApprovalTests.Approvals.Verify(
                new QiqqaApprover(json_out, ris_filepath),
                ApprovalTests.Approvals.GetReporter()
                );
        }
        public static List <RISRecord> Parse(string ris_text)
        {
            List <RISRecord> ris_records = new List <RISRecord>();

            List <List <string> > ris_record_texts = SplitMultipleRISLines(ris_text);

            foreach (List <string> ris_record_text in ris_record_texts)
            {
                RISRecord ris_record = MapRISLinesToDictionary(ris_record_text);
                ris_records.Add(ris_record);
            }

            return(ris_records);
        }
        public static void Test()
        {
            string ris_text = File.ReadAllText(@"c:\TEMP\SAMPLEENDNOTE.TXT");
            List <List <string> > lines_set = SplitMultipleRISLines(ris_text);

            foreach (List <string> lines in lines_set)
            {
                RISRecord record = MapRISLinesToDictionary(lines);
                if (record.errors.Count > 0)
                {
                    Logging.Warn("Errors!");
                }

                BibTexItem bibtex = record.ToBibTeX();
                string     result = bibtex.ToBibTex();
            }
        }
        protected static RISRecord MapRISLinesToDictionary(List <string> lines)
        {
            RISRecord ris_record = new RISRecord();

            string last_attribute = null;

            for (int i = 0; i < lines.Count; ++i)
            {
                string line = lines[i];

                try
                {
                    // If it's a new attribute
                    if (line.StartsWith("%"))
                    {
                        string attribute = line.Substring(0, 2).ToUpper();
                        string remainder = line.Substring(3);

                        if (!ris_record.attributes.ContainsKey(attribute))
                        {
                            ris_record.attributes[attribute] = new List <string>();
                        }
                        ris_record.attributes[attribute].Add(remainder);

                        last_attribute = attribute;
                        continue;
                    }

                    // Check that the rest are not just blanks
                    if (String.IsNullOrEmpty(line))
                    {
                        bool have_some_non_blanks = false;
                        for (int j = i + 1; j < lines.Count; ++j)
                        {
                            if (!String.IsNullOrEmpty(lines[j]))
                            {
                                have_some_non_blanks = true;
                                break;
                            }
                        }

                        if (!have_some_non_blanks)
                        {
                            break;
                        }
                    }

                    // If we get here, it must be continuation code...
                    {
                        if (null != last_attribute)
                        {
                            // Append this txt to the end of the last text of the last attribute
                            int max_attribute_index = ris_record.attributes[last_attribute].Count - 1;
                            ris_record.attributes[last_attribute][max_attribute_index] =
                                ris_record.attributes[last_attribute][max_attribute_index]
                                + "\n" +
                                line;
                        }
                        else
                        {
                            throw new Exception(String.Format("Parsed line with no attribution: {0}", line));
                        }
                    }
                }
                catch (Exception ex)
                {
                    ris_record.errors.Add(String.Format("Error parsing line '{0}': {1}", line, ex.Message));
                }
            }

            return(ris_record);
        }