private static void RunSample(CalendarResourceService service) { try { const String TEST_RESOURCE_ID = "NYV-BUILDING-5-Batman"; // Create a new CalendarResource AppsExtendedEntry entry = service.CreateCalendarResource( TEST_RESOURCE_ID, "Batman", "6 Person VC", "CR"); Console.WriteLine("Created: " + entry.getPropertyValueByName(AppsCalendarResourceNameTable.resourceId)); // Retrieve a CalendarResource entry = service.RetrieveCalendarResource(TEST_RESOURCE_ID); Console.WriteLine("Retrieved: " + entry.getPropertyValueByName(AppsCalendarResourceNameTable.resourceEmail)); Console.WriteLine("Dscription: " + entry.getPropertyValueByName(AppsCalendarResourceNameTable.resourceDescription)); Console.WriteLine("Resource Id: " + entry.getPropertyValueByName(AppsCalendarResourceNameTable.resourceId)); Console.WriteLine("Common name: " + entry.getPropertyValueByName(AppsCalendarResourceNameTable.resourceCommonName)); //Retrieve all resources Console.WriteLine("Retrieving all calendar resources (this may take some time) ..... "); AppsExtendedFeed feed = service.RetrieveAllCalendarResources(); Console.WriteLine("Retrieved Entries Count: " + feed.Entries.Count); foreach (AppsExtendedEntry resourceEntry in feed.Entries) { Console.WriteLine("Resource Emails: " + entry.getPropertyValueByName(AppsCalendarResourceNameTable.resourceEmail)); } //Delete a resource service.DeleteCalendarResource(TEST_RESOURCE_ID); Console.WriteLine("Deleted: " + TEST_RESOURCE_ID); Console.Read(); } catch (AppsException a) { Console.WriteLine("A Google Apps error occurred."); Console.WriteLine(); Console.WriteLine("Error code: {0}", a.ErrorCode); Console.WriteLine("Invalid input: {0}", a.InvalidInput); Console.WriteLine("Reason: {0}", a.Reason); } }
/// <summary> /// /// </summary> /// <param name="service"></param> private static void RunSample(OrganizationService service) { try { const String testOrgunit = "TestOrgUnitForSample"; const String testOrgunitDescription = "Test Organization"; // Retrieve customer Id AppsExtendedEntry entry = service.RetrieveCustomerId(service.DomainName); String customerId = entry.getPropertyValueByName(AppsOrganizationNameTable.CustomerId); Console.WriteLine("CustomerId: " + customerId); // Delete, if all already exists try { service.DeleteOrganizationUnit(customerId, testOrgunit); } catch { } // Create a new Organization Unit Console.WriteLine("\n-----------Creating organization unit-----------"); entry = service.CreateOrganizationUnit( customerId, testOrgunit, "/", testOrgunitDescription, false); Console.WriteLine("Created: " + entry.getPropertyValueByName(AppsOrganizationNameTable.OrgUnitName)); // Retrieve Organization Unit and list all properties Console.WriteLine("\n-----------Retrieving organization unit---------"); entry = service.RetrieveOrganizationUnit(customerId, testOrgunit); foreach (PropertyElement element in entry.Properties) { Console.WriteLine(String.Format("{0} - {1}", element.Name, element.Value)); } // Update organization unit and list all properties Console.WriteLine("\n-----------Updating organization unit----"); IDictionary <OrganizationService.OrgUnitProperty, string> updates = new Dictionary <OrganizationService.OrgUnitProperty, string>(); updates[OrganizationService.OrgUnitProperty.Description] = "Updated description"; entry = service.UpdateOrganizationUnit(customerId, testOrgunit, updates); foreach (PropertyElement element in entry.Properties) { Console.WriteLine(String.Format("{0} - {1}", element.Name, element.Value)); } // Retrieve all organization units and list the names Console.WriteLine("\n-----------Retrieving all organization units----"); AppsExtendedFeed feed = service.RetrieveAllOrganizationUnits(customerId); foreach (AppsExtendedEntry unit in feed.Entries) { Console.WriteLine( unit.getPropertyValueByName(AppsOrganizationNameTable.OrgUnitName)); } // Retrieve child organization unit of a given unit Console.WriteLine("\n-----------Retrieving child organization units----"); feed = service.RetrieveChildOrganizationUnits(customerId, testOrgunit); foreach (AppsExtendedEntry unit in feed.Entries) { Console.WriteLine( unit.getPropertyValueByName(AppsOrganizationNameTable.OrgUnitName)); } // Retrieve org user Console.WriteLine("\n-----------Retrieving Org User-------------------"); entry = service.RetrieveOrganizationUser(customerId, testUser); Console.WriteLine("Retrieved OrgUser"); foreach (PropertyElement element in entry.Properties) { Console.WriteLine(String.Format("{0} - {1}", element.Name, element.Value)); } // update org user i.e. move from one org unit to another Console.WriteLine("\n-----------Updating Org User---------------------"); entry = service.UpdateOrganizationUser(customerId, testUser, testOrgunit, "/"); Console.WriteLine("Updated OrgUser"); foreach (PropertyElement element in entry.Properties) { Console.WriteLine(String.Format("{0} - {1}", element.Name, element.Value)); } // Retrieve all org users Console.WriteLine("\n-----------Retrieving all Org Users--------------"); feed = service.RetrieveAllOrganizationUsers(customerId); Console.WriteLine("Retrieved User count: " + feed.Entries.Count); //using pagination Console.WriteLine("\n--------Retrieving all Org Users(paginated)------"); feed = service.RetrieveFirstPageOrganizationUsers(customerId); Console.WriteLine("Retrieved User count: " + feed.Entries.Count); AtomLink next, prev = null; while ((next = feed.Links.FindService("next", null)) != null && prev != next) { feed = service.RetrieveNextPageFromResumeKey(next.HRef.ToString()); prev = next; Console.WriteLine("Retrieved User count: " + feed.Entries.Count); } // Retrieve org users by org unit Console.WriteLine("\n-----------Retrieving Org Users by orgunit--------------"); feed = service.RetrieveAllOrganizationUsersByOrgUnit(customerId, testOrgunit); Console.WriteLine("Retrieved User count: " + feed.Entries.Count); //cleanup try { Console.WriteLine("\nCleaning up..."); entry = service.UpdateOrganizationUser(customerId, testUser, "/", testOrgunit); service.DeleteOrganizationUnit(customerId, testOrgunit); } catch { } } catch (AppsException a) { Console.WriteLine("A Google Apps error occurred."); Console.WriteLine(); Console.WriteLine("Error code: {0}", a.ErrorCode); Console.WriteLine("Invalid input: {0}", a.InvalidInput); Console.WriteLine("Reason: {0}", a.Reason); } }
/// <summary> /// /// </summary> /// <param name="service"></param> private static void RunSample(MultiDomainManagementService service) { const String testUserPassword = "******"; const String testUserFirstName = "Liz"; const String testUserLastName = "Smith"; const bool testUserIsAdmin = true; const String testUserNewFirstName = "Elizabeth"; String testUserNewEmail = "liz@" + secondaryDomain; String testUserAliasEmail = "helpdesk@" + secondaryDomain; try { // Create a new Domain User Console.WriteLine("\n-----------Creating domain user-----------"); AppsExtendedEntry entry = service.CreateDomainUser(primaryDomain, testUserEmail, testUserPassword, testUserFirstName, testUserLastName, testUserIsAdmin); Console.WriteLine("Created: " + entry.getPropertyValueByName(AppsMultiDomainNameTable.UserEmail)); // Update Domain User and list all properties Console.WriteLine("\n-----------Updating domain user----"); IDictionary <MultiDomainManagementService.MultiDomainUserProperty, string> updates = new Dictionary <MultiDomainManagementService.MultiDomainUserProperty, string>(); updates[MultiDomainManagementService.MultiDomainUserProperty.FirstName] = testUserNewFirstName; entry = service.UpdateDomainUser(primaryDomain, testUserEmail, updates); foreach (PropertyElement element in entry.Properties) { Console.WriteLine(String.Format("{0} - {1}", element.Name, element.Value)); } // Create a new Domain User to be renamed Console.WriteLine("\n-----------Creating domain user to be renamed-----------"); String tempEmail = "TOBERENAMED@" + primaryDomain; entry = service.CreateDomainUser(primaryDomain, tempEmail, testUserPassword, testUserFirstName, testUserLastName, testUserIsAdmin); Console.WriteLine("Created: " + entry.getPropertyValueByName(AppsMultiDomainNameTable.UserEmail)); // Rename Domain User Console.WriteLine("\n-----------Renaming domain user---------------------"); entry = service.RenameDomainUser(primaryDomain, tempEmail, testUserNewEmail); Console.WriteLine("Renamed domain user: "******"\n-----------Retrieving domain user----"); entry = service.RetrieveDomainUser(primaryDomain, testUserEmail); String firstName = entry.getPropertyValueByName(AppsMultiDomainNameTable.FirstName); Console.WriteLine("FirstName: " + firstName); // Retrieve all domain users unit and list the emails Console.WriteLine("\n-----------Retrieving all domain users----"); AppsExtendedFeed feed = service.RetrieveAllDomainUsers(primaryDomain); foreach (AppsExtendedEntry unit in feed.Entries) { Console.WriteLine( unit.getPropertyValueByName(AppsMultiDomainNameTable.UserEmail)); } // Create a new User Alias Console.WriteLine("\n-----------Creating user alias-----------"); entry = service.CreateDomainUserAlias(primaryDomain, testUserEmail, testUserAliasEmail); Console.WriteLine("Created Alias: " + entry.getPropertyValueByName(AppsMultiDomainNameTable.AliasEmail)); // Retrieve User Alias entry = service.RetrieveDomainUserAlias(primaryDomain, testUserAliasEmail); String userEmail = entry.getPropertyValueByName(AppsMultiDomainNameTable.UserEmail); Console.WriteLine("UserEmail: " + userEmail); // Retrieve all user aliases for the domain Console.WriteLine("\n-----------Retrieving all user aliases----"); feed = service.RetrieveAllDomainUserAlias(primaryDomain); foreach (AppsExtendedEntry unit in feed.Entries) { Console.WriteLine( unit.getPropertyValueByName(AppsMultiDomainNameTable.UserEmail)); } // Retrieve all aliases for an user Console.WriteLine("\n-----------Retrieving all aliases for user----"); feed = service.RetrieveAllDomainUserAliasForUser(primaryDomain, testUserEmail); foreach (AppsExtendedEntry unit in feed.Entries) { Console.WriteLine( unit.getPropertyValueByName(AppsMultiDomainNameTable.AliasEmail)); } // Delete User Alias Console.WriteLine("\n-----------Deleting alias----"); service.DeleteDomainUserAlias(primaryDomain, testUserAliasEmail); // Delete User Console.WriteLine("\n-----------Deleting user----"); service.DeleteDomainUser(primaryDomain, testUserEmail); } catch (AppsException a) { Console.WriteLine("A Google Apps error occurred."); Console.WriteLine(); Console.WriteLine("Error code: {0}", a.ErrorCode); Console.WriteLine("Invalid input: {0}", a.InvalidInput); Console.WriteLine("Reason: {0}", a.Reason); } }
private static void RunSample(GoogleMailSettingsService service) { try { // Create a new Label for the user testUserName service.CreateLabel(testUserName, "Test-Label"); // Retrieve all labels for the user testUserName AppsExtendedFeed labels = service.RetrieveLabels(testUserName); Console.WriteLine(String.Format("First label: {0}", ((AppsExtendedEntry)labels.Entries[0]).getPropertyValueByName("label"))); // Create a filter for emails from [email protected] // for the user testUserName and applies the new label "Test-Label" service.CreateFilter(testUserName, "test@" + domain, "", "", "", "", "", "Test-Label", "true", ""); // Create a filter for emails having "important" in the subject // for the user testUserName to never send them to Spam and star them service.CreateFilter(testUserName, "", "", "important", "", "", "", "", "", "", "true", "true", "", ""); // Create a new Send As for the user testUserName service.CreateSendAs(testUserName, "Test email", testUserName + "@" + domain, "", ""); // Retrieve all send-as for user testUserName AppsExtendedFeed sendas = service.RetrieveSendAs(testUserName); Console.WriteLine(String.Format("First send-as: {0}", ((AppsExtendedEntry)sendas.Entries[0]).getPropertyValueByName("name"))); // Updates the forwarding rule to forward emails to // test@domain for the user testUserName and keeps the email. service.UpdateForwarding(testUserName, "true", "test@" + domain, "KEEP"); // Disable web clip for the user testUserName. service.UpdateWebclip(testUserName, "false"); // Retrieve forwarding settings for user testUserName AppsExtendedEntry forwarding = service.RetrieveForwarding(testUserName); Console.WriteLine(String.Format("Forwarding to: {0}", forwarding.getPropertyValueByName("forwardTo"))); // Deactivate POP for the user testUserName service.UpdatePop(testUserName, "false", null, null); // Retrieve POP settings for user testUserName AppsExtendedEntry pop = service.RetrievePop(testUserName); Console.WriteLine(String.Format("POP enabled: {0}", pop.getPropertyValueByName("enable"))); // Activate IMAP for the user testUserName service.UpdateImap(testUserName, "true"); // Retrieve IMAP settings for user testUserName AppsExtendedEntry imap = service.RetrieveImap(testUserName); Console.WriteLine(String.Format("IMAP enabled: {0}", imap.getPropertyValueByName("enable"))); // Activate vacation autoresponse for the user testUserName service.UpdateVacation(testUserName, "true", "vacation", "vacation text...", "false", "true", "2012-01-15", "2012-01-22"); // Retrieve vacation responder settings for user testUserName AppsExtendedEntry vacation = service.RetrieveVacation(testUserName); Console.WriteLine(String.Format("Vacation responder message: {0}", vacation.getPropertyValueByName("message"))); // Update the signature for the user testUserName service.UpdateSignature(testUserName, "Signature text..."); // Retrieve signature for user testUserName AppsExtendedEntry signature = service.RetrieveSignature(testUserName); Console.WriteLine(String.Format("Signature: {0}", signature.getPropertyValueByName("signature"))); // Update the language settings to French (fr) for the user testUserName service.UpdateLanguage(testUserName, "fr"); // Update general settings for the user testUserName service.UpdateGeneralSettings(testUserName, "50", "false", "false", "false", "false"); // Create a new Delegate for the user testUserName service.CreateDelegate(testUserName, adminEmail); // Retrieve all delegates for the user testUserName AppsExtendedFeed delegates = service.RetrieveDelegates(testUserName); Console.WriteLine(String.Format("First delegate: {0}", ((AppsExtendedEntry)delegates.Entries[0]).getPropertyValueByName("delegationId"))); // Delete the Delegate for the user testUserName service.DeleteDelegate(testUserName, adminEmail); } catch (AppsException a) { Console.WriteLine("A Google Apps error occurred."); Console.WriteLine(); Console.WriteLine("Error code: {0}", a.ErrorCode); Console.WriteLine("Invalid input: {0}", a.InvalidInput); Console.WriteLine("Reason: {0}", a.Reason); } }