public static void Execute(
            IPlugin plugin
            , IOrganizationService service, PluginExecutionContextFake context
            , ITracingService tracingService = null
            , IServiceEndpointNotificationService notificationService = null
            )
        {
            ServiceProviderFake serviceProvider = new ServiceProviderFake();

            serviceProvider.MyPluginExecutionContext = context;
            serviceProvider.MyTracingServiceFake     = new TracingServiceFake();
            if (tracingService != null)
            {
                serviceProvider.MyTracingServiceFake.crmTracingService = tracingService;
            }

            serviceProvider.MyOrganizationServiceFactory         = new OrganizationServiceFactoryFake();
            serviceProvider.MyOrganizationServiceFactory.Service = service;

            serviceProvider.MyServiceEndpointNotificationServiceFake = new ServiceEndpointNotificationServiceFake();
            if (notificationService != null)
            {
                serviceProvider.MyServiceEndpointNotificationServiceFake.crmServiceEndpointNotificationService
                    = notificationService;
            }

            plugin.Execute(serviceProvider);
        }
Esempio n. 2
0
 public QueueLogger(IPluginExecutionContext context,
                    IServiceEndpointNotificationService cloudService)
 {
     _serviceProvider = null;
     _context         = context;
     _cloudService    = cloudService;
 }
Esempio n. 3
0
        public void Execute(IServiceProvider serviceProvider)
        {
            // Obtain the execution context from the service provider.
            IPluginExecutionContext context = (IPluginExecutionContext)
                                              serviceProvider.GetService(typeof(IPluginExecutionContext));

            // Obtain the organization service from the service provider
            IOrganizationService service = (IOrganizationService)
                                           serviceProvider.GetService(typeof(IOrganizationService));

            // Obtain the tracing service from the service provider
            ITracingService tracingService = (ITracingService)
                                             serviceProvider.GetService(typeof(ITracingService));

            // Obtain the service endpoint notificaito nservice from the service provider
            IServiceEndpointNotificationService cloudService = (IServiceEndpointNotificationService)
                                                               serviceProvider.GetService(typeof(IServiceEndpointNotificationService));

            try
            {
                tracingService.Trace("Posting the execution context.");
                string response = cloudService.Execute(new EntityReference("serviceendpoint", _serviceEndpointId), context);
                if (!String.IsNullOrEmpty(response))
                {
                    tracingService.Trace("Response = {0}", response);
                }
                tracingService.Trace("Done.");
            }
            catch (Exception e)
            {
                tracingService.Trace("Exception: {0}", e.ToString());
                throw;
            }
        }
Esempio n. 4
0
        public void Execute(IServiceProvider serviceProvider)
        {
            IPluginExecutionContext context        = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            ITracingService         tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

            IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService        service = factory.CreateOrganizationService(context.UserId);

            IServiceEndpointNotificationService cloudService = (IServiceEndpointNotificationService)serviceProvider.GetService(typeof(IServiceEndpointNotificationService));

            try
            {
                tracingService.Trace("Posting the execution context.");

                string response = cloudService.Execute(new EntityReference("serviceendpoint", serviceEndpointId), context);
                if (!string.IsNullOrEmpty(response))
                {
                    tracingService.Trace("Response = {0}", response);
                }
                tracingService.Trace("Done.");
            }
            catch (Exception e)
            {
                tracingService.Trace("Exception: {0}", e.ToString());
                throw new InvalidPluginExecutionException(e.Message);
            }
        }
Esempio n. 5
0
 public AccountLogic(IPluginExecutionContext pluginContext, IOrganizationService orgService, ITracingService traceService, IServiceEndpointNotificationService notificationService)
 {
     context        = pluginContext;
     service        = orgService;
     tracingService = traceService;
     cloudService   = notificationService;
 }
Esempio n. 6
0
        /// <summary>
        /// This method is called when the workflow executes.
        /// </summary>
        /// <param name="executionContext">The data for the event triggering
        /// the workflow.</param>
        protected override void Execute(CodeActivityContext executionContext)
        {
            IWorkflowContext context = executionContext.GetExtension <IWorkflowContext>();

            IServiceEndpointNotificationService endpointService =
                executionContext.GetExtension <IServiceEndpointNotificationService>();

            endpointService.Execute(ServiceEndpoint.Get(executionContext), context);
        }
Esempio n. 7
0
 public QueueLogger(IServiceProvider serviceProvider)
 {
     _serviceProvider = serviceProvider;
     _context         = (IPluginExecutionContext)_serviceProvider.GetService(typeof(IPluginExecutionContext));
     _cloudService    = (IServiceEndpointNotificationService)_serviceProvider.GetService(typeof(IServiceEndpointNotificationService));
     if (_cloudService == null)
     {
         throw new InvalidPluginExecutionException("Failed to retrieve the service bus service.");
     }
 }
Esempio n. 8
0
        private void SendContextToQueue(IPluginExecutionContext executionContext,
                                        IServiceEndpointNotificationService endpointNotificationService,
                                        ITracingService tracingService)
        {
            //send message to the queue
            var serviceEndpointId = new Guid("3dce31eb-7cf1-e611-80c5-00155d07290a");

            var azureQueue = new EntityReference("serviceendpoint", serviceEndpointId);

            endpointNotificationService.Execute(azureQueue, executionContext);
        }
Esempio n. 9
0
        public void Execute(IServiceProvider serviceProvider)
        {
            ITracingService         tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
            IPluginExecutionContext context        = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

            IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService        service = factory.CreateOrganizationService(context.UserId);

            IServiceEndpointNotificationService cloudService = (IServiceEndpointNotificationService)serviceProvider.GetService(typeof(IServiceEndpointNotificationService));

            try
            {
                var myContext = context;

                /* Data myData = new Data();
                 * if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity entity)
                 * {
                 *   myData.Contact = entity;
                 *   myData.Success = true;
                 * }
                 * else
                 * {
                 *   myData.Success = false;
                 * }*/

                var myEntity = new Entity("dummy");
                myEntity.Attributes.Add("mybool", true);
                myEntity.Attributes.Add("mystring", "sometext");


                myContext.OutputParameters.Add(new KeyValuePair <string, object>("MyData", myEntity));
                myContext.SharedVariables.Add(new KeyValuePair <string, object>("MyShare", myEntity));

                tracingService.Trace("Posting the execution context.");

                string response = cloudService.Execute(new EntityReference("serviceendpoint", serviceEndpointId), myContext);

                if (!string.IsNullOrEmpty(response))
                {
                    tracingService.Trace("Response = {0}", response);
                }
                tracingService.Trace("Done.");
            }
            catch (Exception e)
            {
                tracingService.Trace("Exception: {0}", e.ToString());
                throw new InvalidPluginExecutionException(e.Message);
            }
        }
Esempio n. 10
0
        protected override void Execute(CodeActivityContext executionContext)
        {
            Context        = executionContext.GetExtension <IWorkflowContext>();
            ServiceFactory = executionContext.GetExtension <IOrganizationServiceFactory>();
            Service        = ServiceFactory.CreateOrganizationService(Context.UserId);
            Trace          = executionContext.GetExtension <ITracingService>();
            Trace.Trace($"Starting Ping");

            //retrieve configuration values
            var configurationRequest  = new OrganizationRequest("ccrm_GetConfigurationValues");
            var configurationResponse = Service.Execute(configurationRequest);

            //define System Name Variable
            var crmSystemName = string.Empty;

            if (configurationResponse.Results.Contains("CrmSystem"))
            {
                crmSystemName = (string)configurationResponse.Results["CrmSystem"];
            }
            Trace.Trace($"System Name is {crmSystemName}");
            Context.SharedVariables.Add(SharedVariables.CRMSystemName, crmSystemName);

            Context.SharedVariables.Add(SharedVariables.Operation, OperationType.Ping);
            var pingValue = PingValue.Get(executionContext);

            if (string.IsNullOrEmpty(pingValue))
            {
                pingValue = "1234";
            }
            Context.SharedVariables.Add(SharedVariables.PingVal, pingValue);

            Trace.Trace(
                $"Pinging Oracle Request Listener: {string.Join(", ", (from s in Context.SharedVariables select $"{s.Key}:{s.Value}"))}]");
            Trace.Trace($"Calling service endpoint for Ping");
            IServiceEndpointNotificationService endpointService =
                executionContext.GetExtension <IServiceEndpointNotificationService>();

            var result = endpointService.Execute(ServiceEndpoint.Get(executionContext), Context);

            Trace.Trace($"Response received {result}");

            // Pass the result in shared variable as a work around for the issue
            // with calling the service endpoint from the Opportunity
            Context.SharedVariables.Add(SharedVariables.Result, result);
        }
Esempio n. 11
0
        public void Execute(IServiceProvider serviceProvider)
        {
            // Retrieve the execution context.
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

            // Extract the tracing service.
            ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

            if (tracingService == null)
            {
                throw new InvalidPluginExecutionException("Failed to retrieve the tracing service.");
            }

            IServiceEndpointNotificationService cloudService = (IServiceEndpointNotificationService)serviceProvider.GetService(typeof(IServiceEndpointNotificationService));

            if (cloudService == null)
            {
                throw new InvalidPluginExecutionException("Failed to retrieve the service bus service.");
            }

            try
            {
                // ここにプラグインのビジネスロジックを記述する
                //
                // ・・・カスタムの処理を実装したり、
                // ・・・Azure 側に渡すカスタムのデータを context に追加したり、
                //

                tracingService.Trace("Posting the execution context.");
                string response = cloudService.Execute(new EntityReference("serviceendpoint", serviceEndpointId), context);
                if (!String.IsNullOrEmpty(response))
                {
                    tracingService.Trace("Response = {0}", response);
                }
                tracingService.Trace("Done.");
            }
            catch (Exception e)
            {
                tracingService.Trace("Exception: {0}", e.ToString());
                throw;
            }
        }
Esempio n. 12
0
            internal LocalPluginContext(IServiceProvider serviceProvider)
            {
                if (serviceProvider == null)
                {
                    throw new ArgumentNullException("serviceProvider");
                }

                // Obtain the execution context service from the service provider.
                this.PluginExecutionContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

                // Obtain the tracing service from the service provider.
                this.TracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

                // Obtain the Organization Service factory service from the service provider
                IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

                // Use the factory to generate the Organization Service.
                this.OrganizationService = factory.CreateOrganizationService(this.PluginExecutionContext.UserId);

                this.CloudService = (IServiceEndpointNotificationService)serviceProvider.GetService(typeof(IServiceEndpointNotificationService));
            }
        public static IDictionary <string, object> Execute(
            CodeActivity workflow
            , CrmServiceClient service, CodeActivityContextFake context, Dictionary <string, object> inputs
            , ITracingService tracingService = null
            , IServiceEndpointNotificationService notificationService = null
            )
        {
            WorkflowInvoker invoker = new WorkflowInvoker(workflow);

            invoker.Extensions.Add <IOrganizationService>(() => service);
            invoker.Extensions.Add <IWorkflowContext>(() => context);
            if (tracingService != null)
            {
                invoker.Extensions.Add <ITracingService>(() => tracingService);
            }
            else
            {
                invoker.Extensions.Add <ITracingService>(() => new TracingServiceFake());
            }

            ServiceFactoryFake serviceFactory = new ServiceFactoryFake();

            serviceFactory.service = (IOrganizationService)service?.OrganizationServiceProxy;
            invoker.Extensions.Add <IOrganizationServiceFactory>(() => serviceFactory);

            if (notificationService != null)
            {
                invoker.Extensions.Add <IServiceEndpointNotificationService>(() => notificationService);
            }
            else
            {
                invoker.Extensions.Add <IServiceEndpointNotificationService>(() => new ServiceEndpointNotificationServiceFake());
            }

            return(invoker.Invoke(inputs));
        }
Esempio n. 14
0
        public void Execute(IServiceProvider serviceProvider)
        {
            // Retrieve the execution context.
            ITracingService             tracer  = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
            IPluginExecutionContext     context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService        service = factory.CreateOrganizationService(context.UserId);


            try
            {
                Entity azureIntegrationCallEntity = null;
                if (!context.InputParameters.Contains(Constants.TARGET))
                {
                    return;
                }
                if (((Entity)context.InputParameters[Constants.TARGET]).LogicalName != Constants.AzureIntegrationCalls.LogicalName)
                {
                    return;
                }

                switch (context.MessageName)
                {
                case Constants.Messages.Create:
                    if (context.InputParameters.Contains(Constants.TARGET) && context.InputParameters[Constants.TARGET] is Entity)
                    {
                        azureIntegrationCallEntity = context.InputParameters[Constants.TARGET] as Entity;
                    }
                    else
                    {
                        return;
                    }
                    break;

                case Constants.Messages.Update:
                    if (context.InputParameters.Contains(Constants.TARGET) && context.InputParameters[Constants.TARGET] is Entity && context.PostEntityImages.Contains(Constants.POST_IMAGE))
                    {
                        azureIntegrationCallEntity = context.PostEntityImages[Constants.POST_IMAGE] as Entity;
                    }
                    else
                    {
                        return;
                    }
                    break;
                }

                if (azureIntegrationCallEntity == null || context.Depth > 2)
                {
                    tracer.Trace($"Azure Integration Call entity is Null OR Context Depth is higher than 2. Actual Depth is : {context.Depth}");
                    return;
                }
                if (!azureIntegrationCallEntity.Attributes.Contains(Constants.AzureIntegrationCalls.Direction) || !azureIntegrationCallEntity.Attributes.Contains(Constants.AzureIntegrationCalls.EventData) ||
                    !azureIntegrationCallEntity.Attributes.Contains(Constants.AzureIntegrationCalls.StatusCode))
                {
                    tracer.Trace($"Azure Integration Call missing either Direction or EventData field. Failing Azure Integration Call");
                    if (azureIntegrationCallEntity is Entity)
                    {
                        UpdateAzureIntegrationCallErrorDetails(service, azureIntegrationCallEntity.ToEntityReference(), "Azure Integration Call missing either Direction or EventData field. Failing Azure Integration Call");
                    }
                    return;
                }

                if (azureIntegrationCallEntity.GetAttributeValue <OptionSetValue>(Constants.AzureIntegrationCalls.StatusCode).Value != 1)
                {
                    return;
                }

                if (azureIntegrationCallEntity is Entity)
                {
                    if (azureIntegrationCallEntity.GetAttributeValue <bool>(Constants.AzureIntegrationCalls.Direction))                 //OutGoing
                    {
                        IServiceEndpointNotificationService cloudService = (IServiceEndpointNotificationService)serviceProvider.GetService(typeof(IServiceEndpointNotificationService));
                        if (cloudService == null)
                        {
                            throw new InvalidPluginExecutionException("Failed to retrieve the service bus service.");
                        }

                        tracer.Trace("Posting the execution context.");
                        string response = cloudService.Execute(new EntityReference("serviceendpoint", serviceEndpointId), context);
                        if (!String.IsNullOrEmpty(response))
                        {
                            tracer.Trace("Response = {0}", response);
                        }
                        tracer.Trace("Done.");
                        CommonMethods.ChangeEntityStatus(tracer, service, azureIntegrationCallEntity.ToEntityReference(), 0, 963850000);
                    }
                    else                                                                                                    //InComing
                    {
                        tracer.Trace($"Azure Integration Call Direction is InComing.");
                    }
                }
            }
            catch (Exception e)
            {
                tracer.Trace("Exception: {0}", e.ToString());
                throw;
            }
        }
Esempio n. 15
0
        public void Execute(IServiceProvider serviceProvider)
        {
            ITracingService             tracer  = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
            IPluginExecutionContext     context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService        service = factory.CreateOrganizationService(context.UserId);

            try
            {
                Entity entity = null;

                IServiceEndpointNotificationService cloudService = (IServiceEndpointNotificationService)serviceProvider.GetService(typeof(IServiceEndpointNotificationService));
                if (cloudService == null)
                {
                    throw new InvalidPluginExecutionException("Failed to retrieve the service bus service.");
                }

                try
                {
                    tracer.Trace("Posting the execution context.");
                    string response = cloudService.Execute(new EntityReference("serviceendpoint", new Guid("1fe8dd32-bfd0-e811-a96e-000d3a16acee")), context);
                    if (!String.IsNullOrEmpty(response))
                    {
                        tracer.Trace("Response = {0}", response);
                    }
                    tracer.Trace("Done.");
                }
                catch (Exception e)
                {
                    tracer.Trace("Exception: {0}", e.ToString());
                    throw;
                }


                //TODO: Do stuff
                //switch (context.MessageName)
                //{
                //    case Constants.MessageNames.Update:
                //        if (context.InputParameters.Contains(Constants.TARGET) && context.InputParameters[Constants.TARGET] is Entity && context.PostEntityImages.Contains(Constants.POST_IMAGE))
                //        {
                //            entity = context.PostEntityImages[Constants.POST_IMAGE] as Entity;
                //        }
                //        else
                //            return;
                //        break;
                //}

                //if (entity is Entity)
                //{
                //    tracer.Trace("Sending Property Message to Queue.");
                //    tracer.Trace($"Queue Connection String : {_unsecureConfig}");

                //    //ExecuteMessage(service, entity);

                //}
            }
            catch (Exception e)
            {
                throw new InvalidPluginExecutionException(e.Message);
            }
        }
Esempio n. 16
0
 public IServiceEndpointNotificationService GetFakedServiceEndpointNotificationService()
 {
     return _serviceEndpointNotificationService ??
            ( _serviceEndpointNotificationService = A.Fake<IServiceEndpointNotificationService>());
 }
Esempio n. 17
0
        protected override void Execute(CodeActivityContext context)
        {
            Entity targetEntity = null;

            //define required services
            IWorkflowContext                    workflowcontext = context.GetExtension <IWorkflowContext>();
            IOrganizationServiceFactory         serviceFactory  = context.GetExtension <IOrganizationServiceFactory>();
            IOrganizationService                service         = serviceFactory.CreateOrganizationService(workflowcontext.InitiatingUserId);
            IServiceEndpointNotificationService cloudService    = context.GetExtension <IServiceEndpointNotificationService>();

            tracingService = context.GetExtension <ITracingService>();

            //extract input parameters
            EntityReference serviceEndPoint = this.serviceEndPoint.Get(context);
            string          propertiesSet   = this.propertiesSet.Get(context);
            string          customMessage   = this.customMessage.Get(context);

            tracingService.Trace("Execution start");

            try
            {
                //clear redundant data from context to reduce payload weight
                workflowcontext.PreEntityImages.Clear();
                workflowcontext.PostEntityImages.Clear();
                workflowcontext.InputParameters.Clear();
                workflowcontext.OutputParameters.Clear();
                workflowcontext.SharedVariables.Clear();

                //extract required entity attributes if specified
                if (!string.IsNullOrEmpty(propertiesSet))
                {
                    string[] attributes = propertiesSet.Split(';');

                    ColumnSet cs = attributes.Length > 0 ? new ColumnSet(attributes) : new ColumnSet(propertiesSet);

                    //retrieve target record attributes
                    targetEntity = service.Retrieve(workflowcontext.PrimaryEntityName, workflowcontext.PrimaryEntityId, cs);
                }

                //parse retrieved attributes into SharedVariables collection
                if (targetEntity != null)
                {
                    foreach (var attribute in targetEntity.Attributes)
                    {
                        workflowcontext.SharedVariables.Add(attribute.Key, attribute.Value);
                    }
                }

                //add custom message to the SharedVariables collection
                if (!string.IsNullOrEmpty(customMessage))
                {
                    workflowcontext.SharedVariables.Add("customMessage", customMessage);
                }

                //send message to target service endpoint
                tracingService.Trace("Starting posting the execution context");

                string response = cloudService.Execute(new EntityReference("serviceendpoint",
                                                                           serviceEndPoint.Id),
                                                       workflowcontext);

                if (!String.IsNullOrEmpty(response))
                {
                    tracingService.Trace("Response = {0}", response);
                }

                tracingService.Trace("completed posting the execution context");
            }
            catch (Exception ex)
            {
                //handle exception
                tracingService.Trace("Exception: {0}", ex.Message);
                //set output parameter
                errorMessage.Set(context, ex.Message);
            }

            //set output parameter
            isSuccessfulExecution.Set(context, true);

            tracingService.Trace("Execution end");
        }
        private void PostAccountContextToAzure(IServiceProvider serviceProvider, ITracingService tracer, IPluginExecutionContext context, Entity entity)
        {
            IServiceEndpointNotificationService cloudService = (IServiceEndpointNotificationService)serviceProvider.GetService(typeof(IServiceEndpointNotificationService));

            if (cloudService == null)
            {
                throw new InvalidPluginExecutionException("Failed to retrieve the service bus service.");
            }

            try
            {
                tracer.Trace("Posting the execution context.");

                string response = cloudService.Execute(new EntityReference("serviceendpoint", serviceEndpointId), context);

                if (!String.IsNullOrEmpty(response))
                {
                    tracer.Trace("Response = {0}", response);

                    if (response.StartsWith("false,"))
                    {
                        string[] errorInfo        = response.Split(',');
                        string   exceptionMessage = null;

                        if (errorInfo.Length > 1)
                        {
                            exceptionMessage = errorInfo[1];
                        }
                        else
                        {
                            exceptionMessage = "Unknown error.";
                        }

                        throw new InvalidPluginExecutionException(exceptionMessage);
                    }
                    else
                    {
                        string[] studentInfo = response.Split(',');

                        if (studentInfo.Length > 0)
                        {
                            if (entity.Attributes.Contains("name"))
                            {
                                entity.Attributes["name"] = studentInfo[0];
                            }
                            else
                            {
                                entity.Attributes.Add("name", studentInfo[0]);
                            }
                        }

                        if (studentInfo.Length > 1)
                        {
                            if (entity.Attributes.Contains("telephone1"))
                            {
                                entity.Attributes["telephone1"] = studentInfo[1];
                            }
                            else
                            {
                                entity.Attributes.Add("telephone1", studentInfo[1]);
                            }
                        }
                    }
                }
                tracer.Trace("Done.");
            }
            catch (Exception e)
            {
                tracer.Trace("Exception: {0}", e.ToString());
                throw;
            }
        }