public static void Run() { try { // ExStart:DeleteParticularCalendar // 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)) { // Access and delete calendar with summary starting from "Calendar summary - " string summary = "Calendar summary - "; // Get calendars list ExtendedCalendar[] lst0 = client.ListCalendars(); foreach (ExtendedCalendar extCal in lst0) { // Delete selected calendars if (extCal.Summary.StartsWith(summary)) { client.DeleteCalendar(extCal.Id); } } } // ExEnd:DeleteParticularCalendar } catch (Exception ex) { Console.WriteLine(ex.Message); } }
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); } }
public static void Run() { try { // ExStart:ManageAccessRule 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)) { // Retrieve list of calendars for the current client ExtendedCalendar[] calendarList = client.ListCalendars(); // Get first calendar id and retrieve list of AccessControlRule for the first calendar string calendarId = calendarList[0].Id; AccessControlRule[] roles1 = client.ListAccessRules(calendarId); // Create a local access control rule and Set rule properties AccessControlRule rule = new AccessControlRule(); rule.Role = AccessRole.reader; rule.Scope = new AclScope(AclScopeType.user, User2.EMail); // Insert new rule for the calendar. It returns the newly created rule AccessControlRule createdRule = client.CreateAccessRule(calendarId, rule); // Confirm if local created rule and returned rule are equal if ((rule.Role == createdRule.Role) && (rule.Scope.Type == createdRule.Scope.Type) && (rule.Scope.Value.ToLower() == createdRule.Scope.Value.ToLower())) { Console.WriteLine("local rule and returned rule after creation are equal"); } else { Console.WriteLine("Rule could not be created successfully"); return; } // Get list of rules AccessControlRule[] roles2 = client.ListAccessRules(calendarId); // Current list length should be 1 more than the earlier one if (roles1.Length + 1 == roles2.Length) { Console.WriteLine("List lengths are ok"); } else { Console.WriteLine("List lengths are not ok"); return; } // Change rule and Update the rule for the selected calendar createdRule.Role = AccessRole.writer; AccessControlRule updatedRule = client.UpdateAccessRule(calendarId, createdRule); // Check if returned access control rule after update is ok if ((createdRule.Role == updatedRule.Role) && (createdRule.Id == updatedRule.Id)) { Console.WriteLine("Rule is updated successfully"); } else { Console.WriteLine("Rule is not updated"); return; } // Retrieve individaul rule against a calendar AccessControlRule fetchedRule = client.FetchAccessRule(calendarId, createdRule.Id); //Check if rule parameters are ok if ((updatedRule.Id == fetchedRule.Id) && (updatedRule.Role == fetchedRule.Role) && (updatedRule.Scope.Type == fetchedRule.Scope.Type) && (updatedRule.Scope.Value.ToLower() == fetchedRule.Scope.Value.ToLower())) { Console.WriteLine("Rule parameters are ok"); } else { Console.WriteLine("Rule parameters are not ok"); } // Delete particular rule against a given calendar and Retrieve the all rules list for the same calendar client.DeleteAccessRule(calendarId, createdRule.Id); AccessControlRule[] roles3 = client.ListAccessRules(calendarId); // Check that current rules list length should be equal to the original list length before adding and deleting the rule if (roles1.Length == roles3.Length) { Console.WriteLine("List lengths are same"); } else { Console.WriteLine("List lengths are not equal"); return; } } // ExEnd:ManageAccessRule } catch (Exception ex) { Console.WriteLine(ex.Message); } }