Пример #1
0
        protected override bool Process(IInteraction parameters)
        {
            IIncomingBodiedInteraction incoming = (IIncomingBodiedInteraction)parameters.GetClosest(typeof(IIncomingBodiedInteraction));
            IOutgoingBodiedInteraction outgoing = (IOutgoingBodiedInteraction)parameters.GetClosest(typeof(IOutgoingBodiedInteraction));

            incoming.IncomingBody.CopyTo(outgoing.OutgoingBody);

            return(true);
        }
Пример #2
0
        protected bool TryGetImage(IInteraction parameters, ImageProcessor imageCallback)
        {
            bool success = false;

            IInteraction candidateImageOut;

            if (parameters.TryGetClosest(typeof(IOutgoingBodiedInteraction), out candidateImageOut))
            {
                IOutgoingBodiedInteraction imageOut = (IOutgoingBodiedInteraction)candidateImageOut;

                if (imageOut is IHttpInteraction)
                {
                    if (this.UseJpgInsteadOfPng)
                    {
                        ((IHttpInteraction)imageOut).ResponseHeaders["Content-Type"] = "image/jpg";
                    }
                    else
                    {
                        ((IHttpInteraction)imageOut).ResponseHeaders["Content-Type"] = "image/png";
                    }
                }

                MemoryStream imageData = new MemoryStream();
                SimpleOutgoingInteraction imageSourcer = new SimpleOutgoingInteraction(
                    imageData, Encoding.Default, parameters);

                if (WithBranch.TryProcess(imageSourcer))
                {
                    Image inImage = Bitmap.FromStream(imageData);

                    Bitmap outImage = imageCallback(inImage);

                    inImage.Dispose();

                    if (outImage != emptyBitmap)
                    {
                        outImage.Save(imageOut.OutgoingBody, selectedImageformat);

                        outImage.Dispose();
                    }

                    success = true;
                }
                else
                {
                    Secretary.Report(5, "Image source failure");
                }
            }
            else
            {
                Secretary.Report(5, "No outgoing body found to write result image to.");
            }

            return(success);
        }
Пример #3
0
        /// <summary>
        /// Shows form for faulty input
        /// </summary>
        /// <returns><c>true</c>, if successfully shown form, <c>false</c> otherwise.</returns>
        /// <param name="parsedData">Parsed data.</param>
        /// <param name="parameters">Parameters.</param>
        private bool DoFaultyForm(VerificationInteraction parsedData, IInteraction parameters)
        {
            bool success = true;

            Encoding encoding;

            IInteraction outgoingCandidate;

            if (parameters.TryGetClosest(typeof(IOutgoingBodiedInteraction), out outgoingCandidate))
            {
                IOutgoingBodiedInteraction outgoing = (IOutgoingBodiedInteraction)outgoingCandidate;

                encoding = outgoing.Encoding;
            }
            else
            {
                encoding = Encoding.UTF8;
            }

            foreach (string fieldName in parsedData.FaultyFields)
            {
                string failName = string.Format("{0}_failure", fieldName);

                Service handler;
                FailureWrapperInteraction fwInteraction = null;
                IInteraction interaction = parameters;

                handler = FailureHandler ?? Branches [failName];

                if (handler != null)
                {
                    if (MapErrorStrings)
                    {
                        interaction = fwInteraction = new FailureWrapperInteraction(parameters, encoding);
                    }

                    if (FailureHandler != null)
                    {
                        SimpleInteraction failureInteraction;
                        interaction = failureInteraction = new SimpleInteraction(interaction);
                        failureInteraction ["failurename"] = failName;
                    }

                    success &= handler.TryProcess(interaction);

                    if (fwInteraction != null)
                    {
                        parsedData [failName] = fwInteraction.GetTextAndClose();
                    }
                }
            }

            return(success & Form.TryProcess(parsedData));
        }
 private StringProcessorInteraction(
     MemoryStream underlyingStream,
     IInteraction parent,
     IOutgoingBodiedInteraction sinkInteraction
     ) : base(
         underlyingStream,
         sinkInteraction.Encoding,
         parent
         )
 {
     this.UnderlyingStream = underlyingStream;
     this.SinkInteraction  = sinkInteraction;
 }
Пример #5
0
        protected override bool Process(IInteraction parameters)
        {
            IInteraction candidateOutgoing;

            if (parameters.TryGetClosest(typeof(IOutgoingBodiedInteraction), out candidateOutgoing))
            {
                IOutgoingBodiedInteraction outgoing = (IOutgoingBodiedInteraction)candidateOutgoing;

                using (FileStream source = File.OpenRead(this.Filename)) {
                    source.CopyTo(outgoing.OutgoingBody);
                }
            }

            return(true);
        }
Пример #6
0
        protected override bool Process(IInteraction parameters)
        {
            bool         success = true;
            object       dateTimeCandidate;
            IInteraction targetOutgoing;

            if (parameters.TryGetFallback(this.VariableName, out dateTimeCandidate) && dateTimeCandidate is DateTime)
            {
                if (parameters.TryGetClosest(typeof(IOutgoingBodiedInteraction), out targetOutgoing))
                {
                    IOutgoingBodiedInteraction target = (IOutgoingBodiedInteraction)targetOutgoing;
                    DateTime source = (DateTime)dateTimeCandidate;

                    byte[] formatted = target.Encoding.GetBytes(source.ToString(this.DateTimeFormat));
                    target.OutgoingBody.Write(formatted, 0, formatted.Length);

                    success &= (Successful == null) || Successful.TryProcess(parameters);
                }
                else
                {
                    success &= (Failure == null) || Failure.TryProcess(parameters);
                }
            }
            else
            {
                string actualValueType;

                if (dateTimeCandidate == null)
                {
                    actualValueType = "NULL";
                }
                else
                {
                    actualValueType = dateTimeCandidate.GetType().ToString();
                }

                success &= (Failure == null) || Failure.TryProcess(parameters);
            }

            return(success);
        }
Пример #7
0
        protected override bool Process(IInteraction parameters)
        {
            IOutgoingBodiedInteraction interaction = (IOutgoingBodiedInteraction)parameters.GetClosest(typeof(IOutgoingBodiedInteraction));

            bool   success = true;
            string text;

            if (VariableName.Length == 0)
            {
                text = Format;
            }
            else if (success = parameters.TryGetFallbackString(VariableName, out text))
            {
                text = string.Format(Format, text);
            }

            byte[] data = interaction.Encoding.GetBytes(text);

            interaction.OutgoingBody.Write(data, 0, data.Length);

            return(success);
        }