public static void Run() { try { // ExStart:InsertFetchAndUpdateCalendar // 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); using (IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail)) { // Insert, get and update calendar Aspose.Email.Clients.Google.Calendar calendar = new Aspose.Email.Clients.Google.Calendar("summary - " + Guid.NewGuid().ToString(), null, null, "America/Los_Angeles"); // Insert calendar and Retrieve same calendar using id string id = client.CreateCalendar(calendar); Aspose.Email.Clients.Google.Calendar cal = client.FetchCalendar(id); //Match the retrieved calendar info with local calendar if ((calendar.Summary == cal.Summary) && (calendar.TimeZone == cal.TimeZone)) { Console.WriteLine("fetched calendar information matches"); } else { Console.WriteLine("fetched calendar information does not match"); } // Change information in the fetched calendar and Update calendar cal.Description = "Description - " + Guid.NewGuid().ToString(); cal.Location = "Location - " + Guid.NewGuid().ToString(); client.UpdateCalendar(cal); } // ExEnd:InsertFetchAndUpdateCalendar } catch (Exception ex) { Console.WriteLine(ex.Message); } }
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); } }