/// <summary> /// Removes the taxon id from the TaxonIds list. /// </summary> /// <param name="taxonId">The taxon id.</param> public void RemoveTaxonId(int taxonId) { if (TaxonIds.IsNull()) { return; } TaxonIds.Remove(taxonId); }
/// <summary> /// Add taxon id to search criteria. /// </summary> /// <param name="taxonId">Taxon id.</param> public void AddTaxon(Int32 taxonId) { if (TaxonIds.IsNull()) { TaxonIds = new List <Int32>(); } TaxonIds.Add(taxonId); }
/// <summary> /// Removes the taxon ids from the TaxonIds list. /// </summary> /// <param name="taxonIds">The taxon ids.</param> public void RemoveTaxonIds(int[] taxonIds) { if (TaxonIds.IsNull()) { return; } foreach (int taxonId in taxonIds) { TaxonIds.Remove(taxonId); } }
/// <summary> /// Adds taxon id to the TaxonIds list. /// </summary> /// <param name="taxonId">The taxon id.</param> public void AddTaxonId(int taxonId) { int countBefore = TaxonIds.Count; TaxonIds.Add(taxonId); IEnumerable <int> distinctList = TaxonIds.Distinct(); var distinctCollection = new ObservableCollection <int>(); foreach (int id in distinctList) { distinctCollection.Add(id); } TaxonIds = distinctCollection; int countAfter = TaxonIds.Count; if (!IsActive && (countAfter > countBefore)) { IsActive = true; } }
public void Activate() { TaxonIds Data = TaxonIds.Compute(TaxonUtils.OriginalRoot); string message = "Check Ids:\n"; message += String.Format(" Total Ids used: {0} (min = {1}, max = {2})\n", Data.Ids.Count, Data.MinId, Data.MaxId); if (Data.TolIds.Count > 0) { message += String.Format(" Total TOL Ids used: {0} (min = {1}, max = {2})\n", Data.TolIds.Count, Data.MinTolId, Data.MaxTolId); } message += String.Format(" Number of ranges: {0}\n", Data.Ranges.Count); message += String.Format(" Total Duplicate: {0}\n", Data.Duplicates.Count); message += String.Format(" Total without Id: {0}\n", Data.NoIds.Count); message += String.Format("for more details, look at CheckTaxonIDs.log file"); Loggers.WriteInformation(LogTags.Data, message); try { string file = Path.Combine(TaxonUtils.GetLogPath(), "CheckTaxonIDs.log"); if (File.Exists(file)) { File.Delete(file); } using (StreamWriter outfile = new StreamWriter(file)) { outfile.WriteLine("CheckTaxonIDs results:\n"); outfile.WriteLine(string.Format("Ranges ( {0} ) :", Data.Ranges.Count)); foreach (Tuple <uint, uint> tuple in Data.Ranges) { outfile.WriteLine(string.Format(" from {0} to {1} ({2})", tuple.Item1, tuple.Item2, tuple.Item2 - tuple.Item1 + 1)); } outfile.WriteLine(""); outfile.WriteLine(string.Format("Duplicates ( {0} ) :", Data.Duplicates.Count)); foreach (Tuple <TaxonDesc, TaxonDesc> tuple in Data.Duplicates) { outfile.WriteLine(string.Format(" {0}({1}), {2}({3})", tuple.Item1.RefMultiName.Main, tuple.Item1.OTTID, tuple.Item2.RefMultiName.Main, tuple.Item2.OTTID)); } outfile.WriteLine(""); outfile.WriteLine(string.Format("Without id ( {0} ) :", Data.NoIds.Count)); foreach (TaxonDesc node in Data.NoIds) { outfile.WriteLine(" " + node.RefMultiName.Main); } outfile.WriteLine(""); outfile.WriteLine(string.Format("Tols id ( {0} ) :", Data.TolIds.Count)); foreach (KeyValuePair <UInt32, TaxonDesc> pair in Data.TolIds) { outfile.WriteLine(" " + pair.Key + " ( FirstTolID + " + (pair.Key - TaxonIds.FirstTolID) + " ) : " + pair.Value.RefMultiName.Main); } outfile.WriteLine(""); } } catch (Exception e) { string error = "Exception while saving results in CheckTaxonIDs.log: \n\n"; error += e.Message; if (e.InnerException != null) { error += "\n" + e.InnerException.Message; } Loggers.WriteError(LogTags.Data, error); } }
public void Activate() { DialogResult result = MessageBox.Show("Generate IDs for doublon without ID ?", "Quit ?", MessageBoxButtons.YesNo, MessageBoxIcon.Information); bool generateId = result == DialogResult.Yes; Dictionary <string, object> dico = new Dictionary <string, object>(); List <TaxonTreeNode> All = new List <TaxonTreeNode>() { TaxonUtils.OriginalRoot }; TaxonUtils.OriginalRoot.GetAllChildrenRecursively(All); List <string> doublons = new List <string>(); foreach (TaxonTreeNode node in All) { if (node.Desc.IsUnnamed) { continue; } string name = node.Desc.RefMultiName.Main; if (dico.ContainsKey(name)) { if (dico[name] is TaxonTreeNode) { doublons.Add(name); List <TaxonTreeNode> list = new List <TaxonTreeNode>(); list.Add(dico[name] as TaxonTreeNode); dico[name] = list; } (dico[name] as List <TaxonTreeNode>).Add(node); } else { dico[name] = node; } } string file = Path.Combine(TaxonUtils.GetLogPath(), "CheckDuplicateNames.log"); if (File.Exists(file)) { File.Delete(file); } UInt32 maxId = 0; int createIds = 0; using (StreamWriter outfile = new StreamWriter(file)) { outfile.WriteLine("CheckDuplicateNames result ( " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + " )\n"); outfile.WriteLine("Find " + doublons.Count.ToString() + " duplicated names\n"); foreach (string dupName in doublons) { List <TaxonTreeNode> duplicatas = dico[dupName] as List <TaxonTreeNode>; if (duplicatas == null) { continue; } outfile.WriteLine("[ " + dupName + " ], " + duplicatas.Count.ToString() + " occurences:"); foreach (TaxonTreeNode node in duplicatas) { string descId = "[id: " + node.Desc.OTTID + "]"; if (generateId && node.Desc.OTTID == 0) { if (maxId == 0) { maxId = TaxonIds.GetUnusedTolId(TaxonUtils.OriginalRoot); } node.Desc.OTTID = maxId++; descId = "[id created: " + node.Desc.OTTID + "]"; createIds++; } outfile.WriteLine(" " + node.GetHierarchicalName() + " " + descId); } } } string message = "Check duplicate names : \n\n"; message += String.Format(" duplicate names : {0}\n\n", doublons.Count); if (createIds > 0) { message += String.Format(" {0} ids have been created, do not forget to save\n\n", createIds); } message += String.Format("for more details, look at CheckDuplicateNames.log file"); Loggers.WriteInformation(LogTags.Data, message); }
public void ResetSettings() { TaxonIds.Clear(); }