Example #1
0
        public override void Execute(params object[] args)
        {
            var builder = new StringBuilder();

            builder.AppendLine("Diagnostics.Execute()");
            builder.AppendLine(new string('-', 80));

            builder.AppendLine($"ONENOTE...: {Process.GetProcessesByName("ONENOTE")[0].MainModule.FileName}");
            builder.AppendLine($"Addin path: {Assembly.GetExecutingAssembly().Location}");
            builder.AppendLine($"Data path.: {PathFactory.GetAppDataPath()}");
            builder.AppendLine($"Log path..: {logger.LogPath}");
            builder.AppendLine();

            using (var one = new OneNote())
            {
                var(backupFolder, defaultFolder, unfiledFolder) = one.GetFolders();
                builder.AppendLine($"Default path: {defaultFolder}");
                builder.AppendLine($"Backup  path: {backupFolder}");
                builder.AppendLine($"Unfiled path: {unfiledFolder}");
                builder.AppendLine();

                var(Name, Path, Link) = one.GetPageInfo();
                builder.AppendLine($"Page name: {Name}");
                builder.AppendLine($"Page path: {Path}");
                builder.AppendLine($"Page link: {Link}");
                builder.AppendLine();

                one.ReportWindowDiagnostics(builder);

                builder.AppendLine();

                var page           = one.GetPage();
                var pageColor      = page.GetPageColor(out _, out _);
                var pageBrightness = pageColor.GetBrightness();

                builder.AppendLine($"Page background: {pageColor.ToRGBHtml()}");
                builder.AppendLine($"Page brightness: {pageBrightness}");
                builder.AppendLine($"Page is dark...: {pageBrightness < 0.5}");

                (float dpiX, float dpiY) = UIHelper.GetDpiValues();
                builder.AppendLine($"Screen DPI.....: horizontal/X:{dpiX} vertical/Y:{dpiY}");

                (float scalingX, float scalingY) = UIHelper.GetScalingFactors();
                builder.AppendLine($"Scaling factors: horizontal/X:{scalingX} vertical/Y:{scalingY}");

                builder.AppendLine(new string('-', 80));

                logger.WriteLine(builder.ToString());

                UIHelper.ShowInfo($"Diagnostics written to {logger.LogPath}");
            }
        }
Example #2
0
        public void AddFavorite(bool addSection = false)
        {
            XElement root;

            if (File.Exists(path))
            {
                root = UpgradeFavoritesMenu(XElement.Load(path, LoadOptions.None));
            }
            else
            {
                root = MakeMenuRoot();
            }

            using (var one = new OneNote())
            {
                var info = addSection ? one.GetSectionInfo() : one.GetPageInfo();

                var name = info.Name;
                if (name.Length > 50)
                {
                    name = name.Substring(0, 50) + "...";
                }

                // similar to mongo ObjectId, a random-enough identifier for our needs
                var id = ((DateTimeOffset.Now.ToUnixTimeSeconds() << 32)
                          + new Random().Next()).ToString("x");

                var imageMso = addSection ? "GroupInsertLinks" : "FileLinksToFiles";

                root.Add(new XElement(ns + "button",
                                      new XAttribute("id", $"omFavoriteLink{id}"),
                                      new XAttribute("onAction", GotoFavoriteCmd),
                                      new XAttribute("imageMso", imageMso),
                                      new XAttribute("label", name),
                                      new XAttribute("tag", info.Link),
                                      new XAttribute("screentip", info.Path)
                                      ));

                logger.WriteLine($"Saving favorite '{info.Path}' ({info.Link})");
            }

            SaveFavorites(root);
        }
Example #3
0
        public void AddFavorite()
        {
            XElement root;

            if (File.Exists(path))
            {
                root = XElement.Load(path, LoadOptions.None);
            }
            else
            {
                root = MakeMenuRoot();
            }

            using (var one = new OneNote())
            {
                var info = one.GetPageInfo();

                var name = EmojiDialog.RemoveEmojis(info.Name);
                if (name.Length > 50)
                {
                    name = name.Substring(0, 50) + "...";
                }

                // similar to mongo ObjectId, a random-enough identifier for our needs
                var id = ((DateTimeOffset.Now.ToUnixTimeSeconds() << 32)
                          + new Random().Next()).ToString("x");

                root.Add(new XElement(ns + "splitButton",
                                      new XAttribute("id", $"omFavorite{id}"),
                                      new XElement(ns + "button",
                                                   new XAttribute("id", $"omFavoriteLink{id}"),
                                                   new XAttribute("onAction", "NavigateToFavorite"),
                                                   new XAttribute("imageMso", "FileLinksToFiles"),
                                                   new XAttribute("label", name),
                                                   new XAttribute("tag", info.Link),
                                                   new XAttribute("screentip", info.Path)
                                                   ),
                                      new XElement(ns + "menu",
                                                   new XAttribute("id", $"omFavoriteMenu{id}"),
                                                   new XElement(ns + "button",
                                                                new XAttribute("id", $"omFavoriteRemoveButton{id}"),
                                                                new XAttribute("onAction", "RemoveFavorite"),
                                                                new XAttribute("label", "Remove this item"),
                                                                new XAttribute("imageMso", "HyperlinkRemove"),
                                                                new XAttribute("tag", $"omFavorite{id}")
                                                                )
                                                   )
                                      ));

                // sort by name/label
                var items =
                    from e in root.Elements(ns + "splitButton")
                    let key = e.Element(ns + "button").Attribute("label").Value
                              orderby key
                              select e;

                root = MakeMenuRoot();
                foreach (var item in items)
                {
                    root.Add(item);
                }

                logger.WriteLine($"Saving favorite '{info.Path}' ({info.Link})");
            }

            try
            {
                PathFactory.EnsurePathExists(PathFactory.GetAppDataPath());
                root.Save(path, SaveOptions.None);

                ribbon.InvalidateControl("ribFavoritesMenu");
            }
            catch (Exception exc)
            {
                logger.WriteLine($"Cannot save {path}");
                logger.WriteLine(exc);
            }
        }