/// <summary>
        /// Executes the plug-in.
        /// </summary>
        /// <param name="localContext">The <see cref="LocalPluginContext"/> which contains the
        /// <see cref="IPluginExecutionContext"/>,
        /// <see cref="IOrganizationService"/>
        /// and <see cref="ITracingService"/>
        /// </param>
        /// <remarks>
        /// For improved performance, Microsoft Dynamics CRM caches plug-in instances.
        /// The plug-in's Execute method should be written to be stateless as the constructor
        /// is not called for every invocation of the plug-in. Also, multiple system threads
        /// could execute the plug-in at the same time. All per invocation state information
        /// is stored in the context. This means that you should not use global variables in plug-ins.
        /// </remarks>
        protected void ExecutePreValidateInsuranceCoverageDelete(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException("localContext");
            }

            IPluginExecutionContext context = localContext.PluginExecutionContext;
            IOrganizationService    service = localContext.OrganizationService;
            ITracingService         trace   = localContext.TracingService;
            var insuranceCoverageEntity     = (EntityReference)context.InputParameters["Target"];

            try
            {
                EntityCollection coverageCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_cmn_insurancecoverage", "gsc_cmn_insurancecoverageid", insuranceCoverageEntity.Id, service, null, OrderType.Ascending,
                                                                                              new[] { "gsc_premium", "gsc_insuranceid" });

                InsuranceCoverageHandler coverageHandler = new InsuranceCoverageHandler(service, trace);
                coverageHandler.ComputeTotalPremium(coverageCollection.Entities[0], context.MessageName);
            }
            catch (Exception ex)
            {
                throw new InvalidPluginExecutionException(String.Concat("(Exception)\n", ex.Message, Environment.NewLine, ex.StackTrace));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Executes the plug-in.
        /// </summary>
        /// <param name="localContext">The <see cref="LocalPluginContext"/> which contains the
        /// <see cref="IPluginExecutionContext"/>,
        /// <see cref="IOrganizationService"/>
        /// and <see cref="ITracingService"/>
        /// </param>
        /// <remarks>
        /// For improved performance, Microsoft Dynamics CRM caches plug-in instances.
        /// The plug-in's Execute method should be written to be stateless as the constructor
        /// is not called for every invocation of the plug-in. Also, multiple system threads
        /// could execute the plug-in at the same time. All per invocation state information
        /// is stored in the context. This means that you should not use global variables in plug-ins.
        /// </remarks>
        protected void ExecutePostInsuranceCoverageCreate(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException("localContext");
            }

            IPluginExecutionContext context = localContext.PluginExecutionContext;
            IOrganizationService    service = localContext.OrganizationService;
            ITracingService         trace   = localContext.TracingService;
            Entity insuranceCoverageEntity  = (Entity)context.InputParameters["Target"];

            if (insuranceCoverageEntity.LogicalName != "gsc_cmn_insurancecoverage")
            {
                return;
            }

            try
            {
                InsuranceCoverageHandler coverageHandler = new InsuranceCoverageHandler(service, trace);
                coverageHandler.ComputeTotalPremium(insuranceCoverageEntity, context.MessageName);
            }
            catch (Exception ex)
            {
                throw new InvalidPluginExecutionException(ex.ToString());
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Executes the plug-in.
        /// </summary>
        /// <param name="localContext">The <see cref="LocalPluginContext"/> which contains the
        /// <see cref="IPluginExecutionContext"/>,
        /// <see cref="IOrganizationService"/>
        /// and <see cref="ITracingService"/>
        /// </param>
        /// <remarks>
        /// For improved performance, Microsoft Dynamics CRM caches plug-in instances.
        /// The plug-in's Execute method should be written to be stateless as the constructor
        /// is not called for every invocation of the plug-in. Also, multiple system threads
        /// could execute the plug-in at the same time. All per invocation state information
        /// is stored in the context. This means that you should not use global variables in plug-ins.
        /// </remarks>
        protected void ExecutePostInsuranceCoverageUpdate(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException("localContext");
            }

            IPluginExecutionContext context = localContext.PluginExecutionContext;

            Entity preImageEntity  = (context.PreEntityImages != null && context.PreEntityImages.Contains(this.preImageAlias)) ? context.PreEntityImages[this.preImageAlias] : null;
            Entity postImageEntity = (context.PostEntityImages != null && context.PostEntityImages.Contains(this.postImageAlias)) ? context.PostEntityImages[this.postImageAlias] : null;

            IOrganizationService service = localContext.OrganizationService;
            ITracingService      trace   = localContext.TracingService;

            if (!(context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity))
            {
                return;
            }

            Entity insuranceCoverageEntity = (Entity)context.InputParameters["Target"];

            if (insuranceCoverageEntity.LogicalName != "gsc_cmn_insurancecoverage")
            {
                return;
            }

            if (context.Mode == 0) //Synchronous Plugin
            {
                try
                {
                    var preImagePremium = preImageEntity.GetAttributeValue <Money>("gsc_premium") != null
                        ? preImageEntity.GetAttributeValue <Money>("gsc_premium").Value
                        : Decimal.Zero;

                    var postImagePremium = postImageEntity.GetAttributeValue <Money>("gsc_premium") != null
                        ? postImageEntity.GetAttributeValue <Money>("gsc_premium").Value
                        : Decimal.Zero;

                    if (preImagePremium != postImagePremium)
                    {
                        InsuranceCoverageHandler coverageHandler = new InsuranceCoverageHandler(service, trace);
                        coverageHandler.ComputeTotalPremium(postImageEntity, context.MessageName);
                    }
                }
                catch (Exception ex)
                {
                    //throw new InvalidPluginExecutionException(String.Concat("(Exception)\n", ex.Message, Environment.NewLine, ex.StackTrace, Environment.NewLine, error));
                    throw new InvalidPluginExecutionException(ex.Message);
                }
            }
        }