/// <summary> /// Creates any entity records that this sample requires. /// </summary> public void CreateRequiredRecords() { // For this sample, all required entities are created in the Run() method. // Obtain the current user's information. WhoAmIRequest who = new WhoAmIRequest(); WhoAmIResponse whoResp = (WhoAmIResponse)_serviceProxy.Execute(who); Guid currentUserId = whoResp.UserId; SystemUser currentUser = _serviceProxy.Retrieve(SystemUser.EntityLogicalName, currentUserId, new ColumnSet("domainname")).ToEntity <SystemUser>(); // Extract the domain and create the LDAP object. String[] userPath = currentUser.DomainName.Split(new char[] { '\\' }); if (userPath.Length > 1) { _domain = userPath[0] + "\\"; } else { _domain = String.Empty; } SystemUser existingUser = SystemUserProvider.GetUserIdIfExist(_serviceProxy, _domain, _userName, _firstName, _lastName); if (existingUser != null) { throw new Exception("User already exist!"); } // Set up an Active Directory account in the current domain for this sample. String ldapPath = String.Empty; Boolean accountSetup = SystemUserProvider.CreateADAccount(_userName, _firstName, _lastName, _serviceProxy, ref ldapPath); if (accountSetup) { Console.WriteLine("An AD account created for '{0}, {1}'", _lastName, _firstName); } else { Console.WriteLine("AD account already exist for '{0}, {1}'", _lastName, _firstName); } }