Exemplo n.º 1
0
        public void Execute(IServiceProvider serviceProvider)
        {
            //Extract the tracing service for use in debugging sandboxed plug-ins.
            ITracingService tracingService =
                (ITracingService)serviceProvider.GetService(typeof(ITracingService));

            // Obtain the execution context from the service provider.
            IPluginExecutionContext context = (IPluginExecutionContext)
                                              serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            var service = serviceFactory.CreateOrganizationService(context.UserId);
            OrganizationServiceContext ctx = new OrganizationServiceContext(service);
            FaultException             ex1 = new FaultException();

            //throw new InvalidPluginExecutionException("asdfsd", ex1);


            // The InputParameters collection contains all the data passed in the message request.
            if (context.InputParameters.Contains("Target") &&
                context.InputParameters["Target"] is EntityReference)
            {
                // Obtain the target entity from the input parameters.
                EntityReference entityRef  = (EntityReference)context.InputParameters["Target"];
                Entity          preEntity  = (Entity)context.PreEntityImages["fp_name"];
                var             entityName = preEntity.GetAttributeValue <string>("fp_name");

                if (entityRef.LogicalName != "fp_multilingualentity")
                {
                    return;
                }

                try
                {
                    var multiLingual = new MultiLingual(service, tracingService, entityName);

                    if (!multiLingual.destroyPluginSteps())
                    {
                        // throw new InvalidPluginExecutionException("Something went wrong", ex1);
                    }
                }

                catch (FaultException <OrganizationServiceFault> ex)
                {
                    throw new InvalidPluginExecutionException("An error occurred in the multi lingual entityplug-in.", ex);
                }

                catch (Exception ex)
                {
                    tracingService.Trace("Multi Lingual Entity Plugin: {0}", ex.ToString());
                    throw;
                }
            }
        }
        public void Execute(IServiceProvider serviceProvider)
        {
            //Extract the tracing service for use in debugging sandboxed plug-ins.
            ITracingService tracingService =
                (ITracingService)serviceProvider.GetService(typeof(ITracingService));
            FaultException ex1 = new FaultException();
            // Obtain the execution context from the service provider.
            IPluginExecutionContext context = (IPluginExecutionContext)
                                              serviceProvider.GetService(typeof(IPluginExecutionContext));

            try
            {
                IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService        service        = serviceFactory.CreateOrganizationService(context.UserId);
                EntityCollection            targets        = (EntityCollection)context.OutputParameters["BusinessEntityCollection"];

                var lang = new UserLocaleHelper(service, context).getUserLanguage();

                if (context.Depth <= 1)
                {
                    foreach (Entity outputEntity in targets.Entities)
                    {
                        var publisherPrefix = outputEntity.LogicalName.Split('_')[0];
                        if (publisherPrefix == outputEntity.LogicalName)
                        {
                            publisherPrefix = "egcs";
                        }
                        Entity entity     = service.Retrieve(outputEntity.LogicalName, outputEntity.Id, new ColumnSet(publisherPrefix + "_nameen", publisherPrefix + "_namefr"));
                        var    translator = new MultiLingual(service, tracingService, context, outputEntity, entity);
                        translator.translateOutput();
                    }
                }
            }
            catch (FaultException <OrganizationServiceFault> ex)
            {
                throw new InvalidPluginExecutionException("An error occurred in the multi lingual plug-in.", ex);
            }
        }
        public void Execute(IServiceProvider serviceProvider)
        {
            //Extract the tracing service for use in debugging sandboxed plug-ins.
            ITracingService tracingService =
                (ITracingService)serviceProvider.GetService(typeof(ITracingService));
            FaultException ex1 = new FaultException();
            // Obtain the execution context from the service provider.
            IPluginExecutionContext context = (IPluginExecutionContext)
                                              serviceProvider.GetService(typeof(IPluginExecutionContext));

            try
            {
                IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService        service        = serviceFactory.CreateOrganizationService(context.UserId);
                Entity outputEntity = (Entity)context.OutputParameters["BusinessEntity"];
                // var entityRef = (EntityReference)context.InputParameters["Target"];

                if (outputEntity != null)
                {
                    if (context.Depth > 1)
                    {
                        return;
                    }
                    //get current entity inside this context
                    QueryExpression qe = new QueryExpression(outputEntity.LogicalName);
                    qe.Criteria.AddCondition(outputEntity.LogicalName + "id", ConditionOperator.Equal, outputEntity.Id);
                    qe.ColumnSet = new ColumnSet(true);
                    Entity entity = service.RetrieveMultiple(qe).Entities[0];

                    var translator = new MultiLingual(service, tracingService, context, outputEntity, entity);
                    translator.translateOutput();
                }
            }
            catch (FaultException <OrganizationServiceFault> ex)
            {
                throw new InvalidPluginExecutionException("An error occurred in the multi lingual plug-in.", ex);
            }
        }