public bool ImportUsers(string OU_Filter, int requestor, int reqId, ref string err) { err = ""; bool logErr = false; try { UserManagerEvent e = new UserManagerEvent(reqId, UserMgrCommandType.ImportUsers, requestor); m_ThreadContext.Post(new SendOrPostCallback(ProcessRequest), e); err = "Your request is being processed. It'll take a few minutes to complete."; } catch (Exception ex) { err = "Failed to import user accounts, Exception:" + ex.Message; int Event_id = 6047; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); return(false); } finally { if (logErr) { int Event_id = 6048; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); } } return(true); }
private void ProcessRequest(object o) { bool logErr = false; bool fatal = false; bool status = false; string err = ""; ADUserDetail adUser = null; UserManagerEvent e = o as UserManagerEvent; if (e == null) { err = "ProcessRequest, UserManagerEvent argument is empty, OU " + m_OU_Filter; int Event_id = 6012; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); } if (e.UserId <= 0) { e.UserId = 0; } if (e.RequestType == Common.UserMgrCommandType.Unknown) { err = "UserManagerEvent RequestType is Unknown, ReqType=" + e.RequestType; int Event_id = 6014; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); } if (e.RequestId <= 0) { err = "UserManagerEvent RequestId is invalid, RequestId=" + e.RequestId.ToString(); int Event_id = 6015; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); } try { if ((e.RequestType != Common.UserMgrCommandType.ImportUsers) && (e.RequestType != Common.UserMgrCommandType.StartImport) && (e.RequestType != Common.UserMgrCommandType.StopImport)) { if (e.ADUser == null) { err = "Received invalid UserManagerEvent RequestType, ReqType=" + e.RequestType + ", OU=" + m_OU_Filter; int Event_id = 6016; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); } adUser = new ADUserDetail(e.ADUser.Username, !e.ADUser.Enabled, e.ADUser.Firstname, e.ADUser.Lastname, e.ADUser.Email, e.ADUser.Password); } if (SetUpADHelper(ref err) == false) { int Event_id = 6017; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); } switch (e.RequestType) { case Common.UserMgrCommandType.CreateUser: status = m_adHelper.AddUserByLogin(adUser, false, ref err); break; case Common.UserMgrCommandType.DeleteUser: status = m_adHelper.DeleteUserByLogin(adUser, ref err); break; case Common.UserMgrCommandType.DisableUser: status = m_adHelper.DisableUserByLogin(adUser, ref err); break; case Common.UserMgrCommandType.EnableUser: status = m_adHelper.EnableUserByLogin(adUser, ref err); break; case Common.UserMgrCommandType.ImportUsers: status = ImportADUsers(e.UserId, e.RequestId, ref err); break; case Common.UserMgrCommandType.StartImport: //status = StartImport(); break; case Common.UserMgrCommandType.StopImport: //status = StopImport(); break; } if (status == false) { int Event_id = 6018; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); } } catch (Exception ex) { err = "Failed to " + e.RequestType.ToString() + ", OU " + m_OU_Filter + ", Exception:" + ex.Message; int Event_id = 6019; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); } finally { if (logErr) { int Event_id = 6020; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); } string errMsg = ""; UpdateRequest(e.UserId, e.RequestId, e.RequestType, status, err, ref errMsg); } }