如何处理单值扩展属性?

huangapple go评论63阅读模式
英文:

How to work with single-value extended properties?

问题

在我们的应用程序中,我们希望将投票选项与MS Graph集成。不幸的是,官方尚未提供此功能,因此我们必须创建自己的解决方案。我找到了这个链接:https://learn.microsoft.com/en-us/answers/questions/826338/adding-voting-option-in-microsoft-graph-api

现在的问题是,我如何在C#中处理单值属性?是否有任何用于处理的类,也许是SingleValueLegacyExtendedProperty

英文:

I have searched everywhere for an instruction, how to work with single-value extended properties, but have not found something like that.

In our application, we want to integrate voting options with MS Graph. Unfortunately, it is not official available yet, so we have to create our own solution. I found this one: https://learn.microsoft.com/en-us/answers/questions/826338/adding-voting-option-in-microsoft-graph-api

Now the question is, how I can work with single-value properties in C#. Are there any classes to work with, maybe SingleValueLegacyExtendedProperty?

答案1

得分: 0

在SDK v5中,在读取单值扩展属性时,您需要在扩展查询参数中指定属性:

var result = await _client.Me.Messages.GetAsync((requestConfiguration) =>
{
    requestConfiguration.QueryParameters.Expand = new string[] { "singleValueExtendedProperties($filter=id+eq+'Binary {00062008-0000-0000-C000-000000000046} Id 0x00008520')" };
});

// 获取具有单值扩展属性的第一条消息
var message = result.Value.FirstOrDefault(x => x.SingleValueExtendedProperties != null);
var votingData = message.SingleValueExtendedProperties[0].Value;

要创建具有单值扩展属性的新消息:

var body = new SendMailPostRequestBody
{
    Message = new Message
    {
        Subject = "Voting",
        Sender = new Recipient
        {
            EmailAddress = new EmailAddress
            {
                Address = "xxx@contoso.com"
            }
        },
        ToRecipients = new List<Recipient>
        {
             new Recipient
             {
                 EmailAddress = new EmailAddress { Address = "yyy@contoso.com" }
             }
         },
         Body = new ItemBody
         {
             ContentType = BodyType.Html,
             Content = "Please vote"
         },
         SingleValueExtendedProperties = new List<SingleValueLegacyExtendedProperty>
         {
             new SingleValueLegacyExtendedProperty
             {
                 Id = "Binary {00062008-0000-0000-C000-000000000046} Id 0x00008520",
                 Value = "data"
             }
         }
     },
     SaveToSentItems = true
};
await _client.Me.SendMail.PostAsync(body);

对于较旧版本的SDK,如v4和v3:

var response = await client.Me.Messages.Request()
            .Expand("singleValueExtendedProperties($filter=id+eq+'Binary {00062008-0000-0000-C000-000000000046} Id 0x00008520')")
            .GetAsync();

var message = response.FirstOrDefault(x => x.SingleValueExtendedProperties != null);
var votingData = message.SingleValueExtendedProperties[0].Value;

新消息:

var message = new Message
{
    Subject = "Voting",
    Sender = new Recipient
    {
        EmailAddress = new EmailAddress
        {
            Address = "xxx@contoso.com"
        }
    },
    ToRecipients = new List<Recipient>
    {
        new Recipient
        {
            EmailAddress = new EmailAddress { Address = "yyy@contoso.com" }
        }
    },
    Body = new ItemBody
    {
        ContentType = BodyType.Html,
        Content = "Please vote"
    },
    SingleValueExtendedProperties = new MessageSingleValueExtendedPropertiesCollectionPage
    {
        new SingleValueLegacyExtendedProperty
        {
            Id = "Binary {00062008-0000-0000-C000-000000000046} Id 0x00008520",
            Value = "data"
        }
    }
};
await client.Me.SendMail(message, true).Request().PostAsync();
英文:

In SDK v5, when reading single-value extended property, you have to specify the property in expand query parameter:

var result = await _client.Me.Messages.GetAsync((requestConfiguration) =&gt;
{
    requestConfiguration.QueryParameters.Expand = new string[] { &quot;singleValueExtendedProperties($filter=id+eq+&#39;Binary {00062008-0000-0000-C000-000000000046} Id 0x00008520&#39;)&quot; };
});

// get first message with single-value extended property
var message = result.Value.FirstOrDefault(x =&gt; x.SingleValueExtendedProperties != null);
var votingData = message.SingleValueExtendedProperties[0].Value;

To create a new message with single-value extended property

var body = new SendMailPostRequestBody
{
    Message = new Message
    {
        Subject = &quot;Voting&quot;,
        Sender = new Recipient
        {
            EmailAddress = new EmailAddress
            {
                Address = &quot;xxx@contoso.com&quot;
            }
        },
        ToRecipients = new List&lt;Recipient&gt;
        {
             new Recipient
             {
                 EmailAddress = new EmailAddress { Address = &quot;yyy@contoso.com&quot; }
             }
         },
         Body = new ItemBody
         {
             ContentType = BodyType.Html,
             Content = &quot;Please vote&quot;
         },
         SingleValueExtendedProperties = new List&lt;SingleValueLegacyExtendedProperty&gt;
         {
             new SingleValueLegacyExtendedProperty
             {
                 Id = &quot;Binary {00062008-0000-0000-C000-000000000046} Id 0x00008520&quot;,
                 Value = &quot;data&quot;
             }
         }
     },
     SaveToSentItems = true
};
await _client.Me.SendMail.PostAsync(body);

For older version of SDK like v4 and v3

var response = await client.Me.Messages.Request()
            .Expand(&quot;singleValueExtendedProperties($filter=id+eq+&#39;Binary {00062008-0000-0000-C000-000000000046} Id 0x00008520&#39;)&quot;)
            .GetAsync();

var message = response.FirstOrDefault(x =&gt; x.SingleValueExtendedProperties != null);
var votingData = message.SingleValueExtendedProperties[0].Value;

New message

var message = new Message
{
    Subject = &quot;Voting&quot;,
    Sender = new Recipient
    {
        EmailAddress = new EmailAddress
        {
            Address = &quot;xxx@contoso.com&quot;
        }
    },
    ToRecipients = new List&lt;Recipient&gt;
    {
        new Recipient
        {
            EmailAddress = new EmailAddress { Address = &quot;yyy@contoso.com&quot; }
        }
    },
    Body = new ItemBody
    {
        ContentType = BodyType.Html,
        Content = &quot;Please vote&quot;
    },
    SingleValueExtendedProperties = new MessageSingleValueExtendedPropertiesCollectionPage
    {
        new SingleValueLegacyExtendedProperty
        {
            Id = &quot;Binary {00062008-0000-0000-C000-000000000046} Id 0x00008520&quot;,
            Value = &quot;data&quot;
        }
    }
};
await client.Me.SendMail(message, true).Request().PostAsync();

huangapple
  • 本文由 发表于 2023年6月5日 17:07:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76404941.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定