Exemple #1
0
        public static void Run()
        {
            try
            {
                // ExStart:MoveAndDeleteAppointment
                GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret");
                string         accessToken;
                string         refreshToken;
                GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken);

                // Get IGmailclient
                using (IGmailClient client = Aspose.Email.Clients.Google.GmailClient.GetInstance(accessToken, User2.EMail))
                {
                    string SourceCalendarId      = client.ListCalendars()[0].Id;
                    string DestinationCalendarId = client.ListCalendars()[1].Id;
                    string TargetAppUniqueId     = client.ListAppointments(SourceCalendarId)[0].UniqueId;

                    // Retrieve the list of appointments in the destination calendar before moving the appointment
                    Appointment[] appointments = client.ListAppointments(DestinationCalendarId);
                    Console.WriteLine("Before moving count = " + appointments.Length);
                    Appointment Movedapp = client.MoveAppointment(SourceCalendarId, DestinationCalendarId, TargetAppUniqueId);

                    // Retrieve the list of appointments in the destination calendar after moving the appointment
                    appointments = client.ListAppointments(DestinationCalendarId);
                    Console.WriteLine("After moving count = " + appointments.Length);

                    // Delete particular appointment from a calendar using unique id
                    client.DeleteAppointment(DestinationCalendarId, Movedapp.UniqueId);

                    // Retrieve the list of appointments. It should be one less than the earlier appointments in the destination calendar
                    appointments = client.ListAppointments(DestinationCalendarId);
                    Console.WriteLine("After deleting count = " + appointments.Length);
                }

                // ExEnd:MoveAndDeleteAppointment
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public static void Run()
        {
            try
            {
                // ExStart:RetrieveUpdateAppointment
                GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret");
                string         accessToken;
                string         refreshToken;
                GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken);

                // Get IGmailclient
                using (IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail))
                {
                    string calendarId          = client.ListCalendars()[0].Id;
                    string AppointmentUniqueId = client.ListAppointments(calendarId)[0].UniqueId;

                    // Retrieve Appointment
                    Appointment app3 = client.FetchAppointment(calendarId, AppointmentUniqueId);
                    // Change the appointment information
                    app3.Summary       = "New Summary - " + Guid.NewGuid().ToString();
                    app3.Description   = "New Description - " + Guid.NewGuid().ToString();
                    app3.Location      = "New Location - " + Guid.NewGuid().ToString();
                    app3.Flags         = AppointmentFlags.AllDayEvent;
                    app3.StartDate     = DateTime.Now.AddHours(2);
                    app3.EndDate       = app3.StartDate.AddHours(1);
                    app3.StartTimeZone = "Europe/Kiev";
                    app3.EndTimeZone   = "Europe/Kiev";
                    // Update the appointment and get back updated appointment
                    Appointment app4 = client.UpdateAppointment(calendarId, app3);
                }
                // ExEnd:RetrieveUpdateAppointment
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Exemple #3
0
        public static void Run()
        {
            try
            {
                // ExStart:AddingAnAppointment

                GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret");
                string         accessToken;
                string         refreshToken;
                GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken);

                // Get IGmailclient
                using (IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail))
                {
                    // Create local calendar
                    Aspose.Email.Clients.Google.Calendar calendar1 = new Aspose.Email.Clients.Google.Calendar("summary - " + Guid.NewGuid().ToString(), null, null, "Europe/Kiev");

                    // Insert calendar and get id of inserted calendar and Get back calendar using an id
                    string id = client.CreateCalendar(calendar1);
                    Aspose.Email.Clients.Google.Calendar cal1 = client.FetchCalendar(id);
                    string calendarId1 = cal1.Id;

                    try
                    {
                        // Retrieve list of appointments from the first calendar
                        Appointment[] appointments = client.ListAppointments(calendarId1);
                        if (appointments.Length > 0)
                        {
                            Console.WriteLine("Wrong number of appointments");
                            return;
                        }

                        // Get current time and Calculate time after an hour from now
                        DateTime startDate = DateTime.Now;
                        DateTime endDate   = startDate.AddHours(1);

                        // Initialize a mail address collection and set attendees mail address
                        MailAddressCollection attendees = new MailAddressCollection();
                        attendees.Add("*****@*****.**");
                        attendees.Add("*****@*****.**");

                        // Create an appointment with above attendees
                        Appointment app1 = new Appointment("Location - " + Guid.NewGuid().ToString(), startDate, endDate, User2.EMail, attendees);

                        // Set appointment summary, description, start/end time zone
                        app1.Summary       = "Summary - " + Guid.NewGuid().ToString();
                        app1.Description   = "Description - " + Guid.NewGuid().ToString();
                        app1.StartTimeZone = "Europe/Kiev";
                        app1.EndTimeZone   = "Europe/Kiev";

                        // Insert appointment in the first calendar inserted above and get back inserted appointment
                        Appointment app2 = client.CreateAppointment(calendarId1, app1);

                        // Retrieve appointment using unique id
                        Appointment app3 = client.FetchAppointment(calendarId1, app2.UniqueId);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                // ExEnd:AddingAnAppointment
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public static void Run()
        {
            try
            {
                // ExStart:QueryingCalendar
                // Get access token
                GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret");
                string         accessToken;
                string         refreshToken;
                GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken);

                // Get IGmailClient
                using (IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail))
                {
                    // Initialize calendar item
                    Aspose.Email.Clients.Google.Calendar calendar1 = new Aspose.Email.Clients.Google.Calendar("summary - " + Guid.NewGuid().ToString(), null, null, "Europe/Kiev");

                    // Insert calendar and get back id of newly inserted calendar and Fetch the same calendar using calendar id
                    string id = client.CreateCalendar(calendar1);
                    Aspose.Email.Clients.Google.Calendar cal1 = client.FetchCalendar(id);
                    string calendarId1 = cal1.Id;
                    try
                    {
                        // Get list of appointments in newly inserted calendar. It should be zero
                        Appointment[] appointments = client.ListAppointments(calendarId1);
                        if (appointments.Length != 0)
                        {
                            Console.WriteLine("Wrong number of appointments");
                            return;
                        }

                        // Create a new appointment and Calculate appointment start and finish time
                        DateTime startDate = DateTime.Now;
                        DateTime endDate   = startDate.AddHours(1);

                        // Create attendees list for appointment
                        MailAddressCollection attendees = new MailAddressCollection();
                        attendees.Add("*****@*****.**");
                        attendees.Add("*****@*****.**");

                        // Create appointment
                        Appointment app1 = new Appointment("Location - " + Guid.NewGuid().ToString(), startDate, endDate, "*****@*****.**", attendees);
                        app1.Summary       = "Summary - " + Guid.NewGuid().ToString();
                        app1.Description   = "Description - " + Guid.NewGuid().ToString();
                        app1.StartTimeZone = "Europe/Kiev";
                        app1.EndTimeZone   = "Europe/Kiev";

                        // Insert the newly created appointment and get back the same in case of successful insertion
                        Appointment app2 = client.CreateAppointment(calendarId1, app1);

                        // Create Freebusy query by setting min/max timeand time zone
                        FreebusyQuery query = new FreebusyQuery();
                        query.TimeMin  = DateTime.Now.AddDays(-1);
                        query.TimeMax  = DateTime.Now.AddDays(1);
                        query.TimeZone = "Europe/Kiev";

                        // Set calendar item to search and Get the reponse of query containing
                        query.Items.Add(cal1.Id);
                        FreebusyResponse resp = client.GetFreebusyInfo(query);
                        // Delete the appointment
                        client.DeleteAppointment(calendarId1, app2.UniqueId);
                    }
                    finally
                    {
                        // Delete the calendar
                        client.DeleteCalendar(cal1.Id);
                    }
                }
                // ExEnd:QueryingCalendar
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }