Пример #1
0
        private static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            bool abort = false;
            // Check if we've already started the Manager
            bool isFirstInstance;

            // Please use a unique name for the mutex to prevent conflicts with other programs
            using (Mutex appMutex = new Mutex(true, "SugarCube_Manager", out isFirstInstance)) {
                if (!isFirstInstance)
                {
                    // The application is already running, so let's find its process id
                    Process me = Process.GetCurrentProcess();
                    foreach (Process process in Process.GetProcessesByName(me.ProcessName))
                    {
                        if (process.Id != me.Id)
                        {
                            // found it, let's switch over and then exit
                            Activate(process.MainWindowHandle);
                            abort = true;
                            break;
                        }
                    }
                }

                if (abort)
                {
                    return;
                }

                bool noOtherCubeUserIsRunning;
                // Make sure not other software that communicates with the cube is running, if it is, abort
                using (Mutex cubeMutex = new Mutex(true, "SugarCube_Interactor", out noOtherCubeUserIsRunning)) {
                    // Check if we're going to be using logging
                    string loggingConfigFile = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "3DWares"), "manager.lc.xml");
                    if (File.Exists(loggingConfigFile))
                    {
                        XmlConfigurator.Configure(new FileInfo(loggingConfigFile));
                    }

                    if (!noOtherCubeUserIsRunning)
                    {
                        if (log.IsErrorEnabled)
                        {
                            log.Error("The manager can not run if the test bed or test bed batch runner are open");
                        }

                        MessageBox.Show("The Manager can NOT be run while the test bed or batch runner are open", "UNABLE TO START TEST BED BATCH RUNNER",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        abort = true;
                    }


                    if (abort)
                    {
                        return;
                    }

                    //show splash
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Starting splash screen");
                    }

                    Thread splashThread = new Thread(new ThreadStart(
                                                         delegate {
                        splashScreen = new SplashScreen();
                        Application.Run(splashScreen);
                    }));

                    splashThread.SetApartmentState(ApartmentState.STA);
                    splashThread.Start();

                    MainForm theForm = null;
                    try {
                        theForm       = new MainForm();
                        theForm.Load += new EventHandler(OnMainFormLoaded);
                        Application.Run(theForm);
                    } catch (Exception ex) {
                        if (log.IsErrorEnabled)
                        {
                            log.Error("Fatal error while initializing the main form", ex);
                        }

                        ErrorDialog dlg = new ErrorDialog("SugarCube Manager", "A fatal error has occured while trying to initialize the application", "The SugarCube Manager will now close", ex.StackTrace);
                        dlg.ShowDialog();
                    }
                    if (splashScreen != null)
                    {
                        CloseSplashScreen();
                    }
                }         // release the cubeMutex
            }             //release the appMutex
        }
Пример #2
0
        private static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            bool abort = false;


            // Check if we've already started the Test Bed
            bool isFirstInstance;

            // Please use a unique name for the mutex to prevent conflicts with other programs
            using (Mutex appMutex = new Mutex(true, "SugarCube_TestBed", out isFirstInstance)) {
                if (!isFirstInstance)
                {
                    // The application is already running, so let's find its process id
                    Process me = Process.GetCurrentProcess();
                    foreach (Process process in Process.GetProcessesByName(me.ProcessName))
                    {
                        if (process.Id != me.Id)
                        {
                            // found it, let's switch over and then exit
                            Activate(process.MainWindowHandle);
                            abort = true;
                            break;
                        }
                    }
                }

                if (abort)
                {
                    return;
                }

                // Make sure not other software that communicates with the cube is running, if it is, abort, else start the app
                bool noOtherCubeUserIsRunning;
                using (Mutex cubeMutex = new Mutex(true, "SugarCube_Interactor", out noOtherCubeUserIsRunning)) {
                    // Check if we're going to be using logging
                    string loggingConfigFile = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "3DWares"), "testbed.lc.xml");
                    if (File.Exists(loggingConfigFile))
                    {
                        XmlConfigurator.Configure(new FileInfo(loggingConfigFile));
                    }

                    if (!noOtherCubeUserIsRunning)
                    {
                        if (log.IsErrorEnabled)
                        {
                            log.Error("The Test Bed can NOT be run while the batch runner or manager are open");
                        }

                        MessageBox.Show("The Test Bed can NOT be run while the batch runner or manager are open", "UNABLE TO START TEST BED",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        abort = true;
                    }


                    if (abort)
                    {
                        return;
                    }

                    if (!SecurityManager.PromptForAndCheckPassword())
                    {
                        if (log.IsWarnEnabled)
                        {
                            log.Warn("User entered invalid password, launch aborted");
                        }


                        MessageBox.Show("Invalid password, you do not have permission to run this application.");
                        return;
                    }

                    try {
                        Application.Run(new MainForm());
                    } catch (Exception ex) {
                        if (log.IsFatalEnabled)
                        {
                            log.Fatal("Fatal Error causing application to abort", ex);
                        }

                        ErrorDialog dlg = new ErrorDialog("Test Bed", "Something has gone very wrong.\nSo Long and Thanks for All the Fish!\n" + ex.Message, "The TestBed will now go poof!", ex.StackTrace);
                        dlg.ShowDialog();
                    }
                }         // release cubeMutex
            }             //release appMutex
        }
Пример #3
0
        private void SetOptionsFromConfig()
        {
            try {
                LogWriteLn("Processing Configuration File:");
                if (log.IsInfoEnabled)
                {
                    log.Info("Processing config file");
                }

                int idx = cbCameraList.Items.IndexOf(_config.Camera);
                if (idx > -1)
                {
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("Setting camera list index to " + idx);
                    }

                    cbCameraList.SelectedIndex = idx;
                }
                else
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("unable to set camera to " + _config.Camera);
                    }

                    LogWriteLn("Error processing config, unable to set camera to " + _config.Camera);
                }
                idx = cbResolutionList.Items.IndexOf(_config.Resolution);
                if (idx > -1)
                {
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("Setting resolution list index to " + idx);
                    }

                    cbResolutionList.SelectedIndex = idx;
                }
                else
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("unable to set resolution to " + _config.Resolution);
                    }

                    LogWriteLn("Error processing config, unable to set resolution to " + _config.Resolution);
                }

                tbShootString.Text               = _config.ShootString;
                tbQuality.Value                  = _config.JpegQuality;
                cbUseMotionDetection.Checked     = _config.UseMotionDetection;
                tbSensitivity.Value              = _config.MotionSensitivity;
                cbUseMedianStacking.Checked      = _config.UseMedianStacking;
                cbUseContrastEnhancement.Checked = _config.UseContrastEnhancement;
                tbMidpoint.Value                 = _config.ContrastMidpoint;
                tbContrast.Value                 = _config.ContrastValue;
                cbSetEXIF.Checked                = _config.DoSetEXIF;

                tbHost.Text         = _config.SftpHost;
                tbUser.Text         = _config.SftpUser;
                tbPass.Text         = _config.SftpPassword;
                tbEmail.Text        = _config.UserEmail;
                tbScanIDPrefix.Text = _config.ShootPrefix;
                tbUploadBase.Text   = _config.SftpUploadBase;
                tbTriggerURL.Text   = _config.TriggerURL;

                _modelOpts.doImageCropping        = _config.DoImageCropping.ToString();
                _modelOpts.imageCroppingRectangle = _config.ImageCropRectangle;
                _modelOpts.doModelScaling         = _config.DoModelScaling.ToString();
                _modelOpts.doModelCropping        = _config.DoModelCropping.ToString();
                _modelOpts.boundingBox            = _config.BoundingBox;
                _modelOpts.meshlevel   = _config.MeshLevel.ToString();
                _modelOpts.template3DP = _config.Template3DP;
            } catch (Exception ex) {
                if (log.IsErrorEnabled)
                {
                    log.Error("Failed to load config from disk", ex);
                }

                using (ErrorDialog dlg = new ErrorDialog("Test Bed", "Unable to load the configuration from disk: " + ex.Message, "Click OK to continue", ex.StackTrace)) {
                    dlg.ShowDialog();
                }
            }
        }