public static Cell Run( IHostContext hostContext, Action<IHostCommand> sendCommand, CellDefinition cellDefinition, SolutionHead deployment, string solutionName, CancellationToken cancellationToken) { var process = new Cell(hostContext, sendCommand, cellDefinition, deployment, solutionName, cancellationToken); process.Run(); return process; }
public static Cell Run( IHostContext hostContext, Action <IHostCommand> sendCommand, CellDefinition cellDefinition, SolutionHead deployment, string solutionName, CancellationToken cancellationToken) { var process = new Cell(hostContext, sendCommand, cellDefinition, deployment, solutionName, cancellationToken); process.Run(); return(process); }
void OnDeploymentChanged(SolutionHead newDeployment, SolutionDefinition newSolution, CancellationToken cancellationToken) { // 0. ANALYZE CELL LAYOUT CHANGES var removed = new Dictionary <string, Cell>(_cells); var added = new List <CellDefinition>(); var remaining = new List <CellDefinition>(); Dictionary <string, CellDefinition> old; if (_currentSolution == null || _currentSolution.SolutionName != newSolution.SolutionName) { // we do not reuse cells in completely unrelated solutions (i.e. solution name changed) _hostContext.Observer.TryNotify(() => new NewUnrelatedSolutionDetectedEvent(_hostContext.Identity, newDeployment, newSolution)); old = new Dictionary <string, CellDefinition>(); added.AddRange(newSolution.Cells); } else { // keep remaining cells (only touch cells that actually change in some way) _hostContext.Observer.TryNotify(() => new NewDeploymentOfSolutionDetectedEvent(_hostContext.Identity, newDeployment, newSolution)); old = _currentSolution.Cells.ToDictionary(cellDefinition => cellDefinition.CellName); foreach (var newCellDefinition in newSolution.Cells) { if (old.ContainsKey(newCellDefinition.CellName)) { removed.Remove(newCellDefinition.CellName); remaining.Add(newCellDefinition); } else { added.Add(newCellDefinition); } } } // 1. UPDATE _currentSolution = newSolution; _currentDeployment = newDeployment; // 2. REMOVE CELLS NO LONGER PRESENT foreach (var cell in removed) { _cells.Remove(cell.Key); cell.Value.Cancel(); } // 3. UPDATE CELLS STILL PRESENT foreach (var newCellDefinition in remaining) { var oldCellDefinition = old[newCellDefinition.CellName]; if (!newCellDefinition.Equals(oldCellDefinition)) { _cells[newCellDefinition.CellName].OnCellDefinitionChanged(newCellDefinition, newDeployment); } } // 4. ADD NEW CELLS foreach (var cellDefinition in added) { var cellName = cellDefinition.CellName; _cells.Add(cellName, Cell.Run(_hostContext, _commandQueue.Add, cellDefinition, newDeployment, newSolution.SolutionName, cancellationToken)); } }