示例#1
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;
            }
        }
示例#2
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);
            }
        }
示例#3
0
        private void CreateUpdateAccount(Guid accountId)
        {
            tracingService.Trace("Entry for CreateUpdateAccount");
            Entity account    = service.Retrieve("account", accountId, new ColumnSet(true));
            Guid   endpointId = RetrieveServiceEndPointId();

            tracingService.Trace($"Endpoint Id: {endpointId.ToString()}");

            string response = "";

            if (endpointId != Guid.Empty)
            {
                this.context.SharedVariables.Add("Account", account);
                tracingService.Trace("Added Account Entity to SharedVariables");

                try
                {
                    tracingService.Trace("Trying to connect to Cloud Service");
                    response = cloudService.Execute(new EntityReference("serviceendpoint", endpointId), context);
                }
                catch (Exception ex)
                {
                    tracingService.Trace($"CreateUpdateAccount Error: {ex.Message}");
                    response = "There was no response from the Azure Service Bus Listener. Please try again";
                }
            }

            CreateAnnotation(accountId, response);
        }
示例#4
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);
        }
示例#5
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);
        }
 public string Execute(EntityReference serviceEndpoint, IExecutionContext context)
 {
     if (crmServiceEndpointNotificationService != null)
     {
         return(crmServiceEndpointNotificationService.Execute(serviceEndpoint, context));
     }
     else
     {
         throw new NotImplementedException();
     }
 }
示例#7
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);
            }
        }
示例#8
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);
        }
示例#9
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;
            }
        }
示例#10
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");
        }
示例#11
0
 public string Execute(Guid endpointGuid)
 {
     return(_cloudService.Execute(new EntityReference(EndpointEntityName, endpointGuid), _context));
 }
示例#12
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;
            }
        }
        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;
            }
        }
示例#14
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);
            }
        }