Ejemplo n.º 1
0
 private GEDCOMChecker(IBaseContext baseContext, IProgressController progress)
 {
     fBaseContext = baseContext;
     fTree        = fBaseContext.Tree;
     fFormat      = GEDCOMProvider.GetGEDCOMFormat(fTree);
     fProgress    = progress;
 }
Ejemplo n.º 2
0
        public void Test_GetGEDCOMFormat()
        {
            GDMTree tree = new GDMTree();

            // Tests of determine GEDCOM-format
            Assert.AreEqual(GEDCOMFormat.gf_Unknown, GEDCOMProvider.GetGEDCOMFormat(tree));
            tree.Header.Source.StringValue = "GENBOX";
            Assert.AreEqual(GEDCOMFormat.gf_GENBOX, GEDCOMProvider.GetGEDCOMFormat(tree));
        }
Ejemplo n.º 3
0
        public static bool CheckGEDCOMFormat(GDMTree tree, IBaseContext baseContext, IProgressController pc)
        {
            if (tree == null)
            {
                throw new ArgumentNullException("tree");
            }

            if (baseContext == null)
            {
                throw new ArgumentNullException("baseContext");
            }

            if (pc == null)
            {
                throw new ArgumentNullException("pc");
            }

            bool result = false;

            try {
                GEDCOMFormat format = GEDCOMProvider.GetGEDCOMFormat(tree);
                int          fileVer;
                // remove a deprecated features
                if (format == GEDCOMFormat.gf_Native)
                {
                    GDMHeader header = tree.Header;
                    GDMTag    tag;

                    tag = header.FindTag("_ADVANCED", 0);
                    if (tag != null)
                    {
                        header.DeleteTag("_ADVANCED");
                    }

                    tag = header.FindTag("_EXT_NAME", 0);
                    if (tag != null)
                    {
                        header.DeleteTag("_EXT_NAME");
                    }

                    fileVer = ConvertHelper.ParseInt(header.Source.Version, GKData.APP_FORMAT_DEFVER);
                }
                else
                {
                    fileVer = -1;
                }

                pc.ProgressInit(LangMan.LS(LSID.LSID_FormatCheck), 100);
                try {
                    bool xrefValid    = true;
                    bool isExtraneous = (format != GEDCOMFormat.gf_Native);

                    int progress = 0;
                    int num      = tree.RecordsCount;
                    for (int i = 0; i < num; i++)
                    {
                        GDMRecord rec = tree[i];
                        CheckRecord(baseContext, tree, rec, format, fileVer);

                        if (isExtraneous && xrefValid && !CheckRecordXRef(rec))
                        {
                            xrefValid = false;
                        }

                        int newProgress = (int)Math.Min(100, ((i + 1) * 100.0f) / num);
                        if (progress != newProgress)
                        {
                            progress = newProgress;
                            pc.ProgressStep(progress);
                        }
                    }

                    // obsolete: AppHost.StdDialogs.ShowQuestionYN(LangMan.LS(LSID.LSID_IDsCorrectNeed))
                    if (!xrefValid)
                    {
                        ConvertIdentifiers(tree, pc);
                    }

                    result = true;
                } finally {
                    pc.ProgressDone();
                }
            } catch (Exception ex) {
                Logger.LogWrite("GEDCOMChecker.CheckGEDCOMFormat(): " + ex.Message);
                AppHost.StdDialogs.ShowError(LangMan.LS(LSID.LSID_CheckGedComFailed));
            }

            return(result);
        }