Ejemplo n.º 1
0
        public void Export(SequenceModel model, ISequenceBuilder builder)
        {
            // From last visible parent skipping hidden calls to another visible call.
            _visibleParents = new Stack <FunctionPresentation>();
            _builder        = builder;

            // TODO many variations are not evaluated. Input arg should be a single sequence!
            builder.AddCategory("indirect", "color", "#0000FF");

            var variations = model.SequenceVariations;

            if (variations.Count == 0)
            {
                throw new Exception("No Sequence to generate!");
            }

            var sequence             = variations.Last();
            var presentationSequence = sequence.Select(tuple => (new FunctionPresentation(tuple.Item1), new FunctionPresentation(tuple.Item2))).ToList();

            // Optional to get rid of the async await state machine objects

            // When I wrote this code it seemed to make sense. What changed?
            // MergeAsyncAwaitInternals(presentationSequence);
            InsertDummyCaller(presentationSequence);

            // Debug
            //var lines = presentationSequence.Select(tuple => $"{tuple.Item1.FullName}->{tuple.Item2?.FullName}");
            //File.WriteAllLines("d:\\lines.txt", lines);

            int lineNumber = 0;

            foreach (var(source, target) in presentationSequence)
            {
                lineNumber++;

                if (target == null || target.IsNull)
                {
                    ExitFunction(source);
                    continue;
                }

                var lastVisibleParent = _visibleParents.Any() ? _visibleParents.Peek() : null;

                if (!source.IsFiltered && !target.IsFiltered)
                {
                    InvokeFunctionDirectly(source, target);
                }
                else if (lastVisibleParent != null && !target.IsFiltered)
                {
                    Debug.Assert(source.IsFiltered);
                    InvokeFunctionIndirectly(lastVisibleParent, target);
                }
                else if (source.IsFiltered && target.IsFiltered)
                {
                    // Ignore hidden calls
                }
                else
                {
                    // Visible -> Hidden
                }
            }
        }