/// <summary>
        /// Returns a list of events given the start and end time, inclusive.
        /// </summary>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <returns></returns>
        public IEnumerable<ICalendarEvent> GetCalendarEvents(DateTimeOffset startDate, DateTimeOffset endDate)
        {
            // Initialize the calendar folder object with only the folder ID.
            var propertiesToGet = new PropertySet(PropertySet.IdOnly);
            propertiesToGet.RequestedBodyType = BodyType.Text;

            var calendar = CalendarFolder.Bind(_exchangeService, WellKnownFolderName.Calendar, propertiesToGet);
            
            // Set the start and end time and number of appointments to retrieve.
            var calendarView = new CalendarView(
                startDate.ToOffset(_exchangeService.TimeZone.BaseUtcOffset).DateTime,
                endDate.ToOffset(_exchangeService.TimeZone.BaseUtcOffset).DateTime,
                MAX_EVENTS_TO_RETRIEVE);

            // Retrieve a collection of appointments by using the calendar view.
            var appointments = calendar.FindAppointments(calendarView);

            // Get specific properties.
            var appointmentSpecificPropertiesToGet = new PropertySet(PropertySet.FirstClassProperties);
            appointmentSpecificPropertiesToGet.AddRange(NonFirstClassAppointmentProperties);
            appointmentSpecificPropertiesToGet.RequestedBodyType = BodyType.Text;
            _exchangeService.LoadPropertiesForItems(appointments, appointmentSpecificPropertiesToGet);

            return TransformExchangeAppointmentsToGenericEvents(appointments);
        }
        private PropertySet CreatePropertySet(IEnumerable <PropertyDefinition> properties, out bool hasReturnOnBindProperty)
        {
            List <PropertyDefinition> expandedList = new List <PropertyDefinition>(properties);

            for (int i = 0; i < expandedList.Count; i++)
            {
                ProviderPropertyDefinition providerPropertyDefinition = expandedList[i] as ProviderPropertyDefinition;
                if (providerPropertyDefinition.IsCalculated)
                {
                    expandedList.AddRange(from x in providerPropertyDefinition.SupportingProperties
                                          where !expandedList.Contains(x)
                                          select x);
                }
            }
            properties = expandedList;
            hasReturnOnBindProperty = properties.Any((PropertyDefinition x) => x is EwsStoreObjectPropertyDefinition && ((EwsStoreObjectPropertyDefinition)x).ReturnOnBind);
            PropertySet propertySet = new PropertySet(0);

            propertySet.AddRange(from x in properties
                                 where x is EwsStoreObjectPropertyDefinition && x != EwsStoreObjectSchema.Identity && ((EwsStoreObjectPropertyDefinition)x).StorePropertyDefinition.Version <= this.RequestedServerVersion
                                 select((EwsStoreObjectPropertyDefinition)x).StorePropertyDefinition);
            if (!properties.Any((PropertyDefinition x) => x == EwsStoreObjectSchema.ExchangeVersion))
            {
                propertySet.Add(EwsStoreObjectSchema.ExchangeVersion.StorePropertyDefinition);
            }
            return(propertySet);
        }
        private void DoGetContacts()
        {
            if(isUserCancel)
            {
                return;
            }
            PropertySet propertySet = new PropertySet();
            Dictionary<PropertyDefinitionBase, String> schemaList =
                ContactsHelper.GetSchemaList();
            propertySet.AddRange(schemaList.Keys);

            List<Item> results = GetItems(service, null, WellKnownFolderName.Contacts,
                propertySet);
            if (results == null)
            {
                return;
            }
            ProcessExchangeContacts(results);
        }
        private IEnumerable<Models.Contact> DoGetContacts()
        {
            Log("DoGetContacts");
            PropertySet propertySet = new PropertySet();
            Dictionary<PropertyDefinitionBase, String> schemaList =
                GetSchemaList();
            propertySet.AddRange(schemaList.Keys);

            List<Item> results = GetItems(service, null, WellKnownFolderName.Contacts,
                propertySet);
            if (results == null)
            {
                return null;
            }
            return ProcessExchangeContacts(results);
        }
        /// <summary>
        /// Export all contacts into the CSV file from Office 365 Exchange Online.
        /// </summary>
        private static void ExportContacts(ExchangeService service)
        {
            // Get the properties we need to write.
            PropertySet propertySet = new PropertySet();
            Dictionary <PropertyDefinitionBase, String> schemaList =
                ContactsHelper.GetSchemaList();

            propertySet.AddRange(schemaList.Keys);

            List <Item> results = GetItems(service, null, WellKnownFolderName.Contacts,
                                           propertySet);
            String path     = GetFolderPath();
            String filePath = Path.Combine(path, "contacts.csv");

            using (StreamWriter writer = new StreamWriter(filePath))
            {
                Boolean firstCell = true;

                // Write the head title
                foreach (PropertyDefinitionBase head in schemaList.Keys)
                {
                    if (!firstCell)
                    {
                        writer.Write(",");
                    }
                    else
                    {
                        firstCell = false;
                    }

                    writer.Write("\"{0}\"", schemaList[head]);
                }
                writer.WriteLine();
                firstCell = true;

                // Write the contact.
                foreach (Item item in results)
                {
                    Contact contact = item as Contact;

                    foreach (PropertyDefinitionBase proerty in schemaList.Keys)
                    {
                        if (!firstCell)
                        {
                            writer.Write(",");
                        }
                        else
                        {
                            firstCell = false;
                        }

                        ContactsHelper.WriteContacts(writer, proerty, contact);
                    }

                    writer.WriteLine();
                    firstCell = true;
                }
            }

            Console.WriteLine();
            Console.WriteLine("Export the contacts to the file:{0}", filePath);
        }
Exemple #6
0
 static PropertySets()
 {
     AppointmentAll.AddRange(ItemAll);
     EmailAll.AddRange(ItemAll);
     TaskAll.AddRange(ItemAll);
 }