public CreateDomainUserAlias ( String domain, String userEmail, String aliasEmail ) : Google.GData.Apps.AppsExtendedEntry | ||
domain | String | The user's domain |
userEmail | String | The user's email address |
aliasEmail | String | The alias to be added to the user |
Résultat | Google.GData.Apps.AppsExtendedEntry |
/// <summary> /// /// </summary> /// <param name="service"></param> private static void RunSample(MultiDomainManagementService service) { const String testUserHashFunction = "SHA-1"; 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, testUserHashFunction, 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); } }
static string AddAlias( MultiDomainManagementService service, string primaryDomain, string user, string alias ) { try { var entry = service.CreateDomainUserAlias( primaryDomain, user, alias ); return string.Format( "Alias {0} created for {1}.", entry.getPropertyValueByName( AppsMultiDomainNameTable.AliasEmail ), user ); //return alias from server } catch( GDataRequestException ex ) { return string.Format( "Error creating alias: {0}.", ex.ParseError() ); //or else return error message } }