diff --git a/DLaB.XrmAutoNumberGenerator/AutoNumberIncrementor.cs b/DLaB.XrmAutoNumberGenerator/AutoNumberIncrementor.cs index ccb2967..a3a1ae6 100644 --- a/DLaB.XrmAutoNumberGenerator/AutoNumberIncrementor.cs +++ b/DLaB.XrmAutoNumberGenerator/AutoNumberIncrementor.cs @@ -75,7 +75,7 @@ private string GetKey(LocalPluginContext context, string name) protected override void ExecuteInternal(LocalPluginContext context) { - if (string.IsNullOrWhiteSpace(UnsecureConfig) && !context.IsInTransaction) + if (string.IsNullOrWhiteSpace(UnsecureConfig)) { ExecuteForEntity(context, context.GetTarget()); } @@ -219,7 +219,7 @@ public void EnqueueBatch(LocalPluginContext context) { try { - Setting = dlab_AutoNumbering.EnqueueNextBatch(context.SystemOrganizationService, Setting, AutoNumberBatch, context.TracingService); + Setting = dlab_AutoNumbering.EnqueueNextBatch(context.SystemOrganizationService, Setting, AutoNumberBatch, context.TracingService, context.IsInTransaction); context.Trace("Successfully enqueued batch"); break; } diff --git a/DLaB.XrmAutoNumberGenerator/Entities/EntityExtensions/dlab_AutoNumbering.cs b/DLaB.XrmAutoNumberGenerator/Entities/EntityExtensions/dlab_AutoNumbering.cs index 0e9f552..87e6dc6 100644 --- a/DLaB.XrmAutoNumberGenerator/Entities/EntityExtensions/dlab_AutoNumbering.cs +++ b/DLaB.XrmAutoNumberGenerator/Entities/EntityExtensions/dlab_AutoNumbering.cs @@ -36,18 +36,39 @@ partial class dlab_AutoNumbering /// Queues the generated values in the Batch using the settings. Returns the most current Setting Value /// /// - public static dlab_AutoNumbering EnqueueNextBatch(IOrganizationService service, dlab_AutoNumbering setting, Queue queue, ITracingService log) + public static dlab_AutoNumbering EnqueueNextBatch(IOrganizationService service, dlab_AutoNumbering setting, Queue queue, ITracingService log, bool isInTransaction) { int currentNumber; - if (string.IsNullOrWhiteSpace(setting.RowVersion)) + if (string.IsNullOrWhiteSpace(setting.RowVersion) || isInTransaction) { - // Some older versions of CRM don't contain RowVersions - log.Trace("No Row Version found. Performing Non-Thread Safe Update."); + if (isInTransaction) + { + log.Trace("Executing within transaction, Can't use the OptimisticUpdate. Falling Back to Manual Database Lock"); + } + else + { + // Some older versions of CRM don't contain RowVersions + log.Trace("No Row Version found. Performing Non-Thread Safe Update."); + } + + var stopwatch = new System.Diagnostics.Stopwatch(); + stopwatch.Start(); + // Update Entity to lock it + service.Update(new dlab_AutoNumbering + { + Id = setting.Id, + dlab_EntityName = setting.dlab_EntityName + }); + setting = service.GetEntity(setting.Id); currentNumber = setting.IncrementNextNumber(); log.Trace("Grabbing values {0} to {1} and updating setting.", currentNumber, setting.dlab_NextNumber - 1); service.Update(setting.CreateUpdateNextNumberEntity()); setting.EnqueueBatchValues(queue, currentNumber); + + stopwatch.Stop(); + + log.Trace($"Time to retrieve and Update AutoNumber {stopwatch.ElapsedMilliseconds} ms"); return setting; } diff --git a/DLaB.XrmAutoNumberGenerator/Properties/AssemblyInfo.cs b/DLaB.XrmAutoNumberGenerator/Properties/AssemblyInfo.cs index 5706008..a5fcc6f 100644 --- a/DLaB.XrmAutoNumberGenerator/Properties/AssemblyInfo.cs +++ b/DLaB.XrmAutoNumberGenerator/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.4")] -[assembly: AssemblyFileVersion("1.0.0.4")] +[assembly: AssemblyVersion("1.0.0.5")] +[assembly: AssemblyFileVersion("1.0.0.5")] diff --git a/Solutions/AutoNumberGenerator.zip b/Solutions/AutoNumberGenerator.zip index 00f998e..8271ce2 100644 Binary files a/Solutions/AutoNumberGenerator.zip and b/Solutions/AutoNumberGenerator.zip differ diff --git a/Solutions/AutoNumberGenerator/Other/Solution.xml b/Solutions/AutoNumberGenerator/Other/Solution.xml index dd07a55..46cefac 100644 --- a/Solutions/AutoNumberGenerator/Other/Solution.xml +++ b/Solutions/AutoNumberGenerator/Other/Solution.xml @@ -8,7 +8,7 @@ - 1.0.0.4 + 1.0.0.5 2 daryllabar @@ -86,7 +86,7 @@ - + diff --git a/Solutions/AutoNumberGenerator/PluginAssemblies/DLaBXrmAutoNumberGenerator-CD48BA08-B1E2-4824-927C-C3E0441A298A/DLaBXrmAutoNumberGenerator.dll b/Solutions/AutoNumberGenerator/PluginAssemblies/DLaBXrmAutoNumberGenerator-CD48BA08-B1E2-4824-927C-C3E0441A298A/DLaBXrmAutoNumberGenerator.dll index 76c1b8b..25a3b85 100644 Binary files a/Solutions/AutoNumberGenerator/PluginAssemblies/DLaBXrmAutoNumberGenerator-CD48BA08-B1E2-4824-927C-C3E0441A298A/DLaBXrmAutoNumberGenerator.dll and b/Solutions/AutoNumberGenerator/PluginAssemblies/DLaBXrmAutoNumberGenerator-CD48BA08-B1E2-4824-927C-C3E0441A298A/DLaBXrmAutoNumberGenerator.dll differ diff --git a/Solutions/AutoNumberGenerator/PluginAssemblies/DLaBXrmAutoNumberGenerator-CD48BA08-B1E2-4824-927C-C3E0441A298A/DLaBXrmAutoNumberGenerator.dll.data.xml b/Solutions/AutoNumberGenerator/PluginAssemblies/DLaBXrmAutoNumberGenerator-CD48BA08-B1E2-4824-927C-C3E0441A298A/DLaBXrmAutoNumberGenerator.dll.data.xml index 82d5aca..1d9f1d2 100644 --- a/Solutions/AutoNumberGenerator/PluginAssemblies/DLaBXrmAutoNumberGenerator-CD48BA08-B1E2-4824-927C-C3E0441A298A/DLaBXrmAutoNumberGenerator.dll.data.xml +++ b/Solutions/AutoNumberGenerator/PluginAssemblies/DLaBXrmAutoNumberGenerator-CD48BA08-B1E2-4824-927C-C3E0441A298A/DLaBXrmAutoNumberGenerator.dll.data.xml @@ -1,14 +1,14 @@  - + 2 0 1.0 /PluginAssemblies/DLaBXrmAutoNumberGenerator-CD48BA08-B1E2-4824-927C-C3E0441A298A/DLaBXrmAutoNumberGenerator.dll - + ac415b12-2085-4c41-8d2e-2046a6398f88 - + f538c8e0-d228-4ecf-a58e-f6f52f04f5fa diff --git a/Solutions/AutoNumberGenerator/SdkMessageProcessingSteps/{2a15647f-96ab-e511-80e1-6c3be5a8a258}.xml b/Solutions/AutoNumberGenerator/SdkMessageProcessingSteps/{2a15647f-96ab-e511-80e1-6c3be5a8a258}.xml index f1aefc4..bf8b4f7 100644 --- a/Solutions/AutoNumberGenerator/SdkMessageProcessingSteps/{2a15647f-96ab-e511-80e1-6c3be5a8a258}.xml +++ b/Solutions/AutoNumberGenerator/SdkMessageProcessingSteps/{2a15647f-96ab-e511-80e1-6c3be5a8a258}.xml @@ -1,6 +1,6 @@  - DLaB.XrmAutoNumberGenerator.AutoNumberRegister, DLaB.XrmAutoNumberGenerator, Version=1.0.0.4, Culture=neutral, PublicKeyToken=f7aa25e7f5f86d89 + DLaB.XrmAutoNumberGenerator.AutoNumberRegister, DLaB.XrmAutoNumberGenerator, Version=1.0.0.5, Culture=neutral, PublicKeyToken=f7aa25e7f5f86d89 dlab_autonumbering 0 DLaB.XrmAutoNumberGenerator.AutoNumberRegister: Create of dlab_autonumbering diff --git a/Solutions/AutoNumberGenerator/SdkMessageProcessingSteps/{a63ed0d8-96ab-e511-80e1-6c3be5a852b0}.xml b/Solutions/AutoNumberGenerator/SdkMessageProcessingSteps/{a63ed0d8-96ab-e511-80e1-6c3be5a852b0}.xml index 959fe5b..a63e507 100644 --- a/Solutions/AutoNumberGenerator/SdkMessageProcessingSteps/{a63ed0d8-96ab-e511-80e1-6c3be5a852b0}.xml +++ b/Solutions/AutoNumberGenerator/SdkMessageProcessingSteps/{a63ed0d8-96ab-e511-80e1-6c3be5a852b0}.xml @@ -1,6 +1,6 @@  - DLaB.XrmAutoNumberGenerator.AutoNumberRegister, DLaB.XrmAutoNumberGenerator, Version=1.0.0.4, Culture=neutral, PublicKeyToken=f7aa25e7f5f86d89 + DLaB.XrmAutoNumberGenerator.AutoNumberRegister, DLaB.XrmAutoNumberGenerator, Version=1.0.0.5, Culture=neutral, PublicKeyToken=f7aa25e7f5f86d89 dlab_autonumbering 0 DLaB.XrmAutoNumberGenerator.AutoNumberRegister: Update of dlab_autonumbering diff --git a/Solutions/AutoNumberGenerator/SdkMessageProcessingSteps/{f37f2291-96ab-e511-80e1-6c3be5a8a258}.xml b/Solutions/AutoNumberGenerator/SdkMessageProcessingSteps/{f37f2291-96ab-e511-80e1-6c3be5a8a258}.xml index 50554c0..6bb00a3 100644 --- a/Solutions/AutoNumberGenerator/SdkMessageProcessingSteps/{f37f2291-96ab-e511-80e1-6c3be5a8a258}.xml +++ b/Solutions/AutoNumberGenerator/SdkMessageProcessingSteps/{f37f2291-96ab-e511-80e1-6c3be5a8a258}.xml @@ -1,6 +1,6 @@  - DLaB.XrmAutoNumberGenerator.AutoNumberRegister, DLaB.XrmAutoNumberGenerator, Version=1.0.0.4, Culture=neutral, PublicKeyToken=f7aa25e7f5f86d89 + DLaB.XrmAutoNumberGenerator.AutoNumberRegister, DLaB.XrmAutoNumberGenerator, Version=1.0.0.5, Culture=neutral, PublicKeyToken=f7aa25e7f5f86d89 dlab_autonumbering 0 DLaB.XrmAutoNumberGenerator.AutoNumberRegister: Delete of dlab_autonumbering diff --git a/Solutions/AutoNumberGenerator_managed.zip b/Solutions/AutoNumberGenerator_managed.zip index 7bf56f3..81a7323 100644 Binary files a/Solutions/AutoNumberGenerator_managed.zip and b/Solutions/AutoNumberGenerator_managed.zip differ