コード例 #1
0
        internal static void GetAccessToken(GoogleTestUser user, out string access_token, out string refresh_token)
        {
            string token_type;
            int    expires_in;

            GoogleOAuthHelper.GetAccessToken(user, out access_token, out refresh_token, out token_type, out expires_in);
        }
コード例 #2
0
        public static void Run()
        {
            try
            {
                GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret");
                string         accessToken;
                string         refreshToken;
                GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken);

                // Get IGmailclient
                using (IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail))
                {
                    Contact[] contacts = client.GetAllContacts();
                    Contact   contact  = contacts[0];

                    // ExStart:DeleteGmailContact
                    client.DeleteContact(contact.Id.GoogleId);
                    // ExEnd:DeleteGmailContact
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #3
0
        public static void Run()
        {
            try
            {
                // ExStart:UpdateGmailContact
                GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret");
                string         accessToken;
                string         refreshToken;
                GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken);

                // Get IGmailclient
                using (IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail))
                {
                    Contact[] contacts = client.GetAllContacts();
                    Contact   contact  = contacts[0];
                    contact.JobTitle       = "Manager IT";
                    contact.DepartmentName = "Customer Support";
                    contact.CompanyName    = "Aspose";
                    contact.Profession     = "Software Developer";
                    client.UpdateContact(contact);
                }
                // ExEnd:UpdateGmailContact
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #4
0
        public static void Run()
        {
            try
            {
                // ExStart:AccessColorInfo
                GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret");
                string         accessToken;
                string         refreshToken;
                GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken);

                using (IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail))
                {
                    ColorsInfo colors = client.GetColors();
                    Dictionary <string, Colors> palettes = colors.Calendar;

                    // Traverse the settings list
                    foreach (KeyValuePair <string, Colors> pair in palettes)
                    {
                        Console.WriteLine("Key = " + pair.Key + ", Color = " + pair.Value);
                    }
                    Console.WriteLine("Update Date = " + colors.Updated);
                }
                // ExEnd:AccessColorInfo
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #5
0
        public static void Run()
        {
            try
            {
                // ExStart:DeleteParticularCalendar
                // Get access token
                GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret");
                string         accessToken;
                string         refreshToken;
                GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken);

                using (IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail))
                {
                    // Access and delete calendar with summary starting from "Calendar summary - "
                    string summary = "Calendar summary - ";

                    // Get calendars list
                    ExtendedCalendar[] lst0 = client.ListCalendars();

                    foreach (ExtendedCalendar extCal in lst0)
                    {
                        // Delete selected calendars
                        if (extCal.Summary.StartsWith(summary))
                        {
                            client.DeleteCalendar(extCal.Id);
                        }
                    }
                }
                // ExEnd:DeleteParticularCalendar
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #6
0
        public static void Run()
        {
            try
            {
                string         dataDir = RunExamples.GetDataDir_Gmail();
                GoogleTestUser User2   = new GoogleTestUser("user", "email address", "password", "clientId", "client secret");
                string         accessToken;
                string         refreshToken;
                GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken);

                // Get IGmailclient
                using (IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail))
                {
                    Contact[] contacts = client.GetAllContacts();
                    Contact   contact  = contacts[0];

                    // ExStart:SavingContact
                    contact.Save(dataDir + "contact_out.msg", ContactSaveFormat.Msg);
                    contact.Save(dataDir + "contact_out.vcf", ContactSaveFormat.VCard);
                    // ExEnd:SavingContact
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #7
0
        internal static void GetAccessToken(string authorizationCode, GoogleTestUser user, out string access_token, out string token_type, out int expires_in, out string refresh_token)
        {
            access_token  = null;
            token_type    = null;
            expires_in    = 0;
            refresh_token = null;
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(TOKEN_REQUEST_URL);

            request.CookieContainer = new CookieContainer();
            request.Method          = "POST";
            request.ContentType     = "application/x-www-form-urlencoded";
            string encodedParameters = string.Format("client_id={0}&code={1}&client_secret={2}&redirect_uri={3}&grant_type={4}", System.Web.HttpUtility.UrlEncode(user.ClientId), System.Web.HttpUtility.UrlEncode(authorizationCode), System.Web.HttpUtility.UrlEncode(user.ClientSecret), System.Web.HttpUtility.UrlEncode(REDIRECT_URI), System.Web.HttpUtility.UrlEncode(GrantTypes.authorization_code.ToString()));

            byte[] requestData = Encoding.UTF8.GetBytes(encodedParameters);
            request.ContentLength = requestData.Length;
            if (requestData.Length > 0)
            {
                using (Stream stream = request.GetRequestStream())
                    stream.Write(requestData, 0, requestData.Length);
            }
            HttpWebResponse response     = (HttpWebResponse)request.GetResponse();
            string          responseText = null;

            using (TextReader reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII))
                responseText = reader.ReadToEnd();
            foreach (string sPair in responseText.Replace("{", "").Replace("}", "").Replace("\"", "").Split(new string[] { ",\n" }, StringSplitOptions.None))
            {
                string[] pair  = sPair.Split(':');
                string   name  = pair[0].Trim().ToLower();
                string   value = System.Web.HttpUtility.UrlDecode(pair[1].Trim());
                switch (name)
                {
                case "access_token":
                    access_token = value;
                    break;

                case "token_type":
                    token_type = value;
                    break;

                case "expires_in":
                    expires_in = Convert.ToInt32(value);
                    break;

                case "refresh_token":
                    refresh_token = value;
                    break;
                }
            }

            Debug.WriteLine(string.Format("Authorization code: '{0}'", authorizationCode));
            Debug.WriteLine(string.Format("Access token: '{0}'", access_token));
            Debug.WriteLine(string.Format("Refresh token: '{0}'", refresh_token));
            Debug.WriteLine(string.Format("Token type: '{0}'", token_type));
            Debug.WriteLine(string.Format("Expires in: '{0}'", expires_in));
            Debug.WriteLine("---------------------------------------------------------");
            Debug.WriteLine("");
        }
コード例 #8
0
        internal static string GetAccessToken(GoogleTestUser user)
        {
            string access_token;
            string token_type;
            int    expires_in;

            GetAccessToken(user, out access_token, out token_type, out expires_in);
            return(access_token);
        }
コード例 #9
0
        public static void Run()
        {
            try
            {
                // ExStart:AccessGmailContacts
                GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret");
                string         accessToken;
                string         refreshToken;
                GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken);

                // Get IGmailclient
                using (IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail))
                {
                    Contact[] contacts = client.GetAllContacts();
                    foreach (Contact contact in contacts)
                    {
                        Console.WriteLine(contact.DisplayName + ", " + contact.EmailAddresses[0]);
                    }

                    // Fetch contacts from a specific group
                    ContactGroupCollection groups = client.GetAllGroups();
                    GoogleContactGroup     group  = null;
                    foreach (GoogleContactGroup g in groups)
                    {
                        switch (g.Title)
                        {
                        case "TestGroup": group = g;
                            break;
                        }
                    }

                    // Retrieve contacts from the Group
                    if (group != null)
                    {
                        Contact[] contacts2 = client.GetContactsFromGroup(group.Id);
                        foreach (Contact con in contacts2)
                        {
                            Console.WriteLine(con.DisplayName + "," + con.EmailAddresses[0].ToString());
                        }
                    }
                }
                // ExEnd:AccessGmailContacts
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #10
0
        public static void Run()
        {
            try
            {
                // ExStart:InsertFetchAndUpdateCalendar
                // Get access token
                GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret");
                string         accessToken;
                string         refreshToken;
                GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken);

                using (IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail))
                {
                    // Insert, get and update calendar
                    Aspose.Email.Clients.Google.Calendar calendar = new Aspose.Email.Clients.Google.Calendar("summary - " + Guid.NewGuid().ToString(), null, null, "America/Los_Angeles");

                    // Insert calendar and Retrieve same calendar using id
                    string id = client.CreateCalendar(calendar);
                    Aspose.Email.Clients.Google.Calendar cal = client.FetchCalendar(id);

                    //Match the retrieved calendar info with local calendar
                    if ((calendar.Summary == cal.Summary) && (calendar.TimeZone == cal.TimeZone))
                    {
                        Console.WriteLine("fetched calendar information matches");
                    }
                    else
                    {
                        Console.WriteLine("fetched calendar information does not match");
                    }

                    // Change information in the fetched calendar and Update calendar
                    cal.Description = "Description - " + Guid.NewGuid().ToString();
                    cal.Location    = "Location - " + Guid.NewGuid().ToString();
                    client.UpdateCalendar(cal);
                }

                // ExEnd:InsertFetchAndUpdateCalendar
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #11
0
        public static void Run()
        {
            try
            {
                // ExStart:AccessClientSettings
                GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret");
                string         accessToken;
                string         refreshToken;
                GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken);

                using (IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail))
                {
                    // Retrieve client settings
                    Dictionary <string, string> settings = client.GetSettings();
                    if (settings.Count < 1)
                    {
                        Console.WriteLine("No settings are available.");
                        return;
                    }

                    // Traverse the settings list
                    foreach (KeyValuePair <string, string> pair in settings)
                    {
                        // Get the setting value and test if settings are ok
                        string value = client.GetSetting(pair.Key);
                        if (pair.Value == value)
                        {
                            Console.WriteLine("Key = " + pair.Key + ", Value = " + pair.Value);
                        }
                        else
                        {
                            Console.WriteLine("Settings could not be retrieved");
                        }
                    }
                }
                // ExEnd:AccessClientSettings
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #12
0
        public static void Run()
        {
            try
            {
                // ExStart:MoveAndDeleteAppointment
                GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret");
                string         accessToken;
                string         refreshToken;
                GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken);

                // Get IGmailclient
                using (IGmailClient client = Aspose.Email.Clients.Google.GmailClient.GetInstance(accessToken, User2.EMail))
                {
                    string SourceCalendarId      = client.ListCalendars()[0].Id;
                    string DestinationCalendarId = client.ListCalendars()[1].Id;
                    string TargetAppUniqueId     = client.ListAppointments(SourceCalendarId)[0].UniqueId;

                    // Retrieve the list of appointments in the destination calendar before moving the appointment
                    Appointment[] appointments = client.ListAppointments(DestinationCalendarId);
                    Console.WriteLine("Before moving count = " + appointments.Length);
                    Appointment Movedapp = client.MoveAppointment(SourceCalendarId, DestinationCalendarId, TargetAppUniqueId);

                    // Retrieve the list of appointments in the destination calendar after moving the appointment
                    appointments = client.ListAppointments(DestinationCalendarId);
                    Console.WriteLine("After moving count = " + appointments.Length);

                    // Delete particular appointment from a calendar using unique id
                    client.DeleteAppointment(DestinationCalendarId, Movedapp.UniqueId);

                    // Retrieve the list of appointments. It should be one less than the earlier appointments in the destination calendar
                    appointments = client.ListAppointments(DestinationCalendarId);
                    Console.WriteLine("After deleting count = " + appointments.Length);
                }

                // ExEnd:MoveAndDeleteAppointment
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #13
0
        public static void Run()
        {
            try
            {
                // ExStart:RetrieveUpdateAppointment
                GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret");
                string         accessToken;
                string         refreshToken;
                GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken);

                // Get IGmailclient
                using (IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail))
                {
                    string calendarId          = client.ListCalendars()[0].Id;
                    string AppointmentUniqueId = client.ListAppointments(calendarId)[0].UniqueId;

                    // Retrieve Appointment
                    Appointment app3 = client.FetchAppointment(calendarId, AppointmentUniqueId);
                    // Change the appointment information
                    app3.Summary       = "New Summary - " + Guid.NewGuid().ToString();
                    app3.Description   = "New Description - " + Guid.NewGuid().ToString();
                    app3.Location      = "New Location - " + Guid.NewGuid().ToString();
                    app3.Flags         = AppointmentFlags.AllDayEvent;
                    app3.StartDate     = DateTime.Now.AddHours(2);
                    app3.EndDate       = app3.StartDate.AddHours(1);
                    app3.StartTimeZone = "Europe/Kiev";
                    app3.EndTimeZone   = "Europe/Kiev";
                    // Update the appointment and get back updated appointment
                    Appointment app4 = client.UpdateAppointment(calendarId, app3);
                }
                // ExEnd:RetrieveUpdateAppointment
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #14
0
        public static void Run()
        {
            try
            {
                // ExStart:ManageAccessRule
                GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret");
                string         accessToken;
                string         refreshToken;
                GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken);

                using (IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail))
                {
                    // Retrieve list of calendars for the current client
                    ExtendedCalendar[] calendarList = client.ListCalendars();

                    // Get first calendar id and retrieve list of AccessControlRule for the first calendar
                    string calendarId          = calendarList[0].Id;
                    AccessControlRule[] roles1 = client.ListAccessRules(calendarId);

                    // Create a local access control rule and Set rule properties
                    AccessControlRule rule = new AccessControlRule();
                    rule.Role  = AccessRole.reader;
                    rule.Scope = new AclScope(AclScopeType.user, User2.EMail);

                    // Insert new rule for the calendar. It returns the newly created rule
                    AccessControlRule createdRule = client.CreateAccessRule(calendarId, rule);

                    // Confirm if local created rule and returned rule are equal
                    if ((rule.Role == createdRule.Role) && (rule.Scope.Type == createdRule.Scope.Type) && (rule.Scope.Value.ToLower() == createdRule.Scope.Value.ToLower()))
                    {
                        Console.WriteLine("local rule and returned rule after creation are equal");
                    }
                    else
                    {
                        Console.WriteLine("Rule could not be created successfully");
                        return;
                    }

                    // Get list of rules
                    AccessControlRule[] roles2 = client.ListAccessRules(calendarId);

                    // Current list length should be 1 more than the earlier one
                    if (roles1.Length + 1 == roles2.Length)
                    {
                        Console.WriteLine("List lengths are ok");
                    }
                    else
                    {
                        Console.WriteLine("List lengths are not ok");
                        return;
                    }

                    // Change rule and Update the rule for the selected calendar
                    createdRule.Role = AccessRole.writer;
                    AccessControlRule updatedRule = client.UpdateAccessRule(calendarId, createdRule);

                    // Check if returned access control rule after update is ok
                    if ((createdRule.Role == updatedRule.Role) && (createdRule.Id == updatedRule.Id))
                    {
                        Console.WriteLine("Rule is updated successfully");
                    }
                    else
                    {
                        Console.WriteLine("Rule is not updated");
                        return;
                    }

                    // Retrieve individaul rule against a calendar
                    AccessControlRule fetchedRule = client.FetchAccessRule(calendarId, createdRule.Id);

                    //Check if rule parameters are ok
                    if ((updatedRule.Id == fetchedRule.Id) && (updatedRule.Role == fetchedRule.Role) && (updatedRule.Scope.Type == fetchedRule.Scope.Type) && (updatedRule.Scope.Value.ToLower() == fetchedRule.Scope.Value.ToLower()))
                    {
                        Console.WriteLine("Rule parameters are ok");
                    }
                    else
                    {
                        Console.WriteLine("Rule parameters are not ok");
                    }

                    // Delete particular rule against a given calendar and Retrieve the all rules list for the same calendar
                    client.DeleteAccessRule(calendarId, createdRule.Id);
                    AccessControlRule[] roles3 = client.ListAccessRules(calendarId);

                    // Check that current rules list length should be equal to the original list length before adding and deleting the rule
                    if (roles1.Length == roles3.Length)
                    {
                        Console.WriteLine("List lengths are same");
                    }
                    else
                    {
                        Console.WriteLine("List lengths are not equal");
                        return;
                    }
                }
                // ExEnd:ManageAccessRule
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #15
0
        public static void Run()
        {
            try
            {
                // ExStart:CreateGmailContact
                GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret");
                string         accessToken;
                string         refreshToken;
                GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken);

                // Gmail Client
                IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail);

                // Create a Contact
                Contact contact = new Contact();
                contact.Prefix         = "Prefix";
                contact.GivenName      = "GivenName";
                contact.Surname        = "Surname";
                contact.MiddleName     = "MiddleName";
                contact.DisplayName    = "Test User 1";
                contact.Suffix         = "Suffix";
                contact.JobTitle       = "JobTitle";
                contact.DepartmentName = "DepartmentName";
                contact.CompanyName    = "CompanyName";
                contact.Profession     = "Profession";
                contact.Notes          = "Notes";
                PostalAddress address = new PostalAddress();
                address.Category        = PostalAddressCategory.Work;
                address.Address         = "Address";
                address.Street          = "Street";
                address.PostOfficeBox   = "PostOfficeBox";
                address.City            = "City";
                address.StateOrProvince = "StateOrProvince";
                address.PostalCode      = "PostalCode";
                address.Country         = "Country";
                contact.PhysicalAddresses.Add(address);
                PhoneNumber pnWork = new PhoneNumber();
                pnWork.Number   = "323423423423";
                pnWork.Category = PhoneNumberCategory.Work;
                contact.PhoneNumbers.Add(pnWork);
                PhoneNumber pnHome = new PhoneNumber();
                pnHome.Number   = "323423423423";
                pnHome.Category = PhoneNumberCategory.Home;
                contact.PhoneNumbers.Add(pnHome);
                PhoneNumber pnMobile = new PhoneNumber();
                pnMobile.Number   = "323423423423";
                pnMobile.Category = PhoneNumberCategory.Mobile;
                contact.PhoneNumbers.Add(pnMobile);
                contact.Urls.Blog                    = "Blog.ru";
                contact.Urls.BusinessHomePage        = "BusinessHomePage.ru";
                contact.Urls.HomePage                = "HomePage.ru";
                contact.Urls.Profile                 = "Profile.ru";
                contact.Events.Birthday              = DateTime.Now.AddYears(-30);
                contact.Events.Anniversary           = DateTime.Now.AddYears(-10);
                contact.InstantMessengers.AIM        = "AIM";
                contact.InstantMessengers.GoogleTalk = "GoogleTalk";
                contact.InstantMessengers.ICQ        = "ICQ";
                contact.InstantMessengers.Jabber     = "Jabber";
                contact.InstantMessengers.MSN        = "MSN";
                contact.InstantMessengers.QQ         = "QQ";
                contact.InstantMessengers.Skype      = "Skype";
                contact.InstantMessengers.Yahoo      = "Yahoo";
                contact.AssociatedPersons.Spouse     = "Spouse";
                contact.AssociatedPersons.Sister     = "Sister";
                contact.AssociatedPersons.Relative   = "Relative";
                contact.AssociatedPersons.ReferredBy = "ReferredBy";
                contact.AssociatedPersons.Partner    = "Partner";
                contact.AssociatedPersons.Parent     = "Parent";
                contact.AssociatedPersons.Mother     = "Mother";
                contact.AssociatedPersons.Manager    = "Manager";

                // Email Address
                EmailAddress eAddress = new EmailAddress();
                eAddress.Address = "*****@*****.**";
                contact.EmailAddresses.Add(eAddress);
                string contactUri = client.CreateContact(contact);
                // ExEnd:CreateGmailContact
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #16
0
        public static void Run()
        {
            try
            {
                // ExStart:QueryingCalendar
                // Get access token
                GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret");
                string         accessToken;
                string         refreshToken;
                GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken);

                // Get IGmailClient
                using (IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail))
                {
                    // Initialize calendar item
                    Aspose.Email.Clients.Google.Calendar calendar1 = new Aspose.Email.Clients.Google.Calendar("summary - " + Guid.NewGuid().ToString(), null, null, "Europe/Kiev");

                    // Insert calendar and get back id of newly inserted calendar and Fetch the same calendar using calendar id
                    string id = client.CreateCalendar(calendar1);
                    Aspose.Email.Clients.Google.Calendar cal1 = client.FetchCalendar(id);
                    string calendarId1 = cal1.Id;
                    try
                    {
                        // Get list of appointments in newly inserted calendar. It should be zero
                        Appointment[] appointments = client.ListAppointments(calendarId1);
                        if (appointments.Length != 0)
                        {
                            Console.WriteLine("Wrong number of appointments");
                            return;
                        }

                        // Create a new appointment and Calculate appointment start and finish time
                        DateTime startDate = DateTime.Now;
                        DateTime endDate   = startDate.AddHours(1);

                        // Create attendees list for appointment
                        MailAddressCollection attendees = new MailAddressCollection();
                        attendees.Add("*****@*****.**");
                        attendees.Add("*****@*****.**");

                        // Create appointment
                        Appointment app1 = new Appointment("Location - " + Guid.NewGuid().ToString(), startDate, endDate, "*****@*****.**", attendees);
                        app1.Summary       = "Summary - " + Guid.NewGuid().ToString();
                        app1.Description   = "Description - " + Guid.NewGuid().ToString();
                        app1.StartTimeZone = "Europe/Kiev";
                        app1.EndTimeZone   = "Europe/Kiev";

                        // Insert the newly created appointment and get back the same in case of successful insertion
                        Appointment app2 = client.CreateAppointment(calendarId1, app1);

                        // Create Freebusy query by setting min/max timeand time zone
                        FreebusyQuery query = new FreebusyQuery();
                        query.TimeMin  = DateTime.Now.AddDays(-1);
                        query.TimeMax  = DateTime.Now.AddDays(1);
                        query.TimeZone = "Europe/Kiev";

                        // Set calendar item to search and Get the reponse of query containing
                        query.Items.Add(cal1.Id);
                        FreebusyResponse resp = client.GetFreebusyInfo(query);
                        // Delete the appointment
                        client.DeleteAppointment(calendarId1, app2.UniqueId);
                    }
                    finally
                    {
                        // Delete the calendar
                        client.DeleteCalendar(cal1.Id);
                    }
                }
                // ExEnd:QueryingCalendar
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #17
0
        public static void Run()
        {
            try
            {
                // ExStart:AddingAnAppointment

                GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret");
                string         accessToken;
                string         refreshToken;
                GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken);

                // Get IGmailclient
                using (IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail))
                {
                    // Create local calendar
                    Aspose.Email.Clients.Google.Calendar calendar1 = new Aspose.Email.Clients.Google.Calendar("summary - " + Guid.NewGuid().ToString(), null, null, "Europe/Kiev");

                    // Insert calendar and get id of inserted calendar and Get back calendar using an id
                    string id = client.CreateCalendar(calendar1);
                    Aspose.Email.Clients.Google.Calendar cal1 = client.FetchCalendar(id);
                    string calendarId1 = cal1.Id;

                    try
                    {
                        // Retrieve list of appointments from the first calendar
                        Appointment[] appointments = client.ListAppointments(calendarId1);
                        if (appointments.Length > 0)
                        {
                            Console.WriteLine("Wrong number of appointments");
                            return;
                        }

                        // Get current time and Calculate time after an hour from now
                        DateTime startDate = DateTime.Now;
                        DateTime endDate   = startDate.AddHours(1);

                        // Initialize a mail address collection and set attendees mail address
                        MailAddressCollection attendees = new MailAddressCollection();
                        attendees.Add("*****@*****.**");
                        attendees.Add("*****@*****.**");

                        // Create an appointment with above attendees
                        Appointment app1 = new Appointment("Location - " + Guid.NewGuid().ToString(), startDate, endDate, User2.EMail, attendees);

                        // Set appointment summary, description, start/end time zone
                        app1.Summary       = "Summary - " + Guid.NewGuid().ToString();
                        app1.Description   = "Description - " + Guid.NewGuid().ToString();
                        app1.StartTimeZone = "Europe/Kiev";
                        app1.EndTimeZone   = "Europe/Kiev";

                        // Insert appointment in the first calendar inserted above and get back inserted appointment
                        Appointment app2 = client.CreateAppointment(calendarId1, app1);

                        // Retrieve appointment using unique id
                        Appointment app3 = client.FetchAppointment(calendarId1, app2.UniqueId);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                // ExEnd:AddingAnAppointment
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #18
0
        internal static void GetAccessToken(GoogleTestUser user, out string access_token, out string refresh_token, out string token_type, out int expires_in)
        {
            string authorizationCode = GoogleOAuthHelper.GetAuthorizationCode(user, GoogleOAuthHelper.SCOPE, GoogleOAuthHelper.REDIRECT_URI, GoogleOAuthHelper.REDIRECT_TYPE);

            GoogleOAuthHelper.GetAccessToken(authorizationCode, user, out access_token, out token_type, out expires_in, out refresh_token);
        }
コード例 #19
0
        internal static string GetAuthorizationCode(GoogleTestUser acc, string scope, string redirectUri, string responseType)
        {
            Debug.WriteLine("");
            Debug.WriteLine("---------------------------------------------------------");
            Debug.WriteLine("-----------OAuth 2.0 authorization information-----------");
            Debug.WriteLine("---------------------------------------------------------");
            Debug.WriteLine(string.Format("Login: '******'", acc.EMail));
            string authorizationCode = null;
            string error             = null;
            string approveUrl        = string.Format("https://accounts.google.com/o/oauth2/auth?redirect_uri={0}&response_type={1}&client_id={2}&scope={3}", redirectUri, responseType, acc.ClientId, scope);

            AutoResetEvent are0 = new AutoResetEvent(false);
            Thread         t    = new Thread(delegate()
            {
                bool doEvents              = true;
                WebBrowser browser         = new WebBrowser();
                browser.AllowNavigation    = true;
                browser.DocumentCompleted += delegate(object sender, WebBrowserDocumentCompletedEventArgs e) { doEvents = false; };
                Form f            = new Form();
                f.FormBorderStyle = FormBorderStyle.FixedToolWindow;
                f.ShowInTaskbar   = false;
                f.StartPosition   = FormStartPosition.Manual;
                f.Location        = new System.Drawing.Point(-2000, -2000);
                f.Size            = new System.Drawing.Size(1, 1);
                f.Controls.Add(browser);
                f.Load += delegate(object sender, EventArgs e)
                {
                    try
                    {
                        browser.Navigate("https://accounts.google.com/Logout");
                        doEvents = true;
                        while (doEvents)
                        {
                            Application.DoEvents();
                        }
                        browser.Navigate("https://accounts.google.com/ServiceLogin?sacu=1");
                        doEvents = true;
                        while (doEvents)
                        {
                            Application.DoEvents();
                        }
                        HtmlElement loginForm = browser.Document.Forms["gaia_loginform"];
                        if (loginForm != null)
                        {
                            HtmlElement userName = browser.Document.All["Email"];

                            userName.SetAttribute("value", acc.EMail);
                            loginForm.InvokeMember("submit");
                            doEvents = true;
                            while (doEvents)
                            {
                                Application.DoEvents();
                            }

                            loginForm          = browser.Document.Forms["gaia_loginform"];
                            HtmlElement passwd = browser.Document.All["Passwd"];
                            passwd.SetAttribute("value", acc.Password);

                            loginForm.InvokeMember("submit");
                            doEvents = true;
                            while (doEvents)
                            {
                                Application.DoEvents();
                            }
                        }
                        else
                        {
                            error = "Login form is not found in \n" + browser.Document.Body.InnerHtml;
                            return;
                        }
                        browser.Navigate(approveUrl);
                        doEvents = true;
                        while (doEvents)
                        {
                            Application.DoEvents();
                        }
                        HtmlElement approveForm = browser.Document.Forms["connect-approve"];
                        if (approveForm != null)
                        {
                            HtmlElement submitAccess = browser.Document.All["submit_access"];
                            submitAccess.SetAttribute("value", "true");
                            approveForm.InvokeMember("submit");
                            doEvents = true;
                            while (doEvents)
                            {
                                Application.DoEvents();
                            }
                        }
                        else
                        {
                            error = "Approve form is not found in \n" + browser.Document.Body.InnerHtml;
                            return;
                        }
                        HtmlElement code = browser.Document.All["code"];
                        if (code != null)
                        {
                            authorizationCode = code.GetAttribute("value");
                        }
                        else
                        {
                            error = "Authorization code is not found in \n" + browser.Document.Body.InnerHtml;
                        }
                    }
                    catch (Exception ex)
                    {
                        error = ex.Message;
                    }
                    finally
                    {
                        f.Close();
                    }
                };
                Application.Run(f);
                are0.Set();
            });

            t.SetApartmentState(ApartmentState.STA);
            t.Start();
            are0.WaitOne();
            if (error != null)
            {
                throw new Exception(error);
            }
            return(authorizationCode);
        }