/// <summary>
        /// Update the navigation property singleValueExtendedProperties in groups
        /// <param name="body"></param>
        /// <param name="requestConfiguration">Configuration for the request such as headers, query parameters, and middleware options.</param>
        /// </summary>
        public RequestInformation CreatePatchRequestInformation(SingleValueLegacyExtendedProperty body, Action <SingleValueLegacyExtendedPropertyItemRequestBuilderPatchRequestConfiguration> requestConfiguration = default)
        {
            _ = body ?? throw new ArgumentNullException(nameof(body));
            var requestInfo = new RequestInformation {
                HttpMethod     = Method.PATCH,
                UrlTemplate    = UrlTemplate,
                PathParameters = PathParameters,
            };

            requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body);
            if (requestConfiguration != null)
            {
                var requestConfig = new SingleValueLegacyExtendedPropertyItemRequestBuilderPatchRequestConfiguration();
                requestConfiguration.Invoke(requestConfig);
                requestInfo.AddRequestOptions(requestConfig.Options);
                requestInfo.AddHeaders(requestConfig.Headers);
            }
            return(requestInfo);
        }
        public async System.Threading.Tasks.Task ContactsSetGetSingleExtendedProperty()
        {
            try
            {
                var contact = new Contact();
                contact.GivenName = "_Tom" + Guid.NewGuid().ToString();

                var customProperty   = new SingleValueLegacyExtendedProperty();
                var namespaceGuid    = "f5939744-0f22-4f03-b33c-f18a8acfa20b";
                var mapiPropertyType = "String";
                var propertyName     = "CustomProperty";
                var propertyId       = $"{mapiPropertyType} {{{namespaceGuid}}} Name {propertyName}";
                customProperty.Id    = propertyId;
                customProperty.Value = "My custom property value";

                var extendedValueCollection = new ContactSingleValueExtendedPropertiesCollectionPage();
                extendedValueCollection.Add(customProperty);

                contact.SingleValueExtendedProperties = extendedValueCollection;

                // This results in a call to the service. It adds a contact with the extended property set on it.
                var partiallySyncdContact = await graphClient.Me.Contacts.Request().AddAsync(contact);

                Assert.IsNotNull(partiallySyncdContact.Id, "The ID property is not set on the contact.");

                // This results in a call to the service. It gets the contact with the extended property.
                // http://graph.microsoft.io/en-us/docs/api-reference/v1.0/api/singlevaluelegacyextendedproperty_get
                var syncdContact = await graphClient.Me.Contacts[partiallySyncdContact.Id].Request().Expand($"singleValueExtendedProperties($filter=id eq '{propertyId}')").GetAsync();

                Assert.IsNotNull(syncdContact.SingleValueExtendedProperties, "The expected extended property was not set on the contact");
            }
            catch (Microsoft.Graph.ServiceException e)
            {
                Assert.Fail("Something happened, check out a trace. Error code: {0}", e.Error.Code);
            }
        }
Пример #3
0
        /// <summary>
        /// Sends the message with extended property.
        /// </summary>
        /// <param name="exchangeServiceA">The exchange service a.</param>
        /// <param name="exchangeServiceB">The exchange service b.</param>
        public static async Task SendMessageWithExtendedProperty(ExchangeService exchangeServiceA, ExchangeService exchangeServiceB)
        {
            string  messageSubject = Guid.NewGuid().ToString();
            Message message        = new Message(exchangeServiceA)
            {
                Subject = messageSubject,
                Body    = new ItemBody()
                {
                    Content     = "Test message",
                    ContentType = BodyType.Html
                }
            };

            message.ToRecipients = new List <Recipient>
            {
                new Recipient()
                {
                    EmailAddress = new EmailAddress()
                    {
                        Address = AppConfig.MailboxB
                    }
                }
            };

            ExtendedPropertyDefinition extendedPropertyDefinition = new ExtendedPropertyDefinition(
                MapiPropertyType.String,
                "MyIdProp",
                Guid.NewGuid());

            string testValue = Guid.NewGuid().ToString();
            SingleValueLegacyExtendedProperty singleValueLegacyExtendedProperty = (SingleValueLegacyExtendedProperty)extendedPropertyDefinition;

            singleValueLegacyExtendedProperty.Value = testValue;
            message.SingleValueExtendedProperties.Add(singleValueLegacyExtendedProperty);

            MailFolder draftFolder = await exchangeServiceA.GetAsync <MailFolder>(
                new EntityPath(WellKnownFolderName.Drafts.ToString(),
                               typeof(MailFolder)));

            await message.SaveAsync(draftFolder);

            await message.Send();

            Thread.Sleep(6000); // allow some time for email to be delivered
            MessageView messageView = new MessageView(10);

            messageView.PropertySet.Expand(extendedPropertyDefinition);

            SearchFilter subjectFilter = new SearchFilter.IsEqualTo(
                MessageObjectSchema.Subject,
                messageSubject);

            FindItemResults <Message> mailboxBMessages = await exchangeServiceB.FindItems(
                "Inbox",
                messageView,
                subjectFilter);

            Assert.AreEqual(
                1,
                mailboxBMessages.TotalCount);

            Assert.AreEqual(
                testValue,
                mailboxBMessages.Items[0].SingleValueExtendedProperties[0].Value);
        }
        /// <summary>
        /// Creates the do not forward event.
        /// </summary>
        /// <param name="exchangeServiceA">The exchange service a.</param>
        /// <param name="exchangeServiceB">The exchange service b.</param>
        public static async Task CreateDoNotForwardEvent(ExchangeService exchangeServiceA, ExchangeService exchangeServiceB)
        {
            string subject       = Guid.NewGuid().ToString();
            Event  calendarEvent = new Event(exchangeServiceA);

            calendarEvent.Body = new ItemBody()
            {
                Content     = "test",
                ContentType = BodyType.Html
            };

            calendarEvent.Subject = subject;
            calendarEvent.Start   = new DateTimeTimeZone()
            {
                DateTime = DateTimeHelper.GetFormattedDateTime().ToString("yyyy-MM-ddThh:mm:ss"),
                TimeZone = "Central European Standard Time"
            };

            calendarEvent.End = new DateTimeTimeZone()
            {
                DateTime = DateTimeHelper.GetFormattedDateTime(5).ToString("yyyy-MM-ddThh:mm:ss"),
                TimeZone = "Central European Standard Time"
            };

            calendarEvent.Attendees = new List <Attendee>()
            {
                new Attendee()
                {
                    EmailAddress = new EmailAddress()
                    {
                        Address = AppConfig.MailboxB
                    }
                }
            };

            ExtendedPropertyDefinition doNotForwardExt = new ExtendedPropertyDefinition(MapiPropertyType.Boolean,
                                                                                        "DoNotForward",
                                                                                        new Guid("00020329-0000-0000-C000-000000000046"));

            SingleValueLegacyExtendedProperty doNotForward = doNotForwardExt;

            doNotForward.Value = "true";

            calendarEvent.SingleValueExtendedProperties.Add(doNotForward);
            await calendarEvent.SaveAsync();

            Thread.Sleep(8000); // allow item to be delivered to mailbox b
            SearchFilter subjectFilter = new SearchFilter.IsEqualTo(
                EventObjectSchema.Subject,
                subject);

            EventView view = new EventView();

            view.PropertySet.Expand(doNotForwardExt);

            FindItemResults <Event> items = await exchangeServiceB.FindItems <Event>(view, subjectFilter);

            Assert.AreEqual(
                1,
                items.TotalCount);

            Assert.AreEqual(
                doNotForward.Id,
                items.Items[0].SingleValueExtendedProperties[0].Id);

            Assert.AreEqual(
                doNotForward.Value,
                items.Items[0].SingleValueExtendedProperties[0].Value);
        }