本文整理汇总了C#中EntityBase.GetUpdatePolicy方法的典型用法代码示例。如果您正苦于以下问题:C# EntityBase.GetUpdatePolicy方法的具体用法?C# EntityBase.GetUpdatePolicy怎么用?C# EntityBase.GetUpdatePolicy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityBase
的用法示例。
在下文中一共展示了EntityBase.GetUpdatePolicy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PerformUpdate
/// <summary>
/// Given the provided strategies, manipulate all entities to correct any violations
/// of the current policy. If no strategies are provided, the policy's default
/// strategies are used. An exception is thrown if the provided strategies are not
/// valid for the current policy.
/// </summary>
/// <param name="Item">The item.</param>
/// <param name="Entity">The entity.</param>
/// <param name="PreferredUpdateStrategy">The preferred update strategy.</param>
/// <param name="PreferredUpdateStrategyForDuplicateDates">The preferred update strategy for duplicate dates.</param>
/// <exception cref="System.ArgumentNullException"></exception>
/// <exception cref="System.InvalidOperationException">
/// The requested strategy is not available for this policy.
/// or
/// The requested strategy is not available for this policy.
/// </exception>
public void PerformUpdate(Item Item, EntityBase Entity, IUpdateStrategy PreferredUpdateStrategy = null, IUpdateStrategy PreferredUpdateStrategyForDuplicateDates = null)
{
if (Item == null)
{
throw new ArgumentNullException(nameof(Item));
}
if (Entity == null)
{
throw new ArgumentNullException(nameof(Entity));
}
IUpdateStrategy Strategy = Entity.GetUpdateStrategy();
IUpdateStrategy StrategyForDuplicateDates = Entity.GetUpdateStrategyForDuplicateDates();
if (PreferredUpdateStrategy != null)
{
if (!Entity.GetUpdatePolicy().GetAvailableStrategies().Any(s => s.GetType() == PreferredUpdateStrategy.GetType()))
{
throw new InvalidOperationException("The requested strategy is not available for this policy.");
}
Strategy = PreferredUpdateStrategy;
}
if (PreferredUpdateStrategyForDuplicateDates != null)
{
if (!Entity.GetUpdatePolicy().GetAvailableStrategies().Any(s => s.GetType() == PreferredUpdateStrategyForDuplicateDates.GetType()))
{
throw new InvalidOperationException("The requested strategy is not available for this policy.");
}
StrategyForDuplicateDates = PreferredUpdateStrategyForDuplicateDates;
}
var AllEntities = Item.AllEntities.ToArray();
for (int i = 0; i < AllEntities.Count(); i++)
{
var OtherEntity = AllEntities.ElementAt(i);
if (OtherEntity.EffectiveDate == Entity.EffectiveDate && OtherEntity.EndEffectiveDate == Entity.EndEffectiveDate)
{
StrategyForDuplicateDates.PerformUpdate(OtherEntity, Entity);
}
else
{
Strategy.PerformUpdate(OtherEntity, Entity);
}
}
}