// Just loops though getting all the rows.
        private CalendarList ProcessResults(CalendarListResource.ListRequest request)
        {
            var result  = request.Execute();
            var allRows = new List <CalendarListEntry>();

            //// Loop through until we arrive at an empty page
            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 = request.Execute();
            }

            var allData = result;

            allData.Items = allRows;
            return(allData);
        }
Пример #2
0
        public static void CreateGoogleCalendarEvent(string title, DateTime startTime, DateTime endTime, string calendar)
        {
            AuthorizeGoogleCalendar();

            CalendarListResource.ListRequest calRequest = calendarService.CalendarList.List();
            calRequest.MinAccessRole = CalendarListResource.ListRequest.MinAccessRoleEnum.Owner;
            CalendarList calendars = calRequest.Execute();

            CalendarListEntry reminderCalendar = calendars.Items.Where(p => p.Summary == calendar).FirstOrDefault();

            Event newReminderEvent = new Event()
            {
                Summary = title
            };

            newReminderEvent.Start = new EventDateTime()
            {
                DateTime = startTime
            };
            newReminderEvent.End = new EventDateTime()
            {
                DateTime = endTime
            };

            EventsResource.InsertRequest createRequest = calendarService.Events.Insert(newReminderEvent, reminderCalendar.Id);
            createRequest.Execute();
        }
Пример #3
0
        /// <summary>
        /// Retorna Todos os Calendarios Disponiveis para Sua Conta
        /// </summary>
        /// <returns>Lista de Calendarios</returns>
        public List <Calendario> ListarCalendarios()
        {
            try
            {
                List <Calendario> retorno = new List <Calendario>();
                Calendario        calendario;

                CalendarService service = _Autenticacao.Autenticar();
                CalendarListResource.ListRequest lista = service.CalendarList.List();
                CalendarList clist = lista.Execute();

                for (int i = 0; i < clist.Items.Count; i++)
                {
                    calendario           = new Calendario();
                    calendario.Id        = clist.Items[i].Id;
                    calendario.Nome      = clist.Items[i].Summary;
                    calendario.Descricao = clist.Items[i].Description;
                    retorno.Add(calendario);
                }


                return(retorno);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public CalendarList GetGoogleCalendars(string account)
        {
            CalendarListResource.ListRequest request = GetService(account).CalendarList.List();

            CalendarList x = request.Execute();

            return(x);
        }
        private static string GetMainCalendarId(CalendarService service)
        {
            var calendarListRequest = new CalendarListResource.ListRequest(service);
            var calendars           = calendarListRequest.Execute();
            var result = calendars.Items.First().Id;

            return(result);
        }
        public static string GetCalendarIdForName(this CalendarService service, string name)
        {
            CalendarListResource.ListRequest listRequest = service.CalendarList.List();
            CalendarList calendarList = listRequest.Execute();

            CalendarListEntry entry = calendarList.Items?.FirstOrDefault(e => e.Summary == name);

            return(entry?.Id);
        }
Пример #7
0
        private static CalendarListEntry GetCalendarListEntry(CalendarService service)
        {
            CalendarListResource.ListRequest calendarListRequest = service.CalendarList.List();
            CalendarList calendarList = calendarListRequest.Execute();

            CalendarListEntry dienstplan = calendarList.Items.FirstOrDefault(x => x.Summary == _calendarName);

            return(dienstplan);
        }
Пример #8
0
        public void Delete(int id)
        {
            using (var context = new DbGoogleContext())
            {
                var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(

                    new ClientSecrets
                {
                    ClientId     = "491606904456-nr7nscjo3l75na40kq939t35fd55i9o7.apps.googleusercontent.com",
                    ClientSecret = "xhc5pCiEoW54ch7aF_J8Ah69",
                },
                    new[] { CalendarService.Scope.Calendar },
                    "user",

                    CancellationToken.None).Result;
                try
                {
                    var service = new CalendarService(new BaseClientService.Initializer
                    {
                        HttpClientInitializer = credential,
                        ApplicationName       = "Calendar API Realtor",
                    });

                    CalendarListResource.ListRequest cal = service.CalendarList.List();
                    cal.MaxResults = 100;

                    var calresult = cal.Execute().Items;



                    foreach (CalendarListEntry entry in calresult)
                    {
                        EventsResource.ListRequest request = service.Events.List(entry.Id);
                        request.TimeMin      = Convert.ToDateTime("03/01/2019");
                        request.ShowDeleted  = false;
                        request.SingleEvents = true;
                        request.MaxResults   = 200;
                        request.OrderBy      = EventsResource.ListRequest.OrderByEnum.StartTime;
                        Events eventss = request.Execute();
                    }
                    var    eid        = new DbGoogleContext().Content.Where(d => d.Id == id).FirstOrDefault().EventId;
                    String calendarId = "*****@*****.**";
                    String eventId    = eid;
                    var    delCal     = service.Events.Delete(calendarId, eventId);
                    delCal.SendNotifications = true;
                    delCal.Execute();

                    var removes = context.Content.Where(s => s.Id == id).FirstOrDefault();
                    context.Content.Remove(removes);
                    context.SaveChanges();
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }
Пример #9
0
 public override object GetCalendarList()
 {
     try
     {
         CalendarListResource.ListRequest req = CalendarService.CalendarList.List();
         return(req.Execute());
     }
     catch (Exception ex)
     {
         return(ex);
     }
 }
        private void btnGetCalendars_Click(object sender, EventArgs e)
        {
            CalendarListResource.ListRequest callist = CalendarService.CalendarList.List();
            CalendarList list = callist.Execute();

            dgvFromCalendars.AutoGenerateColumns = true;
            dgvFromCalendars.DataSource          = list.Items.Select(o => new { o.Id, o.Summary, o.Description }).ToList();
            dgvToCalendars.DataSource            = list.Items.Select(o => new { o.Id, o.Summary, o.Description }).ToList();

            btnCopyEvents.Enabled = tbSearchFilter.Enabled = tbReplace.Enabled = startDate.Enabled = endDate.Enabled = true;

            lblInfo.Text = "Double click calendar to preview events with filters.  Select Source (left) and Destination (right) calendar and click 'Copy Events'";
        }
Пример #11
0
        private static string getLifeCoachCalendarId(CalendarService service, string calendarName)
        {
            CalendarListResource.ListRequest listRequest = service.CalendarList.List();
            var calendarList = listRequest.Execute();

            foreach (var calendar in calendarList.Items)
            {
                if (calendar.Summary == calendarName)
                {
                    return(calendar.Id);
                }
            }
            return(null);
        }
        // Just loops though getting all the rows.
        private static CalendarList ProcessResults(CalendarListResource.ListRequest request)
        {
            try
            {
                CalendarList             result  = request.Execute();
                List <CalendarListEntry> allRows = new List <CalendarListEntry>();

                //// Loop through until we arrive at an empty page
                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 = request.Execute();
                }
                CalendarList allData = result;
                allData.Items = (List <CalendarListEntry>)allRows;
                return(allData);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
        }
        public CalendarList getCalendars()
        {
            CalendarList cl  = new CalendarList();
            CalendarList clr = new CalendarList();

            clr.Items = new List <CalendarListEntry>();
            CalendarListResource.ListRequest request = service.CalendarList.List();
            try
            {
                cl = request.Execute();
            } catch (Exception e)
            {
            }
            for (int i = 0; i < cl.Items.Count; i++)
            {
                if (cl.Items[i].AccessRole == "owner" || cl.Items[i].AccessRole == "writer")
                {
                    clr.Items.Add(cl.Items[i]);
                }
            }
            return(clr);
        }
Пример #14
0
        /// <summary>
        /// Get the list of calendars in the Google account
        /// </summary>
        /// <param name="owner">Accoutn to return list of calendars for</param>
        /// <returns>List of google calendar names and id's associated with the Google account</returns>
        public static CalendarListItem[] GetCalendars(string owner)
        {
            log.Info("Starting Retrieval of Google Calendars for " + owner);

            CalendarListItem[] lstCalendars = new CalendarListItem[0];

            CalendarListResource.ListRequest request = GetCalendarService(owner).CalendarList.List();
            request.ShowDeleted = false;
            request.ShowHidden  = false;
            request.MaxResults  = 20;

            CalendarList calendars = request.Execute();

            if (calendars.Items != null && calendars.Items.Count > 0)
            {
                lstCalendars = new CalendarListItem[calendars.Items.Count];
                int count = 0;

                foreach (var calItem in calendars.Items)
                {
                    string calId   = calItem.Id.ToString();
                    string calName = calItem.Summary.ToString();

                    CalendarListItem item = new CalendarListItem();
                    item.Text  = calName;
                    item.Value = calId;

                    lstCalendars[count] = item;

                    count++;
                }
            }

            log.Info("Finished Retrieval of Google Calendars for " + owner);
            return(lstCalendars);
        }
Пример #15
0
        public async Task <ActionResult> GoogleCalendarAsync(CancellationToken cancellationToken)
        {
            var result = await new AuthorizationCodeMvcApp(this, new Showcase.Util.ZenoFlowMetadata()).
                         AuthorizeAsync(cancellationToken);

            if (result.Credential != null)
            {
                var service = new CalendarService(new BaseClientService.Initializer
                {
                    HttpClientInitializer = result.Credential,
                    ApplicationName       = "ASP.NET MVC Sample"
                });

                if (String.IsNullOrEmpty(Request.Form["CalendarID"]))
                {
                    CalendarListResource.ListRequest request0 = service.CalendarList.List();
                    request0.MaxResults = 10;

                    // List events.
                    CalendarList calendars = request0.Execute();
                    string       desc      = string.Empty;
                    Dictionary <string, string> calendarList = new Dictionary <string, string>();
                    if (calendars.Items != null && calendars.Items.Count > 0)
                    {
                        foreach (var calendarItem in calendars.Items)
                        {
                            calendarList.Add(calendarItem.Id, calendarItem.Summary);
                        }
                    }
                    ViewBag.Message = "Please select which calendar you want to add.";
                    return(View(calendarList));
                }
                else
                {
                    DateTime tomorrow    = DateTime.Today.AddDays(1);
                    string   chineseDate = ChineseCalendar.GetChineseDate(tomorrow);

                    var newEvent = new Google.Apis.Calendar.v3.Data.Event()
                    {
                        Summary = chineseDate,

                        Start = new EventDateTime()
                        {
                            Date = tomorrow.ToString("yyyy-MM-dd"),
                        },
                        End = new EventDateTime()
                        {
                            Date = tomorrow.ToString("yyyy-MM-dd"),
                        },
                        Transparency = "transparent"
                    };

                    EventsResource.InsertRequest request = service.Events.Insert(newEvent, Request.Form["CalendarID"]);
                    Event createdEvent = request.Execute();

                    ViewBag.Message = "Google Calendar Event Added: URL = " + createdEvent.HtmlLink;
                    return(View());
                }

                /*
                 * Showcase.ZenoService.ZenoServiceClient zeno = new Showcase.ZenoService.ZenoServiceClient();
                 * GoogleRequest request = new GoogleRequest();
                 * request.Type = ShowcaseService.Contract.GoogleRequestType.CalendarPush;
                 * request.User = new ShowcaseService.Contract.GoogleUser(){ AccessToken = result.Credential.Token.AccessToken, RefreshToken = result.Credential.Token.RefreshToken};
                 * GoogleResponse response = zeno.InvokeGoogleService(request);
                 * ViewBag.Message = response.Message;
                 */
            }
            else
            {
                return(new RedirectResult(result.RedirectUri));
            }
        }
Пример #16
0
        public static Dictionary <Event, string> GetGoogleCalendarEvents(List <string> calendarNames, DateTime startDate, DateTime endDate, int returnAmount)
        {
            Dictionary <Event, string> eventDictionary = new Dictionary <Event, string>();

            AuthorizeGoogleCalendar();

            CalendarListResource.ListRequest calRequest = calendarService.CalendarList.List();
            calRequest.MinAccessRole = CalendarListResource.ListRequest.MinAccessRoleEnum.Owner;
            CalendarList calendars = calRequest.Execute();

            if (calendarNames == null || calendarNames.Count == 0)
            {
                foreach (CalendarListEntry calendar in calendars.Items)
                {
                    EventsResource.ListRequest eventRequest = calendarService.Events.List(calendar.Id);
                    eventRequest.TimeMin      = startDate.Date + new TimeSpan(0, 0, 0);  //Force the start to the bottom of the date
                    eventRequest.TimeMax      = endDate.Date + new TimeSpan(23, 59, 59); //Make the "endDate" inclusive
                    eventRequest.ShowDeleted  = false;
                    eventRequest.SingleEvents = true;
                    eventRequest.MaxResults   = returnAmount;
                    eventRequest.OrderBy      = EventsResource.ListRequest.OrderByEnum.StartTime;

                    Events        events       = eventRequest.Execute();
                    List <string> eventDisplay = new List <string>();
                    for (var i = 0; i < events.Items.Count; i++)
                    {
                        string eventSummary = events.Items[i].Summary + " (" + events.Items[i].Start.DateTime.Value.ToString("HH:mm") + " - " + events.Items[i].End.DateTime.Value.ToString("HH:mm") + ")";
                        eventDictionary.Add(events.Items[i], eventSummary);
                    }
                }
            }
            else if (calendarNames.Count == 1)
            {
                CalendarListEntry calendar = calendars.Items.Where(p => p.Summary == "*****@*****.**").FirstOrDefault(); //Todo: get the user's personal calendar from the Google Calendar API? https://developers.google.com/gmail/api/v1/reference/users/getProfile

                EventsResource.ListRequest eventRequest = calendarService.Events.List(calendar.Id);
                eventRequest.TimeMin      = startDate.Date + new TimeSpan(0, 0, 0);  //Force the start to the bottom of the date
                eventRequest.TimeMax      = endDate.Date + new TimeSpan(23, 59, 59); //Make the "endDate" inclusive
                eventRequest.ShowDeleted  = false;
                eventRequest.SingleEvents = true;
                eventRequest.MaxResults   = returnAmount;
                eventRequest.OrderBy      = EventsResource.ListRequest.OrderByEnum.StartTime;

                Events        events       = eventRequest.Execute();
                List <string> eventDisplay = new List <string>();
                for (var i = 0; i < events.Items.Count; i++)
                {
                    string eventSummary = events.Items[i].Summary + " (" + events.Items[i].Start.DateTime.Value.ToString("HH:mm") + " - " + events.Items[i].End.DateTime.Value.ToString("HH:mm") + ")";
                    eventDictionary.Add(events.Items[i], eventSummary);
                }
            }
            else
            {
                foreach (string calendarString in calendarNames)
                {
                    CalendarListEntry calendar = calendars.Items.Where(p => p.Summary == calendarString).FirstOrDefault();

                    EventsResource.ListRequest eventRequest = calendarService.Events.List(calendar.Id);
                    eventRequest.TimeMin      = startDate.Date + new TimeSpan(0, 0, 0);  //Force the start to the bottom of the date
                    eventRequest.TimeMax      = endDate.Date + new TimeSpan(23, 59, 59); //Make the "endDate" inclusive
                    eventRequest.ShowDeleted  = false;
                    eventRequest.SingleEvents = true;
                    eventRequest.MaxResults   = returnAmount;
                    eventRequest.OrderBy      = EventsResource.ListRequest.OrderByEnum.StartTime;

                    Events        events       = eventRequest.Execute();
                    List <string> eventDisplay = new List <string>();
                    for (var i = 0; i < events.Items.Count; i++)
                    {
                        string eventSummary = events.Items[i].Summary + " (" + events.Items[i].Start.DateTime.Value.ToString("HH:mm") + " - " + events.Items[i].End.DateTime.Value.ToString("HH:mm") + ")";
                        eventDictionary.Add(events.Items[i], eventSummary);
                    }
                }
            }

            //Reorganize the dictionary by startDate
            eventDictionary = eventDictionary.OrderBy(p => p.Key.Start.DateTime.Value).ToDictionary(pair => pair.Key, pair => pair.Value);

            return(eventDictionary);
        }
Пример #17
0
        public bool Post([FromBody] Content val)
        {
            bool state = false;

            using (var context = new DbGoogleContext())
            {
                var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    new ClientSecrets
                {
                    ClientId     = "491606904456-nr7nscjo3l75na40kq939t35fd55i9o7.apps.googleusercontent.com",
                    ClientSecret = "xhc5pCiEoW54ch7aF_J8Ah69",
                },
                    new[] { CalendarService.Scope.Calendar },
                    "user",
                    CancellationToken.None).Result;

                try
                {
                    var service = new CalendarService(new BaseClientService.Initializer
                    {
                        HttpClientInitializer = credential,
                        ApplicationName       = "Calendar API Realtor",
                    });

                    CalendarListResource.ListRequest cal = service.CalendarList.List();
                    cal.MaxResults = 100;
                    var calresult = cal.Execute().Items;



                    foreach (CalendarListEntry entry in calresult)
                    {
                        EventsResource.ListRequest request = service.Events.List(entry.Id);
                        request.TimeMin      = Convert.ToDateTime("03/01/2015");
                        request.ShowDeleted  = false;
                        request.SingleEvents = true;
                        request.MaxResults   = 200;
                        request.OrderBy      = EventsResource.ListRequest.OrderByEnum.StartTime;


                        Events events = request.Execute();
                    }



                    DateTime sDate = val.Start;

                    DateTime eDate = val.End;



                    var myEvent = new Event
                    {
                        Id          = val.EventId,
                        Summary     = val.Title,
                        Description = val.Description,
                        Location    = "Thailand",

                        Start = new EventDateTime()
                        {
                            DateTime = sDate,
                            TimeZone = "Asia/Colombo",
                        },
                        End = new EventDateTime()
                        {
                            DateTime = eDate,
                            TimeZone = "Asia/Colombo",
                        },
                        Attendees = new EventAttendee[] {
                            new EventAttendee()
                            {
                                Email = "*****@*****.**"
                            },
                            new EventAttendee()
                            {
                                Email = "*****@*****.**"
                            },
                        },
                        Reminders = new Event.RemindersData()
                        {
                            UseDefault = false,
                            Overrides  = new EventReminder[]
                            {
                                new EventReminder()
                                {
                                    Method = "email", Minutes = 24 * 60
                                },
                                new EventReminder()
                                {
                                    Method = "popup", Minutes = 10
                                },
                            }
                        }
                    };
                    String calendarId = "*****@*****.**";
                    EventsResource.InsertRequest singleEvent = service.Events.Insert(myEvent, calendarId);
                    singleEvent.SendNotifications = true;
                    singleEvent.Execute();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
                context.Content.Add(val);
                context.SaveChanges();
                state = true;
            }

            return(state);
        }
Пример #18
0
        public async Task <IActionResult> PutValues(int id, Content vals)
        {
            using (var context = new DbGoogleContext())
            {
                var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(

                    new ClientSecrets
                {
                    ClientId     = "491606904456-nr7nscjo3l75na40kq939t35fd55i9o7.apps.googleusercontent.com",
                    ClientSecret = "xhc5pCiEoW54ch7aF_J8Ah69",
                },
                    new[] { CalendarService.Scope.Calendar },
                    "user",

                    CancellationToken.None).Result;


                try
                {
                    var service = new CalendarService(new BaseClientService.Initializer
                    {
                        HttpClientInitializer = credential,
                        ApplicationName       = "Calendar API Realtor",
                    });

                    CalendarListResource.ListRequest cal = service.CalendarList.List();
                    cal.MaxResults = 100;

                    var calresult = cal.Execute().Items;


                    // List<EventDetails> ed = new List<EventDetails>();

                    foreach (CalendarListEntry entry in calresult)
                    {
                        EventsResource.ListRequest request = service.Events.List(entry.Id);
                        request.TimeMin      = Convert.ToDateTime("03/01/2019");
                        request.ShowDeleted  = false;
                        request.SingleEvents = true;
                        request.MaxResults   = 200;
                        request.OrderBy      = EventsResource.ListRequest.OrderByEnum.StartTime;

                        // List events.
                        Events eventss = request.Execute();
                    }



                    var eid = new DbGoogleContext().Content.Where(d => d.Id == id).FirstOrDefault().EventId;

                    String calendarId = "*****@*****.**";
                    String eventId    = eid;
                    // var eventslist = service.Events.List(calendarId);
                    var events = service.Events.Get(calendarId, eventId).Execute();

                    DateTime ssDate = vals.Start;

                    DateTime esDate = vals.End;
                    Event    ev     = new Event
                    {
                        Summary     = vals.Title,
                        Id          = vals.EventId,
                        Description = vals.Description,
                        Start       = new EventDateTime()
                        {
                            DateTime = ssDate,
                            TimeZone = "Asia/Colombo",
                        },
                        End = new EventDateTime()
                        {
                            DateTime = esDate,
                            TimeZone = "Asia/Colombo",
                        }
                    };
                    //string FoundEventID = events.Id;

                    var updateCal = service.Events.Patch(ev, calendarId, eventId);
                    updateCal.SendNotifications = true;
                    updateCal.Execute();

                    context.Entry(vals).State = EntityState.Modified;
                    try
                    {
                        await context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!Content(id))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
                catch (Exception e)
                {
                    throw e;
                }



                if (id != vals.Id)
                {
                    return(BadRequest());
                }
            }


            return(NoContent());
        }
Пример #19
0
 public static CalendarList getCalendar()
 {
     CalendarListResource.ListRequest request = s.CalendarList.List();
     request.MaxResults = 20;
     return(request.Execute());
 }