コード例 #1
0
        public void Compile(BlueSwitchProject project)
        {
            Errors.Clear();

            OnCompileStart();
            RenderingEngine.EventManager.Items.Clear();
            Items.Clear();
            var starts = project.FindPotentialStarts();

            foreach (var connection in starts)
            {
                var tree = new ProcessingTree <SwitchBase>
                {
                    Root = new ProcessingNode <SwitchBase>(connection.ToInputOutput.Origin, connection)
                };

                tree.UpdateConnections(project.ConnectionsForCompilation);
                tree.Root.Value.OnRegisterEvents(tree, RenderingEngine);

                var current = tree.Root;
                ResolveTree(tree, current, current);

                tree.Started  -= ProcessingTreeOnStarted;
                tree.Started  += ProcessingTreeOnStarted;
                tree.Finished -= ProcessingTreeOnFinished;
                tree.Finished += ProcessingTreeOnFinished;

                Items.Add(tree);
            }

            OnCompileFinished();
        }
コード例 #2
0
        private void ResolveData(ProcessingTree <SwitchBase> root, ProcessingNode <SwitchBase> start, ProcessingNode <SwitchBase> node)
        {
            var items =
                root.ConnectionsForCompilation.Where(x => !(x.ToInputOutput.InputOutput.Signature is ActionSignature))
                .OrderBy(x => x.ToInputOutput.InputOutputId);

            foreach (var c in items) // sorgt für korrekte reihenfolge
            {
                if (node.Value == c.FromInputOutput.Origin)
                {
                    var nextNode = new ProcessingNode <SwitchBase>(c.ToInputOutput.Origin, c, true);

                    if (node.Previous.Count == 0)
                    {
                        nextNode.NextData.Add(node);
                    }

                    node.PreviousData.Add(nextNode);

                    if (!start.ChainedNodes.Contains(nextNode.Value.Id) && c.ToInputOutput.Origin != start.Value)
                    {
                        start.ChainedNodes.Add(nextNode.Value.Id);
                        ResolveData(root, start, nextNode);
                    }
                }
            }
        }
コード例 #3
0
        public void Run(Engine renderingEngine, ProcessingTree <SwitchBase> processingTree)
        {
            CancellationTokenSource tokenSource = new CancellationTokenSource();

            processingTree.CancellationTokenSource = tokenSource;

            Task.Run(() =>
            {
                Processor processor = null;
                try
                {
                    processor = new Processor(renderingEngine, tokenSource);


                    processingTree.IsActive = true;
                    processingTree.OnStarted();

                    do
                    {
                        processingTree.Process(processor, renderingEngine);
                    } while (processor.Restarting && !tokenSource.IsCancellationRequested);
                }
                catch (TaskCanceledException)
                {
                    processingTree.IsActive = false;
                    processingTree.OnFinished();
                }
                catch (Exception ex)
                {
                    if (processor != null)
                    {
                        ExceptionEntry entry = new ExceptionEntry {
                            Exception = ex, Step = processor.Step, Node = processor.CurrentNode, Tree = processingTree
                        };
                        processor.CurrentNode.Value.CleanUp(processor, processor.CurrentNode);
                        Errors.Add(entry);
                        OnErrorAdded(new ExceptionEntryEventArgs {
                            ExceptionEntry = entry
                        });
                    }
                }
                finally
                {
                    processingTree.IsActive = false;
                    processingTree.OnFinished();
                }
            }, tokenSource.Token);
        }
コード例 #4
0
        private void ResolveTree(ProcessingTree <SwitchBase> root, ProcessingNode <SwitchBase> start, ProcessingNode <SwitchBase> node)
        {
            ResolveData(root, node, node);
            BacktrackData(node, node, RenderingEngine, 0);

            var items =
                root.ConnectionsForCompilation.Where(x => x.ToInputOutput.InputOutput.Signature is ActionSignature)
                .OrderBy(x => x.ToInputOutput.InputOutputId);

            foreach (var c in items) // sorgt für korrekte reihenfolge
            {
                if (node.Value == c.ToInputOutput.Origin)
                {
                    var nextNode = new ProcessingNode <SwitchBase>(c.FromInputOutput.Origin, c);
                    nextNode.Previous.Add(node);
                    node.Next.Add(nextNode);
                    node.OutputIndex = c.ToInputOutput.InputOutputId;
                    ResolveTree(root, start, nextNode);
                }
            }
        }