Exemple #1
0
        public static void Run()
        {
            // Connect to EWS
            const string mailboxUri = "https://outlook.office365.com/ews/exchange.asmx";
            const string username   = "******";
            const string password   = "******";
            const string domain     = "domain";

            //ExStart: FilterAppointmentsByDateUsingEWS
            IEWSClient client = EWSClient.GetEWSClient(mailboxUri, username, password, domain);

            DateTime             startTime = new DateTime(2017, 09, 15);
            DateTime             endTime   = new DateTime(2017, 10, 10);
            ExchangeQueryBuilder builder   = new ExchangeQueryBuilder();

            builder.Appointment.Start.Since(startTime);
            builder.Appointment.End.BeforeOrEqual(endTime);
            MailQuery query = builder.GetQuery();

            Appointment[] appointments = client.ListAppointments(query);
            //ExEnd: FilterAppointmentsByDateUsingEWS

            //ExStart: FilterAppointmentsByRecurrenceUsingEWS
            builder = new ExchangeQueryBuilder();
            builder.Appointment.IsRecurring.Equals(false);
            query        = builder.GetQuery();
            appointments = client.ListAppointments(query);
            //ExEnd: FilterAppointmentsByRecurrenceUsingEWS
        }
        static void Run()
        {
            // ExStart:PagingSupportForListingAppointments
            using (IEWSClient client = EWSClient.GetEWSClient("exchange.domain.com", "username", "password"))
            {
                try
                {
                    Appointment[] appts = client.ListAppointments();
                    Console.WriteLine(appts.Length);
                    DateTime date      = DateTime.Now;
                    DateTime startTime = new DateTime(date.Year, date.Month, date.Day, date.Hour, 0, 0);
                    DateTime endTime   = startTime.AddHours(1);
                    int      appNumber = 10;
                    Dictionary <string, Appointment> appointmentsDict = new Dictionary <string, Appointment>();
                    for (int i = 0; i < appNumber; i++)
                    {
                        startTime = startTime.AddHours(1);
                        endTime   = endTime.AddHours(1);
                        string      timeZone    = "America/New_York";
                        Appointment appointment = new Appointment(
                            "Room 112",
                            startTime,
                            endTime,
                            "*****@*****.**",
                            "*****@*****.**");
                        appointment.SetTimeZone(timeZone);
                        appointment.Summary     = "NETWORKNET-35157_3 - " + Guid.NewGuid().ToString();
                        appointment.Description = "EMAILNET-35157 Move paging parameters to separate class";
                        string uid = client.CreateAppointment(appointment);
                        appointmentsDict.Add(uid, appointment);
                    }
                    AppointmentCollection totalAppointmentCol = client.ListAppointments();

                    ///// LISTING APPOINTMENTS WITH PAGING SUPPORT ///////
                    int itemsPerPage = 2;
                    List <AppointmentPageInfo> pages = new List <AppointmentPageInfo>();
                    AppointmentPageInfo        pagedAppointmentCol = client.ListAppointmentsByPage(itemsPerPage);
                    Console.WriteLine(pagedAppointmentCol.Items.Count);
                    pages.Add(pagedAppointmentCol);
                    while (!pagedAppointmentCol.LastPage)
                    {
                        pagedAppointmentCol = client.ListAppointmentsByPage(itemsPerPage, pagedAppointmentCol.PageOffset + 1);
                        pages.Add(pagedAppointmentCol);
                    }
                    int retrievedItems = 0;
                    foreach (AppointmentPageInfo folderCol in pages)
                    {
                        retrievedItems += folderCol.Items.Count;
                    }
                }
                finally
                {
                }
            }
            // ExEnd:PagingSupportForListingAppointments
        }
Exemple #3
0
        public static void Run()
        {
            try
            {
                // ExStart:CreatingUpdatingAndDeletingCalendarItemsUsingEWS
                IEWSClient client    = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "your.username", "your.Password");
                DateTime   date      = DateTime.Now;
                DateTime   startTime = new DateTime(date.Year, date.Month, date.Day, date.Hour, 0, 0);
                DateTime   endTime   = startTime.AddHours(1);
                string     timeZone  = "America/New_York";

                Appointment app = new Appointment("Room 112", startTime, endTime, "*****@*****.**", "*****@*****.**");
                app.SetTimeZone(timeZone);
                app.Summary     = "NETWORKNET-34136" + Guid.NewGuid().ToString();
                app.Description = "NETWORKNET-34136 Exchange 2007/EWS: Provide support for Add/Update/Delete calendar items";

                string      uid = client.CreateAppointment(app);
                Appointment fetchedAppointment1 = client.FetchAppointment(uid);
                app.Location    = "Room 115";
                app.Summary     = "New summary for " + app.Summary;
                app.Description = "New Description";
                client.UpdateAppointment(app);

                Appointment[] appointments1 = client.ListAppointments();
                Console.WriteLine("Total Appointments: " + appointments1.Length);
                Appointment fetchedAppointment2 = client.FetchAppointment(uid);
                Console.WriteLine("Summary: " + fetchedAppointment2.Summary);
                Console.WriteLine("Location: " + fetchedAppointment2.Location);
                Console.WriteLine("Description: " + fetchedAppointment2.Description);
                client.CancelAppointment(app);
                Appointment[] appointments2 = client.ListAppointments();
                Console.WriteLine("Total Appointments: " + appointments2.Length);
                // ExEnd:CreatingUpdatingAndDeletingCalendarItemsUsingEWS
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Exemple #4
0
        public static void Run()
        {
            using (IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "your.username", "your.Password"))
            {
                try
                {
                    // Create an appointmenta that will be added to secondary calendar folder

                    DateTime date      = DateTime.Now;
                    DateTime startTime = new DateTime(date.Year, date.Month, date.Day, date.Hour, 0, 0);
                    DateTime endTime   = startTime.AddHours(1);

                    string timeZone = "America/New_York";

                    Appointment[] listAppointments;
                    Appointment   appointment = new Appointment("Room 121", startTime, endTime, "*****@*****.**", "*****@*****.**");
                    appointment.SetTimeZone(timeZone);
                    appointment.Summary     = "EMAILNET-35198 - " + Guid.NewGuid().ToString();
                    appointment.Description = "EMAILNET-35198 Ability to add event to Secondary Calendar of Office 365";

                    // Verify that the new folder has been created
                    ExchangeFolderInfoCollection calendarSubFolders = client.ListSubFolders(client.MailboxInfo.CalendarUri);

                    string getfolderName;
                    string setFolderName = "New Calendar";
                    bool   alreadyExits  = false;

                    // Verify that the new folder has been created already exits or not

                    for (int i = 0; i < calendarSubFolders.Count; i++)
                    {
                        getfolderName = calendarSubFolders[i].DisplayName;

                        if (getfolderName.Equals(setFolderName))
                        {
                            alreadyExits = true;
                        }
                    }

                    if (alreadyExits)
                    {
                        Console.WriteLine("Folder Already Exists");
                    }
                    else
                    {
                        // Create new calendar folder
                        client.CreateFolder(client.MailboxInfo.CalendarUri, setFolderName, null, "IPF.Appointment");

                        Console.WriteLine(calendarSubFolders.Count);

                        // Get the created folder URI
                        string newCalendarFolderUri = calendarSubFolders[0].Uri;

                        // appointment api with calendar folder uri
                        // Create
                        client.CreateAppointment(appointment, newCalendarFolderUri);
                        appointment.Location = "Room 122";
                        // update
                        client.UpdateAppointment(appointment, newCalendarFolderUri);
                        // list
                        listAppointments = client.ListAppointments(newCalendarFolderUri);

                        // list default calendar folder
                        listAppointments = client.ListAppointments(client.MailboxInfo.CalendarUri);

                        // Cancel
                        client.CancelAppointment(appointment, newCalendarFolderUri);
                        listAppointments = client.ListAppointments(newCalendarFolderUri);

                        // appointment api with context current calendar folder uri
                        client.CurrentCalendarFolderUri = newCalendarFolderUri;
                        // Create
                        client.CreateAppointment(appointment);
                        appointment.Location = "Room 122";
                        // update
                        client.UpdateAppointment(appointment);
                        // list
                        listAppointments = client.ListAppointments();

                        // list default calendar folder
                        listAppointments = client.ListAppointments(client.MailboxInfo.CalendarUri);

                        // Cancel
                        client.CancelAppointment(appointment);
                        listAppointments = client.ListAppointments();
                    }
                }
                finally
                {
                }
            }
        }