/// <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 ExecutePreVehicleCabChassisCreate(LocalPluginContext localContext) { if (localContext == null) { throw new ArgumentNullException("localContext"); } IPluginExecutionContext context = localContext.PluginExecutionContext; IOrganizationService service = localContext.OrganizationService; ITracingService trace = localContext.TracingService; Entity vehicleCabChassis = (Entity)context.InputParameters["Target"]; string message = context.MessageName; try { PriceListItemHandler priceListHandler = new PriceListItemHandler(service, trace); priceListHandler.OnImportGetVehicle(vehicleCabChassis); VehicleCabChassisHandler cahChassisHandler = new VehicleCabChassisHandler(service, trace); cahChassisHandler.OnImportVehicleCabChassis(vehicleCabChassis); if (cahChassisHandler.IsCabChassisDuplicate(vehicleCabChassis)) { throw new InvalidPluginExecutionException("Cannot add duplicate item."); } cahChassisHandler.ReplicateAccessoryDetail(vehicleCabChassis); } catch (Exception ex) { throw new InvalidPluginExecutionException(ex.Message); } }
public void OnImportVehiclePriceListItem(Entity extendedPriceListItem) { _tracingService.Trace("Started OnImportVehiclePriceListItem Method.."); var productId = CommonHandler.GetEntityReferenceIdSafe(extendedPriceListItem, "gsc_productid"); Entity productEntity = new Entity(); if (productId != Guid.Empty) { _tracingService.Trace("Product not empty."); productEntity = GetProductDetails(productId); var productType = productEntity.Contains("gsc_producttype") ? productEntity.GetAttributeValue <OptionSetValue>("gsc_producttype").Value : 0; //Not Vehicle if (productType != 100000000) { _tracingService.Trace("Product not vehicle."); return; } _tracingService.Trace("Product is a vehicle."); } else { _tracingService.Trace("Product Id empty."); var optionCode = extendedPriceListItem.Contains("gsc_optioncode") ? extendedPriceListItem.GetAttributeValue <String>("gsc_optioncode") : String.Empty; var modelCode = extendedPriceListItem.Contains("gsc_modelcode") ? extendedPriceListItem.GetAttributeValue <String>("gsc_modelcode") : String.Empty; //Not Vehicle Price List item if (optionCode == String.Empty && modelCode == String.Empty) { _tracingService.Trace("Product not vehicle."); return; } else { _tracingService.Trace("Product is a vehicle."); PriceListItemHandler priceListItemHandler = new PriceListItemHandler(_organizationService, _tracingService); productEntity = priceListItemHandler.OnImportGetVehicle(extendedPriceListItem); } } UpdateExtendedPriceListItemDetails(extendedPriceListItem, productEntity); Guid priceListItemId = CreatePriceLisItem(extendedPriceListItem, productEntity); AssociateExtendedtoPriceListItem(extendedPriceListItem.Id, priceListItemId); _tracingService.Trace("Ended OnImportVehiclePriceListItem Method.."); }
public void OnImportVehiclePriceListItem(Entity extendedPriceListItem) { if (extendedPriceListItem.Contains("gsc_productid")) { if (extendedPriceListItem.GetAttributeValue <EntityReference>("gsc_productid") != null) { _tracingService.Trace("Extended Created manually."); return; } } var optionCode = extendedPriceListItem.Contains("gsc_optioncode") ? extendedPriceListItem.GetAttributeValue <String>("gsc_optioncode") : String.Empty; var modelCode = extendedPriceListItem.Contains("gsc_modelcode") ? extendedPriceListItem.GetAttributeValue <String>("gsc_modelcode") : String.Empty; //Not Vehicle Price List item if (optionCode == String.Empty && modelCode == String.Empty) { return; } _tracingService.Trace("Started UpdateExtendedPriceListItem Method.."); PriceListItemHandler priceListItemHandler = new PriceListItemHandler(_organizationService, _tracingService); var productEntity = priceListItemHandler.OnImportGetVehicle(extendedPriceListItem); var priceListName = extendedPriceListItem.GetAttributeValue <EntityReference>("gsc_pricelistid") != null ? extendedPriceListItem.GetAttributeValue <EntityReference>("gsc_pricelistid").Name : ""; extendedPriceListItem["gsc_productid"] = new EntityReference("product", productEntity.Id); extendedPriceListItem["gsc_extendedpricelistitempn"] = priceListName; extendedPriceListItem["gsc_modelyear"] = productEntity.Contains("gsc_modelyear") ? productEntity.GetAttributeValue <String>("gsc_modelyear") : String.Empty; extendedPriceListItem["gsc_basemodel"] = productEntity.GetAttributeValue <EntityReference>("gsc_vehiclemodelid") != null ? productEntity.GetAttributeValue <EntityReference>("gsc_vehiclemodelid").Name : String.Empty; _organizationService.Update(extendedPriceListItem); _tracingService.Trace("Ended UpdateExtendedPriceListItem Method.."); CreatePriceLisItem(extendedPriceListItem, productEntity); }
/// <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 ExecutePreVehicleColorCreate(LocalPluginContext localContext) { if (localContext == null) { throw new ArgumentNullException("localContext"); } IPluginExecutionContext context = localContext.PluginExecutionContext; IOrganizationService service = localContext.OrganizationService; ITracingService trace = localContext.TracingService; Entity entity = (Entity)context.InputParameters["Target"]; string message = context.MessageName; string error = ""; try { PriceListItemHandler priceListHandler = new PriceListItemHandler(service, trace); priceListHandler.OnImportGetVehicle(entity); VehicleColorHandler vehicleColorHandler = new VehicleColorHandler(service, trace); vehicleColorHandler.OnImportVehicleColor(entity); if (vehicleColorHandler.IsColorDuplicate(entity)) { throw new InvalidPluginExecutionException("Cannot add duplicate color."); } vehicleColorHandler.PopulateColorCode(entity); } catch (Exception ex) { throw new InvalidPluginExecutionException(ex.Message); } }