/// <summary> /// Validates the column set. /// </summary> /// <param name="pluginContext">The plugin context.</param> /// <exception cref="System.NullReferenceException">PostImage</exception> private static void ValidateColumnSet(IPluginContextBase pluginContext) { if (pluginContext.ColumnSet == null) { throw new NullReferenceException(nameof(pluginContext.ColumnSet)); } }
/// <summary> /// Validates the output business entity collection. /// </summary> /// <param name="pluginContext">The plugin context.</param> /// <exception cref="System.NullReferenceException">OutputBusinessEntityCollection</exception> private static void ValidateOutputBusinessEntityCollection(IPluginContextBase pluginContext) { if (pluginContext.OutputBusinessEntityCollection == null) { throw new NullReferenceException(nameof(pluginContext.OutputBusinessEntityCollection)); } }
public static bool GetIsUserDirectlyAssociatedWithSecurityRole( this IPluginContextBase pluginCtx, Guid userId, string rootRoleId = null, string templateRoleId = null) { var invalidAgrs = rootRoleId == null && templateRoleId == null; if (invalidAgrs) { throw new ArgumentOutOfRangeException($"Neither {nameof(rootRoleId)} nor {nameof(templateRoleId)} is provided."); } string[] rootRoleIds = null; if (rootRoleId != null) { rootRoleIds = new[] { rootRoleId }; } string[] templateRoleIds = null; if (templateRoleId != null) { templateRoleIds = new[] { templateRoleId }; } return(pluginCtx.GetIsUserDirectlyAssociatedWithSecurityRole(userId, rootRoleIds, templateRoleIds)); }
/// <summary> /// Validates the target entity reference. /// </summary> /// <param name="pluginContext">The local context.</param> /// <exception cref="System.NullReferenceException">TargetAsEntityReference</exception> private static void ValidateTargetEntityReference(IPluginContextBase pluginContext) { if (pluginContext.TargetAsEntityReference == null) { throw new NullReferenceException(nameof(pluginContext.TargetAsEntityReference)); } }
protected TraceLogBase(IPluginContextBase pluginCtx, ITracingService systemTracingService) { this.PluginCtx = pluginCtx; this.SystemTracingService = systemTracingService; this.traceDetailsStringBuilder = new Lazy <StringBuilder>(() => new StringBuilder()); }
public static bool GetIsUserDirectlyAssociatedWithSecurityRole( this IPluginContextBase pluginCtx, string[] rootRoleIds = null, string[] templateRoleIds = null) { return(pluginCtx.GetIsUserDirectlyAssociatedWithSecurityRole( pluginCtx.InitiatingUserId, rootRoleIds, templateRoleIds)); }
public static bool GetIsExecutionAllowed(IPluginContextBase pluginCtx) { var executeHandler = true; // ReSharper disable once SwitchStatementMissingSomeCases switch (pluginCtx.MessageName) { case MessageName.Create: case MessageName.Update: var target = pluginCtx.TargetEntityAsBaseEntity; var serviceOperationDateIsChanged = target.GetIsFieldSpecified(ServiceOperationDateFieldName); if (serviceOperationDateIsChanged) { if (pluginCtx.GetIsAdminUser() == false) { throw new PluginBusinessLogicExceptionWithSimpleLogging("Only System Administrator may initiate Service Operation."); } executeHandler = target.Attributes[ServiceOperationDateFieldName] == null; } break; case MessageName.Delete: var isServiceDeleteAction = false; var parentExecCtx = pluginCtx.ParentExecContext; if (parentExecCtx != null) { var grandParentExecCtx = parentExecCtx.ParentContext; if (grandParentExecCtx != null) { isServiceDeleteAction = ServiceDeleteActionName.Equals(grandParentExecCtx.MessageName); } if (!isServiceDeleteAction) { isServiceDeleteAction = ServiceDeleteActionName.Equals(parentExecCtx.MessageName); } } executeHandler = !isServiceDeleteAction; break; } return(executeHandler); }
/// <summary> /// Locks the given record /// </summary> /// <param name="pluginCtx">Plugin context</param> /// <param name="entityReference">The reference to the locked record.</param> /// <param name="dummyUpdatedFieldName">The logical name of the dummy updated DateTime field</param> public static void LockRecord(this IPluginContextBase pluginCtx, EntityReference entityReference, string dummyUpdatedFieldName) { if (entityReference == null) { throw new ArgumentNullException(nameof(entityReference)); } var logicalName = entityReference.LogicalName; Entity entity; var id = entityReference.Id; if (id != Guid.Empty) { pluginCtx.Trace($" LockRecord. {logicalName}. {id}"); entity = new Entity(logicalName, id); } else { var keyAttrs = entityReference.KeyAttributes; var incorrectArgument = keyAttrs == null || keyAttrs.Count == 0; if (incorrectArgument) { throw new ArgumentOutOfRangeException(nameof(entityReference)); } var keyAttrValues = keyAttrs .Select(r => $"{r.Key}:{r.Value}") .Aggregate((k1, k2) => $"{k1}, {k2}"); pluginCtx.Trace($" LockRecord. {logicalName}. {keyAttrValues}"); entity = new Entity(logicalName, keyAttrs); } entity.SetAttrValue(dummyUpdatedFieldName, DateTime.UtcNow); var orgService = pluginCtx.OrgServiceOnBehalfOfSystemUser; orgService.Update(entity); }
public ServiceBusTraceLog(IPluginContextBase pluginCtx, ITracingService systemTracingService, Guid traceServiceBusEndpointId) : base(pluginCtx, systemTracingService) { this.traceServiceBusEndpointId = traceServiceBusEndpointId; }
public AdvancedTraceLog(IPluginContextBase pluginCtx, ITracingService systemTracingService) : base(pluginCtx, systemTracingService) { }
protected override bool GetIsExecutionAllowed(IPluginContextBase pluginCtx) { return(PluginCtxExt.GetIsExecutionAllowed(pluginCtx)); }
protected override AdvancedTraceLog BuildTraceLog(IPluginContextBase pluginCtx, ITracingService tracingService) { return(new AdvancedTraceLog(pluginCtx, tracingService)); }
public static bool GetIsUserDirectlyAssociatedWithSecurityRole( this IPluginContextBase pluginCtx, Guid userId, string[] rootRoleIds = null, string[] templateRoleIds = null) { var invalidAgrs = rootRoleIds == null && templateRoleIds == null; if (invalidAgrs) { throw new ArgumentOutOfRangeException($"Neither {nameof(rootRoleIds)} nor {nameof(templateRoleIds)} is provided."); } string rootRolesCondition; if (rootRoleIds == null) { rootRolesCondition = string.Empty; } else { if (!rootRoleIds.Any()) { throw new ArgumentOutOfRangeException(nameof(rootRoleIds)); } var values = FetchXmlQueryHelper.ConvertToFetchXmlInValuesString(rootRoleIds); rootRolesCondition = $@" <condition attribute='parentrootroleid' operator='in'> {values} </condition>"; } string templateRolesCondition; if (templateRoleIds == null) { templateRolesCondition = string.Empty; } else { if (!templateRoleIds.Any()) { throw new ArgumentOutOfRangeException(nameof(rootRoleIds)); } var values = FetchXmlQueryHelper.ConvertToFetchXmlInValuesString(templateRoleIds); templateRolesCondition = $@" <condition attribute='roletemplateid' operator='in'> {values} </condition>"; } var fetchXml = $@" <fetch top='1' no-lock='true'> <entity name='role'> <attribute name='roleid' /> <filter type='or' > {templateRolesCondition} {rootRolesCondition} </filter> <link-entity name='systemuserroles' from='roleid' to='roleid' link-type='inner'> <filter> <condition attribute='systemuserid' operator='eq' value='{userId:D}'/> </filter> </link-entity> </entity> </fetch>"; return(pluginCtx.OrgServiceOnBehalfOfSystemUser.GetFetchXmlQueryResultAsSingleEntity(fetchXml) != null); }
/// <summary> /// Gets if the initiating user is a system administrator. /// </summary> /// <param name="pluginCtx">The plugin context.</param> /// <returns></returns> public static bool GetIsAdminUser(this IPluginContextBase pluginCtx) { return(pluginCtx.GetIsAdminUser(pluginCtx.InitiatingUserId)); }
/// <summary> /// Gets if the user is a system administrator. /// </summary> /// <param name="pluginCtx">The plugin context.</param> /// <param name="userId">The user identifier.</param> /// <returns></returns> public static bool GetIsAdminUser(this IPluginContextBase pluginCtx, Guid userId) { return(pluginCtx.GetIsUserDirectlyAssociatedWithSecurityRole( userId, templateRoleId: TemplateSecurityRoleIds.SystemAdministratorRoleTemplateId)); }
public ExtendedOutOfBoxTraceLog(IPluginContextBase pluginCtx, ITracingService systemTracingService) : base(pluginCtx, systemTracingService) { }
protected override ExtendedOutOfBoxTraceLog BuildTraceLog(IPluginContextBase pluginCtx, ITracingService tracingService) { return(new ExtendedOutOfBoxTraceLog(pluginCtx, tracingService)); }
protected CustomTracingServiceTraceLog(IPluginContextBase pluginCtx, ITracingService systemTracingService) : base(pluginCtx, systemTracingService) { this.customTracingService = new Lazy <CustomTracingService>( () => (CustomTracingService)this.TracingService); }