Пример #1
0
 private void UpdateServerTextBox()
 {
     if (cbUseServers.IsChecked == true)
     {
         NeuronClient.GetServerList();
         Thread.Sleep(1000);
         if (NeuronClient.serverList.Count == 0)
         {
             ServerList.Text           = "No Servers Detected";
             buttonSpeedTest.IsEnabled = false;
         }
         else
         {
             int.TryParse(textBoxColumns.Text, out cols);
             int.TryParse(textBoxRows.Text, out rows);
             ServerList.Text       = "";
             MainWindow.useServers = true;
             int numServers    = NeuronClient.serverList.Count;
             int neuronsNeeded = rows * cols;
             for (int i = 0; i < numServers; i++)
             {
                 NeuronClient.Server s = NeuronClient.serverList[i];
                 s.firstNeuron    = i * neuronsNeeded / numServers;
                 s.lastNeuron     = (i + 1) * neuronsNeeded / numServers;
                 ServerList.Text += s.ipAddress.ToString() + " " + s.name + " " + s.firstNeuron + " " + s.lastNeuron + "\n";
             }
             buttonSpeedTest.IsEnabled = true;
         }
     }
     else
     {
         ServerList.Text = "";
     }
 }
Пример #2
0
        private void ButtonOK_Click(object sender, RoutedEventArgs e)
        {
            bool previousShowSynapses = false;

            if (MainWindow.theNeuronArray != null)
            {
                previousShowSynapses = MainWindow.theNeuronArray.ShowSynapses;
            }
            MainWindow.CloseAllModuleDialogs();
            MainWindow.CloseHistoryWindow();
            MainWindow.CloseNotesWindow();
            MainWindow.arrayView.ClearShowingSynapses();
            if (MainWindow.theNeuronArray != null)
            {
                lock (MainWindow.theNeuronArray.Modules)
                {
                    MainWindow.theNeuronArray.Modules.Clear();
                }
            }
            MainWindow.arrayView.ClearSelection();
            MainWindow.theNeuronArray = new NeuronArray();

            if (!int.TryParse(textBoxColumns.Text, out cols))
            {
                return;
            }
            if (!int.TryParse(textBoxRows.Text, out rows))
            {
                return;
            }
            if (cols <= 0)
            {
                return;
            }
            if (rows <= 0)
            {
                return;
            }
            //if (checkBoxSynapses.IsChecked == true) doSynapses = true;
            if (!int.TryParse(Refractory.Text, out refractory))
            {
                return;
            }

            arraySize = rows * cols;
            //progressBar.Maximum = arraySize;

            //int.TryParse(textBoxSynapses.Text, out synapsesPerNeuron);
            MainWindow.arrayView.Dp.NeuronDisplaySize = 62;
            MainWindow.arrayView.Dp.DisplayOffset     = new Point(0, 0);

            if (MainWindow.useServers && NeuronClient.serverList.Count > 0)
            {
                //TODO: Replace this with a multicolumn UI
                MainWindow.theNeuronArray.Initialize(arraySize, rows);
                string[] lines = ServerList.Text.Split('\n');
                NeuronClient.serverList.Clear();
                foreach (string line in lines)
                {
                    if (line == "")
                    {
                        continue;
                    }
                    string[]            command = line.Split(' ');
                    NeuronClient.Server s       = new NeuronClient.Server();
                    s.ipAddress = IPAddress.Parse(command[0]);
                    s.name      = command[1];
                    int.TryParse(command[2], out s.firstNeuron);
                    int.TryParse(command[3], out s.lastNeuron);
                    NeuronClient.serverList.Add(s);
                }

                int totalNeuronsInServers = 0;
                for (int i = 0; i < NeuronClient.serverList.Count; i++)
                {
                    totalNeuronsInServers += NeuronClient.serverList[i].lastNeuron - NeuronClient.serverList[i].firstNeuron;
                }
                if (totalNeuronsInServers != arraySize)
                {
                    MessageBox.Show("Server neuron allocation does not equal total neurons!");
                    buttonOK.IsEnabled = true;
                    returnValue        = false;
                    return;
                }

                NeuronClient.InitServers(0, arraySize);
                NeuronClient.WaitForDoneOnAllServers();
                returnValue = true;
                Close();
                returnValue = true;
            }
            else
            {
                GC.Collect(3, GCCollectionMode.Forced, true);
                MainWindow.theNeuronArray.Initialize(arraySize, rows);
                MainWindow.theNeuronArray.RefractoryDelay = refractory;

                MainWindow.theNeuronArray.ShowSynapses = previousShowSynapses;
                MainWindow.thisWindow.SetShowSynapsesCheckBox(previousShowSynapses);
                Close();
                returnValue = true;
            }
            MainWindow.theNeuronArray.LoadComplete = true;
        }
Пример #3
0
        private void ButtonOK_Click(object sender, RoutedEventArgs e)
        {
            buttonOK.IsEnabled = false;
            MainWindow.CloseAllModuleDialogs();
            MainWindow.CloseHistoryWindow();
            MainWindow.CloseNotesWindow();
            if (MainWindow.theNeuronArray != null)
            {
                MainWindow.theNeuronArray.Modules.Clear();
            }
            MainWindow.arrayView.ClearSelection();
            MainWindow.theNeuronArray = new NeuronArray();

            if (!int.TryParse(textBoxColumns.Text, out cols))
            {
                return;
            }
            if (!int.TryParse(textBoxRows.Text, out rows))
            {
                return;
            }
            if (checkBoxSynapses.IsChecked == true)
            {
                doSynapses = true;
            }

            arraySize           = rows * cols;
            progressBar.Maximum = arraySize;

            int.TryParse(textBoxSynapses.Text, out synapsesPerNeuron);
            MainWindow.arrayView.Dp.NeuronDisplaySize = 62;
            MainWindow.arrayView.Dp.DisplayOffset     = new Point(0, 0);

            if (MainWindow.useServers)
            {
                //TODO: Replace this with a multicolumn UI
                MainWindow.theNeuronArray.Initialize(arraySize, rows);
                string[] lines = ServerList.Text.Split('\n');
                NeuronClient.serverList.Clear();
                foreach (string line in lines)
                {
                    if (line == "")
                    {
                        continue;
                    }
                    string[]            command = line.Split(' ');
                    NeuronClient.Server s       = new NeuronClient.Server();
                    s.ipAddress = IPAddress.Parse(command[0]);
                    s.name      = command[1];
                    int.TryParse(command[2], out s.firstNeuron);
                    int.TryParse(command[3], out s.lastNeuron);
                    NeuronClient.serverList.Add(s);
                }

                int totalNeuronsInServers = 0;
                for (int i = 0; i < NeuronClient.serverList.Count; i++)
                {
                    totalNeuronsInServers += NeuronClient.serverList[i].lastNeuron - NeuronClient.serverList[i].firstNeuron;
                }
                if (totalNeuronsInServers != arraySize)
                {
                    MessageBox.Show("Server neuron allocation does not equal total neurons!");
                    buttonOK.IsEnabled = true;
                    returnValue        = false;
                    return;
                }

                if (!doSynapses)
                {
                    synapsesPerNeuron = 0;
                }
                NeuronClient.InitServers(synapsesPerNeuron, arraySize);
                NeuronClient.WaitForDoneOnAllServers();
                returnValue = true;
                Close();
            }
            else
            {
                bgw.DoWork += AsyncCreateNeurons;
                bgw.RunWorkerAsync();

                barUpdateTimer.Tick += Dt_Tick;
                barUpdateTimer.Start();
            }
        }