예제 #1
0
        public Family Convert(GedcomParseResult parseResult)
        {
            var persons = new Dictionary <string, GitPerson>();

            foreach (KeyValuePair <string, GedcomPerson> gedcomPerson in parseResult.Persons)
            {
                GitPerson gitPerson = Convert(gedcomPerson.Value);
                persons.Add(gitPerson.Id, gitPerson);
            }

            FillRelations(parseResult, persons, out List <GitPersonEvent> notPersonEvents);

            var family = new Family(parseResult.Title, persons, notPersonEvents);

            return(family);
        }
예제 #2
0
        private static void FillRelations(GedcomParseResult parseResult, Dictionary <string, GitPerson> persons,
                                          out List <GitPersonEvent> notPersonEvents)
        {
            notPersonEvents = new List <GitPersonEvent>();

            foreach (GedcomRelation relation in parseResult.Relations)
            {
                if (persons.TryGetValue(relation.ToId, out GitPerson toPerson) &&
                    persons.TryGetValue(relation.FromId, out GitPerson fromPerson))
                {
                    if (relation is ChildRelation childRelation)
                    {
                        GitPerson parent = toPerson;
                        GitPerson child  = fromPerson;

                        DateTime prevDate = parent.Events.FirstOrDefault(p => IsParentBeforeTheChildBirthEvent(p.Type))?.Date ?? DateTime.MinValue;

                        for (int i = 0; i < child.Events.Count; i++)
                        {
                            GitPersonEvent childEvent = child.Events[i];

                            if (childEvent.Date <= prevDate && childEvent.DateType != GitDateType.Exact)
                            {
                                childEvent.Date     = prevDate.AddTicks(1);
                                childEvent.DateType = GitDateType.After;
                                FixChildrenDates(childEvent);
                            }
                            prevDate = childEvent.Date;

                            if (childEvent.Type == EventType.Birth)
                            {
                                childEvent.Parents.Add(parent);
                                child.Events[i] = childEvent;
                                InsertChild(parseResult.Persons[parent.Id], parent, child, childEvent);
                            }
                        }
                    }
                    else if (relation is SpouseRelation spouseRelation)
                    {
                    }
                }
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            var logger = new ConsoleLogger();

            if (args.Length == 0)
            {
                logger.LogError("Path to .ged file should be specified");
                return;
            }

            if (!File.Exists(args[0]))
            {
                logger.LogError($"File {args[0]} does not exist");
                return;
            }

            var gedcomParser = new GedcomParser()
            {
                Logger = logger
            };
            GedcomParseResult parseResult = gedcomParser.Parse(args[0]);

            var    converter = new GedcomToGitFamilyConverter();
            Family family    = converter.Convert(parseResult);

            bool runScript        = false;
            var  commandGenerator = new GitCommandGenerator(family);

            for (int i = 1; i < args.Length; i++)
            {
                string arg = args[i];
                if (arg == "-r" || arg == "--run")
                {
                    runScript = true;
                }
                else if (arg == "--only-birth-events")
                {
                    commandGenerator.OnlyBirthEvents = true;
                }
                else if (arg == "--ignore-not-person-events")
                {
                    commandGenerator.IgnoreNotPersonEvents = true;
                }
                else if (arg == "--ignore-events-without-date")
                {
                    commandGenerator.IgnoreEventsWithoutDate = true;
                }
                else if (arg.StartsWith("http") || arg.StartsWith("git"))
                {
                    commandGenerator.Source = arg;
                }
                else
                {
                    logger.LogError($"Unknown parameter {arg}");
                }
            }

            string commands = commandGenerator.Generate();
            string filePath = Path.GetDirectoryName(args[0]);
            string fileName = Path.GetFileNameWithoutExtension(args[0]);

            string ext            = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".cmd" : ".sh";
            string scriptFileName = Path.Combine(filePath, fileName + ext);

            File.WriteAllText(scriptFileName, commands);

            if (runScript)
            {
                string dirName = Path.Combine(filePath, fileName);
                if (Directory.Exists(dirName))
                {
                    logger.LogError($"Directory {dirName} exists. Remove it before running script");
                    return;
                }

                var runner = new GitScriptRunner
                {
                    Logger = logger
                };
                runner.Run(filePath, scriptFileName);
            }
        }