private void SetAutoNumber(LocalPluginContext context, Entity target, AutoNumberManager manager) { var setting = manager.Setting; if (setting.UseInitializedValue(target)) { context.TraceFormat( "The Attribute {0} in the Entity {1} already contains a value, and will not be overriden", setting.AttributeName, setting.EntityName); return; } // Attempt to use Batched Auto Number if (manager.AutoNumberBatch.Count == 0) { context.TraceFormat("No batched value found. Repopulating batch for {0}.{1}", setting.EntityName, setting.AttributeName); manager.EnqueueBatch(context); if (manager.AutoNumberBatch.Count == 0) { throw new InvalidPluginExecutionException("EnqueueBatch never enqueued a new value!"); } } target[setting.AttributeName] = manager.AutoNumberBatch.Dequeue(); }
private void AssertNonDuplicateId(LocalPluginContext context, dlab_AutoNumbering target) { if (target.dlab_NextNumber == null) { return; } var preImage = context.GetPreEntity <dlab_AutoNumbering>(); preImage.AssertContainsAllNonNull(dlab_AutoNumbering.Fields.dlab_NextNumber); if (context.Depth > 1 && target.dlab_NextNumber <= preImage.dlab_NextNumber) { throw new InvalidPluginExecutionException(AutoNumberRegister.MultiThreadedErrorMessage); } context.TraceFormat("Updating Next Number from {0} to {1}", preImage.dlab_NextNumber, target.dlab_NextNumber); }