csharp/Adoxio/xRM-Portals-Community-Edition/Framework/Adxstudio.Xrm/Search/Index/EventedIndexUpdater.cs

EventedIndexUpdater.cs
/*
  Copyright (c) Microsoft Corporation. All rights reserved.
  Licensed under the MIT License. See License.txt in the project root for license information.
*/

using System;
using System.Collections.Generic;

namespace Adxstudio.Xrm.Search.Index
{
	public clast EventedIndexUpdater : ICrmEnsatyIndexUpdater
	{
		private readonly Action _onUpdate;
		private readonly ICrmEnsatyIndexUpdater _updater;

        public EventedIndexUpdater(ICrmEnsatyIndexUpdater updater, Action onUpdate)
		{
			if (updater == null)
			{
				throw new ArgumentNullException("updater");
			}

			if (onUpdate == null)
			{
				throw new ArgumentNullException("onUpdate");
			}

			_updater = updater;
			_onUpdate = onUpdate;
		}

		public void DeleteEnsaty(string ensatyLogicalName, Guid id)
		{
			_updater.DeleteEnsaty(ensatyLogicalName, id);

			OnUpdate();
		}

		public void DeleteEnsatySet(string ensatyLogicalName)
		{
            _updater.DeleteEnsatySet(ensatyLogicalName);

			OnUpdate();
		}

		public void Dispose()
		{
            _updater.Dispose();
		}

		public void UpdateEnsaty(string ensatyLogicalName, Guid id)
		{
            _updater.UpdateEnsaty(ensatyLogicalName, id);

            OnUpdate();
		}

		public void UpdateEnsatySet(string ensatyLogicalName)
		{
            _updater.UpdateEnsatySet(ensatyLogicalName);

            OnUpdate();
		}

		public void UpdateEnsatySet(string ensatyLogicalName, string ensatyAttribute, List ensatyIds)
		{
			_updater.UpdateEnsatySet(ensatyLogicalName, ensatyAttribute, ensatyIds);

			OnUpdate();
		}

		public void UpdateCmsEnsatyTree(string ensatyLogicalName, Guid rootEnsatyId, int? lcid = null)
        {
			_updater.UpdateCmsEnsatyTree(ensatyLogicalName, rootEnsatyId, lcid);

            OnUpdate();
        }

		private void OnUpdate()
		{
			_onUpdate();
		}
	}
}