private void InsertNewEvent(CalendarService service, string eventName, string description, string startDate, string endDate, string location, string teacher, string group, EventAttendee[] mails) { Event.ExtendedPropertiesData exProp = new Event.ExtendedPropertiesData { Shared = new Dictionary <string, string> { { "GroupName", @group } } }; Event newEvent = new Event() { Summary = eventName, Location = location, Description = description, Start = new EventDateTime() { DateTime = DateTime.Parse(startDate), TimeZone = "Europe/Moscow", }, End = new EventDateTime() { DateTime = DateTime.Parse(endDate), TimeZone = "Europe/Moscow", }, ExtendedProperties = exProp, //Recurrence = new String[] { "RRULE:FREQ=DAILY;COUNT=2" }, /*Organizer = new Event.OrganizerData() * { * DisplayName = teacher, * Email = teacher, * Self = false * },*/ Attendees = mails , Reminders = new Event.RemindersData() { UseDefault = false, Overrides = new EventReminder[] { new EventReminder() { Method = "email", Minutes = 24 * 60 }, new EventReminder() { Method = "email", Minutes = 1 * 60 }, //new EventReminder() { Method = "sms", Minutes = 10 }, } }, }; EventsResource.InsertRequest request = service.Events.Insert(newEvent, CalendarId); request.SendNotifications = true; Event createdEvent = request.Execute(); richTextBox2.Text = richTextBox2.Text + "Event '" + createdEvent.Summary + "' created: " + createdEvent.HtmlLink + '\n'; Thread.Sleep(1000); }
public static bool AddUpdateDeleteEvent(List <GoogleCalendarAppointmentModel> GoogleCalendarAppointmentModelList, List <GoogleTokenModel> GoogleTokenModelList, double TimeOffset) { //Get the calendar service for a user to add/update/delete events CalendarService calService = GetCalendarService(GoogleTokenModelList[0]); if (GoogleCalendarAppointmentModelList != null && GoogleCalendarAppointmentModelList.Count > 0) { foreach (GoogleCalendarAppointmentModel GoogleCalendarAppointmentModelObj in GoogleCalendarAppointmentModelList) { EventsResource er = new EventsResource(calService); string ExpKey = "EventID"; string ExpVal = GoogleCalendarAppointmentModelObj.EventID; var queryEvent = er.List(calID); queryEvent.SharedExtendedProperty = ExpKey + "=" + ExpVal; //"EventID=9999" var EventsList = queryEvent.Execute(); //to restrict the appointment for specific staff only //Delete this appointment from google calendar if (GoogleCalendarAppointmentModelObj.DeleteAppointment == true) { string FoundEventID = String.Empty; foreach (Event evItem in EventsList.Items) { FoundEventID = evItem.Id; if (!String.IsNullOrEmpty(FoundEventID)) { er.Delete(calID, FoundEventID).Execute(); } } return(true); } //Add if not found OR update if appointment already present on google calendar else { Event eventEntry = new Event(); EventDateTime StartDate = new EventDateTime(); EventDateTime EndDate = new EventDateTime(); StartDate.Date = GoogleCalendarAppointmentModelObj.EventStartTime.ToString("yyyy-MM-dd"); //"2014-11-17"; EndDate.Date = StartDate.Date; //GoogleCalendarAppointmentModelObj.EventEndTime //Always append Extended Property whether creating or updating event Event.ExtendedPropertiesData exp = new Event.ExtendedPropertiesData(); exp.Shared = new Dictionary <string, string>(); exp.Shared.Add(ExpKey, ExpVal); eventEntry.Summary = GoogleCalendarAppointmentModelObj.EventTitle; eventEntry.Start = StartDate; eventEntry.End = EndDate; eventEntry.Location = GoogleCalendarAppointmentModelObj.EventLocation; eventEntry.Description = GoogleCalendarAppointmentModelObj.EventDetails; eventEntry.ExtendedProperties = exp; string FoundEventID = String.Empty; foreach (var evItem in EventsList.Items) { FoundEventID = evItem.Id; if (!String.IsNullOrEmpty(FoundEventID)) { //Update the event er.Update(eventEntry, calID, FoundEventID).Execute(); } } if (String.IsNullOrEmpty(FoundEventID)) { //create the event er.Insert(eventEntry, calID).Execute(); } return(true); } } } return(false); }
public async Task MakeEvents(IReadOnlyList <ScheduleDiff> schedule, WeekSchedule updatedWeekSchedule) { Calendar calendar = await _calendarService.GetCalendarById(_googleCalendarId); if (calendar == null) { throw new CalendarNotFoundException(_googleCalendarId); } var timezone = calendar.TimeZone; EventsResource.ListRequest request = _calendarService.CreateListRequestForWeek( _googleCalendarId, updatedWeekSchedule.Year, updatedWeekSchedule.WeekNumber); Events result = await _calendarService.GetEvents(request); var allRows = new List <Event>(); while (result.Items != null) { // Add the rows to the final list allRows.AddRange(result.Items); // We will know we are on the last page when the next page token is null. // If this is the case, break. if (result.NextPageToken == null) { break; } // Prepare the next page of results request.PageToken = result.NextPageToken; // Execute and process the next page request result = await _calendarService.GetEvents(request); } foreach (Event ev in allRows) { _ = await _calendarService.DeleteEvent(_googleCalendarId, ev); } // add items to calendar. IOrderedEnumerable <ScheduleDiff> addedSchedules = schedule .Where(x => x.Status is ScheduleStatus.Added or ScheduleStatus.Unchanged) .OrderBy(x => x.Start) .ThenBy(x => x.Status); foreach (ScheduleDiff item in addedSchedules) { var extendedProperty = new Event.ExtendedPropertiesData { Shared = new Dictionary <string, string> { { "Week", item.SingleShift.WeekSchedule.Year + "-" + item.SingleShift.WeekSchedule.WeekNumber }, }, }; var newEvent = new Event { Start = CreateEventDateTime(item.SingleShift.StartDateTime, timezone), End = CreateEventDateTime(item.SingleShift.EndDateTime, timezone), Description = string.Empty, Location = item.SingleShift.Location, Summary = item.SingleShift.Location, ExtendedProperties = extendedProperty, }; _ = await _calendarService.InsertEvent(_googleCalendarId, newEvent); } }
public void MakeEvents(IList <ScheduleDiff> schedule) { var weeks = schedule.Select(x => x.Schedule.Week).Distinct(); foreach (var w in weeks) { /* * List<string> xxy = new List<string>(); * //xxy.Add("MadeByApplication=Coen"); * xxy.Add("Week=" + w.Year + "-" + w.WeekNr); * var x = new Google.Apis.Util.Repeatable<string>(xxy); * * * * var request = calendarService.CreateListRequest(calendarId); * request.MaxResults = 100; * request.ShowDeleted = false; * * //request.SharedExtendedProperty = x; * request.SharedExtendedProperty = "Week=" + w.Year + "-"+ w.WeekNr; */ var request = calendarService.CreateListRequestForWeek(googleCalendarId, w); var result = calendarService.GetEvents(request); var allRows = new List <Event>(); while (result.Items != null) { //Add the rows to the final list allRows.AddRange(result.Items); // We will know we are on the last page when the next page token is // null. // If this is the case, break. if (result.NextPageToken == null) { break; } // Prepare the next page of results request.PageToken = result.NextPageToken; // Execute and process the next page request result = calendarService.GetEvents(request); } foreach (Event ev in allRows) { calendarService.DeleteEvent(googleCalendarId, ev); } } // add items to calendar. foreach (var item in schedule.Where(x => x.Status == ScheduleStatus.Added).OrderBy(x => x.Start).ThenBy(x => x.Status)) { var extendedProperty = new Event.ExtendedPropertiesData(); extendedProperty.Shared = new Dictionary <string, string>(); // x.Shared.Add("MadeByApplication", "Coen"); extendedProperty.Shared.Add("Week", item.Schedule.Week.Year + "-" + item.Schedule.Week.WeekNr); // queryEvent.SharedExtendedProperty = "EventID=3684"; var newEvent = new Event { Start = new EventDateTime { DateTime = item.Schedule.StartDateTime }, End = new EventDateTime { DateTime = item.Schedule.EndDateTime }, Description = "Ja, je moet werken! xx coen", Location = item.Schedule.Location, Summary = item.Schedule.Location, ExtendedProperties = extendedProperty }; var e = calendarService.InsertEvent(googleCalendarId, newEvent); } // [email protected] -> Gmail Account (default Kalender) // var request = service.Events.Create("*****@*****.**", newEvent); }