Как прочитать значение «UserProperty» в Outlook, используя MS Graph - PullRequest
0 голосов
/ 18 сентября 2018

У нас есть устаревший код, который записывает пользовательские данные в коллекцию «UserProperties» объекта Outlook AppointmentItem.Теперь мы перешли на использование Outlook в Интернете (OWA).

Используя MS Graph, как можно получить эти значения?

Я пролил эту документацию ()Обзор расширенных свойств Outlook ), но я не могу заставить его работать.Я использую MS Graph Explorer .

Вот событие, для которого я пытаюсь получить информацию о пользовательских данных.

{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#users('45d5e17d-348a-4ca8-b53c-c7d353b928b3')/events",
"value": [
    {
        "@odata.etag": "W/\"GKUifH9QgE6zbEa7VG6rswABBwIJDw==\"",
        "id": "AAMkADU4MzkxN2RmLTdiZDAtNDIwYS04NjQzLTUzNzMyMjM0Y2VkNQBGAAAAAABGjw0ByCaySL6aUxJmew3qBwDwiT27qO5xT6RMWiWBhwRzAAAADIqqAADdUihFgnKFTYATejxXFszxADsYsAgxAAA=",
        "createdDateTime": "2018-07-11T19:17:12.340183Z",
        "lastModifiedDateTime": "2018-09-17T19:50:10.7118964Z",

Я предполагаю, что "id "значение этого события - это то, что я должен использовать.

Вот вызов REST, который я делаю (Примечание: использую BETA)

https://graph.microsoft.com/beta/me/events('AAMkADU4MzkxN2RmLTdiZDAtNDIwYS04NjQzLTUzNzMyMjM0Y2VkNQBGAAAAAABGjw0ByCaySL6aUxJmew3qBwDwiT27qO5xT6RMWiWBhwRzAAAADIqqAADdUihFgnKFTYATejxXFszxADsYsAgxAAA=')?$expand=SingleValueExtendedProperties($filter=id%20eq%20'Integer%20{0006303D-0000-0000-C000-000000000046}%20Name%20TaskID'  )

Имя UserProperty равно"TaskID ", и он содержит целое число.Мне не ясно, каким должно быть значение GUID.

Я попробовал GUID самого AppointmentItem;затем GUID коллекции «UserProperties», содержащейся в AppointmentItem, и, наконец, GUID свойства «UserProperty», содержащейся в коллекции «UserProperties».Ничего не помогло.

Есть какие-нибудь подсказки?

Образец кода для создания пользовательских данных

  1. Создание проекта VSTO для Outlook
  2. Скопируйте код вставки ниже
  3. Создание встречи в календаре Outlook
  4. Обновите строку темы на «MS Graph - тест расширенных свойств».
  5. Закройте Outlook
  6. Скомпилируйте и запуститекод.
  7. Откройте свою встречу, запишите ее (НЕ по теме) и сохраните.
  8. Надстройка обновляет текст вашего Назначения с указанием времени сохранения.
  9. Попробуйте получить эти данные с помощью Microsoft Graph

    using System;
    using System.Runtime.InteropServices;
    using Outlook = Microsoft.Office.Interop.Outlook;
    
    namespace AddCustomProperty
    {
        public partial class ThisAddIn
        {
            Outlook.Items _items;
            Outlook.Folder _calendar;
            Outlook.Inspectors _inspectors;
            const string sCustomData = "MyCustomData";
    
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                _calendar = this.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar) as Outlook.Folder;
    
               _items = _calendar.Items;
    
               _items.ItemChange += eventChange;
    
               _inspectors = this.Application.Inspectors;
               _inspectors.NewInspector += newInspectorWindow;
    
    
            }
    
            private void newInspectorWindow(Outlook.Inspector Inspector)
            {
                Object oAppointmentItem = null;
                Outlook.UserProperties userProperties = null;
                Outlook.UserProperty userProperty = null;
    
                try
                {
                    oAppointmentItem = Inspector.CurrentItem;
                    if (oAppointmentItem is Outlook.AppointmentItem)
                    {
                        userProperties = ((Outlook.AppointmentItem)oAppointmentItem).UserProperties;
                        userProperty = userProperties.Find(sCustomData);
                        if( userProperty != null)
                        {
                            ((Outlook.AppointmentItem)oAppointmentItem).Body = string.Format("MY CUSTOM DATA FOUND [{0}]: {1}\n", DateTime.Now, userProperty.Value);                    
                        }
                    }
                }
                catch(Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Message);
                }
                finally
                {
                    if (userProperty != null) { Marshal.ReleaseComObject(userProperty); userProperty = null; }
                    if (userProperties != null) { Marshal.ReleaseComObject(userProperties); userProperties = null; }
                    if (oAppointmentItem != null) { Marshal.ReleaseComObject(oAppointmentItem); oAppointmentItem = null; }
                }
            }
    
            private void eventChange(object Item)
            {
                Outlook.AppointmentItem apptItem = null;
                Outlook.UserProperties userProperties = null;
                Outlook.UserProperty userProperty = null;
    
                try
                {
                    apptItem = Item as Outlook.AppointmentItem;
    
                    if (apptItem.Subject == "MS Graph - Extended Properties Test") 
                    {
                        userProperties = apptItem.UserProperties;
                        userProperty = userProperties.Find(sCustomData);
                        if( userProperty == null)
                        {
                            userProperty = userProperties.Add(sCustomData, Outlook.OlUserPropertyType.olInteger);
                            userProperty.Value = 10;
                        }
                        else
                        {
                            ((Outlook.AppointmentItem)apptItem).Body = string.Format("MY CUSTOM DATA FOUND [{0}]: {1}\n", DateTime.Now, userProperty.Value);
    
                        }
    
                    }
                }
                catch( Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Message);
                }
                finally
                {
                    if( userProperty != null) { Marshal.ReleaseComObject(userProperty); userProperty = null; }
                    if (userProperties != null) { Marshal.ReleaseComObject(userProperties); userProperties = null; }
    
                }            
            }
    
            private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
            {
                // Note: Outlook no longer raises this event. If you have code that 
                //    must run when Outlook shuts down, see https://go.microsoft.com/fwlink/?LinkId=506785
            }
    
            #region VSTO generated code
    
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InternalStartup()
            {
                this.Startup += new System.EventHandler(ThisAddIn_Startup);
                this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
            }
    
            #endregion
        }
    

1 Ответ

0 голосов
/ 04 октября 2018

Я получил ответ на другом сайте.

Проблема заключалась в том, что GUID я использовал в одном из моих запросов. Я использовал GUID для объекта UserProperty вместо GUID для объекта, который наследуется от UserProperty

НЕПРАВИЛЬНЫЙ РУКОВОДСТВО

Правильный GUID получен из самого объекта MAPI.

ПРАВИЛЬНАЯ ИНФОРМАЦИЯ

Последний звонок выглядит следующим образом: Полный ответ

https://graph.microsoft.com/v1.0/me/events('AAMkADU4MzkxN2RmLTdiZDAtNDIwYS04NjQzLTUzNzMyMjM0Y2VkNQBGAAAAAABGjw0ByCaySL6aUxJmew3qBwDwiT27qO5xT6RMWiWBhwRzAAAADIqqAAAYpSJ8f1CATrNsRrtUbquzAAEOAONsAAA=')?$expand=singleValueExtendedProperties($filter=id%20eq%20'Integer%20{00020329-0000-0000-C000-000000000046}%20Name%20MyCustomData')
...