private void button7_Click(object sender, EventArgs e) { //bool bAdjInit = true; adjListLines = new List <string>(); using (OpenFileDialog ofd = new OpenFileDialog()) { if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { sAdjFileName = Path.GetFileNameWithoutExtension(ofd.FileName); using (FileStream fs = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (BufferedStream bs = new BufferedStream(fs)) { using (StreamReader sr = new StreamReader(bs)) { string line; int lineId = 1; while ((line = sr.ReadLine()) != null) { /* Add the line to the list reference */ adjListLines.Add(line); /* Break the line up into the definitions */ List <String> parameters = line.Split(new char[] { ',' }).ToList(); /* Parse the line */ if (parameters.Count > 1) { /* Initialise the adjacency list */ //if (bAdjInit) //{ // bAdjInit = false; // adj = new AdjacencyList<string>(parameters[0]); //} //for (int i = 1; i < parameters.Count; i++) //{ // adj.AddEdge(parameters[0], parameters[i]); //} /* Edges */ for (int i = 1; i < parameters.Count; i++) { adj.AddEdge(parameters[0], parameters[i], lineId); } /* Increment the line id */ lineId++; } } } } } /* Convert the adjacency list into a list of processes and channels */ Translator tl = new Translator(); if (radioButtonBroadcast.Checked) { tl.ParseGraphNeigbours(adj); commType = enCommType.Broadcasting; } else if (radioButtonSimplex.Checked) { tl.ParseGraphSimplex(adj); commType = enCommType.Simplex; } else if (radioButtonHalfDuplex.Checked) { tl.ParseGraphHalfDuplex(adj); commType = enCommType.HalfDuplex; } else { tl.ParseGraphP2P(adj); } nodeList = tl.NodeList; channelList = tl.ChannelList; modelTraces = new List <List <string> >(); } } }
private void buttonLoad_Click(object sender, EventArgs e) { try { /* Clear all variables */ sAdjFileName = String.Empty; modelFile = String.Empty; adj = new EdgeList(); modelTraces = new List <List <string> >(); adjListLines = new List <string>(); nodeList = new List <Node>(); richTextBoxOutput.Clear(); bool bFirstLine = true; adjListLines = new List <string>(); using (OpenFileDialog ofd = new OpenFileDialog()) { if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { sAdjFileName = Path.GetFileNameWithoutExtension(ofd.FileName); toolStripStatusLabelFileName.Text = Path.GetFileName(ofd.FileName); using (FileStream fs = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (BufferedStream bs = new BufferedStream(fs)) { using (StreamReader sr = new StreamReader(bs)) { string line; int lineId = 1; while ((line = sr.ReadLine()) != null) { /* Remove all leading and trailing white spaces */ line = line.Trim(); /* Add the line to the list reference */ adjListLines.Add(line); /* Determine the type of synchronisation. Here we are looking for '(' or '{' */ if (bFirstLine) { bFirstLine = false; if (!String.IsNullOrEmpty(line)) { if (line[0] == '(') { if (line.Length == 5) { commType = enCommType.Simplex; } else { commType = enCommType.Broadcasting; } } else if (line[0] == '{') { commType = enCommType.HalfDuplex; } } } /* Break the line up into the definitions, removing the leading and trailing synchronisation selector characters */ List <String> parameters = line.Trim().Trim(new char[] { '(', ')', '{', '}' }).Split(new char[] { ',' }).ToList(); /* Parse the line */ if (parameters.Count > 1) { /* Edges */ for (int i = 1; i < parameters.Count; i++) { adj.AddEdge(parameters[0], parameters[i], lineId); } /* Increment the line id */ lineId++; } } } } } /* Convert the adjacency list into a list of processes and channels */ Translator tl = new Translator(); switch (commType) { case enCommType.Broadcasting: radioButtonBroadcast.Checked = true; tl.ParseGraphNeigbours(adj); break; case enCommType.Simplex: radioButtonSimplex.Checked = true; tl.ParseGraphSimplex(adj); break; case enCommType.HalfDuplex: radioButtonHalfDuplex.Checked = true; tl.ParseGraphHalfDuplex(adj); break; default: break; } nodeList = tl.NodeList; ClearInput(); } } } catch (Exception ex) { MessageBox.Show("An error occurred while parsing the in input file, please check that file is in the correct format", "Input File Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }