Esempio n. 1
0
 public virtual void Execute(IPluginExecutorContext pluginContext)
 {
     if (ExecutionOrder < 1)
     {
         throw new InvalidOperationException("Invalid Execution Order.");
     }
 }
        public override void Execute(IPluginExecutorContext context)
        {
            base.Execute(context);

            var targetEntity = context.GetTargetEntity<Incident>();
            var crmServiceContext = (ICrmServiceContext)Context[0];

            var customerAccount =
                        crmServiceContext.CreateQuery<Account>().Single(x => x.Id == targetEntity.CustomerId.Id);
            targetEntity.ResponsibleContactId = customerAccount.PrimaryContactId;
        }
        public CrmPluginEvent GetPluginEvent(IPluginExecutorContext executorContext)
        {
            IPluginExecutionContext context = executorContext.PluginExecutionContext;

            var stage = (CrmEventStage)context.Stage;
            string pluginEventText = string.Concat(stage.ToString(), context.MessageName);

            CrmPluginEvent pluginEvent;
            if (Enum.TryParse(pluginEventText, out pluginEvent))
            {
                return pluginEvent;
            }
            throw new InvalidCastException(String.Format(Resources.PluginEventExtractorError, pluginEventText));
        }
        public override void Execute(IPluginExecutorContext context)
        {
            base.Execute(context);

            var targetEntity = context.GetTargetEntity<Incident>();
            var crmServiceContext = (ICrmServiceContext)Context[0];

            Guid customerId = targetEntity.Attributes.ContainsKey("customerid") ? targetEntity.CustomerId.Id
                                                            : context.GetPreEntityImage<Incident>().CustomerId.Id;
            var customerAccount = crmServiceContext.CreateQuery<Account>().Single(x => x.Id == customerId);

            if (targetEntity.ResponsibleContactId.Id != customerAccount.PrimaryContactId.Id)
            {
                throw new InvalidPluginExecutionException("Invalid Responsible Contact");
            }
        }
        public override IEnumerable<IBusinessAgent> Configure(IPluginExecutorContext context)
        {
            var targetEntity = context.GetTargetEntity<Incident>();
            if (targetEntity.ResponsibleContactId == null)
            {
                return new List<IBusinessAgent>();
            }

            var businessAgents = new List<IBusinessAgent>
            {
                new IncidentCustomerContactValidator
                {
                    ExecutionOrder = 1, Context = new object[] { CreateCrmServiceContext(context) }
                }
            };
            return businessAgents;
        }
        public override IEnumerable<IBusinessAgent> Configure(IPluginExecutorContext context)
        {
            var targetEntity = context.GetTargetEntity<Account>();
            if (!targetEntity.Attributes.ContainsKey("primarycontactid"))
            {
                return new List<IBusinessAgent>();
            }

            var businessAgents = new List<IBusinessAgent>
            {
                new IncidentsCustomerContactUpdater
                {
                    ExecutionOrder = 1, Context = new object[] { CreateCrmServiceContext(context) }
                }
            };
            return businessAgents;
        }
        public override void Execute(IPluginExecutorContext context)
        {
            base.Execute(context);

            var targetEntity = context.GetTargetEntity<Account>();
            var crmServiceContext = (ICrmServiceContext)Context[0];
            var incidents =
                    crmServiceContext.CreateQuery<Incident>().Where(x => x.CustomerId.Id == targetEntity.Id).ToArray();
            if (!incidents.Any())
            {
                return;
            }

            foreach (var incident in incidents)
            {
                incident.ResponsibleContactId = targetEntity.PrimaryContactId;
                crmServiceContext.UpdateObject(incident);
            }
            crmServiceContext.SaveChanges();
        }
Esempio n. 8
0
        public void Init()
        {
            MockCrmServiceProvider();

            m_pluginContext = new PluginContext(crmServiceProviderMock.Object, typeof(Entity));
        }
Esempio n. 9
0
        protected ICrmServiceContext CreateCrmServiceContext(IPluginExecutorContext executorContext)
        {
            var serviceContextFactory = CrmServiceProvider.Current.GetService<ICrmServiceContextFactory>();

            return serviceContextFactory.CreateServiceContext(executorContext.OrganizationService);
        }
Esempio n. 10
0
 public abstract IEnumerable<IBusinessAgent> Configure(IPluginExecutorContext context);