Esempio n. 1
0
 private void UnmarkSimulationParticpants()
 {
     while (SimulationMarkedNodes.Count > 0)
     {
         var node = SimulationMarkedNodes.Pop();
         node.Color = Colors.Black;
     }
     while (SimulationMarkedEdges.Count > 0)
     {
         var edge = SimulationMarkedEdges.Pop();
         edge.Color = Colors.Black;
     }
 }
Esempio n. 2
0
        private void simulation_Execute(object sender, ExecuteEventArgs e)
        {
            UnmarkSimulationParticpants();

            foreach (var tuple in e.Tuples)
            {
                int sourceId = tuple.Item1;
                int destId   = tuple.Item2;

                if (!NodeIdMap.ContainsKey(sourceId) || !NodeIdMap.ContainsKey(destId))
                {
                    continue;
                }

                Node source = null, dest = null;
                NodeIdMap.TryGetValue(sourceId, out source);
                NodeIdMap.TryGetValue(destId, out dest);

                Edge        connector = null;
                List <Edge> edges;
                Nodes.TryGetValue(source, out edges);
                foreach (var edge in edges)
                {
                    if (edge.SourceNode == dest || edge.DestinationNode == dest)
                    {
                        connector = edge;
                        break;
                    }
                }

                if (connector == null)
                {
                    MessageBox.Show(String.Format("There is no edge connecting nodes with ids \"{0}\" and \"{1}\"", sourceId, destId), "Error",
                                    System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                    continue;
                }

                if (source == SimulationServerNode)
                {
                    MessageBox.Show("Server node can't send information!", "Error",
                                    System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                    continue;
                }

                List <int> sourceData;
                SimulationData.TryGetValue(sourceId, out sourceData);
                if (sourceData.Count == 0)
                {
                    MessageBox.Show(String.Format("Node with id \"{0}\" doesn't have any information to send", sourceId), "Error",
                                    System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                    continue;
                }

                List <int> destData;
                SimulationData.TryGetValue(destId, out destData);

                var data = sourceData[sourceData.Count - 1];
                sourceData.RemoveAt(sourceData.Count - 1);
                destData.Add(data);

                dest.Color      = MarkerColor;
                connector.Color = MarkerColor;
                SimulationMarkedNodes.Push(dest);
                SimulationMarkedEdges.Push(connector);

                // move data
            }
        }