public MainWindow(MainViewType initialControl) { InitializeComponent(); Instance = this; InitialControl = initialControl; CurrentViewType = MainViewType.Invalid; KnownViews[MainViewType.Services] = new DataView(new services.ServicesDataController(), ButtonServices); KnownViews[MainViewType.Devices] = new DataView(new devices.DevicesDataController(), ButtonDevices); KnownViews[MainViewType.Windows] = new DataView(new windows.WindowsDataController(), ButtonWindows); KnownViews[MainViewType.Uninstaller] = new DataView(new uninstaller.UninstallerDataController(), ButtonUninstaller); KnownViews[MainViewType.Processes] = new DataView(new processes.ProcessesDataController(), ButtonProcesses); KnownViews[MainViewType.Modules] = new DataView(new modules.ModulesDataController(), ButtonModules); SetBitmapImage(BIStart, "play"); SetBitmapImage(BIStop, "stop"); SetBitmapImage(BIRestart, "repeat"); SetBitmapImage(BIPause, "pause"); SetBitmapImage(BIContinue, "fastforward"); UnselectedBackgroundColor = new SolidColorBrush(Color.FromArgb(255, 0xF5, 0xF5, 0xF5)); UnselectedForegroundColor = new SolidColorBrush(Colors.Black); SelectedBackgroundColor = new SolidColorBrush(Colors.CornflowerBlue); SelectedForegroundColor = new SolidColorBrush(Colors.White); MainGridView.Columns.CollectionChanged += Columns_CollectionChanged; }
private void SwitchController(MainViewType displayMode, bool visible = true) { if (CurrentViewType == displayMode) { return; } Log.InfoFormat("**** BEGIN SwitchController(): switch from {0} to {1} **** ", CurrentViewType, displayMode); using (new WaitCursor()) { Items.Clear(); if (visible) { ICollectionView dataView = CollectionViewSource.GetDefaultView(Items); dataView.SortDescriptions.Clear(); if (CurrentViewType != MainViewType.Invalid) { KnownViews[CurrentViewType].Button.Background = UnselectedBackgroundColor; KnownViews[CurrentViewType].Button.Foreground = UnselectedForegroundColor; } } // create columns DateTime startTime = DateTime.Now; try { DataController.Refresh(Items, KnownViews[displayMode].Controller); } catch (Exception e) { Log.Error(string.Format("{0}.Refresh()", DataController), e); } Log.InfoFormat("Total time for DataController.Refresh: {0}", DateTime.Now - startTime); Log.InfoFormat("Total items count: {0}", Items.Count); FindThisText.Text = ""; if (visible) { MainTreeView.ItemsSource = Items; //your query result CreateInitialSort(); KnownViews[displayMode].Button.Background = SelectedBackgroundColor; KnownViews[displayMode].Button.Foreground = SelectedForegroundColor; } CurrentViewType = displayMode; } Log.Info("**** END SwitchController() ****"); }
public void SwitchController(MainViewType newViewType, bool visible = true) { if (CurrentViewType == newViewType) { return; } Log.InfoFormat("**** BEGIN SwitchController(): switch from {0} to {1} **** ", CurrentViewType, newViewType); using (new WaitCursor()) { Items.Clear(); if (visible) { MainGridView.Columns.Clear(); LastSortOrder.Clear(); if (CurrentViewType != MainViewType.Invalid) { KnownViews[CurrentViewType].Button.Background = UnselectedBackgroundColor; KnownViews[CurrentViewType].Button.Foreground = UnselectedForegroundColor; } } // cleanup CurrentController = KnownViews[newViewType].Controller; // create columns DateTime startTime = DateTime.Now; try { CurrentController.Refresh(Items); } catch (Exception e) { Log.Error(string.Format("Exception caught while refreshing {0}", CurrentController), e); } Log.InfoFormat("Total time for CurrentController.Refresh: {0}", DateTime.Now - startTime); Log.InfoFormat("Total items count: {0}", Items.Count); FindThisText.Text = ""; if (visible) { MainListView.ItemsSource = Items; //your query result foreach (DataObjectColumn oc in CurrentController.Columns) { GridViewColumn column = new GridViewColumn(); column.Header = oc.DisplayName; column.DisplayMemberBinding = new Binding(oc.BindingName); column.Width = System.Double.NaN; MainGridView.Columns.Add(column); } CurrentController.MainListView = MainListView; MainListView.ContextMenu = CurrentController.ContextMenu; MainListView.ContextMenuOpening += MainListView_ContextMenuOpening; UpdateDefaultStatusBar(); TbControlStart.Text = CurrentController.ControlStartDescription; TbControlStop.Text = CurrentController.ControlStopDescription; TbControlRestart.Text = CurrentController.ControlRestartDescription; TbControlPause.Text = CurrentController.ControlPauseDescription; TbControlContinue.Text = CurrentController.ControlContinueDescription; UpdateTitle(); CreateInitialSort(); KnownViews[newViewType].Button.Background = SelectedBackgroundColor; KnownViews[newViewType].Button.Foreground = SelectedForegroundColor; if (FirstDisplay) { FindThisText.Text = App.Settings.LastSearchText; FirstDisplay = false; } } CurrentViewType = newViewType; App.Settings.LastViewType = CurrentViewType.ToString(); if ((InitialSSR != null) && (InitialServiceNames != null)) { if (newViewType == MainViewType.Services) { services.ServicesDataController sdc = CurrentController as services.ServicesDataController; sdc.PerformExplicitRequest(InitialSSR, InitialServiceNames, pserv4.Properties.Resources.IDS_PERFORMING_ACTION); Close(); } else { InitialSSR = null; InitialServiceNames = null; } } } Log.Info("**** END SwitchController() ****"); }
private void Application_Startup(object sender, StartupEventArgs sea) { Log.Info("- starting up pserv -"); Settings = new pserv4.Properties.Settings(); PersistentSettings = new PersistentSettings(Settings, "p-nand-q.com\\pserv4"); PersistentSettings.Load(); MainViewType initialView = MainViewType.Modules; try { if (!string.IsNullOrEmpty(Settings.LastViewType)) { initialView = (MainViewType)Enum.Parse(typeof(MainViewType), Settings.LastViewType, true); } } catch (Exception) { } services.ServiceStateRequest ssr = null; bool dumpXml = false; bool useClipboard = false; string dumpXmlFilename = null; List <string> servicenames = new List <string>(); int n = 0; foreach (string arg in sea.Args) { Log.InfoFormat("- arg[{0}]: {1}", n++, arg); if (arg.StartsWith("/")) { string key = arg.Substring(1).ToUpper(); if (key.Equals("DEVICES")) { initialView = MainViewType.Devices; Log.InfoFormat("=> set initialView to {0}", initialView); } else if (key.Equals("MODULES")) { initialView = MainViewType.Modules; Log.InfoFormat("=> set initialView to {0}", initialView); } else if (key.Equals("PROCESSES")) { initialView = MainViewType.Processes; Log.InfoFormat("=> set initialView to {0}", initialView); } else if (key.Equals("UNINSTALLER")) { initialView = MainViewType.Uninstaller; Log.InfoFormat("=> set initialView to {0}", initialView); } else if (key.Equals("WINDOWS")) { initialView = MainViewType.Windows; Log.InfoFormat("=> set initialView to {0}", initialView); } else if (key.Equals("DUMPXML")) { dumpXml = true; Log.Info("=> set dumpXml to true"); } else if (key.Equals("CLIPBOARD")) { dumpXml = true; useClipboard = true; Log.Info("=> set dumpXml to true"); Log.Info("=> set useClipboard to true"); } else if (key.Equals("START")) { ssr = new services.RequestServiceStart(); Log.InfoFormat("=> set ssr to {0}", ssr); } else if (key.Equals("STOP")) { ssr = new services.RequestServiceStop(); Log.InfoFormat("=> set ssr to {0}", ssr); } else if (key.Equals("RESTART")) { ssr = new services.RequestServiceRestart(); Log.InfoFormat("=> set ssr to {0}", ssr); } else if (key.Equals("PAUSE")) { ssr = new services.RequestServicePause(); Log.InfoFormat("=> set ssr to {0}", ssr); } else if (key.Equals("CONTINUE")) { ssr = new services.RequestServiceContinue(); Log.InfoFormat("=> set ssr to {0}", ssr); } } else if (dumpXml && string.IsNullOrEmpty(dumpXmlFilename)) { dumpXmlFilename = arg; Log.InfoFormat("=> set dumpXmlFilename to {0}", dumpXmlFilename); } else if (ssr != null) { Log.InfoFormat("=> add service named '{0}'", arg); servicenames.Add(arg); } } MainWindow wnd = new MainWindow(initialView); if (dumpXml) { wnd.SwitchController(initialView, false); if (useClipboard) { wnd.CopyToClipboard(null, null); } else if (string.IsNullOrEmpty(dumpXmlFilename)) { wnd.SaveAsXML(null, null); } else { wnd.SaveAsXML(dumpXmlFilename, null); } Shutdown(); } else { if (ssr != null) { wnd.SetInitialAction(ssr, servicenames); } wnd.Show(); } }
private void SwitchController(MainViewType displayMode, bool visible = true) { if (CurrentViewType == displayMode) return; Log.InfoFormat("**** BEGIN SwitchController(): switch from {0} to {1} **** ", CurrentViewType, displayMode); using (new WaitCursor()) { Items.Clear(); if (visible) { ICollectionView dataView = CollectionViewSource.GetDefaultView(Items); dataView.SortDescriptions.Clear(); if (CurrentViewType != MainViewType.Invalid) { KnownViews[CurrentViewType].Button.Background = UnselectedBackgroundColor; KnownViews[CurrentViewType].Button.Foreground = UnselectedForegroundColor; } } // create columns DateTime startTime = DateTime.Now; try { DataController.Refresh(Items, KnownViews[displayMode].Controller); } catch (Exception e) { Log.Error(string.Format("{0}.Refresh()", DataController), e); } Log.InfoFormat("Total time for DataController.Refresh: {0}", DateTime.Now - startTime); Log.InfoFormat("Total items count: {0}", Items.Count); FindThisText.Text = ""; if (visible) { MainTreeView.ItemsSource = Items; //your query result CreateInitialSort(); KnownViews[displayMode].Button.Background = SelectedBackgroundColor; KnownViews[displayMode].Button.Foreground = SelectedForegroundColor; } CurrentViewType = displayMode; } Log.Info("**** END SwitchController() ****"); }