Exemplo n.º 1
0
        public void ClearCalendarEventByGroupName(string groupname)
        {
            // If modifying these scopes, delete your previously saved credentials
            // at ~/.credentials/calendar-dotnet-quickstart.json

            using (CalendarService service = new CalendarService(new BaseClientService.Initializer {
                HttpClientInitializer = credential, ApplicationName = ApplicationName,
            }))
            {
                // Define parameters of request.
                EventsResource.ListRequest request2 = service.Events.List("primary");
                request2.SharedExtendedProperty = "GroupName=" + groupname;
                request2.ShowDeleted            = false;
                request2.SingleEvents           = true;
                request2.MaxResults             = 100;
                request2.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime;

                // List events.
                Events events = request2.Execute();
                if (events.Items != null && events.Items.Count > 0)
                {
                    foreach (var eventItem in events.Items)
                    {
                        richTextBox2.Text = richTextBox2.Text + "Delete event '" + eventItem.Summary + "'\n";
                        EventsResource.DeleteRequest request3 = service.Events.Delete(CalendarId, eventItem.Id);
                        request3.Execute();
                        Thread.Sleep(1000);
                    }
                }
            }
        }
        /// <summary>
        /// Удаление событие календаря
        /// </summary>
        /// <param name="eventForDel">Событие</param>
        public void DeleteEvent(Event eventForDel, string calendarName)
        {
            if (isConnect)
            {
                EventsResource.DeleteRequest request = new EventsResource.DeleteRequest(Service, calendarName, eventForDel.Id);
                WorkBD.Execution_query($"delete from Events_calendar where Id_Event = N'{eventForDel.Id}'");
                request.Execute();
            }
            else
            {
                int idEvent = 0;

                var result = WorkBD.Select_query($"select Id from Events_Calendar where Id_Event = N'{eventForDel.Id}'");

                if (result.Rows.Count > 0)
                {
                    idEvent = int.Parse(result.Rows[0].ItemArray[0].ToString());
                    WorkBD.Execution_query($"insert into Del_Event (Event_Cal_id) values ((select Id from Activity where EvendId = {idEvent}))");
                }
                else
                {
                    var nextVariant = WorkBD.Select_query($"select Id from Ins_Event where Id_New_Ev = N'{eventForDel.Id}'");

                    if (nextVariant.Rows.Count > 0)
                    {
                        idEvent = int.Parse(nextVariant.Rows[0].ItemArray[0].ToString());

                        WorkBD.Execution_query($"delete from Ins_Event where Id = {idEvent}");
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void ClearCalendarEventsByDatetime(CalendarService service, string startDate, string endDate, string group)
        {
            // Define parameters of request.
            EventsResource.ListRequest request2 = service.Events.List("primary");
            request2.TimeMin = DateTime.Parse(startDate);
            request2.TimeMax = DateTime.Parse(endDate);
            request2.SharedExtendedProperty = "GroupName=" + group;
            request2.ShowDeleted            = false;
            request2.SingleEvents           = true;
            request2.MaxResults             = 100;
            request2.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime;

            // List events.
            Events events = request2.Execute();

            //richTextBox2.Text = richTextBox2.Text + "Founded events:\n\n";
            if (events.Items != null && events.Items.Count > 0)
            {
                foreach (var eventItem in events.Items)
                {
                    richTextBox2.Text = richTextBox2.Text + "Delete event '" + eventItem.Summary + "'\n";
                    EventsResource.DeleteRequest request3 = service.Events.Delete(CalendarId, eventItem.Id);
                    request3.Execute();
                }
            }
        }
        private void DeleteEvents(CalendarService _service)
        {
            string CalendarId = "";

            EventsResource.DeleteRequest Delrequest = new EventsResource.DeleteRequest(_service, UserEmail, CalendarId);
            Delrequest.Execute();
        }
Exemplo n.º 5
0
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            if (selEvent != null)
            {
                try
                {
                    EventsResource.DeleteRequest delReq = new EventsResource.DeleteRequest(myService, "primary", selEvent.Id);
                    string deletedTitle = selEvent.Summary;
                    addAttendees(selEvent);
                    delReq.Execute();

                    if (deletedTitle == null)
                    {
                        MessageBox.Show("The selected event has been deleted.");
                    }
                    else
                    {
                        MessageBox.Show("The selected event, titled " + deletedTitle + ", has been deleted.");
                    }
                }
                catch (Google.GoogleApiException)
                {
                    MessageBox.Show("The selected event has already been deleted.");
                }

                selEvent = null;
                EventListBox.SelectedItem = null;

                setReadRequest();
                EventListBox.DataContext = request.Execute();
            }
        }
Exemplo n.º 6
0
        public bool RemoveCalendarEvent(Item item)
        {   // remove CalendarEvent
            Item       metaItem     = storage.UserFolder.GetEntityRef(user, item);
            FieldValue fvCalEventID = metaItem.GetFieldValue(ExtendedFieldNames.CalEventID, true);

            if (!string.IsNullOrEmpty(fvCalEventID.Value))
            {   // CalendarEvent has been added for this Item
                try
                {
                    Event calEvent = GetCalendarEvent(fvCalEventID.Value);
                    if (calEvent != null)
                    {   // remove existing CalendarEvent
                        EventsResource.DeleteRequest eventDeleteReq = this.CalendarService.Events.Delete(UserCalendar, calEvent.Id);
                        string result = eventDeleteReq.Fetch();
                        // EntityRef holding association will get cleaned up when Item is deleted
                        return(result == string.Empty);
                    }
                }
                catch (Exception e)
                {
                    TraceLog.TraceException("Could not remove appointment from Calendar", e);
                }
            }
            return(false);
        }
Exemplo n.º 7
0
        public async Task <bool> RemoveEvent(string eventId, string calendarID)
        {
            var service = GetCalendarService();

            EventsResource.DeleteRequest request = service.Events.Delete(calendarID, eventId);
            var res = await request.ExecuteAsync();

            return(true);
        }
Exemplo n.º 8
0
        public async Task DeleteEvent(string eventId, string calendar = "primary")
        {
            if (calService == null)
            {
                await Auth(EditScopes);
            }

            EventsResource.DeleteRequest req = calService.Events.Delete(calendar, eventId);
            await req.ExecuteAsync();
        }
Exemplo n.º 9
0
 public void DeleteAppointment(string id)
 {
     EventsResource.DeleteRequest deleteRequest = service.Events.Delete("primary", id);
     try
     {
         deleteRequest.Execute();
     }
     catch
     {
     }
 }
Exemplo n.º 10
0
 private static void tryExecuteEvent(EventsResource.DeleteRequest gEvent, int tries)
 {
     for (int i = 0; i < tries; i++)
     {
         try
         {
             gEvent.Execute();
             return;
         }
         catch { };
     }
 }
Exemplo n.º 11
0
 // Kill spezifischen Eintrag, return Erfolg oder Misserfolg
 public Boolean kalenderEventRemove(String ID)
 {
     try
     {
         EventsResource.DeleteRequest request = dienst.Events.Delete("primary", ID);
         request.Execute();
     }
     catch (Exception)
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 12
0
        public async Task DeleteAppointmentAsync(ILoadedAppointment appointment)
        {
            using (Logger.Scope($"GoogleCalendar.UpdateAppointment(\"{appointment}\")"))
            {
                var googleAppointment = appointment as GoogleCalendarAppointment
                                        ?? throw new ArgumentException("Cannot delete appointment from a different calendar");

                EventsResource.DeleteRequest request = _service.Events.Delete(CalendarId, googleAppointment.GoogleCalendarEventId);
                await request.ExecuteAsync().ConfigureAwait(false);

                Logger.Verbose($"Deleted event \"{appointment}\" on {appointment.Schedule?.Start:d}");
            }
        }
Exemplo n.º 13
0
        public async Task DeleteEvent(string GoogleEventId, string userId)
        {
            var userToken = await _db.UserGoogleToken.FirstOrDefaultAsync(u => u.UserId == userId);

            if (userToken != null && GoogleEventId != null)
            {
                UserCredential credential = await GetCredential(userToken.AccessToken, userToken.RefreshToken, userToken.IssuedAt, clientId, clientSecret);

                var service = new CalendarService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName       = "Futurify Vacation",
                });
                EventsResource.DeleteRequest deleteEvent = service.Events.Delete(calendarId, GoogleEventId);
                await deleteEvent.ExecuteAsync();
            }
        }
Exemplo n.º 14
0
        public static async Task <bool> DeleteEvent(string calendarId, string eventId)
        {
            UserCredential credential;

            CalendarService service;

            SetupRequest(out credential, out service);
            EventsResource.DeleteRequest request = service.Events.Delete(calendarId, eventId);
            var result = await request.ExecuteAsync();

            if (result != null)
            {
                Console.WriteLine("Event Deleted");
                return(true);
            }

            Console.WriteLine("Event Not Deleted");
            return(false);
        }
Exemplo n.º 15
0
 public void Delete(string calendarId, string eventId)
 {
     EventsResource.DeleteRequest request = service.Events.Delete(calendarId, eventId);
 }
Exemplo n.º 16
0
        public async Task <IActionResult> Post()
        {
            try
            {
                string body;
                using (var reader = new StreamReader(Request.Body))
                {
                    body = await reader.ReadToEndAsync();
                }

                var eventsToImport = body.Split(new[] { "->" }, StringSplitOptions.RemoveEmptyEntries)
                                     .Select(e => new CalendarEvent(e))
                                     .ToList();

                var credential = new ServiceAccountCredential(
                    new ServiceAccountCredential.Initializer(_settings.ServiceAccountEmail)
                {
                    Scopes = new[] { CalendarService.Scope.Calendar }
                }.FromPrivateKey(_settings.PrivateKey));

                // Create the service.
                var service = new CalendarService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName       = _settings.ApplicationName
                });

                var listRequest =
                    service.Events.List(_settings.CalendarId);
                listRequest.TimeMin = DateTime.Now.Date;

                // Take the last date of the passed events to determine the range
                // By having the same range we're able to cleanup deleted events not found in the Google calendar
                var upperLimit = eventsToImport.Any()
                    ? eventsToImport.OrderByDescending(e => e.DateTimeIdentifier).FirstOrDefault().End
                    : DateTime.Now.AddDays(10);

                listRequest.TimeMax     = upperLimit;
                listRequest.ShowDeleted = false;

                // Dealing with recurring events just causes more effort for this simple use case so we treat them as single events
                listRequest.SingleEvents = true;
                listRequest.MaxResults   = 1000;
                listRequest.OrderBy      = EventsResource.ListRequest.OrderByEnum.StartTime;

                var eventsFromGoogle = listRequest.Execute();

                // Delete old events
                var eventsToDelete = eventsFromGoogle.Items
                                     .Where(gEvent => !eventsToImport.Any(z => z.IsEqualToGoogle(gEvent))).ToList();

                foreach (var @event in eventsToDelete)
                {
                    var deleteRequest = new EventsResource.DeleteRequest(service, _settings.CalendarId, @event.Id);
                    await deleteRequest.ExecuteAsync();
                }

                // We get all the new events that are not stored in the Google calendar so far
                // Not very efficient code, but for these few events it will not hurt that much :-)
                var todo = eventsToImport.Where(e => !eventsFromGoogle.Items.Any(e.IsEqualToGoogle)).ToList();

                foreach (var calendarEvent in todo)
                {
                    var begin = new EventDateTime {
                        DateTime = calendarEvent.Start, TimeZone = "Europe/Zurich"
                    };
                    var end = new EventDateTime {
                        DateTime = calendarEvent.End, TimeZone = "Europe/Zurich"
                    };

                    var @event = new Event
                    {
                        Start   = begin,
                        End     = end,
                        Created = DateTime.Now,
                        Summary = calendarEvent.Title.StartsWith("Work@", StringComparison.OrdinalIgnoreCase)
                            ? $"{calendarEvent.Title} (via Phone)"
                            : "n/a"
                    };

                    // Using ical doesn't make it easier -> We use our own datetime based identifier
                    // @event.ICalUID = calendarEvent.Id;
                    var insertRequest = service.Events.Insert(@event, _settings.CalendarId);

                    await insertRequest.ExecuteAsync();
                }


                return(Ok($"Created {todo.Count}; Removed {eventsToDelete.Count()}"));
            }

            catch (Exception e)
            {
                // Most likely the input was not correct; Not a nice errror handling here but sufficient
                return(BadRequest(e.Message));
            }
        }
 public string deleteFromGoogleCalendar(Event googleAppointment)
 {
     EventsResource.DeleteRequest request = service.Events.Delete(calendarId, googleAppointment.Id);
     return(request.Execute());
 }
 public void DeleteEvent(string eventIdToDelete, string calendarId, bool sendNotifications = false)
 {
     EventsResource.DeleteRequest eventDeleteRequest = service.Events.Delete(calendarId, eventIdToDelete);
     eventDeleteRequest.SendNotifications = sendNotifications;
     DoActionWithExponentialBackoff(eventDeleteRequest, new HttpStatusCode[] { HttpStatusCode.Gone }, new HttpStatusCode[0]);
 }