protected void UpdateEventInPSTable(Google.Apis.Calendar.v3.Data.Event googleEvent, string account)
        {
            PSCalendarContract.Dto.GoogleEvent @event = CalendarSyncBL.GetEvent(googleEvent.Id);

            @event.Name = googleEvent.Summary;
            if (googleEvent.Start.DateTime.HasValue)
            {
                @event.StartDate = googleEvent.Start.DateTime.Value;
            }
            else
            {
                @event.StartDate = DateTime.Parse(googleEvent.Start.Date);
            }

            if (googleEvent.End.DateTime.HasValue)
            {
                @event.EndDate = googleEvent.End.DateTime.Value;
            }
            else
            {
                @event.EndDate = DateTime.Parse(googleEvent.End.Date);
            }

            //    @event.EndDate = googleEvent.End.DateTime.Value;
            //todo: change to automapper
            CalendarCoreBL.ChangeEvent(@event);
        }
 private async Task <Event> ToEvent(Google.Apis.Calendar.v3.Data.Event v, string feedId, string providerFeedId)
 {
     if (!v.End.DateTime.HasValue)
     {
         throw new InvalidEventException($"End DateTime of event {v.Summary} was null, raw: {v.End.DateTimeRaw}.");
     }
     if (!v.Start.DateTime.HasValue)
     {
         throw new InvalidEventException($"Start DateTime of event {v.Summary} was null, raw: {v.Start.DateTimeRaw}.");
     }
     return(new Event()
     {
         End = new DateTimeOffset(v.End.DateTime.Value),
         Start = new DateTimeOffset(v.Start.DateTime.Value),
         Subject = v.Summary,
         Location = new LocationData()
         {
             Text = v.Location
         },
         IsAllDay = false,
         Id = v.Id,
         FeedId = feedId,
         Category = await _googleCalendarColorProvider.GetCategory(v, providerFeedId)
     });
 }
        public async Task <EventCategory> GetCategory(Google.Apis.Calendar.v3.Data.Event e,
                                                      string feedId)
        {
            var colors = await GetColors();

            if (null != e.ColorId)
            {
                if (colors.Event__.TryGetValue(e.ColorId, out Google.Apis.Calendar.v3.Data.ColorDefinition eventColor))
                {
                    return(new EventCategory()
                    {
                        Background = eventColor.Background,
                        Foreground = eventColor.Foreground,
                        Name = e.ColorId
                    });
                }
            }
            var calendarListEntry = await GetCalendarListEntry(feedId);

            if (null != calendarListEntry?.ColorId)
            {
                if (colors.Calendar.TryGetValue(calendarListEntry.ColorId, out Google.Apis.Calendar.v3.Data.ColorDefinition feedColor))
                {
                    return(new EventCategory()
                    {
                        Background = feedColor.Background,
                        Foreground = feedColor.Foreground,
                        Name = null
                    });
                }
            }
            return(null);
        }
Example #4
0
 public GoogleEvent(Google.Apis.Calendar.v3.Data.Event googleEvent)
 {
     Id                  = googleEvent.Id;
     Summary             = googleEvent.Summary;
     StartDate           = GetStartDate(googleEvent);
     EndDate             = GetEndDate(googleEvent);
     IsLongMultiDayEvent = (EndDate - StartDate).TotalDays > 2;
 }
Example #5
0
 private bool GoogleEventDeleted(Google.Apis.Calendar.v3.Data.Event googleCalendarEvent)
 {
     if (googleCalendarEvent.Status == GoogleCalendarAPI.EventNotFound)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #6
0
        public Event(Google.Apis.Calendar.v3.Data.Event targetEvent)
        {
            InitializeComponent();

            TargetEvent = targetEvent;

            DateField.Value            = TargetEvent.Start.DateTime;
            NameField.Text             = TargetEvent.Summary;
            PlaceField.Text            = TargetEvent.Location;
            DescrioptionField.Text     = TargetEvent.Description;
            DurationField.Text         = (TargetEvent.End.DateTime - TargetEvent.Start.DateTime).ToString();
            NotifyBeforeField.Text     = "00:30:00";
            GuestsListView.ItemsSource = TargetEvent.Attendees;
        }
Example #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EventModel"/> class.
        /// </summary>
        /// <param name="source">the event source.</param>
        public EventModel(EventSource source)
        {
            this.source = source;
            switch (this.source)
            {
            case EventSource.Microsoft:
                msftEventData = new Microsoft.Graph.Event();
                break;

            case EventSource.Google:
                gmailEventData = new Google.Apis.Calendar.v3.Data.Event();
                break;

            default:
                throw new Exception("Event Type not Defined");
            }
        }
Example #8
0
        private void AddTidesToGoogleCalendar(DateTime startTime, double hoursToUpdate, double height)
        {
            List <Google.Apis.Calendar.v3.Data.Event> calendarEvents = new List <Google.Apis.Calendar.v3.Data.Event>();

            // find all {height} foot tides for today
            List <double> sevenFootTides        = this.constituents.FindTimesForHeight(height, this.HoursSinceEpochStart(startTime), hoursToUpdate);
            double        previousTideSpeed     = -1000;
            DateTime      previousSevenFootTime = DateTime.Now;

            // now build google calendar events for each {height} foot tide
            foreach (double sevenFootTide in sevenFootTides)
            {
                Google.Apis.Calendar.v3.Data.Event calendarEvent = new Google.Apis.Calendar.v3.Data.Event();
                DateTime sevenFootTime    = this.DateTimeFromHoursSinceEpochStart(sevenFootTide);
                double   tideHeight       = this.constituents.PredictTideHeight(sevenFootTide);
                double   tideSpeed        = this.constituents.PredictRateOfChange(sevenFootTide);
                double   tideAcceleration = this.constituents.PredictAccelerationOfChange(sevenFootTide);

                calendarEvent.Summary = $"{height.ToString("0.0")}ft+ tide ";

                if (tideSpeed < 0 && previousTideSpeed > 0)
                {
                    calendarEvent.Start = new Google.Apis.Calendar.v3.Data.EventDateTime()
                    {
                        DateTime = previousSevenFootTime, TimeZone = "America/Los_Angeles"
                    };
                    calendarEvent.End = new Google.Apis.Calendar.v3.Data.EventDateTime()
                    {
                        DateTime = sevenFootTime, TimeZone = "America/Los_Angeles"
                    };
                    calendarEvents.Add(calendarEvent);
                }

                previousTideSpeed     = tideSpeed;
                previousSevenFootTime = sevenFootTime;
            }
            // now add all tide events to the google calendar
            this.AddGoogleCalendarEvents(calendarEvents, "*****@*****.**");
        }
        /// <summary>
        /// Metoda dodaje wydarzenie do kolejki zdarzeń.
        /// </summary>
        /// <param name="guest">Rezerwacja, która zostanie dodana do kolejki.</param>
        /// <param name="user">Użytkownik, któremu zostanie zakolejkowane wydarzenie.</param>
        private static void AddEventToQueue(SimpleBookingUser guest, User user)
        {
            Logs.WriteErrorLog("AddEventToQueue");
            var eventStartDateTime = new Google.Apis.Calendar.v3.Data.EventDateTime {
                DateTime = guest.BookingBeginTime
            };
            var eventEndDateTime = new Google.Apis.Calendar.v3.Data.EventDateTime {
                DateTime = guest.BookingEndTime
            };

            var e = new Google.Apis.Calendar.v3.Data.Event()
            {
                Start       = eventStartDateTime,
                End         = eventEndDateTime,
                Description = guest.BookingDescription,
                Summary     = guest.BookingTitle,
                Location    = guest.BookingRoomName
            };

            user.Calendar.EventsQueue.Enqueue(e);
            Logs.WriteErrorLog("Koniec AddEventToQueue");
        }
Example #10
0
 public void Load(Google.Apis.Calendar.v3.Data.Event remote_event)
 {
     this.DateUpdated = remote_event.Updated.GetValueOrDefault(DateTime.MinValue);
     this.DateFrom    = remote_event.Start.DateTime.GetValueOrDefault(DateTime.MinValue);
     this.DateTill    = remote_event.End.DateTime.GetValueOrDefault(DateTime.MinValue);
     if (this.DateFrom == DateTime.MinValue)
     {
         try { this.DateFrom = DateTime.ParseExact(remote_event.Start.Date, "yyyy-MM-dd", CultureInfo.InvariantCulture); this.IsFullDay = true; } catch (Exception) { }
     }
     if (this.DateTill == DateTime.MinValue)
     {
         try { this.DateTill = DateTime.ParseExact(remote_event.End.Date, "yyyy-MM-dd", CultureInfo.InvariantCulture); } catch (Exception) { }
     }
     this.Subject   = remote_event.Summary;
     this.Body      = remote_event.Description;
     this.Organiser = remote_event.Organizer.DisplayName + " <" + remote_event.Organizer.Email + ">";
     this.Attendees.Add(this.Organiser);
     if (remote_event.Attendees != null)
     {
         this.Attendees.AddRange(remote_event.Attendees.Where(x => x.Email != remote_event.Organizer.Email).Select(x => x.DisplayName + " <" + x.Email + ">"));
     }
     this.Location  = remote_event.Location;
     this.Tentative = remote_event.Status == "tentative";
 }
Example #11
0
        private void AddSlackTidesToGoogleCalendar(DateTime startTime, double hoursToUpdate)
        {
            List <Google.Apis.Calendar.v3.Data.Event> calendarEvents = new List <Google.Apis.Calendar.v3.Data.Event>();

            // find all slack tides for today
            List <double> slackTides = this.constituents.FindTimesForRateOfChange(0, this.HoursSinceEpochStart(startTime), hoursToUpdate);

            // now build google calendar events for each slack tide
            foreach (double slackHoursSinceEpochStart in slackTides)
            {
                Google.Apis.Calendar.v3.Data.Event calendarEvent = new Google.Apis.Calendar.v3.Data.Event();
                DateTime slackTime        = this.DateTimeFromHoursSinceEpochStart(slackHoursSinceEpochStart);
                double   tideHeight       = this.constituents.PredictTideHeight(slackHoursSinceEpochStart);
                double   tideSpeed        = this.constituents.PredictRateOfChange(slackHoursSinceEpochStart);
                double   tideAcceleration = this.constituents.PredictAccelerationOfChange(slackHoursSinceEpochStart);

                calendarEvent.Summary = "High Tide " + tideHeight.ToString("0.0") + " ft";
                if (tideAcceleration > 0)
                {
                    calendarEvent.Summary = "Low Tide " + tideHeight.ToString("0.0") + " ft";
                }

                calendarEvent.Start = new Google.Apis.Calendar.v3.Data.EventDateTime()
                {
                    DateTime = slackTime, TimeZone = "America/Los_Angeles"
                };
                calendarEvent.End = new Google.Apis.Calendar.v3.Data.EventDateTime()
                {
                    DateTime = slackTime + new TimeSpan(0, 5, 0), TimeZone = "America/Los_Angeles"
                };
                calendarEvents.Add(calendarEvent);
            }

            // now add all tide events to the google calendar
            this.AddGoogleCalendarEvents(calendarEvents, "*****@*****.**");
        }
 public GoogleCalendarEventSyncData(GoogleCalendarEvent calendarEvent)
 {
     GoogleCalendarEvent = calendarEvent;
     IsFromDefault = true;
 }
 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;
 }
Example #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EventModel"/> class from Google event.
 /// </summary>
 /// <param name="gmailEvent">Google event.</param>
 public EventModel(Google.Apis.Calendar.v3.Data.Event gmailEvent)
 {
     source         = EventSource.Google;
     gmailEventData = gmailEvent;
 }
Example #15
0
 public static void Log(Google.Apis.Calendar.v3.Data.Event e, EventType eventType)
 {
     Log("*** Google event ***", eventType);
     Log(" - AnyoneCanAddSelf: " + (e.AnyoneCanAddSelf != null ? e.AnyoneCanAddSelf.ToString() : "null"), eventType);
     if (e.Attachments != null)
     {
         Log(" - Attachments:", eventType);
         foreach (var a in e.Attachments)
         {
             Log("  - Title: " + (a.Title != null ? a.Title : "null"), eventType);
         }
     }
     if (e.Attendees != null)
     {
         Log(" - Attendees:", eventType);
         foreach (var a in e.Attendees)
         {
             Log("  - DisplayName: " + (a.DisplayName != null ? a.DisplayName : "null"), eventType);
         }
     }
     Log(" - AttendeesOmitted: " + (e.AttendeesOmitted != null ? e.AttendeesOmitted.ToString() : "null"), eventType);
     Log(" - ColorId: " + (e.ColorId != null ? e.ColorId : "null"), eventType);
     Log(" - Created: " + (e.Created != null ? e.Created.ToString() : "null"), eventType);
     Log(" - CreatedRaw: " + (e.CreatedRaw != null ? e.CreatedRaw : "null"), eventType);
     if (e.Creator != null)
     {
         Log(" - Creator:", eventType);
         Log("  - DisplayName: " + (e.Creator.DisplayName != null ? e.Creator.DisplayName : "null"), eventType);
     }
     Log(" - Description: " + (e.Description != null ? e.Description : "null"), eventType);
     if (e.End != null)
     {
         Log(" - End:", eventType);
         if (!string.IsNullOrEmpty(e.End.Date))
         {
             Log("  - Date: " + e.End.Date, eventType);
         }
         if (e.End.DateTime != null)
         {
             Log("  - DateTime: " + e.End.DateTime.Value.ToString(), eventType);
         }
         if (!string.IsNullOrEmpty(e.End.TimeZone))
         {
             Log("  - TimeZone: " + e.End.TimeZone, eventType);
         }
     }
     Log(" - EndTimeUnspecified: " + (e.EndTimeUnspecified != null ? e.EndTimeUnspecified.ToString() : "null"), eventType);
     if (e.ExtendedProperties != null)
     {
         Log(" - ExtendedProperties:", eventType);
         if (e.ExtendedProperties.Shared != null)
         {
             Log("  - Shared:", eventType);
             foreach (var p in e.ExtendedProperties.Shared)
             {
                 Log("   - Key: " + (p.Key != null ? p.Key : "null"), eventType);
                 Log("   - Value: " + (p.Value != null ? p.Value : "null"), eventType);
             }
         }
         if (e.ExtendedProperties.Private__ != null)
         {
             Log("  - Private__:", eventType);
             foreach (var p in e.ExtendedProperties.Private__)
             {
                 Log("   - Key: " + (p.Key != null ? p.Key : "null"), eventType);
                 Log("   - Value: " + (p.Value != null ? p.Value : "null"), eventType);
             }
         }
     }
     if (e.Gadget != null)
     {
         Log(" - Gadget:", eventType);
         if (!string.IsNullOrEmpty(e.Gadget.Title))
         {
             Log("  - Title: " + e.Gadget.Title, eventType);
         }
     }
     Log(" - GuestsCanInviteOthers: " + (e.GuestsCanInviteOthers != null ? e.GuestsCanInviteOthers.ToString() : "null"), eventType);
     Log(" - GuestsCanModify: " + (e.GuestsCanModify != null ? e.GuestsCanModify.ToString() : "null"), eventType);
     Log(" - GuestsCanSeeOtherGuests: " + (e.GuestsCanSeeOtherGuests != null ? e.GuestsCanSeeOtherGuests.ToString() : "null"), eventType);
     Log(" - HangoutLink: " + (e.HangoutLink != null ? e.HangoutLink : "null"), eventType);
     Log(" - HtmlLink: " + (e.HtmlLink != null ? e.HtmlLink : "null"), eventType);
     Log(" - ICalUID: " + (e.ICalUID != null ? e.ICalUID : "null"), eventType);
     Log(" - Id: " + (e.Id != null ? e.Id : "null"), eventType);
     Log(" - Kind: " + (e.Kind != null ? e.Kind : "null"), eventType);
     Log(" - Location: " + (e.Location != null ? e.Location : "null"), eventType);
     Log(" - Locked: " + (e.Locked != null ? e.Locked.ToString() : "null"), eventType);
     if (e.Organizer != null)
     {
         Log(" - Organizer:", eventType);
         Log("  - DisplayName: " + (e.Organizer.DisplayName != null ? e.Organizer.DisplayName : "null"), eventType);
     }
     if (e.OriginalStartTime != null)
     {
         Log(" - OriginalStartTime:", eventType);
         if (!string.IsNullOrEmpty(e.OriginalStartTime.Date))
         {
             Log("  - Date: " + e.OriginalStartTime.Date, eventType);
         }
         if (e.OriginalStartTime.DateTime != null)
         {
             Log("  - DateTime: " + e.OriginalStartTime.DateTime.Value.ToString(), eventType);
         }
         if (!string.IsNullOrEmpty(e.OriginalStartTime.TimeZone))
         {
             Log("  - TimeZone: " + e.OriginalStartTime.TimeZone, eventType);
         }
     }
     Log(" - PrivateCopy: " + (e.PrivateCopy != null ? e.PrivateCopy.ToString() : "null"), eventType);
     if (e.Recurrence != null)
     {
         Log(" - Recurrence:", eventType);
         foreach (var r in e.Recurrence)
         {
             Log("  - : " + r, eventType);
         }
     }
     Log(" - RecurringEventId: " + (e.RecurringEventId != null ? e.RecurringEventId : "null"), eventType);
     if (e.Reminders != null)
     {
         Log(" - Reminders:", eventType);
         if (e.Reminders.UseDefault != null)
         {
             Log("  - UseDefault: " + e.Reminders.UseDefault.ToString(), eventType);
         }
         if (e.Reminders.Overrides != null)
         {
             Log("  - Overrides:", eventType);
             foreach (var o in e.Reminders.Overrides)
             {
                 Log("   - Minutes: " + (o.Minutes != null ? o.Minutes.ToString() : "null"), eventType);
             }
         }
     }
     Log(" - Sequence: " + (e.Sequence != null ? e.Sequence.ToString() : "null"), eventType);
     if (e.Source != null)
     {
         Log(" - Source:", eventType);
         Log("  - Url: " + (e.Source.Url != null ? e.Source.Url : "null"), eventType);
     }
     if (e.Start != null)
     {
         Log(" - Start:", eventType);
         if (!string.IsNullOrEmpty(e.Start.Date))
         {
             Log("  - Date: " + e.Start.Date, eventType);
         }
         if (e.Start.DateTime != null)
         {
             Log("  - DateTime: " + e.Start.DateTime.Value.ToString(), eventType);
         }
         if (!string.IsNullOrEmpty(e.Start.TimeZone))
         {
             Log("  - TimeZone: " + e.Start.TimeZone, eventType);
         }
     }
     Log(" - Status: " + (e.Status != null ? e.Status : "null"), eventType);
     Log(" - Summary: " + (e.Summary != null ? e.Summary : "null"), eventType);
     Log(" - Transparency: " + (e.Transparency != null ? e.Transparency : "null"), eventType);
     Log(" - Updated: " + (e.Updated != null ? e.Updated.ToString() : "null"), eventType);
     Log(" - UpdatedRaw: " + (e.UpdatedRaw != null ? e.UpdatedRaw : "null"), eventType);
     Log(" - Visibility: " + (e.Visibility != null ? e.Visibility : "null"), eventType);
     Log("*** Google event ***", eventType);
 }
        /// <summary> 
        /// Metoda dodaje wydarzenie do kolejki zdarzeń.
        /// </summary>
        /// <param name="guest">Rezerwacja, która zostanie dodana do kolejki.</param>
        /// <param name="user">Użytkownik, któremu zostanie zakolejkowane wydarzenie.</param>
        private static void AddEventToQueue(SimpleBookingUser guest, User user)
        {
            Logs.WriteErrorLog("AddEventToQueue");
            var eventStartDateTime = new Google.Apis.Calendar.v3.Data.EventDateTime { DateTime = guest.BookingBeginTime };
            var eventEndDateTime = new Google.Apis.Calendar.v3.Data.EventDateTime { DateTime = guest.BookingEndTime };

            var e = new Google.Apis.Calendar.v3.Data.Event()
            {
                Start = eventStartDateTime,
                End = eventEndDateTime,
                Description = guest.BookingDescription,
                Summary = guest.BookingTitle,
                Location = guest.BookingRoomName
            };
            user.Calendar.EventsQueue.Enqueue(e);
            Logs.WriteErrorLog("Koniec AddEventToQueue");
        }
Example #17
0
 private static DateTime GetEndDate(Google.Apis.Calendar.v3.Data.Event googleEvent)
 {
     return(googleEvent.End.Date != null
         ? DateTime.Parse(googleEvent.End.Date).Date
         : googleEvent.End.DateTime.Value.Date);
 }
        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);
        }
Example #19
0
        private Google.Apis.Calendar.v3.Data.Event UpdateEventInGoogleCalendar(string account, Event item, Google.Apis.Calendar.v3.Data.Event googleCalendarEvent, string calendarid)
        {
            var r = SyncGoogleCalendarAPI.UpdateEvent(account, item, googleCalendarEvent.Id, calendarid);

            return(r);
        }
Example #20
0
 private static bool GoogleEventIsMoreUpdatedThanPS(Google.Apis.Calendar.v3.Data.Event googleCalendarEvent, DateTime lastSyncAccountLogItemModyficationDate)
 {
     return(googleCalendarEvent.Updated.Value.TrimMilliseconds() > lastSyncAccountLogItemModyficationDate.TrimMilliseconds());
 }
Example #21
0
 public GoogleCalendarEventSyncData(GoogleCalendarEvent calendarEvent)
 {
     GoogleCalendarEvent = calendarEvent;
     IsFromDefault       = true;
 }