protected override void Execute(IWorkflowActivityContext context) { this.EnsureNotNull(context, nameof(context)); var activityContext = context.GetExecutionContext(); var primaryEntityId = context.WorkflowContext.PrimaryEntityId; var primaryEntityName = context.WorkflowContext.PrimaryEntityName; var attributeName = AttributeName.Get(activityContext); var primaryEntity = RetrievePrimaryEntity(context, primaryEntityName, primaryEntityId, attributeName); var value = primaryEntity?.GetAttributeValue <Object>(attributeName); if (value == null) { return; } if (!(value is EntityReference)) { throw new InvalidPluginExecutionException($"Invalid field value type {value.GetType().FullName}."); } var entityReference = (EntityReference)value; EntityLogicalName.Set(activityContext, entityReference.LogicalName); EntityId.Set(activityContext, entityReference.Id.ToString()); }
private IEnumerable <Entity> GetTeamUsers(IWorkflowActivityContext context, EntityReference team) { if (team == null) { return(Enumerable.Empty <Entity>()); } var fetch = $@"<fetch distinct='true'> <entity name='systemuser'> <attribute name='systemuserid'/> <attribute name='fullname'/> <order descending='false' attribute='fullname'/> <filter type='and'> <condition attribute='isdisabled' value='0' operator='eq'/> <condition attribute='accessmode' value='3' operator='ne'/> <condition attribute='accessmode' value='5' operator='ne'/> </filter> <link-entity name='teammembership' to='systemuserid' from='systemuserid'> <filter type='and'> <condition attribute='teamid' value='{team.Id}' operator='eq' /> </filter> </link-entity> </entity> </fetch>"; var entities = context.OrganizationService.FetchAll(fetch); return(entities); }
protected override void Execute(IWorkflowActivityContext context) { var user = UserId.Get(context.ExecutionContext.InnerContext); var role = RoleId.Get(context.ExecutionContext.InnerContext); var remove = Remove.Get(context.ExecutionContext.InnerContext); if (user == null || role == null) { return; } var relationship = "systemuserroles_association"; if (remove) { context.OrganizationService.Disassociate( user.LogicalName, user.Id, new Relationship(relationship), new EntityReferenceCollection { role }); } else { context.OrganizationService.Associate( user.LogicalName, user.Id, new Relationship(relationship), new EntityReferenceCollection { role }); } }
protected override void Execute(IWorkflowActivityContext context) { var executionContext = context.GetExecutionContext(); var user = new EntityReference("systemuser", context.WorkflowContext.InitiatingUserId); User.Set(executionContext, user); }
protected override void Execute(IWorkflowActivityContext context) { var entityId = context.WorkflowContext.PrimaryEntityId; var entityName = context.WorkflowContext.PrimaryEntityName; var entity = new EntityReference(entityName, entityId); Share(context, entity); }
protected virtual void Share(IWorkflowActivityContext context, EntityReference entity, EntityReference principal) { var mask = GetMask(context); if (mask == AccessRights.None) { return; } context.OrganizationService.GrantAccess(principal, entity, mask); }
private Entity RetrievePrimaryEntity( IWorkflowActivityContext context, String entityLogicalName, Guid entityId, String attributeName) { this.EnsureNotNull(context, nameof(context)); this.EnsureNotNull(entityLogicalName, nameof(entityLogicalName)); this.EnsureNotEmpty(entityId); this.EnsureNotNull(attributeName, nameof(attributeName)); return(context.OrganizationService.Retrieve(entityLogicalName, entityId, attributeName)); }
private void UpdateEmail( IWorkflowActivityContext context, EntityReference email, String applyTo, Entity[] users) { var attribute = applyTo.ToLower().Trim(); var entity = context.OrganizationService.Retrieve(email.LogicalName, email.Id, attribute); var collection = entity.GetAttributeValue <EntityCollection>(attribute); entity.AddOrUpdateAttribute(attribute, MergeActivityPartyList(collection, users)); context.OrganizationService.Update(entity); }
protected virtual void Share(IWorkflowActivityContext context, EntityReference entity) { var user = UserId.Get(context.GetExecutionContext()); var team = TeamId.Get(context.GetExecutionContext()); if (user != null) { Share(context, entity, user); } if (team != null) { Share(context, entity, team); } }
protected override void Execute(IWorkflowActivityContext context) { this.EnsureNotNull(context, nameof(context)); var activityContext = context.GetExecutionContext(); var input = Input?.Get(activityContext); var output = Transform(activityContext, input); if (output.IsNotNull()) { Output.Set(activityContext, output); } }
private Entity GetUser(IWorkflowActivityContext context, String email) { var fetch = $@"<fetch distinct='true'> <entity name='systemuser'> <attribute name='systemuserid' /> <attribute name='fullname' /> <filter type='and'> <condition attribute='internalemailaddress' value='{email.Trim()}' operator='eq' /> </filter> </entity> </fetch>"; var users = context.OrganizationService.FetchAll(fetch); return(users.FirstOrDefault()); }
protected override void Execute(IWorkflowActivityContext context) { this.EnsureNotNull(context, nameof(context)); var activityContext = context.GetExecutionContext(); var email = TargetEmail.Get(activityContext); var applyTo = ApplyTo.Get(activityContext); if (email == null) { return; } if (applyTo.IsNullOrWhiteSpace()) { return; } var role = Role.Get(activityContext); var team = Team.Get(activityContext); if (role == null && team == null) { return; } var roleUsers = GetRoleUsers(context, role); context.TracingService.Trace($"Found {roleUsers?.Count()} for role {role?.Id}"); var teamUsers = GetTeamUsers(context, team); context.TracingService.Trace($"Found {teamUsers?.Count()} for team {team?.Id}"); var users = roleUsers.Union(teamUsers).ToArray(); if (users.Any()) { UpdateEmail( context, email, applyTo, users); } }
protected virtual AccessRights GetMask(IWorkflowActivityContext context) { var mask = AccessRights.None; if (Read.Get(context.GetExecutionContext())) { mask = mask | AccessRights.ReadAccess; } if (Append.Get(context.GetExecutionContext())) { mask = mask | AccessRights.AppendAccess; } if (AppendTo.Get(context.GetExecutionContext())) { mask = mask | AccessRights.AppendToAccess; } if (Read.Get(context.GetExecutionContext())) { mask = mask | AccessRights.ReadAccess; } if (Write.Get(context.GetExecutionContext())) { mask = mask | AccessRights.WriteAccess; } if (Delete.Get(context.GetExecutionContext())) { mask = mask | AccessRights.DeleteAccess; } if (AssignAccess.Get(context.GetExecutionContext())) { mask = mask | AccessRights.AssignAccess; } if (ShareAccess.Get(context.GetExecutionContext())) { mask = mask | AccessRights.ShareAccess; } return(mask); }
protected override void Execute(IWorkflowActivityContext context) { var executionContext = context.GetExecutionContext(); var email = Email.Get(executionContext); if (email.IsNullOrEmpty()) { return; } var user = GetUser(context, email); if (user == null) { return; } User.Set(executionContext, user.ToEntityReference()); }
protected override void Execute(IWorkflowActivityContext context) { var executionContext = context.GetExecutionContext(); var user = User.Get(executionContext); if (user == null) { return; } var manager = context.OrganizationService.Retrieve( user.LogicalName, user.Id, SystemUserEntity.ManagerFieldName)?.GetAttributeValue <EntityReference>(SystemUserEntity.ManagerFieldName); if (manager == null) { return; } Manager.Set(executionContext, manager); }
public static CodeActivityContext GetExecutionContext(this IWorkflowActivityContext executionContext) { return(executionContext.ExecutionContext.InnerContext); }
protected abstract void Execute(IWorkflowActivityContext context);