コード例 #1
0
        // This custom code activity is no longer used because we found that for files larger than 22MB
        // calling the custom code activity caused errors. Smaller files work ok.
        public override void ExecuteCRMWorkFlowActivity(CodeActivityContext executionContext, LocalWorkflowContext crmWorkflowContext)
        {
            if (crmWorkflowContext == null)
            {
                throw new ArgumentNullException(nameof(crmWorkflowContext));
            }

            try
            {
                var tracingService = executionContext.GetExtension <ITracingService>();
                var context        = executionContext.GetExtension <IWorkflowContext>();
                var serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>();
                var service        = crmWorkflowContext.OrganizationService;
                var adminService   = serviceFactory.CreateOrganizationService(null);

                tracingService.Trace("In UploadIndividualAttachmentToSharePoint.");

                var parentEntityName = Parent_Entity_Name.Get(executionContext);
                var parentLookupName = Parent_Lookup_Name.Get(executionContext);

                tracingService.Trace(string.Format("Parent Entity = {0}; Parent Lookup = {1}", parentEntityName, parentLookupName));

                var azureInterface = new AzureInterface(adminService, service, tracingService);
                azureInterface.UploadFile(new EntityReference(context.PrimaryEntityName, context.PrimaryEntityId), parentEntityName, parentLookupName);
            }
            catch (Exception ex)
            {
                throw new InvalidPluginExecutionException("An error occurred in Workflow assembly.", ex);
            }
        }
コード例 #2
0
        /// <summary>
        /// Main entry point for he business logic that the plug-in is to execute.
        /// </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 365 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 override void ExecuteCrmPlugin(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new InvalidPluginExecutionException("localContext");
            }

            var tracingService = localContext.TracingService;
            var context        = localContext.PluginExecutionContext;
            var service        = localContext.OrganizationService;
            var serviceFactory = (IOrganizationServiceFactory)localContext.ServiceProvider.GetService(typeof(IOrganizationServiceFactory));
            var adminService   = serviceFactory.CreateOrganizationService(null);

            tracingService.Trace("Message = {0}", context.MessageName);

            // If its a standard Create or Update then we should have an Entity in Target.
            EntityReference entityReference = null;

            if (context.InputParameters.Contains(PluginInputParams.Target) && context.InputParameters[PluginInputParams.Target] is Entity)
            {
                entityReference = ((Entity)context.InputParameters[PluginInputParams.Target]).ToEntityReference();
            }

            // If plugin is triggered from the Custom Action Message , then we have some custom input parameters.
            if (context.InputParameters.Contains(PluginInputParams.TargetEntityName) && context.InputParameters.Contains(PluginInputParams.TargetEntityId))
            {
                entityReference = new EntityReference((string)context.InputParameters[PluginInputParams.TargetEntityName],
                                                      new Guid((string)context.InputParameters[PluginInputParams.TargetEntityId]));
            }

            tracingService.Trace("Execution depth = {0};", context.Depth.ToString());

            if (entityReference != null)
            {
                //var entity = (Entity)context.InputParameters["Target"];
                var azureInterface = new AzureInterface(adminService, service, tracingService);

                // Process the attachment depending on the target entity
                tracingService.Trace("Start of UploadFile for entity {0}", entityReference.LogicalName);

                if (entityReference.LogicalName == Annotation.EntityLogicalName ||
                    entityReference.LogicalName == ActivityMimeAttachment.EntityLogicalName ||
                    entityReference.LogicalName == Email.EntityLogicalName)
                {
                    // Triggered for Notes
                    if (context.MessageName == PluginMessages.SendFileToSharePoint || context.MessageName == PluginMessages.Update || context.MessageName == PluginMessages.Create)
                    {
                        // Send file to SharePoint
                        azureInterface.UploadFile(entityReference);
                    }
                }
                tracingService.Trace("{0} processed successfully", entityReference.LogicalName);
            }
            else
            {
                tracingService.Trace("No entity or entity reference found in Target");
            }
        }