2016-11-03 2 views
0

HR에서 MS Active Directory로 사용자 계정을 생성하는 DB Microsoft Identity Manager가 있습니다. 고유의 이메일을 생성하기위한 Microsoft Identity Manager 용 C#에서 고유 한 전자 메일 생성

는 내가 같은 코드를 가지고 :

case "mailgenerate": 
       if (mventry["email"].IsPresent) 
       { 
        // Do nothing, the mail was already generated. 
       } 

       { 

        if (csentry["FIRST"].IsPresent && csentry["LAST"].IsPresent); 
        { 
         string FirstName = replaceRUEN(csentry["FIRST"].Value); 
         string LastName = replaceRUEN(csentry["LAST"].Value); 
         string email = FirstName + "." + LastName + "@test.domain.com"; 
         string newmail = GetCheckedMail(email, mventry); 

          if (newmail.Equals("")) 
         { 
          throw new TerminateRunException("A unique mail could not be found"); 
         } 
          mventry["email"].Value = newmail; 
         } 
       } 
       break; 


    //Generate mail Name method 
    string GetCheckedMail(string email, MVEntry mventry) 
    { 
     MVEntry[] findResultList = null; 
     string checkedmailName = email; 
     for (int nameSuffix = 1; nameSuffix < 100; nameSuffix++) 
     { 
      //added ; and if corrected 
      findResultList = Utils.FindMVEntries("email", checkedmailName,1); 

      if (findResultList.Length == 0) 
      { 
       // The current mailName is not in use. 
       return (checkedmailName); 
      } 
      MVEntry mvEntryFound = findResultList[0]; 
      if (mvEntryFound.Equals(mventry)) 
      { 
       return (checkedmailName); 
      } 
      // If the passed email is already in use, then add an integer value 
      // then verify if the new value exists. Repeat until a unique email is checked 
      checkedmailName = checkedmailName + nameSuffix.ToString(); 
     } 
     // Return an empty string if no unique mailnickName could be created. 
     return ""; 
    } 

문제 : 처음 동기화주기를 실행하면 내가 [email protected] 다음의 경우처럼 정상적인 이메일을 동기화주기 [email protected]

이 코드 나는 또한 아무 문제없이 mailnickname 및 accountname을 생성하는 데 사용하고 있습니다.

왜 그런지 말할 수 있습니까? 감사합니다.

checkedmailName = checkedmailName + nameSuffix.ToString(); 

checkedmailName이 같은 값이 있습니다 :

답변

1

문제는 라인 그래서 [email protected]

을, 당신은이 일을하고 있습니다 :

checkedmailName = [email protected] + 1; 

당신은 같은 것을 할 필요가 이 :

checkedmailName = checkedmailName.Split('@')[0] + nameSuffix.ToString()+ "@" + checkedmailName.Split('@')[1]; 

Whith this, @ 앞에 부분을 가져오고 int 값을 추가 한 다음 @ + domain을 추가합니다.


스레드의 저자에 의해 업데이트 나는 분할 변경 -> 분할을하고 그것을 작동합니다. 감사!