22using System . Collections . Generic ;
33using System . Data ;
44using System . Data . SqlClient ;
5+ using System . Drawing ;
56using System . Globalization ;
67using System . IO ;
78using System . Text ;
@@ -47,9 +48,6 @@ private enum ProfilingStateEnum {
4748 private readonly List < ListViewItem > m_Cached = new List < ListViewItem > ( 1024 ) ;
4849 private readonly List < ListViewItem > m_CachedUnFiltered = new List < ListViewItem > ( 1024 ) ;
4950 private readonly Dictionary < string , ListViewItem > m_itembysql = new Dictionary < string , ListViewItem > ( ) ;
50- private string m_servername = "" ;
51- private string m_username = "" ;
52- private string m_userpassword = "" ;
5351 internal int lastpos = - 1 ;
5452 internal string lastpattern = "" ;
5553 private ListViewNF lvEvents ;
@@ -71,19 +69,45 @@ public MainForm() {
7169 Text = $ "SqlProfiler { ( Environment . Is64BitProcess ? "x64" : "x32" ) } - { Updater . CurrentVersion } ";
7270 StartPosition = FormStartPosition . CenterScreen ;
7371 edPassword . TextBox . PasswordChar = '*' ;
72+
7473 m_currentsettings = TraceProperties . TraceSettings . GetDefaultSettings ( ) ;
75- m_servername = "." ;
76- m_username = "sa" ;
7774 ParseCommandLine ( ) ;
7875 InitLV ( ) ;
79- edServer . Text = m_servername ;
80- edUser . Text = m_username ;
81- edPassword . Text = m_userpassword ;
82- tbAuth . SelectedIndex = String . IsNullOrEmpty ( m_username ) ? 0 : 1 ;
76+ edServer . Text = Config . Instance . Server ;
77+ edUser . Text = Config . Instance . User ;
78+ edPassword . Text = Config . Instance . Password ;
79+ tbAuth . SelectedIndex = String . IsNullOrEmpty ( Config . Instance . User ) ? 0 : 1 ;
8380 if ( m_autostart ) RunProfiling ( false ) ;
8481 UpdateButtons ( ) ;
82+
83+ MinimumSize = new Size ( 1100 , 666 ) ;
84+
85+ Load += ( sender , args ) => {
86+ Left = Config . Instance . Left ;
87+ Top = Config . Instance . Top ;
88+ Height = Config . Instance . Height ;
89+ Width = Config . Instance . Width ;
90+ } ;
91+
92+ Closing += ( sender , args ) => {
93+ Config . Instance . Left = Left ;
94+ Config . Instance . Top = Top ;
95+ Config . Instance . Height = Height ;
96+ Config . Instance . Width = Width ;
97+
98+ Config . Instance . Save ( ) ;
99+ } ;
100+ }
101+
102+ public sealed override Size MinimumSize {
103+ get { return base . MinimumSize ; }
104+ set { base . MinimumSize = value ; }
85105 }
86106
107+ private string GetConfigFilePath ( ) {
108+ return Path . ChangeExtension ( Updater . CurrentFileLocation , ".json" ) ;
109+ }
110+
87111//DatabaseName = Filters.DatabaseName,
88112//LoginName = Filters.LoginName,
89113//HostName = Filters.HostName,
@@ -149,17 +173,17 @@ private void ParseCommandLine() {
149173 switch ( args [ i ] . ToLower ( ) ) {
150174 case "-s" :
151175 case "-server" :
152- m_servername = ep ;
176+ Config . Instance . Server = ep ;
153177 i ++ ;
154178 break ;
155179 case "-u" :
156180 case "-user" :
157- m_username = ep ;
181+ Config . Instance . User = ep ;
158182 i ++ ;
159183 break ;
160184 case "-p" :
161185 case "-password" :
162- m_userpassword = ep ;
186+ Config . Instance . Password = ep ;
163187 i ++ ;
164188 break ;
165189 case "-m" :
@@ -212,8 +236,8 @@ private void ParseCommandLine() {
212236 i ++ ;
213237 }
214238
215- if ( m_servername . Length == 0 ) {
216- m_servername = @".\sqlexpress" ;
239+ if ( Config . Instance . Server . Length == 0 ) {
240+ Config . Instance . Server = @".\sqlexpress" ;
217241 }
218242 }
219243 catch ( Exception e ) {
@@ -253,7 +277,6 @@ private void UpdateButtons() {
253277 edPassword . Enabled = edServer . Enabled && ( tbAuth . SelectedIndex == 1 ) ;
254278 }
255279
256-
257280 private void InitLV ( ) {
258281 lvEvents = new ListViewNF {
259282 Dock = DockStyle . Fill ,
@@ -272,7 +295,6 @@ private void InitLV() {
272295 AllowColumnReorder = false
273296 } ;
274297 lvEvents . RetrieveVirtualItem += lvEvents_RetrieveVirtualItem ;
275- lvEvents . KeyDown += lvEvents_KeyDown ;
276298 lvEvents . ItemSelectionChanged += listView1_ItemSelectionChanged_1 ;
277299 lvEvents . ColumnClick += lvEvents_ColumnClick ;
278300 lvEvents . SelectedIndexChanged += lvEvents_SelectedIndexChanged ;
@@ -688,8 +710,8 @@ private void StartProfiling() {
688710 m_itembysql . Clear ( ) ;
689711 lvEvents . VirtualListSize = 0 ;
690712 StartProfilerThread ( ) ;
691- m_servername = edServer . Text ;
692- m_username = edUser . Text ;
713+ Config . Instance . Server = edServer . Text ;
714+ Config . Instance . User = edUser . Text ;
693715 }
694716 catch ( Exception e ) {
695717 MessageBox . Show ( e . Message , "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
@@ -815,7 +837,6 @@ private void PauseProfiling() {
815837 UpdateButtons ( ) ;
816838 }
817839
818-
819840 internal void SelectAllEvents ( bool select ) {
820841 lock ( m_Cached ) {
821842 lvEvents . BeginUpdate ( ) ;
@@ -833,13 +854,6 @@ internal void SelectAllEvents(bool select) {
833854 }
834855 }
835856
836- private void lvEvents_KeyDown ( object sender , KeyEventArgs e ) {
837- }
838-
839- private void MainForm_Load ( object sender , EventArgs e ) {
840- }
841-
842-
843857 private void timer1_Tick ( object sender , EventArgs e ) {
844858 Queue < ProfilerEvent > saved ;
845859 Exception exc ;
@@ -988,7 +1002,6 @@ private void extractSelectedEventsToolStripMenuItem_Click(object sender, EventAr
9881002 CopyEventsToClipboard ( true ) ;
9891003 }
9901004
991-
9921005 private void pauseTraceToolStripMenuItem_Click ( object sender , EventArgs e ) {
9931006 PauseProfiling ( ) ;
9941007 }
@@ -1050,7 +1063,6 @@ private void selectAllToolStripMenuItem_Click(object sender, EventArgs e) {
10501063 // MessageBox.Show(String.Format("Failed to find \"{0}\". Searched to the end of data. ", lastpattern), "SqlProfiler", MessageBoxButtons.OK, MessageBoxIcon.Information);
10511064 //}
10521065
1053-
10541066 internal void PerformFind ( bool forwards , bool wrapAround ) {
10551067 if ( String . IsNullOrEmpty ( lastpattern ) ) return ;
10561068 int lastpos = lvEvents . Items . IndexOf ( lvEvents . FocusedItem ) ;
@@ -1089,7 +1101,6 @@ internal void PerformFind(bool forwards, bool wrapAround) {
10891101 "SqlProfiler" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
10901102 }
10911103
1092-
10931104 private void ShowSelectedEvent ( ) {
10941105 int focusedIndex = lvEvents . Items . IndexOf ( lvEvents . FocusedItem ) ;
10951106 if ( ( focusedIndex > - 1 ) && ( focusedIndex < m_Cached . Count ) ) {
@@ -1103,7 +1114,6 @@ private void ShowSelectedEvent() {
11031114 }
11041115 }
11051116
1106-
11071117 private bool FindText ( int i ) {
11081118 ListViewItem lvi = m_Cached [ i ] ;
11091119 ProfilerEvent evt = ( ProfilerEvent ) lvi . Tag ;
@@ -1320,7 +1330,6 @@ private void keepSelectedToolStripMenuItem_Click(object sender, EventArgs e) {
13201330 lvEvents . SelectedIndices . Clear ( ) ;
13211331 }
13221332
1323-
13241333 private void SaveToExcelXmlFile ( ) {
13251334 XmlDocument doc = new XmlDocument ( ) ;
13261335 XmlProcessingInstruction pi = doc . CreateProcessingInstruction ( "mso-application" , "progid='Excel.Sheet'" ) ;
@@ -1450,7 +1459,6 @@ private void SaveToExcelXmlFile() {
14501459 }
14511460 }
14521461
1453-
14541462 private void SetFilterEvents ( ) {
14551463 if ( m_CachedUnFiltered . Count == 0 ) {
14561464 lvEvents . SelectedIndices . Clear ( ) ;
@@ -1475,7 +1483,6 @@ private void SetFilterEvents() {
14751483 }
14761484 }
14771485
1478-
14791486 private void ClearFilterEvents ( ) {
14801487 if ( m_CachedUnFiltered . Count > 0 ) {
14811488 m_Cached . Clear ( ) ;
@@ -1488,30 +1495,21 @@ private void ClearFilterEvents() {
14881495 }
14891496 }
14901497
1491-
14921498 private void saveAllEventsToExcelXmlFileToolStripMenuItem_Click ( object sender , EventArgs e ) {
14931499 SaveToExcelXmlFile ( ) ;
14941500 }
14951501
1496- /// <summary>
1497- /// Persist the server string when it changes.
1498- /// </summary>
1499- /// <param name="sender"></param>
1500- /// <param name="e"></param>
15011502 private void edServer_TextChanged ( object sender , EventArgs e ) {
1502- m_servername = edServer . Text ;
1503+ Config . Instance . Server = edServer . Text ;
15031504 }
15041505
1505-
1506- /// <summary>
1507- /// Persist the user name string when it changes.
1508- /// </summary>
1509- /// <param name="sender"></param>
1510- /// <param name="e"></param>
15111506 private void edUser_TextChanged ( object sender , EventArgs e ) {
1512- m_username = edUser . Text ;
1507+ Config . Instance . User = edUser . Text ;
15131508 }
15141509
1510+ private void edPassword_TextChanged ( object sender , EventArgs e ) {
1511+ Config . Instance . Password = edPassword . Text ;
1512+ }
15151513
15161514 private void filterCapturedEventsToolStripMenuItem_Click ( object sender , EventArgs e ) {
15171515 SetFilterEvents ( ) ;
0 commit comments