예제 #1
0
        private void ResetMonitorsThread(ResetMonitors resetDialog, HeliosProfile profile)
        {
            ConfigManager.UndoManager.StartBatch();
            ConfigManager.LogManager.LogDebug("Resetting Monitors");
            try
            {
                // WARNING: monitor naming is 1-based but indexing and NewMonitor references are 0-based
                Monitor[] localMonitors = ConfigManager.DisplayManager.Displays.ToArray <Monitor>();

                // pass1: process all new and/or old monitors in order
                int existingMonitors = Math.Min(localMonitors.Length, profile.Monitors.Count);
                int totalMonitors    = Math.Max(localMonitors.Length, profile.Monitors.Count);

                // monitors that are preserved
                for (int monitorIndex = 0; monitorIndex < existingMonitors; monitorIndex++)
                {
                    MonitorResetItem item = resetDialog.MonitorResets[monitorIndex];
                    ResetExistingMonitor(monitorIndex, item);
                }

                // monitors added (may be zero iterations)
                for (int monitorIndex = existingMonitors; monitorIndex < localMonitors.Length; monitorIndex++)
                {
                    // monitorIndex does not refer to any reset item, as we are off the end of the list
                    ResetAddedMonitor(profile, monitorIndex, localMonitors[monitorIndex]);
                }

                // monitors removed (may be zero iterations)
                for (int monitorIndex = existingMonitors; monitorIndex < resetDialog.MonitorResets.Count; monitorIndex++)
                {
                    MonitorResetItem item = resetDialog.MonitorResets[monitorIndex];
                    ResetRemovedMonitor(profile, monitorIndex, item, localMonitors.Length);
                }

                // pass2: place all controls that were temporarily lifted and
                // copy over any settings from source to target monitors
                foreach (MonitorResetItem item in resetDialog.MonitorResets)
                {
                    ConfigManager.LogManager.LogDebug($"Placing controls for old monitor {item.OldMonitor.Name} onto Monitor {item.NewMonitor + 1}");
                    Dispatcher.Invoke(DispatcherPriority.Background, new Action <Monitor>(item.PlaceControls), profile.Monitors[item.NewMonitor]);
                    Dispatcher.Invoke(DispatcherPriority.Background, new Action <Monitor>(item.CopySettings), profile.Monitors[item.NewMonitor]);
                }

                ConfigManager.UndoManager.CloseBatch();
            }
            catch (Exception ex)
            {
                ConfigManager.LogManager.LogError("Reset Monitors - Unhandled exception", ex);
                ConfigManager.LogManager.LogError("Rolling back any undoable operations from monitor reset");
                ConfigManager.UndoManager.UndoBatch();
                MessageBox.Show("Error encountered while resetting monitors; please file a bug with the contents of the application log", "Error");
            }
            finally
            {
                Dispatcher.Invoke(DispatcherPriority.Background, new Action(RemoveLoadingAdorner));
            }
        }
예제 #2
0
        private void ResetMonitors_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            ResetMonitors resetDialog = new ResetMonitors(Profile);

            resetDialog.Owner = this;
            bool?reset = resetDialog.ShowDialog();

            if (reset.HasValue && reset.Value)
            {
                GetLoadingAdorner();
                // this value comes from a dependency property that can only be
                // read on this thread
                HeliosProfile profile = Profile;

                // now run monitor import as another thread
                new System.Threading.Thread(() => { ResetMonitorsThread(resetDialog, profile); }).Start();
            }
        }
예제 #3
0
        private void ResetMonitors_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            ResetMonitors resetDialog = new ResetMonitors(Profile);

            resetDialog.Owner = this;
            bool?reset = resetDialog.ShowDialog();

            if (reset != null && reset == true)
            {
                HeliosProfile profile = Profile;
                GetLoadingAdorner();
                System.Threading.Thread t = new System.Threading.Thread(delegate()
                {
                    ConfigManager.UndoManager.StartBatch();
                    ConfigManager.LogManager.LogDebug("Reseting Monitors");
                    try
                    {
                        int i = 0;
                        foreach (Monitor display in ConfigManager.DisplayManager.Displays)
                        {
                            if (i < profile.Monitors.Count)
                            {
                                if (resetDialog.MonitorResets[i].NewMonitor != i)
                                {
                                    ConfigManager.LogManager.LogDebug("Removing controls for replacement from Monitor " + i);
                                    Dispatcher.Invoke(DispatcherPriority.Background, new Action(resetDialog.MonitorResets[i].RemoveControls));
                                }
                                ConfigManager.LogManager.LogDebug("Reseting Monitor " + i);
                                Dispatcher.Invoke(DispatcherPriority.Background, new Action(resetDialog.MonitorResets[i].Reset));
                            }
                            else
                            {
                                ConfigManager.LogManager.LogDebug("Adding Monitor " + i);
                                Monitor monitor = new Monitor(display);
                                monitor.Name    = "Monitor " + i++;
                                ConfigManager.UndoManager.AddUndoItem(new AddMonitorUndoEvent(profile, monitor));
                                Dispatcher.Invoke(DispatcherPriority.Background, new Action <Monitor>(profile.Monitors.Add), monitor);
                            }
                            i++;
                        }
                        while (i < profile.Monitors.Count)
                        {
                            ConfigManager.LogManager.LogDebug("Removing Monitor " + i);
                            Dispatcher.Invoke(DispatcherPriority.Background, new Action <HeliosObject>(CloseProfileItem), profile.Monitors[i]);
                            Dispatcher.Invoke(DispatcherPriority.Background, new Action(resetDialog.MonitorResets[i].RemoveControls));

                            ConfigManager.UndoManager.AddUndoItem(new DeleteMonitorUndoEvent(profile, profile.Monitors[i], i));
                            profile.Monitors.RemoveAt(i);
                        }
                        foreach (MonitorResetItem item in resetDialog.MonitorResets)
                        {
                            ConfigManager.LogManager.LogDebug("Placeing controls for old monitor " + item.OldMonitor);
                            Dispatcher.Invoke(DispatcherPriority.Background, new Action <Monitor>(item.PlaceControls), profile.Monitors[item.NewMonitor]);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error encountered while reseting monitors, please contact support via forums at www.scsimulations.com", "Error");
                        ConfigManager.LogManager.LogError("Reset Monitors - Unhandled exception", ex);
                    }

                    ConfigManager.UndoManager.CloseBatch();

                    Dispatcher.Invoke(DispatcherPriority.Background, new Action(RemoveLoadingAdorner));
                });
                t.Start();
            }
        }
예제 #4
0
        private void ResetMonitors_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            ResetMonitors resetDialog = new ResetMonitors(Profile);
            resetDialog.Owner = this;
            bool? reset = resetDialog.ShowDialog();

            if (reset != null && reset == true)
            {
                HeliosProfile profile = Profile;
                GetLoadingAdorner();
                System.Threading.Thread t = new System.Threading.Thread(delegate()
                {
                    ConfigManager.UndoManager.StartBatch();
                    ConfigManager.LogManager.LogDebug("Reseting Monitors");
                    try
                    {
                        int i = 0;
                        foreach (Monitor display in ConfigManager.DisplayManager.Displays)
                        {
                            if (i < profile.Monitors.Count)
                            {
                                if (resetDialog.MonitorResets[i].NewMonitor != i)
                                {
                                    ConfigManager.LogManager.LogDebug("Removing controls for replacement from Monitor " + i);
                                    Dispatcher.Invoke(DispatcherPriority.Background, new Action(resetDialog.MonitorResets[i].RemoveControls));
                                }
                                ConfigManager.LogManager.LogDebug("Reseting Monitor " + i);
                                Dispatcher.Invoke(DispatcherPriority.Background, new Action(resetDialog.MonitorResets[i].Reset));
                            }
                            else
                            {
                                ConfigManager.LogManager.LogDebug("Adding Monitor " + i);
                                Monitor monitor = new Monitor(display);
                                monitor.Name = "Monitor " + i++;
                                ConfigManager.UndoManager.AddUndoItem(new AddMonitorUndoEvent(profile, monitor));
                                Dispatcher.Invoke(DispatcherPriority.Background, new Action<Monitor>(profile.Monitors.Add), monitor);
                            }
                            i++;
                        }
                        while (i < profile.Monitors.Count)
                        {
                            ConfigManager.LogManager.LogDebug("Removing Monitor " + i);
                            Dispatcher.Invoke(DispatcherPriority.Background, new Action<HeliosObject>(CloseProfileItem), profile.Monitors[i]);
                            Dispatcher.Invoke(DispatcherPriority.Background, new Action(resetDialog.MonitorResets[i].RemoveControls));

                            ConfigManager.UndoManager.AddUndoItem(new DeleteMonitorUndoEvent(profile, profile.Monitors[i], i));
                            profile.Monitors.RemoveAt(i);
                        }
                        foreach (MonitorResetItem item in resetDialog.MonitorResets)
                        {
                            ConfigManager.LogManager.LogDebug("Placeing controls for old monitor " + item.OldMonitor);
                            Dispatcher.Invoke(DispatcherPriority.Background, new Action<Monitor>(item.PlaceControls), profile.Monitors[item.NewMonitor]);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error encountered while reseting monitors, please contact support via forums at www.scsimulations.com", "Error");
                        ConfigManager.LogManager.LogError("Reset Monitors - Unhandled exception", ex);
                    }

                    ConfigManager.UndoManager.CloseBatch();

                    Dispatcher.Invoke(DispatcherPriority.Background, new Action(RemoveLoadingAdorner));
                });
                t.Start();
            }
        }