Пример #1
0
        private bool Prepare()
        {
            // Use MSAL and acquire access token.

            AcquireViewerTokenForm acuireViewerTokenForm = new AcquireViewerTokenForm();

            if (acuireViewerTokenForm.ShowDialog(out pca, out ar) != DialogResult.OK)
            {
                return(false);
            }

            string token = ar.AccessToken;

            currentUser = ar.User;

            try
            {
                client = new OutlookServicesClient(new Uri("https://outlook.office.com/api/v2.0"),
                                                   () =>
                {
                    return(Task.Run(() =>
                    {
                        return token;
                    }));
                });

                client.Context.SendingRequest2 += new EventHandler <SendingRequest2EventArgs>(
                    (eventSender, eventArgs) => InsertXAnchorMailboxHeader(eventSender, eventArgs, currentUser.DisplayableId));

                // Get the root folder.
                GetRootFolder();

                // Get CalendarFolders (Calendars)
                GetCalendarFolders();

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("ERROR retrieving folders: {0}", ex.Message, "Office365APIEditor"));

                return(false);
            }
        }
        private void MailboxViewerForm_Load(object sender, System.EventArgs e)
        {
            // Use MSAL and acquire access token.

            AcquireViewerTokenForm acuireViewerTokenForm = new AcquireViewerTokenForm();

            if (acuireViewerTokenForm.ShowDialog(out pca, out ar) != DialogResult.OK)
            {
                Close();
                return;
            }

            string token = ar.Token;

            email = ar.User.DisplayableId; // DisplayableId is UPN format.

            try
            {
                client = new OutlookServicesClient(new Uri("https://outlook.office.com/api/v2.0"),
                                                   () =>
                {
                    return(Task.Run(() =>
                    {
                        return token;
                    }));
                });

                client.Context.SendingRequest2 += new EventHandler <SendingRequest2EventArgs>(
                    (eventSender, eventArgs) => InsertXAnchorMailboxHeader(eventSender, eventArgs, email));

                // フォルダー階層を動的に取得するパターン。

                // Get the root folder.
                GetRootFolder();

                // Get CalendarFolders (Calendars)
                GetCalendarFolders();
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("ERROR retrieving folders: {0}", ex.Message, "Office365APIEditor"));
            }
        }
Пример #3
0
        private bool Prepare()
        {
            // Use MSAL and acquire access token.

            AcquireViewerTokenForm acuireViewerTokenForm = new AcquireViewerTokenForm();

            if (acuireViewerTokenForm.ShowDialog(out Global.pca, out Global.LastAuthenticationResult) != DialogResult.OK)
            {
                return(false);
            }

            Global.currentUser = Global.LastAuthenticationResult.Account;

            try
            {
                viewerRequestHelper = new ViewerRequestHelper();

                // Get the Drafts folder.
                GetDraftsFolderAsync();

                // Get the root folder.
                PrepareMsgFolderRootAsync();

                // Create Calendar dummy root folder.
                PrepareCalendarGroupRootFolder();

                // Create To Do dummy root folder.
                PrepareToDoRootFolder();

                // Get the default calendar folder.
                GetDefaultCalendarAsync();

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("ERROR retrieving folders: {0}", ex.Message, "Office365APIEditor"));

                return(false);
            }
        }
        private bool Prepare()
        {
            // Use MSAL and acquire access token.

            AcquireViewerTokenForm acuireViewerTokenForm = new AcquireViewerTokenForm();

            if (acuireViewerTokenForm.ShowDialog(out pca, out ar) != DialogResult.OK)
            {
                return(false);
            }

            string token = ar.AccessToken;

            currentUser = ar.User;

            try
            {
                viewerHelper = new ViewerHelper.ViewerHelper(pca, currentUser);

                // Get the Drafts folder.
                GetDraftsFolderAsync();

                // Get the root folder.
                PrepareMsgFolderRootAsync();

                // Create Calendar dummy root folder.
                PrepareCalendarRootFolder();

                // Create TaskGroup dummy root folder.
                PrepareTaskGroupRootFolder();

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("ERROR retrieving folders: {0}", ex.Message, "Office365APIEditor"));

                return(false);
            }
        }