Beispiel #1
0
        public async Task UpdatePageContentAsync(XDocument pageDoc)
        {
            var xnm = OneNoteUtils.GetOneNoteXnm();

            CleanPageContent(pageDoc, xnm);

            await UseOneNoteAppInSingleThreadAsync(app =>
            {
                app.UpdatePageContent(pageDoc.ToString(), DateTime.MinValue, OneNoteConstants.CurrentOneNoteSchema);
            });
        }
Beispiel #2
0
        unsafe static void Main(string[] args)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            Console.WriteLine("Start");

            try
            {
                _oneNoteApp = OneNoteUtils.CreateOneNoteAppSafe();

//                var s = @"<one:OE creationTime='2019-01-30T16:11:26.000Z' lastModifiedTime='2019-05-13T03:51:39.000Z' objectID='{E892A88C-B8DF-4EA0-85C7-60A9724D2E46}{17}{B0}' alignment='left' quickStyleIndex='1' style='font-family:Calibri;font-size:11.0pt'>
//                    <one:List>
//                      <one:Number numberSequence='58' numberFormat='##.' fontColor='#FF0000' fontSize='11.0' font='Calibri' italic='true' language='1049' text='а.' />
//                    </one:List>
//                    <one:T><![CDATA[<span
//style='font-style:italic;color:red' lang=ru>Аналогичная реакция была и у Петра, когда он осознал, Кто перед ним находится (</span><a
//href='isbtBibleVerse:rst/42%205:8;Луки%205:8'><span style='font-style:italic;
//background:#92D050' lang=ru>Лк 5:8</span></a><span style='font-style:italic;
//color:red' lang=en-US>). </span>]]></one:T>
//                  </one:OE>
//                  <one:OE creationTime='2019-01-30T16:07:54.000Z' lastModifiedTime='2019-05-13T03:51:39.000Z' objectID='{E892A88C-B8DF-4EA0-85C7-60A9724D2E46}{13}{B0}' alignment='left' quickStyleIndex='1' style='font-family:Calibri;font-size:11.0pt'>
//                    <one:List>
//                      <one:Number numberSequence='58' numberFormat='##.' fontColor='#FF0000' fontSize='11.0' font='Calibri' italic='true' language='1049' text='б.' />
//                    </one:List>
//                    <one:T><![CDATA[<span
//style='font-style:italic;color:red'>В конце своей жизни, находясь в ссылке на острове Патмос, Апостол Иоанн (наиболее приближённый к Иисусу Христу ученик) увидел Иисуса Христа. Иоанн не принялся Его обнимать, а упал как мёртвый (</span><a
//href='isbtBibleVerse:rst/66%201:17;Откровение%201:17&amp;qa=1'><span
//style='font-style:italic;background:#92D050'>Отк 1:17</span></a><span
//style='font-style:italic;color:red'> - дополнительная ссылка).</span>]]></one:T>
//                  </one:OE>";

//                var result = SanitizeText(s);
//                Console.WriteLine(result);

                SaveFiles();
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.ToString());
            }

            sw.Stop();

            Console.WriteLine("Finish. Elapsed time: {0}", sw.Elapsed);
            Console.ReadKey();
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="oneNoteApp"></param>
        /// <param name="hierarchyId"></param>
        /// <param name="scope"></param>
        /// <param name="refreshCache">Стоит ли загружать данные из OneNote (true) или из кэша (false)</param>
        /// <returns></returns>
        public HierarchyElement GetHierarchy(ref Application oneNoteApp, string hierarchyId, HierarchyScope scope, bool refreshCache = false)
        {
            OneNoteHierarchyContentId contentId = new OneNoteHierarchyContentId()
            {
                ID = hierarchyId, ContentScope = scope
            };

            HierarchyElement result;

            if (!_hierarchyContentCache.ContainsKey(contentId) || refreshCache)
            {
                lock (_locker)
                {
                    string xml = null;
                    try
                    {
                        OneNoteUtils.UseOneNoteAPI(ref oneNoteApp, (oneNoteAppSafe) =>
                        {
                            oneNoteAppSafe.GetHierarchy(hierarchyId, scope, out xml, Constants.CurrentOneNoteSchema);
                        });
                    }
                    catch (Exception ex)
                    {
                        throw new HierarchyNotFoundException(string.Format("Не удаётся найти иерархию типа '{0}' для элемента '{1}': {2}", scope, hierarchyId, OneNoteUtils.ParseErrorAndMakeItMoreUserFriendly(ex.Message)));
                    }

                    XmlNamespaceManager xnm;
                    XDocument           doc = OneNoteUtils.GetXDocument(xml, out xnm);

                    if (!_hierarchyContentCache.ContainsKey(contentId))
                    {
                        _hierarchyContentCache.Add(contentId, new HierarchyElement()
                        {
                            Id = contentId, Content = doc, Xnm = xnm
                        });
                    }
                    else
                    {
                        _hierarchyContentCache[contentId].Content = doc;
                    }
                }
            }

            result = _hierarchyContentCache[contentId];

            return(result);
        }
Beispiel #4
0
        private ContainerInfo ProcessSectionGroup(XElement sectionGroupEl)
        {
            var sectionGroup = new ContainerInfo();

            ProcessHierarchyElement(sectionGroup, sectionGroupEl);

            foreach (var subSectionGroupEl in sectionGroupEl.Elements(this.xNamespace + "SectionGroup")
                     .Where(sg => !OneNoteUtils.IsRecycleBin(sg)))
            {
                var subSectionGroup = ProcessSectionGroup(subSectionGroupEl);
                sectionGroup.ChildrenContainers.Add(subSectionGroup);
            }

            foreach (var subSection in sectionGroupEl.Elements(this.xNamespace + "Section"))
            {
                var section = ProcessSection(subSection);
                sectionGroup.ChildrenContainers.Add(section);
            }

            return(sectionGroup);
        }
Beispiel #5
0
        private ContainerInfo ProcessSection(XElement sectionEl)
        {
            var section = new ContainerInfo();

            ProcessHierarchyElement(section, sectionEl);

            foreach (var pageEl in sectionEl.Elements(this.xNamespace + "Page"))
            {
                if (!OneNoteUtils.IsRecycleBin(pageEl))
                {
                    var page = new PageInfo()
                    {
                        LastModifiedTime = StringUtils.ParseDateTime((string)pageEl.Attribute("lastModifiedTime"))
                    };

                    ProcessHierarchyElement(page, pageEl);
                    section.Pages.Add(page);
                }
            }

            return(section);
        }
Beispiel #6
0
        private static List <string> GetPagesIds()
        {
            var sectionPathParts = SettingsManager.SourceSectionPath.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);

            var    notebookId     = OneNoteUtils.GetNotebookIdByName(ref _oneNoteApp, sectionPathParts[0], false);
            string sectionGroupId = notebookId;

            for (var i = 1; i < sectionPathParts.Length - 1; i++)
            {
                sectionGroupId = (string)OneNoteUtils.GetHierarchyElementByName(ref _oneNoteApp, "SectionGroup", sectionPathParts[i], sectionGroupId).Attribute("ID");
            }

            var sectionId = (string)OneNoteUtils.GetHierarchyElementByName(ref _oneNoteApp, "Section", sectionPathParts.Last(), sectionGroupId).Attribute("ID");
            var sectionEl = ApplicationCache.Instance.GetHierarchy(ref _oneNoteApp, sectionId, HierarchyScope.hsPages);

            var pagesIds = new List <string>();

            foreach (var pageEl in sectionEl.Content.Root.Elements())
            {
                pagesIds.Add((string)pageEl.Attribute("ID"));
            }

            return(pagesIds);
        }
Beispiel #7
0
 public static void LogError(string message, Exception ex)
 {
     LogMessageToFileAndConsole(true, string.Format("{0}{1} {2}", _errorText, message, OneNoteUtils.ParseErrorAndMakeItMoreUserFriendly(ex.Message)), string.Format("{0} {1}", message, ex.ToString()), true, false, Severity.Error, null, null);
     ErrorWasLogged = true;
 }