예제 #1
0
        // for updated
        // throws event doesn't exist exception
        // throws not found exception
        // throws locationOverlay
        public static void LocationOverlay(DateTime?start, DateTime?end, string location, string calendarId, string eventId)
        {
            // can throw event doesn't exist exception
            var events = Eventss.IgetAllNotDeletedEvent(calendarId);

            // tests if there are any events
            if (events != null)
            {
                foreach (Event ev in events.Items)
                {             // tests the overlay
                    if (ev.Location == location)
                    {         // tests the overlay
                        if (Math.Max(end.Value.Ticks, ev.End.DateTime.Value.Ticks) - Math.Min(start.Value.Ticks, ev.Start.DateTime.Value.Ticks) < (end.Value.Ticks - start.Value.Ticks) + (ev.End.DateTime.Value.Ticks - ev.Start.DateTime.Value.Ticks))
                        {     // makes sure the overlay is not from the notUpdated version of the event
                            if (eventId != ev.Id)
                            { // overlay
                                throw new LocationOverlayException("there is an location overlay");
                            }
                        }
                    }
                }
            }
            // there are no events = no test needed = no overlay
            return;
        }
예제 #2
0
        // for creates
        // throws event doesn't exist exception
        // throws not found exception
        // throws attendeeOverlay
        public static void AttendeeOverlay(DateTime?start, DateTime?end, IList <EventAttendee> eventAttendees, string calendarId)
        {
            // tests if there are attendees added
            if (eventAttendees == null)
            {
                // no attendees == no tests needed = no overlay
                return;
            }

            // can throw event doesn't exist exception
            var events = Eventss.IgetAllNotDeletedEvent(calendarId);

            // tests if there are any events
            if (events != null)
            {
                foreach (var ev in events.Items)
                {
                    foreach (var attendee in eventAttendees)
                    {         // tests the overlay
                        if (ev.Attendees != null && ev.Attendees.Contains(attendee))
                        {     // tests the overlay
                            if (Math.Max(end.Value.Ticks, ev.End.DateTime.Value.Ticks) - Math.Min(start.Value.Ticks, ev.Start.DateTime.Value.Ticks) < (end.Value.Ticks - start.Value.Ticks) + (ev.End.DateTime.Value.Ticks - ev.Start.DateTime.Value.Ticks))
                            { // overlay
                                throw new AttendeeOverlayException("attendee overlay");
                            }
                        }
                    }
                }
            }
            // there are no events = no test needed = no overlay
            return;
        }
예제 #3
0
        /*
         *      public GService()
         *      {
         *              try
         *              {
         *                      // Get active credential
         *                      string credPath = "credentials.json";
         *
         *                      var json = File.ReadAllText(credPath);
         *                      PersonalServiceAccountCred cr = JsonConvert.DeserializeObject<PersonalServiceAccountCred>(json); // "personal" service account credential
         *
         *                      // Create an explicit ServiceAccountCredential credential
         *                      var xCred = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(cr.client_email)
         *                      {
         *                              Scopes = Scopes
         *                      }.FromPrivateKey(cr.private_key));
         *
         *
         *
         *                      GService.service = new CalendarService(new BaseClientService.Initializer()
         *                      {
         *                              HttpClientInitializer = xCred,
         *                              ApplicationName = ApplicationName,
         *
         *                      });
         *
         *                      peopleService = new PeopleServiceService(new BaseClientService.Initializer()
         *                      {
         *                              HttpClientInitializer = xCred,
         *                              ApplicationName = ApplicationName,
         *                      });
         *
         *                      Attendee a = new Attendee();
         *                      Calendarss c = new Calendarss();
         *                      Eventss e = new Eventss();
         *              }
         *              catch (Exception e)
         *              {
         *                      Console.Write(e.Message);
         *              }
         *      }
         */

        public GService()
        {
            //initiation of services
            UserCredential credential;

            /*
             *          using (var stream = new FileStream(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "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 = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "token.json");
             *                  credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
             *                          GoogleClientSecrets.Load(stream).Secrets,
             *                          Scopes,
             *                          "admin",
             *                          CancellationToken.None,
             *                          new FileDataStore(credPath, true)).Result;
             *                  Console.WriteLine("Credential file saved to: " + credPath);
             *          }*/

            using (var stream = new FileStream(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "credentials.json"), FileMode.Open, FileAccess.Read))
            {
                var flow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
                {
                    ClientSecrets = GoogleClientSecrets.Load(stream).Secrets,
                    Scopes        = Scopes,
                });

                var token = new TokenResponse
                {
                    AccessToken  = ConfigurationManager.AppSettings["g_access_token"].ToString(),
                    RefreshToken = ConfigurationManager.AppSettings["g_refresh_token"].ToString()
                };

                credential = new UserCredential(flow, Environment.UserName, token);
            }



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

            peopleService = new PeopleServiceService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });

            //accolating services to classes
            Attendee   a = new Attendee();
            Calendarss c = new Calendarss();
            Eventss    e = new Eventss();

            service.CalendarList.Watch(new Channel()
            {
                Id      = "calendar.watch.",
                Type    = "web_hook",
                Address = "http://dtsl.ehb.be/~bo.bracquez/webhook.php",
            });
        }