public override void Run() { Library.Windows.Windows.Pause(60000); return; UserList UsrLst = null; User ImpUsr = null, DefUsr = null; string sDefUsrLogID = Global.StringNull, sMsg = Global.StringNull; object[] ValMat = null; ADUserInfo ADUsrInf = null; List <ADUserInfo> ADUsrInfLst = null; bool bAddUsr = Global.BooleanNull, bUpdUsr = Global.BooleanNull, bDelUsr = Global.BooleanNull; //--- Create a new start import message CreateMessage(ProgressMessage.enMessageState.Info, ProgMsg_StartImpADUsrs); //--- Get the action flags bAddUsr = ServiceTarget.ConfigFile.GetBoolean(GetConfigNodePath(NodName_AddUsr)); bUpdUsr = ServiceTarget.ConfigFile.GetBoolean(GetConfigNodePath(NodName_UpdUsr)); bDelUsr = ServiceTarget.ConfigFile.GetBoolean(GetConfigNodePath(NodName_DelUsr)); //--- Create a new read AD users message CreateMessage(ProgressMessage.enMessageState.Info, ProgMsg_ReadADUsrsFile); //--- Parse the AD user value matrix and remove the header line ValMat = Files.ParseCsvFile(ADUserFileWatcher.FileName, Sep_ADUsrFile_Ln, Sep_ADUsrFile_Val); Library.Arrays.Array.RemoveAt(ref ValMat, 0); //--- Init the AD user infos ADUsrInfLst = new List <ADUserInfo>(); //--- Add the AD user infos for (int nIdx = 0; nIdx < ValMat.Length; nIdx++) { //--- Init the AD user info ADUsrInf = new ADUserInfo((string[])ValMat[nIdx]); //--- Check person user if (!ADUsrInf.IsPersonUser()) { continue; } //--- Add to the AD unser infos ADUsrInfLst.Add(ADUsrInf); } //--- Create a new read server users message CreateMessage(ProgressMessage.enMessageState.Info, ProgMsg_ReadUsrsSvr.Replace("%svr%", GetServer().ServerName)); //--- Get the default user login ID and read the users sDefUsrLogID = ServiceTarget.ConfigFile.GetString(GetConfigNodePath(NodName_DefUsr), true); UsrLst = ReadAllSBMUsers(); //--- Find the default user and remove from the users if exists if ((DefUsr = UsrLst.FindByLoginID(sDefUsrLogID)) == null) { throw new SBMException(ErrMsg_DefUsrNotExi.Replace("%log%", sDefUsrLogID)); } //--- Create a new read AD users message CreateMessage(ProgressMessage.enMessageState.Info, ProgMsg_ImpADUsrs); //--- Add or updste the AD users for (int nUsrIdx = 0; nUsrIdx < ADUsrInfLst.Count; nUsrIdx++) { //--- Get the AD user and clear the user ADUsrInf = ADUsrInfLst[nUsrIdx]; ImpUsr = null; //--- Find the user with the login ID if ((ImpUsr = UsrLst.FindByLoginID(ADUsrInf.LoginID)) == null) { //--- Check add user if (bAddUsr) { //--- Init the user and set the user values ImpUsr = GetServer().NewUser(); SetUserValues(ImpUsr, DefUsr, ADUsrInf, true); //--- Tag the user and add the user to the users ImpUsr.Tag = enAction.Create; UsrLst.Add(ImpUsr); } } else { //--- Check update user if (bUpdUsr) { //--- Update the and tag the user ImpUsr.Tag = enAction.Update; SetUserValues(ImpUsr, DefUsr, ADUsrInf, false); } //--- Remove the user else { UsrLst.Remove(ImpUsr); } } } //--- Delete the users for (int nUsrIdx = UsrLst.Count - 1; nUsrIdx >= 0; nUsrIdx--) { //--- Get the user ImpUsr = UsrLst[nUsrIdx]; //--- Check user tag not exists if (ImpUsr.Tag != null) { continue; } //--- Remove the user if not deleted and not an AD user and delete user else if (ImpUsr.IsDeleted() || String.IsNullOrEmpty(ImpUsr.GetEmailCC()) || !bDelUsr) { UsrLst.RemoveAt(nUsrIdx); } else { //--- Tag the user and set the user deleted ImpUsr.Tag = enAction.Delete; ImpUsr.SetDeleted(true); } } //--- Create a new read AD users message CreateMessage(ProgressMessage.enMessageState.Info, ProgMsg_AddOrUpdADUsrs); //--- Add, update or delete the users for (int nUsrIdx = 0; nUsrIdx < UsrLst.Count; nUsrIdx++) { //--- Get the user and the message ImpUsr = UsrLst[nUsrIdx]; sMsg = (enAction)ImpUsr.Tag == enAction.Create ? ProgMsg_CreUsr : (enAction)ImpUsr.Tag == enAction.Update ? ProgMsg_UpdUsr : (enAction)ImpUsr.Tag == enAction.Delete ? ProgMsg_DelUsr : null; //--- Create a new message CreateMessage ( ProgressMessage.enMessageState.Info, sMsg.Replace("%log%", ImpUsr.GetLoginID()).Replace("%name%", ImpUsr.GetDisplayName()), nUsrIdx + 1, UsrLst.Count ); try { //--- Create the user if ((enAction)ImpUsr.Tag == enAction.Create) { ImpUsr.Create(); } //--- Update the user else if (((enAction)ImpUsr.Tag == enAction.Update) || ((enAction)ImpUsr.Tag == enAction.Delete)) { ImpUsr.Update(); } } //--- Log the exception message catch (Exception Exc) { CreateMessage(Exc); } } //--- Create a new message CreateMessage(ProgressMessage.enMessageState.Info, ProgMsg_FinImpADUsrs, UsrLst.Count, UsrLst.Count); }