コード例 #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 ExecutePostVehiclePurchaseOrderDetailCreate(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException("localContext");
            }

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

            string message = context.MessageName;
            string error   = "";

            try
            {
                VehiclePurchaseOrderDetailsHandler vpoDetailsHandler = new VehiclePurchaseOrderDetailsHandler(service, trace);
                VehiclePurchaseOrderHandler        vpoHandler        = new VehiclePurchaseOrderHandler(service, trace);

                EntityCollection vpoDetailsCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_cmn_purchaseorderitemdetails", "gsc_cmn_purchaseorderitemdetailsid", vpoDetails.Id, service, null, OrderType.Ascending,
                                                                                                new[] { "gsc_productid", "gsc_dnpamount", "gsc_purchaseorderid", "gsc_branchid" });
                if (vpoDetailsCollection != null && vpoDetailsCollection.Entities.Count > 0)
                {
                    Entity vpoDetailsToUpdate = vpoDetailsCollection.Entities[0];
                    vpoDetailsHandler.SetDNPAmount(vpoDetailsToUpdate);
                }
            }

            catch (Exception ex)
            {
                throw new InvalidPluginExecutionException(ex.Message);
                //throw new InvalidPluginExecutionException(String.Concat("(Exceptionss)\n", ex.Message, Environment.NewLine, ex.StackTrace, Environment.NewLine, "trace>>>" + error));
            }
        }
コード例 #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 ExecutePrePurchaseOrderDetailDelete(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException("localContext");
            }

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

            try
            {
                VehiclePurchaseOrderDetailsHandler poDetailHandler = new VehiclePurchaseOrderDetailsHandler(service, trace);

                EntityCollection vpoItemCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_cmn_purchaseorderitemdetails", "gsc_cmn_purchaseorderitemdetailsid", purchaseOrderDetail.Id, service, null, OrderType.Ascending,
                                                                                             new[] { "gsc_purchaseorderid" });

                trace.Trace(vpoItemCollection.Entities.Count.ToString());
                poDetailHandler.ClearComputation(vpoItemCollection.Entities[0]);
            }
            catch (Exception ex)
            {
                throw new InvalidPluginExecutionException(String.Concat("(Exception)\n", ex.Message, Environment.NewLine, ex.StackTrace));
            }
        }
コード例 #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 ExecutePostPurchaseOrderDetailUpdate(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException("localContext");
            }

            IPluginExecutionContext context = localContext.PluginExecutionContext;
            IOrganizationService    service = localContext.OrganizationService;
            ITracingService         trace   = localContext.TracingService;
            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;

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

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

            if (vpoDetails.LogicalName != "gsc_cmn_purchaseorderitemdetails")
            {
                return;
            }

            if (context.Mode == 0) //synchronous plugin
            {
                try
                {
                    Guid preImageProductId = preImageEntity.GetAttributeValue <EntityReference>("gsc_productid") != null
                        ? preImageEntity.GetAttributeValue <EntityReference>("gsc_productid").Id
                        : Guid.Empty;

                    Guid postImageProductId = postImageEntity.GetAttributeValue <EntityReference>("gsc_productid") != null
                        ? postImageEntity.GetAttributeValue <EntityReference>("gsc_productid").Id
                        : Guid.Empty;

                    if (preImageProductId != postImageProductId)
                    {
                        VehiclePurchaseOrderDetailsHandler vpoDetailsHandler = new VehiclePurchaseOrderDetailsHandler(service, trace);

                        EntityCollection vpoDetailsCollection = CommonHandler.RetrieveRecordsByOneValue("gsc_cmn_purchaseorderitemdetails", "gsc_cmn_purchaseorderitemdetailsid", vpoDetails.Id, service, null, OrderType.Ascending,
                                                                                                        new[] { "gsc_productid", "gsc_dnpamount", "gsc_purchaseorderid", "gsc_branchid" });
                        if (vpoDetailsCollection != null && vpoDetailsCollection.Entities.Count > 0)
                        {
                            Entity vpoDetailsToUpdate = vpoDetailsCollection.Entities[0];
                            vpoDetailsHandler.SetDNPAmount(vpoDetailsToUpdate);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new InvalidPluginExecutionException(ex.Message);
                    //throw new InvalidPluginExecutionException(String.Concat("(Exception)\n", ex.Message, Environment.NewLine, ex.StackTrace));
                }
            }
        }
コード例 #4
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 ExecutePrePurchaseOrderDetailCreate(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException("localContext");
            }

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

            try
            {
                VehiclePurchaseOrderDetailsHandler vpoDetailsHandler = new VehiclePurchaseOrderDetailsHandler(service, trace);
                vpoDetailsHandler.RestrictMultipleCreate(vpoDetails);
            }

            catch (Exception ex)
            {
                throw new InvalidPluginExecutionException(ex.Message);
            }
        }