public bool Delete(Task task)
 {
     ErrorMessage = String.Empty;
     CalendarService service = new CalendarService("googleCalendar");
     service.setUserCredentials(task.AccountInfo.Username, task.AccountInfo.Password);
     Log.InfoFormat("Fetching google account : [{0}]", task.AccountInfo.ToString());
     string queryUri = String.Format(CultureInfo.InvariantCulture,
                                     "http://www.google.com/calendar/feeds/{0}/private/full",
                                     service.Credentials.Username);
     Log.DebugFormat("Query='{0}'", queryUri);
     EventQuery eventQuery = new EventQuery(queryUri);
     try
     {
         EventFeed eventFeed = service.Query(eventQuery);
         foreach (EventEntry eventEntry in eventFeed.Entries.Cast<EventEntry>())
         {
             if (eventEntry.Times.Count > 0)
             {
                 if (eventEntry.EventId == task.Id)
                 {
                     Log.InfoFormat("Deleting : [{0}]-[{1}]", eventEntry.EventId, eventEntry.Title);
                     eventEntry.Delete();
                     return true;
                 }
             }
         }
     }
     catch (Exception exception)
     {
         Log.ErrorFormat(exception.Message);
         Log.ErrorFormat(exception.ToString());
         ErrorMessage = exception.Message;
     }
     return false;
 }
 public bool Insert(Task task)
 {
     EventEntry eventEntry = new EventEntry
                             {
                                 Title = {Text = task.Head},
                                 Content = {Content = task.Description,},
                                 Locations = {new Where("", "", task.Location)},
                                 Times = {new When(task.StartDate, task.StopDate)},
                             };
     Log.InfoFormat("Inserting new entry to google : [{0}]", task.ToString());
     CalendarService service = new CalendarService("googleCalendarInsert");
     service.setUserCredentials(task.AccountInfo.Username, task.AccountInfo.Password);
     Uri postUri = new Uri("https://www.google.com/calendar/feeds/default/private/full");
     ErrorMessage = String.Empty;
     try
     {
         EventEntry createdEntry = service.Insert(postUri, eventEntry);
         return createdEntry != null;
     }
     catch (Exception exception)
     {
         Log.ErrorFormat(exception.Message);
         Log.ErrorFormat(exception.ToString());
         ErrorMessage = exception.Message;
     }
     return false;
 }
Example #3
0
 private CalendarService getService()
 {
     // Create a CalenderService and authenticate
     CalendarService googleCalendarService = new CalendarService("rpcwc-rpcwcorg-2");
     googleCalendarService.setUserCredentials("*****@*****.**", "Vert1go");
     return googleCalendarService;
 }
Example #4
0
 public GoogleCalendar()
 {
     this.userName = GoogleUsername;
     this.userPassword = GooglePassword;
     calendarService = new CalendarService("webcsm");
     calendarService.setUserCredentials(userName, userPassword);
 }
Example #5
0
 public BookThemAllSample(string domain, string admin, string password)
 {
     apps = new AppsService(domain, admin, password);
     calendar = new CalendarService("BookThemAll");
     calendar.setUserCredentials(admin, password);
     this.admin = admin;
 }
Example #6
0
 public CalendarManager(string email, string password)
 {
     _userID = email;
     _password = password;
     _myService = new CalendarService("Bruce's Application");
     _myService.setUserCredentials(_userID, _password);
 }
Example #7
0
        public void googlecalendarSMSreminder(string sendstring)
        {
            CalendarService service = new CalendarService("exampleCo-exampleApp-1");
            service.setUserCredentials(UserName.Text, Password.Text);

            EventEntry entry = new EventEntry();

            // Set the title and content of the entry.
            entry.Title.Text = sendstring;
            entry.Content.Content = "Nadpis Test SMS.";
            // Set a location for the event.
            Where eventLocation = new Where();
            eventLocation.ValueString = "Test sms";
            entry.Locations.Add(eventLocation);

            When eventTime = new When(DateTime.Now.AddMinutes(3), DateTime.Now.AddHours(1));
            entry.Times.Add(eventTime);

            //Add SMS Reminder
            Reminder fiftyMinReminder = new Reminder();
            fiftyMinReminder.Minutes = 1;
            fiftyMinReminder.Method = Reminder.ReminderMethod.sms;
            entry.Reminders.Add(fiftyMinReminder);

            Uri postUri = new Uri("http://www.google.com/calendar/feeds/default/private/full");

            // Send the request and receive the response:
            AtomEntry insertedEntry = service.Insert(postUri, entry);
        }
        public static List<CalendarEvent> GetCalendarEvents(Calendar calendar)
        {
            List<CalendarEvent> eventList = new List<CalendarEvent>();

            EventQuery query = new EventQuery();
            CalendarService service = new CalendarService("GoogleCalendarReminder");
            service.SetAuthenticationToken(GetAuthToken());

            //service.setUserCredentials(Account.Default.Username
            //                            , SecureStringUtility.SecureStringToString(Account.Default.Password));

            query.Uri = new Uri(calendar.CalendarUri);
            query.SingleEvents = true;
            query.StartTime = DateTime.Now;
            query.EndTime = DateTime.Today.AddDays(Settings.Default.DayRange);

            EventFeed calFeed;
            try
            {
                calFeed = service.Query(query) as EventFeed;
            }
            catch (Exception)
            {
                return null;
            }

            // now populate the calendar
            while (calFeed != null && calFeed.Entries.Count > 0)
            {
                foreach (EventEntry entry in calFeed.Entries)
                {
                    eventList.Add(new CalendarEvent(entry)
                                        {
                                            Color = calendar.Color
                                        });
                }

                // just query the same query again.
                if (calFeed.NextChunk != null)
                {
                    query.Uri = new Uri(calFeed.NextChunk);

                    try
                    {
                        calFeed = service.Query(query) as EventFeed;
                    }
                    catch (Exception ex)
                    {
                        return null;
                    }
                }
                else
                {
                    calFeed = null;
                }
            }

            return eventList;
        }
        public static void ClassInit( TestContext context )
        {
            _creds = GooCalCreds.CreateAndValidate();
            _calendarPurge = (CalendarPurge)CalendarPurgeFactory.Create( _creds );
            _service = _calendarPurge.GoogleCalendarService;

            DeleteAllEvents();
        }
Example #10
0
        public void Authenticate(string account, string password)
        {
            _calendarService = new Google.GData.Calendar.CalendarService("");
            _calendarService.setUserCredentials(account, password);

            _calendarUri = new Uri(string.Format("https://www.google.com/calendar/feeds/{0}/private/full", account));
            _isAuthenticated = true;
        }
 public GoogleCalendar(string username, string password, int numHours)
 {
     calendar = CalendarHelper.GetService("Jarvis", username, password);
     getCurrentEvents();
     this.numHours = numHours;
     userPresent = true;
     alertedOf = new LinkedList<string>();
     lastCleared = DateTime.Now;
 }
Example #12
0
        public PostableEvents GetPostableEvents(string calendarId)
        {
            var result = new PostableEvents();

            var service = new CalendarService("WascherCom.Auto.CalendarToBlog");

            if (!string.IsNullOrWhiteSpace(UserId))
            {
                service.setUserCredentials(UserId, Password);
            }

            var query = new EventQuery
                {
                    Uri = new Uri(string.Format(GOOGLE_URI, calendarId)),
                    StartTime = StartDate.AddDays(-DaysForPastEvents),
                    EndTime = StartDate.AddDays(DaysForCurrentEvents + DaysForFutureEvents)
                };

            var eventFeed = service.Query(query);

            if (eventFeed == null || eventFeed.Entries.Count == 0)
            {
                return result;
            }

            foreach (EventEntry entry in eventFeed.Entries)
            {
                foreach (var time in entry.Times)
                {
                    var calEvent = new CalendarEvent
                        {
                            Title = entry.Title.Text,
                            Description = string.Empty,
                            StartDateTime = time.StartTime,
                            EndDateTime = time.EndTime,
                            IsAllDay = time.AllDay
                        };

                    if (calEvent.StartDateTime < StartDate)
                    {
                        result.PastEvents.Add(calEvent);
                    }
                    else if (calEvent.StartDateTime > StartDate.AddDays(DaysForCurrentEvents))
                    {
                        result.FutureEvents.Add(calEvent);
                    }
                    else
                    {
                        result.CurrentEvents.Add(calEvent);
                    }

                    Console.WriteLine(string.Format("{0}: {1} All Day: {2}", entry.Title.Text, time.StartTime, time.AllDay));
                }
            }

            return result;
        }
        public void AuthenticateV2()
        {
            // create an OAuth factory to use
            log.Debug("Authenticating to calendar service using 2-legged OAuth");
            GOAuthRequestFactory requestFactory = new GOAuthRequestFactory("cl", "MyApp");
            requestFactory.ConsumerKey = ConfigurationManager.AppSettings["consumerKey"];
            requestFactory.ConsumerSecret = ConfigurationManager.AppSettings["consumerSecret"];

            service = new CalendarService("MyApp");
            service.RequestFactory = requestFactory;
        }
Example #14
0
        public bool Init(string user, string password)
        {
            service = new CalendarService("GTrello");
            service.setUserCredentials(user, password);

            if (!LoadMapping())
            {
                return false;
            }
            return CollectEntries();
        }
 private void SetProxy(CalendarService service)
 {
     var f = (GDataRequestFactory) service.RequestFactory;
     IWebProxy iProxy = WebRequest.DefaultWebProxy;
     var myProxy = new WebProxy(iProxy.GetProxy(new Uri(GOOGLE_CALENDAR_URI)))
                   	{
                   		Credentials = CredentialCache.DefaultCredentials,
                   		UseDefaultCredentials = true
                   	};
     f.Proxy = myProxy;
 }
Example #16
0
        /// <summary>
        /// Prints the titles of all events on the specified calendar.
        /// </summary>
        /// <param name="service">The authenticated CalendarService object.</param>
        static void PrintAllEvents(CalendarService service)
        {
            EventQuery myQuery = new EventQuery(feedUri);
            EventFeed myResultsFeed = service.Query(myQuery) as EventFeed;

            Console.WriteLine("All events on your calendar:");
            Console.WriteLine();
            for (int i = 0; i < myResultsFeed.Entries.Count; i++)
            {
                Console.WriteLine(myResultsFeed.Entries[i].Title.Text);
            }
            Console.WriteLine();
        }
Example #17
0
        static void Main(string[] args)
        {
            try
            {
                // create an OAuth factory to use
                GOAuthRequestFactory requestFactory = new GOAuthRequestFactory("cl", "MyApp");
                requestFactory.ConsumerKey = "CONSUMER_KEY";
                requestFactory.ConsumerSecret = "CONSUMER_SECRET";

                // example of performing a query (use OAuthUri or query.OAuthRequestorId)
                Uri calendarUri = new OAuthUri("http://www.google.com/calendar/feeds/default/owncalendars/full", "USER", "DOMAIN");
                // can use plain Uri if setting OAuthRequestorId in the query
                // Uri calendarUri = new Uri("http://www.google.com/calendar/feeds/default/owncalendars/full");

                CalendarQuery query = new CalendarQuery();
                query.Uri = calendarUri;
                query.OAuthRequestorId = "USER@DOMAIN"; // can do this instead of using OAuthUri for queries

                CalendarService service = new CalendarService("MyApp");
                service.RequestFactory = requestFactory;
                service.Query(query);
                Console.WriteLine("Query Success!");

                // example with insert (must use OAuthUri)
                Uri contactsUri = new OAuthUri("http://www.google.com/m8/feeds/contacts/default/full", "USER", "DOMAIN");

                ContactEntry entry = new ContactEntry();
                EMail primaryEmail = new EMail("*****@*****.**");
                primaryEmail.Primary = true;
                primaryEmail.Rel = ContactsRelationships.IsHome;
                entry.Emails.Add(primaryEmail);

                ContactsService contactsService = new ContactsService("MyApp");
                contactsService.RequestFactory = requestFactory;
                contactsService.Insert(contactsUri, entry); // this could throw if contact exists

                Console.WriteLine("Insert Success!");

                // to perform a batch use
                // service.Batch(batchFeed, new OAuthUri(atomFeed.Batch, userName, domain));

                Console.ReadKey();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Fail!");
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                Console.ReadKey();
            }
        }
Example #18
0
        private void createNewCalendar(CalendarService service)
        {
            CalendarEntry calendar = new CalendarEntry();
            calendar.Title.Text = textBox1.Text;//"Little League Schedule";
            calendar.Summary.Text = "This calendar contains the practice schedule and game times.";
            calendar.TimeZone = "America/Los_Angeles";
            calendar.Hidden = false;
            calendar.Color = "#2952A3";
            calendar.Location = new  Where("", "", "Oakland");

            Uri postUri = new Uri("https://www.google.com/calendar/feeds/default/owncalendars/full");
            CalendarEntry createdCalendar = (CalendarEntry)service.Insert(postUri, calendar);
            refreshCalendar();
        }
Example #19
0
        /// <summary>
        /// Prints the titles of all events matching a full-text query.
        /// </summary>
        /// <param name="service">The authenticated CalendarService object.</param>
        /// <param name="queryString">The text for which to query.</param>
        static void FullTextQuery(CalendarService service, String queryString)
        {
            EventQuery myQuery = new EventQuery(feedUri);
            myQuery.Query = queryString;

            EventFeed myResultsFeed = service.Query(myQuery) as EventFeed;

            Console.WriteLine("Events matching \"{0}\":", queryString);
            Console.WriteLine();
            for (int i = 0; i < myResultsFeed.Entries.Count; i++)
            {
                Console.WriteLine(myResultsFeed.Entries[i].Title.Text);
            }
            Console.WriteLine();
        }
Example #20
0
        /// <summary>
        /// Prints a list of the user's calendars.
        /// </summary>
        /// <param name="service">The authenticated CalendarService object.</param>
        static void PrintUserCalendars(CalendarService service)
        {
            FeedQuery query = new FeedQuery();
            query.Uri = new Uri("http://www.google.com/calendar/feeds/default");

            // Tell the service to query:
            AtomFeed calFeed = service.Query(query);

            Console.WriteLine("Your calendars:");
            Console.WriteLine();
            for (int i = 0; i < calFeed.Entries.Count; i++)
            {
                Console.WriteLine(calFeed.Entries[i].Title.Text);
            }
            Console.WriteLine();
        }
Example #21
0
        /// <summary>
        /// Prints the titles of all events in a specified date/time range.
        /// </summary>
        /// <param name="service">The authenticated CalendarService object.</param>
        /// <param name="startTime">Start time (inclusive) of events to print.</param>
        /// <param name="endTime">End time (exclusive) of events to print.</param>
        static void DateRangeQuery(CalendarService service, DateTime startTime, DateTime endTime)
        {
            EventQuery myQuery = new EventQuery(feedUri);
            myQuery.StartTime = startTime;
            myQuery.EndTime = endTime;

            EventFeed myResultsFeed = service.Query(myQuery) as EventFeed;

            Console.WriteLine("Matching events from {0} to {1}:", 
                              startTime.ToShortDateString(),
                              endTime.ToShortDateString());
            Console.WriteLine();
            for (int i = 0; i < myResultsFeed.Entries.Count; i++)
            {
                Console.WriteLine(myResultsFeed.Entries[i].Title.Text);
            }
            Console.WriteLine();
        }
        /// <summary>
        /// Shares a calendar with the specified user.  Note that this method
        /// will not run by default.
        /// </summary>
        /// <param name="service">The authenticated CalendarService object.</param>
        /// <param name="aclFeedUri">the ACL feed URI of the calendar being shared.</param>
        /// <param name="userEmail">The email address of the user with whom to share.</param>
        /// <param name="role">The role of the user with whom to share.</param>
        /// <returns>The AclEntry returned by the server.</returns>
        static AclEntry AddAccessControl(CalendarService service, string aclFeedUri,
            string userEmail, AclRole role)
        {
            AclEntry entry = new AclEntry();

            entry.Scope = new AclScope();
            entry.Scope.Type = AclScope.SCOPE_USER;
            entry.Scope.Value = userEmail;

            entry.Role = role;

            Uri aclUri =
                new Uri("http://www.google.com/calendar/feeds/[email protected]/acl/full");

            AclEntry insertedEntry = service.Insert(aclUri, entry);
            Console.WriteLine("Added user {0}", insertedEntry.Scope.Value);

            return insertedEntry;
        }
Example #23
0
        // Validates a username/pass by attempting to login to calendar
        public static bool checkPw(string username, string password)
        {
            GDataGAuthRequestFactory authFactory = new GDataGAuthRequestFactory("cl", "Seadragon");
            authFactory.AccountType = "HOSTED";

            CalendarService client = new CalendarService(authFactory.ApplicationName);
            client.RequestFactory = authFactory;
            client.setUserCredentials(username + "@" + DOMAIN, password);

            try
            {
                client.QueryClientLoginToken(); // Authenticate the user immediately
            }
            catch (WebException)     // Invalid login
            {
                return false;
            }

            return true;
        }
Example #24
0
        public static void export(string email, string password, List<LeadTask> tasks)
        {
            CalendarService myService = new CalendarService("exportToGCalendar");
            myService.setUserCredentials(email, password);

            foreach (LeadTask task in tasks) {
                EventEntry entry = new EventEntry();

                // Set the title and content of the entry.
                entry.Title.Text = task.text;
                entry.Content.Content = task.details;

                When eventTime = new When((DateTime)task.start_date, (DateTime)task.end_date);
                entry.Times.Add(eventTime);

                Uri postUri = new Uri("https://www.google.com/calendar/feeds/default/private/full");

                // Send the request and receive the response:
                Google.GData.Client.AtomEntry insertedEntry = myService.Insert(postUri, entry);
            }
        }
Example #25
0
        public  async Task<string> Insert(Guid userId, string title, string content, DateTime start, DateTime end)
        {
            try
            {
                //同步到Google日历
                var item = _iSysUserService.GetById(userId);

                if (string.IsNullOrEmpty(item.GoogleUserName) || string.IsNullOrEmpty(item.GooglePassword)) return "";

                var myService = new CalendarService(item.GoogleUserName);
                myService.setUserCredentials(item.GoogleUserName, item.GooglePassword);

                // Set the title and content of the entry.
                var entry = new EventEntry
                {
                    Title = { Text = "云集 " + title },
                    Content = { Content = content }
                };

                //计划时间
                var eventTime = new When(start, end);

                //判断是否为全天计划
                if (start.Date != end.Date)
                    eventTime.AllDay = true;

                entry.Times.Add(eventTime);

                var postUri = new Uri("https://www.google.com/calendar/feeds/default/private/full");

                // Send the request and receive the response:
                var eventEntry = myService.Insert(postUri, entry);
                return eventEntry.EventId;
            }
            catch
            {
                return "";
            }
        }
Example #26
0
        private void deleteCalendar(CalendarService service,string calendarTitle)
        {
            //assume title is non-empty for now
            CalendarQuery query = new CalendarQuery();
            query.Uri = new Uri("https://www.google.com/calendar/feeds/default/owncalendars/full");
            CalendarFeed resultFeed = (CalendarFeed)service.Query(query);

            foreach (CalendarEntry entry in resultFeed.Entries)
            {
                if (entry.Title.Text == calendarTitle)
                {
                    try
                    {
                        entry.Delete();
                    }
                    catch (GDataRequestException)
                    {
                        MessageBox.Show("Unable to delete primary calendar.\n");
                    }
                }
            }
        }
        public EventDto[] GetItems()
        {
            EventQuery query = new EventQuery();
            CalendarService service = new CalendarService("Virtual ALT.NET calendar");

            query.Uri = new Uri(@"http://www.google.com/calendar/feeds/[email protected]/public/full");
            query.StartTime = DateTime.Now;
            query.EndTime = DateTime.Now.AddMonths(3);
            query.SingleEvents = true;
            query.ExtraParameters = "orderby=starttime&sortorder=ascending";

            try
            {
                EventFeed calFeed = service.Query(query);

                return this.GetEventDtos(calFeed.Entries.OfType<EventEntry>());
            }
            catch (Exception)
            {
                return new EventDto[0];
            }
        }
Example #28
0
        public async Task Delete(Guid userId, string eventId)
        {
            try
            {
                var item = _iSysUserService.GetById(userId);

                if (string.IsNullOrEmpty(item.GoogleUserName) || string.IsNullOrEmpty(item.GooglePassword)) return;
                var myService = new CalendarService(item.GoogleUserName);
                myService.setUserCredentials(item.GoogleUserName, item.GooglePassword);

                var calendar =
                    myService.Get("https://www.google.com/calendar/feeds/default/private/full/" + eventId);

                foreach (var item1 in calendar.Feed.Entries)
                {
                    item1.Delete();
                }
            }
            catch
            {
            }
        }
Example #29
0
        static void Main(string[] args)
        {
            //
            // TODO: Add code to start application here
            //
            if (args.Length != 1 && args.Length != 3)
            {
                Console.WriteLine("Not enough parameters. Usage is Sample <uri> <username> <password>");
                return;
            }

            string calendarURI = args[0];

            string userName = args.Length == 3 ? args[1] : null;
            string passWord = args.Length == 3 ? args[2] : null;

            EventQuery query = new EventQuery();
            CalendarService service = new CalendarService(ApplicationName);

            if (userName != null)
            {
                service.setUserCredentials(userName, passWord);
            }

            query.Uri = new Uri(calendarURI);
            EventFeed calFeed = service.Query(query) as EventFeed;

            Console.WriteLine("");
            Console.WriteLine("Query Feed Test " + query.Uri);

            Console.WriteLine("Post URI is:  " + calFeed.Post); 

            foreach (EventEntry feedEntry in calFeed.Entries)
            {
                DumpEventEntry(feedEntry);
            }
        }
Example #30
0
        static void Main(string[] args)
        {
            //
            // TODO: Add code to start application here
            //
            if (args.Length < 3)
            {
                Console.WriteLine("Not enough parameters. Usage is Sample <uri> <username> <password>");
                return;
            }

            string calendarURI = args[0];
            string userName = args[1];
            string passWord = args[2];

            EventQuery query = new EventQuery();
            CalendarService service = new CalendarService(ApplicationName);

            if (userName != null)
            {
                service.setUserCredentials(userName, passWord);
            }

            query.Uri = new Uri(calendarURI);
            EventFeed calFeed = service.Query(query);

            EventEntry insertedEntry = InsertEvent(calFeed, "Conference www2006",
                "Frank Mantek", DateTime.Now, 
                                DateTime.Now.AddDays(1), 
                                true,
                                "Edinburgh");

            if (insertedEntry != null) 
            {
                DumpEventEntry(insertedEntry);
            }
        }