コード例 #1
0
        public Dictionary <Node, NodeState> SaveState()
        {
            if (State == Status.Running)
            {
                _processor.CompleteProcessing();
                _processor.Stop();
            }

            // ok, save states
            var states = new Dictionary <Node, NodeState>();

            foreach (var node in Nodes)
            {
                var state = node.SaveState();
                if (state != null)
                {
                    states.Add(node, state);
                }
            }

            if (State == Status.Running)
            {
                _processor = new GraphProcessor(this);
                _processor.Start();
            }

            return(states);
        }
コード例 #2
0
        //public bool AddRecord(Recording rec) {
        //    lock (_writerLock) {
        //        if (_setWriter == null) {
        //            var file = "index.lst";
        //            var path = System.IO.Path.Combine(BaseDirectory, WorkingDirectory, file);

        //            try {
        //                _setWriter = new RecordSetWriter(path);
        //            } catch (Exception) {
        //                return false;
        //            }
        //        }

        //        _setWriter.AddRecord(rec);
        //        return true;
        //    }
        //}

        public bool Run()
        {
            if (State == Status.Running)
            {
                return(true);
            }

            var workingDirRel = WorkingDirectoryMask.Replace("%count%", RunCount.ToString());

            WorkingDirectory = System.IO.Path.Combine(BaseDirectory, workingDirRel);

            while (System.IO.Directory.Exists(WorkingDirectory))
            {
                RunCount++;
                workingDirRel    = WorkingDirectoryMask.Replace("%count%", RunCount.ToString());
                WorkingDirectory = System.IO.Path.Combine(BaseDirectory, workingDirRel);
            }

            // 1. Hole Liste von Device Nodes
            var devNodes = Nodes.Where(HasNoInputConnections);

            // 2. Erstelle Queue mit Verknüpfungszielen
            var nodeQueue = new Queue <Node>();

            devNodes.ForEach(nodeQueue.Enqueue);

            var visited = new List <Node>();

            try {
                BFS(
                    nodeQueue,
                    visited,
                    (node) => {
                    if (!node.PrepareProcessing())
                    {
                        throw new OperationCanceledException();
                    }
                },
                    NodesReachableByOutput
                    );
            } catch (OperationCanceledException) {
                return(false);
            } catch (Exception e) {
                System.Diagnostics.Debug.WriteLine($"Graph.Run Exception: {e}");
                return(false);
            }

            OsClock.Start();
            SynchronizeClock(TimeStamp.Zero());

            _processor = new GraphProcessor(this);
            _processor.Start();

            Nodes.ForEach(n => n.StartProcessing());

            State = Status.Running;

            return(true);
        }
コード例 #3
0
        public void LoadState(Dictionary <Node, NodeState> states)
        {
            if (State == Status.Running)
            {
                _processor.CompleteProcessing();
                _processor.Stop();
            }

            // ok, load states
            foreach (var node in Nodes)
            {
                if (states.ContainsKey(node))
                {
                    node.LoadState(states[node]);
                }
            }

            if (State == Status.Running)
            {
                _processor = new GraphProcessor(this);
                _processor.Start();
            }
        }