コード例 #1
0
        public static void CreateFromDirectory(TaxonTreeNode _root, string path)
        {
            TaxonSearch searchTool    = new TaxonSearch(_root, true, true);
            int         countFound    = 0;
            int         countNotFound = 0;

            string[] files = Directory.GetFiles(path, "*.txt");

            string logFilename = Path.Combine(TaxonUtils.GetTaxonLocationPath(), "CreateFromDirectory.log");

            using (StreamWriter log = new StreamWriter(logFilename))
            {
                using (ProgressDialog progressDlg = new ProgressDialog())
                {
                    progressDlg.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
                    progressDlg.Show();

                    ProgressItem parseFiles = progressDlg.Add("parseFiles", "", 0, files.Length);
                    foreach (string file in files)
                    {
                        parseFiles.Inc(file);
                        log.WriteLine("Import " + file + ":");
                        France.Departement dep = France.Data.Departements.GetDepartementFromName(Path.GetFileNameWithoutExtension(file));
                        if (dep == null)
                        {
                            log.WriteLine("  associated departement not found");
                            continue;
                        }

                        TaxonList.ImportFileResult resultImport = TaxonList.ImportFile(file, searchTool);
                        log.WriteLine("  " + resultImport.TaxonsFound + " taxons found");
                        log.WriteLine("  " + resultImport.TaxonNotFound + " taxons not found");

                        countFound    += resultImport.TaxonsFound;
                        countNotFound += resultImport.TaxonNotFound;

                        TaxonList taxons = new TaxonList();
                        taxons.FromTaxonTreeNodeList(resultImport.List);
                        taxons.HasFile  = true;
                        taxons.FileName = Path.Combine(TaxonUtils.GetTaxonLocationPath(), dep.Id + ".xml");
                        taxons.Save();
                    }
                }
            }

            string message = "Create location data from directory " + path + ": \n";

            message += String.Format("    taxons found: {0}\n", countFound);
            message += String.Format("    taxons not found: {0}\n", countNotFound);
            message += String.Format("for more details, look at " + logFilename + " file, and all other generated logs");
            Loggers.WriteInformation(LogTags.Location, message);
        }
コード例 #2
0
        public TagBatchImportDialog()
        {
            InitializeComponent();
            textBoxSource.Text      = TaxonUtils.MyConfig.Options.TagBatchImportSourceFolder;
            textBoxDestination.Text = TaxonUtils.MyConfig.Options.TagBatchImportDestinationFolder;
            switch (TaxonUtils.MyConfig.Options.TagBatchImportOverwrite)
            {
            case "always": radioButtonOverwrite.Checked = true; break;

            case "never": radioButtonLeaveIt.Checked = true; break;
            }

            Task.Factory.StartNew(() =>
            {
                _Searchtool = new TaxonSearch(TaxonUtils.OriginalRoot, true, true);
                Console.WriteLine("_Searchtool completed");
            });
        }
コード例 #3
0
ファイル: TaxonList.cs プロジェクト: karimsqualli/treeoflife
        public static ImportFileResult ImportFile(string _filename, TaxonSearch _searchTool, bool _logFoundTaxon = true)
        {
            ImportFileResult result = new ImportFileResult();

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

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

                    TaxonTreeNode node = _searchTool.FindOne(line);
                    if (node == null)
                    {
                        notFound.Add(line);
                    }
                    else
                    {
                        found.Add(new Tuple <string, TaxonTreeNode>(line, node));
                    }
                }
            }

            result.LogFilename = _filename.Replace(".txt", "") + "_import.log";
            using (StreamWriter log = new StreamWriter(result.LogFilename))
            {
                log.WriteLine("Import " + _filename + " results");
                log.WriteLine("");
                log.WriteLine(found.Count + " taxons found");
                log.WriteLine(notFound.Count + " taxons not found");
                log.WriteLine("");
                log.WriteLine("Not found:");
                foreach (string name in notFound)
                {
                    log.WriteLine("    " + name);
                }
                log.WriteLine("");
                if (_logFoundTaxon)
                {
                    log.WriteLine("Found:");
                    foreach (Tuple <string, TaxonTreeNode> tuple in found)
                    {
                        log.WriteLine("    " + tuple.Item1 + " ==> " + tuple.Item2.GetHierarchicalName());
                    }
                }
                log.WriteLine("");
            }

            result.TaxonsFound   = found.Count;
            result.TaxonNotFound = notFound.Count;
            Dictionary <TaxonTreeNode, bool> dico = new Dictionary <TaxonTreeNode, bool>();

            foreach (Tuple <string, TaxonTreeNode> tuple in found)
            {
                if (dico.ContainsKey(tuple.Item2))
                {
                    continue;
                }
                dico[tuple.Item2] = true;
            }
            result.List = dico.Keys.ToList();
            return(result);
        }