Changeset 1018 for trunk/sources/HeuristicLab.Hive.Server.Console
- Timestamp:
- 12/17/08 16:52:15 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Hive.Server.Console
- Files:
-
- 6 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Hive.Server.Console/HeuristicLab.Hive.Server.Console.csproj
r978 r1018 73 73 </ItemGroup> 74 74 <ItemGroup> 75 <Compile Include="Add NewForm.cs">75 <Compile Include="AddUserForm.cs"> 76 76 <SubType>Form</SubType> 77 77 </Compile> 78 <Compile Include="AddNewForm.Designer.cs"> 79 <DependentUpon>AddNewForm.cs</DependentUpon> 78 <Compile Include="AddUserForm.Designer.cs"> 79 <DependentUpon>AddUserForm.cs</DependentUpon> 80 </Compile> 81 <Compile Include="AddJobForm.cs"> 82 <SubType>Form</SubType> 83 </Compile> 84 <Compile Include="AddJobForm.Designer.cs"> 85 <DependentUpon>AddJobForm.cs</DependentUpon> 80 86 </Compile> 81 87 <Compile Include="HiveServerConsole.cs"> … … 94 100 <Compile Include="HiveServerConsolePlugin.cs" /> 95 101 <Compile Include="IPAdressTextBox.cs"> 96 <SubType>Component</SubType>97 102 </Compile> 98 103 <Compile Include="Properties\AssemblyInfo.cs" /> 99 <EmbeddedResource Include="AddNewForm.resx"> 100 <DependentUpon>AddNewForm.cs</DependentUpon> 104 <EmbeddedResource Include="AddUserForm.resx"> 105 <DependentUpon>AddUserForm.cs</DependentUpon> 106 </EmbeddedResource> 107 <EmbeddedResource Include="AddJobForm.resx"> 108 <DependentUpon>AddJobForm.cs</DependentUpon> 101 109 </EmbeddedResource> 102 110 <EmbeddedResource Include="HiveServerConsole.resx"> -
trunk/sources/HeuristicLab.Hive.Server.Console/HiveServerConsole.Designer.cs
r978 r1018 59 59 this.tbPwd = new System.Windows.Forms.TextBox(); 60 60 this.lblError = new System.Windows.Forms.Label(); 61 this.tbIp = new HeuristicLab.Hive.Server.Console.IPAddressTextBox();61 this.tbIp = new System.Windows.Forms.TextBox(); 62 62 this.msServerConsole.SuspendLayout(); 63 63 this.gbManager.SuspendLayout(); -
trunk/sources/HeuristicLab.Hive.Server.Console/HiveServerConsole.cs
r978 r1018 104 104 } else if (tbPort.Text == "") { 105 105 lblError.Text = "Please type in Port"; 106 } else if (tbIp.Text == "") { 107 lblError.Text = "Please type in IP-Adress"; 106 108 } 107 109 return false; -
trunk/sources/HeuristicLab.Hive.Server.Console/HiveServerManagementConsole.Designer.cs
r978 r1018 25 25 private void InitializeComponent() { 26 26 this.components = new System.ComponentModel.Container(); 27 System.Windows.Forms.ListViewItem listViewItem 1= new System.Windows.Forms.ListViewItem(new string[] {27 System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem(new string[] { 28 28 "", 29 29 "Test"}, -1); … … 34 34 this.addToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 35 35 this.jobToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 36 this.jobToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();37 this.groupToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();38 36 this.userToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 39 37 this.userToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); … … 43 41 this.scClientControl = new System.Windows.Forms.SplitContainer(); 44 42 this.tvClientControl = new System.Windows.Forms.TreeView(); 45 this.cmsAddDelete = new System.Windows.Forms.ContextMenuStrip(this.components);46 this.tsmiDelete = new System.Windows.Forms.ToolStripMenuItem();47 43 this.lvClientControl = new System.Windows.Forms.ListView(); 48 44 this.imageList1 = new System.Windows.Forms.ImageList(this.components); … … 50 46 this.scJobControl = new System.Windows.Forms.SplitContainer(); 51 47 this.tvJobControl = new System.Windows.Forms.TreeView(); 52 this.l istView3= new System.Windows.Forms.ListView();48 this.lvJobControl = new System.Windows.Forms.ListView(); 53 49 this.tpUserControl = new System.Windows.Forms.TabPage(); 54 50 this.scUserControl = new System.Windows.Forms.SplitContainer(); … … 59 55 this.listView2 = new System.Windows.Forms.ListView(); 60 56 this.directorySearcher1 = new System.DirectoryServices.DirectorySearcher(); 57 this.timerSyncronize = new System.Windows.Forms.Timer(this.components); 58 this.imageList3 = new System.Windows.Forms.ImageList(this.components); 61 59 this.menuStrip1.SuspendLayout(); 62 60 this.tcManagementConsole.SuspendLayout(); … … 65 63 this.scClientControl.Panel2.SuspendLayout(); 66 64 this.scClientControl.SuspendLayout(); 67 this.cmsAddDelete.SuspendLayout();68 65 this.tpJobControl.SuspendLayout(); 69 66 this.scJobControl.Panel1.SuspendLayout(); … … 98 95 // 99 96 this.closeToolStripMenuItem.Name = "closeToolStripMenuItem"; 100 this.closeToolStripMenuItem.Size = new System.Drawing.Size(1 52, 22);97 this.closeToolStripMenuItem.Size = new System.Drawing.Size(111, 22); 101 98 this.closeToolStripMenuItem.Text = "Close"; 102 99 this.closeToolStripMenuItem.Click += new System.EventHandler(this.close_Click); … … 113 110 // jobToolStripMenuItem 114 111 // 115 this.jobToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {116 this.jobToolStripMenuItem1,117 this.groupToolStripMenuItem1});118 112 this.jobToolStripMenuItem.Name = "jobToolStripMenuItem"; 119 113 this.jobToolStripMenuItem.Size = new System.Drawing.Size(152, 22); 120 114 this.jobToolStripMenuItem.Text = "Job"; 121 // 122 // jobToolStripMenuItem1 123 // 124 this.jobToolStripMenuItem1.Name = "jobToolStripMenuItem1"; 125 this.jobToolStripMenuItem1.Size = new System.Drawing.Size(114, 22); 126 this.jobToolStripMenuItem1.Text = "Job"; 127 this.jobToolStripMenuItem1.Click += new System.EventHandler(this.jobToolStripMenuItem1_Click); 128 // 129 // groupToolStripMenuItem1 130 // 131 this.groupToolStripMenuItem1.Name = "groupToolStripMenuItem1"; 132 this.groupToolStripMenuItem1.Size = new System.Drawing.Size(114, 22); 133 this.groupToolStripMenuItem1.Text = "Group"; 115 this.jobToolStripMenuItem.Click += new System.EventHandler(this.jobToolStripMenuItem1_Click); 134 116 // 135 117 // userToolStripMenuItem … … 139 121 this.groupToolStripMenuItem2}); 140 122 this.userToolStripMenuItem.Name = "userToolStripMenuItem"; 141 this.userToolStripMenuItem.Size = new System.Drawing.Size(1 52, 22);123 this.userToolStripMenuItem.Size = new System.Drawing.Size(107, 22); 142 124 this.userToolStripMenuItem.Text = "User"; 143 125 // … … 145 127 // 146 128 this.userToolStripMenuItem1.Name = "userToolStripMenuItem1"; 147 this.userToolStripMenuItem1.Size = new System.Drawing.Size(1 52, 22);129 this.userToolStripMenuItem1.Size = new System.Drawing.Size(114, 22); 148 130 this.userToolStripMenuItem1.Text = "User"; 149 131 this.userToolStripMenuItem1.Click += new System.EventHandler(this.userToolStripMenuItem1_Click); … … 152 134 // 153 135 this.groupToolStripMenuItem2.Name = "groupToolStripMenuItem2"; 154 this.groupToolStripMenuItem2.Size = new System.Drawing.Size(1 52, 22);136 this.groupToolStripMenuItem2.Size = new System.Drawing.Size(114, 22); 155 137 this.groupToolStripMenuItem2.Text = "Group"; 156 138 this.groupToolStripMenuItem2.Click += new System.EventHandler(this.groupToolStripMenuItem2_Click); … … 199 181 // tvClientControl 200 182 // 201 this.tvClientControl.ContextMenuStrip = this.cmsAddDelete;202 183 this.tvClientControl.Dock = System.Windows.Forms.DockStyle.Fill; 203 184 this.tvClientControl.Location = new System.Drawing.Point(0, 0); … … 206 187 this.tvClientControl.TabIndex = 0; 207 188 // 208 // cmsAddDelete209 //210 this.cmsAddDelete.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {211 this.tsmiDelete});212 this.cmsAddDelete.Name = "cmsAddDelete";213 this.cmsAddDelete.Size = new System.Drawing.Size(117, 26);214 //215 // tsmiDelete216 //217 this.tsmiDelete.Name = "tsmiDelete";218 this.tsmiDelete.Size = new System.Drawing.Size(116, 22);219 this.tsmiDelete.Text = "Delete";220 //221 189 // lvClientControl 222 190 // … … 224 192 this.lvClientControl.ImeMode = System.Windows.Forms.ImeMode.Off; 225 193 this.lvClientControl.Items.AddRange(new System.Windows.Forms.ListViewItem[] { 226 listViewItem 1});194 listViewItem2}); 227 195 this.lvClientControl.LargeImageList = this.imageList1; 228 196 this.lvClientControl.Location = new System.Drawing.Point(0, 0); … … 263 231 // scJobControl.Panel2 264 232 // 265 this.scJobControl.Panel2.Controls.Add(this.l istView3);233 this.scJobControl.Panel2.Controls.Add(this.lvJobControl); 266 234 this.scJobControl.Size = new System.Drawing.Size(637, 346); 267 235 this.scJobControl.SplitterDistance = 139; … … 270 238 // tvJobControl 271 239 // 272 this.tvJobControl.ContextMenuStrip = this.cmsAddDelete;273 240 this.tvJobControl.Dock = System.Windows.Forms.DockStyle.Fill; 274 241 this.tvJobControl.Location = new System.Drawing.Point(0, 0); … … 277 244 this.tvJobControl.TabIndex = 2; 278 245 // 279 // listView3 280 // 281 this.listView3.Dock = System.Windows.Forms.DockStyle.Fill; 282 this.listView3.Location = new System.Drawing.Point(0, 0); 283 this.listView3.Name = "listView3"; 284 this.listView3.Size = new System.Drawing.Size(494, 346); 285 this.listView3.TabIndex = 0; 286 this.listView3.UseCompatibleStateImageBehavior = false; 246 // lvJobControl 247 // 248 this.lvJobControl.Dock = System.Windows.Forms.DockStyle.Fill; 249 this.lvJobControl.LargeImageList = this.imageList3; 250 this.lvJobControl.Location = new System.Drawing.Point(0, 0); 251 this.lvJobControl.Name = "lvJobControl"; 252 this.lvJobControl.Size = new System.Drawing.Size(494, 346); 253 this.lvJobControl.TabIndex = 0; 254 this.lvJobControl.UseCompatibleStateImageBehavior = false; 287 255 // 288 256 // tpUserControl … … 316 284 // tvUserControl 317 285 // 318 this.tvUserControl.ContextMenuStrip = this.cmsAddDelete;319 286 this.tvUserControl.Dock = System.Windows.Forms.DockStyle.Fill; 320 287 this.tvUserControl.Location = new System.Drawing.Point(0, 0); … … 362 329 this.directorySearcher1.ServerPageTimeLimit = System.TimeSpan.Parse("-00:00:01"); 363 330 this.directorySearcher1.ServerTimeLimit = System.TimeSpan.Parse("-00:00:01"); 331 // 332 // timerSyncronize 333 // 334 this.timerSyncronize.Interval = 10000; 335 // 336 // imageList3 337 // 338 this.imageList3.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList3.ImageStream"))); 339 this.imageList3.TransparentColor = System.Drawing.Color.Transparent; 340 this.imageList3.Images.SetKeyName(0, "PlayHS.bmp"); 364 341 // 365 342 // HiveServerManagementConsole … … 381 358 this.scClientControl.Panel2.ResumeLayout(false); 382 359 this.scClientControl.ResumeLayout(false); 383 this.cmsAddDelete.ResumeLayout(false);384 360 this.tpJobControl.ResumeLayout(false); 385 361 this.scJobControl.Panel1.ResumeLayout(false); … … 408 384 private System.Windows.Forms.ListView lvClientControl; 409 385 private System.Windows.Forms.SplitContainer scJobControl; 410 private System.Windows.Forms.ListView l istView3;386 private System.Windows.Forms.ListView lvJobControl; 411 387 private System.Windows.Forms.SplitContainer scUserControl; 412 388 private System.Windows.Forms.TreeView treeView2; … … 419 395 private System.Windows.Forms.ToolStripMenuItem jobToolStripMenuItem; 420 396 private System.Windows.Forms.ToolStripMenuItem userToolStripMenuItem; 421 private System.Windows.Forms.ToolStripMenuItem jobToolStripMenuItem1;422 private System.Windows.Forms.ToolStripMenuItem groupToolStripMenuItem1;423 397 private System.Windows.Forms.ToolStripMenuItem userToolStripMenuItem1; 424 398 private System.Windows.Forms.ToolStripMenuItem groupToolStripMenuItem2; 425 private System.Windows.Forms.ContextMenuStrip cmsAddDelete;426 private System.Windows.Forms.ToolStripMenuItem tsmiDelete;427 399 private System.Windows.Forms.ImageList imageList2; 428 400 private System.DirectoryServices.DirectorySearcher directorySearcher1; 401 private System.Windows.Forms.Timer timerSyncronize; 402 private System.Windows.Forms.ImageList imageList3; 429 403 } 430 404 } -
trunk/sources/HeuristicLab.Hive.Server.Console/HiveServerManagementConsole.cs
r995 r1018 41 41 42 42 ResponseList<ClientGroup> clients = null; 43 ResponseList<ClientInfo> clientInfo = null; 43 44 ResponseList<Job> jobs = null; 44 45 ResponseList<UserGroup> userGroups = null; 46 ResponseList<User> usersList = null; 45 47 46 48 public HiveServerManagementConsole() { 47 49 InitializeComponent(); 48 addItems(); 50 addClients(); 51 addJobs(); 52 addUsers(); 53 54 timerSyncronize.Tick += new EventHandler(tickSync); 55 timerSyncronize.Start(); 49 56 } 50 57 51 private void addItems() { 58 private void tickSync(object obj, EventArgs e) { 59 addClients(); 60 addJobs(); 61 addUsers(); 62 } 63 64 private void addClients() { 52 65 IClientManager clientManager = 53 66 ServiceLocator.GetClientManager(); 54 67 55 IJobManager jobManager =56 ServiceLocator.GetJobManager();57 58 IUserRoleManager userRoleManager =59 ServiceLocator.GetUserRoleManager();60 61 62 68 clients = clientManager.GetAllClientGroups(); 63 jobs = jobManager.GetAllJobs();64 65 userGroups = userRoleManager.GetAllUserGroups();66 69 67 70 lvClientControl.Items.Clear(); 71 tvClientControl.Nodes.Clear(); 68 72 int count = 0; 69 73 foreach (ClientGroup cg in clients.List) { … … 78 82 } // Groups 79 83 84 clientInfo = clientManager.GetAllClients(); 85 ListViewGroup lvunsorted = new ListViewGroup("unsorted", HorizontalAlignment.Left); 86 foreach (ClientInfo ci in clientInfo.List) { 87 tvClientControl.Nodes.Add(ci.Name); 88 lvClientControl.Items.Add(new ListViewItem(ci.Name, count, lvunsorted)); 89 count = (count + 1) % 3; 90 } 91 lvClientControl.Groups.Add(lvunsorted); 92 } 93 94 private void addJobs() { 95 IJobManager jobManager = 96 ServiceLocator.GetJobManager(); 97 jobs = jobManager.GetAllJobs(); 98 99 lvJobControl.Items.Clear(); 100 tvJobControl.Nodes.Clear(); 80 101 81 102 foreach (Job job in jobs.List) { 82 103 tvJobControl.Nodes.Add(job.Id.ToString()); 104 lvJobControl.Items.Add(new ListViewItem(job.Id.ToString(), 0)); 83 105 } // Jobs 106 107 } 108 109 private void addUsers() { 110 IUserRoleManager userRoleManager = 111 ServiceLocator.GetUserRoleManager(); 112 113 userGroups = userRoleManager.GetAllUserGroups(); 114 115 lvUserControl.Items.Clear(); 116 tvUserControl.Nodes.Clear(); 84 117 85 118 foreach (UserGroup ug in userGroups.List) { … … 87 120 ListViewGroup lvg = new ListViewGroup(ug.Name, HorizontalAlignment.Left); 88 121 89 foreach (User users in ug.Members) { 90 tvUserControl.Nodes[tvUserControl.Nodes.Count - 1].Nodes.Add(users.Name); 91 lvUserControl.Items.Add(new ListViewItem(users.Name, count, lvg)); 122 foreach (PermissionOwner permOwner in ug.Members) { 123 if (permOwner is User) { 124 User users = permOwner as User; 125 tvUserControl.Nodes[tvUserControl.Nodes.Count - 1].Nodes.Add(users.Name); 126 lvUserControl.Items.Add(new ListViewItem(users.Name, 0, lvg)); 127 } 92 128 } 93 129 lvUserControl.Groups.Add(lvg); 130 94 131 } // Users 132 usersList = userRoleManager.GetAllUsers(); 133 ListViewGroup lvunsorted = new ListViewGroup("unsorted", HorizontalAlignment.Left); 134 foreach (User u in usersList.List) { 135 tvUserControl.Nodes.Add(u.Name); 136 lvUserControl.Items.Add(new ListViewItem(u.Name, 0, lvunsorted)); 137 } 138 lvUserControl.Groups.Add(lvunsorted); 95 139 } 96 140 … … 120 164 121 165 private void jobToolStripMenuItem1_Click(object sender, EventArgs e) { 122 Add NewForm newForm = new AddNewForm("Job", false);166 AddJobForm newForm = new AddJobForm(); 123 167 newForm.Show(); 124 168 } 125 169 126 170 private void userToolStripMenuItem1_Click(object sender, EventArgs e) { 127 Add NewForm newForm = new AddNewForm("User", false);171 AddUserForm newForm = new AddUserForm("User", false); 128 172 newForm.Show(); 129 173 } 130 174 131 175 private void groupToolStripMenuItem2_Click(object sender, EventArgs e) { 132 Add NewForm newForm = new AddNewForm("User", true);176 AddUserForm newForm = new AddUserForm("User", true); 133 177 newForm.Show(); 134 178 -
trunk/sources/HeuristicLab.Hive.Server.Console/HiveServerManagementConsole.resx
r978 r1018 119 119 </resheader> 120 120 <metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> 121 <value>17, 17</value> 122 </metadata> 123 <metadata name="cmsAddDelete.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> 124 <value>231, 22</value> 121 <value>139, 17</value> 125 122 </metadata> 126 123 <metadata name="imageList1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> 127 <value> 126, 17</value>124 <value>248, 17</value> 128 125 </metadata> 129 126 <data name="imageList1.ImageStream" mimetype="application/x-microsoft.net.object.binary.base64"> … … 218 215 </value> 219 216 </data> 217 <metadata name="imageList3.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> 218 <value>17, 54</value> 219 </metadata> 220 <data name="imageList3.ImageStream" mimetype="application/x-microsoft.net.object.binary.base64"> 221 <value> 222 AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w 223 LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 224 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAAG 225 CQAAAk1TRnQBSQFMAwEBAAEFAQABBAEAASABAAEgAQAE/wEJAQAI/wFCAU0BNgEEBgABNgEEAgABKAMA 226 AYADAAEgAwABAQEAAQgGAAEQGAABgAIAAYADAAKAAQABgAMAAYABAAGAAQACgAIAA8ABAAHAAdwBwAEA 227 AfABygGmAQABMwUAATMBAAEzAQABMwEAAjMCAAMWAQADHAEAAyIBAAMpAQADVQEAA00BAANCAQADOQEA 228 AYABfAH/AQACUAH/AQABkwEAAdYBAAH/AewBzAEAAcYB1gHvAQAB1gLnAQABkAGpAa0CAAH/ATMDAAFm 229 AwABmQMAAcwCAAEzAwACMwIAATMBZgIAATMBmQIAATMBzAIAATMB/wIAAWYDAAFmATMCAAJmAgABZgGZ 230 AgABZgHMAgABZgH/AgABmQMAAZkBMwIAAZkBZgIAApkCAAGZAcwCAAGZAf8CAAHMAwABzAEzAgABzAFm 231 AgABzAGZAgACzAIAAcwB/wIAAf8BZgIAAf8BmQIAAf8BzAEAATMB/wIAAf8BAAEzAQABMwEAAWYBAAEz 232 AQABmQEAATMBAAHMAQABMwEAAf8BAAH/ATMCAAMzAQACMwFmAQACMwGZAQACMwHMAQACMwH/AQABMwFm 233 AgABMwFmATMBAAEzAmYBAAEzAWYBmQEAATMBZgHMAQABMwFmAf8BAAEzAZkCAAEzAZkBMwEAATMBmQFm 234 AQABMwKZAQABMwGZAcwBAAEzAZkB/wEAATMBzAIAATMBzAEzAQABMwHMAWYBAAEzAcwBmQEAATMCzAEA 235 ATMBzAH/AQABMwH/ATMBAAEzAf8BZgEAATMB/wGZAQABMwH/AcwBAAEzAv8BAAFmAwABZgEAATMBAAFm 236 AQABZgEAAWYBAAGZAQABZgEAAcwBAAFmAQAB/wEAAWYBMwIAAWYCMwEAAWYBMwFmAQABZgEzAZkBAAFm 237 ATMBzAEAAWYBMwH/AQACZgIAAmYBMwEAA2YBAAJmAZkBAAJmAcwBAAFmAZkCAAFmAZkBMwEAAWYBmQFm 238 AQABZgKZAQABZgGZAcwBAAFmAZkB/wEAAWYBzAIAAWYBzAEzAQABZgHMAZkBAAFmAswBAAFmAcwB/wEA 239 AWYB/wIAAWYB/wEzAQABZgH/AZkBAAFmAf8BzAEAAcwBAAH/AQAB/wEAAcwBAAKZAgABmQEzAZkBAAGZ 240 AQABmQEAAZkBAAHMAQABmQMAAZkCMwEAAZkBAAFmAQABmQEzAcwBAAGZAQAB/wEAAZkBZgIAAZkBZgEz 241 AQABmQEzAWYBAAGZAWYBmQEAAZkBZgHMAQABmQEzAf8BAAKZATMBAAKZAWYBAAOZAQACmQHMAQACmQH/ 242 AQABmQHMAgABmQHMATMBAAFmAcwBZgEAAZkBzAGZAQABmQLMAQABmQHMAf8BAAGZAf8CAAGZAf8BMwEA 243 AZkBzAFmAQABmQH/AZkBAAGZAf8BzAEAAZkC/wEAAcwDAAGZAQABMwEAAcwBAAFmAQABzAEAAZkBAAHM 244 AQABzAEAAZkBMwIAAcwCMwEAAcwBMwFmAQABzAEzAZkBAAHMATMBzAEAAcwBMwH/AQABzAFmAgABzAFm 245 ATMBAAGZAmYBAAHMAWYBmQEAAcwBZgHMAQABmQFmAf8BAAHMAZkCAAHMAZkBMwEAAcwBmQFmAQABzAKZ 246 AQABzAGZAcwBAAHMAZkB/wEAAswCAALMATMBAALMAWYBAALMAZkBAAPMAQACzAH/AQABzAH/AgABzAH/ 247 ATMBAAGZAf8BZgEAAcwB/wGZAQABzAH/AcwBAAHMAv8BAAHMAQABMwEAAf8BAAFmAQAB/wEAAZkBAAHM 248 ATMCAAH/AjMBAAH/ATMBZgEAAf8BMwGZAQAB/wEzAcwBAAH/ATMB/wEAAf8BZgIAAf8BZgEzAQABzAJm 249 AQAB/wFmAZkBAAH/AWYBzAEAAcwBZgH/AQAB/wGZAgAB/wGZATMBAAH/AZkBZgEAAf8CmQEAAf8BmQHM 250 AQAB/wGZAf8BAAH/AcwCAAH/AcwBMwEAAf8BzAFmAQAB/wHMAZkBAAH/AswBAAH/AcwB/wEAAv8BMwEA 251 AcwB/wFmAQAC/wGZAQAC/wHMAQACZgH/AQABZgH/AWYBAAFmAv8BAAH/AmYBAAH/AWYB/wEAAv8BZgEA 252 ASEBAAGlAQADXwEAA3cBAAOGAQADlgEAA8sBAAOyAQAD1wEAA90BAAPjAQAD6gEAA/EBAAP4AQAB8AH7 253 Af8BAAGkAqABAAOAAwAB/wIAAf8DAAL/AQAB/wMAAf8BAAH/AQAC/wIAA/8BAB9fAYV/AAFffwABX38A 254 AV9pAAEOASEBDhMAAV9pAAEhAUkBIRMAAV9pAAEhAigBIQEOEQABX2kAASEBJwEoAUkBIREAAV9pAAEh 255 BCgBIQEODwABX2kAASEBKAInASgBSQEhDwABX2kAASEGKAEhAQ4NAAFfaQABIQNJASgBJwEoAUkBIQ0A 256 AV9pAAEhBEkEKAEhAQ4LAAFfaQABIQJJAU8CSQEoAScBKAFJASELAAFfaQABEAFJA08CSQQoASEBDgkA 257 AV9pAAEQAUkBTwFyAk8CSQEoAScBKAFJASEJAAFfaQABEQJPAXIBUAJPAkkEKAEhAQ4HAAFfaQABEQFP 258 AVABlwJyAk8CSQMoAUkBIQcAAV9pAAERAU8BcgOXAVACTwFJAk8BSQEhAQ4HAAFfaQABQwFPAXIElwFy 259 AU8BSQFQAZcBSQkAAV9pAAFDAVABcgGXAXgBmAFyAU8CUAJJARAJAAFfaQABQwFQAXIBlwGYAQgBcgFJ 260 AVABlwFJCwABX2kAARUBUAGXAZgBeAJyAVACSQEQCwABX2kAARUBcgF4AQgBcgFJAVABlwFJDQABX2kA 261 ARUEcgFQAkkBEA0AAV9pAAEVAXIBTwFJAVABlwFJDwABX2kAARUCcgFQAkkBEA8AAV9pAAEVAnIBlwFJ 262 EQABX2kAAUkBcgFQAUkBEBEAAV9pAAFJAZcBSRMAAV9pAAEQAUkBEBMAAV9/AAFfYAABQgFNAT4HAAE+ 263 AwABKAMAAYADAAEgAwABAQEAAQEGAAECFgAD//8A/wADAAs= 264 </value> 265 </data> 220 266 <metadata name="imageList2.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> 221 <value>353, 22</value>267 <value>353, 17</value> 222 268 </metadata> 223 269 <data name="imageList2.ImageStream" mimetype="application/x-microsoft.net.object.binary.base64"> … … 298 344 </data> 299 345 <metadata name="directorySearcher1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> 300 <value>458, 22</value> 346 <value>458, 17</value> 347 </metadata> 348 <metadata name="timerSyncronize.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> 349 <value>603, 17</value> 301 350 </metadata> 302 351 </root> -
trunk/sources/HeuristicLab.Hive.Server.Console/IPAdressTextBox.cs
r778 r1018 20 20 #endregion 21 21 22 // copied from http://www.codeproject.com/KB/edit/IPAddressTextBox.aspx23 24 using System;25 using System.Collections;26 using System.ComponentModel;27 using System.Windows.Forms;28 using System.Text.RegularExpressions;29 30 namespace HeuristicLab.Hive.Server.Console {31 [32 DefaultProperty("Text"),33 DefaultEvent("TextChanged"),34 ]35 /// <summary>36 /// IPAddressTextBox37 /// Control to enter IP-Addresses manually38 /// Supports Binary and Decimal Notation39 /// Supports input of CIDR Notation (appending of Bitmask of Subnetmask devided by Slash)40 /// Support input of IP-Address in IPv6 format41 /// </summary>42 public class IPAddressTextBox : System.Windows.Forms.TextBox {43 /// <summary>44 /// Required designer variable.45 /// </summary>46 private System.ComponentModel.Container components = null;47 48 private IPNotation m_ipNotation = IPNotation.IPv4Decimal;49 private IPNotation m_newIPNotation = IPNotation.IPv4Decimal;50 private bool m_bOverwrite = true;51 private bool m_bPreventLeave = true;52 private System.Windows.Forms.ErrorProvider error;53 private Regex m_regexValidNumbers = new Regex("[0-9]");54 private ArrayList m_arlDelimeter = new ArrayList(new char[] { '.' });55 56 57 public enum IPNotation {58 IPv4Decimal, //192.168.000.00159 IPv4Binary, //11000000.10101000.00000000.0000000160 IPv4DecimalCIDR, //192.168.000.001/1661 IPv4BinaryCIDR, //11000000.10101000.00000000.00000001/1662 }63 64 /// <summary>65 /// Constructor66 /// </summary>67 public IPAddressTextBox()68 : base() {69 this.InitializeComponent();70 71 this.ResetText();72 }73 74 private void InitializeComponent() {75 this.error = new System.Windows.Forms.ErrorProvider();76 }77 78 /// <summary>79 /// Clean up any resources being used.80 /// </summary>81 protected override void Dispose(bool disposing) {82 if (disposing) {83 if (components != null)84 components.Dispose();85 }86 base.Dispose(disposing);87 }88 89 #region Properties90 #region Not allowed Properties from BaseClass91 /// <summary>92 /// Multiline is not allowed93 /// </summary>94 [95 Category("Behavior"),96 Description("Multiline is not allowed"),97 DefaultValue(false),98 Browsable(false)99 ]100 public override bool Multiline {101 get {102 return base.Multiline;103 }104 set {105 //base.Multiline = value;106 base.Multiline = false;107 }108 }109 [110 Category("Behavior"),111 Description("AllowDrop is not allowed"),112 DefaultValue(false),113 Browsable(false)114 ]115 public override bool AllowDrop {116 get {117 return base.AllowDrop;118 }119 set {120 //base.AllowDrop = value;121 base.AllowDrop = false;122 }123 }124 [125 Category("Behavior"),126 Description("AcceptsReturn is not allowed"),127 DefaultValue(false),128 Browsable(false)129 ]130 public new bool AcceptsReturn {131 get {132 return base.AcceptsReturn;133 }134 set {135 //base.AcceptsReturn = value;136 base.AcceptsReturn = false;137 }138 }139 [140 Category("Behavior"),141 Description("AcceptsTab is not allowed"),142 DefaultValue(false),143 Browsable(false)144 ]145 public new bool AcceptsTab {146 get {147 return base.AcceptsTab;148 }149 set {150 //base.AcceptTab = value;151 base.AcceptsTab = false;152 }153 }154 [155 Category("Behavior"),156 Description("CharacterCasing is not allowed"),157 DefaultValue(CharacterCasing.Normal),158 Browsable(false)159 ]160 public new CharacterCasing CharacterCasing {161 get {162 return base.CharacterCasing;163 }164 set {165 //base.CharacterCasing = value;166 base.CharacterCasing = CharacterCasing.Normal;167 }168 }169 [170 Category("Behavior"),171 Description("WordWrap is not allowed"),172 DefaultValue(true),173 Browsable(false)174 ]175 public new bool WordWrap {176 get {177 return base.WordWrap;178 }179 set {180 //base.WordWrap = value;181 base.WordWrap = true;182 }183 }184 185 /// <summary>186 /// Maxlength must not be changed by user187 /// </summary>188 [189 Category("Behavior"),190 Description("Specifies maximum length of a String. Change is not allowed"),191 DefaultValue(15),192 Browsable(false)193 ]194 public override int MaxLength {195 get {196 return base.MaxLength;197 }198 set {199 //base.MaxLength = value;200 base.MaxLength = this.Text.Length;201 }202 }203 204 #endregion // Not allowed Properties from BaseClass205 206 /// <summary>207 /// Specifies if IP-Address208 /// </summary>209 [210 Category("Appearance"),211 Description("Specifies the IP-Address"),212 DefaultValue(" . . . ")213 ]214 public override string Text {215 get {216 return base.Text;217 }218 set {219 try {220 if (IPAddressTextBox.ValidateIP(value, this.m_newIPNotation, this.m_arlDelimeter))221 base.Text = IPAddressTextBox.MakeValidSpaces(value, this.m_newIPNotation, this.m_arlDelimeter);222 }223 catch {224 225 }226 }227 }228 229 /// <summary>230 /// Specifies if Numbers should be overwritten231 /// </summary>232 [233 Category("Behavior"),234 Description("Specifies if Numbers should be overwritten"),235 DefaultValue(true)236 ]237 public bool OverWriteMode {238 get {239 return this.m_bOverwrite;240 }241 set {242 if (value != this.m_bOverwrite) {243 this.m_bOverwrite = value;244 this.OnOverWriteChanged(value);245 }246 }247 }248 249 /// <summary>250 /// Prevents leaving of Control if there is an input-error251 /// </summary>252 [253 Category("Behavior"),254 Description("Prevents leaving of Control if there is an input-error"),255 DefaultValue(true)256 ]257 public bool PreventLeaveAtError {258 get {259 return this.m_bPreventLeave;260 }261 set {262 if (value != this.m_bPreventLeave) {263 this.m_bPreventLeave = value;264 this.OnPreventLeaveChanged(value);265 }266 }267 }268 269 /// <summary>270 /// Specifies if IP-Address Notation (IPv4, IPv6, Binary, Decimal, CIDR271 /// </summary>272 [273 Category("Appearance"),274 Description("Specifies if IP-Address Notation (IPv4, IPv6, Binary, Decimal, CIDR"),275 DefaultValue(IPNotation.IPv4Decimal)276 ]277 public IPNotation Notation {278 get {279 return this.m_ipNotation;280 }281 set {282 if (value != this.m_ipNotation) {283 try {284 this.m_newIPNotation = value;285 this.ChangeNotation(this.m_ipNotation, this.m_newIPNotation);286 this.m_ipNotation = this.m_newIPNotation;287 this.OnNotationChanged(this.m_newIPNotation);288 }289 catch (Exception LastError) {290 System.Diagnostics.Debug.WriteLine(LastError.Message);291 throw LastError;292 }293 }294 }295 }296 297 /// <summary>298 /// Specifies the Errorprovider that appears at invalid IPs299 /// </summary>300 [301 Category("Appearance"),302 Description("Specifies the Errorprovider that appears at invalid IPs"),303 DefaultValue(false)304 ]305 public ErrorProvider IPError {306 get {307 return this.error;308 }309 }310 311 312 #endregion //Properties313 314 #region Eventhandling315 316 /// <summary>317 /// Delegate for Notation-Events318 /// </summary>319 public delegate void NotationChangedEventHandler(IPNotation arg_newValue);320 /// <summary>321 /// Event called if AppearanceMode Notation is changed322 /// </summary>323 public event NotationChangedEventHandler NotationChanged;324 /// <summary>325 /// Delegate for Bool-Properties-Events326 /// </summary>327 public delegate void BoolPropertyChangedEventHandler(bool arg_bNewValue);328 /// <summary>329 /// Event called if BehaviorMode OverWriteMode is changed330 /// </summary>331 public event BoolPropertyChangedEventHandler OverWriteModeChanged;332 /// <summary>333 /// Event called if BehaviorMode PreventLeave is changed334 /// </summary>335 public event BoolPropertyChangedEventHandler PreventLeaveChanged;336 337 /// <summary>338 /// Occures when Appearance-Mode Notation was changed339 /// </summary>340 /// <param name="arg_Value">Value, Input IP-Address notation</param>341 protected virtual void OnNotationChanged(IPNotation arg_Value) {342 if (this.NotationChanged != null)343 this.NotationChanged(arg_Value);344 }345 346 private void ChangeNotation(IPNotation arg_oldValue, IPNotation arg_newValue) {347 string sTo = "";348 ArrayList arlFrom = new ArrayList(this.Text.Replace(" ", "").Split((char[])this.m_arlDelimeter.ToArray(typeof(char))));349 350 switch (arg_newValue) {351 case IPNotation.IPv4Decimal:352 this.m_regexValidNumbers = new Regex("[0-9]");353 this.m_arlDelimeter = new ArrayList(new char[] { '.' });354 break;355 case IPNotation.IPv4DecimalCIDR:356 this.m_regexValidNumbers = new Regex("[0-9]");357 this.m_arlDelimeter = new ArrayList(new char[] { '.', '/' });358 break;359 case IPNotation.IPv4Binary:360 this.m_regexValidNumbers = new Regex("[01]");361 this.m_arlDelimeter = new ArrayList(new char[] { '.' });362 break;363 case IPNotation.IPv4BinaryCIDR:364 this.m_regexValidNumbers = new Regex("[01]");365 this.m_arlDelimeter = new ArrayList(new char[] { '.', '/' });366 break;367 default:368 break;369 }370 371 switch (arg_oldValue) {372 case IPNotation.IPv4Decimal:373 switch (arg_newValue) {374 case IPNotation.IPv4Decimal:375 break;376 case IPNotation.IPv4DecimalCIDR:377 for (int i = 0; i < arlFrom.Count; i++) {378 sTo += arlFrom[i].ToString() +379 //Add Slash if its the last IPPart, els add a dot380 (i == arlFrom.Count - 1 ? "/ " : ".");381 }382 break;383 case IPNotation.IPv4Binary:384 for (int i = 0; i < arlFrom.Count; i++) {385 //Convert Decimal to Binary386 sTo += this.Dec2Bin(arlFrom[i].ToString()) +387 //Add Dot if its not the last IPPart, else add nothing388 (i == arlFrom.Count - 1 ? "" : ".");389 }390 break;391 case IPNotation.IPv4BinaryCIDR:392 for (int i = 0; i < arlFrom.Count; i++) {393 //Convert Decimal to Binary394 sTo += this.Dec2Bin(arlFrom[i].ToString()) +395 //Add Slash if its the last IPPart, else add a dot396 (i == arlFrom.Count - 1 ? "/ " : ".");397 }398 break;399 default:400 break;401 }402 break;403 case IPNotation.IPv4DecimalCIDR:404 switch (arg_newValue) {405 case IPNotation.IPv4Decimal:406 //do not use the last Item, its the Subnetmask407 for (int i = 0; i < arlFrom.Count - 1; i++) {408 sTo += arlFrom[i].ToString() +409 //Add Dot if its not the last IPPart, else add nothing410 (i == arlFrom.Count - 2 ? "" : ".");411 }412 break;413 case IPNotation.IPv4DecimalCIDR:414 break;415 case IPNotation.IPv4Binary:416 //do not use the last Item, its the Subnetmask417 for (int i = 0; i < arlFrom.Count - 1; i++) {418 //Convert Decimal to Binary419 sTo += this.Dec2Bin(arlFrom[i].ToString()) +420 //Add Dot if its not the last IPPart, else add nothing421 (i == arlFrom.Count - 2 ? "" : ".");422 }423 break;424 case IPNotation.IPv4BinaryCIDR:425 //do not use the last Item, its the Subnetmask426 for (int i = 0; i < arlFrom.Count - 1; i++) {427 //Convert Decimal to Binary428 sTo += this.Dec2Bin(arlFrom[i].ToString()) +429 //Add Dot if its not the last IPPart, else add nothing430 (i == arlFrom.Count - 2 ? "" : ".");431 }432 //Add Subnetmask433 sTo += "/" + arlFrom[arlFrom.Count - 1];434 break;435 default:436 break;437 }438 break;439 case IPNotation.IPv4Binary:440 switch (arg_newValue) {441 case IPNotation.IPv4Decimal:442 for (int i = 0; i < arlFrom.Count; i++) {443 //Convert Binary to Decimal444 sTo += this.Bin2Dec(arlFrom[i].ToString()) +445 //Add Dot if its not the last IPPart, else add nothing446 (i == arlFrom.Count - 1 ? "" : ".");447 }448 break;449 case IPNotation.IPv4DecimalCIDR:450 for (int i = 0; i < arlFrom.Count; i++) {451 //Convert Binary to Decimal452 sTo += this.Bin2Dec(arlFrom[i].ToString()) +453 //Add Slash if its the last IPPart, els add a dot454 (i == arlFrom.Count - 1 ? "/ " : ".");455 }456 break;457 case IPNotation.IPv4Binary:458 break;459 case IPNotation.IPv4BinaryCIDR:460 for (int i = 0; i < arlFrom.Count; i++) {461 sTo += arlFrom[i].ToString() +462 //Add Slash if its the last IPPart, else add a dot463 (i == arlFrom.Count - 1 ? "/ " : ".");464 }465 break;466 default:467 break;468 }469 break;470 case IPNotation.IPv4BinaryCIDR:471 switch (arg_newValue) {472 case IPNotation.IPv4Decimal:473 //do not use the last Item, its the Subnetmask474 for (int i = 0; i < arlFrom.Count - 1; i++) {475 sTo += this.Bin2Dec(arlFrom[i].ToString()) +476 //Add Dot if its not the last IPPart, else add nothing477 (i == arlFrom.Count - 2 ? "" : ".");478 }479 break;480 case IPNotation.IPv4DecimalCIDR:481 //do not use the last Item, its the Subnetmask482 for (int i = 0; i < arlFrom.Count - 1; i++) {483 sTo += this.Bin2Dec(arlFrom[i].ToString()) +484 //Add Dot if its not the last IPPart, else add nothing485 (i == arlFrom.Count - 2 ? "" : ".");486 }487 //Add Subnetmask488 sTo += "/" + arlFrom[arlFrom.Count - 1];489 break;490 case IPNotation.IPv4Binary:491 //do not use the last Item, its the Subnetmask492 for (int i = 0; i < arlFrom.Count - 1; i++) {493 sTo += arlFrom[i].ToString() +494 //Add Dot if its not the last IPPart, else add nothing495 (i == arlFrom.Count - 2 ? "" : ".");496 }497 break;498 case IPNotation.IPv4BinaryCIDR:499 break;500 default:501 break;502 }503 break;504 default:505 break;506 }507 508 this.Text = sTo;509 this.MaxLength = this.TextLength;510 }511 512 /// <summary>513 /// Occures when Behaviour-Mode OverWriteMode was changed514 /// </summary>515 /// <param name="arg_bValue">Value, Overwrite Numbers in Editfield or not</param>516 protected virtual void OnOverWriteChanged(bool arg_bValue) {517 if (this.OverWriteModeChanged != null)518 this.OverWriteModeChanged(arg_bValue);519 }520 521 /// <summary>522 /// Occures when Behaviour-Mode PreventLeave was changed523 /// </summary>524 /// <param name="arg_bValue">Value, leave control if there is an error or not</param>525 protected virtual void OnPreventLeaveChanged(bool arg_bValue) {526 if (this.PreventLeaveChanged != null)527 this.PreventLeaveChanged(arg_bValue);528 }529 530 #endregion //events531 532 #region Event-Overrides533 534 /// <summary>535 /// Override standard KeyDownEventHandler536 /// Catches Inputs of "." and "/" to jump to next positions537 /// </summary>538 /// <param name="e">KeyEventArgument</param>539 protected override void OnKeyDown(KeyEventArgs e) {540 //Zeichen an die richtige stelle schreiben541 int iPos = this.SelectionStart;542 char[] cText = this.Text.ToCharArray();543 544 if (e.Modifiers == Keys.None) {545 if ((char.IsLetterOrDigit(Convert.ToChar(e.KeyValue)) || e.KeyCode == Keys.NumPad0)//Numpad0=96 --> `546 && iPos < this.TextLength) {547 if (this.m_arlDelimeter.Contains(cText[iPos]))548 iPos += 1;549 this.SelectionStart = iPos;550 if (this.OverWriteMode) {551 if (iPos < this.TextLength)552 this.SelectionLength = 1;553 } else {554 if (iPos < this.TextLength)555 if (cText[iPos] == ' ')556 this.SelectionLength = 1;557 }558 }559 }560 base.OnKeyDown(e);561 }562 563 /// <summary>564 /// Override standard KeyUpEventHandler565 /// Catches Inputs of "." and "/" to jump to next positions566 /// </summary>567 /// <param name="e">KeyEventArgument</param>568 protected override void OnKeyUp(KeyEventArgs e) {569 //Zeichen an die richtige stelle schreiben570 int iPos = this.SelectionStart;571 char[] cText = this.Text.ToCharArray();572 573 //Cursor hintern Punkt setzen574 if ((char.IsLetterOrDigit(Convert.ToChar(e.KeyValue)) || e.KeyCode == Keys.NumPad0)//Numpad0=96 --> `575 && iPos < this.TextLength) {576 if (this.m_arlDelimeter.Contains(cText[iPos]))577 iPos += 1;578 579 this.SelectionStart = iPos;580 }581 base.OnKeyUp(e);582 }583 584 585 /// <summary>586 /// Override standard KeyPressEventHandler587 /// Catches Inputs of "." and "/" to jump to next positions588 /// </summary>589 /// <param name="e">KeyPressEventArgument</param>590 protected override void OnKeyPress(KeyPressEventArgs e) {591 //valid input charachters592 if (char.IsControl(e.KeyChar) ||593 m_regexValidNumbers.IsMatch(e.KeyChar.ToString())) {594 e.Handled = false;595 } else {596 switch (e.KeyChar) {597 case '/':598 this.JumpToSlash();599 break;600 case '.':601 case ':':602 this.JumpToNextDot();603 break;604 default:605 break;606 }607 e.Handled = true;608 }609 base.OnKeyPress(e);610 }611 612 /// <summary>613 /// Override standard TextChangedEventHandler614 /// Looks if inserted IP-Address is valid615 /// </summary>616 /// <param name="e">EventArgument</param>617 protected override void OnTextChanged(EventArgs e) {618 base.OnTextChanged(e);619 if (this.Text.Length == 0)620 this.ResetText();621 622 try {623 if (!this.ValidateIP())624 this.error.SetError(this, "Invalid IP-address");625 else626 this.error.SetError(this, "");627 }628 catch (Exception LastError) {629 this.error.SetError(this, LastError.Message);630 }631 }632 633 /// <summary>634 /// Override standard ValidatingEventHandler635 /// Validates inserted IP-Address, and cancels Textbox if valid or PreventLeave=false636 /// </summary>637 /// <param name="e">CancelEventArgument</param>638 protected override void OnValidating(CancelEventArgs e) {639 //e.Cancel = true;//suppress cancel-signal = not validated640 e.Cancel = (!this.ValidateIP() && this.m_bPreventLeave);641 base.OnValidating(e);642 }643 644 #endregion //Eventhandling645 646 #region Methods647 648 /// <summary>649 /// Override standard ResetText650 /// Fills Textbox with Dots and Slashes dependend on Properties651 /// </summary>652 public override void ResetText() {653 base.ResetText();654 switch (this.Notation) {655 case IPNotation.IPv4Decimal:656 this.Text = " . . . ";657 break;658 case IPNotation.IPv4DecimalCIDR:659 this.Text = " . . . / ";660 break;661 case IPNotation.IPv4Binary:662 this.Text = " . . . ";663 break;664 case IPNotation.IPv4BinaryCIDR:665 this.Text = " . . . / ";666 break;667 default:668 break;669 }670 671 this.MaxLength = this.TextLength;672 }673 674 675 /// <summary>676 /// Window-Message Constant677 /// </summary>678 protected const int WM_KEYDOWN = 0x0100;679 680 /// <summary>681 /// Override standard PreProcessMessge682 /// Catches Inputs of Backspaces and Deletes to remove IP-Digits at the right position683 /// </summary>684 /// <param name="msg">Process Message</param>685 public override bool PreProcessMessage(ref Message msg) {686 if (msg.Msg == WM_KEYDOWN) {687 Keys keyData = ((Keys)(int)msg.WParam) | ModifierKeys;688 Keys keyCode = ((Keys)(int)msg.WParam);689 690 int iPos = this.SelectionStart;691 char[] cText = this.Text.ToCharArray();692 switch (keyCode) {693 case Keys.Delete:694 if (iPos < this.TextLength) {695 while (cText[iPos] == '.' || cText[iPos] == ':' || cText[iPos] == '/') {696 if ((iPos += 1) >= cText.Length)697 break;698 }699 if (iPos < this.TextLength) {700 base.Text = this.Text.Substring(0, iPos) + " " + this.Text.Substring(iPos + 1);701 this.SelectionStart = iPos + 1;702 } else703 this.SelectionStart = this.TextLength - 1;704 }705 return true;706 case Keys.Back:707 if (iPos > 0) {708 while (cText[iPos - 1] == '.' || cText[iPos - 1] == ':' || cText[iPos - 1] == '/') {709 if ((iPos -= 1) <= 0)710 break;711 }712 if (iPos > 0) {713 base.Text = this.Text.Substring(0, iPos - 1) + " " + this.Text.Substring(iPos);714 this.SelectionStart = iPos - 1;715 } else716 this.SelectionStart = 0;717 }718 return true;719 default:720 break;721 }722 }723 return base.PreProcessMessage(ref msg);724 }725 726 /// <summary>727 /// Returns the formatted IP-Addresses without spaces and Zeroes728 /// </summary>729 /// <returns>IP-Address without spaces and Zeroes</returns>730 public string GetPureIPAddress() {731 string s = "";732 ArrayList arlIP = new ArrayList(this.Text.Replace(" ", "").Split((char[])this.m_arlDelimeter.ToArray(typeof(char))));733 for (int i = 0; i < arlIP.Count; i++) {734 while (arlIP[i].ToString().StartsWith("0"))735 arlIP[i] = arlIP[i].ToString().Substring(1);736 }737 s = IPAddressTextBox.MakeIP((string[])arlIP.ToArray(typeof(string)), this.m_ipNotation);738 return s;739 }740 741 #endregion //Methods742 743 #region Helperfunctions744 745 /// <summary>746 /// Sets Inputcursor to Subnet-Slash747 /// </summary>748 private void JumpToSlash() {749 int iSelStart = this.Text.LastIndexOf("/");750 if (iSelStart >= 0) {751 this.Select(iSelStart + 1, 0);752 }753 }754 755 /// <summary>756 /// Sets input cursour to next Dot757 /// </summary>758 private void JumpToNextDot() {759 int iSelStart = this.Text.IndexOf('.', this.SelectionStart);760 if (iSelStart >= 0) {761 this.Select(iSelStart + 1, 0);762 } else {763 iSelStart = this.Text.IndexOf(':', this.SelectionStart);764 if (iSelStart >= 0) {765 this.Select(iSelStart + 1, 0);766 }767 }768 }769 770 /// <summary>771 /// Converts Decimal IP-Part to Binary (default IPv6 = false)772 /// </summary>773 /// <param name="arg_sDec">Decimal IP-Part</param>774 /// <param name="arg_bIPv6">Binary for IPv6 (has 16 digits)</param>775 /// <returns>Binary IP-Part</returns>776 private string Dec2Bin(string arg_sDec) {777 return this.Dec2Bin(arg_sDec, false);778 }779 /// <summary>780 /// Converts Decimal IP-Part to Binary781 /// </summary>782 /// <param name="arg_sDec">Decimal IP-Part</param>783 /// <param name="arg_bIPv6">Binary for IPv6 (has 16 digits)</param>784 /// <returns>Binary IP-Part</returns>785 private string Dec2Bin(string arg_sDec, bool arg_bIPv6) {786 string sBin = (arg_bIPv6 ? "0000000000000000" : "00000000"), sSubnet = "";787 arg_sDec = arg_sDec.Trim();788 while (arg_sDec.Length < 3)789 arg_sDec = "0" + arg_sDec;790 if (arg_sDec.IndexOf("/") >= 0) {791 sSubnet = arg_sDec.Substring(arg_sDec.IndexOf("/"));792 arg_sDec = arg_sDec.Substring(0, arg_sDec.IndexOf("/"));793 }794 int iDec = Convert.ToInt32(arg_sDec, 10);795 sBin = Convert.ToString(iDec, 2);796 while (sBin.Length < (arg_bIPv6 ? 16 : 8))797 sBin = "0" + sBin;798 return sBin + sSubnet;799 }800 801 /// <summary>802 /// Converts Binary IP-Part to Decimal803 /// </summary>804 /// <param name="arg_sBin">Binary IP-Part</param>805 /// <returns>Decimal IP-Part</returns>806 private string Bin2Dec(string arg_sBin) {807 string sDec = "000", sSubnet = "";808 arg_sBin = arg_sBin.Trim();809 while (arg_sBin.Length < 8)810 arg_sBin = "0" + arg_sBin;811 if (arg_sBin.IndexOf("/") >= 0) {812 sSubnet = arg_sBin.Substring(arg_sBin.IndexOf("/"));813 arg_sBin = arg_sBin.Substring(0, arg_sBin.IndexOf("/"));814 }815 int iBin = Convert.ToInt32(arg_sBin, 2);816 if (iBin > 255)817 throw new Exception(string.Format("Can't convert Binary to Decimal IP-Address\nbin:{0} is greater than 255", iBin));818 sDec = Convert.ToString(iBin, 10);819 while (sDec.Length < 3)820 sDec = "0" + sDec;821 return sDec + sSubnet;822 }823 824 /// <summary>825 /// Converts Binary IP-Part to Hexadecimal826 /// </summary>827 /// <param name="arg_sBin">Binary IP-Part</param>828 /// <returns>Hexadecimal IP-Part</returns>829 private string Bin2Hex(string arg_sBin) {830 string sHex = "0000", sSubnet = "";831 arg_sBin = arg_sBin.Trim();832 while (arg_sBin.Length < 8)833 arg_sBin = "0" + arg_sBin;834 if (arg_sBin.IndexOf("/") >= 0) {835 sSubnet = arg_sBin.Substring(arg_sBin.IndexOf("/"));836 arg_sBin = arg_sBin.Substring(0, arg_sBin.IndexOf("/"));837 }838 int iBin = Convert.ToInt32(arg_sBin, 2);839 sHex = Convert.ToString(iBin, 16);840 while (sHex.Length < 4)841 sHex = "0" + sHex;842 return sHex + sSubnet;843 }844 845 /// <summary>846 /// Converts Hexadecimal IP-Part to Binary (default IPv6=true)847 /// </summary>848 /// <param name="arg_sHex">Hexadecimal IP-Part</param>849 /// <returns>Binary IP-Part</returns>850 private string Hex2Bin(string arg_sHex) {851 return this.Hex2Bin(arg_sHex, true);852 }853 /// <summary>854 /// Converts Hexadecimal IP-Part to Binary855 /// </summary>856 /// <param name="arg_sHex">Hexadecimal IP-Part</param>857 /// <param name="arg_bIPv6">Binary for IPv6 (16 digits)</param>858 /// <returns>Binary IP-Part</returns>859 private string Hex2Bin(string arg_sHex, bool arg_bIPv6) {860 string sBin = (arg_bIPv6 ? "0000000000000000" : "00000000"), sSubnet = "";861 arg_sHex = arg_sHex.Trim();862 while (arg_sHex.Length < 3)863 arg_sHex = "0" + arg_sHex;864 if (arg_sHex.IndexOf("/") >= 0) {865 sSubnet = arg_sHex.Substring(arg_sHex.IndexOf("/"));866 arg_sHex = arg_sHex.Substring(0, arg_sHex.IndexOf("/"));867 }868 int iHex = Convert.ToInt32(arg_sHex, 16);869 if (iHex > 255 && !arg_bIPv6)870 throw new Exception(string.Format("Can't convert Hexadecimal to Binary IP-Address\nhex:{0} is greater than 11111111", iHex));871 sBin = Convert.ToString(iHex, 2);872 while (sBin.Length < (arg_bIPv6 ? 16 : 8))873 sBin = "0" + sBin;874 return sBin + sSubnet;875 }876 877 /// <summary>878 /// Converts Decimal IP-Part to Hexadecimal879 /// </summary>880 /// <param name="arg_sDec">Decimal IP-Part</param>881 /// <returns>Hexadecimal IP-Part</returns>882 private string Dec2Hex(string arg_sDec) {883 string sHex = "0000", sSubnet = "";884 arg_sDec = arg_sDec.Trim();885 while (arg_sDec.Length < 8)886 arg_sDec = "0" + arg_sDec;887 if (arg_sDec.IndexOf("/") >= 0) {888 sSubnet = arg_sDec.Substring(arg_sDec.IndexOf("/"));889 arg_sDec = arg_sDec.Substring(0, arg_sDec.IndexOf("/"));890 }891 int iDec = Convert.ToInt32(arg_sDec, 10);892 sHex = Convert.ToString(iDec, 16);893 while (sHex.Length < 4)894 sHex = "0" + sHex;895 return sHex + sSubnet;896 }897 898 /// <summary>899 /// Converts Hexadecimal IP-Part to Decimal900 /// </summary>901 /// <param name="arg_sHex">Hexadecimal IP-Part</param>902 /// <returns>Decimal IP-Part</returns>903 private string Hex2Dec(string arg_sHex) {904 string sDec = "000", sSubnet = "";905 arg_sHex = arg_sHex.Trim();906 while (arg_sHex.Length < 8)907 arg_sHex = "0" + arg_sHex;908 if (arg_sHex.IndexOf("/") >= 0) {909 sSubnet = arg_sHex.Substring(arg_sHex.IndexOf("/"));910 arg_sHex = arg_sHex.Substring(0, arg_sHex.IndexOf("/"));911 }912 int iHex = Convert.ToInt32(arg_sHex, 16);913 if (iHex > 255)914 throw new Exception(string.Format("Can't convert Hexadecimal to Decimal IP-Address\nhex:{0} is greater than 255", iHex));915 sDec = Convert.ToString(iHex, 10);916 while (sDec.Length < 3)917 sDec = "0" + sDec;918 return sDec + sSubnet;919 }920 921 /// <summary>922 /// Checks if IP in Textfield is valid923 /// </summary>924 /// <returns>true/false valid/not</returns>925 private bool ValidateIP() {926 if (IPAddressTextBox.ValidateIP(this.Text, this.m_newIPNotation, this.m_arlDelimeter))927 return true;928 else929 //if Control is not visible or enabled, it doesn't matter if IP is valid930 return this.Enabled || this.Visible ? false : true;931 }932 933 /// <summary>934 /// Checks if the given String is an valid ip-address935 /// </summary>936 /// <param name="arg_sIP">IP-String</param>937 /// <param name="arg_ipNotation">IP-notation</param>938 /// <param name="arg_arlDelimeter">Delimeter to parse IPString</param>939 /// <returns>true/false validated/not</returns>940 protected static bool ValidateIP(string arg_sIP, IPNotation arg_ipNotation, ArrayList arg_arlDelimeter) {941 bool bValidated = false;942 ArrayList arlIP = new ArrayList(arg_sIP.Split((char[])arg_arlDelimeter.ToArray(typeof(char))));943 944 try {945 switch (arg_ipNotation) {946 case IPNotation.IPv4Decimal:947 case IPNotation.IPv4Binary:948 bValidated = arlIP.Count == 4;949 break;950 case IPNotation.IPv4DecimalCIDR:951 case IPNotation.IPv4BinaryCIDR:952 bValidated = arlIP.Count == 5;953 break;954 default:955 break;956 }957 if (!bValidated) {958 throw new Exception("IP-Address has wrong element count");959 }960 961 //don't check the 1st 2 elemnt if its IPv4 in IPv6-notation962 for (int i = (arg_ipNotation.ToString().IndexOf("IPv6IPv4") == 0 ? 2 : 0);963 //don't check the subnet element964 i < (arg_ipNotation.ToString().IndexOf("CIDR") > 0 ? arlIP.Count - 1 : arlIP.Count);965 i++) {966 string sIPPart = arlIP[i].ToString().Replace(" ", "");967 int iIPPart = 0;968 switch (arg_ipNotation) {969 case IPNotation.IPv4Decimal:970 case IPNotation.IPv4DecimalCIDR:971 while (sIPPart.Length < 3)972 sIPPart = "0" + sIPPart;973 iIPPart = Convert.ToInt32(sIPPart, 10);974 if (iIPPart < 256)975 bValidated = true;976 else977 bValidated = false;978 break;979 case IPNotation.IPv4Binary:980 case IPNotation.IPv4BinaryCIDR:981 while (sIPPart.Length < 8)982 sIPPart = "0" + sIPPart;983 iIPPart = Convert.ToInt32(sIPPart, 2);984 if (iIPPart < 256)985 bValidated = true;986 else987 bValidated = false;988 break;989 default:990 break;991 }992 if (!bValidated) {993 throw new Exception(string.Format("IP-Address element {0}({1}) has wrong format", i, sIPPart));994 }995 }996 }997 catch (Exception LastError) {998 System.Diagnostics.Debug.WriteLine(LastError.Message);999 bValidated = false;1000 throw LastError;1001 }1002 return bValidated;1003 }1004 1005 /// <summary>1006 /// Adds Spaces to given IP-Address, so it fits in the textfield1007 /// </summary>1008 /// <param name="arg_sIP">IP-String</param>1009 /// <param name="arg_ipNotation">IP-notation</param>1010 /// <param name="arg_arlDelimeter">Delimeter to parse IPString</param>1011 /// <returns>IP-Address with Spaces</returns>1012 protected static string MakeValidSpaces(string arg_sIP, IPNotation arg_ipNotation, ArrayList arg_arlDelimeter) {1013 ArrayList arlIP = new ArrayList(arg_sIP.Split((char[])arg_arlDelimeter.ToArray(typeof(char))));1014 //don't check the 1st 2 elemnt if its IPv4 in IPv6-notation1015 for (int i = (arg_ipNotation.ToString().IndexOf("IPv6IPv4") == 0 ? 2 : 0);1016 //don't check the subnet element1017 i < (arg_ipNotation.ToString().IndexOf("CIDR") > 0 ? arlIP.Count - 1 : arlIP.Count);1018 i++) {1019 switch (arg_ipNotation) {1020 case IPNotation.IPv4Decimal:1021 case IPNotation.IPv4DecimalCIDR:1022 while (arlIP[i].ToString().Length < 3)1023 arlIP[i] = arlIP[i].ToString() + " ";1024 break;1025 case IPNotation.IPv4Binary:1026 case IPNotation.IPv4BinaryCIDR:1027 while (arlIP[i].ToString().Length < 8)1028 arlIP[i] = arlIP[i].ToString() + " ";1029 break;1030 default:1031 break;1032 }1033 }1034 1035 return IPAddressTextBox.MakeIP((string[])arlIP.ToArray(typeof(string)), arg_ipNotation);1036 }1037 1038 /// <summary>1039 /// Adds Zeroes to given IP-Address, so it fits in the textfield1040 /// </summary>1041 /// <param name="arg_sIP">IP-String</param>1042 /// <param name="arg_ipNotation">IP-notation</param>1043 /// <param name="arg_arlDelimeter">Delimeter to parse IPString</param>1044 /// <returns>IP-Address with Spaces</returns>1045 protected static string MakeValidZeroes(string arg_sIP, IPNotation arg_ipNotation, ArrayList arg_arlDelimeter) {1046 ArrayList arlIP = new ArrayList(arg_sIP.Split((char[])arg_arlDelimeter.ToArray(typeof(char))));1047 //don't check the 1st 2 elemnt if its IPv4 in IPv6-notation1048 for (int i = (arg_ipNotation.ToString().IndexOf("IPv6IPv4") == 0 ? 2 : 0);1049 //don't check the subnet element1050 i < (arg_ipNotation.ToString().IndexOf("CIDR") > 0 ? arlIP.Count - 1 : arlIP.Count);1051 i++) {1052 switch (arg_ipNotation) {1053 case IPNotation.IPv4Decimal:1054 case IPNotation.IPv4DecimalCIDR:1055 while (arlIP[i].ToString().Length < 3)1056 arlIP[i] = "0" + arlIP[i].ToString();1057 break;1058 case IPNotation.IPv4Binary:1059 case IPNotation.IPv4BinaryCIDR:1060 while (arlIP[i].ToString().Length < 8)1061 arlIP[i] = "0" + arlIP[i].ToString();1062 break;1063 default:1064 break;1065 }1066 }1067 1068 return IPAddressTextBox.MakeIP((string[])arlIP.ToArray(typeof(string)), arg_ipNotation);1069 }1070 1071 /// <summary>1072 /// Creates IP-Addresstring from given StrignArray and Notation1073 /// </summary>1074 /// <param name="arg_sIP">String-Array with elements for IP-Address</param>1075 /// <param name="arg_ipNotation">Notation of IP-Address</param>1076 /// <returns>IPAddress-String</returns>1077 protected static string MakeIP(string[] arg_sIP, IPNotation arg_ipNotation) {1078 string s = "";1079 for (int i = 0; i < arg_sIP.Length; i++) {1080 switch (arg_ipNotation) {1081 case IPNotation.IPv4Decimal:1082 case IPNotation.IPv4Binary:1083 s += (arg_sIP[i].Length > 0 ? arg_sIP[i] : "0") + (i < (arg_sIP.Length - 1) ? "." : "");1084 break;1085 case IPNotation.IPv4DecimalCIDR:1086 case IPNotation.IPv4BinaryCIDR:1087 s += (arg_sIP[i].Length > 0 ? arg_sIP[i] : "0") + (i < (arg_sIP.Length - 2) ? "." : (i < arg_sIP.Length - 1) ? "/" : "");1088 break;1089 default:1090 break;1091 }1092 }1093 return s;1094 }1095 1096 #endregion //Helperfunctions1097 }1098 }22 //// copied from http://www.codeproject.com/KB/edit/IPAddressTextBox.aspx 23 24 //using System; 25 //using System.Collections; 26 //using System.ComponentModel; 27 //using System.Windows.Forms; 28 //using System.Text.RegularExpressions; 29 30 //namespace HeuristicLab.Hive.Server.Console { 31 // [ 32 // DefaultProperty("Text"), 33 // DefaultEvent("TextChanged"), 34 // ] 35 // /// <summary> 36 // /// IPAddressTextBox 37 // /// Control to enter IP-Addresses manually 38 // /// Supports Binary and Decimal Notation 39 // /// Supports input of CIDR Notation (appending of Bitmask of Subnetmask devided by Slash) 40 // /// Support input of IP-Address in IPv6 format 41 // /// </summary> 42 // public class IPAddressTextBox : System.Windows.Forms.TextBox { 43 // /// <summary> 44 // /// Required designer variable. 45 // /// </summary> 46 // private System.ComponentModel.Container components = null; 47 48 // private IPNotation m_ipNotation = IPNotation.IPv4Decimal; 49 // private IPNotation m_newIPNotation = IPNotation.IPv4Decimal; 50 // private bool m_bOverwrite = true; 51 // private bool m_bPreventLeave = true; 52 // private System.Windows.Forms.ErrorProvider error; 53 // private Regex m_regexValidNumbers = new Regex("[0-9]"); 54 // private ArrayList m_arlDelimeter = new ArrayList(new char[] { '.' }); 55 56 57 // public enum IPNotation { 58 // IPv4Decimal, //192.168.000.001 59 // IPv4Binary, //11000000.10101000.00000000.00000001 60 // IPv4DecimalCIDR, //192.168.000.001/16 61 // IPv4BinaryCIDR, //11000000.10101000.00000000.00000001/16 62 // } 63 64 // /// <summary> 65 // /// Constructor 66 // /// </summary> 67 // public IPAddressTextBox() 68 // : base() { 69 // this.InitializeComponent(); 70 71 // this.ResetText(); 72 // } 73 74 // private void InitializeComponent() { 75 // this.error = new System.Windows.Forms.ErrorProvider(); 76 // } 77 78 // /// <summary> 79 // /// Clean up any resources being used. 80 // /// </summary> 81 // protected override void Dispose(bool disposing) { 82 // if (disposing) { 83 // if (components != null) 84 // components.Dispose(); 85 // } 86 // base.Dispose(disposing); 87 // } 88 89 // #region Properties 90 // #region Not allowed Properties from BaseClass 91 // /// <summary> 92 // /// Multiline is not allowed 93 // /// </summary> 94 // [ 95 // Category("Behavior"), 96 // Description("Multiline is not allowed"), 97 // DefaultValue(false), 98 // Browsable(false) 99 // ] 100 // public override bool Multiline { 101 // get { 102 // return base.Multiline; 103 // } 104 // set { 105 // //base.Multiline = value; 106 // base.Multiline = false; 107 // } 108 // } 109 // [ 110 // Category("Behavior"), 111 // Description("AllowDrop is not allowed"), 112 // DefaultValue(false), 113 // Browsable(false) 114 // ] 115 // public override bool AllowDrop { 116 // get { 117 // return base.AllowDrop; 118 // } 119 // set { 120 // //base.AllowDrop = value; 121 // base.AllowDrop = false; 122 // } 123 // } 124 // [ 125 // Category("Behavior"), 126 // Description("AcceptsReturn is not allowed"), 127 // DefaultValue(false), 128 // Browsable(false) 129 // ] 130 // public new bool AcceptsReturn { 131 // get { 132 // return base.AcceptsReturn; 133 // } 134 // set { 135 // //base.AcceptsReturn = value; 136 // base.AcceptsReturn = false; 137 // } 138 // } 139 // [ 140 // Category("Behavior"), 141 // Description("AcceptsTab is not allowed"), 142 // DefaultValue(false), 143 // Browsable(false) 144 // ] 145 // public new bool AcceptsTab { 146 // get { 147 // return base.AcceptsTab; 148 // } 149 // set { 150 // //base.AcceptTab = value; 151 // base.AcceptsTab = false; 152 // } 153 // } 154 // [ 155 // Category("Behavior"), 156 // Description("CharacterCasing is not allowed"), 157 // DefaultValue(CharacterCasing.Normal), 158 // Browsable(false) 159 // ] 160 // public new CharacterCasing CharacterCasing { 161 // get { 162 // return base.CharacterCasing; 163 // } 164 // set { 165 // //base.CharacterCasing = value; 166 // base.CharacterCasing = CharacterCasing.Normal; 167 // } 168 // } 169 // [ 170 // Category("Behavior"), 171 // Description("WordWrap is not allowed"), 172 // DefaultValue(true), 173 // Browsable(false) 174 // ] 175 // public new bool WordWrap { 176 // get { 177 // return base.WordWrap; 178 // } 179 // set { 180 // //base.WordWrap = value; 181 // base.WordWrap = true; 182 // } 183 // } 184 185 // /// <summary> 186 // /// Maxlength must not be changed by user 187 // /// </summary> 188 // [ 189 // Category("Behavior"), 190 // Description("Specifies maximum length of a String. Change is not allowed"), 191 // DefaultValue(15), 192 // Browsable(false) 193 // ] 194 // public override int MaxLength { 195 // get { 196 // return base.MaxLength; 197 // } 198 // set { 199 // //base.MaxLength = value; 200 // base.MaxLength = this.Text.Length; 201 // } 202 // } 203 204 // #endregion // Not allowed Properties from BaseClass 205 206 // /// <summary> 207 // /// Specifies if IP-Address 208 // /// </summary> 209 // [ 210 // Category("Appearance"), 211 // Description("Specifies the IP-Address"), 212 // DefaultValue(" . . . ") 213 // ] 214 // public override string Text { 215 // get { 216 // return base.Text; 217 // } 218 // set { 219 // try { 220 // if (IPAddressTextBox.ValidateIP(value, this.m_newIPNotation, this.m_arlDelimeter)) 221 // base.Text = IPAddressTextBox.MakeValidSpaces(value, this.m_newIPNotation, this.m_arlDelimeter); 222 // } 223 // catch { 224 225 // } 226 // } 227 // } 228 229 // /// <summary> 230 // /// Specifies if Numbers should be overwritten 231 // /// </summary> 232 // [ 233 // Category("Behavior"), 234 // Description("Specifies if Numbers should be overwritten"), 235 // DefaultValue(true) 236 // ] 237 // public bool OverWriteMode { 238 // get { 239 // return this.m_bOverwrite; 240 // } 241 // set { 242 // if (value != this.m_bOverwrite) { 243 // this.m_bOverwrite = value; 244 // this.OnOverWriteChanged(value); 245 // } 246 // } 247 // } 248 249 // /// <summary> 250 // /// Prevents leaving of Control if there is an input-error 251 // /// </summary> 252 // [ 253 // Category("Behavior"), 254 // Description("Prevents leaving of Control if there is an input-error"), 255 // DefaultValue(true) 256 // ] 257 // public bool PreventLeaveAtError { 258 // get { 259 // return this.m_bPreventLeave; 260 // } 261 // set { 262 // if (value != this.m_bPreventLeave) { 263 // this.m_bPreventLeave = value; 264 // this.OnPreventLeaveChanged(value); 265 // } 266 // } 267 // } 268 269 // /// <summary> 270 // /// Specifies if IP-Address Notation (IPv4, IPv6, Binary, Decimal, CIDR 271 // /// </summary> 272 // [ 273 // Category("Appearance"), 274 // Description("Specifies if IP-Address Notation (IPv4, IPv6, Binary, Decimal, CIDR"), 275 // DefaultValue(IPNotation.IPv4Decimal) 276 // ] 277 // public IPNotation Notation { 278 // get { 279 // return this.m_ipNotation; 280 // } 281 // set { 282 // if (value != this.m_ipNotation) { 283 // try { 284 // this.m_newIPNotation = value; 285 // this.ChangeNotation(this.m_ipNotation, this.m_newIPNotation); 286 // this.m_ipNotation = this.m_newIPNotation; 287 // this.OnNotationChanged(this.m_newIPNotation); 288 // } 289 // catch (Exception LastError) { 290 // System.Diagnostics.Debug.WriteLine(LastError.Message); 291 // throw LastError; 292 // } 293 // } 294 // } 295 // } 296 297 // /// <summary> 298 // /// Specifies the Errorprovider that appears at invalid IPs 299 // /// </summary> 300 // [ 301 // Category("Appearance"), 302 // Description("Specifies the Errorprovider that appears at invalid IPs"), 303 // DefaultValue(false) 304 // ] 305 // public ErrorProvider IPError { 306 // get { 307 // return this.error; 308 // } 309 // } 310 311 312 // #endregion //Properties 313 314 // #region Eventhandling 315 316 // /// <summary> 317 // /// Delegate for Notation-Events 318 // /// </summary> 319 // public delegate void NotationChangedEventHandler(IPNotation arg_newValue); 320 // /// <summary> 321 // /// Event called if AppearanceMode Notation is changed 322 // /// </summary> 323 // public event NotationChangedEventHandler NotationChanged; 324 // /// <summary> 325 // /// Delegate for Bool-Properties-Events 326 // /// </summary> 327 // public delegate void BoolPropertyChangedEventHandler(bool arg_bNewValue); 328 // /// <summary> 329 // /// Event called if BehaviorMode OverWriteMode is changed 330 // /// </summary> 331 // public event BoolPropertyChangedEventHandler OverWriteModeChanged; 332 // /// <summary> 333 // /// Event called if BehaviorMode PreventLeave is changed 334 // /// </summary> 335 // public event BoolPropertyChangedEventHandler PreventLeaveChanged; 336 337 // /// <summary> 338 // /// Occures when Appearance-Mode Notation was changed 339 // /// </summary> 340 // /// <param name="arg_Value">Value, Input IP-Address notation</param> 341 // protected virtual void OnNotationChanged(IPNotation arg_Value) { 342 // if (this.NotationChanged != null) 343 // this.NotationChanged(arg_Value); 344 // } 345 346 // private void ChangeNotation(IPNotation arg_oldValue, IPNotation arg_newValue) { 347 // string sTo = ""; 348 // ArrayList arlFrom = new ArrayList(this.Text.Replace(" ", "").Split((char[])this.m_arlDelimeter.ToArray(typeof(char)))); 349 350 // switch (arg_newValue) { 351 // case IPNotation.IPv4Decimal: 352 // this.m_regexValidNumbers = new Regex("[0-9]"); 353 // this.m_arlDelimeter = new ArrayList(new char[] { '.' }); 354 // break; 355 // case IPNotation.IPv4DecimalCIDR: 356 // this.m_regexValidNumbers = new Regex("[0-9]"); 357 // this.m_arlDelimeter = new ArrayList(new char[] { '.', '/' }); 358 // break; 359 // case IPNotation.IPv4Binary: 360 // this.m_regexValidNumbers = new Regex("[01]"); 361 // this.m_arlDelimeter = new ArrayList(new char[] { '.' }); 362 // break; 363 // case IPNotation.IPv4BinaryCIDR: 364 // this.m_regexValidNumbers = new Regex("[01]"); 365 // this.m_arlDelimeter = new ArrayList(new char[] { '.', '/' }); 366 // break; 367 // default: 368 // break; 369 // } 370 371 // switch (arg_oldValue) { 372 // case IPNotation.IPv4Decimal: 373 // switch (arg_newValue) { 374 // case IPNotation.IPv4Decimal: 375 // break; 376 // case IPNotation.IPv4DecimalCIDR: 377 // for (int i = 0; i < arlFrom.Count; i++) { 378 // sTo += arlFrom[i].ToString() + 379 // //Add Slash if its the last IPPart, els add a dot 380 // (i == arlFrom.Count - 1 ? "/ " : "."); 381 // } 382 // break; 383 // case IPNotation.IPv4Binary: 384 // for (int i = 0; i < arlFrom.Count; i++) { 385 // //Convert Decimal to Binary 386 // sTo += this.Dec2Bin(arlFrom[i].ToString()) + 387 // //Add Dot if its not the last IPPart, else add nothing 388 // (i == arlFrom.Count - 1 ? "" : "."); 389 // } 390 // break; 391 // case IPNotation.IPv4BinaryCIDR: 392 // for (int i = 0; i < arlFrom.Count; i++) { 393 // //Convert Decimal to Binary 394 // sTo += this.Dec2Bin(arlFrom[i].ToString()) + 395 // //Add Slash if its the last IPPart, else add a dot 396 // (i == arlFrom.Count - 1 ? "/ " : "."); 397 // } 398 // break; 399 // default: 400 // break; 401 // } 402 // break; 403 // case IPNotation.IPv4DecimalCIDR: 404 // switch (arg_newValue) { 405 // case IPNotation.IPv4Decimal: 406 // //do not use the last Item, its the Subnetmask 407 // for (int i = 0; i < arlFrom.Count - 1; i++) { 408 // sTo += arlFrom[i].ToString() + 409 // //Add Dot if its not the last IPPart, else add nothing 410 // (i == arlFrom.Count - 2 ? "" : "."); 411 // } 412 // break; 413 // case IPNotation.IPv4DecimalCIDR: 414 // break; 415 // case IPNotation.IPv4Binary: 416 // //do not use the last Item, its the Subnetmask 417 // for (int i = 0; i < arlFrom.Count - 1; i++) { 418 // //Convert Decimal to Binary 419 // sTo += this.Dec2Bin(arlFrom[i].ToString()) + 420 // //Add Dot if its not the last IPPart, else add nothing 421 // (i == arlFrom.Count - 2 ? "" : "."); 422 // } 423 // break; 424 // case IPNotation.IPv4BinaryCIDR: 425 // //do not use the last Item, its the Subnetmask 426 // for (int i = 0; i < arlFrom.Count - 1; i++) { 427 // //Convert Decimal to Binary 428 // sTo += this.Dec2Bin(arlFrom[i].ToString()) + 429 // //Add Dot if its not the last IPPart, else add nothing 430 // (i == arlFrom.Count - 2 ? "" : "."); 431 // } 432 // //Add Subnetmask 433 // sTo += "/" + arlFrom[arlFrom.Count - 1]; 434 // break; 435 // default: 436 // break; 437 // } 438 // break; 439 // case IPNotation.IPv4Binary: 440 // switch (arg_newValue) { 441 // case IPNotation.IPv4Decimal: 442 // for (int i = 0; i < arlFrom.Count; i++) { 443 // //Convert Binary to Decimal 444 // sTo += this.Bin2Dec(arlFrom[i].ToString()) + 445 // //Add Dot if its not the last IPPart, else add nothing 446 // (i == arlFrom.Count - 1 ? "" : "."); 447 // } 448 // break; 449 // case IPNotation.IPv4DecimalCIDR: 450 // for (int i = 0; i < arlFrom.Count; i++) { 451 // //Convert Binary to Decimal 452 // sTo += this.Bin2Dec(arlFrom[i].ToString()) + 453 // //Add Slash if its the last IPPart, els add a dot 454 // (i == arlFrom.Count - 1 ? "/ " : "."); 455 // } 456 // break; 457 // case IPNotation.IPv4Binary: 458 // break; 459 // case IPNotation.IPv4BinaryCIDR: 460 // for (int i = 0; i < arlFrom.Count; i++) { 461 // sTo += arlFrom[i].ToString() + 462 // //Add Slash if its the last IPPart, else add a dot 463 // (i == arlFrom.Count - 1 ? "/ " : "."); 464 // } 465 // break; 466 // default: 467 // break; 468 // } 469 // break; 470 // case IPNotation.IPv4BinaryCIDR: 471 // switch (arg_newValue) { 472 // case IPNotation.IPv4Decimal: 473 // //do not use the last Item, its the Subnetmask 474 // for (int i = 0; i < arlFrom.Count - 1; i++) { 475 // sTo += this.Bin2Dec(arlFrom[i].ToString()) + 476 // //Add Dot if its not the last IPPart, else add nothing 477 // (i == arlFrom.Count - 2 ? "" : "."); 478 // } 479 // break; 480 // case IPNotation.IPv4DecimalCIDR: 481 // //do not use the last Item, its the Subnetmask 482 // for (int i = 0; i < arlFrom.Count - 1; i++) { 483 // sTo += this.Bin2Dec(arlFrom[i].ToString()) + 484 // //Add Dot if its not the last IPPart, else add nothing 485 // (i == arlFrom.Count - 2 ? "" : "."); 486 // } 487 // //Add Subnetmask 488 // sTo += "/" + arlFrom[arlFrom.Count - 1]; 489 // break; 490 // case IPNotation.IPv4Binary: 491 // //do not use the last Item, its the Subnetmask 492 // for (int i = 0; i < arlFrom.Count - 1; i++) { 493 // sTo += arlFrom[i].ToString() + 494 // //Add Dot if its not the last IPPart, else add nothing 495 // (i == arlFrom.Count - 2 ? "" : "."); 496 // } 497 // break; 498 // case IPNotation.IPv4BinaryCIDR: 499 // break; 500 // default: 501 // break; 502 // } 503 // break; 504 // default: 505 // break; 506 // } 507 508 // this.Text = sTo; 509 // this.MaxLength = this.TextLength; 510 // } 511 512 // /// <summary> 513 // /// Occures when Behaviour-Mode OverWriteMode was changed 514 // /// </summary> 515 // /// <param name="arg_bValue">Value, Overwrite Numbers in Editfield or not</param> 516 // protected virtual void OnOverWriteChanged(bool arg_bValue) { 517 // if (this.OverWriteModeChanged != null) 518 // this.OverWriteModeChanged(arg_bValue); 519 // } 520 521 // /// <summary> 522 // /// Occures when Behaviour-Mode PreventLeave was changed 523 // /// </summary> 524 // /// <param name="arg_bValue">Value, leave control if there is an error or not</param> 525 // protected virtual void OnPreventLeaveChanged(bool arg_bValue) { 526 // if (this.PreventLeaveChanged != null) 527 // this.PreventLeaveChanged(arg_bValue); 528 // } 529 530 // #endregion //events 531 532 // #region Event-Overrides 533 534 // /// <summary> 535 // /// Override standard KeyDownEventHandler 536 // /// Catches Inputs of "." and "/" to jump to next positions 537 // /// </summary> 538 // /// <param name="e">KeyEventArgument</param> 539 // protected override void OnKeyDown(KeyEventArgs e) { 540 // //Zeichen an die richtige stelle schreiben 541 // int iPos = this.SelectionStart; 542 // char[] cText = this.Text.ToCharArray(); 543 544 // if (e.Modifiers == Keys.None) { 545 // if ((char.IsLetterOrDigit(Convert.ToChar(e.KeyValue)) || e.KeyCode == Keys.NumPad0)//Numpad0=96 --> ` 546 // && iPos < this.TextLength) { 547 // if (this.m_arlDelimeter.Contains(cText[iPos])) 548 // iPos += 1; 549 // this.SelectionStart = iPos; 550 // if (this.OverWriteMode) { 551 // if (iPos < this.TextLength) 552 // this.SelectionLength = 1; 553 // } else { 554 // if (iPos < this.TextLength) 555 // if (cText[iPos] == ' ') 556 // this.SelectionLength = 1; 557 // } 558 // } 559 // } 560 // base.OnKeyDown(e); 561 // } 562 563 // /// <summary> 564 // /// Override standard KeyUpEventHandler 565 // /// Catches Inputs of "." and "/" to jump to next positions 566 // /// </summary> 567 // /// <param name="e">KeyEventArgument</param> 568 // protected override void OnKeyUp(KeyEventArgs e) { 569 // //Zeichen an die richtige stelle schreiben 570 // int iPos = this.SelectionStart; 571 // char[] cText = this.Text.ToCharArray(); 572 573 // //Cursor hintern Punkt setzen 574 // if ((char.IsLetterOrDigit(Convert.ToChar(e.KeyValue)) || e.KeyCode == Keys.NumPad0)//Numpad0=96 --> ` 575 // && iPos < this.TextLength) { 576 // if (this.m_arlDelimeter.Contains(cText[iPos])) 577 // iPos += 1; 578 579 // this.SelectionStart = iPos; 580 // } 581 // base.OnKeyUp(e); 582 // } 583 584 585 // /// <summary> 586 // /// Override standard KeyPressEventHandler 587 // /// Catches Inputs of "." and "/" to jump to next positions 588 // /// </summary> 589 // /// <param name="e">KeyPressEventArgument</param> 590 // protected override void OnKeyPress(KeyPressEventArgs e) { 591 // //valid input charachters 592 // if (char.IsControl(e.KeyChar) || 593 // m_regexValidNumbers.IsMatch(e.KeyChar.ToString())) { 594 // e.Handled = false; 595 // } else { 596 // switch (e.KeyChar) { 597 // case '/': 598 // this.JumpToSlash(); 599 // break; 600 // case '.': 601 // case ':': 602 // this.JumpToNextDot(); 603 // break; 604 // default: 605 // break; 606 // } 607 // e.Handled = true; 608 // } 609 // base.OnKeyPress(e); 610 // } 611 612 // /// <summary> 613 // /// Override standard TextChangedEventHandler 614 // /// Looks if inserted IP-Address is valid 615 // /// </summary> 616 // /// <param name="e">EventArgument</param> 617 // protected override void OnTextChanged(EventArgs e) { 618 // base.OnTextChanged(e); 619 // if (this.Text.Length == 0) 620 // this.ResetText(); 621 622 // try { 623 // if (!this.ValidateIP()) 624 // this.error.SetError(this, "Invalid IP-address"); 625 // else 626 // this.error.SetError(this, ""); 627 // } 628 // catch (Exception LastError) { 629 // this.error.SetError(this, LastError.Message); 630 // } 631 // } 632 633 // /// <summary> 634 // /// Override standard ValidatingEventHandler 635 // /// Validates inserted IP-Address, and cancels Textbox if valid or PreventLeave=false 636 // /// </summary> 637 // /// <param name="e">CancelEventArgument</param> 638 // protected override void OnValidating(CancelEventArgs e) { 639 // //e.Cancel = true;//suppress cancel-signal = not validated 640 // e.Cancel = (!this.ValidateIP() && this.m_bPreventLeave); 641 // base.OnValidating(e); 642 // } 643 644 // #endregion //Eventhandling 645 646 // #region Methods 647 648 // /// <summary> 649 // /// Override standard ResetText 650 // /// Fills Textbox with Dots and Slashes dependend on Properties 651 // /// </summary> 652 // public override void ResetText() { 653 // base.ResetText(); 654 // switch (this.Notation) { 655 // case IPNotation.IPv4Decimal: 656 // this.Text = " . . . "; 657 // break; 658 // case IPNotation.IPv4DecimalCIDR: 659 // this.Text = " . . . / "; 660 // break; 661 // case IPNotation.IPv4Binary: 662 // this.Text = " . . . "; 663 // break; 664 // case IPNotation.IPv4BinaryCIDR: 665 // this.Text = " . . . / "; 666 // break; 667 // default: 668 // break; 669 // } 670 671 // this.MaxLength = this.TextLength; 672 // } 673 674 675 // /// <summary> 676 // /// Window-Message Constant 677 // /// </summary> 678 // protected const int WM_KEYDOWN = 0x0100; 679 680 // /// <summary> 681 // /// Override standard PreProcessMessge 682 // /// Catches Inputs of Backspaces and Deletes to remove IP-Digits at the right position 683 // /// </summary> 684 // /// <param name="msg">Process Message</param> 685 // public override bool PreProcessMessage(ref Message msg) { 686 // if (msg.Msg == WM_KEYDOWN) { 687 // Keys keyData = ((Keys)(int)msg.WParam) | ModifierKeys; 688 // Keys keyCode = ((Keys)(int)msg.WParam); 689 690 // int iPos = this.SelectionStart; 691 // char[] cText = this.Text.ToCharArray(); 692 // switch (keyCode) { 693 // case Keys.Delete: 694 // if (iPos < this.TextLength) { 695 // while (cText[iPos] == '.' || cText[iPos] == ':' || cText[iPos] == '/') { 696 // if ((iPos += 1) >= cText.Length) 697 // break; 698 // } 699 // if (iPos < this.TextLength) { 700 // base.Text = this.Text.Substring(0, iPos) + " " + this.Text.Substring(iPos + 1); 701 // this.SelectionStart = iPos + 1; 702 // } else 703 // this.SelectionStart = this.TextLength - 1; 704 // } 705 // return true; 706 // case Keys.Back: 707 // if (iPos > 0) { 708 // while (cText[iPos - 1] == '.' || cText[iPos - 1] == ':' || cText[iPos - 1] == '/') { 709 // if ((iPos -= 1) <= 0) 710 // break; 711 // } 712 // if (iPos > 0) { 713 // base.Text = this.Text.Substring(0, iPos - 1) + " " + this.Text.Substring(iPos); 714 // this.SelectionStart = iPos - 1; 715 // } else 716 // this.SelectionStart = 0; 717 // } 718 // return true; 719 // default: 720 // break; 721 // } 722 // } 723 // return base.PreProcessMessage(ref msg); 724 // } 725 726 // /// <summary> 727 // /// Returns the formatted IP-Addresses without spaces and Zeroes 728 // /// </summary> 729 // /// <returns>IP-Address without spaces and Zeroes</returns> 730 // public string GetPureIPAddress() { 731 // string s = ""; 732 // ArrayList arlIP = new ArrayList(this.Text.Replace(" ", "").Split((char[])this.m_arlDelimeter.ToArray(typeof(char)))); 733 // for (int i = 0; i < arlIP.Count; i++) { 734 // while (arlIP[i].ToString().StartsWith("0")) 735 // arlIP[i] = arlIP[i].ToString().Substring(1); 736 // } 737 // s = IPAddressTextBox.MakeIP((string[])arlIP.ToArray(typeof(string)), this.m_ipNotation); 738 // return s; 739 // } 740 741 // #endregion //Methods 742 743 // #region Helperfunctions 744 745 // /// <summary> 746 // /// Sets Inputcursor to Subnet-Slash 747 // /// </summary> 748 // private void JumpToSlash() { 749 // int iSelStart = this.Text.LastIndexOf("/"); 750 // if (iSelStart >= 0) { 751 // this.Select(iSelStart + 1, 0); 752 // } 753 // } 754 755 // /// <summary> 756 // /// Sets input cursour to next Dot 757 // /// </summary> 758 // private void JumpToNextDot() { 759 // int iSelStart = this.Text.IndexOf('.', this.SelectionStart); 760 // if (iSelStart >= 0) { 761 // this.Select(iSelStart + 1, 0); 762 // } else { 763 // iSelStart = this.Text.IndexOf(':', this.SelectionStart); 764 // if (iSelStart >= 0) { 765 // this.Select(iSelStart + 1, 0); 766 // } 767 // } 768 // } 769 770 // /// <summary> 771 // /// Converts Decimal IP-Part to Binary (default IPv6 = false) 772 // /// </summary> 773 // /// <param name="arg_sDec">Decimal IP-Part</param> 774 // /// <param name="arg_bIPv6">Binary for IPv6 (has 16 digits)</param> 775 // /// <returns>Binary IP-Part</returns> 776 // private string Dec2Bin(string arg_sDec) { 777 // return this.Dec2Bin(arg_sDec, false); 778 // } 779 // /// <summary> 780 // /// Converts Decimal IP-Part to Binary 781 // /// </summary> 782 // /// <param name="arg_sDec">Decimal IP-Part</param> 783 // /// <param name="arg_bIPv6">Binary for IPv6 (has 16 digits)</param> 784 // /// <returns>Binary IP-Part</returns> 785 // private string Dec2Bin(string arg_sDec, bool arg_bIPv6) { 786 // string sBin = (arg_bIPv6 ? "0000000000000000" : "00000000"), sSubnet = ""; 787 // arg_sDec = arg_sDec.Trim(); 788 // while (arg_sDec.Length < 3) 789 // arg_sDec = "0" + arg_sDec; 790 // if (arg_sDec.IndexOf("/") >= 0) { 791 // sSubnet = arg_sDec.Substring(arg_sDec.IndexOf("/")); 792 // arg_sDec = arg_sDec.Substring(0, arg_sDec.IndexOf("/")); 793 // } 794 // int iDec = Convert.ToInt32(arg_sDec, 10); 795 // sBin = Convert.ToString(iDec, 2); 796 // while (sBin.Length < (arg_bIPv6 ? 16 : 8)) 797 // sBin = "0" + sBin; 798 // return sBin + sSubnet; 799 // } 800 801 // /// <summary> 802 // /// Converts Binary IP-Part to Decimal 803 // /// </summary> 804 // /// <param name="arg_sBin">Binary IP-Part</param> 805 // /// <returns>Decimal IP-Part</returns> 806 // private string Bin2Dec(string arg_sBin) { 807 // string sDec = "000", sSubnet = ""; 808 // arg_sBin = arg_sBin.Trim(); 809 // while (arg_sBin.Length < 8) 810 // arg_sBin = "0" + arg_sBin; 811 // if (arg_sBin.IndexOf("/") >= 0) { 812 // sSubnet = arg_sBin.Substring(arg_sBin.IndexOf("/")); 813 // arg_sBin = arg_sBin.Substring(0, arg_sBin.IndexOf("/")); 814 // } 815 // int iBin = Convert.ToInt32(arg_sBin, 2); 816 // if (iBin > 255) 817 // throw new Exception(string.Format("Can't convert Binary to Decimal IP-Address\nbin:{0} is greater than 255", iBin)); 818 // sDec = Convert.ToString(iBin, 10); 819 // while (sDec.Length < 3) 820 // sDec = "0" + sDec; 821 // return sDec + sSubnet; 822 // } 823 824 // /// <summary> 825 // /// Converts Binary IP-Part to Hexadecimal 826 // /// </summary> 827 // /// <param name="arg_sBin">Binary IP-Part</param> 828 // /// <returns>Hexadecimal IP-Part</returns> 829 // private string Bin2Hex(string arg_sBin) { 830 // string sHex = "0000", sSubnet = ""; 831 // arg_sBin = arg_sBin.Trim(); 832 // while (arg_sBin.Length < 8) 833 // arg_sBin = "0" + arg_sBin; 834 // if (arg_sBin.IndexOf("/") >= 0) { 835 // sSubnet = arg_sBin.Substring(arg_sBin.IndexOf("/")); 836 // arg_sBin = arg_sBin.Substring(0, arg_sBin.IndexOf("/")); 837 // } 838 // int iBin = Convert.ToInt32(arg_sBin, 2); 839 // sHex = Convert.ToString(iBin, 16); 840 // while (sHex.Length < 4) 841 // sHex = "0" + sHex; 842 // return sHex + sSubnet; 843 // } 844 845 // /// <summary> 846 // /// Converts Hexadecimal IP-Part to Binary (default IPv6=true) 847 // /// </summary> 848 // /// <param name="arg_sHex">Hexadecimal IP-Part</param> 849 // /// <returns>Binary IP-Part</returns> 850 // private string Hex2Bin(string arg_sHex) { 851 // return this.Hex2Bin(arg_sHex, true); 852 // } 853 // /// <summary> 854 // /// Converts Hexadecimal IP-Part to Binary 855 // /// </summary> 856 // /// <param name="arg_sHex">Hexadecimal IP-Part</param> 857 // /// <param name="arg_bIPv6">Binary for IPv6 (16 digits)</param> 858 // /// <returns>Binary IP-Part</returns> 859 // private string Hex2Bin(string arg_sHex, bool arg_bIPv6) { 860 // string sBin = (arg_bIPv6 ? "0000000000000000" : "00000000"), sSubnet = ""; 861 // arg_sHex = arg_sHex.Trim(); 862 // while (arg_sHex.Length < 3) 863 // arg_sHex = "0" + arg_sHex; 864 // if (arg_sHex.IndexOf("/") >= 0) { 865 // sSubnet = arg_sHex.Substring(arg_sHex.IndexOf("/")); 866 // arg_sHex = arg_sHex.Substring(0, arg_sHex.IndexOf("/")); 867 // } 868 // int iHex = Convert.ToInt32(arg_sHex, 16); 869 // if (iHex > 255 && !arg_bIPv6) 870 // throw new Exception(string.Format("Can't convert Hexadecimal to Binary IP-Address\nhex:{0} is greater than 11111111", iHex)); 871 // sBin = Convert.ToString(iHex, 2); 872 // while (sBin.Length < (arg_bIPv6 ? 16 : 8)) 873 // sBin = "0" + sBin; 874 // return sBin + sSubnet; 875 // } 876 877 // /// <summary> 878 // /// Converts Decimal IP-Part to Hexadecimal 879 // /// </summary> 880 // /// <param name="arg_sDec">Decimal IP-Part</param> 881 // /// <returns>Hexadecimal IP-Part</returns> 882 // private string Dec2Hex(string arg_sDec) { 883 // string sHex = "0000", sSubnet = ""; 884 // arg_sDec = arg_sDec.Trim(); 885 // while (arg_sDec.Length < 8) 886 // arg_sDec = "0" + arg_sDec; 887 // if (arg_sDec.IndexOf("/") >= 0) { 888 // sSubnet = arg_sDec.Substring(arg_sDec.IndexOf("/")); 889 // arg_sDec = arg_sDec.Substring(0, arg_sDec.IndexOf("/")); 890 // } 891 // int iDec = Convert.ToInt32(arg_sDec, 10); 892 // sHex = Convert.ToString(iDec, 16); 893 // while (sHex.Length < 4) 894 // sHex = "0" + sHex; 895 // return sHex + sSubnet; 896 // } 897 898 // /// <summary> 899 // /// Converts Hexadecimal IP-Part to Decimal 900 // /// </summary> 901 // /// <param name="arg_sHex">Hexadecimal IP-Part</param> 902 // /// <returns>Decimal IP-Part</returns> 903 // private string Hex2Dec(string arg_sHex) { 904 // string sDec = "000", sSubnet = ""; 905 // arg_sHex = arg_sHex.Trim(); 906 // while (arg_sHex.Length < 8) 907 // arg_sHex = "0" + arg_sHex; 908 // if (arg_sHex.IndexOf("/") >= 0) { 909 // sSubnet = arg_sHex.Substring(arg_sHex.IndexOf("/")); 910 // arg_sHex = arg_sHex.Substring(0, arg_sHex.IndexOf("/")); 911 // } 912 // int iHex = Convert.ToInt32(arg_sHex, 16); 913 // if (iHex > 255) 914 // throw new Exception(string.Format("Can't convert Hexadecimal to Decimal IP-Address\nhex:{0} is greater than 255", iHex)); 915 // sDec = Convert.ToString(iHex, 10); 916 // while (sDec.Length < 3) 917 // sDec = "0" + sDec; 918 // return sDec + sSubnet; 919 // } 920 921 // /// <summary> 922 // /// Checks if IP in Textfield is valid 923 // /// </summary> 924 // /// <returns>true/false valid/not</returns> 925 // private bool ValidateIP() { 926 // if (IPAddressTextBox.ValidateIP(this.Text, this.m_newIPNotation, this.m_arlDelimeter)) 927 // return true; 928 // else 929 // //if Control is not visible or enabled, it doesn't matter if IP is valid 930 // return this.Enabled || this.Visible ? false : true; 931 // } 932 933 // /// <summary> 934 // /// Checks if the given String is an valid ip-address 935 // /// </summary> 936 // /// <param name="arg_sIP">IP-String</param> 937 // /// <param name="arg_ipNotation">IP-notation</param> 938 // /// <param name="arg_arlDelimeter">Delimeter to parse IPString</param> 939 // /// <returns>true/false validated/not</returns> 940 // protected static bool ValidateIP(string arg_sIP, IPNotation arg_ipNotation, ArrayList arg_arlDelimeter) { 941 // bool bValidated = false; 942 // ArrayList arlIP = new ArrayList(arg_sIP.Split((char[])arg_arlDelimeter.ToArray(typeof(char)))); 943 944 // try { 945 // switch (arg_ipNotation) { 946 // case IPNotation.IPv4Decimal: 947 // case IPNotation.IPv4Binary: 948 // bValidated = arlIP.Count == 4; 949 // break; 950 // case IPNotation.IPv4DecimalCIDR: 951 // case IPNotation.IPv4BinaryCIDR: 952 // bValidated = arlIP.Count == 5; 953 // break; 954 // default: 955 // break; 956 // } 957 // if (!bValidated) { 958 // throw new Exception("IP-Address has wrong element count"); 959 // } 960 961 // //don't check the 1st 2 elemnt if its IPv4 in IPv6-notation 962 // for (int i = (arg_ipNotation.ToString().IndexOf("IPv6IPv4") == 0 ? 2 : 0); 963 // //don't check the subnet element 964 // i < (arg_ipNotation.ToString().IndexOf("CIDR") > 0 ? arlIP.Count - 1 : arlIP.Count); 965 // i++) { 966 // string sIPPart = arlIP[i].ToString().Replace(" ", ""); 967 // int iIPPart = 0; 968 // switch (arg_ipNotation) { 969 // case IPNotation.IPv4Decimal: 970 // case IPNotation.IPv4DecimalCIDR: 971 // while (sIPPart.Length < 3) 972 // sIPPart = "0" + sIPPart; 973 // iIPPart = Convert.ToInt32(sIPPart, 10); 974 // if (iIPPart < 256) 975 // bValidated = true; 976 // else 977 // bValidated = false; 978 // break; 979 // case IPNotation.IPv4Binary: 980 // case IPNotation.IPv4BinaryCIDR: 981 // while (sIPPart.Length < 8) 982 // sIPPart = "0" + sIPPart; 983 // iIPPart = Convert.ToInt32(sIPPart, 2); 984 // if (iIPPart < 256) 985 // bValidated = true; 986 // else 987 // bValidated = false; 988 // break; 989 // default: 990 // break; 991 // } 992 // if (!bValidated) { 993 // throw new Exception(string.Format("IP-Address element {0}({1}) has wrong format", i, sIPPart)); 994 // } 995 // } 996 // } 997 // catch (Exception LastError) { 998 // System.Diagnostics.Debug.WriteLine(LastError.Message); 999 // bValidated = false; 1000 // throw LastError; 1001 // } 1002 // return bValidated; 1003 // } 1004 1005 // /// <summary> 1006 // /// Adds Spaces to given IP-Address, so it fits in the textfield 1007 // /// </summary> 1008 // /// <param name="arg_sIP">IP-String</param> 1009 // /// <param name="arg_ipNotation">IP-notation</param> 1010 // /// <param name="arg_arlDelimeter">Delimeter to parse IPString</param> 1011 // /// <returns>IP-Address with Spaces</returns> 1012 // protected static string MakeValidSpaces(string arg_sIP, IPNotation arg_ipNotation, ArrayList arg_arlDelimeter) { 1013 // ArrayList arlIP = new ArrayList(arg_sIP.Split((char[])arg_arlDelimeter.ToArray(typeof(char)))); 1014 // //don't check the 1st 2 elemnt if its IPv4 in IPv6-notation 1015 // for (int i = (arg_ipNotation.ToString().IndexOf("IPv6IPv4") == 0 ? 2 : 0); 1016 // //don't check the subnet element 1017 // i < (arg_ipNotation.ToString().IndexOf("CIDR") > 0 ? arlIP.Count - 1 : arlIP.Count); 1018 // i++) { 1019 // switch (arg_ipNotation) { 1020 // case IPNotation.IPv4Decimal: 1021 // case IPNotation.IPv4DecimalCIDR: 1022 // while (arlIP[i].ToString().Length < 3) 1023 // arlIP[i] = arlIP[i].ToString() + " "; 1024 // break; 1025 // case IPNotation.IPv4Binary: 1026 // case IPNotation.IPv4BinaryCIDR: 1027 // while (arlIP[i].ToString().Length < 8) 1028 // arlIP[i] = arlIP[i].ToString() + " "; 1029 // break; 1030 // default: 1031 // break; 1032 // } 1033 // } 1034 1035 // return IPAddressTextBox.MakeIP((string[])arlIP.ToArray(typeof(string)), arg_ipNotation); 1036 // } 1037 1038 // /// <summary> 1039 // /// Adds Zeroes to given IP-Address, so it fits in the textfield 1040 // /// </summary> 1041 // /// <param name="arg_sIP">IP-String</param> 1042 // /// <param name="arg_ipNotation">IP-notation</param> 1043 // /// <param name="arg_arlDelimeter">Delimeter to parse IPString</param> 1044 // /// <returns>IP-Address with Spaces</returns> 1045 // protected static string MakeValidZeroes(string arg_sIP, IPNotation arg_ipNotation, ArrayList arg_arlDelimeter) { 1046 // ArrayList arlIP = new ArrayList(arg_sIP.Split((char[])arg_arlDelimeter.ToArray(typeof(char)))); 1047 // //don't check the 1st 2 elemnt if its IPv4 in IPv6-notation 1048 // for (int i = (arg_ipNotation.ToString().IndexOf("IPv6IPv4") == 0 ? 2 : 0); 1049 // //don't check the subnet element 1050 // i < (arg_ipNotation.ToString().IndexOf("CIDR") > 0 ? arlIP.Count - 1 : arlIP.Count); 1051 // i++) { 1052 // switch (arg_ipNotation) { 1053 // case IPNotation.IPv4Decimal: 1054 // case IPNotation.IPv4DecimalCIDR: 1055 // while (arlIP[i].ToString().Length < 3) 1056 // arlIP[i] = "0" + arlIP[i].ToString(); 1057 // break; 1058 // case IPNotation.IPv4Binary: 1059 // case IPNotation.IPv4BinaryCIDR: 1060 // while (arlIP[i].ToString().Length < 8) 1061 // arlIP[i] = "0" + arlIP[i].ToString(); 1062 // break; 1063 // default: 1064 // break; 1065 // } 1066 // } 1067 1068 // return IPAddressTextBox.MakeIP((string[])arlIP.ToArray(typeof(string)), arg_ipNotation); 1069 // } 1070 1071 // /// <summary> 1072 // /// Creates IP-Addresstring from given StrignArray and Notation 1073 // /// </summary> 1074 // /// <param name="arg_sIP">String-Array with elements for IP-Address</param> 1075 // /// <param name="arg_ipNotation">Notation of IP-Address</param> 1076 // /// <returns>IPAddress-String</returns> 1077 // protected static string MakeIP(string[] arg_sIP, IPNotation arg_ipNotation) { 1078 // string s = ""; 1079 // for (int i = 0; i < arg_sIP.Length; i++) { 1080 // switch (arg_ipNotation) { 1081 // case IPNotation.IPv4Decimal: 1082 // case IPNotation.IPv4Binary: 1083 // s += (arg_sIP[i].Length > 0 ? arg_sIP[i] : "0") + (i < (arg_sIP.Length - 1) ? "." : ""); 1084 // break; 1085 // case IPNotation.IPv4DecimalCIDR: 1086 // case IPNotation.IPv4BinaryCIDR: 1087 // s += (arg_sIP[i].Length > 0 ? arg_sIP[i] : "0") + (i < (arg_sIP.Length - 2) ? "." : (i < arg_sIP.Length - 1) ? "/" : ""); 1088 // break; 1089 // default: 1090 // break; 1091 // } 1092 // } 1093 // return s; 1094 // } 1095 1096 // #endregion //Helperfunctions 1097 // } 1098 //}
Note: See TracChangeset
for help on using the changeset viewer.