File: MainForm.cs

package info (click to toggle)
nini 1.1.0%2Bdfsg-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,776 kB
  • ctags: 882
  • sloc: cs: 7,649; xml: 2,945; makefile: 62; ansic: 7
file content (272 lines) | stat: -rw-r--r-- 9,302 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Diagnostics;

// Includes Nini namespace (don't forget to add the reference in your project)
using Nini.Config;

namespace BasicApp
{
	/// <summary>
	/// Windows forms application that demonstrates some of Nini's 
	/// core features.
	/// </summary>
	public class MainForm : System.Windows.Forms.Form
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.GroupBox loggingGroup;
		private System.Windows.Forms.Label logFileNameLabel;
		private System.Windows.Forms.TextBox logFileNameText;
		private System.Windows.Forms.TextBox maxFileSizeText;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Button viewIniButton;
		private System.Windows.Forms.Button saveIniButton;
		private System.Windows.Forms.TextBox userEmailText;
		private System.Windows.Forms.Label userEmailLabel;
		private System.Windows.Forms.TextBox userNameText;
		private System.Windows.Forms.Label userNameLabel;
		private System.Windows.Forms.Button closeButton;
		private IConfigSource source = null;

		public MainForm ()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent ();

			LoadConfigs ();
		}

		/// <summary>
		/// Loads all configuration values into the UI controls.
		/// </summary>
		private void LoadConfigs ()
		{
			// Load the configuration source file
			source = new IniConfigSource (@"..\..\BasicApp.ini");

			// Set the config to the Logging section of the INI file.
			IConfig config = source.Configs["Logging"];

			// Load up some normal configuration values
			logFileNameText.Text = config.Get ("File Name");
			maxFileSizeText.Text = config.Get ("MaxFileSize");
			userNameText.Text = source.Configs["User"].Get ("Name");
			userEmailText.Text = source.Configs["User"].Get ("Email");
		}

		#region Required methods
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run (new MainForm ());
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose (bool disposing)
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}
		#endregion

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.logFileNameLabel = new System.Windows.Forms.Label();
			this.loggingGroup = new System.Windows.Forms.GroupBox();
			this.userNameText = new System.Windows.Forms.TextBox();
			this.userNameLabel = new System.Windows.Forms.Label();
			this.saveIniButton = new System.Windows.Forms.Button();
			this.viewIniButton = new System.Windows.Forms.Button();
			this.maxFileSizeText = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.logFileNameText = new System.Windows.Forms.TextBox();
			this.userEmailText = new System.Windows.Forms.TextBox();
			this.userEmailLabel = new System.Windows.Forms.Label();
			this.closeButton = new System.Windows.Forms.Button();
			this.loggingGroup.SuspendLayout();
			this.SuspendLayout();
			// 
			// logFileNameLabel
			// 
			this.logFileNameLabel.Location = new System.Drawing.Point(16, 32);
			this.logFileNameLabel.Name = "logFileNameLabel";
			this.logFileNameLabel.Size = new System.Drawing.Size(88, 16);
			this.logFileNameLabel.TabIndex = 1;
			this.logFileNameLabel.Text = "Log File Name:";
			// 
			// loggingGroup
			// 
			this.loggingGroup.Controls.AddRange(new System.Windows.Forms.Control[] {
																					   this.closeButton,
																					   this.userNameText,
																					   this.userNameLabel,
																					   this.saveIniButton,
																					   this.viewIniButton,
																					   this.maxFileSizeText,
																					   this.label1,
																					   this.logFileNameText,
																					   this.logFileNameLabel,
																					   this.userEmailText,
																					   this.userEmailLabel});
			this.loggingGroup.Location = new System.Drawing.Point(16, 24);
			this.loggingGroup.Name = "loggingGroup";
			this.loggingGroup.Size = new System.Drawing.Size(440, 200);
			this.loggingGroup.TabIndex = 2;
			this.loggingGroup.TabStop = false;
			this.loggingGroup.Text = "IConfigs (Sections) in INI file";
			// 
			// userNameText
			// 
			this.userNameText.Location = new System.Drawing.Point(128, 120);
			this.userNameText.Name = "userNameText";
			this.userNameText.Size = new System.Drawing.Size(152, 20);
			this.userNameText.TabIndex = 12;
			this.userNameText.Text = "";
			// 
			// userNameLabel
			// 
			this.userNameLabel.Location = new System.Drawing.Point(16, 120);
			this.userNameLabel.Name = "userNameLabel";
			this.userNameLabel.Size = new System.Drawing.Size(88, 16);
			this.userNameLabel.TabIndex = 11;
			this.userNameLabel.Text = "User Name";
			// 
			// saveIniButton
			// 
			this.saveIniButton.Location = new System.Drawing.Point(312, 32);
			this.saveIniButton.Name = "saveIniButton";
			this.saveIniButton.Size = new System.Drawing.Size(112, 23);
			this.saveIniButton.TabIndex = 8;
			this.saveIniButton.Text = "Save Changes";
			this.saveIniButton.Click += new System.EventHandler(this.saveIniButton_Click);
			// 
			// viewIniButton
			// 
			this.viewIniButton.Location = new System.Drawing.Point(312, 72);
			this.viewIniButton.Name = "viewIniButton";
			this.viewIniButton.Size = new System.Drawing.Size(112, 23);
			this.viewIniButton.TabIndex = 7;
			this.viewIniButton.Text = "View INI File";
			this.viewIniButton.Click += new System.EventHandler(this.viewIniButton_Click);
			// 
			// maxFileSizeText
			// 
			this.maxFileSizeText.Location = new System.Drawing.Point(128, 72);
			this.maxFileSizeText.Name = "maxFileSizeText";
			this.maxFileSizeText.Size = new System.Drawing.Size(152, 20);
			this.maxFileSizeText.TabIndex = 4;
			this.maxFileSizeText.Text = "";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 72);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(104, 16);
			this.label1.TabIndex = 3;
			this.label1.Text = "Log File Max Size:";
			// 
			// logFileNameText
			// 
			this.logFileNameText.Location = new System.Drawing.Point(128, 32);
			this.logFileNameText.Name = "logFileNameText";
			this.logFileNameText.Size = new System.Drawing.Size(152, 20);
			this.logFileNameText.TabIndex = 2;
			this.logFileNameText.Text = "";
			// 
			// userEmailText
			// 
			this.userEmailText.Location = new System.Drawing.Point(128, 160);
			this.userEmailText.Name = "userEmailText";
			this.userEmailText.Size = new System.Drawing.Size(152, 20);
			this.userEmailText.TabIndex = 10;
			this.userEmailText.Text = "";
			// 
			// userEmailLabel
			// 
			this.userEmailLabel.Location = new System.Drawing.Point(16, 160);
			this.userEmailLabel.Name = "userEmailLabel";
			this.userEmailLabel.Size = new System.Drawing.Size(88, 16);
			this.userEmailLabel.TabIndex = 9;
			this.userEmailLabel.Text = "User Email";
			// 
			// closeButton
			// 
			this.closeButton.Location = new System.Drawing.Point(312, 120);
			this.closeButton.Name = "closeButton";
			this.closeButton.Size = new System.Drawing.Size(112, 23);
			this.closeButton.TabIndex = 13;
			this.closeButton.Text = "Close";
			this.closeButton.Click += new System.EventHandler(this.closeButton_Click);
			// 
			// MainForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(472, 245);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.loggingGroup});
			this.Name = "MainForm";
			this.Text = "Nini C# BasicApp";
			this.loggingGroup.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// Handles saving the file.
		/// </summary>
		private void saveIniButton_Click (object sender, System.EventArgs e)
		{
			source.Configs["Logging"].Set ("File Name", logFileNameText.Text);
			source.Configs["Logging"].Set ("MaxFileSize", maxFileSizeText.Text);

			source.Configs["User"].Set ("Name", userNameText.Text);
			source.Configs["User"].Set ("Email", userEmailText.Text);

			// Save the INI file
			source.Save ();
		}

		/// <summary>
		/// Loads up the INI file in whatever editor is the default.
		/// </summary>
		private void viewIniButton_Click (object sender, System.EventArgs e)
		{
			Process.Start("notepad.exe", @"..\..\BasicApp.ini");
		}

		/// <summary>
		/// Handles the close button event.
		/// </summary>
		private void closeButton_Click (object sender, System.EventArgs e)
		{
			this.Close ();
		}

	}
}