Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1018 for trunk


Ignore:
Timestamp:
12/17/08 16:52:15 (16 years ago)
Author:
aleitner
Message:

Job and User insert updated, also job with parent-job, user in user-group. (#380)

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  
    7373  </ItemGroup>
    7474  <ItemGroup>
    75     <Compile Include="AddNewForm.cs">
     75    <Compile Include="AddUserForm.cs">
    7676      <SubType>Form</SubType>
    7777    </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>
    8086    </Compile>
    8187    <Compile Include="HiveServerConsole.cs">
     
    94100    <Compile Include="HiveServerConsolePlugin.cs" />
    95101    <Compile Include="IPAdressTextBox.cs">
    96       <SubType>Component</SubType>
    97102    </Compile>
    98103    <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>
    101109    </EmbeddedResource>
    102110    <EmbeddedResource Include="HiveServerConsole.resx">
  • trunk/sources/HeuristicLab.Hive.Server.Console/HiveServerConsole.Designer.cs

    r978 r1018  
    5959      this.tbPwd = new System.Windows.Forms.TextBox();
    6060      this.lblError = new System.Windows.Forms.Label();
    61       this.tbIp = new HeuristicLab.Hive.Server.Console.IPAddressTextBox();
     61      this.tbIp = new System.Windows.Forms.TextBox();
    6262      this.msServerConsole.SuspendLayout();
    6363      this.gbManager.SuspendLayout();
  • trunk/sources/HeuristicLab.Hive.Server.Console/HiveServerConsole.cs

    r978 r1018  
    104104        } else if (tbPort.Text == "") {
    105105          lblError.Text = "Please type in Port";
     106        } else if (tbIp.Text == "") {
     107          lblError.Text = "Please type in IP-Adress";
    106108        }
    107109        return false;
  • trunk/sources/HeuristicLab.Hive.Server.Console/HiveServerManagementConsole.Designer.cs

    r978 r1018  
    2525    private void InitializeComponent() {
    2626      this.components = new System.ComponentModel.Container();
    27       System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new string[] {
     27      System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem(new string[] {
    2828            "",
    2929            "Test"}, -1);
     
    3434      this.addToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    3535      this.jobToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    36       this.jobToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
    37       this.groupToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
    3836      this.userToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    3937      this.userToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
     
    4341      this.scClientControl = new System.Windows.Forms.SplitContainer();
    4442      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();
    4743      this.lvClientControl = new System.Windows.Forms.ListView();
    4844      this.imageList1 = new System.Windows.Forms.ImageList(this.components);
     
    5046      this.scJobControl = new System.Windows.Forms.SplitContainer();
    5147      this.tvJobControl = new System.Windows.Forms.TreeView();
    52       this.listView3 = new System.Windows.Forms.ListView();
     48      this.lvJobControl = new System.Windows.Forms.ListView();
    5349      this.tpUserControl = new System.Windows.Forms.TabPage();
    5450      this.scUserControl = new System.Windows.Forms.SplitContainer();
     
    5955      this.listView2 = new System.Windows.Forms.ListView();
    6056      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);
    6159      this.menuStrip1.SuspendLayout();
    6260      this.tcManagementConsole.SuspendLayout();
     
    6563      this.scClientControl.Panel2.SuspendLayout();
    6664      this.scClientControl.SuspendLayout();
    67       this.cmsAddDelete.SuspendLayout();
    6865      this.tpJobControl.SuspendLayout();
    6966      this.scJobControl.Panel1.SuspendLayout();
     
    9895      //
    9996      this.closeToolStripMenuItem.Name = "closeToolStripMenuItem";
    100       this.closeToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
     97      this.closeToolStripMenuItem.Size = new System.Drawing.Size(111, 22);
    10198      this.closeToolStripMenuItem.Text = "Close";
    10299      this.closeToolStripMenuItem.Click += new System.EventHandler(this.close_Click);
     
    113110      // jobToolStripMenuItem
    114111      //
    115       this.jobToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
    116             this.jobToolStripMenuItem1,
    117             this.groupToolStripMenuItem1});
    118112      this.jobToolStripMenuItem.Name = "jobToolStripMenuItem";
    119113      this.jobToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
    120114      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);
    134116      //
    135117      // userToolStripMenuItem
     
    139121            this.groupToolStripMenuItem2});
    140122      this.userToolStripMenuItem.Name = "userToolStripMenuItem";
    141       this.userToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
     123      this.userToolStripMenuItem.Size = new System.Drawing.Size(107, 22);
    142124      this.userToolStripMenuItem.Text = "User";
    143125      //
     
    145127      //
    146128      this.userToolStripMenuItem1.Name = "userToolStripMenuItem1";
    147       this.userToolStripMenuItem1.Size = new System.Drawing.Size(152, 22);
     129      this.userToolStripMenuItem1.Size = new System.Drawing.Size(114, 22);
    148130      this.userToolStripMenuItem1.Text = "User";
    149131      this.userToolStripMenuItem1.Click += new System.EventHandler(this.userToolStripMenuItem1_Click);
     
    152134      //
    153135      this.groupToolStripMenuItem2.Name = "groupToolStripMenuItem2";
    154       this.groupToolStripMenuItem2.Size = new System.Drawing.Size(152, 22);
     136      this.groupToolStripMenuItem2.Size = new System.Drawing.Size(114, 22);
    155137      this.groupToolStripMenuItem2.Text = "Group";
    156138      this.groupToolStripMenuItem2.Click += new System.EventHandler(this.groupToolStripMenuItem2_Click);
     
    199181      // tvClientControl
    200182      //
    201       this.tvClientControl.ContextMenuStrip = this.cmsAddDelete;
    202183      this.tvClientControl.Dock = System.Windows.Forms.DockStyle.Fill;
    203184      this.tvClientControl.Location = new System.Drawing.Point(0, 0);
     
    206187      this.tvClientControl.TabIndex = 0;
    207188      //
    208       // cmsAddDelete
    209       //
    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       // tsmiDelete
    216       //
    217       this.tsmiDelete.Name = "tsmiDelete";
    218       this.tsmiDelete.Size = new System.Drawing.Size(116, 22);
    219       this.tsmiDelete.Text = "Delete";
    220       //
    221189      // lvClientControl
    222190      //
     
    224192      this.lvClientControl.ImeMode = System.Windows.Forms.ImeMode.Off;
    225193      this.lvClientControl.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
    226             listViewItem1});
     194            listViewItem2});
    227195      this.lvClientControl.LargeImageList = this.imageList1;
    228196      this.lvClientControl.Location = new System.Drawing.Point(0, 0);
     
    263231      // scJobControl.Panel2
    264232      //
    265       this.scJobControl.Panel2.Controls.Add(this.listView3);
     233      this.scJobControl.Panel2.Controls.Add(this.lvJobControl);
    266234      this.scJobControl.Size = new System.Drawing.Size(637, 346);
    267235      this.scJobControl.SplitterDistance = 139;
     
    270238      // tvJobControl
    271239      //
    272       this.tvJobControl.ContextMenuStrip = this.cmsAddDelete;
    273240      this.tvJobControl.Dock = System.Windows.Forms.DockStyle.Fill;
    274241      this.tvJobControl.Location = new System.Drawing.Point(0, 0);
     
    277244      this.tvJobControl.TabIndex = 2;
    278245      //
    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;
    287255      //
    288256      // tpUserControl
     
    316284      // tvUserControl
    317285      //
    318       this.tvUserControl.ContextMenuStrip = this.cmsAddDelete;
    319286      this.tvUserControl.Dock = System.Windows.Forms.DockStyle.Fill;
    320287      this.tvUserControl.Location = new System.Drawing.Point(0, 0);
     
    362329      this.directorySearcher1.ServerPageTimeLimit = System.TimeSpan.Parse("-00:00:01");
    363330      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");
    364341      //
    365342      // HiveServerManagementConsole
     
    381358      this.scClientControl.Panel2.ResumeLayout(false);
    382359      this.scClientControl.ResumeLayout(false);
    383       this.cmsAddDelete.ResumeLayout(false);
    384360      this.tpJobControl.ResumeLayout(false);
    385361      this.scJobControl.Panel1.ResumeLayout(false);
     
    408384    private System.Windows.Forms.ListView lvClientControl;
    409385    private System.Windows.Forms.SplitContainer scJobControl;
    410     private System.Windows.Forms.ListView listView3;
     386    private System.Windows.Forms.ListView lvJobControl;
    411387    private System.Windows.Forms.SplitContainer scUserControl;
    412388    private System.Windows.Forms.TreeView treeView2;
     
    419395    private System.Windows.Forms.ToolStripMenuItem jobToolStripMenuItem;
    420396    private System.Windows.Forms.ToolStripMenuItem userToolStripMenuItem;
    421     private System.Windows.Forms.ToolStripMenuItem jobToolStripMenuItem1;
    422     private System.Windows.Forms.ToolStripMenuItem groupToolStripMenuItem1;
    423397    private System.Windows.Forms.ToolStripMenuItem userToolStripMenuItem1;
    424398    private System.Windows.Forms.ToolStripMenuItem groupToolStripMenuItem2;
    425     private System.Windows.Forms.ContextMenuStrip cmsAddDelete;
    426     private System.Windows.Forms.ToolStripMenuItem tsmiDelete;
    427399    private System.Windows.Forms.ImageList imageList2;
    428400    private System.DirectoryServices.DirectorySearcher directorySearcher1;
     401    private System.Windows.Forms.Timer timerSyncronize;
     402    private System.Windows.Forms.ImageList imageList3;
    429403  }
    430404}
  • trunk/sources/HeuristicLab.Hive.Server.Console/HiveServerManagementConsole.cs

    r995 r1018  
    4141
    4242    ResponseList<ClientGroup> clients = null;
     43    ResponseList<ClientInfo> clientInfo = null;
    4344    ResponseList<Job> jobs = null;
    4445    ResponseList<UserGroup> userGroups = null;
     46    ResponseList<User> usersList = null;
    4547
    4648    public HiveServerManagementConsole() {
    4749      InitializeComponent();
    48       addItems();
     50      addClients();
     51      addJobs();
     52      addUsers();
     53
     54      timerSyncronize.Tick += new EventHandler(tickSync);
     55      timerSyncronize.Start();
    4956    }
    5057
    51     private void addItems() {
     58    private void tickSync(object obj, EventArgs e) {
     59      addClients();
     60      addJobs();
     61      addUsers();
     62    }
     63
     64    private void addClients() {
    5265      IClientManager clientManager =
    5366        ServiceLocator.GetClientManager();
    5467
    55       IJobManager jobManager =
    56         ServiceLocator.GetJobManager();
    57 
    58       IUserRoleManager userRoleManager =
    59         ServiceLocator.GetUserRoleManager();
    60 
    61 
    6268      clients = clientManager.GetAllClientGroups();
    63       jobs = jobManager.GetAllJobs();
    64 
    65       userGroups = userRoleManager.GetAllUserGroups();
    6669
    6770      lvClientControl.Items.Clear();
     71      tvClientControl.Nodes.Clear();
    6872      int count = 0;
    6973      foreach (ClientGroup cg in clients.List) {
     
    7882      } // Groups
    7983
     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();
    80101
    81102      foreach (Job job in jobs.List) {
    82103        tvJobControl.Nodes.Add(job.Id.ToString());
     104        lvJobControl.Items.Add(new ListViewItem(job.Id.ToString(), 0));
    83105      } // 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();
    84117
    85118      foreach (UserGroup ug in userGroups.List) {
     
    87120        ListViewGroup lvg = new ListViewGroup(ug.Name, HorizontalAlignment.Left);
    88121
    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          }
    92128        }
    93129        lvUserControl.Groups.Add(lvg);
     130
    94131      } // 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);
    95139    }
    96140
     
    120164
    121165    private void jobToolStripMenuItem1_Click(object sender, EventArgs e) {
    122       AddNewForm newForm = new AddNewForm("Job", false);
     166      AddJobForm newForm = new AddJobForm();
    123167      newForm.Show();
    124168    }
    125169
    126170    private void userToolStripMenuItem1_Click(object sender, EventArgs e) {
    127       AddNewForm newForm = new AddNewForm("User", false);
     171      AddUserForm newForm = new AddUserForm("User", false);
    128172      newForm.Show();
    129173    }
    130174
    131175    private void groupToolStripMenuItem2_Click(object sender, EventArgs e) {
    132       AddNewForm newForm = new AddNewForm("User", true);
     176      AddUserForm newForm = new AddUserForm("User", true);
    133177      newForm.Show();
    134178
  • trunk/sources/HeuristicLab.Hive.Server.Console/HiveServerManagementConsole.resx

    r978 r1018  
    119119  </resheader>
    120120  <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>
    125122  </metadata>
    126123  <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>
    128125  </metadata>
    129126  <data name="imageList1.ImageStream" mimetype="application/x-microsoft.net.object.binary.base64">
     
    218215</value>
    219216  </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>
    220266  <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>
    222268  </metadata>
    223269  <data name="imageList2.ImageStream" mimetype="application/x-microsoft.net.object.binary.base64">
     
    298344  </data>
    299345  <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>
    301350  </metadata>
    302351</root>
  • trunk/sources/HeuristicLab.Hive.Server.Console/IPAdressTextBox.cs

    r778 r1018  
    2020#endregion
    2121
    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 }
     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.