Skip to content

Instantly share code, notes, and snippets.

@gashupl
gashupl / EnableCustomProcessingSteps.sql
Last active August 29, 2019 09:10
Enable Custom Processing Steps for SystemUser entity
UPDATE dbo.SdkMessageFilterBase
SET [IsCustomProcessingStepAllowed] = 1
WHERE PrimaryObjectTypeCode = (SELECT DISTINCT ObjectTypeCode FROM Entity WHERE Name LIKE 'SystemUser')
public class RepositoryFactory
{
private IOrganizationService service;
public RepositoryFactory(IOrganizationService service)
{
this.service = service;
}
public T Get<E, T>() where E : Entity where T : RepositoryBase<E>
{
var repository = (T)Activator.CreateInstance(typeof(T), this.service);
var orgService = serviceFactory.CreateOrganizationService(pluginExecutionContext.UserId);
var factory = new RepositoryFactory(orgService);
var opportunityRepo = factory.Get<Opportunity, OpportunityRepository>();
var data = opportunityRepo.GetSomeData();
public class RepositoryFactory
{
private IOrganizationService service;
public RepositoryFactory(IOrganizationService service)
{
this.service = service;
}
public T Get<E, T>() where E : Entity where T: RepositoryBase<E>, new()
{
var repository = new T();
public override void Execute(IPluginExecutionContext pluginExecutionContext, IOrganizationServiceFactory serviceFactory, ITracingService tracingService)
{
var orgService = serviceFactory.CreateOrganizationService(pluginExecutionContext.UserId);
var factory = new RepositoryFactory(orgService);
var opportunityRepo = factory.Get();
var data = opportunityRepo.GetSomeData();
}
class RepositoryFactory
{
private IOrganizationService service
public RepositoryFactory(IOrganizationService service)
{
this.service = service;
}
public OpportunityRepository Get()
{
return new OpportunityRepository(this.service);
public override void Execute(IPluginExecutionContext pluginExecutionContext, IOrganizationServiceFactory serviceFactory, ITracingService tracingService)
{
var orgService = serviceFactory.CreateOrganizationService(pluginExecutionContext.UserId);
var opportunityRepo = new OpportunityRepository(orgService);
var data = opportunityRepo.GetSomeData();
}
public interface IOpportunityRepository : IRepository<Opportunity>
{
List<Opportunity> GetByAccountId(Guid id);
}
public class OpportunityRepository : RepositoryBase<Opportunity>, IOpportunityRepository
{
public OpportunityRepository(IOrganizationService service) : base(service)
{
}
public abstract class RepositoryBase<T> : IRepository<T> where T : Entity
{
protected Dyn365ServiceContext ServiceContext;
protected IOrganizationService OrgService;
public RepositoryBase(IOrganizationService service)
{
this.OrgService = service;
this.ServiceContext = new Dyn365ServiceContext(service);
}
public interface IRepository<T> where T: Entity
{
T GetById(Guid id);
void Create(T entity);
void SaveChanges();
void Dispose();
}