Ejemplo n.º 1
0
        /// <summary>
        /// Create an individual with a specific name.
        /// </summary>
        /// <param name="gedcomDb">The gedcom database to attach the name and individual to.</param>
        /// <param name="givenName">The given name (first name) to attach to the new individual.</param>
        /// <param name="surname">The surname (last name) to attach to the new individual.</param>
        /// <returns>The constructed individual.</returns>
        public static GedcomIndividualRecord NamedPerson(this GedcomDatabase gedcomDb, string givenName, string surname)
        {
            var person = new GedcomIndividualRecord(gedcomDb);

            person.Names.Clear();
            if (!string.IsNullOrWhiteSpace(givenName) || !string.IsNullOrWhiteSpace(surname))
            {
                var personName = new GedcomName();
                personName.Level    = 1;
                personName.Database = gedcomDb;
                if (!string.IsNullOrWhiteSpace(givenName))
                {
                    personName.Given = givenName;
                }

                personName.PreferredName = true;
                if (!string.IsNullOrWhiteSpace(surname))
                {
                    personName.Surname = surname;
                }

                person.Names.Add(personName);
            }

            return(person);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Outputs a GedcomDatabase to the given file.
        /// </summary>
        /// <param name="database">The GedcomDatabase to write.</param>
        /// <param name="file">The filename to write to.</param>
        public void WriteGedcom(GedcomDatabase database, string file)
        {
            Encoding enc = new UTF8Encoding();

            using (var writer = new GedcomStreamWriter(file, false, enc))
            {
                Write(database, writer);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Outputs a GedcomDatabase to the passed stream.
        /// </summary>
        /// <param name="database">The GedcomDatabase to write.</param>
        /// <param name="stream">The stream to write to.</param>
        public void WriteGedcom(GedcomDatabase database, Stream stream)
        {
            Encoding enc = new UTF8Encoding();

            using (var writer = new GedcomStreamWriter(stream, enc, 1024, true))
            {
                Write(database, writer);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GedcomParseState"/> class.
        /// </summary>
        public GedcomParseState()
        {
            Records  = new Stack <GedcomRecord>();
            Database = new GedcomDatabase();

            // max level of 99, pre alloc size of stack
            PreviousTags = new Stack <GedcomTagLevel>(100);

            pairPool = new GedcomTagLevel[100];
        }
Ejemplo n.º 5
0
        public static void ctree(string file)
        {
            var gedcomReader = GedcomRecordReader.CreateReader(file);

            tree1 = gedcomReader.Database;
            if (tree1 != null)
            {
                tree2 = gedcomReader.Database;
            }
        }
Ejemplo n.º 6
0
        private void Time_when_output_is_24_hour_format()
        {
            SystemTime.SetDateTime(new System.DateTime(2020, 12, 13, 18, 30, 59));
            var gedcom = new GedcomDatabase {
                Header = new GedcomHeader(),
            };

            var individual = new GedcomIndividualRecord(gedcom, "O'Neill");

            Assert.Equal("18:30:59", individual.Names.Single().ChangeDate.Time);
        }
Ejemplo n.º 7
0
        private void Date_when_output_is_in_english_and_not_the_culture_of_the_current_thread()
        {
            SystemTime.SetDateTime(new System.DateTime(2020, 12, 13));
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("de-DE");
            var gedcom = new GedcomDatabase {
                Header = new GedcomHeader(),
            };

            var individual = new GedcomIndividualRecord(gedcom, "O'Neill");

            Assert.Equal("13 Dec 2020", individual.Names.Single().ChangeDate.Date1);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Queries the tree for any individual with a name, just to show how to query.
        /// </summary>
        /// <param name="db">The database to query.</param>
        public static void QueryTree(GedcomDatabase db)
        {
            Console.WriteLine($"Found {db.Families.Count} families and {db.Individuals.Count} individuals.");
            var individual = db
                             .Individuals
                             .FirstOrDefault(f => f.Names.Any());

            if (individual == null)
            {
                Console.WriteLine($"Couldn't find any individuals in the GEDCOM file with a name, which is odd!");
                return;
            }

            Console.WriteLine($"Individual found with a preferred name of '{individual.GetName().Name}'.");
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Create an individual with a specific name.
        /// </summary>
        /// <param name="gedcomDb">The gedcom database to attach the name and individual to.</param>
        /// <param name="name">The name to place directly into the name field.</param>
        /// <returns>The constructed individual.</returns>
        public static GedcomIndividualRecord NamedPerson(this GedcomDatabase gedcomDb, string name)
        {
            var personName = new GedcomName();

            personName.Level         = 1;
            personName.Database      = gedcomDb;
            personName.Name          = name;
            personName.PreferredName = true;

            var person = new GedcomIndividualRecord(gedcomDb);

            person.Names.Clear();
            person.Names.Add(personName);
            return(person);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Finds the duplicates.
        /// </summary>
        /// <param name="databaseA">The database a.</param>
        /// <param name="databaseB">The database b.</param>
        /// <param name="matchThreshold">The match threshold.</param>
        /// <param name="foundFunc">The found function.</param>
        public static void FindDuplicates(GedcomDatabase databaseA, GedcomDatabase databaseB, decimal matchThreshold, DuplicateFoundFunc foundFunc)
        {
            int total     = databaseA.Individuals.Count;
            int potential = 0;

            foreach (GedcomIndividualRecord indi in databaseA.Individuals)
            {
                List <GedcomIndividualRecord> matches = FindDuplicates(indi, databaseB, matchThreshold);

                if (matches.Count > 0)
                {
                    foundFunc(indi, matches);
                    potential++;
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Writes the specified database to the passed writer.
        /// Not for use outside this class as the writer must be
        /// responsibly disposed in a using block by the caller.
        /// </summary>
        /// <param name="database">The database to write.</param>
        /// <param name="writer">The writer to use for outputting the database.</param>
        private void Write(GedcomDatabase database, GedcomStreamWriter writer)
        {
            writer.AllowInformationSeparatorOnSave = AllowInformationSeparatorOnSave;
            writer.AllowLineTabsSave = AllowLineTabsSave;
            writer.AllowTabsSave     = AllowTabsSave;

            database.Header.Output(writer);

            // write records
            foreach (DictionaryEntry entry in database)
            {
                var record = entry.Value as GedcomRecord;

                record.Output(writer);
                writer.Write(Environment.NewLine);
            }

            writer.Write(Environment.NewLine);
            writer.WriteLine("0 TRLR");
            writer.Write(Environment.NewLine);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Adds a sample person (well, a cartoon mouse) to the presidents file. The mouse may do a better job if elected president.
        /// </summary>
        /// <param name="db">The database to add the individual to.</param>
        public static void AddPerson(GedcomDatabase db)
        {
            var individual = new GedcomIndividualRecord(db);

            var name = individual.Names[0];

            name.Given   = "Michael";
            name.Surname = "Mouse";
            name.Nick    = "Mickey";

            individual.Names.Add(name);

            var birthDate = new GedcomDate(db);

            birthDate.ParseDateString("24 Jan 1933");
            individual.Events.Add(new GedcomIndividualEvent
            {
                Database  = db,
                Date      = birthDate,
                EventType = Enums.GedcomEventType.Birth
            });

            Console.WriteLine($"Added record for '{individual.GetName().Name}' with birth date {individual.Birth.Date.Date1}.");
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GedcomIndividualComparisonTest"/> class.
 /// </summary>
 public GedcomIndividualComparisonTest()
 {
     gedcomDb = new GedcomDatabase();
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GedcomNameParsingTest"/> class.
 /// </summary>
 public GedcomNameParsingTest()
 {
     gedcomDb = new GedcomDatabase();
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Finds the duplicates.
        /// </summary>
        /// <param name="indi">The indi.</param>
        /// <param name="databaseB">The database b.</param>
        /// <param name="matchThreshold">The match threshold.</param>
        /// <returns>A list of duplicate records.</returns>
        public static List <GedcomIndividualRecord> FindDuplicates(GedcomIndividualRecord indi, GedcomDatabase databaseB, decimal matchThreshold)
        {
            List <GedcomIndividualRecord> matches = new List <GedcomIndividualRecord>();

            foreach (GedcomIndividualRecord matchIndi in databaseB.Individuals)
            {
                // can't match self, databaseB could be the same database as indi.Database
                // so we can check this
                if (matchIndi != indi)
                {
                    var match = indi.CalculateSimilarityScore(matchIndi);

                    if (match > matchThreshold)
                    {
                        matches.Add(matchIndi);

                        // System.Console.WriteLine(indi.Names[0].Name + " matches " + matchIndi.Names[0].Name + " at " + match + "%");
                    }
                }
            }

            return(matches);
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GedcomChangeDate"/> class.
 /// </summary>
 /// <param name="database">The GEDCOM database to associate this date with.</param>
 public GedcomChangeDate(GedcomDatabase database)
     : base(database)
 {
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Helper method to output a standard GEDCOM file without needing to create a writer.
        /// </summary>
        /// <param name="database">The database to output.</param>
        /// <param name="stream">The stream to write to.</param>
        public static void OutputGedcom(GedcomDatabase database, Stream stream)
        {
            var writer = new GedcomRecordWriter();

            writer.WriteGedcom(database, stream);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Helper method to output a standard GEDCOM file without needing to create a writer.
        /// </summary>
        /// <param name="database">The database to output.</param>
        /// <param name="file">The file path to output to.</param>
        public static void OutputGedcom(GedcomDatabase database, string file)
        {
            var writer = new GedcomRecordWriter();

            writer.WriteGedcom(database, file);
        }
Ejemplo n.º 19
0
		private void SetGedcomDatabase(GedcomDatabase database)
		{
			_database = null;
			_record = null;

			_database = database;

			_record = _database.Individuals[0];

			if (_currentView != null)
			{
				_currentView.Database = _database;
				_currentView.Record = _record;
			}
		}
Ejemplo n.º 20
0
 /// <summary>
 /// Saves the sample database out to a new file.
 /// </summary>
 /// <param name="db">The database to save.</param>
 public static void Save(GedcomDatabase db)
 {
     GedcomRecordWriter.OutputGedcom(db, "Rewritten.ged");
     Console.WriteLine($"Output database to rewritten.ged.");
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="GedcomNameComparisonTest"/> class.
 /// </summary>
 public GedcomNameComparisonTest()
 {
     gedcomDb = new GedcomDatabase();
 }