コード例 #1
0
        private ZooBankRegistration GetZoobankRegistrationObject(string sourceFileName)
        {
            if (string.IsNullOrWhiteSpace(sourceFileName))
            {
                throw new ArgumentNullException(nameof(sourceFileName));
            }

            List <ZooBankRegistration> zoobankRegistrationList = null;

            using (var stream = new FileStream(sourceFileName, FileMode.Open, FileAccess.Read))
            {
                var serializer = new DataContractJsonSerializer(typeof(List <ZooBankRegistration>));
                zoobankRegistrationList = (List <ZooBankRegistration>)serializer.ReadObject(stream);
                stream.Close();
            }

            ZooBankRegistration zoobankRegistration = null;

            if (zoobankRegistrationList == null || zoobankRegistrationList.Count < 1)
            {
                throw new ApplicationException("No valid ZooBank registration records in JSON file");
            }
            else
            {
                if (zoobankRegistrationList.Count > 1)
                {
                    this.logger?.Log(LogType.Warning, "More than one ZooBank registration records in JSON File.\n\tIt will be used only the first one.");
                }

                zoobankRegistration = zoobankRegistrationList[0];
            }

            return(zoobankRegistration);
        }
コード例 #2
0
        private void ProcessArticleLsid(IDocument target, ZooBankRegistration source)
        {
            string articleLsid = UrlConstants.ZooBankPrefix + source.ReferenceUuid.Trim();
            var    selfUriNode = target.SelectSingleNode(XPathStrings.ArticleZooBankSelfUri);

            if (selfUriNode == null)
            {
                throw new ApplicationException("article-meta/self-uri/@content-type='zoobank' is missing.");
            }

            selfUriNode.InnerText = articleLsid;
        }
コード例 #3
0
 private void ResolveEmptyParentNames(ZooBankRegistration zoobankRegistration, NomenclaturalAct nomenclaturalAct)
 {
     if (nomenclaturalAct.Parentname == string.Empty && nomenclaturalAct.ParentUsageUuid != string.Empty)
     {
         foreach (NomenclaturalAct n in zoobankRegistration.NomenclaturalActs)
         {
             if (string.Compare(nomenclaturalAct.ParentUsageUuid, n.TnuUuid) == 0)
             {
                 nomenclaturalAct.Parentname = n.NameString;
                 break;
             }
         }
     }
 }
コード例 #4
0
        public Task <object> Clone(IDocument target, ZooBankRegistration source)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            return(Task.Run <object>(() =>
            {
                this.ProcessArticleLsid(target, source);
                this.ProcessTaxonomicActsLsid(target, source);

                return true;
            }));
        }
コード例 #5
0
        private void ProcessTaxonomicActsLsid(IDocument target, ZooBankRegistration source)
        {
            int numberOfNomenclaturalActs    = source.NomenclaturalActs.Count;
            int numberOfNewNomenclaturalActs = 0;

            foreach (var nomenclaturalAct in source.NomenclaturalActs)
            {
                this.ResolveEmptyParentNames(source, nomenclaturalAct);

                this.logger?.Log(
                    "\n\n{0}{1}{2} {3}",
                    nomenclaturalAct.Parentname,
                    string.IsNullOrEmpty(nomenclaturalAct.Parentname) ? string.Empty : " ",
                    nomenclaturalAct.NameString,
                    nomenclaturalAct.TnuUuid);

                string xpath = this.GetNomenclatureTaxonObjectIdXPath(nomenclaturalAct);
                if (xpath != null)
                {
                    var objectIdNode = target.SelectSingleNode(xpath);
                    if (objectIdNode != null)
                    {
                        objectIdNode.InnerText = UrlConstants.ZooBankPrefix + nomenclaturalAct.TnuUuid.Trim();
                        numberOfNewNomenclaturalActs++;

                        this.logger?.Log(
                            "{0}{1}{2} {3}",
                            nomenclaturalAct.Parentname,
                            string.IsNullOrEmpty(nomenclaturalAct.Parentname) ? string.Empty : " ",
                            nomenclaturalAct.NameString,
                            nomenclaturalAct.TnuUuid);
                    }
                }
            }

            this.logger?.Log(
                "\n\n\nNumber of nomenclatural acts = {0}.\nNumber of new nomenclatural acts = {1}.\n\n\n",
                numberOfNomenclaturalActs,
                numberOfNewNomenclaturalActs);
        }