public bool ModifyRecycleOu(Guid transactionid, AdminInfo admin, string recycleOuPath, string newOuName, out ErrorCodeInfo error) { bool result = false; error = new ErrorCodeInfo(); string message = string.Empty; string paramstr = string.Empty; paramstr += $"userID:{admin.UserID}"; paramstr += $"||UserAccount:{admin.UserAccount}"; paramstr += $"||recycleOuPath:{recycleOuPath}"; paramstr += $"||newOuName:{newOuName}"; DirectoryEntry ouRecycleEntry = new DirectoryEntry(); try { do { CommonProvider commonProvider = new CommonProvider(); if (!commonProvider.GetADEntryByPath(recycleOuPath, out ouRecycleEntry, out message)) { break; } DirectoryEntry newOuEntry = new DirectoryEntry(); if (commonProvider.GetOneLevelSigleOuEntry(ouRecycleEntry.Parent.Path, newOuName, out newOuEntry, out message)) { break; } ouRecycleEntry.Rename(string.Format("OU = {0}", newOuName)); ouRecycleEntry.Close(); result = true; } while (false); } catch (Exception ex) { error.Code = ErrorCode.Exception; LoggerHelper.Error("OuProvider调用ModifyRecycleOu异常", paramstr, ex.ToString(), transactionid); result = false; } finally { if (ouRecycleEntry != null) { ouRecycleEntry.Close(); } } return(result); }
public bool MoveRecycleOu(Guid transactionid, AdminInfo admin, string recycleOuPath, string targetRecycleOuPath, out ErrorCodeInfo error) { bool result = false; error = new ErrorCodeInfo(); string message = string.Empty; string paramstr = string.Empty; paramstr += $"userID:{admin.UserID}"; paramstr += $"||UserAccount:{admin.UserAccount}"; paramstr += $"||recycleOuPath:{recycleOuPath}"; paramstr += $"||targetRecycleOuPath:{targetRecycleOuPath}"; DirectoryEntry ouRecycleEntry = new DirectoryEntry(); DirectoryEntry targetOuRecycleEntry = new DirectoryEntry(); try { do { CommonProvider commonProvider = new CommonProvider(); if (!commonProvider.GetADEntryByPath(recycleOuPath, out ouRecycleEntry, out message)) { LoggerHelper.Error("MoveRecycleOu调用GetADEntryByPath异常", paramstr, message, transactionid); break; } if (!commonProvider.GetADEntryByPath(targetRecycleOuPath, out targetOuRecycleEntry, out message)) { LoggerHelper.Error("MoveRecycleOu调用GetADEntryByPath异常", paramstr, message, transactionid); break; } DirectoryEntry newOuEntry = new DirectoryEntry(); if (commonProvider.GetOneLevelSigleOuEntry(targetOuRecycleEntry.Path, Convert.ToString(ouRecycleEntry.Properties["name"].Value), out newOuEntry, out message)) { LoggerHelper.Error("MoveRecycleOu调用GetOneLevelSigleOuEntry异常", paramstr, message, transactionid); break; } ouRecycleEntry.MoveTo(targetOuRecycleEntry); ouRecycleEntry.CommitChanges(); ouRecycleEntry.Close(); result = true; } while (false); } catch (Exception ex) { error.Code = ErrorCode.Exception; LoggerHelper.Error("MoveRecycleOu异常", paramstr, ex.ToString(), transactionid); result = false; } finally { if (ouRecycleEntry != null) { ouRecycleEntry.Close(); } } return(result); }
public bool AddRecycleOu(Guid transactionid, AdminInfo admin, OuInfo ou, out ErrorCodeInfo error) { bool result = false; error = new ErrorCodeInfo(); string message = string.Empty; string paramstr = string.Empty; paramstr += $"userID:{admin.UserID}"; paramstr += $"||UserAccount:{admin.UserAccount}"; paramstr += $"||Id:{ou.id}"; paramstr += $"||distinguishedName:{ou.distinguishedName}"; DirectoryEntry ouParentEntry = new DirectoryEntry(); DirectoryEntry ouRecycleEntry = new DirectoryEntry(); DirectoryEntry OuEntry = new DirectoryEntry(); try { do { CommonProvider commonProvider = new CommonProvider(); if (!commonProvider.GetADEntryByGuid(ou.parentid, out ouParentEntry, out message)) { error.Code = ErrorCode.SearchADDataError; LoggerHelper.Error("OuManager调用AddRecycleOu异常", paramstr, message, transactionid); result = false; break; } string recycleoupath = ConfigADProvider.GetADRecycleOuLdapByLdap(Convert.ToString(ouParentEntry.Properties["distinguishedName"].Value)); if (!commonProvider.GetADEntryByPath(recycleoupath, out ouRecycleEntry, out message)) { result = true; break; } DirectoryEntry newOuEntry = new DirectoryEntry(); if (commonProvider.GetOneLevelSigleOuEntry(ouRecycleEntry.Path, ou.name, out newOuEntry, out message)) { result = true; break; } OuEntry = ouRecycleEntry.Children.Add(string.Format("OU = {0}", ou.name), "organizationalUnit"); OuEntry.Properties["name"].Value = ou.name; ouRecycleEntry.CommitChanges(); ouRecycleEntry.Close(); OuEntry.CommitChanges(); OuEntry.Close(); result = true; } while (false); } catch (Exception ex) { error.Code = ErrorCode.Exception; LoggerHelper.Error("OuManager调用AddRecycleOu异常", paramstr, ex.ToString(), transactionid); result = false; } finally { if (ouParentEntry != null) { ouParentEntry.Close(); } if (ouRecycleEntry != null) { ouRecycleEntry.Close(); } if (OuEntry != null) { OuEntry.Close(); } } return(result); }