public void ReadLineTest()
 {
     var writer = new FixedFileReader<Person>();
     var line = writer.ReadLine("00123Elvis Presley       ");
     Assert.AreEqual(line.Id, 123);
     Assert.AreEqual(line.Name, "Elvis Presley");
 }
Exemple #2
0
        public void CleanTo(FileStream file)
        {
            var encoding = Encoding.GetEncoding(1252);
            var personDecoder = new FixedFileReader<Person>();
            personDecoder.TrimInput = TrimInputMode.NoTrim;
            var writer = new FixedFileWriter<Person>();
            var streamWriter = new StreamWriter(file);
            using (var reader = new StreamReader(peopleStream, encoding))
            {
                string line;
                //skip first row
                reader.ReadLine();
                while ((line = reader.ReadLine()) != null)
                {
                    var person = personDecoder.ReadLine(line);
                    Debug.WriteLine("");
                    Debug.Write(i++);
                    if (personnummer.Contains(person.Personnr))
                    {
                        Debug.Write("Ignore duplicate " + person.Personnr);
                        continue;
                    }

                    if (pnrCounter >= personnummer.Count - 1)
                    {
                        Debug.Write("Ingen ledige personnr");
                        continue;
                    }

                    string key = person.Kommunenr + "-" + person.Kretsnr;
                    if (locationCounter.ContainsKey(key))
                    {
                        int value = locationCounter[key];

                        if (value <= 40)
                        {
                            locationCounter[key] = value + 1;
                            person.Personnr = GetNextNumber();
                            Debug.Write(" " + key + " " + person.Personnr + "(" + pnrCounter + ")");
                        }
                    }
                    streamWriter.WriteLine(writer.MakeLine(person));

                }
            }
        }