예제 #1
0
            public async Task <Calendar[]> GetCalendarsAsync()
            {
                if (service == null)
                {
                    return(new Calendar[0]);
                }
                CalendarListResource.ListRequest req = service.CalendarList.List();
                req.ShowDeleted = false;

                CalendarList src = await req.ExecuteAsync();

                var dst = new Calendar[src.Items.Count];

                for (int i = 0; i < src.Items.Count; i++)
                {
                    var   calendar = src.Items[i];
                    Color col;
                    col.A  = 255;
                    col.R  = Convert.ToByte(calendar.BackgroundColor.Substring(1, 2), 16);
                    col.G  = Convert.ToByte(calendar.BackgroundColor.Substring(3, 2), 16);
                    col.B  = Convert.ToByte(calendar.BackgroundColor.Substring(5, 2), 16);
                    dst[i] = new Calendar()
                    {
                        color    = col,
                        id       = calendar.Id,
                        name     = String.IsNullOrEmpty(calendar.SummaryOverride) ? calendar.Summary : calendar.SummaryOverride,
                        isHidden = false
                    };
                }
                return(dst);
            }
예제 #2
0
        async Task UpdateCalendarListUI()
        {
            CalendarListResource.ListRequest listRequest = this.service.CalendarList.List();
            this.calendarList = await listRequest.ExecuteAsync();

            this.ricbCalendarList.Items.Clear();
            foreach (CalendarListEntry item in this.calendarList.Items)
            {
                this.ricbCalendarList.Items.Add(item.Summary);
            }
            if (!String.IsNullOrEmpty(this.activeCalendarId))
            {
                CalendarListEntry itemToSelect = this.calendarList.Items.FirstOrDefault(x => x.Id == this.activeCalendarId);
                this.dxGoogleCalendarSync.CalendarId = this.activeCalendarId;
                if (this.ricbCalendarList.Items.Contains(itemToSelect.Summary))
                {
                    this.beiCalendarList.EditValue = itemToSelect.Summary;
                }
                else
                {
                    this.activeCalendarId = String.Empty;
                }
            }
            UpdateBbiAvailability();
        }
예제 #3
0
        public async Task <IEnumerable <Event> > GetEvents()
        {
            // Define parameters of request.
            CalendarListResource.ListRequest calendarRequest = service.CalendarList.List();
            var calendars = await calendarRequest.ExecuteAsync();

            List <Event> allEvents = new List <Event>();

            foreach (var calendar in calendars.Items.Where(item => item.Selected ?? false))
            {
                EventsResource.ListRequest request = service.Events.List(calendar.Id);
                request.TimeMin      = DateTime.Now.Date;
                request.TimeMax      = DateTime.Now.Date.AddDays(1);
                request.ShowDeleted  = false;
                request.SingleEvents = true;
                request.OrderBy      = EventsResource.ListRequest.OrderByEnum.StartTime;
                Events events = await request.ExecuteAsync();

                if (events.Items != null)
                {
                    allEvents.AddRange(events.Items);
                }
            }
            return(allEvents);
        }
        async protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            CalendarListResource.ListRequest listRequest = Service.CalendarList.List();
            var calendarList = await listRequest.ExecuteAsync();

            this.lookUpEdit1.Properties.DataSource    = calendarList.Items;
            this.lookUpEdit1.Properties.DisplayMember = "Summary";
            this.lookUpEdit1.Properties.ValueMember   = "Id";
            this.lookUpEdit1.Properties.Columns.Clear();
            this.lookUpEdit1.Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("Summary"));
            this.lookUpEdit1.EditValue         = CalendarId;
            this.lookUpEdit1.EditValueChanged += OnLookUpEdit1EditValueChanged;
        }
        private void StartUpdatingCalendarList()
        {
            SharedCalendarEntryList.Clear();

            if (ApplicationName.Length == 0)
            {
                return;
            }

            if (CredentialToken == null)
            {
                ObtainCredentialToken(false);
            }

            if (CredentialToken == null)
            {
                return;
            }

            try
            {
                // Create Google Calendar API service.
                using CalendarService service = new CalendarService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = CredentialToken, ApplicationName = ApplicationName
                });

                // Define parameters of requestCalendarList.
                CalendarListResource.ListRequest requestCalendarList = service.CalendarList.List();
                requestCalendarList.ShowDeleted = false;
                requestCalendarList.MaxResults  = 10;

                // List events.
                ListTaskCancellation = new CancellationTokenSource();
                ListTask             = requestCalendarList.ExecuteAsync(ListTaskCancellation.Token);
                IsListing            = true;
                IsListingCancelable  = true;
                ListTimer.Change(ListTimerStart, ListTimerInterval);
            }
            catch
            {
            }
        }
예제 #6
0
        public static async Task <int> GetNumberOfCalendars()
        {
            int            numberOfCalendars = 0;
            UserCredential credential;

            using (var stream =
                       new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
            {
                // The file token.json stores the user's access and refresh tokens, and is created
                // automatically when the authorization flow completes for the first time.
                string credPath = "token.json";
                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

            // Create Google Calendar API service.
            var service = new CalendarService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });

            //var service = new DiscoveryService(new BaseClientService.Initializer()
            //{
            //ApplicationName = ApplicationName,
            //HttpClientInitializer = credential
            //});

            // Define parameters of request.
            //EventsResource.ListRequest request = service.Events.List("primary");
            CalendarListResource.ListRequest request = service.CalendarList.List();
            //var request = service.Apis.List().Execute();
            //request.TimeMin = DateTime.Now;
            //request.ShowDeleted = false;
            //request.SingleEvents = true;
            //request.MaxResults = 10;
            //request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime;

            // List events.
            //Events events = request.Execute();
            //Console.WriteLine("Upcoming events:");
            var calendars = await request.ExecuteAsync();

            Console.WriteLine("Calendar Names");
            if (calendars.Items != null)
            {
                numberOfCalendars = calendars.Items.Count;
                foreach (var item in calendars.Items)
                {
                    Console.WriteLine($"{item.Id} - {item.Summary}");
                }
            }
            //if (events.Items != null && events.Items.Count > 0)
            //{
            //foreach (var eventItem in events.Items)
            //{
            //string when = eventItem.Start.DateTime.ToString();
            //if (String.IsNullOrEmpty(when))
            //{
            //when = eventItem.Start.Date;
            //}
            //Console.WriteLine("{0} ({1})", eventItem.Summary, when);
            //}
            //}
            //else
            //{
            //Console.WriteLine("No upcoming events found.");
            //}
            //Console.Read();
            return(numberOfCalendars);
        }