Пример #1
0
        public IPipeResult Transform(IPipeSource source)
        {
            var transforms = _pack.Transforms.ToList();
            var destinations = _pack.Destinations.ToList();
            var nameTransform = _pack.NameTransform ?? (Func<string, string>)(s => s);

            var result = new PipeResult() { Success = true };

            try
            {
                var workDoc = source.GetDocument();
                foreach (var transform in transforms)
                {
                    if (workDoc == null) break;
                    var tmpDoc = transform.Process(workDoc);
                    workDoc = tmpDoc;
                }

                // transforming failed
                if (workDoc == null)
                {
                    result.Success = false;
                    return result;
                }

                result.Document = workDoc;

                foreach (var destination in destinations)
                {
                    var name = nameTransform(source.Name);

                    var streamDestination = destination as IPipeStreamDestination;
                    if (streamDestination != null)
                    {
                        var tmpStream = new MemoryStream();
                        workDoc.Save(tmpStream);
                        tmpStream.Position = 0;

                        streamDestination.Save(tmpStream, name);

                        tmpStream.Position = 0;
                        result.Stream = tmpStream;
                    }

                    var customDestination = destination as IPipeCustomDestination;
                    if (customDestination != null)
                    {
                        customDestination.Save(workDoc, name);
                    }
                }
            }
            catch (Exception ex)
            {
                result.Exception = ex;
                result.Success = false;
            }

            return result;
        }
Пример #2
0
 /// <summary>
 /// Constructs a serialize-friendly PipeResult.
 /// </summary>
 /// <param name="pipeResult">PipeResult to make serialize-friendly</param>
 /// <param name="position">Position of the pipe in the pipeline</param>
 public FriendlyPipeResult(PipeResult pipeResult, int position)
 {
     Position  = position;
     Pipe      = pipeResult.Pipe.ToString();
     Started   = pipeResult.Started;
     Ended     = pipeResult.Ended;
     Exception = pipeResult.Exception == null ? null : pipeResult.Exception.ToString();
 }
Пример #3
0
        public ValueTask <PipeResult> Execute(CancellationToken cancellationToken)
        {
            Console.WriteLine("PrepareConfiguration...");

            var builder = new ConfigurationBuilder();

            builder.Add(new MemoryConfigurationSource
            {
                InitialData = new[]
                {
                    new KeyValuePair <string, string>("AppVersion", "1.0.0"),
                    new KeyValuePair <string, string>("Storage", "InMemory")
                }
            });
            var config = builder.Build();

            var result = new PipeResult(PipeActionAfterExecute.Continue, config);

            return(new ValueTask <PipeResult>(result));
        }
Пример #4
0
        protected bool IfBreak(
            ExecutorSettings <M, R> settings,
            PipeResult <R> result)
        {
            if (settings.FailedBreak &&
                result.Success == ExecutionResult.Failed &&
                result.Break)
            {
                return(true);
            }

            if (settings.OkBreak &&
                result.Success == ExecutionResult.Successful &&
                result.Break)
            {
                return(true);
            }

            return(false);
        }
Пример #5
0
        public IPipeResult Transform(IPipeSource source)
        {
            var transforms    = _pack.Transforms.ToList();
            var destinations  = _pack.Destinations.ToList();
            var nameTransform = _pack.NameTransform ?? (s => s);

            var result = new PipeResult {
                Success = true
            };

            try
            {
                var workDoc = source.GetDocument();
                foreach (var transform in transforms)
                {
                    if (workDoc == null)
                    {
                        break;
                    }
                    var tmpDoc = transform.Process(workDoc);
                    workDoc = tmpDoc;
                }

                // transforming failed
                if (workDoc == null)
                {
                    result.Success = false;
                    return(result);
                }

                result.Document = workDoc;

                foreach (var destination in destinations)
                {
                    var name = nameTransform(source.Name);

                    if (destination is IPipeStreamDestination streamDestination)
                    {
                        var tmpStream = new MemoryStream();
                        workDoc.Save(tmpStream);
                        tmpStream.Position = 0;

                        streamDestination.Save(tmpStream, name);

                        tmpStream.Position = 0;
                        result.Stream      = tmpStream;
                    }

                    if (destination is IPipeCustomDestination customDestination)
                    {
                        customDestination.Save(workDoc, name);
                    }
                }
            }
            catch (Exception ex)
            {
                result.Exception = ex;
                result.Success   = false;
            }

            return(result);
        }
Пример #6
0
            public ValueTask <PipeResult> Execute(CancellationToken cancellationToken)
            {
                var result = PipeResult.NewContinue("some extra data");

                return(new ValueTask <PipeResult>(result));
            }