Пример #1
0
        public void Activate()
        {
            int count1 = 0;
            int count2 = 0;

            char[] forbiddenChar = "<>:\"/\\|?*".ToCharArray();

            string logFile = Path.Combine(TaxonUtils.GetLogPath(), "CheckNames.log");

            using (StreamWriter log = new StreamWriter(logFile))
            {
                TaxonUtils.OriginalRoot.ParseNode((d) =>
                {
                    string name = d.Desc.RefMultiName.Main;
                    if (name.Trim() != name)
                    {
                        count1++;
                        log.WriteLine("empty spaces in " + d.GetHierarchicalName());
                    }
                    if (name.IndexOfAny(forbiddenChar) != -1)
                    {
                        count2++;
                        log.WriteLine("forbidden char in " + d.GetHierarchicalName());
                    }
                });

                string message = "Name check:\n";
                message += string.Format("{0} with spaces (or tab) at start or end of name\n", count1);
                message += string.Format("{0} with forbidden characters\n", count2);
                message += "more informations in " + logFile + " file.\n";
                Loggers.WriteInformation(LogTags.Data, message);
                log.Write(message);
            }
        }
Пример #2
0
        public void Activate()
        {
            List <TaxonDesc> taxonToModify = new List <TaxonDesc>();

            TaxonUtils.OriginalRoot.ParseNodeDesc((d) => { if (d.HasFrenchName && d.FrenchMultiName.Full.Contains(" ou "))
                                                           {
                                                               taxonToModify.Add(d);
                                                           }
                                                  });

            string logFile = Path.Combine(TaxonUtils.GetLogPath(), "SynonymRemoveOu.log");

            using (StreamWriter log = new StreamWriter(logFile))
            {
                log.WriteLine("Replace synonym separator ' ou ' with ';' (" + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + ")\n");
                log.WriteLine("  found " + taxonToModify.Count + " taxon that need to be changed\n\n");

                string[] separatorArray = new string[] { " ou " };
                foreach (TaxonDesc node in taxonToModify)
                {
                    string oldName = node.FrenchMultiName.Full;
                    node.FrenchMultiName = new Helpers.MultiName(string.Join(Helpers.MultiName.SeparatorAsString, node.FrenchMultiName.Full.Split(separatorArray, StringSplitOptions.RemoveEmptyEntries)));
                    log.WriteLine("(" + node.RefMainName + ")" + oldName + " => " + node.FrenchMultiName.Full);
                }
            }

            string message = "Replacing synonym separator ' ou ' with ';' \n";

            message += taxonToModify.Count + " taxons impacted\n";
            message += "for more details, look at SynonymRemoveOu.log files";
            Loggers.WriteInformation(LogTags.Data, message);
        }
Пример #3
0
        public void Activate()
        {
            _Result = new List <TaxonTreeNode>();
            TaxonUtils.OriginalRoot.ParseNode(CheckLeaf);

            TaxonList list = new TaxonList {
                HasFile = true, FileName = Path.Combine(TaxonUtils.GetLogPath(), "ListOfNonSpeciesLeaves.lot")
            };

            list.FromTaxonTreeNodeList(_Result);
            list.Save(false, TaxonList.FileFilterIndexEnum.ListOfTaxons);

            string message = string.Format("{0} taxons with no children and that are not species or sub species", _Result.Count);

            string logFile = Path.Combine(TaxonUtils.GetLogPath(), "ListOfNonSpeciesLeaves.log");

            using (StreamWriter log = new StreamWriter(logFile))
            {
                log.WriteLine(message);
                log.WriteLine();
                foreach (TaxonTreeNode node in _Result)
                {
                    log.WriteLine(node.GetHierarchicalName());
                }
            }
            message += string.Format("\ntaxons found are saved as filter list in {0}", list.FileName);
            message += string.Format("\nfor more details, look at {0}", logFile);
            Loggers.WriteInformation(LogTags.Data, message);
        }
        public void Activate()
        {
            Data data = new Data();

            TaxonUtils.OriginalRoot.ParseNode(CheckCollectionIds, data);

            string message = "CheckCollectionsIds results: \n\n";

            message += String.Format("    Existents collections  : {0} ids, {1} total images\n", data.Exists.Count, data.TotalExistsImage());
            message += String.Format("    Inexistents collections: {0} ids, {1} total images\n", data.DontExists.Count, data.TotalDontExistsImage());
            message += String.Format("for more details, look at CheckCollectionsIds.log file");
            Loggers.WriteInformation(LogTags.Image, message);

            try
            {
                string file = Path.Combine(TaxonUtils.GetLogPath(), "CheckCollectionsIds.log");
                if (File.Exists(file))
                {
                    File.Delete(file);
                }
                using (StreamWriter outfile = new StreamWriter(file))
                {
                    outfile.WriteLine("CheckCollectionsIds result ( " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + " )\n");
                    outfile.WriteLine("\n");
                    outfile.WriteLine(string.Format("Existent collections ( {0} ) :", data.Exists.Count));
                    foreach (KeyValuePair <int, int> p in data.Exists)
                    {
                        ImageCollection ic   = TaxonImages.Manager.Collection(p.Key);
                        string          desc = "    " + p.Key + " (" + p.Value + " images)";
                        if (ic == null)
                        {
                            outfile.WriteLine(desc + " not found in Manager");
                        }
                        else
                        {
                            outfile.WriteLine(desc + " = " + ic.Name);
                        }
                    }
                    outfile.WriteLine("\n");
                    outfile.WriteLine(string.Format("Inexistent collections ( {0} ) :", data.DontExists.Count));
                    foreach (KeyValuePair <int, int> p in data.DontExists)
                    {
                        string desc = "    " + p.Key + " (" + p.Value + " images)";
                        outfile.WriteLine(desc);
                    }
                }
            }
            catch (Exception e)
            {
                string error = "Exception while saving results in CheckCollectionsIds.log: \n\n";
                error += e.Message;
                if (e.InnerException != null)
                {
                    error += "\n" + e.InnerException.Message;
                }
                Loggers.WriteError(LogTags.Image, error);
            }
        }
Пример #5
0
        public void Activate()
        {
            int count1 = 0;
            int count2 = 0;
            int count3 = 0;
            int count4 = 0;

            string logFile = Path.Combine(TaxonUtils.GetLogPath(), "_TempCheck.log");

            using (StreamWriter log = new StreamWriter(logFile))
            {
                TaxonUtils.OriginalRoot.ParseNode((d) =>
                {
                    if (d.Desc.RefMultiName.Full.IndexOf('†') != -1 || (d.Desc.FrenchMultiName != null && d.Desc.FrenchMultiName.Full.Contains('†')))
                    {
                        count1++;
                        log.WriteLine("Cross in name for " + d.GetHierarchicalName());
                    }

                    if (d.Desc.RedListCategory == RedListCategoryEnum.Extinct)
                    {
                        if (d.Desc.HasFlag(FlagsEnum.Extinct) || d.Desc.HasFlag(FlagsEnum.ExtinctInherited))
                        {
                            d.Desc.SetFlagValue(FlagsEnum.Extinct, false);
                            d.Desc.SetFlagValue(FlagsEnum.ExtinctInherited, false);
                            count4++;
                        }
                    }
                    else
                    {
                        if (d.Desc.HasFlag(FlagsEnum.ExtinctInherited))
                        {
                            log.WriteLine("Extinct inherited: " + d.GetHierarchicalName());
                            count2++;
                        }
                        if (d.Desc.HasFlag(FlagsEnum.Extinct))
                        {
                            log.WriteLine("Extinct: " + d.GetHierarchicalName());
                            count3++;
                        }
                    }
                });

                string message = "Extinct check:\n";
                message += string.Format("{0} with cross within name\n", count1);
                message += string.Format("{0} with extinct inherited flag\n", count2);
                message += string.Format("{0} with extinct flag\n", count3);
                if (count4 > 0)
                {
                    message += string.Format("{0} remove extinct or extinct inherited flag\n", count4);
                    message += string.Format("some data has been changed do not forget to save\n");
                }
                message += "more informations in " + logFile + " file.\n";
                Loggers.WriteInformation(LogTags.Data, message);
                log.Write(message);
            }
        }
        public void Activate()
        {
            List <TaxonTreeNode> ListTaxons = new List <TaxonTreeNode>();

            TaxonUtils.OriginalRoot.GetAllChildrenWithImageRecursively(ListTaxons);

            List <TaxonTreeNode> ListTaxonWithoutFrench = new List <TaxonTreeNode>();

            foreach (TaxonTreeNode taxon in ListTaxons)
            {
                if (taxon.Desc.HasFrenchName)
                {
                    ListTaxonWithoutFrench.Add(taxon);
                }
            }

            string message = "Check taxon with image but without French name:\n";

            message += String.Format("    Total found: {0}\n", ListTaxonWithoutFrench.Count);
            message += String.Format("for more details, look at CheckImagesWithoutFrenchNames.log file");
            Loggers.WriteInformation(LogTags.Image, message);

            try
            {
                string file = Path.Combine(TaxonUtils.GetLogPath(), "CheckImagesWithoutFrenchNames.log");
                if (File.Exists(file))
                {
                    File.Delete(file);
                }
                using (StreamWriter outfile = new StreamWriter(file))
                {
                    outfile.WriteLine("CheckImagesWithoutFrenchNames result ( " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + " )\n");
                    outfile.WriteLine(string.Format("Taxon found: {0}", ListTaxonWithoutFrench.Count));

                    foreach (TaxonTreeNode taxon in ListTaxonWithoutFrench)
                    {
                        outfile.WriteLine("    " + taxon.GetHierarchicalName());
                    }
                }
            }
            catch (Exception e)
            {
                string error = "Exception while saving results in CheckImagesWithoutFrenchNames.log: \n\n";
                error += e.Message;
                if (e.InnerException != null)
                {
                    error += "\n" + e.InnerException.Message;
                }
                Loggers.WriteError(LogTags.Data, error);
            }
        }
        public void Activate()
        {
            // retrouve la liste de toutes les especes
            List <TaxonTreeNode> Species = new List <TaxonTreeNode>();

            TaxonUtils.OriginalRoot.GetAllChildrenRecursively(Species, ClassicRankEnum.Espece);

            List <TaxonTreeNode> badTaxons = new List <TaxonTreeNode>();

            foreach (TaxonTreeNode t in Species)
            {
                if (t.Desc.RefMultiName.Main.Contains(" "))
                {
                    continue;
                }
                badTaxons.Add(t);
            }

            string message = "Check species named with only one word : ";

            if (badTaxons.Count == 0)
            {
                message += "none found\n";
                Loggers.WriteInformation(LogTags.Data, message);
                return;
            }

            message += String.Format("found {0} species\n\n", badTaxons.Count);
            message += String.Format("for more details, look at CheckSpeciesWithoutSpaceChar.log file");
            Loggers.WriteInformation(LogTags.Data, message);

            string file = Path.Combine(TaxonUtils.GetLogPath(), "CheckSpeciesWithoutSpaceChar.log");

            if (File.Exists(file))
            {
                File.Delete(file);
            }

            using (StreamWriter outfile = new StreamWriter(file))
            {
                outfile.WriteLine("CheckSpeciesWithoutSpaceChar result ( " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + " )\n");
                outfile.WriteLine("Find " + badTaxons.Count.ToString() + " species named with only one word\n");

                foreach (TaxonTreeNode taxon in badTaxons)
                {
                    outfile.WriteLine("    " + taxon.GetHierarchicalName());
                }
            }
        }
Пример #8
0
        public void Activate()
        {
            _Data = new ComputeClassicRankData();
            TaxonUtils.OriginalRoot.GetAllLastChildrenRecursively(_Data.Leaves);

            string file = Path.Combine(TaxonUtils.GetLogPath(), "ComputeClassicRank.log");

            if (File.Exists(file))
            {
                File.Delete(file);
            }

            using (_Data.Writer = new StreamWriter(file))
            {
                ComputeTwoWordsSpeciesSupSpecies();
                ComputeWithoutLatinName();
                ComputeSubSpeciesSecond();
                ComputeSpeciesFirst();
                ComputeSubGenreFirst();
                ComputeGenreFirst();

                _Data.Holozoa = TaxonUtils.OriginalRoot.FindTaxonByName("holozoa");
                if (_Data.Holozoa != null)
                {
                    Compute4Animals();
                }

                Compute4Others();
            }

            string message = "";

            message += String.Format("detect {0} new sub species\n", _Data.NewSubSpecies);
            message += String.Format("detect {0} new species\n", _Data.NewSpecies);
            message += String.Format("detect {0} new sub genre\n", _Data.NewSousGenre);
            message += String.Format("detect {0} new genre\n", _Data.NewGenre);
            message += String.Format("detect {0} new sous tribu\n", _Data.NewSousTribu);
            message += String.Format("detect {0} new tribus\n", _Data.NewTribu);
            message += String.Format("detect {0} new sous familles\n", _Data.NewSousFamille);
            message += String.Format("detect {0} new familles\n", _Data.NewFamille);
            message += String.Format("detect {0} new super famille\n", _Data.NewSuperFamille);
            message += String.Format("detect {0} new order\n", _Data.NewOrder);
            message += String.Format("detect {0} new without latin name\n", _Data.WithoutLatinName.Count);
            message += String.Format("for more details, look at ComputeClassicRank.log file");
            Loggers.WriteInformation(LogTags.Data, message);
        }
Пример #9
0
        public void Activate()
        {
            List <TaxonTreeNode> extincts          = new List <TaxonTreeNode>();
            List <TaxonTreeNode> extinctsInherited = new List <TaxonTreeNode>();

            string logFile = Path.Combine(TaxonUtils.GetLogPath(), "ExtinctsTaxons.log");

            using (StreamWriter log = new StreamWriter(logFile))
            {
                log.WriteLine("Move extinct flag to red list category EX (" + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + ")\n");

                TaxonUtils.OriginalRoot.ParseNode((d) =>
                {
                    if (d.Desc.HasFlag(FlagsEnum.Extinct))
                    {
                        extincts.Add(d);
                    }
                    if (d.Desc.HasFlag(FlagsEnum.ExtinctInherited))
                    {
                        extinctsInherited.Add(d);
                    }
                });

                log.WriteLine("taxon with extincts flag: " + extincts.Count.ToString());
                foreach (TaxonTreeNode node in extincts)
                {
                    log.WriteLine("    [" + node.Desc.RedListCategory.ToString() + "] " + node.GetHierarchicalName());
                }
                log.WriteLine();

                log.WriteLine("taxon with extincts inherited flag: " + extincts.Count.ToString());
                foreach (TaxonTreeNode node in extinctsInherited)
                {
                    log.WriteLine("    [" + node.Desc.RedListCategory.ToString() + "] " + node.GetHierarchicalName());
                }
                log.WriteLine();


                string message = "Move extinct flag to red list category EX results:\n";
                message += string.Format("{0} taxons with extinct flag\n", extincts.Count.ToString());
                message += string.Format("{0} taxons with extinct inherited flag\n", extinctsInherited.Count.ToString());
                message += string.Format("for more details, look at {0}", logFile);
                Loggers.WriteInformation(LogTags.Data, message);
                log.Write(message);
            }
        }
Пример #10
0
        public void Activate()
        {
            int    countDescChanged = 0;
            int    countExtinct     = 0;
            string logFile          = Path.Combine(TaxonUtils.GetLogPath(), "RemoveExtinctCross.log");

            using (StreamWriter log = new StreamWriter(logFile))
            {
                log.WriteLine("Remove '†' (" + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + ")\n");

                TaxonUtils.OriginalRoot.ParseNodeDesc((d) =>
                {
                    if (d.RefMultiName.Main.Length == 0)
                    {
                        return;
                    }
                    if (d.RefMultiName.Main[d.RefMultiName.Main.Length - 1] == '†')
                    {
                        log.WriteLine("  " + d.RefMultiName.Main);
                        List <string> names = d.RefMultiName.GetAll().ToList();
                        for (int i = 0; i < names.Count; i++)
                        {
                            names[i] = names[i].Replace("†", "").Trim();
                        }
                        d.RefMultiName = new Helpers.MultiName(names);
                        d.Flags       |= (uint)FlagsEnum.Extinct;
                        countDescChanged++;
                        countExtinct++;
                    }
                    else if ((d.Flags & (uint)FlagsEnum.Extinct) != 0)
                    {
                        countExtinct++;
                    }
                });

                string message = "Remove Extinct Cross:\n";
                message += String.Format("{0} extinct taxon renamed\n", countDescChanged);
                message += String.Format("{0} extinct taxons (with flags)\n", countExtinct);
                Loggers.WriteInformation(LogTags.Data, message);
                log.Write(message);
            }
        }
Пример #11
0
        public void Activate()
        {
            List <TaxonTreeNode> ListTaxonsLatin = new List <TaxonTreeNode>();

            TaxonUtils.OriginalRoot.ParseNode((d) => { if (d.Desc.RefMultiName.HasSynonym)
                                                       {
                                                           ListTaxonsLatin.Add(d);
                                                       }
                                              });

            List <TaxonTreeNode> ListTaxonsFrench = new List <TaxonTreeNode>();

            TaxonUtils.OriginalRoot.ParseNode((d) => { if (d.Desc.HasFrenchName && d.Desc.FrenchMultiName.HasSynonym)
                                                       {
                                                           ListTaxonsFrench.Add(d);
                                                       }
                                              });

            string message = "List all taxon with synonyms:\n";

            message += String.Format("    Taxons with latin synonyms : {0}\n", ListTaxonsLatin.Count);
            message += String.Format("    Taxons with french synonyms : {0}\n", ListTaxonsFrench.Count);
            message += String.Format("for more details, look at SynonymListAll_*.log file");
            Loggers.WriteInformation(LogTags.Image, message);

            List <Tuple <string, List <TaxonTreeNode> > > outputs = new List <Tuple <string, List <TaxonTreeNode> > >()
            {
                new Tuple <string, List <TaxonTreeNode> >("latin", ListTaxonsLatin),
                new Tuple <string, List <TaxonTreeNode> >("french", ListTaxonsFrench)
            };

            try
            {
                foreach (Tuple <string, List <TaxonTreeNode> > tuple in outputs)
                {
                    string logFilename = Path.Combine(TaxonUtils.GetLogPath(), "SynonymListAll_" + tuple.Item1 + ".log");
                    if (File.Exists(logFilename))
                    {
                        File.Delete(logFilename);
                    }
                    using (StreamWriter outfile = new StreamWriter(logFilename))
                    {
                        outfile.WriteLine("SynonymsListAll " + tuple.Item1 + " results ( " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + " )\n");
                        outfile.WriteLine(string.Format("Taxon found: {0}", tuple.Item2.Count));

                        foreach (TaxonTreeNode taxon in tuple.Item2)
                        {
                            outfile.WriteLine("    " + taxon.GetHierarchicalName());

                            Helpers.MultiName multiName  = (tuple.Item1 == "french") ? taxon.Desc.FrenchMultiName : taxon.Desc.RefMultiName;
                            string[]          otherNames = multiName.GetSynonymsArray();
                            if (otherNames == null || otherNames.Length == 0)
                            {
                                outfile.WriteLine("    " + taxon.Desc.RefMainName + " has no synonyms (should not happen here!!)");
                                continue;
                            }

                            outfile.WriteLine("    " + taxon.Desc.RefMainName + " has " + otherNames.Length.ToString() + " synonym" + (otherNames.Length == 1 ? "" : "s"));
                            foreach (string synonym in otherNames)
                            {
                                outfile.WriteLine("        " + synonym);
                            }
                        }
                    }
                    System.Diagnostics.Process.Start(logFilename);
                }
            }
            catch (Exception e)
            {
                string error = "Exception while saving results in SynonymsListAll.log: \n\n";
                error += e.Message;
                if (e.InnerException != null)
                {
                    error += "\n" + e.InnerException.Message;
                }
                Loggers.WriteError(LogTags.Data, error);
            }
        }
Пример #12
0
        public void Activate()
        {
            DateTime ts_Start = DateTime.Now;

            using (ProgressDialog progressDlg = new ProgressDialog())
            {
                progressDlg.StartPosition = FormStartPosition.CenterScreen;
                progressDlg.Show();

                // retrouve la liste de toutes les especes / sous especes
                ProgressItem         piPrepare = progressDlg.Add("Prepare ...", "get species", 0, 4);
                List <TaxonTreeNode> Species   = new List <TaxonTreeNode>();
                TaxonUtils.OriginalRoot.GetAllChildrenRecursively(Species, ClassicRankEnum.Espece);
                piPrepare.Update(1, "get sub species");
                TaxonUtils.OriginalRoot.GetAllChildrenRecursively(Species, ClassicRankEnum.SousEspece);
                piPrepare.Update(2, "init");

                int beforeWith    = 0;
                int beforeImages  = 0;
                int beforeWithout = 0;

                DateTime ts_StartDico = DateTime.Now;
                Dictionary <string, TaxonTreeNode> dico = new Dictionary <string, TaxonTreeNode>();
                foreach (TaxonTreeNode node in Species)
                {
                    if (node.Desc.Images != null && node.Desc.Images.Count != 0)
                    {
                        beforeWith++;
                        beforeImages += node.Desc.Images.Count;
                    }
                    else
                    {
                        beforeWithout++;
                    }

                    dico[node.Desc.RefMultiName.Main.ToLower()] = node;
                }

                piPrepare.Update(3, "clear");
                TaxonUtils.OriginalRoot.ParseNodeDesc((d) => { d.Images = null; });
                piPrepare.Update(4, "end");
                piPrepare.End();

                DateTime ts_StartParseCollection = DateTime.Now;

                List <string> badFormatFilenames = new List <string>();

                ProgressItem piCollections = progressDlg.Add("Parse collections ...", "", 0, TaxonImages.Manager.CollectionsEnumerable().Count());
                foreach (ImageCollection collection in TaxonImages.Manager.CollectionsEnumerable())
                {
                    piCollections.Update(piCollections.Current + 1, collection.Name);

                    if (!Directory.Exists(collection.Path))
                    {
                        continue;
                    }
                    IEnumerable <string> files = Directory.EnumerateFiles(collection.Path, "*.jpg");

                    int  count        = 10000;
                    Task getCountTask = Task.Factory.StartNew(() => { count = files.Count(); });

                    int          counter  = 0;
                    ProgressItem piPhotos = progressDlg.Add("Parse " + collection.Name + " photos ...", "", 0, count - 1);
                    foreach (string file in files)
                    {
                        string name = Path.GetFileNameWithoutExtension(file);

                        counter++;
                        if (counter == 10)
                        {
                            counter = 0;
                            if (getCountTask != null)
                            {
                                if (getCountTask.IsCompleted)
                                {
                                    piPhotos.Max = count - 1;
                                    getCountTask = null;
                                }
                                else if (piPhotos.Max < piPhotos.Current + 10)
                                {
                                    piPhotos.Max += 10000;
                                }
                            }
                            piPhotos.Update(piPhotos.Current + 10, name);
                        }

                        TaxonImages.SplitImageFilenameResult result = TaxonImages.Manager.SplitImageFilename(file, false, collection);
                        if (result == null)
                        {
                            badFormatFilenames.Add(file);
                            continue;
                        }

                        name = result.TaxonName.ToLower();

                        if (dico.ContainsKey(name))
                        {
                            if (dico[name].Desc.Images == null)
                            {
                                dico[name].Desc.Images = new List <TaxonImageDesc>();
                            }
                            dico[name].Desc.Images.Add(result.Desc);
                        }
                    }
                    piPhotos.End();

                    // treat xmls
                    foreach (var pair in collection.AllLinks)
                    {
                        ImagesLinks list = pair.Value;

                        for (int i = 0; i < list.Count; i++)
                        {
                            ImageLink link = list[i];
                            if (dico.TryGetValue(link.Key.ToLower(), out TaxonTreeNode node))
                            {
                                TaxonImageDesc desc = new TaxonImageDesc
                                {
                                    CollectionId = collection.Id,
                                    Secondary    = false,
                                    LinksId      = pair.Key,
                                    Index        = i
                                };

                                if (node.Desc.Images == null)
                                {
                                    node.Desc.Images = new List <TaxonImageDesc>();
                                }
                                node.Desc.Images.Add(desc);
                            }
                        }
                    }

                    foreach (var reference in collection.DistantReferences)
                    {
                        if (dico.TryGetValue(reference.TaxonName.ToLower(), out TaxonTreeNode node))
                        {
                            TaxonImageDesc desc = new TaxonImageDesc
                            {
                                CollectionId = collection.Id,
                                Secondary    = false,
                                LinksId      = 0,
                                Index        = reference.Index
                            };

                            if (node.Desc.Images == null)
                            {
                                node.Desc.Images = new List <TaxonImageDesc>();
                            }
                            node.Desc.Images.Add(desc);
                        }
                    }
                }

                DateTime ts_StartFinalise = DateTime.Now;

                int afterWith    = 0;
                int afterImages  = 0;
                int afterWithout = 0;

                foreach (TaxonTreeNode node in Species)
                {
                    if (node.Desc.Images != null)
                    {
                        afterWith++;
                        afterImages += node.Desc.Images.Count;
                    }
                    else
                    {
                        afterWithout++;
                    }
                }

                DateTime ts_End = DateTime.Now;

                string message = "Update image flag : \n\n";
                message += String.Format("    Total with image     : {0} referencing {1} images, (before: {2} referencing {3} images)\n", afterWith, afterImages, beforeWith, beforeImages);
                message += String.Format("    Total without image  : {0}, (before: {1})\n\n", afterWithout, beforeWithout);
                message += String.Format("    Badly formatted files: {0}\n", badFormatFilenames.Count);
                message += String.Format("    {0} ms to get taxons\n", (ts_StartDico - ts_Start).Milliseconds);
                message += String.Format("    {0} ms to fill dico\n", (ts_StartParseCollection - ts_StartDico).Milliseconds);
                message += String.Format("    {0} ms to parse collections\n", (ts_StartFinalise - ts_StartParseCollection).Milliseconds);
                message += String.Format("    {0} ms to finalize taxons\n", (ts_End - ts_StartFinalise).Milliseconds);
                message += String.Format("Dumped in UpdateImages.log file");
                Loggers.WriteInformation(LogTags.Image, message);

                string logfile = Path.Combine(TaxonUtils.GetLogPath(), "UpdateImages.log");
                if (File.Exists(logfile))
                {
                    File.Delete(logfile);
                }
                using (StreamWriter log = new StreamWriter(logfile))
                {
                    log.WriteLine("UpdateImages result ( " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + " )\n");
                    log.WriteLine(message);
                    log.WriteLine("");
                    log.WriteLine("Files with bad format names detected:\n");
                    foreach (string filename in badFormatFilenames)
                    {
                        log.WriteLine("    " + filename);
                    }
                }
            }

            TaxonUtils.OriginalRoot.UpdateAvailableImages();
            TaxonControlList.OnAvailableImagesChanged();
        }
Пример #13
0
        public void Activate()
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter       = "txt files (*.txt)|*.txt";
            ofd.Multiselect  = false;
            ofd.AddExtension = true;
            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            if (!File.Exists(ofd.FileName))
            {
                return;
            }

            List <string> notFound = new List <string>();
            List <Tuple <string, TaxonTreeNode> > found = new List <Tuple <string, TaxonTreeNode> >();

            string shortName = Path.GetFileNameWithoutExtension(ofd.FileName);

            int totalLines           = 0;
            int lineWithOnlyOneName  = 0;
            int lineWithNoTaxon      = 0;
            int lineWithSeveralTaxon = 0;
            Dictionary <TaxonTreeNode, string>         firstSame    = new Dictionary <TaxonTreeNode, string>();
            Dictionary <TaxonTreeNode, string>         firstDiff    = new Dictionary <TaxonTreeNode, string>();
            Dictionary <TaxonTreeNode, string>         notFirst     = new Dictionary <TaxonTreeNode, string>();
            Dictionary <TaxonTreeNode, List <string> > severalLines = new Dictionary <TaxonTreeNode, List <string> >();

            string logFilenameErrors = Path.Combine(TaxonUtils.GetLogPath(), "ImportSynonym_" + shortName + "_errors.log");

            using (StreamWriter log = new StreamWriter(logFilenameErrors))
            {
                TaxonSearch searchTool = new TaxonSearch(TaxonUtils.OriginalRoot);
                using (StreamReader file = new StreamReader(ofd.FileName))
                {
                    string line;
                    while ((line = file.ReadLine()) != null)
                    {
                        if (string.IsNullOrWhiteSpace(line))
                        {
                            continue;
                        }

                        totalLines++;

                        List <string> names = line.Split(Helpers.MultiName.SeparatorAsCharArray, StringSplitOptions.RemoveEmptyEntries).ToList();
                        if (names.Count == 1)
                        {
                            log.WriteLine("Error, only one name in line: " + line);
                            lineWithOnlyOneName++;
                            continue;
                        }

                        List <TaxonTreeNode> nodes = new List <TaxonTreeNode>();
                        names.ForEach(t => nodes.Add(searchTool.FindOne(t)));

                        int countNodes = nodes.Count(t => t != null);
                        if (countNodes == 0)
                        {
                            log.WriteLine("Error, no matching nodes found for that line: " + line);
                            lineWithNoTaxon++;
                            continue;
                        }

                        if (countNodes > 1)
                        {
                            log.WriteLine("Error, two many matching nodes (" + countNodes.ToString() + ") found for that line: " + line);
                            lineWithSeveralTaxon++;
                            continue;
                        }

                        bool          firstIsGood = nodes[0] != null;
                        TaxonTreeNode node        = nodes.Where(t => t != null).First();

                        if (severalLines.ContainsKey(node))
                        {
                            severalLines[node].Add(line);
                            continue;
                        }

                        if (firstSame.ContainsKey(node))
                        {
                            severalLines[node] = new List <string>()
                            {
                                firstSame[node], line
                            };
                            firstSame.Remove(node);
                            continue;
                        }

                        if (firstDiff.ContainsKey(node))
                        {
                            severalLines[node] = new List <string>()
                            {
                                firstDiff[node], line
                            };
                            firstDiff.Remove(node);
                            continue;
                        }

                        if (notFirst.ContainsKey(node))
                        {
                            severalLines[node] = new List <string>()
                            {
                                notFirst[node], line
                            };
                            notFirst.Remove(node);
                            continue;
                        }

                        if (firstIsGood && names[0] == node.Desc.RefMultiName.Main)
                        {
                            firstSame[node] = line;
                        }
                        else if (firstIsGood)
                        {
                            firstDiff[node] = line;
                        }
                        else
                        {
                            notFirst[node] = line;
                        }
                    }
                }
            }

            string logFilenameFirst = Path.Combine(TaxonUtils.GetLogPath(), "ImportSynonym_" + shortName + "_first.log");

            using (StreamWriter log = new StreamWriter(logFilenameFirst))
            {
                log.WriteLine(firstSame.Count.ToString() + " exact matches found");
                foreach (KeyValuePair <TaxonTreeNode, string> pair in firstSame)
                {
                    log.WriteLine("   replace " + pair.Key.Desc.RefAllNames + " => " + pair.Value);
                    List <string> names = pair.Value.Split(Helpers.MultiName.SeparatorAsCharArray, StringSplitOptions.RemoveEmptyEntries).ToList();
                    pair.Key.Desc.Name = string.Join(Helpers.MultiName.SeparatorAsString, names);
                }
                log.WriteLine();

                log.WriteLine(firstDiff.Count.ToString() + " first match found but diff case");
                foreach (KeyValuePair <TaxonTreeNode, string> pair in firstDiff)
                {
                    log.WriteLine("   replace " + pair.Key.Desc.RefAllNames + " => " + pair.Value);
                    List <string> names = pair.Value.Split(Helpers.MultiName.SeparatorAsCharArray, StringSplitOptions.RemoveEmptyEntries).ToList();
                    pair.Key.Desc.Name = string.Join(Helpers.MultiName.SeparatorAsString, names);
                }
                log.WriteLine();
            }

            string logFilenameNotFirst = Path.Combine(TaxonUtils.GetLogPath(), "ImportSynonym_" + shortName + "_notfirst.log");

            using (StreamWriter log = new StreamWriter(logFilenameNotFirst))
            {
                log.WriteLine(notFirst.Count.ToString() + " match found with one synonym");
                foreach (KeyValuePair <TaxonTreeNode, string> pair in notFirst)
                {
                    log.WriteLine("   replace " + pair.Key.Desc.RefAllNames + " => " + pair.Value);
                    List <string> names = pair.Value.Split(Helpers.MultiName.SeparatorAsCharArray, StringSplitOptions.RemoveEmptyEntries).ToList();
                    pair.Key.Desc.Name = string.Join(Helpers.MultiName.SeparatorAsString, names);
                }
                log.WriteLine();
            }

            string logFilenameSeveral = Path.Combine(TaxonUtils.GetLogPath(), "ImportSynonym_" + shortName + "_several.log");

            using (StreamWriter log = new StreamWriter(logFilenameSeveral))
            {
                log.WriteLine(severalLines.Count.ToString() + " node match with several lines");
                foreach (KeyValuePair <TaxonTreeNode, List <string> > pair in severalLines)
                {
                    log.WriteLine("   " + pair.Value.Count.ToString() + " matches for node: " + pair.Key.Desc.RefAllNames);
                    foreach (string s in pair.Value)
                    {
                        log.WriteLine("        " + s);
                    }
                }
                log.WriteLine();
            }

            string message = "Importing synonyms from: " + ofd.FileName + "\n";

            message += String.Format("    Total lines: {0}\n", totalLines);
            message += String.Format("    lines with only one name: {0}\n", lineWithOnlyOneName);
            message += String.Format("    lines with no associated taxons: {0}\n", lineWithNoTaxon);
            message += String.Format("    lines with more than one associated taxons: {0}\n", lineWithSeveralTaxon);
            message += String.Format("    lines with one ass. taxon, and with same first name: {0}\n", firstSame.Count);
            message += String.Format("    lines with one ass. taxon, and with first name with some lettercase difference: {0}\n", firstDiff.Count);
            message += String.Format("    lines with one ass. taxon, but not with with first name: {0}\n", notFirst.Count);
            message += String.Format("    several lines for same taxon: {0}\n", severalLines.Count);
            message += String.Format("for more details, look at ImportSynonym_{0}_*.log files", shortName);
            Loggers.WriteInformation(LogTags.Data, message);
        }
Пример #14
0
        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);
        }
Пример #15
0
        public void Activate()
        {
            OpenFileDialog ofd = new OpenFileDialog
            {
                Filter       = "Jac Files (*.txt)|*.txt",
                Multiselect  = false,
                AddExtension = true
            };

            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            if (!File.Exists(ofd.FileName))
            {
                return;
            }

            TaxonTreeNode importNodes = TaxonTreeNode.Load(ofd.FileName);

            string shortName = Path.GetFileNameWithoutExtension(ofd.FileName);

            int errorNoTaxon           = 0;
            int errorTwoManyTaxon      = 0;
            int redListCategoryChanged = 0;

            string logFilenameErrors = Path.Combine(TaxonUtils.GetLogPath(), "ImportRedListCategory_" + shortName + ".log");

            using (StreamWriter log = new StreamWriter(logFilenameErrors))
            {
                if (importNodes == null || importNodes.Children == null || importNodes.Children.Count == 0)
                {
                    log.WriteLine("no taxon found in file " + ofd.FileName);
                    Loggers.WriteInformation(LogTags.Data, "no taxon found in file " + ofd.FileName);
                    return;
                }

                TaxonSearch searchTool = new TaxonSearch(TaxonUtils.OriginalRoot, true, true);

                foreach (TaxonTreeNode node in importNodes.Children)
                {
                    List <TaxonTreeNode> dests = searchTool.FindAll(node.Desc.RefMainName);
                    if (dests == null || dests.Count == 0)
                    {
                        errorNoTaxon++;
                        log.WriteLine("Error, no matching taxons found for that name: " + node.Desc.RefMainName);
                    }
                    else if (dests.Count > 1)
                    {
                        errorTwoManyTaxon++;
                        log.WriteLine("Error, two many taxons found for that name: " + node.Desc.RefMainName);
                    }
                    else
                    {
                        if (dests[0].Desc.RedListCategory == node.Desc.RedListCategory)
                        {
                            log.WriteLine(node.Desc.RefMainName + " no change, is already " + node.Desc.RedListCategory.ToString());
                        }
                        else
                        {
                            redListCategoryChanged++;
                            log.WriteLine(node.Desc.RefMainName + " redlist category change from " + dests[0].Desc.RedListCategory.ToString() + " to " + node.Desc.RedListCategory.ToString());
                            dests[0].Desc.RedListCategory = node.Desc.RedListCategory;
                        }
                    }
                }
            }


            string message = "Importing red list category from: " + ofd.FileName + "\n";

            message += String.Format("    Total taxons: {0}\n", importNodes.Children.Count);
            message += String.Format("    taxon not found: {0}\n", errorNoTaxon);
            message += String.Format("    taxon find more than one time: {0}\n", errorTwoManyTaxon);
            message += String.Format("    changed taxons: {0}\n", redListCategoryChanged);
            if (redListCategoryChanged > 0)
            {
                message += string.Format("some data has been changed do not forget to save\n");
            }
            message += String.Format("for more details, look at ImportRedListCategory_{0}.log files", shortName);
            Loggers.WriteInformation(LogTags.Data, message);
        }
Пример #16
0
        public void Activate()
        {
            using (ProgressDialog progressDlg = new ProgressDialog())
            {
                progressDlg.StartPosition = FormStartPosition.CenterScreen;
                progressDlg.Show();

                ProgressItem piPrepare = progressDlg.Add("Prepare ...", "get species", 0, 3);
                // retrouve la liste de toutes les especes / sous especes
                List <TaxonTreeNode> Species = new List <TaxonTreeNode>();
                TaxonUtils.OriginalRoot.GetAllChildrenRecursively(Species, ClassicRankEnum.Espece);
                piPrepare.Update(1, "get sub species");
                List <TaxonTreeNode> SubSpecies = new List <TaxonTreeNode>();
                TaxonUtils.OriginalRoot.GetAllChildrenRecursively(SubSpecies, ClassicRankEnum.SousEspece);
                piPrepare.Update(2, "all images name (can be long)");
                // et la liste des fichiers dans le répertoires d'images
                string PathImages  = TaxonImages.Manager.Path;
                int    TotalImages = 0;
                Dictionary <string, bool> FileUsed = new Dictionary <string, bool>();
                Directory.GetFiles(PathImages, "*.jpg", SearchOption.AllDirectories).ToList().ForEach(f => { FileUsed[f.ToLower()] = false; TotalImages++; });
                piPrepare.Update(3, "init done");

                ProgressItem         piSpecies           = progressDlg.Add("Prepare ...", "get species", 0, Species.Count);
                List <TaxonTreeNode> SpeciesWithImage    = new List <TaxonTreeNode>();
                List <TaxonTreeNode> SpeciesWithBadImage = new List <TaxonTreeNode>();
                List <TaxonTreeNode> SpeciesWithoutImage = new List <TaxonTreeNode>();
                int count = 0;
                foreach (TaxonTreeNode node in Species)
                {
                    piSpecies.Update(++count);
                    if (node.Desc.Images == null)
                    {
                        SpeciesWithoutImage.Add(node);
                        continue;
                    }

                    bool badImage  = false;
                    bool goodImage = false;
                    foreach (TaxonImageDesc imageDesc in node.Desc.Images)
                    {
                        if (imageDesc.IsALink)
                        {
                            continue;
                        }
                        string path = imageDesc.GetPath(node.Desc).ToLower();
                        bool   used;
                        if (!FileUsed.TryGetValue(path, out used))
                        {
                            badImage = true;
                        }
                        else
                        {
                            goodImage = true;
                            if (used)
                            {
                                Console.WriteLine("image " + path + " used several time");
                            }
                            FileUsed[path] = true;
                        }
                    }
                    if (badImage)
                    {
                        SpeciesWithBadImage.Add(node);
                    }
                    if (goodImage)
                    {
                        SpeciesWithImage.Add(node);
                    }
                }

                ProgressItem         piSubSpecies           = progressDlg.Add("Prepare ...", "get species", 0, Species.Count);
                List <TaxonTreeNode> SubSpeciesWithImage    = new List <TaxonTreeNode>();
                List <TaxonTreeNode> SubSpeciesWithBadImage = new List <TaxonTreeNode>();
                List <TaxonTreeNode> SubSpeciesWithoutImage = new List <TaxonTreeNode>();
                count = 0;
                foreach (TaxonTreeNode node in SubSpecies)
                {
                    piSubSpecies.Update(++count);
                    if (node.Desc.Images == null)
                    {
                        SubSpeciesWithoutImage.Add(node);
                        continue;
                    }

                    bool badImage  = false;
                    bool goodImage = false;
                    foreach (TaxonImageDesc imageDesc in node.Desc.Images)
                    {
                        if (imageDesc.IsALink)
                        {
                            continue;
                        }
                        string path = imageDesc.GetPath(node.Desc).ToLower();
                        bool   used;
                        if (!FileUsed.TryGetValue(path, out used))
                        {
                            badImage = true;
                        }
                        else
                        {
                            goodImage = true;
                            if (used)
                            {
                                Console.WriteLine("image " + path + " used several time");
                            }
                            FileUsed[path] = true;
                        }
                    }
                    if (badImage)
                    {
                        SubSpeciesWithBadImage.Add(node);
                    }
                    if (goodImage)
                    {
                        SubSpeciesWithImage.Add(node);
                    }
                }

                List <string> unusedfiles = FileUsed.Where(p => !p.Value).Select(p => p.Key).ToList();

                string message = "Check unused image summary : \n\n";
                message += String.Format("    Total species     : {0}, {1} with images, {2} with bad images, {3} without\n", Species.Count, SpeciesWithImage.Count, SpeciesWithBadImage.Count, SpeciesWithoutImage.Count);
                message += String.Format("    Total sub/species : {0}, {1} with images, {2} with bad images, {3} without\n\n", SubSpecies.Count, SubSpeciesWithImage.Count, SubSpeciesWithBadImage.Count, SubSpeciesWithoutImage.Count);
                message += String.Format("    Total images      : {0}, {1} are unused\n\n", TotalImages, unusedfiles.Count);
                message += String.Format("for more details, look at CheckUnusedImages.log file");
                Loggers.WriteInformation(LogTags.Image, message);

                try
                {
                    string file = Path.Combine(TaxonUtils.GetLogPath(), "CheckUnusedImages.log");
                    if (File.Exists(file))
                    {
                        File.Delete(file);
                    }
                    using (StreamWriter outfile = new StreamWriter(file))
                    {
                        outfile.WriteLine("CheckUnusedImages result ( " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + " )\n");
                        outfile.WriteLine(string.Format("Unused images ( {0} ) :", unusedfiles.Count));
                        unusedfiles.ForEach(f => outfile.WriteLine(string.Format("    " + f)));
                        outfile.WriteLine("\n");

                        outfile.WriteLine(string.Format("Species without bad images ( {0} ) :", SpeciesWithBadImage.Count));
                        foreach (TaxonTreeNode node in SpeciesWithBadImage)
                        {
                            outfile.WriteLine(string.Format("    " + node.Desc.RefMultiName.Main));
                        }
                        outfile.WriteLine("\n");

                        outfile.WriteLine(string.Format("Sub/Species with bad images ( {0} ) :", SubSpeciesWithBadImage.Count));
                        foreach (TaxonTreeNode node in SubSpeciesWithBadImage)
                        {
                            outfile.WriteLine(string.Format("    " + node.Desc.RefMultiName.Main));
                        }

                        outfile.WriteLine("\n");
                    }
                }
                catch (Exception e)
                {
                    string error = "Exception while saving results in CheckUnusedImages.log: \n\n";
                    error += e.Message;
                    if (e.InnerException != null)
                    {
                        error += "\n" + e.InnerException.Message;
                    }
                    Loggers.WriteError(LogTags.Image, error);
                }
            }
        }
        public void Activate()
        {
            OpenFileDialog ofd = new OpenFileDialog
            {
                Filter       = "Species list (*.txt)|*.txt",
                Multiselect  = false,
                AddExtension = true
            };

            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            if (!File.Exists(ofd.FileName))
            {
                return;
            }

            string shortName = Path.GetFileNameWithoutExtension(ofd.FileName);

            int totalLines                   = 0;
            int ErrorNoTwoWords              = 0;
            int ErrorGenreNotFound           = 0;
            int ErrorGenreFoundMoreThanOnce  = 0;
            int WarningSpeciesAlreadyInGenre = 0;
            int NoErrors = 0;

            string logFilenameErrors = Path.Combine(TaxonUtils.GetLogPath(), "ImportSpeciesOnGenre_" + shortName + "_errors.log");

            using (StreamWriter log = new StreamWriter(logFilenameErrors))
            {
                TaxonSearch searchTool = new TaxonSearch(TaxonUtils.OriginalRoot, false, false);
                searchTool.Init((n) =>
                {
                    if (n.Desc.IsUnnamed)
                    {
                        return;
                    }
                    if (n.Desc.ClassicRank == ClassicRankEnum.Genre)
                    {
                        searchTool.Add(n.Desc.RefMultiName.Main, n);
                    }
                });

                using (StreamReader file = new StreamReader(ofd.FileName))
                {
                    string line;
                    while ((line = file.ReadLine()) != null)
                    {
                        if (string.IsNullOrWhiteSpace(line))
                        {
                            continue;
                        }
                        line = line.Trim();

                        totalLines++;

                        List <string> names = line.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList();
                        if (names.Count != 2)
                        {
                            log.WriteLine("Error, species must have two names: " + line);
                            ErrorNoTwoWords++;
                            continue;
                        }

                        List <TaxonTreeNode> searchResult = searchTool.FindAll(names[0]);

                        if (searchResult == null || searchResult.Count == 0)
                        {
                            log.WriteLine("Error, does not found genre for: " + line);
                            ErrorGenreNotFound++;
                            continue;
                        }
                        if (searchResult.Count > 1)
                        {
                            log.WriteLine("Error, more than one genre for: " + line);
                            ErrorGenreFoundMoreThanOnce++;
                            continue;
                        }

                        string        searchString = line.ToLower().Replace('-', ' ');
                        TaxonTreeNode taxonGenre   = searchResult[0];
                        bool          speciesFound = false;
                        foreach (TaxonTreeNode child in taxonGenre.Children)
                        {
                            string formated = child.Desc.RefMultiName.Main.ToLower().Replace('-', ' ');
                            if (formated == searchString)
                            {
                                speciesFound = true;
                            }
                        }

                        if (speciesFound)
                        {
                            log.WriteLine("Warning, species already exists: " + line);
                            WarningSpeciesAlreadyInGenre++;
                            continue;
                        }

                        TaxonDesc newTaxon = new TaxonDesc(line)
                        {
                            ClassicRank = ClassicRankEnum.Espece
                        };
                        taxonGenre.AddChild(new TaxonTreeNode(newTaxon));
                        NoErrors++;
                    }
                }
            }


            string message = "Importing 'species on genre' from: " + ofd.FileName + "\n";

            message += String.Format("    Total lines: {0}\n", totalLines);
            message += String.Format("    lines with species with less or more than two words : {0}\n", ErrorNoTwoWords);
            message += String.Format("    lines without associated genre : {0}\n", ErrorGenreNotFound);
            message += String.Format("    lines with more than one associated genre: {0}\n", ErrorGenreFoundMoreThanOnce);
            message += String.Format("    lines with species already in genre: {0}\n", WarningSpeciesAlreadyInGenre);
            message += String.Format("    lines with imported species: {0}\n", NoErrors);
            message += String.Format("for more details, look at ImportSpeciesOnGenre_{0}_Errors.log files", shortName);
            Loggers.WriteInformation(LogTags.Data, message);
        }
Пример #18
0
        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);
            }
        }
Пример #19
0
        public void Activate()
        {
            // retrouve la liste de toutes les especes / sous especes
            List <TaxonTreeNode> Species = new List <TaxonTreeNode>();

            TaxonUtils.OriginalRoot.GetAllChildrenRecursively(Species, ClassicRankEnum.Espece);
            List <TaxonTreeNode> SubSpecies = new List <TaxonTreeNode>();

            TaxonUtils.OriginalRoot.GetAllChildrenRecursively(SubSpecies, ClassicRankEnum.SousEspece);
            List <string> Incoherences = new List <string>();

            // et la liste des fichiers dans le répertoires de sounds
            string        PathSounds  = TaxonUtils.GetSoundDirectory();
            List <string> Files       = Directory.GetFiles(PathSounds).ToList();
            int           TotalSounds = Files.Count;

            int SpeciesWithSoundCount    = 0;
            int SpeciesWithoutSoundCount = 0;

            foreach (TaxonTreeNode node in Species)
            {
                int index = Files.IndexOf(TaxonUtils.GetSoundFullPath(node));
                if (index != -1)
                {
                    if (!node.Desc.HasSound)
                    {
                        Incoherences.Add(String.Format("taxon ({0}) has no sound flag but a sound file has been found : {1}", node.Desc.RefMultiName.Main, Files[index]));
                    }
                    SpeciesWithSoundCount++;
                    Files.RemoveAt(index);
                }
                else
                {
                    if (node.Desc.HasSound)
                    {
                        Incoherences.Add(String.Format("taxon ({0}) has sound flag but no sound file has been found", node.Desc.RefMultiName.Main));
                    }
                    SpeciesWithoutSoundCount++;
                }
            }

            int SubSpeciesWithSoundCount    = 0;
            int SubSpeciesWithoutSoundCount = 0;

            foreach (TaxonTreeNode node in SubSpecies)
            {
                int index = Files.IndexOf(TaxonUtils.GetSoundFullPath(node));
                if (index != -1)
                {
                    if (!node.Desc.HasSound)
                    {
                        Incoherences.Add(String.Format("taxon ({0}) has no sound flag but a sound file has been found : {1}", node.Desc.RefMultiName.Main, Files[index]));
                    }
                    SubSpeciesWithSoundCount++;
                    Files.RemoveAt(index);
                }
                else
                {
                    if (node.Desc.HasSound)
                    {
                        Incoherences.Add(String.Format("taxon ({0}) has sound flag but no sound file has been found", node.Desc.RefMultiName.Main));
                    }
                    SubSpeciesWithoutSoundCount++;
                }
            }

            string message = "Check unused sounds summary : \n";

            message += String.Format("    Total species     : {0}, {1} with sounds, {2} without\n", Species.Count, SpeciesWithSoundCount, SpeciesWithoutSoundCount);
            message += String.Format("    Total sub/species : {0}, {1} with sounds, {2} without\n", SubSpecies.Count, SubSpeciesWithSoundCount, SubSpeciesWithoutSoundCount);
            message += String.Format("    Total sounds      : {0}, {1} are unused\n", TotalSounds, Files.Count);
            if (Incoherences.Count > 0)
            {
                message += String.Format("!! {0} incoherences found, probably needs to UpdateSoundFlags !!!\n", Incoherences.Count);
            }
            message += String.Format("for more details, look at CheckUnusedSounds.log file");
            Loggers.WriteInformation(LogTags.Sound, message);

            try
            {
                string file = Path.Combine(TaxonUtils.GetLogPath(), "CheckUnusedSounds.log");
                if (File.Exists(file))
                {
                    File.Delete(file);
                }
                using (StreamWriter outfile = new StreamWriter(file))
                {
                    outfile.WriteLine("CheckUnusedSounds result ( " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + " )\n");
                    outfile.WriteLine(string.Format("Unused sounds ( {0} ) :", Files.Count));
                    foreach (string unusedFile in Files)
                    {
                        outfile.WriteLine(string.Format("    " + unusedFile));
                    }
                    outfile.WriteLine("\n");

                    outfile.WriteLine(string.Format("Incoherences ( {0} ) :", Incoherences.Count));
                    foreach (string line in Incoherences)
                    {
                        outfile.WriteLine("    " + line);
                    }
                    outfile.WriteLine("\n");
                }
            }
            catch (Exception e)
            {
                string error = "Exception while saving results in CheckUnusedSounds.log: \n\n";
                error += e.Message;
                if (e.InnerException != null)
                {
                    error += "\n" + e.InnerException.Message;
                }
                Loggers.WriteError(LogTags.Sound, error);
            }
        }
Пример #20
0
        public void Activate()
        {
            Task taskDeleteOldCollection             = null;
            Task taskGatherExistentSpecies           = null;
            Dictionary <string, int> existentSpecies = new Dictionary <string, int>();

            ImageCollection arkiveCollection = TaxonImages.Manager.GetByName("Arkive");

            if (arkiveCollection != null)
            {
                QuestionDialog dlg = new QuestionDialog
                                     (
                    "Arkive collection already exists !\nWhat do you want to do ?",
                    "Confirm ... ",
                    new TaxonDialog.AnswersDesc().
                    Add("Delete", "delete all content of old arkive collection", 0).
                    Add("Merge", "import only image for species newly found", 1).
                    Add("Cancel", "stop the generation of collection", 2)
                                     );
                dlg.ShowDialog();
                OneAnswerDesc answer = dlg.Answer;

                if (answer == null || answer.ID == 2)
                {
                    return;
                }

                /*string message = "Arkive collection exist, remove it ?";
                 * DialogResult result = MessageBox.Show(message, "Confirm ...", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                 * if (result == DialogResult.Cancel)
                 *  return;*/

                if (answer.ID == 0)
                {
                    taskDeleteOldCollection = Task.Factory.StartNew(() => Directory.Delete(arkiveCollection.Path, true));
                }
                else
                {
                    taskGatherExistentSpecies = Task.Factory.StartNew(() =>
                    {
                        foreach (string file in Directory.EnumerateFiles(arkiveCollection.Path))
                        {
                            string species = Path.GetFileNameWithoutExtension(file).Split('_')[0];
                            if (!existentSpecies.ContainsKey(species))
                            {
                                existentSpecies[species] = 0;
                            }
                            existentSpecies[species] = existentSpecies[species] + 1;
                        }
                    });
                }
            }

            string folderArkive;

            using (var fbd = new FolderBrowserDialog())
            {
                fbd.Description  = "Select Folder where Arkive images are stored";
                fbd.SelectedPath = TaxonUtils.GetTaxonPath();
                DialogResult result = fbd.ShowDialog();
                if (result != DialogResult.OK || string.IsNullOrWhiteSpace(fbd.SelectedPath))
                {
                    return;
                }
                folderArkive = fbd.SelectedPath;
            }

            int lengthFolderArkive = folderArkive.Length;

            using (ProgressDialog progressDlg = new ProgressDialog())
            {
                progressDlg.StartPosition = FormStartPosition.CenterScreen;
                progressDlg.Show();

                ProgressItem piInitSearch = progressDlg.Add("Initialize searching", "", 0, 2);
                TaxonSearch  searching    = new TaxonSearch(TaxonUtils.OriginalRoot, true, true);
                piInitSearch.Update(1);
                string[] foldersLevel1 = Directory.GetDirectories(folderArkive);
                piInitSearch.Update(2);
                piInitSearch.End();

                Dictionary <string, string>        unknownFolder = new Dictionary <string, string>();
                Dictionary <string, TaxonTreeNode> knownFolder   = new Dictionary <string, TaxonTreeNode>();
                int missedPhotos          = 0;
                int importedPhotos        = 0;
                int alreadyImportedPhotos = 0;
                int newlyImportedPhotos   = 0;

                ProgressItem piParse = progressDlg.Add("Parse arkive folders", "", 0, foldersLevel1.Length);
                for (uint i = 0; i < foldersLevel1.Length; i++)
                {
                    piParse.Update(i, foldersLevel1[i].Substring(lengthFolderArkive + 1));
                    int folder1Length = foldersLevel1[i].Length + 1;

                    string[] foldersLevel2 = Directory.GetDirectories(foldersLevel1[i]);
                    foreach (string folder2 in foldersLevel2)
                    {
                        //if (folder2.ToLower().Contains("acropora"))
                        //    Console.WriteLine(folder2);

                        string[] photos = Directory.GetFiles(folder2, "*.jpg");
                        if (photos.Length == 0)
                        {
                            continue;
                        }

                        string        name = folder2.Substring(folder1Length).Replace('-', ' ').ToLower().Trim();
                        TaxonTreeNode node = searching.FindOne(name);
                        if (node == null)
                        {
                            unknownFolder[folder2] = name;
                            missedPhotos          += photos.Length;
                        }
                        else
                        {
                            knownFolder[folder2] = node;
                        }
                    }
                }
                piParse.Update(piParse.Max, knownFolder.Count.ToString() + " found, " + unknownFolder.Count.ToString() + " not.");

                if (taskDeleteOldCollection != null && !taskDeleteOldCollection.IsCompleted)
                {
                    ProgressItem piClean = progressDlg.Add("Clean old collection", "", 0, 1);
                    taskDeleteOldCollection.Wait();
                    piClean.Update(1);
                    piClean.End();
                }

                if (taskGatherExistentSpecies != null && !taskGatherExistentSpecies.IsCompleted)
                {
                    ProgressItem piAnalyseOld = progressDlg.Add("Analyse old collection", "", 0, 1);
                    taskGatherExistentSpecies.Wait();
                    piAnalyseOld.Update(1);
                    piAnalyseOld.End();
                }

                arkiveCollection = TaxonImages.Manager.GetOrCreateCollection("Arkive");
                if (arkiveCollection == null)
                {
                    return;
                }
                arkiveCollection.Desc  = "Collection generated from images taken from Arkive site : http://www.arkive.org";
                arkiveCollection.Desc += "Generated date : " + DateTime.Now.ToString();
                arkiveCollection.SaveInfos();
                ProgressItem piPopulate = progressDlg.Add("Populate collection", "", 0, knownFolder.Count);
                foreach (KeyValuePair <string, TaxonTreeNode> pair in knownFolder)
                {
                    string speciesName = pair.Value.Desc.RefMultiName.Main;
                    piPopulate.Update(piPopulate.Current + 1, speciesName);

                    string[] photos = Directory.GetFiles(pair.Key, "*.jpg");
                    importedPhotos += photos.Length;

                    if (existentSpecies.ContainsKey(speciesName))
                    {
                        if (existentSpecies[speciesName] == photos.Length)
                        {
                            alreadyImportedPhotos += photos.Length;
                            continue;
                        }
                        File.Delete(arkiveCollection.Path + Path.DirectorySeparatorChar + speciesName + "*.*");
                    }

                    newlyImportedPhotos += photos.Length;

                    for (int index = 0; index < photos.Length; index++)
                    {
                        string newName = speciesName + "_" + index.ToString() + ".jpg";
                        File.Copy(photos[index], arkiveCollection.Path + Path.DirectorySeparatorChar + newName);
                    }
                }
                piPopulate.Update(piPopulate.Max, importedPhotos.ToString() + " photos imported.");

                string message0 = (unknownFolder.Count + knownFolder.Count).ToString() + " total folders found\n";
                string message1 = knownFolder.Count.ToString() + " with associated taxons ( " + importedPhotos.ToString() + " photos imported )";
                if (newlyImportedPhotos != importedPhotos)
                {
                    message1 += " ( merging : " + newlyImportedPhotos + " new photos";
                }
                string message2 = unknownFolder.Count.ToString() + " names not found ( " + missedPhotos.ToString() + " photos left behind )";
                string message  = message0 + "\n" + message1 + "\n" + message2 + "\n\n" + "for more details, look at GenerateArkiveCollection.log file";
                if (unknownFolder.Count > 0)
                {
                    message += "\nA list of taxons is generated with all name not found : " + Path.Combine(TaxonList.GetFolder(), "ArkiveNames.txt");
                }
                Loggers.WriteInformation(LogTags.Data, message);

                try
                {
                    List <KeyValuePair <string, string> > unknowns = unknownFolder.ToList();
                    unknowns.Sort((x, y) => x.Value.CompareTo(y.Value));

                    string file = Path.Combine(TaxonUtils.GetLogPath(), "GenerateArkiveCollection.log");
                    if (File.Exists(file))
                    {
                        File.Delete(file);
                    }
                    using (StreamWriter outfile = new StreamWriter(file))
                    {
                        outfile.WriteLine("GenerateArkiveCollection results:");
                        outfile.WriteLine();
                        outfile.WriteLine("  " + message0);
                        outfile.WriteLine("  " + message1);
                        outfile.WriteLine("  " + message2);
                        outfile.WriteLine();
                        if (unknowns.Count > 0)
                        {
                            outfile.WriteLine("List of not found names:");
                            outfile.WriteLine();

                            int maxLength = 0;
                            foreach (KeyValuePair <string, string> pair in unknowns)
                            {
                                maxLength = Math.Max(maxLength, pair.Value.Length);
                            }
                            foreach (KeyValuePair <string, string> pair in unknowns)
                            {
                                outfile.WriteLine("  " + pair.Value.PadRight(maxLength) + " => " + pair.Key);
                            }
                            outfile.WriteLine();
                        }
                    }

                    if (unknowns.Count > 0)
                    {
                        file = Path.Combine(TaxonList.GetFolder(), "ArkiveNames.txt");
                        if (File.Exists(file))
                        {
                            File.Delete(file);
                        }
                        using (StreamWriter outfile = new StreamWriter(file))
                        {
                            foreach (KeyValuePair <string, string> pair in unknowns)
                            {
                                outfile.WriteLine(pair.Value);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    string error = "Exception while saving results in GenerateArkiveCollection.log: \n\n";
                    error += e.Message;
                    if (e.InnerException != null)
                    {
                        error += "\n" + e.InnerException.Message;
                    }
                    Loggers.WriteError(LogTags.Data, error);
                }
            }
        }
Пример #21
0
        public void Activate()
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter       = "txt files (*.txt)|*.txt";
            ofd.Multiselect  = false;
            ofd.AddExtension = true;
            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            if (!File.Exists(ofd.FileName))
            {
                return;
            }

            List <string> notFound = new List <string>();
            List <Tuple <string, TaxonTreeNode> > found = new List <Tuple <string, TaxonTreeNode> >();

            string shortName = Path.GetFileNameWithoutExtension(ofd.FileName);

            int totalLines          = 0;
            int lineWithOnlyOneName = 0;
            int lineWithNoTaxon     = 0;
            int nameExistsAlready   = 0;
            int nameAdded           = 0;
            int changedTaxon        = 0;
            Dictionary <TaxonTreeNode, string> infoImport = new Dictionary <TaxonTreeNode, string>();

            string logFilenameErrors = Path.Combine(TaxonUtils.GetLogPath(), "ImportFrenchNames_" + shortName + "_errors.log");

            using (StreamWriter log = new StreamWriter(logFilenameErrors))
            {
                TaxonSearch searchTool = new TaxonSearch(TaxonUtils.OriginalRoot, true, true);
                using (StreamReader file = new StreamReader(ofd.FileName))
                {
                    string line;
                    while ((line = file.ReadLine()) != null)
                    {
                        if (string.IsNullOrWhiteSpace(line))
                        {
                            continue;
                        }

                        totalLines++;

                        List <string> names = line.Split(Helpers.MultiName.SeparatorAsCharArray, StringSplitOptions.RemoveEmptyEntries).ToList();
                        if (names.Count == 1)
                        {
                            log.WriteLine("Error, only one name in line: " + line);
                            lineWithOnlyOneName++;
                            continue;
                        }

                        string latin = names[0];
                        names.RemoveAt(0);

                        TaxonTreeNode node = TaxonUtils.OriginalRoot.FindTaxonByFullName(latin);
                        if (node == null)
                        {
                            int idx = latin.LastIndexOf(TaxonTreeNode.HierarchicalNameSeparator);
                            if (idx != -1)
                            {
                                latin = latin.Substring(idx + 1);
                            }
                            List <TaxonTreeNode> nodes = searchTool.FindAll(latin);
                            if (nodes != null)
                            {
                                if (nodes.Count > 1)
                                {
                                    log.WriteLine("Error, two many nodes fit with that line: " + line);
                                    lineWithNoTaxon++;
                                    continue;
                                }
                                if (nodes.Count == 1)
                                {
                                    node = nodes[0];
                                }
                            }
                        }

                        if (node == null)
                        {
                            log.WriteLine("Error, no matching nodes found for that line: " + line);
                            lineWithNoTaxon++;
                            continue;
                        }

                        List <string> previousNames = null;
                        if (node.Desc.FrenchMultiName == null)
                        {
                            previousNames = new List <string>();
                        }
                        else
                        {
                            previousNames = node.Desc.FrenchMultiName.Full.Split(Helpers.MultiName.SeparatorAsCharArray, StringSplitOptions.RemoveEmptyEntries).ToList();
                        }
                        List <string> previousNamesTest = previousNames.Select(n => n.Trim().ToLower()).ToList();

                        List <string> infos             = new List <string>();
                        int           previousNameAdded = nameAdded;
                        foreach (string name in names)
                        {
                            string testname = name.ToLower().Trim();
                            if (previousNamesTest.IndexOf(testname) != -1)
                            {
                                nameExistsAlready++;
                                infos.Add(name + " exists");
                                continue;
                            }
                            nameAdded++;
                            infos.Add(name + " added");
                            previousNames.Add(name);
                            previousNamesTest.Add(testname);
                        }
                        infoImport[node] = string.Join(", ", infos);
                        if (previousNameAdded == nameAdded)
                        {
                            continue;
                        }
                        changedTaxon++;
                        node.Desc.FrenchMultiName = new Helpers.MultiName(previousNames);
                    }
                }
            }

            string logFilenameFirst = Path.Combine(TaxonUtils.GetLogPath(), "ImportFrenchNames_" + shortName + "_infos.log");

            using (StreamWriter log = new StreamWriter(logFilenameFirst))
            {
                foreach (KeyValuePair <TaxonTreeNode, string> pair in infoImport)
                {
                    log.WriteLine(pair.Key.Desc.Name + " => " + pair.Value);
                }
            }

            string message = "Importing french names from: " + ofd.FileName + "\n";

            message += String.Format("    Total lines: {0}\n", totalLines);
            message += String.Format("    lines with only one name: {0}\n", lineWithOnlyOneName);
            message += String.Format("    lines with no associated taxons: {0}\n", lineWithNoTaxon);
            message += String.Format("    associated taxon found: {0}\n", infoImport.Count);
            message += String.Format("    changed taxons: {0}\n", changedTaxon);
            message += String.Format("    french names already there: {0}\n", nameExistsAlready);
            message += String.Format("    imported french names: {0}\n", nameAdded);
            message += String.Format("for more details, look at ImportFrenchNames_{0}_*.log files", shortName);
            Loggers.WriteInformation(LogTags.Data, message);
        }
Пример #22
0
        public void Activate()
        {
            using (ProgressDialog progressDlg = new ProgressDialog())
            {
                progressDlg.StartPosition = FormStartPosition.CenterScreen;
                progressDlg.Show();

                ProgressItem piPrepare = progressDlg.Add("Prepare ...", "get taxon with images", 0, 2);
                // retrouve la liste de toutes les especes / sous especes
                List <TaxonDesc> Nodes = new List <TaxonDesc>();
                TaxonUtils.OriginalRoot.ParseNodeDesc((d) => { if (d.HasImage)
                                                               {
                                                                   Nodes.Add(d);
                                                               }
                                                      });
                piPrepare.Update(1, "all images name (can be long)");
                // et la liste des fichiers dans le répertoires d'images
                string PathImages  = TaxonImages.Manager.Path;
                int    TotalImages = 0;
                Dictionary <string, bool> FileUsed = new Dictionary <string, bool>();
                Directory.GetFiles(PathImages, "*.jpg", SearchOption.AllDirectories).ToList().ForEach(f => { FileUsed[f.ToLower()] = false; TotalImages++; });
                piPrepare.Update(2, "init done");

                ProgressItem piTaxonDesc = progressDlg.Add("Parse Taxon with images ...", "", 0, Nodes.Count);
                int          count       = 0;
                foreach (TaxonDesc desc in Nodes)
                {
                    piTaxonDesc.Update(++count);
                    foreach (TaxonImageDesc imageDesc in desc.Images)
                    {
                        if (imageDesc.IsALink)
                        {
                            continue;
                        }
                        string path = imageDesc.GetPath(desc).ToLower();
                        if (FileUsed.ContainsKey(path))
                        {
                            FileUsed[path] = true;
                        }
                    }
                }

                List <string> unusedfiles = FileUsed.Where(p => !p.Value).Select(p => p.Key).ToList();
                ProgressItem  piFinder    = progressDlg.Add("Init finder...", "", 0, 1);
                TaxonSearch   finder      = new TaxonSearch(TaxonUtils.OriginalRoot, true, true);
                piFinder.Update(1);

                int noTaxonFound       = 0;
                int severalTaxonFound  = 0;
                int renamedFiles       = 0;
                int sameName           = 0;
                int errorWhileRenaming = 0;

                string logfile = Path.Combine(TaxonUtils.GetLogPath(), "ImageRenameSynonyms.log");
                if (File.Exists(logfile))
                {
                    File.Delete(logfile);
                }
                using (StreamWriter log = new StreamWriter(logfile))
                {
                    ProgressItem piUnused = progressDlg.Add("Treat unused images ...", "", 0, unusedfiles.Count);
                    foreach (string filename in unusedfiles)
                    {
                        piUnused.Inc();
                        TaxonImages.SplitImageFilenameResult splitResult = TaxonImages.Manager.SplitImageFilename(filename);
                        if (splitResult == null)
                        {
                            continue;
                        }

                        List <TaxonTreeNode> nodes = finder.FindAll(splitResult.TaxonName);
                        string textline            = "[" + (nodes == null ? 0 : nodes.Count) + "] " + splitResult.TaxonName + ": ";
                        if (nodes == null || nodes.Count == 0)
                        {
                            noTaxonFound++;
                            textline += "no taxon found";
                        }
                        else if (nodes.Count > 1)
                        {
                            severalTaxonFound++;
                            textline += "too many taxons found";
                        }
                        else if (filename.ToLower() == splitResult.Desc.GetPath(nodes[0].Desc).ToLower())
                        {
                            sameName++;
                            textline += "same name, probably unused due to rank";
                        }
                        else
                        {
                            TaxonTreeNode  node = nodes[0];
                            TaxonImageDesc desc = splitResult.Desc;
                            desc.FillForNewFile(node.Desc);
                            string newFilename = desc.GetPath(node.Desc);
                            textline += " rename " + System.IO.Path.GetFileName(filename) + " in " + System.IO.Path.GetFileName(newFilename);
                            try
                            {
                                System.IO.File.Move(filename, newFilename);
                                renamedFiles++;
                            }
                            catch (System.Exception e)
                            {
                                textline += "[error] " + e.Message;
                                errorWhileRenaming++;
                            }
                        }
                        log.WriteLine(textline);
                    }
                }

                string message = "Rename unused file using synonyms name : \n\n";
                message += String.Format("    Total treated files: {0}\n", unusedfiles.Count);
                message += String.Format("    No match: {0}\n", noTaxonFound);
                message += String.Format("    Several matches: {0}\n", severalTaxonFound);
                message += String.Format("    New name is same as unused: {0}\n", sameName);
                message += String.Format("    Renamed files: {0}\n", renamedFiles);
                message += String.Format("    Error renaming: {0}\n", errorWhileRenaming);
                message += String.Format("Same renaming occurs, do not forget to update images\n");
                message += String.Format("for more details, look at ImageRenameSynonyms.log file");
                Loggers.WriteInformation(LogTags.Image, message);
            }
        }