//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); }
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); } try { if (!Nodes.All(n => n.PrepareProcessing())) { return(false); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine($"Graph.Run Exception: {e}"); return(false); } OsClock.Start(); Nodes.ForEach(n => n.StartProcessing()); State = Status.Running; foreach (var dev in _devices) { if (HasActivePorts(dev) && !dev.StartSampling()) { Stop(); return(false); } } return(true); }
public void Stop() { lock (this) { if (State == Status.Stopped) { return; } Func <Node, bool> HasNoOutputConnections = (n) => n.OutputPorts.Count(p => p.Connections.Count > 0) == 0; Func <Node, bool> HasNoInputConnections = (n) => n.InputPorts.Count(p => p.Connection != null) == 0; if (State == Status.Stopped) { return; } Devices.Where(HasActivePorts).ForEach(n => n.StopSampling()); // 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>(); // 3. Breitensuche mit Node Suspend BFS( nodeQueue, visited, (node) => { System.Diagnostics.Debug.WriteLine($"Wait for {node.Name}"); node.SuspendProcessing(); }, NodesReachableByOutput ); // 4. Hole Liste mit Endpunkten für Vorgängerknoten var lastNodes = Nodes.Where(HasNoOutputConnections); // 5. Flush von hinten nach vorne (Breitensuche rückwärts) // 6. Falls Daten erzeugt wurden, gehe zu 5. bool reflush; do { if (nodeQueue.Any()) { throw new InvalidOperationException("Queue muss an diesem Punkt leer sein!"); } lastNodes.ForEach(nodeQueue.Enqueue); visited.Clear(); reflush = false; BFS( nodeQueue, visited, (node) => { reflush |= (node.FlushData() == Node.FlushState.Some); }, NodesReachableByInput ); } while (reflush); // 7. Alle Nodes stoppen (State reset) Nodes.ForEach(n => n.StopProcessing()); // Vielleicht nicht so gut, weil eventuell Threads noch fertiglaufen müssen? // Garantie, dass Nodes alle gestoppt sind? OsClock.Stop(); RunCount++; _setWriter = null; State = Status.Stopped; } }