protected override void Execute(IPluginContext local) { var attributes = _attributes; if (attributes == null) { return; } var target = local.GetTargetEntity(); var image = local.GetEntityImage(EntityImageType.PreImage); var messages = new StringBuilder(); foreach (var attribute in attributes) { var tuple = Helper.GetAttributeNameAndLabel(attribute); if (!target.EnsureAttributeReadOnly(image, tuple.Item1)) { messages.AppendLine(String.Format(message, tuple.Item2)); } } if (messages.Length > 0) { throw new InvalidPluginExecutionException(messages.ToString().TrimEnd('\r', '\n')); } }
protected override void Execute(IPluginContext context) { var attributes = _attributes; if (attributes == null) { return; } var target = context.GetTargetEntity(); var create = context.IsCreateMessage(); var messages = new StringBuilder(); foreach (var attribute in attributes) { var tuple = Helper.GetAttributeNameAndLabel(attribute); if (create && !target.EnsureAttributeRequired(tuple.Item1)) { messages.AppendLine(String.Format(message, tuple.Item2)); } else if (!create && !target.EnsureAttributeRequired(tuple.Item1, ensureAttributePresent: false)) { messages.AppendLine(String.Format(message, tuple.Item2)); } } if (messages.Length > 0) { throw new InvalidPluginExecutionException(messages.ToString().TrimEnd('\r', '\n')); } }
protected override void Execute(IPluginContext context) { this.EnsureNotNull(context, nameof(context)); var target = context.GetTargetEntity(); var repository = new AutoNumberingRuleRepository(_prefix, context); var rules = repository.GetActiveByEntityName(target.LogicalName); context.TracingService.Trace($"Found {rules.Count()} auto-numbering rules for {target.LogicalName}"); if (!rules.Any()) { return; } var rule = rules.First(); var number = target.GetAttributeValue <String>(rule.AttributeName); context.TracingService.Trace($"Found {rule.AttributeName}={number}"); if (!number.IsNullOrEmpty()) { return; } var stage = (PipelineStage)context.ExecutionContext.Stage; if (stage != PipelineStage.PreValidation && !rule.Lock(context, Common.ConcurrencyTokenFieldName(_prefix))) { throw new InvalidPluginExecutionException( "Unable to lock rule entity. Plug-in should run within the context of a transaction."); } var today = DateTime.Today; var parent = GetParentEntity(context, target, rule); var lastNumber = GetLastNumber(context, rule, parent, today); var nextNumber = lastNumber + 1; ValidateNumber(rule, nextNumber); var formatted = Formatted(rule, today, target, parent, nextNumber); target.AddOrUpdateAttribute(rule.AttributeName, formatted); if (rule.IsParented()) { UpdateParent(context, rule, parent.ToEntityReference(), nextNumber, today); } else { UpdateRule(context, rule, nextNumber, today); } }
protected override void Execute(IPluginContext context) { var target = context.GetTargetEntity(); var name = target.GetAttributeValue <String>(Schema.Common.NameFieldName); name += Guid.NewGuid(); target.AddOrUpdateAttribute(Schema.Common.NameFieldName, name); }
protected override void Execute(IPluginContext context) { this.EnsureNotNull(context, nameof(context)); context.EnsureTargetLogicalName(LogEntryEntity.TypeName(_prefix)); var target = context.GetTargetEntity(); var user = target.GetAttributeValue <EntityReference>(LogEntryEntity.UserFieldName(_prefix)); if (user == null) { user = new EntityReference(SystemUserEntity.TypeName, context.ExecutionContext.InitiatingUserId); target.AddOrUpdateAttribute(LogEntryEntity.UserFieldName(_prefix), user); } }
protected override void Execute(IPluginContext context) { this.EnsureNotNull(context, nameof(context)); context.EnsureTargetLogicalName(GlobalSettingEntity.TypeName(_prefix)); var target = context .GetTargetEntity(); var image = context .GetEntityImage(EntityImageType.PreImage, throwIfNull: context.IsUpdateMessage()); var type = target .GetAttributeValue <OptionSetValue>(GlobalSettingEntity.TypeFieldName(_prefix), image)? .ToEnum <GlobalSettingType>() ?? GlobalSettingType.String; var value = target .GetAttributeValue <String>(GlobalSettingEntity.ValueFieldName(_prefix), image); ValidateValue(type, value); SanitizeValue(target, type, value); }