private async Task <PushedEvent> PushEvent(IEvent evt) { var googleEventId = StringHelper.GoogleBase32.ToBaseString(StringHelper.GetBytes(evt.Id)).ToLower(); Log.Debug(String.Format("Pushing event with googleEventId[{0}]", googleEventId)); Log.Debug(String.Format("and iCalUID [{0}]", evt.Id)); var res = new PushedEvent { Event = evt as GenericEvent }; // try { /* * Identifier of the event. When creating new single or recurring events, you can specify their IDs. Provided IDs must follow these rules: * characters allowed in the ID are those used in base32hex encoding, i.e. lowercase letters a-v and digits 0-9, see section 3.1.2 in RFC2938 * the length of the ID must be between 5 and 1024 characters * the ID must be unique per calendar * Due to the globally distributed nature of the system, we cannot guarantee that ID collisions will be detected at event creation time. To minimize the risk of collisions we recommend using an established UUID algorithm such as one described in RFC4122. */ var myEvt = new Google.Apis.Calendar.v3.Data.Event { Id = googleEventId }; // Id // Organizer if (evt.Organizer != null) { myEvt.Organizer = new Google.Apis.Calendar.v3.Data.Event.OrganizerData { DisplayName = evt.Organizer.Name, Email = evt.Organizer.Email }; } // Creator if (evt.Creator != null) { myEvt.Creator = new Google.Apis.Calendar.v3.Data.Event.CreatorData { DisplayName = evt.Creator.Name, Email = evt.Creator.Email }; } // Summary if (evt.Summary != "") { myEvt.Summary = evt.Summary; } // Description if (evt.Description != "") { myEvt.Description = evt.Description; } // Location if (evt.Location != null) { myEvt.Location = evt.Location.Name; } // Attendees if (evt.Attendees != null) { myEvt.Attendees = new List <Google.Apis.Calendar.v3.Data.EventAttendee>(); foreach (var person in evt.Attendees) { var r = person.Response.GetAttributeOfType <GoogleResponseStatus>(); myEvt.Attendees.Add(new Google.Apis.Calendar.v3.Data.EventAttendee { Email = person.Email, DisplayName = person.Name, ResponseStatus = r.Text }); } } // Start if (evt.Start.HasValue) { myEvt.Start = new Google.Apis.Calendar.v3.Data.EventDateTime { DateTime = evt.Start, TimeZone = "Europe/Rome" }; } // End if (evt.End.HasValue) { myEvt.End = new Google.Apis.Calendar.v3.Data.EventDateTime { DateTime = evt.End, TimeZone = "Europe/Rome" }; } else { myEvt.EndTimeUnspecified = true; } // Recurrency if (evt.Recurrence != null) { myEvt.Recurrence = new List <string> { evt.Recurrence.Get() }; } // Creation date if (evt.Created.HasValue) { myEvt.Created = evt.Created; } // myEvt.Reminders = new Google.Apis.Calendar.v3.Data.Event.RemindersData { UseDefault = true }; // var createdEvent = await Service.Events.Insert(myEvt, _settings.CalendarId).ExecuteAsync(); // if (createdEvent != null) { res.EventIsPushed = true; } } catch (GoogleApiException ex) { Log.Error("GoogleApiException", ex); res.EventIsPushed = false; } catch (AggregateException ex) { foreach (var e in ex.InnerExceptions) { Log.Error(e.GetType().ToString(), e); } res.EventIsPushed = false; } // return(res); }
private async Task<PushedEvent> PushEvent(IEvent evt) { var googleEventId = StringHelper.GoogleBase32.ToBaseString(StringHelper.GetBytes(evt.Id)).ToLower(); Log.Debug(String.Format("Pushing event with googleEventId[{0}]", googleEventId)); Log.Debug(String.Format("and iCalUID [{0}]", evt.Id)); var res = new PushedEvent {Event = evt as GenericEvent}; // try { /* Identifier of the event. When creating new single or recurring events, you can specify their IDs. Provided IDs must follow these rules: characters allowed in the ID are those used in base32hex encoding, i.e. lowercase letters a-v and digits 0-9, see section 3.1.2 in RFC2938 the length of the ID must be between 5 and 1024 characters the ID must be unique per calendar Due to the globally distributed nature of the system, we cannot guarantee that ID collisions will be detected at event creation time. To minimize the risk of collisions we recommend using an established UUID algorithm such as one described in RFC4122. */ var myEvt = new Google.Apis.Calendar.v3.Data.Event { Id = googleEventId }; // Id // Organizer if (evt.Organizer != null) { myEvt.Organizer = new Google.Apis.Calendar.v3.Data.Event.OrganizerData { DisplayName = evt.Organizer.Name, Email = evt.Organizer.Email }; } // Creator if (evt.Creator != null) { myEvt.Creator = new Google.Apis.Calendar.v3.Data.Event.CreatorData { DisplayName = evt.Creator.Name, Email = evt.Creator.Email }; } // Summary if (evt.Summary != "") { myEvt.Summary = evt.Summary; } // Description if (evt.Description != "") { myEvt.Description = evt.Description; } // Location if (evt.Location != null) { myEvt.Location = evt.Location.Name; } // Attendees if (evt.Attendees != null) { myEvt.Attendees = new List<Google.Apis.Calendar.v3.Data.EventAttendee>(); foreach (var person in evt.Attendees) { var r = person.Response.GetAttributeOfType<GoogleResponseStatus>(); myEvt.Attendees.Add(new Google.Apis.Calendar.v3.Data.EventAttendee { Email = person.Email, DisplayName = person.Name, ResponseStatus = r.Text }); } } // Start if (evt.Start.HasValue) { myEvt.Start = new Google.Apis.Calendar.v3.Data.EventDateTime { DateTime = evt.Start, TimeZone = "Europe/Rome" }; } // End if (evt.End.HasValue) { myEvt.End = new Google.Apis.Calendar.v3.Data.EventDateTime { DateTime = evt.End, TimeZone = "Europe/Rome" }; } else { myEvt.EndTimeUnspecified = true; } // Recurrency if (evt.Recurrence != null) { myEvt.Recurrence = new List<string> {evt.Recurrence.Get()}; } // Creation date if (evt.Created.HasValue) { myEvt.Created = evt.Created; } // myEvt.Reminders = new Google.Apis.Calendar.v3.Data.Event.RemindersData {UseDefault = true}; // var createdEvent = await Service.Events.Insert(myEvt, _settings.CalendarId).ExecuteAsync(); // if (createdEvent != null) { res.EventIsPushed = true; } } catch(GoogleApiException ex) { Log.Error("GoogleApiException", ex); res.EventIsPushed = false; } catch (AggregateException ex) { foreach (var e in ex.InnerExceptions) { Log.Error(e.GetType().ToString(), e); } res.EventIsPushed = false; } // return res; }