/// <summary> /// 获取对象RDN的数组,数组最开始为对象RDN /// </summary> /// <param name="oguObject"></param> /// <returns></returns> public static string[] GetOguObjectRdns(IOguObject oguObject) { if (SynchronizeContext.Current.IsIncluded(oguObject) == false) { throw new InvalidOperationException("对象不在同步范围中"); } string relativePath = SynchronizeHelper.GetRelativePath(oguObject); if (relativePath.Length > 0) { string[] paths = relativePath.Split('\\'); if (paths.Length > 0) { paths[0] = SynchronizeContext.Current.GetMappedName(paths[0]); // 一级目录 switch (oguObject.ObjectType) { case SchemaType.Organizations: for (int i = paths.Length - 1; i > 0; i--) { paths[i] = "OU=" + ADHelper.EscapeString(paths[i]); } break; case SchemaType.Users: case SchemaType.Groups: paths[paths.Length - 1] = "CN=" + ADHelper.EscapeString(paths[paths.Length - 1]); for (int i = paths.Length - 2; i > 0; i--) { paths[i] = "OU=" + ADHelper.EscapeString(paths[i]); } break; } } if (string.IsNullOrEmpty(SynchronizeContext.Current.TargetRootOU) == false) { string[] temp = new string[paths.Length + 1]; Array.Copy(paths, 0, temp, 1, paths.Length); temp[0] = SynchronizeContext.Current.TargetRootOU; paths = temp; } Array.Reverse(paths); return(paths); } else { return(new string[0]); } }
public static string GetOguObjectDN(IOguObject oguObject) { StringBuilder strResult = new StringBuilder(oguObject.FullPath.Length * 2); if (SynchronizeContext.Current.IsIncluded(oguObject) == false) { throw new InvalidOperationException("对象不在同步范围中"); } string relativePath = SynchronizeHelper.GetRelativePath(oguObject); if (relativePath.Length > 0) { var paths = relativePath.Split('\\'); if (paths.Length > 0) { paths[0] = SynchronizeContext.Current.GetMappedName(paths[0]); // 一级目录 switch (oguObject.ObjectType) { case SchemaType.Organizations: for (int i = paths.Length - 1; i > 0; i--) { strResult.Append("OU=").Append(ADHelper.EscapeString(paths[i])).Append(","); } strResult.Append(paths[0]); break; case SchemaType.Users: case SchemaType.Groups: string name = "CN="; for (int i = paths.Length - 1; i > 0; i--) { strResult.Append(name).Append(ADHelper.EscapeString(paths[i])).Append(","); name = "OU="; } strResult.Append(paths[0]); break; } } } if (strResult.Length > 0 && string.IsNullOrEmpty(SynchronizeContext.Current.TargetRootOU) == false) { strResult.Append(",").Append(SynchronizeContext.Current.TargetRootOU); } return(strResult.ToString()); }
protected override void SetPropertyValue(IOguObject srcOguObject, string srcPropertyName, DirectoryEntry entry, string targetPropertyName, string context, SetterContext setterContext) { string srcPropertyValue = GetNormalizeddSourceValue(srcOguObject, srcPropertyName, context); string targetPropertyValue = GetNormalizeddTargetValue(entry, targetPropertyName, context); if (srcOguObject.FullPath == SynchronizeContext.Current.SourceRootPath) { srcPropertyValue = new PathPartEnumerator(SynchronizeContext.Current.TargetRootOU).Last(); //极其特别,不一定可靠,权限中心应限制更改这一组织的名称和位置。 } else { string relativePath = SynchronizeHelper.GetRelativePath(srcOguObject); if (relativePath.IndexOf('\\') < 0) { srcPropertyValue = SynchronizeContext.Current.GetMappedName(srcPropertyValue); } } if (srcPropertyValue != targetPropertyValue && entry.IsBounded() == true) { TraceItHere(srcOguObject, srcPropertyName, entry, targetPropertyName, context, srcPropertyValue, targetPropertyValue); entry.CommitChanges(); try { entry.Rename(srcOguObject.ObjectType.SchemaTypeToPrefix() + "=" + ADHelper.EscapeString(srcPropertyValue)); } catch (DirectoryServicesCOMException ex) { if (ex.ErrorCode == -2147019886) { //对象已存在 entry.Rename(srcOguObject.ObjectType.SchemaTypeToPrefix() + "=TMP" + Environment.TickCount.ToString("X")); SynchronizeContext.Current.DelayActions.Add(new DelayRenameAction(srcOguObject, entry.NativeGuid)); } else { throw; } } } }
protected override bool ComparePropertyValue(OGUPermission.IOguObject srcOguObject, string srcPropertyName, ADObjectWrapper adObject, string targetPropertyName, string context) { if (srcOguObject.FullPath == SynchronizeContext.Current.SourceRootPath) { //名称以权限中心为准 return(adObject.DN == SynchronizeHelper.AppendNamingContext(SynchronizeContext.Current.TargetRootOU)); } else { string path = SynchronizeHelper.GetRelativePath(srcOguObject); if (path.IndexOf('\\') > 0) { return(base.ComparePropertyValue(srcOguObject, srcPropertyName, adObject, targetPropertyName, context)); } else { string dn = SynchronizeContext.Current.GetMappedName(srcOguObject.Name); return(adObject.DN == SynchronizeHelper.AppendNamingContext(dn)); } } }