Esempio n. 1
0
            /// <summary>
            /// TBD
            /// </summary>
            /// <param name="module">TBD</param>
            /// <param name="shape">TBD</param>
            /// <exception cref="ArgumentException">TBD</exception>
            public FusedGraph(FusedModule module, TShape shape)
            {
                if (module == null)
                {
                    throw new ArgumentNullException(nameof(module));
                }
                if (shape == null)
                {
                    throw new ArgumentNullException(nameof(shape));
                }

                Module = module;
                Shape  = shape;
            }
Esempio n. 2
0
        /// <summary>
        /// Fuse everything that is not forbidden via AsyncBoundary attribute.
        /// </summary>
        /// <typeparam name="TShape">TBD</typeparam>
        /// <typeparam name="TMat">TBD</typeparam>
        /// <param name="graph">TBD</param>
        /// <returns>TBD</returns>
        public static Streams.Fusing.FusedGraph <TShape, TMat> Aggressive <TShape, TMat>(IGraph <TShape, TMat> graph)
            where TShape : Shape
        {
            if (graph is Streams.Fusing.FusedGraph <TShape, TMat> fusedGraph)
            {
                return(fusedGraph);
            }

            var structInfo = new BuildStructuralInfo();

            // First perform normalization by descending the module tree and recording information in the BuildStructuralInfo instance.
            LinkedList <KeyValuePair <IModule, IMaterializedValueNode> > materializedValue;

            try
            {
                materializedValue = Descend <TMat>(graph.Module, Attributes.None, structInfo,
                                                   structInfo.CreateGroup(0), 0);
            }
            catch
            {
                if (IsDebug)
                {
                    structInfo.Dump();
                }
                throw;
            }

            // Then create a copy of the original Shape with the new copied ports.
            var shape = graph.Shape.CopyFromPorts(structInfo.NewInlets(graph.Shape.Inlets),
                                                  structInfo.NewOutlets(graph.Shape.Outlets));

            // Extract the full topological information from the builder before removing assembly-internal (fused) wirings in the next step.
            var info = structInfo.ToInfo(shape,
                                         materializedValue.Select(pair => Tuple.Create(pair.Key, pair.Value)).ToList());

            // Perform the fusing of `structInfo.groups` into GraphModules (leaving them as they are for non - fusable modules).
            structInfo.RemoveInternalWires();
            structInfo.BreakUpGroupsByDispatcher();
            var modules = Fuse(structInfo);

            // Now we have everything ready for a FusedModule.
            var module = new FusedModule(
                modules,
                shape,
                ImmutableDictionary.CreateRange(structInfo.Downstreams),
                ImmutableDictionary.CreateRange(structInfo.Upstreams),
                materializedValue.First().Value,
                Attributes.None,
                info);

            if (StreamLayout.IsDebug)
            {
                StreamLayout.Validate(module);
            }
            if (IsDebug)
            {
                Console.WriteLine(module.ToString());
            }

            return(new Streams.Fusing.FusedGraph <TShape, TMat>(module, (TShape)shape));
        }