Пример #1
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 ExecutePostExtendedPriceListItemCreate(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException("localContext");
            }


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

            string message = context.MessageName;

            try
            {
                ExtendedPriceListItemHandler priceListHandler = new ExtendedPriceListItemHandler(service, trace);
                priceListHandler.OnImportVehiclePriceListItem(extendedPriceList);
                priceListHandler.OnImportItemPriceListItem(extendedPriceList);
            }
            catch (Exception ex)
            {
                //throw new InvalidPluginExecutionException(String.Concat("(Exception)\n", ex.Message, Environment.NewLine, ex.StackTrace, Environment.NewLine, error));
                throw new InvalidPluginExecutionException(ex.Message);
            }
        }
Пример #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 ExecutePreValidateExtendedPriceListItemDelete(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException("localContext");
            }

            IPluginExecutionContext context = localContext.PluginExecutionContext;
            IOrganizationService    service = localContext.OrganizationService;
            ITracingService         trace   = localContext.TracingService;
            var    entity  = (EntityReference)context.InputParameters["Target"];
            string message = context.MessageName;
            string error   = "";

            try
            {
                ExtendedPriceListItemHandler handler = new ExtendedPriceListItemHandler(service, trace);
                handler.DeleteAssociatedPriceListItem(entity.Id);
            }
            catch (Exception ex)
            {
                throw new InvalidPluginExecutionException(String.Concat("(Exception)\n", ex.Message, Environment.NewLine, ex.StackTrace, Environment.NewLine, error));
            }
        }
        /// <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 ExecutePostExtendedPriceListItemUpdate(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;
            Entity extendedEntity        = (Entity)context.InputParameters["Target"];

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

            if (extendedEntity.LogicalName != "gsc_cmn_extendedpricelistitem")
            {
                return;
            }

            if (context.Mode == 0) //Synchronous Plug-in
            {
                String message = context.MessageName;

                try
                {
                    var preImageUOM = preImageEntity.GetAttributeValue <EntityReference>("gsc_uomid") != null
                        ? preImageEntity.GetAttributeValue <EntityReference>("gsc_uomid").Id
                        : Guid.Empty;

                    var postImageUOM = postImageEntity.GetAttributeValue <EntityReference>("gsc_uomid") != null
                        ? postImageEntity.GetAttributeValue <EntityReference>("gsc_uomid").Id
                        : Guid.Empty;

                    var preImageAmount = preImageEntity.Contains("gsc_amount")
                        ? preImageEntity.GetAttributeValue <Money>("gsc_amount").Value
                        : 0;

                    var postImageAmount = postImageEntity.Contains("gsc_amount")
                        ? postImageEntity.GetAttributeValue <Money>("gsc_amount").Value
                        : 0;

                    if (preImageUOM != postImageUOM || preImageAmount != postImageAmount)
                    {
                        ExtendedPriceListItemHandler entityHandler = new ExtendedPriceListItemHandler(service, trace);
                        entityHandler.UpdatePriceListItem(extendedEntity);
                    }
                }

                catch (Exception ex)
                {
                    throw new InvalidPluginExecutionException(ex.Message);
                    // throw new InvalidPluginExecutionException(String.Concat("(Exception)\n", ex.Message, Environment.NewLine, ex.StackTrace));
                }
            }
        }