Esempio n. 1
0
        private void ProcessAttachments()
        {
            var azureInterface = new AzureInterface(AdminService, Service, TracingService);
            var results        = Service.GetEmailAndAttachmentsForId(Context.PrimaryEntityId);

            // Call the plugin to upload the email and all its attachments as files to SharePoint.
            if (results != null && results.Entities.Count > 0)
            {
                var emailUploaded = false;
                if (results.Entities[0].Contains(Email.Fields.defra_uploadedtosharepoint))
                {
                    // annotation and email
                    emailUploaded = results.Entities[0].GetAttributeValue <bool>(Email.Fields.defra_uploadedtosharepoint);
                }

                if (!emailUploaded)
                {
                    TracingService.Trace("Requesting action for Email upload.");
                    azureInterface.SendFileToSharePointActionRequest(Context.PrimaryEntityName, Context.PrimaryEntityId);
                }
                else
                {
                    TracingService.Trace("Email already uploaded to SharePoint");
                }

                // Now process the attachments
                TracingService.Trace("Processing {0} attachments.", results.Entities.Count.ToString());
                foreach (Entity attachment in results.Entities)
                {
                    var filesize = 0;
                    if (attachment.Contains("attachment.filesize"))
                    {
                        filesize = (int)((AliasedValue)attachment.Attributes["attachment.filesize"]).Value;
                    }
                    var filename = string.Empty;
                    if (attachment.Contains("attachment.filename"))
                    {
                        filename = (string)((AliasedValue)attachment.Attributes["attachment.filename"]).Value;
                    }
                    TracingService.Trace("Attachment Id={0}, filename={1}, size={2}.", attachment.Id.ToString(), filename, filesize.ToString());
                    if (filesize > 0)
                    {
                        var attachmentId = (Guid)((AliasedValue)attachment.Attributes["attachment.activitymimeattachmentid"]).Value;
                        // Using an action because we don't know how many attachments we'll have. Could take more than process
                        // limit of 2 minutes so using action trigger async plugin.
                        azureInterface.SendFileToSharePointActionRequest(ActivityMimeAttachment.EntityLogicalName, attachmentId);

                        TracingService.Trace("{0} request sent", PluginMessages.SendFileToSharePoint);
                    }
                    else
                    {
                        TracingService.Trace("Attachment has zero filesize. Do not upload.", PluginMessages.SendFileToSharePoint, attachment.Id.ToString());
                    }
                }
            }
        }
Esempio n. 2
0
        protected override void Execute(CodeActivityContext executionContext)
        {
            var tracingService = executionContext.GetExtension <ITracingService>();
            var context        = executionContext.GetExtension <IWorkflowContext>();
            var serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>();
            var service        = serviceFactory.CreateOrganizationService(context.UserId);
            var adminService   = serviceFactory.CreateOrganizationService(null);

            var azureInterface = new AzureInterface(adminService, service, tracingService);

            // Using an action because we don't know how many attachments we'll have. Could take more
            // than process limit of 2 minutes so using action trigger async plugin.
            // Additionally, files larger than approx 20MB cause problems with custom workflow code
            // activity if passing the whole file in the context.
            azureInterface.SendFileToSharePointActionRequest(context.PrimaryEntityName, context.PrimaryEntityId);
        }