Skip to content

Commit

Permalink
Added ability to work within a transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
daryllabar committed Nov 2, 2017
1 parent 33644de commit eb55271
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 16 deletions.
4 changes: 2 additions & 2 deletions DLaB.XrmAutoNumberGenerator/AutoNumberIncrementor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Entity>());
}
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,39 @@ partial class dlab_AutoNumbering
/// Queues the generated values in the Batch using the settings. Returns the most current Setting Value
/// </summary>
/// <returns></returns>
public static dlab_AutoNumbering EnqueueNextBatch(IOrganizationService service, dlab_AutoNumbering setting, Queue<string> queue, ITracingService log)
public static dlab_AutoNumbering EnqueueNextBatch(IOrganizationService service, dlab_AutoNumbering setting, Queue<string> 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<dlab_AutoNumbering>(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;
}

Expand Down
4 changes: 2 additions & 2 deletions DLaB.XrmAutoNumberGenerator/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Binary file modified Solutions/AutoNumberGenerator.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions Solutions/AutoNumberGenerator/Other/Solution.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Descriptions>
<Description description="Allows for defining Auto-Numbering for any entity / field" languagecode="1033" />
</Descriptions>
<Version>1.0.0.4</Version>
<Version>1.0.0.5</Version>
<Managed>2</Managed>
<Publisher>
<UniqueName>daryllabar</UniqueName>
Expand Down Expand Up @@ -86,7 +86,7 @@
<RootComponent type="61" schemaName="dlab_/images/ticket_16.png" behavior="0" />
<RootComponent type="61" schemaName="dlab_/images/ticket_32.png" behavior="0" />
<RootComponent type="61" schemaName="dlab_/scripts/DLaB.AutoNumbering.js" behavior="0" />
<RootComponent type="91" schemaName="DLaB.XrmAutoNumberGenerator, Version=1.0.0.4, Culture=neutral, PublicKeyToken=f7aa25e7f5f86d89" behavior="0" />
<RootComponent type="91" schemaName="DLaB.XrmAutoNumberGenerator, Version=1.0.0.5, Culture=neutral, PublicKeyToken=f7aa25e7f5f86d89" behavior="0" />
<RootComponent type="92" id="{2a15647f-96ab-e511-80e1-6c3be5a8a258}" behavior="0" />
<RootComponent type="92" id="{a63ed0d8-96ab-e511-80e1-6c3be5a852b0}" behavior="0" />
<RootComponent type="92" id="{f37f2291-96ab-e511-80e1-6c3be5a8a258}" behavior="0" />
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<PluginAssembly FullName="DLaB.XrmAutoNumberGenerator, Version=1.0.0.4, Culture=neutral, PublicKeyToken=f7aa25e7f5f86d89" CustomizationLevel="1">
<PluginAssembly FullName="DLaB.XrmAutoNumberGenerator, Version=1.0.0.5, Culture=neutral, PublicKeyToken=f7aa25e7f5f86d89" CustomizationLevel="1">
<IsolationMode>2</IsolationMode>
<SourceType>0</SourceType>
<IntroducedVersion>1.0</IntroducedVersion>
<FileName>/PluginAssemblies/DLaBXrmAutoNumberGenerator-CD48BA08-B1E2-4824-927C-C3E0441A298A/DLaBXrmAutoNumberGenerator.dll</FileName>
<PluginTypes>
<PluginType AssemblyQualifiedName="DLaB.XrmAutoNumberGenerator.AutoNumberIncrementor, DLaB.XrmAutoNumberGenerator, Version=1.0.0.4, Culture=neutral, PublicKeyToken=f7aa25e7f5f86d89" Name="DLaB.XrmAutoNumberGenerator.AutoNumberIncrementor">
<PluginType AssemblyQualifiedName="DLaB.XrmAutoNumberGenerator.AutoNumberIncrementor, DLaB.XrmAutoNumberGenerator, Version=1.0.0.5, Culture=neutral, PublicKeyToken=f7aa25e7f5f86d89" Name="DLaB.XrmAutoNumberGenerator.AutoNumberIncrementor">
<FriendlyName>ac415b12-2085-4c41-8d2e-2046a6398f88</FriendlyName>
</PluginType>
<PluginType AssemblyQualifiedName="DLaB.XrmAutoNumberGenerator.AutoNumberRegister, DLaB.XrmAutoNumberGenerator, Version=1.0.0.4, Culture=neutral, PublicKeyToken=f7aa25e7f5f86d89" Name="DLaB.XrmAutoNumberGenerator.AutoNumberRegister">
<PluginType AssemblyQualifiedName="DLaB.XrmAutoNumberGenerator.AutoNumberRegister, DLaB.XrmAutoNumberGenerator, Version=1.0.0.5, Culture=neutral, PublicKeyToken=f7aa25e7f5f86d89" Name="DLaB.XrmAutoNumberGenerator.AutoNumberRegister">
<FriendlyName>f538c8e0-d228-4ecf-a58e-f6f52f04f5fa</FriendlyName>
</PluginType>
</PluginTypes>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<SdkMessageProcessingStep Name="DLaB.XrmAutoNumberGenerator.AutoNumberRegister: Create of dlab_autonumbering" SdkMessageProcessingStepId="{2a15647f-96ab-e511-80e1-6c3be5a8a258}">
<PluginTypeName>DLaB.XrmAutoNumberGenerator.AutoNumberRegister, DLaB.XrmAutoNumberGenerator, Version=1.0.0.4, Culture=neutral, PublicKeyToken=f7aa25e7f5f86d89</PluginTypeName>
<PluginTypeName>DLaB.XrmAutoNumberGenerator.AutoNumberRegister, DLaB.XrmAutoNumberGenerator, Version=1.0.0.5, Culture=neutral, PublicKeyToken=f7aa25e7f5f86d89</PluginTypeName>
<PrimaryEntity>dlab_autonumbering</PrimaryEntity>
<AsyncAutoDelete>0</AsyncAutoDelete>
<Description>DLaB.XrmAutoNumberGenerator.AutoNumberRegister: Create of dlab_autonumbering</Description>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<SdkMessageProcessingStep Name="DLaB.XrmAutoNumberGenerator.AutoNumberRegister: Update of dlab_autonumbering" SdkMessageProcessingStepId="{a63ed0d8-96ab-e511-80e1-6c3be5a852b0}">
<PluginTypeName>DLaB.XrmAutoNumberGenerator.AutoNumberRegister, DLaB.XrmAutoNumberGenerator, Version=1.0.0.4, Culture=neutral, PublicKeyToken=f7aa25e7f5f86d89</PluginTypeName>
<PluginTypeName>DLaB.XrmAutoNumberGenerator.AutoNumberRegister, DLaB.XrmAutoNumberGenerator, Version=1.0.0.5, Culture=neutral, PublicKeyToken=f7aa25e7f5f86d89</PluginTypeName>
<PrimaryEntity>dlab_autonumbering</PrimaryEntity>
<AsyncAutoDelete>0</AsyncAutoDelete>
<Description>DLaB.XrmAutoNumberGenerator.AutoNumberRegister: Update of dlab_autonumbering</Description>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<SdkMessageProcessingStep Name="DLaB.XrmAutoNumberGenerator.AutoNumberRegister: Delete of dlab_autonumbering" SdkMessageProcessingStepId="{f37f2291-96ab-e511-80e1-6c3be5a8a258}">
<PluginTypeName>DLaB.XrmAutoNumberGenerator.AutoNumberRegister, DLaB.XrmAutoNumberGenerator, Version=1.0.0.4, Culture=neutral, PublicKeyToken=f7aa25e7f5f86d89</PluginTypeName>
<PluginTypeName>DLaB.XrmAutoNumberGenerator.AutoNumberRegister, DLaB.XrmAutoNumberGenerator, Version=1.0.0.5, Culture=neutral, PublicKeyToken=f7aa25e7f5f86d89</PluginTypeName>
<PrimaryEntity>dlab_autonumbering</PrimaryEntity>
<AsyncAutoDelete>0</AsyncAutoDelete>
<Description>DLaB.XrmAutoNumberGenerator.AutoNumberRegister: Delete of dlab_autonumbering</Description>
Expand Down
Binary file modified Solutions/AutoNumberGenerator_managed.zip
Binary file not shown.

0 comments on commit eb55271

Please sign in to comment.