Beispiel #1
0
        //static string user1name = ConfigurationManager.AppSettings["CalendarUser1"].ToString();
        //static string user1pwd = ConfigurationManager.AppSettings["Calendarpass1"].ToString();
        public static void AddEvent1(CalendarService service, string id, string title, string contents, string location, DateTime startTime, DateTime endTime, string calendarName, string emailId)
        {
            try
            {
                Google.GData.Calendar.EventEntry entry = new Google.GData.Calendar.EventEntry();
                // Set the title and content of the entry.
                entry.Title.Text      = id + "-" + title;
                entry.Content.Content = contents;

                // Set a location for the event.
                Where eventLocation = new Where();
                eventLocation.ValueString = location;
                entry.Locations.Add(eventLocation);

                When eventTime = new When(startTime, endTime);
                entry.Times.Add(eventTime);
                GoogleCalendar ggadmin = new GoogleCalendar(calendarName, AdminuserName, AdminuserPwd);
                // string CalendarId = ggadmin.GetCalendarId();

                //CalendarService Calservice = new CalendarService("CalendarSampleApp");
                AclEntry aclEntry = new AclEntry();

                aclEntry.Scope       = new AclScope();
                aclEntry.Scope.Type  = AclScope.SCOPE_USER;
                aclEntry.Scope.Value = emailId;
                aclEntry.Role        = AclRole.ACL_CALENDAR_READ;
                // Uri postUri = new Uri("https://www.google.com/calendar/feeds/" + CalendarId + "/private/full");

                Uri aclUri = new Uri(string.Format("https://www.google.com/calendar/feeds/{0}/acl/full", service.Credentials.Username.ToString()));



                GDataGAuthRequestFactory requestFactory = (GDataGAuthRequestFactory)service.RequestFactory;
                IWebProxy iProxy  = WebRequest.GetSystemWebProxy();
                WebProxy  myProxy = new WebProxy();
                // potentially, setup credentials on the proxy here
                myProxy.Credentials           = CredentialCache.DefaultCredentials;
                myProxy.UseDefaultCredentials = false;

                // requestFactory.CreateRequest(GDataRequestType.Insert, postUri);//  = myProxy;
                // Send the request and receive the response:
                //AtomEntry insertEntry = service.Insert(postUri, entry);

                AclEntry insertedEntry = service.Insert(aclUri, aclEntry) as AclEntry;
            }
            catch (Exception ex)
            {
                //LogManager.Instance.WriteToFlatFile(ex.Message);
            }
        }
Beispiel #2
0
        public static void AddEvent(CalendarService service, string id, string title, string contents, string location, DateTime startTime, DateTime endTime, string calendarName)
        {
            try
            {
                Google.GData.Calendar.EventEntry entry = new Google.GData.Calendar.EventEntry();
                // Set the title and content of the entry.
                entry.Title.Text      = id + "-" + title;
                entry.Content.Content = contents;

                // Set a location for the event.
                Where eventLocation = new Where();
                eventLocation.ValueString = location;
                entry.Locations.Add(eventLocation);

                When eventTime = new When(startTime, endTime);
                entry.Times.Add(eventTime);
                GoogleCalendar ggadmin    = new GoogleCalendar(calendarName, AdminuserName, AdminuserPwd);
                string         CalendarId = ggadmin.GetCalendarId();


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


                GDataGAuthRequestFactory requestFactory = (GDataGAuthRequestFactory)service.RequestFactory;
                IWebProxy iProxy  = WebRequest.GetSystemWebProxy();
                WebProxy  myProxy = new WebProxy();
                // potentially, setup credentials on the proxy here
                myProxy.Credentials           = CredentialCache.DefaultCredentials;
                myProxy.UseDefaultCredentials = false;

                requestFactory.CreateRequest(GDataRequestType.Insert, postUri);//  = myProxy;
                // Send the request and receive the response:
                AtomEntry insertedEntry = service.Insert(postUri, entry);
            }
            catch (Exception ex)
            {
                //LogManager.Instance.WriteToFlatFile(ex.Message);
            }
        }