private void TestDecisionTree_Click(object sender, RoutedEventArgs e) { //TestDecisionTreeEventHandler.Invoke(sender, e); var testSampels = dataController.TestSamples.Select(x => x.ToArray()).ToArray(); ListBoxLog.Items.Add($"Test Starting"); Task.Run(() => { decisionTreeController.TestDecisionTrees(DecisionTreeController.DecisionTreeModel, testSampels); Dispatcher.Invoke(new Action(() => { decisionTreeController .ResultTest .GroupBy(x => x) .Select(x => new { a = x.Key, b = x.Count() }) .GroupBy(x => x.a.Split("->".ToArray(), StringSplitOptions.None).First()) .OrderBy(x => x.Key) .ToList() .ForEach(x => { ListBoxLog.Items.Add(x.Key); x.ToList().ForEach(y => { ListBoxLog.Items.Add(y.a + " " + y.b); }); ListBoxLog.Items.Add(""); }); /*dataController.TestSamples.ForEach(x => * { * x.ForEach(y => Console.Write(y)); * Console.WriteLine(); * }); * * Console.WriteLine(dataController.Samples.Count()); * Console.WriteLine(dataController.TestSamples.Count()); * Console.WriteLine(DecisionTreeController.Node); * Console.WriteLine(decisionTreeController.ResultTest.Count(x => x.Contains("true")));*/ /*DecisionTreeController.Node = 0; * decisionTreeController.TestDecisionTrees(DecisionTreeController.DecisionTreeModel, dataController.TestSamples.Select(x => x.ToArray()).ToArray()); * * Console.WriteLine(DecisionTreeController.Node);*/ ListBoxLog.Items.Add(DecisionTreeController.Node / (double)dataController.TestSamples.Count()); ListBoxLog.Items.Add(""); var dateTimeEnd = DateTime.Now; //ListBoxLog.Items.Add($"{dataTimeStart} Build Starting"); ListBoxLog.Items.Add($"{dateTimeEnd} Test Finished"); ListBoxLog.SelectedIndex = ListBoxLog.Items.Count - 1; ListBoxLog.ScrollIntoView(ListBoxLog.SelectedItem); })); }); //var program = new Program(); //Console.WriteLine(program.Run(dataController.Samples, dataController.TestSamples)); }
void ReceiveCallback(IAsyncResult ar) { ClientSocket Socket = (ClientSocket)ar.AsyncState; int SelectedIndex = -1; if (listBoxClients.InvokeRequired) { listBoxClients.Invoke(new MethodInvoker(delegate { SelectedIndex = listBoxClients.SelectedIndex; })); } else { SelectedIndex = listBoxClients.SelectedIndex; } Socket s; if ((s = Socket.Sockets == null ? Socket.socket : (SelectedIndex >= 0 && SelectedIndex < Socket.Sockets.Count ? Socket.Sockets[SelectedIndex] : null)) == null) { return; } int bytesRead = s.EndReceive(ar); if (ListBoxLog.InvokeRequired) { ListBoxLog.Invoke(new MethodInvoker(delegate { ListBoxLog.Items.Add(string.Format("{0}.EndReceive()", Socket.Name)); })); } else { ListBoxLog.Invoke(new MethodInvoker(delegate { ListBoxLog.Items.Add(string.Format("{0}.EndReceive()", Socket.Name)); })); } if (bytesRead > 0) { Socket.sb.Append(Encoding.ASCII.GetString(Socket.buffer, 0, bytesRead)); if (s.Available > 0) { s.BeginReceive(Socket.buffer, 0, Socket.buffer.Length, 0, new AsyncCallback(ReceiveCallback), Socket); } else { if (Socket.sb.Length > 1) { string tmpString = Socket.sb.ToString(); Socket.sb.Length = 0; if (ListBoxLog.InvokeRequired) { ListBoxLog.Invoke(new MethodInvoker(delegate { ListBoxLog.Items.Add(string.Format("{0} (Received {1} bytes Data {2})", Socket.Name, tmpString.Length, tmpString)); })); } else { ListBoxLog.Items.Add(string.Format("{0} (Received {1} bytes Data {2})", Socket.Name, tmpString.Length, tmpString)); } } } } else { if (Socket.sb.Length > 1) { string tmpString = Socket.sb.ToString(); if (ListBoxLog.InvokeRequired) { ListBoxLog.Invoke(new MethodInvoker(delegate { ListBoxLog.Items.Add(string.Format("{0} (Received {1} bytes Data {2})", Socket.Name, tmpString.Length, tmpString)); })); } else { ListBoxLog.Items.Add(string.Format("{0} (Received {1} bytes Data {2})", Socket.Name, tmpString.Length, tmpString)); } } } }
//Clears the log in the listbox public void ClearLog() => ListBoxLog.Clear();
//Gives message to the listbox log private void AddMessage(string message) => Dispatcher.Invoke(() => ListBoxLog.Add(new ListBoxItem { Content = message }));
public static void Initialize(ListBox listBox) { LoggingObject = new ListBoxLog(listBox); }