Exemplo n.º 1
0
        // TODO: Add notable clips
        public Task Populate(string filePath, CancellationToken cancellationToken = default)
        {
            var ver = XRayUtil.CheckXRayVersion(filePath);

            if (ver == XRayUtil.XRayVersion.Invalid)
            {
                throw new Exception("Invalid X-Ray file.");
            }

            var terms = ver == XRayUtil.XRayVersion.New
                ? _termsService.ExtractTermsNew(new SQLiteConnection($"Data Source={filePath}; Version=3;"), true)
                : _termsService.ExtractTermsOld(filePath);

            flpPeople.Controls.Clear();
            flpTerms.Controls.Clear();

            foreach (var t in terms)
            {
                var p        = new XRayPanel(t.Type, t.TermName, Math.Max(t.Occurrences.Count, t.Locs.Count).ToString(), t.Desc);
                var controls = t.Type switch
                {
                    "character" => flpPeople.Controls,
                    "topic" => flpTerms.Controls,
                    _ => null
                };
                controls?.Add(p);
            }
            tcXray.SelectedIndex = 0;
            return(Task.CompletedTask);
        }
Exemplo n.º 2
0
        private void btnExtractTerms_Click(object sender, EventArgs e)
        {
            var selPath = UIFunctions.GetFile("Open a Kindle X-Ray file...", "", "ASC files|*.asc", _settings.outDir);

            if (selPath == "" || !selPath.Contains("XRAY.entities"))
            {
                _logger.Log("Invalid or no file selected.");
                return;
            }
            var newVer = XRayUtil.CheckXRayVersion(selPath);

            if (newVer == XRayUtil.XRayVersion.Invalid)
            {
                _logger.Log("Invalid X-Ray file.");
                return;
            }
            try
            {
                var terms = newVer == XRayUtil.XRayVersion.New
                    ? _termsService.ExtractTermsNew(new SQLiteConnection($"Data Source={selPath}; Version=3;"), true)
                    : _termsService.ExtractTermsOld(selPath);
                if (!Directory.Exists(Environment.CurrentDirectory + @"\xml\"))
                {
                    Directory.CreateDirectory(Environment.CurrentDirectory + @"\xml\");
                }
                var outfile = Environment.CurrentDirectory + @"\xml\" + Path.GetFileNameWithoutExtension(selPath) + ".xml";
                Functions.Save(terms.ToList(), outfile);
                _logger.Log("Character data has been successfully extracted and saved to: " + outfile);
            }
            catch (Exception ex)
            {
                _logger.Log("Error:\r\n" + ex.Message + "\r\n" + ex.StackTrace);
            }
        }