protected void ProcessStateChange(LocalPluginContext context) { var target = context.GetTarget <dlab_AutoNumbering>(); switch (target.statecode) { case dlab_AutoNumberingState.Active: // Register Plugin if it doesn't exist context.Trace("Processing Active State Request"); var settings = context.OrganizationService.GetEntity <dlab_AutoNumbering>(context.PrimaryEntity.Id); if (settings.dlab_PluginStepId == null || context.SystemOrganizationService.GetEntityOrDefault <SdkMessageProcessingStep>(Guid.Parse(settings.dlab_PluginStepId)) == null) { RegisterIncrementor(context); } break; case dlab_AutoNumberingState.Inactive: // Unregister Plugin context.Trace("Processing In-Active State Request"); UnregisterIncrementor(context); break; case null: context.Trace("Processing Non-State Related Change"); AssertNonDuplicateId(context, target); break; default: throw new EnumCaseUndefinedException <dlab_AutoNumberingState>(target.statecode.GetValueOrDefault()); } }
/// <summary> /// Triggers the next number generation. Updates the Setting of the manager /// </summary> /// <param name="context">Plugin Context</param> public void EnqueueBatch(LocalPluginContext context) { var count = 1; while (true) { try { Setting = dlab_AutoNumbering.EnqueueNextBatch(context.SystemOrganizationService, Setting, AutoNumberBatch, context.TracingService); context.Trace("Successfully enqueued batch"); break; } catch (FaultException ex) { // Only Retry if the Error contains the Mult-ThreadedError if (ex.Message.Contains(AutoNumberRegister.MultiThreadedErrorMessage)) { //Reload Setting context.Trace("Conflict Id found. Retry #" + count++); } else { throw; } } catch (Exception ex) { context.Trace("An unexpected exception occured of type " + ex.GetType().FullName); context.Trace("Message: " + ex.Message); throw; } } }