Example #1
0
        // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
        // Word...

        private void ImportWord(string filepath, bool append)
        {
            if (!Office.IsInstalled("Word"))
            {
                UIHelper.ShowMessage("Word is not installed");
            }

            logger.StartClock();

            var completed = RunBackgroundTask(filepath, async() =>
            {
                await WordImporter(filepath, append);

                progressDialog.DialogResult = DialogResult.OK;
                progressDialog.Close();
            });

            if (completed)
            {
                logger.WriteTime("word file imported");
            }
            else
            {
                logger.StopClock();
            }
        }
        public override async Task Execute(params object[] args)
        {
            using (var dialog = new NumberPagesDialog())
            {
                if (dialog.ShowDialog(owner) == DialogResult.OK)
                {
                    using (one = new OneNote())
                    {
                        var section = one.GetSection();
                        ns = one.GetNamespace(section);

                        var pages = section.Elements(ns + "Page")
                                    .Select(e => new PageBasics
                        {
                            ID    = e.Attribute("ID").Value,
                            Name  = e.Attribute("name").Value,
                            Level = int.Parse(e.Attribute("pageLevel").Value)
                        })
                                    .ToList();

                        if (pages?.Count > 0)
                        {
                            logger.StartClock();

                            var index = 0;

                            if (dialog.CleanupNumbering)
                            {
                                cleaner = new RemovePageNumbersCommand();
                            }

                            using (progress = new UI.ProgressDialog())
                            {
                                progress.SetMaximum(pages.Count);
                                progress.Show(owner);

                                await ApplyNumbering(
                                    pages, index, pages[0].Level,
                                    dialog.NumericNumbering, string.Empty);

                                progress.Close();
                            }

                            logger.StopClock();
                            logger.WriteTime("numbered pages");
                        }
                    }
                }
            }
        }
Example #3
0
        public override async Task Execute(params object[] args)
        {
            using (one = new OneNote())
            {
                var section = one.GetSection();
                var ns      = one.GetNamespace(section);

                var infos = section.Elements(ns + "Page")
                            .Select(e => new PageInfo
                {
                    ID   = e.Attribute("ID").Value,
                    Name = e.Attribute("name").Value,
                    Date = e.Attribute("dateTime").Value
                })
                            .ToList();

                if (infos?.Count > 0)
                {
                    logger.StartClock();

                    using (progress = new UI.ProgressDialog())
                    {
                        progress.SetMaximum(infos.Count);
                        progress.Show(owner);

                        foreach (var info in infos)
                        {
                            progress.SetMessage(info.Name);
                            await StampPage(info);
                        }

                        progress.Close();
                    }

                    logger.StopClock();
                    logger.WriteTime("datestamp pages");
                }
            }
        }
Example #4
0
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        // Invoked by the ProgressDialog OnShown callback
        private async Task Execute(UI.ProgressDialog progress, CancellationToken token)
        {
            logger.Start();
            logger.StartClock();

            archivist = new Archivist(one, zipPath);
            await archivist.BuildHyperlinkMap(
                bookScope?OneNote.Scope.Sections : OneNote.Scope.Pages,
                progress,
                token);

            // use this temp folder as a sandbox for each page
            var t = Path.GetTempFileName();

            tempdir = Path.Combine(Path.GetDirectoryName(t), Path.GetFileNameWithoutExtension(t));
            PathFactory.EnsurePathExists(tempdir);
            logger.WriteLine($"building archive {zipPath}");

            progress.SetMaximum(totalCount);
            progress.SetMessage($"Archiving {totalCount} pages");

            using (var stream = new FileStream(zipPath, FileMode.Create))
            {
                using (archive = new ZipArchive(stream, ZipArchiveMode.Create))
                {
                    await Archive(progress, hierarchy, hierarchy.Attribute("name").Value);
                }
            }

            Directory.Delete(tempdir, true);

            progress.Close();
            UIHelper.ShowMessage(string.Format(Resx.ArchiveCommand_archived, pageCount, zipPath));

            logger.WriteTime("archive complete");
            logger.End();
        }
Example #5
0
 private void Process_Exited(object sender, EventArgs e)
 {
     logger.WriteTime("plugin process exited");
     progressDialog.DialogResult = DialogResult.OK;
     progressDialog.Close();
 }