示例#1
0
        internal static FindItemsResults <Appointment> LoadResouceCallendar(string ResourceName)
        {
            ExchangeService service = ExchangeHelper.GetExchangeServiceConnection();

            PropertySet psPropset = new PropertySet(BasePropertySet.FirstClassProperties);
            ExtendedPropertyDefinition PidTagWlinkAddressBookEID = new ExtendedPropertyDefinition(0x6854, MapiPropertyType.Binary);
            ExtendedPropertyDefinition PidTagWlinkFolderType     = new ExtendedPropertyDefinition(0x684F, MapiPropertyType.Binary);

            psPropset.Add(PidTagWlinkAddressBookEID);
            psPropset.Add(PidTagWlinkFolderType);

            NameResolutionCollection resolve = service.ResolveName(ResourceName, ResolveNameSearchLocation.DirectoryOnly, false, psPropset);

            FindItemsResults <Appointment> findResults = null;

            if (resolve.Count > 0)
            {
                try{
                    FolderId       SharedCalendarId = new FolderId(WellKnownFolderName.Calendar, resolve[0].Mailbox.Address);
                    CalendarFolder cf = CalendarFolder.Bind(service, SharedCalendarId);
                    findResults = LoadResouceCallendar(cf);
                }
                catch (Microsoft.Exchange.WebServices.Data.ServiceResponseException ex)
                {
                    Trace.TraceError("Error reading calendar for resource {0} ErrMsg: {1}", ResourceName, ex.Message);
                    throw ex;
                }
                //Folder SharedCalendaFolder = Folder.Bind(service, SharedCalendarId);
            }
            else
            {
                throw new ApplicationException(String.Format("Error resolving resource name in GAL: {0}", ResourceName));
            }



            if (findResults != null && findResults.TotalCount > 0)
            {
                service.LoadPropertiesForItems(from Item item in findResults select item,
                                               new PropertySet(BasePropertySet.IdOnly, AppointmentSchema.Start, AppointmentSchema.End,
                                                               AppointmentSchema.Location, AppointmentSchema.Subject, AppointmentSchema.Categories, OnlineMeetingExternalLink));
            }

            return(findResults);


            /*  PropertySet props = new PropertySet();
             * CalendarFolder.Bind(service,WellKnownFolderName.Calendar,)*/
        }
示例#2
0
        internal static FindItemsResults <Appointment> LoadCallendar()
        {
            ExchangeService service = ExchangeHelper.GetExchangeServiceConnection();

            DateTime DateForImport = String.IsNullOrEmpty(WebConfigurationManager.AppSettings["DateForImport"]) ?
                                     DateTime.Today : DateTime.Parse(WebConfigurationManager.AppSettings["DateForImport"]);

            // Берем с часу ночи, чтобы не попадали мероприятия предидущего дня
            DateTime startDate = DateForImport.AddHours(1);
            DateTime endDate   = startDate.AddDays(1);

            const int NUM_APPTS = 25; // FindItem results should be requested in batches of 25.

            // Initialize the calendar folder object with only the folder ID.
            //CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar);

            // Set the start and end time and number of appointments to retrieve.
            CalendarView cView = new CalendarView(startDate, endDate, NUM_APPTS);


            // Limit the properties returned to the appointment's subject, start time, and end time.
            cView.PropertySet = new PropertySet(BasePropertySet.IdOnly);

            // Retrieve a collection of appointments by using the calendar view.
            // FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);
            FindItemsResults <Appointment> findResults = service.FindAppointments(WellKnownFolderName.Calendar, cView);

            if (findResults != null && findResults.TotalCount > 0)
            {
                service.LoadPropertiesForItems(from Item item in findResults select item,
                                               new PropertySet(BasePropertySet.IdOnly, AppointmentSchema.Start, AppointmentSchema.End,
                                                               AppointmentSchema.Location, AppointmentSchema.Subject, AppointmentSchema.Categories));
            }

            return(findResults);
        }