当前位置: 首页>>代码示例>>C#>>正文


C# CalendarService类代码示例

本文整理汇总了C#中CalendarService的典型用法代码示例。如果您正苦于以下问题:C# CalendarService类的具体用法?C# CalendarService怎么用?C# CalendarService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CalendarService类属于命名空间,在下文中一共展示了CalendarService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateService

        public CalendarService CreateService(string applicationName)
        {
            UserCredential credential;
            string[] scopes = { CalendarService.Scope.CalendarReadonly };

            using (var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
            {
                var credPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

                credPath = Path.Combine(credPath, ".credentials");

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
            }

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

            return service;
        }
开发者ID:raganm,项目名称:GoogleCalendarTest,代码行数:27,代码来源:CalendarUtils.cs

示例2: GoogleMain

        public void GoogleMain()
        {
            UserCredential credential;

            using (FileStream stream =
                new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
            {
                string credPath = System.Environment.GetFolderPath(
                    System.Environment.SpecialFolder.Personal);
                credPath = Path.Combine(credPath, ".credentials/calendar-dotnet-quickstart");

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

          
            CalendarService service = new CalendarService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = ApplicationName,
            });
            EventsResource.ListRequest request = service.Events.List("primary");
            request.TimeMin = DateTime.Now;
            request.ShowDeleted = false;
            request.SingleEvents = true;
            request.MaxResults = 10;
            request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime;

            
            Events events = request.Execute();

           
            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;
                    }
                   
                    gcevents.Add(eventItem.Summary);
                    dates.Add(when);
                }
            }
            else
            {
                
            }
            



        }
开发者ID:KongXiong,项目名称:Airline-Proj2,代码行数:60,代码来源:CalendarReader.cs

示例3: AuthenticateCalendarOauth

        /// <summary>
        ///     <see cref="Authenticate" /> to Google Using Oauth2 Documentation
        ///     https://developers.google.com/accounts/docs/OAuth2
        /// </summary>
        /// <param name="clientId">
        ///     From Google Developer console https://console.developers.google.com
        /// </param>
        /// <param name="clientSecret">
        ///     From Google Developer console https://console.developers.google.com
        /// </param>
        /// <param name="userName">
        ///     A string used to identify a user (locally).
        /// </param>
        /// <param name="fileDataStorePath">
        ///     Name/Path where the Auth Token and refresh token are stored (usually
        ///     in %APPDATA%)
        /// </param>
        /// <param name="applicationName">Applicaiton Name</param>
        /// <param name="isFullPath">
        ///     <paramref name="fileDataStorePath" /> is completePath or Directory
        ///     Name
        /// </param>
        /// <returns>
        /// </returns>
        public CalendarService AuthenticateCalendarOauth(string clientId, string clientSecret, string userName,
            string fileDataStorePath, string applicationName, bool isFullPath = false)
        {
            try
            {
                var authTask = Authenticate(clientId, clientSecret, userName, fileDataStorePath, isFullPath);

                authTask.Wait(30000);

                if (authTask.Status == TaskStatus.WaitingForActivation)
                {
                    return null;
                }

                var service = new CalendarService(new BaseClientService.Initializer
                {
                    HttpClientInitializer = authTask.Result,
                    ApplicationName = applicationName
                });

                return service;
            }
            catch (AggregateException exception)
            {
                Logger.Error(exception);
                return null;
            }
            catch (Exception exception)
            {
                Logger.Error(exception);
                return null;
            }
        }
开发者ID:flyeven,项目名称:PCoMD,代码行数:57,代码来源:AccountAuthenticationService.cs

示例4: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            // Ensure we have at least one calendar. If not, let's move them back to the calendar and explain that this feature is not yet ready.
            var service = new CalendarService();
            var calendars = service.GetCalendars();
            if(calendars.First().CalendarID == 0)
            {
                Response.Redirect(URL_CALENDAR + "?status=0");
            }

            // Ensure that, if we are editing an event, it is the backoffice owner's event.
            if(CalendarItemID != 0)
            {
                if(!service.ValidateCalendarItem(CalendarItemID))
                {
                    Response.Redirect(URL_CALENDARDETAILS + "?id=" + CalendarItemID);
                }
            }

            PopulateCalendarOptions();
            PopulateCalendarItemRepeatTypeOptions();
            PopulateCalendarItemTypeOptions();
            PopulateDefaultFormOptions();
            PopulateTimeZones();
            PopulateExistingData();
        }
    }
开发者ID:BakerWebDev,项目名称:strongbrook.me,代码行数:29,代码来源:ManageEvent.aspx.cs

示例5: addEvent

        public static void addEvent(CalendarService service, string email, string summary, string[] participants, TimePeriod timePeriod)
        {
            Event myEvent = new Event
            {
                Summary = summary,
                //Location = "Somewhere",
                Start = new EventDateTime()
                {
                    DateTime = timePeriod.Start.Value,
                    TimeZone = "Europe/London"
                },
                End = new EventDateTime()
                {
                    DateTime = timePeriod.End.Value,
                    TimeZone = "Europe/London"
                },
                /*Recurrence = new String[] {
                            "RRULE:FREQ=WEEKLY;BYDAY=MO"
                },*/

                //Attendees = getAttendees(participants)
            };

            //or Insert(myEvent, "primary")
            Event recurringEvent = service.Events.Insert(myEvent, email).Execute();
        }
开发者ID:tonyxfox,项目名称:SScheduler,代码行数:26,代码来源:GoogleCalendarUtils.cs

示例6: ApiMethods

        public ApiMethods()
        {
            using (var stream =
                new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
            {
                string credPath = System.Environment.GetFolderPath(
                    System.Environment.SpecialFolder.Personal);
                credPath = Path.Combine(credPath, ".credentials/calendar-dotnet-quickstart");

                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.
            service = new CalendarService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = applicationName,
            });
        }
开发者ID:Alexsus87,项目名称:GAPI,代码行数:25,代码来源:ApiMethods.cs

示例7: AddCalendarEventClick

        private void AddCalendarEventClick(object sender, RoutedEventArgs e)
        {
            const string calendarEventDescription = "Test event for DrZob";
            var timeFrom = DateTime.Today.AddHours(4);
            var timeTo = DateTime.Today.AddHours(6);
            var calendarEvent = CreateCalendarEvent(calendarEventDescription, timeFrom, timeTo);

            try
            {
                var credentials = GetCredentials(new[] { CalendarService.Scope.Calendar }, User.Text);

                var calendarService = new CalendarService(new BaseClientService.Initializer
                                                  {
                                                      HttpClientInitializer = credentials,
                                                      ApplicationName = ApplicationName
                                                  });

                var calendars = calendarService.CalendarList.List().Execute();
                var calendar = calendars.Items.SingleOrDefault(x => x.Summary == "DrZob");

                if (calendar == null)
                {
                    MessageBox.Show("The calendar 'DrZob' does not exist!");
                    return;
                }

                var calendarEventResponse = calendarService.Events.Insert(calendarEvent, calendar.Id).Execute();
            }
            catch (Exception ex)
            {
                Console.WriteLine("A Google Apps error occurred:");
                Console.WriteLine(ex.Message);
            }
        }
开发者ID:LogicInc,项目名称:GoogleCalendarTest,代码行数:34,代码来源:MainWindow.xaml.cs

示例8: Render

    protected override void Render(HtmlTextWriter writer)
    {
        if(Request.QueryString["action"] != null)
        {
            var start = Request.QueryString["start"];
            var end = Request.QueryString["end"];
            var filter = Request.QueryString["filter"];

            var service = new CalendarService();
            var json = service.GetDataAsJson(start, end, filter);

            // Write the JSON
            Response.Clear();
            writer.Write(json);
            Response.End();

            // Write the JSON
            Response.Clear();
            writer.Write(json);
            Response.End();
        }
        else
        {
            base.Render(writer);
        }
    }
开发者ID:BakerWebDev,项目名称:strongbrook.me,代码行数:26,代码来源:Calendar.aspx.cs

示例9: InitCnx

        /// <summary>
        /// Initialise la connexion avec Google Calendar
        /// </summary>
        /// <param name="privateKey"></param>
        /// <param name="googleAccount"></param>
        /// <returns></returns>
        public bool InitCnx()
        {
            Log.Debug("Initialisation de la connexion avec Google ...");
            // Si la fonction n'est pas activée, on passe tout de suite
            if (!p_isActivated) { return false; }

            try
            {
                string[] scopes = new string[] {
                    CalendarService.Scope.Calendar, // Manage your calendars
 	                CalendarService.Scope.CalendarReadonly // View your Calendars
            };
                var certificate = new X509Certificate2(p_privateKey, "notasecret", X509KeyStorageFlags.Exportable);

                ServiceAccountCredential credential = new ServiceAccountCredential(
                         new ServiceAccountCredential.Initializer(p_googleAccount)
                         {
                             Scopes = scopes
                         }.FromCertificate(certificate));
                // Create Google Calendar API service.
                p_myService = new CalendarService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName = "PlanningLAB",
                });
            }
            catch (Exception err) { Log.Error("Erreur Authentification Google {" + p_googleAccount + "} - {" + p_privateKey + "} :", err); return false; }
            return true;
        }/// <summary>
开发者ID:StephOfPixVert,项目名称:PlanningLab,代码行数:35,代码来源:GoogleUtilities.cs

示例10: AuthenticateOauth

        /// <summary>
        /// Authenticate to Google Using Oauth2
        /// Documentation https://developers.google.com/accounts/docs/OAuth2
        /// </summary>
        /// <param name="clientId">From Google Developer console https://console.developers.google.com</param>
        /// <param name="clientSecret">From Google Developer console https://console.developers.google.com</param>
        /// <param name="userName">A string used to identify a user.</param>
        /// <returns></returns>
        public static CalendarService AuthenticateOauth(string clientId, string clientSecret, string userName)
        {

            string[] scopes = new string[] {
        CalendarService.Scope.Calendar  ,  // Manage your calendars
        CalendarService.Scope.CalendarReadonly    // View your Calendars
            };

            try
            {
                // here is where we Request the user to give us access, or use the Refresh Token that was previously stored in %AppData%
                UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = clientId, ClientSecret = clientSecret }
                                                                    , scopes
                                                                    , userName
                                                                    , CancellationToken.None
                                                                    , new FileDataStore("Daimto.GoogleCalendar.Auth.Store")).Result;



                CalendarService service = new CalendarService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName = "Calendar API Sample",
                });
                return service;
            }
            catch (Exception ex)
            {

                Console.WriteLine(ex.InnerException);
                return null;

            }

        }
开发者ID:anhct,项目名称:Google-Dotnet-Samples,代码行数:43,代码来源:Authentication.cs

示例11: GoogleCalendar

        public GoogleCalendar()
        {
            //UserCredential credential;
            //using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
            //{

            //    //var clientSecrets = GoogleClientSecrets.Load(stream).Secrets;
            //     credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
            //        stream,
            //        new[] { CalendarService.Scope.Calendar },
            //        "user", CancellationToken.None, new FileDataStore("Calendar.ListMyLibrary")).Result;

            //    service = new CalendarService(new BaseClientService.Initializer()
            //    {
            //        HttpClientInitializer = credential,
            //        ApplicationName = "Outlook Google Sync" ,

            //    });
            //    //credential = authorizeAsync.Result;
            //}

            var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description);
            provider.ClientIdentifier = "646754649922-g2p0157e4q3d5qv25ia3ur09vrc455k6.apps.googleusercontent.com";
            provider.ClientSecret = "ZyPfCdrOFb6y-VWrdVZ65_8M";

            service = new CalendarService(new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthentication));
            service.Key = "AIzaSyCg7QtvUT6V3Hh3ZG7M5KfDiFScRkaYix0";
        }
开发者ID:rantsi,项目名称:outlookgooglesync,代码行数:28,代码来源:GoogleCalendar.cs

示例12: UpcomingEvents

        // GET: /Calendar/UpcomingEvents
        public async Task<ActionResult> UpcomingEvents()
        {
            const int MaxEventsPerCalendar = 20;
            const int MaxEventsOverall = 50;

            var model = new UpcomingEventsViewModel();

            var credential = await GetCredentialForApiAsync();

            var initializer = new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = "ASP.NET MVC5 Calendar Sample",
            };
            var service = new CalendarService(initializer);

            // Fetch the list of calendars.
            var calendars = await service.CalendarList.List().ExecuteAsync();

            // Fetch some events from each calendar.
            var fetchTasks = new List<Task<Google.Apis.Calendar.v3.Data.Events>>(calendars.Items.Count);
            foreach (var calendar in calendars.Items)
            {
                var request = service.Events.List(calendar.Id);
                request.MaxResults = MaxEventsPerCalendar;
                request.SingleEvents = true;
                request.TimeMin = DateTime.Now;
                fetchTasks.Add(request.ExecuteAsync());
            }
            var fetchResults = await Task.WhenAll(fetchTasks);

            // Sort the events and put them in the model.
            var upcomingEvents = from result in fetchResults
                                 from evt in result.Items
                                 where evt.Start != null
                                 let date = evt.Start.DateTime.HasValue ?
                                     evt.Start.DateTime.Value.Date :
                                     DateTime.ParseExact(evt.Start.Date, "yyyy-MM-dd", null)
                                 let sortKey = evt.Start.DateTimeRaw ?? evt.Start.Date
                                 orderby sortKey
                                 select new { evt, date };
            var eventsByDate = from result in upcomingEvents.Take(MaxEventsOverall)
                               group result.evt by result.date into g
                               orderby g.Key
                               select g;

            var eventGroups = new List<CalendarEventGroup>();
            foreach (var grouping in eventsByDate)
            {
                eventGroups.Add(new CalendarEventGroup
                {
                    GroupTitle = grouping.Key.ToLongDateString(),
                    Events = grouping,
                });
            }

            model.EventGroups = eventGroups;
            return View(model);
        }
开发者ID:Cyril12740,项目名称:google-api-dotnet-client-samples,代码行数:60,代码来源:CalendarController.cs

示例13: AddEvent

        public void AddEvent()
        {
            UserCredential credential;

            using (var stream =
                new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
            {
                string credPath = System.Environment.GetFolderPath(
                    System.Environment.SpecialFolder.Personal);
                credPath = Path.Combine(credPath, ".credentials/calendar-dotnet-quickstart");

                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,
            });
            Console.WriteLine("Enter sumary");
            string sum = Console.ReadLine();

            Console.WriteLine("Enter Location");
            string location = Console.ReadLine();

            Event myEvent = new Event
            {

                Summary = sum,
                Location = location,
                Start = new EventDateTime()
                {
                    DateTime = new DateTime(2016,03,06),
                    TimeZone = "America/Chicago"
                },
                End = new EventDateTime()
                {
                    DateTime = new DateTime(2016,03,07),
                    TimeZone = "America/Chicago"
                },
                Recurrence = new String[] {
      "RRULE:FREQ=WEEKLY;BYDAY=MO"
  },
                Attendees = new List<EventAttendee>()
      {
        new EventAttendee() { Email = "[email protected]" }
      }
            };

            Event recurringEvent = service.Events.Insert(myEvent, "primary").Execute();
        }
开发者ID:KongXiong,项目名称:Airline-Proj2,代码行数:58,代码来源:GoogleCalendar.cs

示例14: Main

        public static void Main(string[] args)
        {
            Console.WriteLine("Google Calender API v3");

            var clientId = ConfigurationManager.AppSettings["ClientId"];
            var clientSecret = ConfigurationManager.AppSettings["ClientSecret"];
            var calendarId = ConfigurationManager.AppSettings["CalendarId"];

            try
            {
                var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    new ClientSecrets
                    {
                        ClientId = clientId,
                        ClientSecret = clientSecret,
                    },
                    new[] { CalendarService.Scope.Calendar },
                    "user",
                    CancellationToken.None).Result;

                var service = new CalendarService(new BaseClientService.Initializer
                {
                    HttpClientInitializer = credential,
                    ApplicationName = "Google Calender API v3",
                });

                var queryStart = DateTime.Now;
                var queryEnd = queryStart.AddYears(1);

                var query = service.Events.List(calendarId);
                // query.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime; - not supported :(
                query.TimeMin = queryStart;
                query.TimeMax = queryEnd;

                var events = query.Execute().Items;

                var eventList = events.Select(e => new Tuple<DateTime, string>(DateTime.Parse(e.Start.Date), e.Summary)).ToList();
                eventList.Sort((e1, e2) => e1.Item1.CompareTo(e2.Item1));

                Console.WriteLine("Query from {0} to {1} returned {2} results", queryStart, queryEnd, eventList.Count);

                foreach (var item in eventList)
                {
                    Console.WriteLine("{0}\t{1}", item.Item1, item.Item2);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception encountered: {0}", e.Message);
            }

            Console.WriteLine("Press any key to continue...");

            while (!Console.KeyAvailable)
            {
            }
        }
开发者ID:zhouhao15917,项目名称:Google-Calendar-API-v3-Simple-Console-Demo,代码行数:57,代码来源:Program.cs

示例15: Main

        static void Main(string[] args)
        {
            UserCredential credential;

            using (var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
            {
                string credPath = System.Environment.GetFolderPath(
                    System.Environment.SpecialFolder.Personal);
                credPath = Path.Combine(credPath, ".credentials");

                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,
            });

            // Define parameters of request.
            EventsResource.ListRequest request = service.Events.List("primary");
            request.TimeMin = DateTime.Now.AddYears(-1);//DateTime.Now.AddYears(-7);
            request.TimeMax = DateTime.Now;
            request.ShowDeleted = false;
            request.SingleEvents = true;
            request.MaxResults = 1000;//{Default:25, Max:2500}
            request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime;

            // List events.
            Events events = request.Execute();
            Console.WriteLine(String.Format("Event Count: {0}", events.Items.Count));
            if (events.Items != null && events.Items.Count > 0)
            {
                foreach (var eventItem in events.Items)
                {
                    Thread.Sleep(200);
                    eventItem.Visibility = "private";
                    eventItem.Transparency = "transparent";
                    EventsResource.UpdateRequest updateReq = service.Events.Update(eventItem, "primary", eventItem.Id);
                    Event updatedEvent = updateReq.Execute();
                    Console.WriteLine("Event Updated: " + updatedEvent.Id + " " + updatedEvent.Visibility + " " + updatedEvent.Description);
                }
            }
            else
            {
                Console.WriteLine("No events found.");
            }
            Console.Read();
            Console.Read();
        }
开发者ID:danielevora,项目名称:CalUndoer,代码行数:57,代码来源:Program.cs


注:本文中的CalendarService类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。