Exemplo n.º 1
0
        void simulation_MarkServer(object sender, MarkServerEventArgs e)
        {
            Node serverNode;

            NodeIdMap.TryGetValue(e.Id, out serverNode);

            if (serverNode != null)
            {
                serverNode.Highlight = true;
                SimulationServerNode = serverNode;

                var nodeIds = GetNodeIds();
                foreach (var id in nodeIds)
                {
                    if (id == SimulationServerNode.Id)
                    {
                        SimulationData.Add(id, new List <int>());
                        continue;
                    }

                    var data = new List <int>();
                    data.Add(id);
                    SimulationData.Add(id, data);
                }
            }
        }
        private void start_Click(object sender, RoutedEventArgs e)
        {
            richTextBox.IsEnabled = false;
            startBtn.IsEnabled    = false;
            nextBtn.IsEnabled     = true;
            stopBtn.IsEnabled     = true;

            BlockCount = richTextBox.Document.Blocks.Count();
            if (BlockCount <= 1)
            {
                nextBtn.IsEnabled = false;
                return;
            }
            else if (BlockCount == 2)
            {
                nextBtn.IsEnabled = false;
            }

            CurrentBlockIndex = 0;

            {
                var enumerator = richTextBox.Document.Blocks.AsEnumerable().GetEnumerator();
                enumerator.MoveNext();
                CurrentBlock = enumerator.Current;
            }

            String blockText = GetBlockText(CurrentBlock);
            String regex     = "^0: server <- ([0-9]+)$";

            int    serverId     = -1;
            bool   error        = false;
            String errorMessage = "";

            Match match = Regex.Match(blockText, regex);

            if (match.Success && match.Groups.Count > 1)
            {
                Int32.TryParse(match.Groups[1].Value, out serverId);
                if (!NodeList.Contains(serverId))
                {
                    errorMessage = String.Format("Node with id \"{0}\" does not exist", serverId);
                    error        = true;
                }
            }
            else
            {
                error = true;
            }

            if (error)
            {
                SetupErrorState();
                ShowErrorMessage(errorMessage);
                return;
            }

            HighlightBlock(CurrentBlock, GreenHighlightBrush);

            MarkServerEventArgs args = new MarkServerEventArgs(serverId);

            MarkServer(this, args);
        }