Esempio n. 1
0
        public static void runCicero(RunLog runLog)
        {
            try
            {
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
                Application.EnableVisualStyles();

                // Detect if Windows 7 or Vista is being used.
                OperatingSystem osInfo = System.Environment.OSVersion;
                if (osInfo.Version.Major == 6)
                {
                    WordGenerator.GlobalInfo.usingWindows7 = true;
                }

                try
                {

                    Application.SetCompatibleTextRenderingDefault(false);

                }
                catch (InvalidOperationException)
                {
                }

                MainClientForm mainForm;

                if (runLog == null)
                {
                    mainForm = new MainClientForm();
                }
                else
                {
                    mainForm =  new MainClientForm(runLog);
                }

                ClientRunner runner = new ClientRunner();

                runner.messageLog += new EventHandler<MessageEvent>(mainForm.addMessageLogText);
                Storage.registerMessageLogHandler(mainForm.handleMessageEvent);

                Application.Run(mainForm);

            }
            catch (Exception e)
            {
                display_unhandled_exception(e);
            }
        }
        /// <summary>
        /// runLog will be null in general, when running Cicero as a standalone application. However, when Cicero is launched through Elgin,
        /// runLog will contain the log that we intent to browse.
        /// </summary>
        /// <param name="runLog"></param>
        public MainClientForm(RunLog runLog)
        {
            #region Singleton
            if (instance != null)
                throw new Exception("Word Generator is already running!");
            instance = this;
            #endregion

            try
            {
                string[] forts = WordGenerator.Properties.Resources.Fortunes.Split('\n');
                fortunes = new List<string>(forts);
            }
            catch { }

            if (runLog == null)
            {
                // Identify the clientStartupSettingsFile
                clientStartupSettingsFile = FileNameStrings.DefaultClientStartupSettingsFile;

                // Load all necessary data into Storage
                Storage.SaveAndLoad.LoadAllSubclasses(clientStartupSettingsFile);

            }
            else
            {
                Storage.clientStartupSettings = new ClientStartupSettings();
                Storage.sequenceData = runLog.RunSequence;
                Storage.settingsData = runLog.RunSettings;
            }

            InitializeComponent();

            #if DEBUG
            debugToolStripMenuItem.Visible = true;
            #endif

            ToolStripMenuItem citationItem = new ToolStripMenuItem();
            citationItem.Text = "Citation";
            citationItem.Click += new EventHandler(citationItem_Click);
            aboutToolStripMenuItem.DropDownItems.Add(citationItem);

            if (hotKeyBindings == null)
                hotKeyBindings = new List<object>();

                try {

                /*
                RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F9);
                hotKeyBindings.Add(sequencePage1.runControl1.runZeroButton);
                */

                // bind F11 hotkey to server manager:
                RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F11);
                hotKeyBindings.Add(this.serverManagerButton);

                // bind F1 to F8 to appropriate tab pages

                RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F1);
                hotKeyBindings.Add(this.sequenceTab);

                RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F2);
                hotKeyBindings.Add(this.overrideTab);

                RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F3);
                hotKeyBindings.Add(this.analogTab);

                RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F4);
                hotKeyBindings.Add(this.gpibTab);

                RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F5);
                hotKeyBindings.Add(this.rs232Tab);

                RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F6);
                hotKeyBindings.Add(this.commonWaveformTab);

                RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F7);
                hotKeyBindings.Add(this.variablesTab);

                RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.None, Keys.F8);
                hotKeyBindings.Add(this.pulsesTab);

                RegisterHotKey(Handle, hotKeyBindings.Count, KeyModifiers.Control, Keys.F9);
                hotKeyBindings.Add(this.sequencePage.runControl1.bgRunButton);
            }
            catch (Exception e) {
                addMessageLogText(this, new MessageEvent("Unable to add hotkeys due to error: " + e.Message,
                                                         0,
                                                         MessageEvent.MessageTypes.Error));
            }

            RefreshRecentFiles();
            this.RefreshSettingsDataToUI();
            this.RefreshSequenceDataToUI();

            if (!Storage.clientStartupSettings.HasShownCitationMessage)
            {
                CitationInfoForm cif = new CitationInfoForm(true);
                cif.ShowDialog();
                Storage.clientStartupSettings.HasShownCitationMessage = true;
            }
        }