protected override void OnStart(string[] args)
        {
            try
            {
                string sourceDirectoryPath    = ConfigurationManager.AppSettings["SourceDirectoryPath"];
                string targetDirectoryPath    = ConfigurationManager.AppSettings["TargetDirectoryPath"];
                string synchronisationMethode = ConfigurationManager.AppSettings["SynchronisationMethode"];

                Loggers.WriteInformation($"Démarrage du service");
                Loggers.WriteInformation($"Dossier source = {sourceDirectoryPath}");
                Loggers.WriteInformation($"Dossier cible = {targetDirectoryPath}");

                _Service = new SynchronisationService(sourceDirectoryPath, targetDirectoryPath, synchronisationMethode);

                _Service.Start();
            }
            catch (Exception ex)
            {
                Loggers.WriteError(ex.ToString());
                // On relance l'exception pour que le gestionnaire de service ne finalise pas le démarrage du service.
                throw new Exception("Erreur au démarrage du service.", ex);
            }
        }
Exemplo n.º 2
0
 private void buttonAddNew_Click(object sender, EventArgs e)
 {
     try
     {
         if (tabControlCollections.SelectedTab == tabPageImages)
         {
             string path = TaxonImages.Manager.Path + "//" + textBoxNew.Text;
             System.IO.Directory.CreateDirectory(path);
             FillCollectionsImages();
         }
         if (tabControlCollections.SelectedTab == tabPageComments)
         {
             string path = TaxonComments.Manager.Path + "//" + textBoxNew.Text;
             System.IO.Directory.CreateDirectory(path);
             FillCollectionsComments();
         }
     }
     catch (Exception ex)
     {
         string message = "Cannot create new collection " + textBoxNew.Text + "\n\n";
         message += "Exception: " + ex.Message;
         Loggers.WriteError(LogTags.Collection, message);
     }
 }
Exemplo n.º 3
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);
                }
            }
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
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);
                }
            }
        }
Exemplo n.º 7
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);
            }
        }