private void form_shown(object sender, EventArgs e) { updatePanel(); if (manager.Exceptions.Count > 0) { ExceptionViewer problems = new ExceptionViewer(manager.Exceptions); problems.ShowDialog(this); manager.Exceptions.Clear(); } // force a direkt start, if manager is ready if (manager.CanStart && directstart) { start(sender, e); } }
private void form_close(object sender, FormClosingEventArgs e) { if (manager.CanStop) { manager.Stop(); } // Alle Plugin-Einstellungen absichern Settings.Default.Save(); manager.SaveSettings(); // show possible problems if (manager.Exceptions != null && manager.Exceptions.Count > 0) { ExceptionViewer form = new ExceptionViewer(manager.Exceptions); manager.Exceptions.Clear(); form.ShowDialog(this); } }
private void addPluginButton_Click(object sender, EventArgs e) { openFileDialog.InitialDirectory = Application.ExecutablePath; openFileDialog.FileName = string.Empty; if (openFileDialog.ShowDialog(this) == DialogResult.OK) { try { foreach (string filename in openFileDialog.FileNames) { manager.CheckForPlugin(filename); } if (manager.Exceptions.Count > 0) { ExceptionViewer problems = new ExceptionViewer(manager.Exceptions); problems.ShowDialog(this); manager.Exceptions.Clear(); } UpdateList(); } catch (Exception ex) { MessageBox.Show(this, ex.Message); } } }
public Main(string[] parameter) { initPhase = true; InitializeComponent(); CreateHandle(); // check Language-buttons switch (Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName) { case "de": germanMenuItem.Checked = true; break; default: englishMenuItem.Checked = true; break; } // Load welcomepage try { infoWebBrowser.Navigate("file://" + Application.StartupPath + Resource.MainWelcomePagePath); } catch {} manager = new PluginManager(); try { manager.LoadSettings(); } catch (Exception ex) { ExceptionViewer problems = new ExceptionViewer(ex); problems.ShowDialog(this); } // Set Window-Position WindowState = Settings.Default.windowState; Location = Settings.Default.windowPosition; Size = Settings.Default.windowSize; manager.SearchForPlugins(); timer.Enabled = true; // Forward startparameter foreach (PluginItem plugin in manager.ProducerPlugins) { plugin.Producer.StartupParameter(parameter); } foreach (PluginItem plugin in manager.ConsumerPlugins) { plugin.Consumer.StartupParameter(parameter); } foreach (string p in parameter) { if (p.ToUpper() == "/START") { directstart = true; } } initPhase = false; }
/// <summary> /// Make updates based on manager-settings /// </summary> private void updatePanel() { if (ignoreTimerEvents) { return; } ignoreTimerEvents = true; // Controlling-Buttons startMenuItem.Enabled = manager.CanStart; startToolItem.Enabled = manager.CanStart; pauseToolItem.Enabled = manager.CanPause; pauseMenuItem.Enabled = manager.CanPause; stopToolItem.Enabled = manager.CanStop; stopMenuItem.Enabled = manager.CanStop; newspanelMenuItem.Checked = Settings.Default.showNews; autoupdateMenuItem.Checked = Settings.Default.checkForUpdates; if (manager.FrameLimiterEnabled) { if ((int)Math.Round(manager.FrameLimit) <= 100) { fasterToolItem.Enabled = true; } else { fasterToolItem.Enabled = false; } if ((int)Math.Round(manager.FrameLimit) > 1) { slowerToolItem.Enabled = true; } else { slowerToolItem.Enabled = false; } speedDropDownToolItem.Text = string.Format(Resource.MainFramesPerSecond, manager.FrameLimit); } else { slowerToolItem.Enabled = false; fasterToolItem.Enabled = false; speedDropDownToolItem.Text = Resource.MainSpeedMaximal; } // producer-list List <PluginItem> producerList = new List <PluginItem>(manager.ProducerPlugins); for (int i = 0; i < producerComboBoxToolItem.Items.Count; i++) { PluginItem item = (PluginItem)producerComboBoxToolItem.Items[i]; if (!producerList.Contains(item)) { producerComboBoxToolItem.Items.Remove(item); i--; } } foreach (PluginItem item in producerList) { if (!producerComboBoxToolItem.Items.Contains(item)) { producerComboBoxToolItem.Items.Add(item); } } // manage tabs if (activeProducer != manager.ActiveProducerPlugin) { // Update Combobox producerComboBoxToolItem.SelectedItem = manager.ActiveProducerPlugin; // remove old tab if (activeProducer != null) { if (activeProducer.Producer.Control != null) { tabControl.TabPages.RemoveAt(1); } activeProducer = null; } // add new tab if (manager.ActiveProducerPlugin != null) { if (manager.ActiveProducerPlugin.Producer.Control != null) { TabPage page = new TabPage(manager.ActiveProducerPlugin.Name); page.Controls.Add(manager.ActiveProducerPlugin.Producer.Control); tabControl.TabPages.Insert(1, page); manager.ActiveProducerPlugin.Producer.Control.Dock = DockStyle.Fill; } activeProducer = manager.ActiveProducerPlugin; } } // synchronize Consumer List <PluginItem> newActiveConsumers = new List <PluginItem>(manager.ActiveConsumerPlugins); for (int i = activeConsumers.Count - 1; i >= 0; i--) { // Kick the old tab if (!newActiveConsumers.Contains(activeConsumers[i])) { if (tabControl.TabPages.ContainsKey(activeConsumers[i].Guid.ToString())) { tabControl.TabPages.RemoveByKey(activeConsumers[i].Guid.ToString()); } activeConsumers.Remove(activeConsumers[i]); } } foreach (PluginItem plugin in newActiveConsumers) { //Create new, if needed if (!activeConsumers.Contains(plugin)) { // Create Tab and place control if (plugin.Consumer.Control != null) { tabControl.TabPages.Add(plugin.Guid.ToString(), plugin.Name); tabControl.TabPages[plugin.Guid.ToString()].Controls.Add(plugin.Consumer.Control); plugin.Consumer.Control.Dock = DockStyle.Fill; } activeConsumers.Add(plugin); } } // popup exceptions if (manager.Exceptions.Count > 0) { ExceptionViewer problems = new ExceptionViewer(manager.Exceptions); problems.ShowDialog(this); manager.Exceptions.Clear(); } // StatusBar-information stateLabelBarItem.Text = string.Empty; switch (manager.State) { case PluginState.NotReady: stateLabelBarItem.Text = Resource.MainStateNotReady; break; case PluginState.Paused: stateLabelBarItem.Text = Resource.MainStatePaused; break; case PluginState.Ready: stateLabelBarItem.Text = Resource.MainStateReady; break; case PluginState.Running: stateLabelBarItem.Text = Resource.MainStateRunning; break; } if (manager.State == PluginState.Running || manager.State == PluginState.Paused) { progressBarItem.Maximum = manager.TotalRounds; progressBarItem.Value = manager.CurrentRound; stepCounterBarItem.Text = string.Format(Resource.MainStateRoundIndicator, manager.CurrentRound, manager.TotalRounds); progressBarItem.Visible = true; stepCounterBarItem.Visible = true; } else { progressBarItem.Visible = false; stepCounterBarItem.Visible = false; } if (manager.State == PluginState.Running) { fpsBarItem.Text = manager.FrameRate.ToString(Resource.MainStateFramesPerSecond); fpsBarItem.Visible = true; } else { fpsBarItem.Visible = false; } // Autoupdater if (updateUrl != string.Empty) { if (MessageBox.Show(this, string.Format(Resource.MainUpdateMessage, Assembly.GetCallingAssembly().GetName().Version, updateVersion), Resource.MainUpdateTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes) { Help.ShowHelp(this, updateUrl); // TODO: Exceptionhandling } updateUrl = string.Empty; } ignoreTimerEvents = false; }
public Main(string[] parameter) { initPhase = true; InitializeComponent(); onlineButton.Tag = ConnectionState.Connected; CreateHandle(); // check Language-buttons switch (Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName) { case "de": germanMenuItem.Checked = true; break; default: englishMenuItem.Checked = true; break; } // Load Player Task t = new Task(() => { PlayerStore.Instance.ToString(); }); t.Start(); // Prüfe auf Updates t = new Task(BackgroundUpdateCheck); t.Start(); // Load welcomepage try { infoWebBrowser.Navigate(Resource.MainWelcomePageUrl); } catch { } manager = new PluginManager(); try { manager.LoadSettings(); } catch (Exception ex) { ExceptionViewer problems = new ExceptionViewer(ex); problems.ShowDialog(this); } // Set Window-Position WindowState = Settings.Default.windowState; Location = Settings.Default.windowPosition; Size = Settings.Default.windowSize; manager.SearchForPlugins(); timer.Enabled = true; // Forward startparameter foreach (PluginItem plugin in manager.ProducerPlugins) { plugin.Producer.StartupParameter(parameter); } foreach (PluginItem plugin in manager.ConsumerPlugins) { plugin.Consumer.StartupParameter(parameter); } foreach (string p in parameter) { if (p.ToUpper() == "/START") { directstart = true; } } initPhase = false; }
/// <summary> /// Make updates based on manager-settings /// </summary> private void updatePanel() { if (ignoreTimerEvents) { return; } ignoreTimerEvents = true; // Controlling-Buttons startMenuItem.Enabled = manager.CanStart; startToolItem.Enabled = manager.CanStart; pauseToolItem.Enabled = manager.CanPause; pauseMenuItem.Enabled = manager.CanPause; stopToolItem.Enabled = manager.CanStop; stopMenuItem.Enabled = manager.CanStop; if (manager.FrameLimiterEnabled) { if ((int)Math.Round(manager.FrameLimit) <= 100) { fasterToolItem.Enabled = true; } else { fasterToolItem.Enabled = false; } if ((int)Math.Round(manager.FrameLimit) > 1) { slowerToolItem.Enabled = true; } else { slowerToolItem.Enabled = false; } speedDropDownToolItem.Text = string.Format(Resource.MainFramesPerSecond, manager.FrameLimit); } else { slowerToolItem.Enabled = false; fasterToolItem.Enabled = false; speedDropDownToolItem.Text = Resource.MainSpeedMaximal; } // Producer List (Button-Based) List <ToolStripItem> remove = new List <ToolStripItem>(); foreach (ToolStripItem item in producerButton.DropDownItems) { if (!manager.ProducerPlugins.Any(p => p == item.Tag)) { remove.Add(item); } } foreach (var item in remove) { producerButton.DropDownItems.Remove(item); } foreach (var item in manager.ProducerPlugins) { if (producerButton.DropDownItems.Find(item.Guid.ToString(), false).Count() == 0) { var menuItem = new ToolStripMenuItem() { Text = item.Name, Name = item.Guid.ToString(), Tag = item }; menuItem.Click += button_producer; producerButton.DropDownItems.Add(menuItem); } } // manage tabs if (activeProducer != manager.ActiveProducerPlugin) { bool isSelected = tabControl.SelectedIndex == 1; // Update Mode Display producerButton.Text = (manager.ActiveProducerPlugin == null ? Resource.MainNoModeSelected : manager.ActiveProducerPlugin.Name); // remove old tab if (activeProducer != null) { if (activeProducer.Producer.Control != null) { tabControl.TabPages.RemoveAt(1); } activeProducer = null; } // add new tab if (manager.ActiveProducerPlugin != null) { if (manager.ActiveProducerPlugin.Producer.Control != null) { TabPage page = new TabPage(manager.ActiveProducerPlugin.Name); page.Padding = new Padding(0); page.Margin = new Padding(0); page.Controls.Add(manager.ActiveProducerPlugin.Producer.Control); manager.ActiveProducerPlugin.Producer.Control.Padding = new Padding(0); manager.ActiveProducerPlugin.Producer.Control.Margin = new Padding(0); tabControl.TabPages.Insert(1, page); manager.ActiveProducerPlugin.Producer.Control.Dock = DockStyle.Fill; if (isSelected) { tabControl.SelectedIndex = 1; } } activeProducer = manager.ActiveProducerPlugin; } } // synchronize Consumer List <PluginItem> newActiveConsumers = new List <PluginItem>(manager.ActiveConsumerPlugins); for (int i = activeConsumers.Count - 1; i >= 0; i--) { // Kick the old tab if (!newActiveConsumers.Contains(activeConsumers[i])) { if (tabControl.TabPages.ContainsKey(activeConsumers[i].Guid.ToString())) { tabControl.TabPages.RemoveByKey(activeConsumers[i].Guid.ToString()); } activeConsumers.Remove(activeConsumers[i]); } } foreach (PluginItem plugin in newActiveConsumers) { //Create new, if needed if (!activeConsumers.Contains(plugin)) { // Create Tab and place control if (plugin.Consumer.Control != null) { tabControl.TabPages.Add(plugin.Guid.ToString(), plugin.Name); tabControl.TabPages[plugin.Guid.ToString()].Controls.Add(plugin.Consumer.Control); plugin.Consumer.Control.Dock = DockStyle.Fill; } activeConsumers.Add(plugin); } } // popup exceptions if (manager.Exceptions.Count > 0) { ExceptionViewer problems = new ExceptionViewer(manager.Exceptions); problems.ShowDialog(this); manager.Exceptions.Clear(); } // StatusBar-information stateLabelBarItem.Text = string.Empty; switch (manager.State) { case PluginState.NotReady: stateLabelBarItem.Text = Resource.MainStateNotReady; break; case PluginState.Paused: stateLabelBarItem.Text = Resource.MainStatePaused; break; case PluginState.Ready: stateLabelBarItem.Text = Resource.MainStateReady; break; case PluginState.Running: stateLabelBarItem.Text = Resource.MainStateRunning; break; } if (manager.State == PluginState.Running || manager.State == PluginState.Paused) { progressBarItem.Maximum = manager.TotalRounds; progressBarItem.Value = manager.CurrentRound; stepCounterBarItem.Text = string.Format(Resource.MainStateRoundIndicator, manager.CurrentRound, manager.TotalRounds); progressBarItem.Visible = true; stepCounterBarItem.Visible = true; } else { progressBarItem.Visible = false; stepCounterBarItem.Visible = false; } if (manager.State == PluginState.Running) { fpsBarItem.Text = manager.FrameRate.ToString(Resource.MainStateFramesPerSecond); fpsBarItem.Visible = true; } else { fpsBarItem.Visible = false; } // Online Connector onlineButton.Text = Connection.Instance.Username; onlineButton.Visible = Connection.Instance.IsLoggedIn; onlineButton.Enabled = !Connection.Instance.IsBusy; if ((ConnectionState)onlineButton.Tag != Connection.Instance.State) { switch (Connection.Instance.State) { case ConnectionState.NoConnection: onlineButton.Image = Resources.connection; onlineButton.ToolTipText = Resource.UpdateNoConnection; break; case ConnectionState.TokenInvalid: onlineButton.Image = Resources.warning; onlineButton.ToolTipText = Resource.UpdateTokenInvalid; break; default: onlineButton.Image = Resources.online; onlineButton.ToolTipText = string.Empty; break; } onlineButton.Tag = Connection.Instance.State; } loginButton.Visible = !Connection.Instance.IsLoggedIn; loginButton.Enabled = !Connection.Instance.IsBusy; versionButton.Visible = !string.IsNullOrEmpty(Properties.Settings.Default.updateLink); ignoreTimerEvents = false; }