public IEnumerable <PipeOutputPackage> PipePackageInstalled(PipeOutputPackage package)
        {
            if (package.InputType.IsEnumerable() || package.OutputType.IsEnumerable())
            {
                yield break;
            }

            MethodInfo castingMethodInfo = GenericCastingMethodInfo.MakeGenericMethod(package.OutputType);

            Type         inputType           = typeof(IEnumerable <>).MakeGenericType(package.InputType);
            Type         outputType          = typeof(IEnumerable <>).MakeGenericType(package.OutputType);
            PipeCallback processCallbackFunc = (rawInputStream, broker) =>
            {
                var inputEnumerable = (IEnumerable)rawInputStream;
                var pipe            =
                    from input in inputEnumerable.Cast <object>()
                    select package.ProcessInput(input, broker);

                return(Task.Factory.ContinueWhenAll(pipe.ToArray(), tasks => tasks.Select(t => t.Result))
                       .ContinueWith(resultTask =>
                {
                    object results = resultTask.Result;
                    return castingMethodInfo.Invoke(results, new[] { results });
                }));
            };

            yield return(PipeOutputPackage.Infer(package, inputType, outputType, processCallbackFunc));
        }
        private PipeOutputPackage ExposeConversion(Type elementType, Type baseType, PipeOutputPackage package)
        {
            Type inputType  = typeof(IEnumerable <>).MakeGenericType(elementType);
            Type outputType = typeof(IEnumerable <>).MakeGenericType(baseType);

            return(PipeOutputPackage.Infer(package, inputType, outputType, (input, broker) => input.IntoTaskResult()));
        }
示例#3
0
        private PipeOutputPackage ConvertToDataType(Type inputType, PipeOutputPackage basedOffPackage)
        {
            PipeCallback processCallbackFunc = (input, broker) =>
            {
                Array array = Array.CreateInstance(inputType, 1);
                array.SetValue(input, 0);
                return(((object)array).IntoTaskResult());
            };

            Type outputType = typeof(IEnumerable <>).MakeGenericType(inputType);

            return(PipeOutputPackage.Infer(basedOffPackage, inputType, outputType, processCallbackFunc));
        }
 private static PipeOutputPackage CreateReturnPackage(PipeOutputPackage package, Type outputType)
 {
     return(PipeOutputPackage.Infer(package, package.InputType, outputType, package.ProcessInput));
 }