コード例 #1
0
        private async Task _deleteTaxonAsync(Taxon[] taxa)
        {
            // Ensure that the user has necessary privileges to use this command.
            if (!await BotUtils.ReplyHasPrivilegeAsync(Context, PrivilegeLevel.ServerModerator))
            {
                return;
            }

            if (await BotUtils.ReplyAsync_ValidateTaxa(Context, taxa))
            {
                if ((await TaxonUtils.GetSpeciesAsync(taxa[0])).Count() > 0)
                {
                    // If the taxon still has species underneath of it, don't allow it to be deleted.
                    await BotUtils.ReplyAsync_Error(Context, "Taxa containing species cannot be deleted.");
                }
                else
                {
                    // The taxon is empty, so delete the taxon.

                    await TaxonUtils.DeleteTaxonAsync(taxa[0]);

                    await BotUtils.ReplyAsync_Success(Context, string.Format("{0} **{1}** was successfully deleted.", StringUtils.ToTitleCase(taxa[0].GetTypeName()), taxa[0].GetName()));
                }
            }
        }
コード例 #2
0
        static Manager()
        {
            if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
            {
                return;
            }
            string path = TaxonUtils.GetConfigFilePath();

            if (Directory.Exists(path))
            {
                string[] files  = Directory.GetFiles(path);
                string   prefix = Path.GetFileNameWithoutExtension(TaxonUtils.GetConfigFileName("language_")).ToLower();
                foreach (string f in files)
                {
                    string fname = Path.GetFileNameWithoutExtension(f).ToLower();
                    if (fname.StartsWith(prefix))
                    {
                        fname = fname.Replace(prefix, "");
                        if (fname.Length == 2)
                        {
                            Languages.Add(fname);
                        }
                    }
                }
            }
            Languages.Load();
            Languages.Save();
            CurrentLanguage = Languages.GetDefault();
            IsDirty         = false;
            StartWatcher();
        }
コード例 #3
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);
        }
コード例 #4
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);
            }
        }
コード例 #5
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);
        }
コード例 #6
0
 void ExportSounds(TaxonDesc desc, ExportData _data)
 {
     _data.ProgressItem.Update(_data.ProgressItem.Current + 1);
     if (desc.HasSound)
     {
         CopyFile(TaxonUtils.GetSoundFullPath(desc), true, _data);
     }
 }
コード例 #7
0
        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);
            }
        }
コード例 #8
0
        private void OnSelectAndSetAsNewRoot(object sender, EventArgs e)
        {
            TaxonTreeNode selected = GetSelected();

            TaxonUtils.CleanSubRoots();
            TaxonUtils.PushSubRoot(selected);
            TaxonUtils.GotoTaxon(selected);
            TaxonUtils.SelectTaxon(selected);
        }
コード例 #9
0
ファイル: _WorkCheck.cs プロジェクト: karimsqualli/treeoflife
        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);
            }
        }
コード例 #10
0
 private static void StartWatcher()
 {
     _Watcher                       = new FileSystemWatcher();
     _Watcher.Path                  = TaxonUtils.GetConfigFilePath();
     _Watcher.NotifyFilter          = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
     _Watcher.Filter                = "*.xml";
     _Watcher.IncludeSubdirectories = false;
     _Watcher.Changed              += new FileSystemEventHandler(OnChanged);
     _Watcher.EnableRaisingEvents   = true;
 }
コード例 #11
0
 public void ScriptCall(string _name, int _index)
 {
     if (_index >= 0 && _index < Owner._HtmlDivs.Count)
     {
         TaxonTreeNode node = Owner._HtmlDivs[_index].Taxon;
         if (node != null && _name == node.Desc.RefMainName)
         {
             TaxonUtils.GotoTaxon(node);
         }
     }
 }
コード例 #12
0
        private async Task _deleteTaxonAsync(string name, TaxonRank rank)
        {
            // Ensure that the user has necessary privileges to use this command.
            if (!await BotUtils.ReplyHasPrivilegeAsync(Context, PrivilegeLevel.ServerModerator))
            {
                return;
            }

            Taxon[] taxa = await TaxonUtils.GetTaxaAsync(name, rank);

            await _deleteTaxonAsync(taxa);
        }
コード例 #13
0
        private bool CheckFolder()
        {
            string folder = BuildFolder();

            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }
            DirectoryInfo dir1 = new DirectoryInfo(folder);
            DirectoryInfo dir0 = new DirectoryInfo(TaxonUtils.GetTaxonPath());

            return(dir0.FullName.ToLower() != dir1.FullName.ToLower());
        }
コード例 #14
0
        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);
            }
        }
コード例 #15
0
 private void buttonBrowse_Click(object sender, EventArgs e)
 {
     using (var fbd = new FolderBrowserDialog())
     {
         fbd.Description  = "Select Folder where new database will be saved";
         fbd.SelectedPath = TaxonUtils.GetTaxonPath();
         DialogResult result = fbd.ShowDialog();
         if (result != DialogResult.OK || string.IsNullOrWhiteSpace(fbd.SelectedPath))
         {
             return;
         }
         labelFolder.Text = fbd.SelectedPath;
     }
 }
コード例 #16
0
        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());
                }
            }
        }
コード例 #17
0
        //=========================================================================================
        // Export / Import
        //

        public static void ExportAllLanguages()
        {
            Dictionary <Language, Dictionary <string, string> > allText = new Dictionary <Language, Dictionary <string, string> >();

            foreach (var lang in Languages.GetAvailableLanguages())
            {
                Dictionary <string, string> result = LoadLanguage(lang.Iso);
                if (result != null)
                {
                    allText[lang] = result;
                }
            }

            // get all keys
            Dictionary <string, bool> allKeys = new Dictionary <string, bool>();

            foreach (var perLang in allText)
            {
                foreach (string key in perLang.Value.Keys)
                {
                    allKeys[key] = true;
                }
            }
            List <string> listKeys = allKeys.Keys.ToList();

            listKeys.Sort();

            string exportFile = Path.Combine(TaxonUtils.GetConfigFilePath(), "AllTexts.csv");

            using (TextWriter writer = new StreamWriter(exportFile))
            {
                string headerLine = "Key;" + string.Join(";", allText.Keys);
                writer.WriteLine(headerLine);

                foreach (string key in listKeys)
                {
                    string line = key;
                    foreach (var dico in allText.Values)
                    {
                        line += ";";
                        if (dico.TryGetValue(key, out string value))
                        {
                            line += value;
                        }
                    }
                    writer.WriteLine(line);
                }
            }
        }
コード例 #18
0
 public GenerateNewDatabaseDialog(TaxonTreeNode _taxon, GenerateNewDatabaseConfig _config)
 {
     InitializeComponent();
     _Taxon  = _taxon;
     _Config = _config;
     if (_Taxon == null)
     {
         return;
     }
     labelTaxon.Text = _Taxon.Desc.RefMainName;
     labelTaxon.Tag  = new Localization.Tag {
         Ignore = true
     };
     labelFolder.Text = Path.Combine(TaxonUtils.GetTaxonPath(), "NewDatas");
     ApplyConfig();
 }
コード例 #19
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);
        }
コード例 #20
0
        //--------------------------------------------------------------------------------------
        protected override void OnMouseDoubleClick(MouseEventArgs e)
        {
            if (MouseDoubleClickMode == MouseDoubleClickModeEnum.DoNothing)
            {
                return;
            }
            if (GetSelected() == null)
            {
                return;
            }

            TaxonUtils.GotoTaxon(GetSelected());
            if (MouseDoubleClickMode == MouseDoubleClickModeEnum.SelectTaxon)
            {
                TaxonUtils.SelectTaxon(GetSelected());
            }
        }
コード例 #21
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);
            }
        }
コード例 #22
0
        private void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;

            bool success = dataSettingsControl1.updateData();

            if (success)
            {
                TaxonUtils.initCollections();
                TaxonUtils.OriginalRoot.UpdateAvailableImages();
                TaxonControlList.OnAvailableImagesChanged();
                Close();
            }
            else
            {
                button1.Enabled = true;
            }
        }
コード例 #23
0
        //--------------------------------------------------------------------------------------
        void ContextMenuStrip_Opening(object sender, System.ComponentModel.CancelEventArgs e)
        {
            ContextMenuStrip.Items.Clear();
            ToolStripMenuItem menuItem;

            TaxonTreeNode taxon = GetSelected();

            if (taxon != null)
            {
                menuItem = new ToolStripMenuItem(Localization.Manager.Get("_GotoTaxon", "Goto {0}", taxon.Desc.RefMainName), null, new System.EventHandler(OnGoto));
                ContextMenuStrip.Items.Add(menuItem);
                menuItem = new ToolStripMenuItem(Localization.Manager.Get("_SelectTaxon", "Select {0}", taxon.Desc.RefMainName), null, new System.EventHandler(OnSelect));
                ContextMenuStrip.Items.Add(menuItem);
                menuItem = new ToolStripMenuItem(Localization.Manager.Get("_SelectTaxonAndSetAsNewRoot", "Select and set as new root {0}", taxon.Desc.RefMainName), null, new System.EventHandler(OnSelectAndSetAsNewRoot));
                ContextMenuStrip.Items.Add(menuItem);

                menuItem = TaxonUtils.FavoritesMenuItem(taxon);
                if (menuItem != null)
                {
                    ContextMenuStrip.Items.Add(new ToolStripSeparator());
                    ContextMenuStrip.Items.Add(menuItem);
                }
            }

            if (CanBeSorted)
            {
                List <TaxonTreeNode> list = DataSource as List <TaxonTreeNode>;
                if (list.Count > 1)
                {
                    if (ContextMenuStrip.Items.Count > 0)
                    {
                        ContextMenuStrip.Items.Add(new ToolStripSeparator());
                    }
                    menuItem = new ToolStripMenuItem(Localization.Manager.Get("_Sort", "Sort"));
                    menuItem.DropDownItems.Add(Localization.Manager.Get("_SortAlpha", "Alpha"), null, new System.EventHandler(OnSort));
                    menuItem.DropDownItems.Add(Localization.Manager.Get("_SortReverseAlpha", "Reverse Alpha"), null, new System.EventHandler(OnSort));
                    menuItem.DropDownItems.Add(Localization.Manager.Get("_SortTree", "Tree"), null, new System.EventHandler(OnSort));
                    menuItem.DropDownItems.Add(Localization.Manager.Get("_SortReverseTree", "Reverse Tree"), null, new System.EventHandler(OnSort));
                    ContextMenuStrip.Items.Add(menuItem);
                }
            }

            e.Cancel = ContextMenuStrip.Items.Count == 0;
        }
コード例 #24
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);
            }
        }
コード例 #25
0
        string BuildFranceMap(string _name)
        {
            if (TaxonUtils.Locations == null || _Current == null)
            {
                return("");
            }
            TaxonTreeNode original = _Current.GetOriginal();

            if (original == null || !TaxonUtils.Locations.LocationByTaxon.TryGetValue(original, out string Ids))
            {
                return("");
            }
            France.Map map = new France.Map();
            foreach (string id in Ids.Split("|".ToCharArray()))
            {
                map.SetTheme(id, "on");
            }

            _MapFileCount = (_MapFileCount + 1) % 100;
            string file = "comment_france_map" + _MapFileCount.ToString("D3") + ".jpg";
            string path = Path.Combine(TaxonUtils.GetTempPath(), file);

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

            map.CreateTexture(path, 0.6f);

            int count = 0;

            while (!File.Exists(path) && ++count < 4)
            {
                System.Threading.Thread.Sleep(500);
            }

            string result = "";

            result += "<p><img src=\"" + path + "\" xmlns = \"\" /></p>";
            return(result);
        }
コード例 #26
0
        public static void ImportAllLanguages()
        {
            Regex isoRegex = new Regex("\\((.*)\\)");

            using (TextReader reader = new StreamReader(Path.Combine(TaxonUtils.GetConfigFilePath(), "AllTexts.csv")))
            {
                // reade head line
                string line = reader.ReadLine();
                if (line == null)
                {
                    return;
                }
                string[] parts      = line.Split(';');
                int      numColumns = parts.Length;
                if (numColumns <= 1)
                {
                    return;
                }
                if (parts[0].Trim().ToLower() != "key")
                {
                    return;
                }

                List <Tuple <Language, Dictionary <string, string> > > allText = new List <Tuple <Language, Dictionary <string, string> > >();
                for (int i = 1; i < numColumns; i++)
                {
                    Match isoMatch = isoRegex.Match(parts[i]);
                    if (!isoMatch.Success || isoMatch.Groups.Count < 2)
                    {
                        return;
                    }
                    string   iso  = isoMatch.Groups[1].Value;
                    Language lang = Languages.Get(iso, true);
                    allText.Add(new Tuple <Language, Dictionary <string, string> >(lang, new Dictionary <string, string>()));
                }

                Dictionary <string, bool> keyDone = new Dictionary <string, bool>();
                while ((line = reader.ReadLine()) != null)
                {
                    parts = line.Split(';');
                    if (parts.Length != numColumns)
                    {
                        continue;
                    }
                    if (keyDone.ContainsKey(parts[0]))
                    {
                        continue;
                    }
                    keyDone[parts[0]] = true;
                    for (int i = 1; i < numColumns; i++)
                    {
                        if (!String.IsNullOrEmpty(parts[i]))
                        {
                            allText[i - 1].Item2[parts[0]] = parts[i];
                        }
                    }
                }

                foreach (var data in allText)
                {
                    SaveLanguage(data.Item1.Iso, data.Item2);
                }
            }
        }
コード例 #27
0
        public bool Build(ContextMenuStrip _menu)
        {
            if (Taxon == null)
            {
                return(false);
            }

            ToolStripMenuItem menuItem;

            // goto
            menuItem = new ToolStripMenuItem(
                Localization.Manager.Get("_GotoTaxon", "Goto {0}", Taxon.Desc.RefMainName),
                null, new System.EventHandler(OnGoto))
            {
                Tag = Taxon
            };
            _menu.Items.Add(menuItem);

            // select
            if (TaxonUtils.SelectedTaxon() != Taxon)
            {
                menuItem = new ToolStripMenuItem(
                    Localization.Manager.Get("_SelectTaxon", "Select {0}", Taxon.Desc.RefMainName),
                    null, new System.EventHandler(OnSelect))
                {
                    Tag = Taxon
                };
                _menu.Items.Add(menuItem);
            }

            // ascendants
            List <TaxonTreeNode> Ascendants = new List <TaxonTreeNode>();

            Taxon.GetAllParents(Ascendants, false, false, false);
            if (Ascendants.Count > 0)
            {
                menuItem = new ToolStripMenuItem(Localization.Manager.Get("_SelectAscendant", "Select ascendant"));
                _menu.Items.Add(menuItem);
                foreach (TaxonTreeNode node in Ascendants)
                {
                    ToolStripMenuItem subMenuItem = new ToolStripMenuItem(
                        node.Desc.RefMainName, null, new System.EventHandler(OnSelect))
                    {
                        Tag = node
                    };
                    menuItem.DropDownItems.Add(subMenuItem);
                }
            }

            // add open image if ImagePath has been setup
            string imagePath = ImageDesc?.GetPath(Taxon.Desc);

            if (imagePath != null)
            {
                _menu.Items.Add(new ToolStripSeparator());

                menuItem = new ToolStripMenuItem(
                    Localization.Manager.Get("_OpenImage", "Open image {0}", imagePath),
                    null, new EventHandler(OnOpenImage))
                {
                    Tag = imagePath
                };
                _menu.Items.Add(menuItem);

                menuItem = new ToolStripMenuItem(
                    Localization.Manager.Get("_LocateImage", "Locate image in explorer"),
                    null, new EventHandler(OnLocateImage))
                {
                    Tag = imagePath
                };
                _menu.Items.Add(menuItem);
            }

            // add favorite menu
            menuItem = TaxonUtils.FavoritesMenuItem(Taxon);
            if (menuItem != null)
            {
                _menu.Items.Add(new ToolStripSeparator());
                _menu.Items.Add(menuItem);
            }

            menuItem = BuildAdvanced();
            if (menuItem != null)
            {
                _menu.Items.Add(new ToolStripSeparator());
                _menu.Items.Add(menuItem);
            }

            return(true);
        }
コード例 #28
0
 private void OnSelect(object sender, EventArgs e)
 {
     TaxonUtils.GotoTaxon(GetTag <TaxonTreeNode>(sender));
     TaxonUtils.SelectTaxon(GetTag <TaxonTreeNode>(sender));
 }
コード例 #29
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);
        }
コード例 #30
0
        public async Task DeleteTaxon(string name)
        {
            Taxon[] taxa = await TaxonUtils.GetTaxaAsync(name);

            await _deleteTaxonAsync(taxa);
        }