/// <summary> /// Update taxon information in database. /// New information is read from web service TaxonService. /// </summary> /// <param name="taxonTree">Contains information about current taxon tree.</param> /// <param name="isRootTaxonTree">True if taxon tree is a root taxon tree node.</param> /// <param name="taxonTreeTable">Contains current taxon tree table.</param> private static void UpdateTaxonTreeInformation(WebTaxonTreeNode taxonTree, Boolean isRootTaxonTree, DataTable taxonTreeTable) { // Add information about current taxon tree node. DataRow row = taxonTreeTable.NewRow(); row[0] = taxonTree.Taxon.Id; row[1] = taxonTree.Taxon.Id; if (isRootTaxonTree) { row[2] = 0; } else { row[2] = 1; } taxonTreeTable.Rows.Add(row); if (taxonTree.Children.IsNotEmpty()) { // Add information about nearest child taxa relations foreach (WebTaxonTreeNode nearestChild in taxonTree.Children) { row = taxonTreeTable.NewRow(); row[0] = taxonTree.Taxon.Id; row[1] = nearestChild.Taxon.Id; row[2] = 2; taxonTreeTable.Rows.Add(row); } // Add information about child taxa relations. WebTaxonList childTaxa = new WebTaxonList(); foreach (WebTaxonTreeNode nearestChild in taxonTree.Children) { childTaxa.Merge(GetChildTaxa(nearestChild)); } foreach (WebTaxon childTaxon in childTaxa) { row = taxonTreeTable.NewRow(); row[0] = taxonTree.Taxon.Id; row[1] = childTaxon.Id; row[2] = 3; taxonTreeTable.Rows.Add(row); } // Add information about child taxon trees. foreach (WebTaxonTreeNode nearestChild in taxonTree.Children) { UpdateTaxonTreeInformation(nearestChild, false, taxonTreeTable); } } }
private static void innerConvertTreeNodeStructure(Dictionary <Int32, MyTaxonTreeNode> dictionary, MyTaxonTreeNode parentNode, WebTaxonTreeNode childNode) { if (dictionary.ContainsKey(childNode.Taxon.Id)) { if (parentNode.IsNotNull()) { var thisNode = dictionary[childNode.Taxon.Id]; if (thisNode.Parents.All(item => item.TaxonId != parentNode.TaxonId)) { thisNode.Parents.Add(parentNode); } } } else { var thisNode = new MyTaxonTreeNode { Childes = new List <MyTaxonTreeNode>(), Information = new TaxonInformation { DyntaxaTaxonId = childNode.Taxon.Id, TaxonCategoryId = childNode.Taxon.CategoryId, ScientificName = childNode.Taxon.ScientificName }, Parents = parentNode == null ? new List <MyTaxonTreeNode>() : new List <MyTaxonTreeNode> { parentNode }, TaxonId = childNode.Taxon.Id }; dictionary.Add(childNode.Taxon.Id, thisNode); if (childNode.Children != null) { foreach (var webTaxonTreeNode in childNode.Children) { innerConvertTreeNodeStructure(dictionary, thisNode, webTaxonTreeNode); thisNode.Childes.Add(dictionary[webTaxonTreeNode.Taxon.Id]); } } } }