Exemple #1
0
        protected void Initialize(CodeActivityContext context)
        {
            doc = Document.Get(context);
            rec = Signer.Get(context);
            if (rec.RecipientType != "Signer")
            {
                throw new ArgumentException("Only Signers can have tabs added to them, not other Recipient types");
            }

            sigX = PositionX.Get(context);
            sigY = PositionY.Get(context);

            anchorText = AnchorText.Get(context);
            offsetX    = OffsetX.Get(context);
            offsetY    = OffsetY.Get(context);

            tabLabel   = TabLabel.Get(context);
            toolTip    = ToolTip.Get(context);
            pageNumber = PageNumber.Get(context);

            if (anchorText != null && anchorText != "" && Path.GetExtension(doc.filename) != ".pdf")
            {
                throw new FormatException("Can only use relative positioning on .pdf files");
            }
        }
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            recipientName    = RecipientName.Get(context);
            recipientEmail   = RecipientEmail.Get(context);
            subject          = Subject.Get(context);
            documentFilePath = DocumentFilePath.Get(context);
            sigX             = PositionX.Get(context);
            sigY             = PositionY.Get(context);

            anchorText = AnchorText.Get(context);
            offsetX    = OffsetX.Get(context);
            offsetY    = OffsetY.Get(context);

            if (anchorText != null && anchorText != "" && Path.GetExtension(documentFilePath) != ".pdf")
            {
                throw new FormatException("Can only use relative positioning on .pdf files");
            }

            LoadAuthentication(context);

            SendEnvelopeDelegate = new Action(SendEnvelope);
            return(SendEnvelopeDelegate.BeginInvoke(callback, state));
        }
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            // Inputs
            var timeout    = TimeoutMS.Get(context);
            var inputImage = InputImage.Get(context);
            var positionX  = PositionX.Get(context);
            var positionY  = PositionY.Get(context);
            var width      = Width.Get(context);
            var height     = Height.Get(context);
            var blur       = Blur.Get(context);
            var blurAmount = BlurAmount.Get(context);

            // Set a timeout on the execution
            var task = ExecuteWithTimeout(context, cancellationToken);

            if (await Task.WhenAny(task, Task.Delay(timeout, cancellationToken)) != task)
            {
                throw new TimeoutException(Resources.Timeout_Error);
            }

            Image returnImage;

            // Check if activity should blur or hide part of the image

            if (blur)
            {
                // Convert image to bytestream
                ImageConverter _imageConverter = new ImageConverter();
                byte[]         imageByteStream = (byte[])_imageConverter.ConvertTo(inputImage, typeof(byte[]));

                // Create image from bytestream for MagickImage use
                var magickimage = new MagickImage(imageByteStream);

                // Blur part of image
                magickimage.RegionMask(new MagickGeometry(positionX, positionY, width, height));
                magickimage.GaussianBlur(blurAmount, 25);
                magickimage.RemoveRegionMask();

                // Convert MagickInmage to Bytestream
                var          imageBytesOut = magickimage.ToByteArray();
                MemoryStream ms            = new MemoryStream(imageBytesOut);

                // Create return image from bytestream
                returnImage = Image.FromStream(ms);
            }
            else
            {
                // Create graphics context with returnImage
                returnImage = inputImage;

                using (Graphics g = Graphics.FromImage(returnImage))
                {
                    // Define brush and rectangle
                    SolidBrush blackBrush = new SolidBrush(Color.Black);
                    Rectangle  rect       = new Rectangle(positionX, positionY, width, height);

                    // Fill rectangle
                    g.FillRectangle(blackBrush, rect);

                    // Cleanup
                    g.Dispose();
                }
            }

            // Outputs
            return((ctx) => {
                OutputImage.Set(ctx, returnImage);
            });
        }