Exemple #1
0
        // throws duplication name exception
        // throws UUID error/ not found exception
        public static Calendar InewCalendar(Calendar newCalendar, string uuid, string version)
        {
            IList <CalendarListEntry> calendars = IgetAllCalendars();

            // tests if there are any calendars
            if (calendars != null)
            {
                //tests duplication name
                foreach (var cal in calendars)
                {
                    if (cal.Summary == newCalendar.Summary)
                    {
                        throw new DuplicationException("Name duplication");
                    }
                }
            }

            // creates new calendar
            newCalendar.Description = version;
            var createdCalendar = service.Calendars.Insert(newCalendar).Execute();

            // updates UUIDMaster
            // throws UUID error / not found exception
            uuidMaster.PutUpdateUUID(uuid, createdCalendar.Id, Int32.Parse(version));

            uuidMaster.PutUpdateUUID(String.Format("name-property-{0}", createdCalendar.Id), createdCalendar.Summary.Trim(), Calendarss.getversion(String.Format("name-property-{0}", createdCalendar.Id)) + 1);

            return(createdCalendar);
        }
Exemple #2
0
        // throws duplication name exception
        // throws doesn't excist exception
        // throws no calendar excists exception
        // throws UUID error/ not found exception
        public static Calendar IupdateCalendarById(Calendar UpdateCalendar, string uuid, string version)
        {
            IList <CalendarListEntry> calendars = IgetAllCalendars();

            // tests if there are any calendars
            if (calendars != null)
            {
                //tests duplication name (if name already excists in an other calendar it throws the exception)
                foreach (var cal in calendars)
                {
                    if (cal.Summary == UpdateCalendar.Summary)
                    {
                        if (cal.Id != IgetId(uuid))
                        {
                            throw new DuplicationException("Name duplication");
                        }
                    }
                }
            }
            // no calendar
            else
            {
                throw new NoCalendarsExistException("there are no calendars");
            }

            // updates calendar
            UpdateCalendar.Description = version;
            // throws doesn't excist exception
            Calendar updatedCalendar = service.Calendars.Update(UpdateCalendar, IgetId(uuid)).Execute();

            // updates UUIDMaster
            // throws UUID error/ not found exception
            uuidMaster.PutUpdateUUID(uuid, updatedCalendar.Id, Int32.Parse(version));

            uuidMaster.PutUpdateUUID(String.Format("name-property-{0}", updatedCalendar.Id), updatedCalendar.Summary.Trim(), Calendarss.getversion(String.Format("name-property-{0}", updatedCalendar.Id)) + 1);

            return(updatedCalendar);
        }
Exemple #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",
            });
        }