Example #1
0
        public override void PostCheck(GEDCommon rec)
        {
            var me = rec as IndiRecord;

            if (string.IsNullOrWhiteSpace(me.Ident))
            {
                UnkRec err = new UnkRec();
                err.Error = UnkRec.ErrorCode.MissIdent; // TODO "INDI missing identifier"; // TODO assign one?
                err.Beg   = err.End = me.BegLine;
                err.Tag   = rec.Tag;
                me.Errors.Add(err);
            }

            // TODO should this be checked in the SEX routine so line # points at the actual line???
            // Make sure sex is set
            if (me.Sex != '\0')
            {
                if (!"MFUmfu".Contains(me.Sex.ToString(CultureInfo.InvariantCulture)))
                {
                    me.Sex = 'U';

                    UnkRec err = new UnkRec();
                    err.Error = UnkRec.ErrorCode.InvSex; // "Non-standard SEX value corrected to U";
                    err.Beg   = err.End = me.BegLine;
                    me.Errors.Add(err);                  // TODO as warning
                }
            }
            CheckRestriction(me, me.Restriction);

            // TODO check restriction value on events
        }
Example #2
0
        public override void PostCheck(GEDCommon rec)
        {
            MediaRecord me = rec as MediaRecord;

            if (string.IsNullOrWhiteSpace(me.Ident))
            {
                UnkRec err = new UnkRec();
                err.Error = UnkRec.ErrorCode.MissIdent; // TODO "Missing identifier"; // TODO assign one?
                err.Beg   = err.End = me.BegLine;
                me.Errors.Add(err);
            }

            // A FILE record is required
            if (me.Files.Count < 1)
            {
                UnkRec err = new UnkRec();
                err.Error = UnkRec.ErrorCode.MissFile; // "Missing FILE";
                err.Beg   = err.End = me.BegLine;
                me.Errors.Add(err);
            }

            // Each FILE record must have a FORM
            foreach (var mediaFile in me.Files)
            {
                if (string.IsNullOrWhiteSpace(mediaFile.Form))
                {
                    UnkRec err = new UnkRec();
                    err.Error = UnkRec.ErrorCode.MissForm; // "Missing FORM";
                    err.Beg   = err.End = me.BegLine;
                    me.Errors.Add(err);
                }
            }
        }
Example #3
0
        internal static void writeIds(StreamWriter file, GEDCommon rec, int level = 1)
        {
            if (rec.REFNs.Count < 1 && string.IsNullOrEmpty(rec.UID) && rec.AFN == null && rec.RFN == null)
            {
                return;
            }
            foreach (var refN in rec.REFNs)
            {
                file.WriteLine("{0} REFN {1}", level, refN.Value);
                // TODO don't have original 'TYPE' lines
            }

            if (!string.IsNullOrEmpty(rec.UID))
            {
                file.WriteLine("{0} _UID {1}", level, rec.UID);
            }
            if (rec.AFN != null)
            {
                file.WriteLine("{0} AFN {1}", level, rec.AFN.Value);
            }
            if (rec.RFN != null)
            {
                file.WriteLine("{0} RFN {1}", level, rec.RFN.Value);
            }
        }
Example #4
0
        public override void PostCheck(GEDCommon rec)
        {
            var me = rec as NoteRecord;

            if (string.IsNullOrWhiteSpace(me.Ident))
            {
                UnkRec err = new UnkRec();
                err.Error = UnkRec.ErrorCode.MissIdent; // TODO {Error = "Missing identifier"};
                err.Beg   = err.End = me.BegLine;
                me.Errors.Add(err);
            }

            if (me.Builder.Length > 0)
            {
                // Store an in-line note to the database
                string text = me.Builder.ToString().Replace("@@", "@");
#if SQLITE
                me.Key = SQLite.Instance.StoreNote(text);
#elif LITEDB
                me.Key = LiteDB.Instance.StoreNote(text);
#elif NOTESTREAM
                me.Key = NoteStream.Instance.StoreNote(text);
#else
                me.Text = text;
#endif
            }
            else
            {
                me.Text = "";
            }

            //me.Text = me.Builder.ToString().Replace("@@", "@"); // TODO faster replace
            me.Builder = null;
        }
Example #5
0
        private void VerifyRepo(Atest torun)
        {
            // Verify REPO specific details
            GEDCommon res = torun("REPO", "1 NAME fumbar");
            var       rec = res as Repository;

            Assert.IsNotNull(rec);
            Assert.AreEqual("fumbar", rec.Name);
        }
Example #6
0
 internal static void writeRecordTrailer(StreamWriter file, GEDCommon rec, int level)
 {
     writeIds(file, rec);
     writeIfNotEmpty(file, "RIN", rec.RIN, level);
     writeSubNotes(file, rec as NoteHold);
     writeSourCit(file, rec as SourceCitHold);
     writeObjeLink(file, rec as MediaHold);
     writeChan(file, rec);
 }
Example #7
0
        private void VerifySour(Atest torun)
        {
            // Verify REPO specific details
            GEDCommon res = torun("SOUR", "1 ABBR fumbar");
            var       rec = res as SourceRecord;

            Assert.IsNotNull(rec);
            Assert.AreEqual("fumbar", rec.Abbreviation);
        }
Example #8
0
        private void VerifyIndi(Atest torun)
        {
            // Verify INDI specific details
            GEDCommon res = torun("INDI", "1 SEX U");
            var       rec = res as IndiRecord;

            Assert.IsNotNull(rec);
            Assert.AreEqual('U', rec.Sex);
        }
Example #9
0
        private void VerifyNote(Atest torun)
        {
            // Verify NOTE specific details
            GEDCommon res = torun("NOTE", "1 CONC fumbar");
            var       rec = res as NoteRecord;

            Assert.IsNotNull(rec);
            Assert.AreEqual("fumbar", rec.Text);
        }
Example #10
0
        private void VerifyObje(Atest torun)
        {
            GEDCommon res = torun("OBJE", "1 FILE ref\n2 FORM tif");
            var       rec = (res as MediaRecord);

            Assert.IsNotNull(rec);
            Assert.AreEqual(1, rec.Files.Count);
            Assert.AreEqual("ref", rec.Files[0].FileRefn);
            Assert.AreEqual("tif", rec.Files[0].Form);
        }
Example #11
0
        private void VerifyFam(Atest torun)
        {
            // Verify FAM specific details
            GEDCommon res = torun("FAM", "1 HUSB @P1@");
            var       rec = res as FamRecord;

            Assert.IsNotNull(rec);
            Assert.AreEqual(1, rec.Dads.Count);
            Assert.AreEqual("P1", rec.Dads[0]);
        }
Example #12
0
        private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            // 1. have a record
            // 2. get lines from file for the record
            // 3. determine range of lines for the error
            // 4. for each line from file:
            // 4a. if line is within error range
            // 4ai. set format to Red
            // 4aii. else
            // 4aiii. set format to black
            // 4b. append text
            // 4c. append environment.newline

            ListBoxItem2 lbi = listBox2.SelectedItem as ListBoxItem2;

            int beg = lbi.rec.BegLine;
            int end = lbi.rec.EndLine;

            if (_lastrec != lbi.rec)
            {
                _lastrec = lbi.rec;
                _lines   = ReadLineSet(beg, end);
            }

            int errbeg = lbi.err.Beg;
            int errend = lbi.err.End;

            richTextBox1.Clear();

            int errLoc = 0; // track location of error lines to insure visibility

            for (int i = beg; i <= end; i++)
            {
                string lin = _lines[i - beg];
                if (i >= errbeg && i <= errend)
                {
                    richTextBox1.SelectionColor = Color.Red;
                    errLoc = richTextBox1.SelectionStart;
                }
                else
                {
                    richTextBox1.SelectionColor = Color.Black;
                }

                richTextBox1.AppendText(lin);
                richTextBox1.AppendText(Environment.NewLine);
            }

            targetVCenter(errbeg - beg, errend - beg);
            //richTextBox1.SelectionStart = errLoc; // insure error lines are visible
            //richTextBox1.ScrollToCaret();
        }
Example #13
0
        internal static void writeChan(StreamWriter file, GEDCommon rec)
        {
            if (rec.CHAN.Date == null)
            {
                return;
            }
            file.WriteLine("1 CHAN");
            file.WriteLine("2 DATE {0}", rec.CHAN.Date.Value.ToString("d MMM yyyy").ToUpper());
            // TODO change time?
            writeSubNotes(file, rec.CHAN, 2);

            // TODO otherlines
        }
Example #14
0
        public override void PostCheck(GEDCommon rec)
        {
            SourceRecord me = rec as SourceRecord;

            if (string.IsNullOrWhiteSpace(me.Ident)) // TODO common?
            {
                UnkRec err = new UnkRec();
                err.Error = UnkRec.ErrorCode.MissIdent; // TODO {Error = "Missing identifier"};
                err.Beg   = err.End = rec.BegLine;
                me.Errors.Add(err);
            }

            // No required data except Xref id?
            // TODO Warning: no data provide
        }
Example #15
0
        public override void PostCheck(GEDCommon rec)
        {
            var me = rec as FamRecord;

            if (string.IsNullOrWhiteSpace(me.Ident))
            {
                UnkRec err = new UnkRec();
                err.Error = UnkRec.ErrorCode.MissIdent; // "Missing identifier"; // TODO assign one?
                err.Beg   = err.End = me.BegLine;
                err.Tag   = rec.Tag;
                me.Errors.Add(err);
            }

            // TODO NCHI value doesn't match # of CHIL refs?

            CheckRestriction(me, me.Restriction);

            // TODO check restriction value on events
        }
Example #16
0
        public static void NonStandardRemain(string remain, GEDCommon rec)
        {
            // Extra text on the record line (e.g. "0 @R1@ REPO blah blah blah") is not standard for
            // most record types. Preserve it as a note if possible.
            if (!string.IsNullOrWhiteSpace(remain))
            {
                UnkRec err = new UnkRec();
                err.Beg   = err.End = rec.BegLine;
                err.Error = UnkRec.ErrorCode.InvExtra;
                rec.Errors.Add(err);

                if (rec is NoteHold)
                {
                    Note not = new Note();
                    not.Text = remain;
                    (rec as NoteHold).Notes.Add(not);
                }
            }
        }
Example #17
0
        public override void PostCheck(GEDCommon rec)
        {
            Repository me = rec as Repository;

            if (string.IsNullOrWhiteSpace(me.Ident))
            {
                UnkRec err = new UnkRec();
                err.Error = UnkRec.ErrorCode.MissIdent; // TODO {Error = "REPO missing identifier"};
                err.Beg   = err.End = me.BegLine;
                me.Errors.Add(err);
            }

            // A NAME record is required
            if (string.IsNullOrWhiteSpace(me.Name))
            {
                UnkRec err = new UnkRec();
                err.Error = UnkRec.ErrorCode.MissName; // TODO {Error = "REPO missing identifier"};
                err.Beg   = err.End = me.BegLine;
                me.Errors.Add(err);
            }
        }
Example #18
0
        public void Parse(GEDCommon rec, GedRecord Lines, GSFactory gsfact)
        {
            ParseContext2 ctx = new ParseContext2();

            ctx.gs       = gsfact.Alloc(); // new GEDSplitter(GedParser._masterTagCache);
            ctx.tagCache = GedParser._masterTagCache;

            ctx.Lines  = Lines;
            ctx.Parent = rec;
            int max = Lines.Max;

            for (int i = 1; i < max; i++)
            {
                var line = Lines.GetLine(i);
                ctx.Begline = i;
                ctx.Endline = i; // assume it is one line long, parser might change it

                ctx.gs.LevelTagAndRemain(line, ctx);
                TagProc2 tagProc;
                if (ctx.Tag != null && _tagSet2.TryGetValue(ctx.Tag, out tagProc))
                {
                    tagProc(ctx);
                }
                else
                {
                    // Custom and invalid treated as 'unknowns': let the consumer figure it out
                    // TODO gedr5419_blood_type_events.ged has garbage characters in SOUR/ABBR tags: incorrect line terminator, blank lines etc.
                    LookAhead(ctx);
                    rec.Unknowns.Add(new UnkRec(ctx.Tag, Lines.Beg + ctx.Begline, Lines.Beg + ctx.Endline));
                }
                i = ctx.Endline;
            }

            // TODO post parse error checking on sub-structures
            PostCheck(ctx.Parent); // post parse error checking

            gsfact.Free(ctx.gs);
            ctx.gs = null;
        }
Example #19
0
        public void CheckRestriction(GEDCommon rec, string restrict)
        {
            // Common post-processing restriction checking
            if (string.IsNullOrWhiteSpace(restrict)) // nothing specified, nothing to do
            {
                return;
            }
            switch (restrict.ToLowerInvariant())
            {
            case "confidential":
            case "locked":
            case "privacy":
                break;

            default:
                UnkRec err = new UnkRec();
                err.Error = UnkRec.ErrorCode.InvRestrict;
                err.Beg   = err.End = rec.BegLine;
                rec.Errors.Add(err);
                break;
            }
        }
Example #20
0
        public GEDCommon Parse(GedRecord rec)
        {
            // Given a glop of lines which represent a 'record', parse it into GED data (INDI/FAM/NOTE/OBJE/REPO/SOUR/etc)
            Tuple <object, GedParse> parseSet = Make(rec);

            if (parseSet == null)
            {
                return(null); // EOF
            }
            if (parseSet.Item2 == null)
            {
                return(parseSet.Item1 as GEDCommon); // unknown or NYI record type
            }
            GEDCommon recC2 = parseSet.Item1 as GEDCommon;

#if PARALLEL
            _allTasks.Add(Task.Run(() => parseSet.Item2.Parse(recC2, rec, _GedSplitFactory)));
#else
            parseSet.Item2.Parse(recC2, rec, _GedSplitFactory);
#endif
            return(parseSet.Item1 as GEDCommon);
        }
Example #21
0
 public override void PostCheck(GEDCommon rec)
 {
     //var me = rec as IndiRecord;
 }
Example #22
0
 public abstract void PostCheck(GEDCommon rec);
Example #23
0
 public void HasErrors(GEDCommon rec, int count)
 {
     Assert.AreEqual(count, rec.Errors.Count);
     Assert.AreNotEqual(0, rec.Errors[0].Error);
 }
Example #24
0
 public void Init(ParseContext2 ctx, StructCommon parent)
 {
     base.Init(ctx);
     Parent = parent;
     Record = ctx.Parent;
 }