Beispiel #1
0
 public void Stop(bool web)
 {
     TrimBot.Abort();
     ManageBot.Abort();
     if (web)
     {
         WebBot.Abort();
     }
 }
Beispiel #2
0
        private void manageTrimmers()
        {
            if (DoTrim)
            {
                TrimBot = new Thread(new ThreadStart(trimData));
            }
            else
            {
                TrimBot = new Thread(new ThreadStart(createxyz));
            }
            TrimBot.Start();
            while (Properties.Settings.Default.progress < 100)
            {
                Thread.Sleep(2000);
                if (!TrimBot.IsAlive)
                {
                    TrimBot.Abort();
                    if (DoTrim)
                    {
                        TrimBot = new Thread(new ThreadStart(trimData));
                    }
                    else
                    {
                        TrimBot = new Thread(new ThreadStart(createxyz));
                    }
                    CurrentFile = Properties.Settings.Default.progress;
                    TrimBot.Start();
                }

                /*if (!WebBot.IsAlive)
                 * {
                 *  WebBot.Abort();
                 *  WebBot = new Thread(new ThreadStart(httplisten));
                 *  WebBot.Start();
                 * }*/
            }
        }
Beispiel #3
0
        private void trimData()
        {
            Timer.Reset();
            Timer.Start();
            string[] files = Directory.GetFiles("C:\\Diplomarbeit_Geoelektrik\\daten_mit_topography\\");
            Process  p     = checkForProcess("RES2DINV_3.59.118");

            if (p == null)
            {
                p = Process.Start("C:\\Diplomarbeit_Geoelektrik\\daten von usb-stick\\RES2DINV_3.59.118.exe");
            }
            try
            {
                Thread.Sleep(500);
                IntPtr res2dHandle = p.MainWindowHandle;
                ShowWindow(res2dHandle, SW_MAXIMIZE);                                                  //show window maximized

                SetForegroundWindow(SleepHelper.WaitForWindow(BASIC_INTERVAL, "System Resources", 5)); //set focus to start dialog and wait for it
                InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                //change settings: read inversion parameters from .inv
                InputSimulator.SimulateKeyPress(VirtualKeyCode.MENU);
                InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                InputSimulator.SimulateKeyPress(VirtualKeyCode.UP);
                InputSimulator.SimulateKeyPress(VirtualKeyCode.UP);
                InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                InputSimulator.SimulateTextEntry("C:\\Diplomarbeit_Geoelektrik\\daten von usb-stick\\Gresten Modelblock-fix.ivp");
                InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                for (int i = CurrentFile; i < files.Length; i++) //run through all files in given directory from startAtFile to endAtFile
                {
                    if (!Timer.IsRunning)
                    {
                        Timer.Reset();
                        Timer.Start();
                    }
                    TaskbarProgress.SetValue(MainHandle, CurrentFile, files.Length - 1); //progress on taskbar
                    if (i % 6 == 0 && restart)
                    {
                        throw new RestartException(i);
                    }
                    else
                    {
                        restart = true;
                    }

                    if (StopAtNext)
                    {
                        StopAtNext = false;
                        ManageBot.Abort();
                        Stop(false);
                    }
                    MyConsole.WriteLine("#" + i + " started.");

                    //files to be saved
                    string invfilename = SAVETOINV + files[i].Split('.')[0].Split('\\').Last() + ".inv"; //Split for filename and add .inv
                    string datfilename = SAVETOTRIM + files[i].Split('\\').Last();                       //Split for filename

                    //if already exist, delete
                    if (File.Exists(invfilename))
                    {
                        MyConsole.WriteLine("#" + i + " (" + invfilename.Split('\\').Last() + ") existed, so it was removed.");
                        File.Delete(invfilename);
                    }
                    if (File.Exists(datfilename))
                    {
                        Console.WriteLine("#" + i + " (" + datfilename.Split('\\').Last() + ") existed, so it was removed.");
                        File.Delete(datfilename);
                    }

                    //read .dat file
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.MENU);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.DOWN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    SleepHelper.WaitForWindow(BASIC_INTERVAL, "Input 2D resistivity data file", 5);
                    InputSimulator.SimulateTextEntry(files[i]);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    SetForegroundWindow(SleepHelper.WaitForWindow(BASIC_INTERVAL, "Message", 5));
                    if (SleepHelper.CheckForWindow(new string[] { "Data Error", "Convergence Warning" }))
                    {
                        MyConsole.WriteLine("#" + i + " skipped due to error.");
                        CurrentFile = i + 1;
                        Properties.Settings.Default.progress = i + 1;
                        Properties.Settings.Default.Save();
                        throw new NotIntendedException(i, "Data Error or RMS error too high.");
                    }
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                    /*SetForegroundWindow(SleepHelper.WaitForWindow(BASIC_INTERVAL, "Incomplete Gauss-Newton method", 5));
                     * Thread.Sleep(150);
                     * //check
                     * if (!SleepHelper.GetActiveWindowTitle().Contains("Incomplete Gauss-Newton method"))
                     * {
                     *  throw new NotIntendedException(i, "Read .dat file");
                     * }*/
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                    //least squares inversion
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.MENU);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.DOWN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    Thread.Sleep(1000);
                    SleepHelper.WaitForWindow(BASIC_INTERVAL, "File Name for Inversion Results", 5);
                    InputSimulator.SimulateTextEntry(invfilename);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    SetForegroundWindow(SleepHelper.WaitForWindow(BASIC_INTERVAL, "Enter Additional Iterations", 1400));
                    if (SleepHelper.CheckForWindow(new string[] { "Data Error", "Convergence Warning" }))
                    {
                        MyConsole.WriteLine("#" + i + " skipped due to error.");
                        CurrentFile = i + 1;
                        Properties.Settings.Default.progress = i + 1;
                        Properties.Settings.Default.Save();
                        throw new NotIntendedException(i, "Data Error or RMS error too high.");
                    }
                    InputSimulator.SimulateTextEntry("0");
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    Thread.Sleep(150);
                    SleepHelper.WaitForCursor(BASIC_INTERVAL, Cursors.Arrow); //window has a slight delay
                    Thread.Sleep(150);

                    //check if everything went right
                    if (!File.Exists(invfilename))
                    {
                        throw new NotIntendedException(i, "Least squares inversion: File not generated");
                    }

                    //display - show results
                    Thread.Sleep(150);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.MENU);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.DOWN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                    //edit data - rms statistics
                    SetForegroundWindow(SleepHelper.WaitForWindow(BASIC_INTERVAL, "Message", 5));
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.MENU);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.DOWN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                    IntPtr test2 = SleepHelper.WaitForWindow(BASIC_INTERVAL, "RMS Error Analysis Window", 5);
                    SetForegroundWindow(test2);
                    Thread.Sleep(300);

                    //check if everything went right
                    if (!SleepHelper.GetActiveWindowTitle().Contains("RMS Error Analysis Window"))
                    {
                        throw new NotIntendedException(i, "Edit data - RMS statistics");
                    }

                    for (int redo = 0; redo < 26; redo++)
                    {
                        InputSimulator.SimulateKeyPress(VirtualKeyCode.LEFT);
                        Thread.Sleep(10);
                    }

                    //trim data
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.MENU);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.DOWN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN); //exit
                    Thread.Sleep(30);
                    SetForegroundWindow(SleepHelper.WaitForWindow(BASIC_INTERVAL, "Trim data set", 5));
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN); //trim data?
                    Thread.Sleep(30);
                    SetForegroundWindow(SleepHelper.WaitForWindow(BASIC_INTERVAL, "Message", 5));
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN); //to trim you need to save
                    Thread.Sleep(100);
                    ShowWindow(res2dHandle, SW_MINIMIZE);                   //minimize maximize, to work around a bug (otherwise filesave dialog does not appear)
                    Thread.Sleep(250);
                    ShowWindow(res2dHandle, SW_MAXIMIZE);
                    SetForegroundWindow(SleepHelper.WaitForWindow(BASIC_INTERVAL, "Output edited data file", 5));
                    InputSimulator.SimulateTextEntry(datfilename);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                    Thread.Sleep(1000); //file needs some time until it is saved
                    //check if everything is right
                    if (!File.Exists(datfilename))
                    {
                        throw new NotIntendedException(i, "Trim data: File not generated");
                    }

                    //close display window
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.MENU);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.UP);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.UP);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT); //change output path? NO. (sometimes not needed)
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                    MyConsole.WriteLine("#" + i + " finished.");
                    //update progress
                    CurrentFile = i + 1;
                    Properties.Settings.Default.progress = i + 1; //progress in settings
                    Properties.Settings.Default.Save();
                    Timer.Stop();
                    TimeIntervals.Add(Timer.ElapsedMilliseconds);
                }
            }
            catch (RestartException rsexc)
            {
                restart = false;
                MyConsole.WriteLine(rsexc);
                p.Kill();
                p.Close();
                TrimBot.Abort();
            }
            catch (ThreadAbortException taexc)
            {
                restart = false;
                MyConsole.WriteLine("#" + Properties.Settings.Default.progress + ": Trimbot aborted.");
                Timer.Stop();
            }
            catch (NotIntendedException niexc)
            {
                restart = false;
                MyConsole.WriteLine(niexc);
                Crashes++;
                p.Kill();
                p.Close();
                TrimBot.Abort();
            }
            catch (Exception exc)
            {
                restart = false;
                MyConsole.WriteLine("#" + Properties.Settings.Default.progress + ":\n" + exc);
                Crashes++;
                p.Kill();
                p.Close();
                TrimBot.Abort();
            }
        }
Beispiel #4
0
        private void createxyz()
        {
            Timer.Reset();
            Timer.Start();
            string[] files = Directory.GetFiles("C:\\Diplomarbeit_Geoelektrik\\daten_trimmed\\");
            Process  p     = checkForProcess("RES2DINV_3.59.118");

            if (p == null)
            {
                p = Process.Start("C:\\Diplomarbeit_Geoelektrik\\daten von usb-stick\\RES2DINV_3.59.118.exe");
            }
            try
            {
                Thread.Sleep(500);
                IntPtr res2dHandle = p.MainWindowHandle;
                ShowWindow(res2dHandle, SW_MAXIMIZE);                                                  //show window maximized

                SetForegroundWindow(SleepHelper.WaitForWindow(BASIC_INTERVAL, "System Resources", 5)); //set focus to start dialog and wait for it
                InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                //change settings: read inversion parameters from .inv
                InputSimulator.SimulateKeyPress(VirtualKeyCode.MENU);
                InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                InputSimulator.SimulateKeyPress(VirtualKeyCode.UP);
                InputSimulator.SimulateKeyPress(VirtualKeyCode.UP);
                InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                InputSimulator.SimulateTextEntry("C:\\Diplomarbeit_Geoelektrik\\daten von usb-stick\\Gresten Modelblock-fix.ivp");
                InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                for (int i = CurrentFile; i < files.Length; i++) //run through all files in given directory from startAtFile to endAtFile
                {
                    if (!Timer.IsRunning)
                    {
                        Timer.Reset();
                        Timer.Start();
                    }
                    TaskbarProgress.SetValue(MainHandle, CurrentFile, files.Length - 1); //progress on taskbar

                    if (StopAtNext)
                    {
                        StopAtNext = false;
                        ManageBot.Abort();
                        Stop(false);
                    }
                    MyConsole.WriteLine("#" + i + " started.");

                    //files to be saved
                    string invtrimfilename = SAVETOTRIMINV + files[i].Split('.')[0].Split('\\').Last() + ".inv"; //Split for filename and add .inv
                    string xyzfilename     = SAVETOXYZ + files[i].Split('.')[0].Split('\\').Last() + ".xyz";     //Split for filename and add .xyz

                    //if already exist, delete
                    if (File.Exists(invtrimfilename))
                    {
                        MyConsole.WriteLine("#" + i + " (" + invtrimfilename.Split('\\').Last() + ") existed, so it was removed.");
                        File.Delete(invtrimfilename);
                    }
                    if (File.Exists(xyzfilename))
                    {
                        Console.WriteLine("#" + i + " (" + xyzfilename.Split('\\').Last() + ") existed, so it was removed.");
                        File.Delete(xyzfilename);
                    }

                    //read .dat file
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.MENU);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.DOWN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    SleepHelper.WaitForWindow(BASIC_INTERVAL, "Input 2D resistivity data file", 5);
                    InputSimulator.SimulateTextEntry(files[i]);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    SetForegroundWindow(SleepHelper.WaitForWindow(BASIC_INTERVAL, "Message", 5));
                    if (SleepHelper.CheckForWindow(new string[] { "Data Error", "Convergence Warning" }))
                    {
                        MyConsole.WriteLine("#" + i + " skipped due to error.");
                        CurrentFile = i + 1;
                        Properties.Settings.Default.progress = i + 1;
                        Properties.Settings.Default.Save();
                        throw new NotIntendedException(i, "Data Error or RMS error too high.");
                    }
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                    //least squares inversion
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.MENU);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.DOWN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    SetForegroundWindow(SleepHelper.WaitForWindow(BASIC_INTERVAL, "File Name for Inversion Results", 5));
                    Thread.Sleep(1500);
                    InputSimulator.SimulateTextEntry(invtrimfilename);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    SetForegroundWindow(SleepHelper.WaitForWindow(BASIC_INTERVAL, "Enter Additional Iterations", 2000));
                    if (SleepHelper.CheckForWindow(new string[] { "Data Error", "Convergence Warning" }))
                    {
                        MyConsole.WriteLine("#" + i + " skipped due to error.");
                        CurrentFile = i + 1;
                        Properties.Settings.Default.progress = i + 1;
                        Properties.Settings.Default.Save();
                        throw new NotIntendedException(i, "Data Error or RMS error too high.");
                    }
                    InputSimulator.SimulateTextEntry("0");
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    Thread.Sleep(150);
                    SleepHelper.WaitForCursor(BASIC_INTERVAL, Cursors.Arrow); //window has a slight delay
                    Thread.Sleep(150);

                    //check if everything went right
                    if (!File.Exists(invtrimfilename))
                    {
                        throw new NotIntendedException(i, "Least squares inversion: File not generated");
                    }

                    //display - show results
                    Thread.Sleep(150);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.MENU);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.DOWN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                    //save xyz
                    Thread.Sleep(2000);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.MENU);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.DOWN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.DOWN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                    SetForegroundWindow(SleepHelper.WaitForWindow(BASIC_INTERVAL, "Choose iteration number", 5));
                    Thread.Sleep(150);
                    if (!SleepHelper.CheckForWindow(new string[] { "Choose iteration number" }))
                    {
                        throw new NotIntendedException(i, "Iteration number selection failed");
                    }

                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    Thread.Sleep(150);
                    InputSimulator.SimulateTextEntry(xyzfilename);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                    SetForegroundWindow(SleepHelper.WaitForWindow(BASIC_INTERVAL, "Message", 5));
                    if (!SleepHelper.CheckForWindow(new string[] { "Message" }))
                    {
                        throw new NotIntendedException(i, "Save .xyz: No Message Window");
                    }

                    //close display window
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.MENU);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.UP);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.UP);
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                    Thread.Sleep(1000); //file needs some time until it is saved
                    //check if everything is right
                    if (!File.Exists(xyzfilename))
                    {
                        throw new NotIntendedException(i, "Save .xyz: File not generated");
                    }

                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT); //change output path? NO. (sometimes not needed)
                    InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

                    MyConsole.WriteLine("#" + i + " finished.");
                    //update progress
                    CurrentFile = i + 1;
                    Properties.Settings.Default.progress = i + 1; //progress in settings
                    Properties.Settings.Default.Save();
                    Timer.Stop();
                    TimeIntervals.Add(Timer.ElapsedMilliseconds);

                    throw new RestartException(i);
                }
            }
            catch (RestartException rsexc)
            {
                p.Kill();
                p.Close();
                TrimBot.Abort();
            }
            catch (NotIntendedException niexc)
            {
                MyConsole.WriteLine(niexc);
                Crashes++;
                p.Kill();
                p.Close();
                TrimBot.Abort();
            } catch (ThreadAbortException taexc)
            {
                MyConsole.WriteLine("#" + Properties.Settings.Default.progress + ": Trimbot aborted.");
                Timer.Stop();
            }
            catch (Exception exc)
            {
                MyConsole.WriteLine("#" + Properties.Settings.Default.progress + ":\n" + exc);
                Crashes++;
                p.Kill();
                p.Close();
                TrimBot.Abort();
            }
        }