Ejemplo n.º 1
0
        private static void ApplyChanges(List <SimpleUser> changes, ADToPermissionCenterSynchronizer context)
        {
            string[] changesIdArray             = changes.Select <SimpleUser, string>(m => m.SCObjectID).ToArray();
            PC.SchemaObjectCollection pcObjects = LoadSCObjects(changesIdArray);

            foreach (SimpleUser item in changes)
            {
                if (pcObjects.ContainsKey(item.SCObjectID))
                {
                    try
                    {
                        PC.SchemaObjectBase scObj = MeargeChanges(item.Tag, pcObjects[item.SCObjectID]);

                        PC.Adapters.SchemaObjectAdapter.Instance.Update(scObj);
                        context.Log.NumberOfModifiedItems++;
                    }
                    catch (Exception ex)
                    {
                        context.Log.NumberOfExceptions++;
                        context.Log.Status = ADSynchronizeResult.HasError;
                        LogHelper.WriteReverseSynchronizeDBLogDetail(context.Log.LogID, item.SCObjectID, AttributeHelper.Hex((byte[])item.Tag.Properties["objectguid"][0]), item.CodeName, ex.Message, ex.ToString());
                        Trace.TraceError("未成功更新," + ex.ToString());
                    }
                }
                else
                {
                    LogHelper.WriteReverseSynchronizeDBLogDetail(context.Log.LogID, item.SCObjectID, AttributeHelper.Hex((byte[])item.Tag.Properties["objectguid"][0]), item.CodeName, "未找到AD对象对应的权限中心对象。", null);
                }
            }
        }
Ejemplo n.º 2
0
        private static void ProcessBatch(ADToPermissionCenterSynchronizer context, EntityMappingCollection mappings, ADHelper adHelper, int startIndex, int size)
        {
            string[] propertiesToGet = { "sAMAccountName", "mail", "msRTCSIP-PrimaryUserAddress" };

            IEnumerable <SearchResult> adResults = SynchronizeHelper.GetSearchResultsByPropertyValues(adHelper, "sAMAccountName", mappings.ToKeyArray("CodeName", startIndex, size), ADSchemaType.Users, propertiesToGet, size);

            Dictionary <string, SimpleUser> codeNameDict = mappings.ToCodeNameDictionary(startIndex, size);

            List <SimpleUser> changes = DiscoverChanges(codeNameDict, adResults);

            ApplyChanges(changes, context);
        }
Ejemplo n.º 3
0
        public static ADReverseSynchronizeLog Start(string taskID)
        {
            taskID = string.IsNullOrEmpty(taskID) ? UuidHelper.NewUuidString() : taskID;
            ADToPermissionCenterSynchronizer context = new ADToPermissionCenterSynchronizer(taskID);

            context.Lock();
            try
            {
                Adapters.ADReverseSynchronizeLogAdapter.Instance.Update(context.Log);

                int batchSize = 32;
                EntityMappingCollection mappings = LoadMappingData();

                ADHelper adHelper = CreateADHelper();

                for (int i = 0; i < mappings.Count / batchSize; i++)
                {
                    ProcessBatch(context, mappings, adHelper, i * batchSize, batchSize);
                }

                ProcessBatch(context, mappings, adHelper, mappings.Count / batchSize * batchSize, mappings.Count % batchSize);

                if (context.Log.Status == ADSynchronizeResult.Running)
                {
                    context.Log.Status = ADSynchronizeResult.Correct;
                }
            }
            catch (Exception ex)
            {
                context.Log.Status = ADSynchronizeResult.Interrupted;
                LogHelper.WriteEventLog("反向同步时出现问题", ex.ToString(), Logging.LogPriority.Lowest, TraceEventType.Stop);
                Trace.TraceError(ex.ToString());
            }
            finally
            {
                context.Log.EndTime = DateTime.Now;
                Adapters.ADReverseSynchronizeLogAdapter.Instance.Update(context.Log);
                context.Unlock();
            }

            return(context.Log);
        }
		public static ADReverseSynchronizeLog Start(string taskID)
		{
			taskID = string.IsNullOrEmpty(taskID) ? UuidHelper.NewUuidString() : taskID;
			ADToPermissionCenterSynchronizer context = new ADToPermissionCenterSynchronizer(taskID);
			context.Lock();
			try
			{
				Adapters.ADReverseSynchronizeLogAdapter.Instance.Update(context.Log);

				int batchSize = 32;
				EntityMappingCollection mappings = LoadMappingData();

				ADHelper adHelper = CreateADHelper();

				for (int i = 0; i < mappings.Count / batchSize; i++)
				{
					ProcessBatch(context, mappings, adHelper, i * batchSize, batchSize);
				}

				ProcessBatch(context, mappings, adHelper, mappings.Count / batchSize * batchSize, mappings.Count % batchSize);

				if (context.Log.Status == ADSynchronizeResult.Running)
					context.Log.Status = ADSynchronizeResult.Correct;
			}
			catch (Exception ex)
			{
				context.Log.Status = ADSynchronizeResult.Interrupted;
				LogHelper.WriteEventLog("反向同步时出现问题", ex.ToString(), Logging.LogPriority.Lowest, TraceEventType.Stop);
				Trace.TraceError(ex.ToString());
			}
			finally
			{
				context.Log.EndTime = DateTime.Now;
				Adapters.ADReverseSynchronizeLogAdapter.Instance.Update(context.Log);
				context.Unlock();
			}

			return context.Log;
		}
		private static void ApplyChanges(List<SimpleUser> changes, ADToPermissionCenterSynchronizer context)
		{
			string[] changesIdArray = changes.Select<SimpleUser, string>(m => m.SCObjectID).ToArray();
			PC.SchemaObjectCollection pcObjects = LoadSCObjects(changesIdArray);

			foreach (SimpleUser item in changes)
			{
				if (pcObjects.ContainsKey(item.SCObjectID))
				{
					try
					{
						PC.SchemaObjectBase scObj = MeargeChanges(item.Tag, pcObjects[item.SCObjectID]);

						PC.Adapters.SchemaObjectAdapter.Instance.Update(scObj);
						context.Log.NumberOfModifiedItems++;
					}
					catch (Exception ex)
					{
						context.Log.NumberOfExceptions++;
						context.Log.Status = ADSynchronizeResult.HasError;
						LogHelper.WriteReverseSynchronizeDBLogDetail(context.Log.LogID, item.SCObjectID, AttributeHelper.Hex((byte[])item.Tag.Properties["objectguid"][0]), item.CodeName, ex.Message, ex.ToString());
						Trace.TraceError("未成功更新," + ex.ToString());
					}
				}
				else
				{
					LogHelper.WriteReverseSynchronizeDBLogDetail(context.Log.LogID, item.SCObjectID, AttributeHelper.Hex((byte[])item.Tag.Properties["objectguid"][0]), item.CodeName, "未找到AD对象对应的权限中心对象。", null);
				}
			}
		}
		private static void ProcessBatch(ADToPermissionCenterSynchronizer context, EntityMappingCollection mappings, ADHelper adHelper, int startIndex, int size)
		{
			string[] propertiesToGet = { "sAMAccountName", "mail", "msRTCSIP-PrimaryUserAddress" };

			IEnumerable<SearchResult> adResults = SynchronizeHelper.GetSearchResultsByPropertyValues(adHelper, "sAMAccountName", mappings.ToKeyArray("CodeName", startIndex, size), ADSchemaType.Users, propertiesToGet, size);

			Dictionary<string, SimpleUser> codeNameDict = mappings.ToCodeNameDictionary(startIndex, size);

			List<SimpleUser> changes = DiscoverChanges(codeNameDict, adResults);

			ApplyChanges(changes, context);
		}