Example #1
0
 private void btnSelect_Click(object sender, EventArgs e)
 {
     try
     {
         int selected = listboxLines.SelectedIndex;
         System.Windows.Forms.ListBox.SelectedIndexCollection collection = listboxLines.SelectedIndices;// lineList[selected];
         if (collection != null)
         {
             selectedLine = new GOSTLine[collection.Count];
             for (int i = 0; i < selectedLine.Length; i++)
             {
                 selectedLine[i] = lineList[collection[i]];
             }
         }
         else
         {
             selectedLine = null;
         }
         Hide();
     }
     catch (Exception ex)
     {
         Log.Out(ex);
     }
 }
        private void button_RemoveVirtual_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.ListBox.SelectedIndexCollection selItems = listBox_VirtualServersUsing.SelectedIndices;
            if (selItems.Count > 0)
            {
                iControl.LocalLBVirtualServerVirtualServerRule[][] rules = new iControl.LocalLBVirtualServerVirtualServerRule[selItems.Count][];
                String[]  vs_list = new String[selItems.Count];
                iRuleInfo iri     = (iRuleInfo)m_tn.Tag;

                for (int i = 0; i < selItems.Count; i++)
                {
                    vs_list[i]            = listBox_VirtualServersUsing.Items[selItems[i]].ToString();
                    rules[i]              = new iControl.LocalLBVirtualServerVirtualServerRule[1];
                    rules[i][0]           = new iControl.LocalLBVirtualServerVirtualServerRule();
                    rules[i][0].rule_name = iri.rule_name;
                    rules[i][0].priority  = 500;
                }

                try
                {
                    Clients.VirtualServer.remove_rule(vs_list, rules);
                    for (int i = 0; i < selItems.Count; i++)
                    {
                        listBox_VirtualServersUsing.Items.RemoveAt(selItems[i]);
                        listBox_VirtualServersNotUsing.Items.Add(vs_list[i]);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error Occurred");
                }
            }
        }
Example #3
0
 private void BEliminar_Click(object sender, EventArgs e)
 {
     System.Windows.Forms.ListBox.SelectedIndexCollection a = listBoxI.SelectedIndices;
     for (int i = a.Count - 1; i >= 0; i--)
     {
         listBoxI.Items.RemoveAt(a[i]);
     }
     numeroDeItens();
     actualizarIndice();
 }
        private void TrackSelectionChange(System.Windows.Forms.ListBox lb, List <int> selection)
        {
            System.Windows.Forms.ListBox.SelectedIndexCollection sic = lb.SelectedIndices;
            foreach (int index in sic)
            {
                if (!selection.Contains(index))
                {
                    selection.Add(index);
                }
            }

            foreach (int index in new List <int>(selection))
            {
                if (!sic.Contains(index))
                {
                    selection.Remove(index);
                }
            }
        }
        btnRemoveSelected_Click
        (
            object sender,
            EventArgs e
        )
        {
            AssertValid();

            System.Windows.Forms.ListBox.ObjectCollection oItems =
                lbxMinimumValues.Items;

            System.Windows.Forms.ListBox.SelectedIndexCollection oSelectedIndices =
                lbxMinimumValues.SelectedIndices;

            Int32 iSelectedIndices = oSelectedIndices.Count;

            for (Int32 i = iSelectedIndices - 1; i >= 0; i--)
            {
                oItems.RemoveAt(oSelectedIndices[i]);
            }
        }
        private void button_AddVirtual_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.ListBox.SelectedIndexCollection selItems = listBox_VirtualServersNotUsing.SelectedIndices;
            if (selItems.Count > 0)
            {
                iControl.LocalLBVirtualServerVirtualServerRule[][] rules = new iControl.LocalLBVirtualServerVirtualServerRule[selItems.Count][];
                String[]  vs_list = new String[selItems.Count];
                iRuleInfo iri     = (iRuleInfo)m_tn.Tag;

                for (int i = 0; i < selItems.Count; i++)
                {
                    vs_list[i]            = listBox_VirtualServersNotUsing.Items[selItems[i]].ToString();
                    rules[i]              = new iControl.LocalLBVirtualServerVirtualServerRule[1];
                    rules[i][0]           = new iControl.LocalLBVirtualServerVirtualServerRule();
                    rules[i][0].rule_name = iri.rule_name;
                    rules[i][0].priority  = 500;

                    // Look for a specified priority in the iRule itself
                    System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("priority\\s+(?<pri>[0-9]+)\\s+");
                    System.Text.RegularExpressions.Match match = regex.Match(iri.rule_details);
                    if (null != match)
                    {
                        int pri = 500;
                        try
                        {
                            String sPri = match.Groups["pri"].Value;
                            pri = Convert.ToInt32(sPri);
                        }
                        catch (Exception)
                        {
                        }
                        rules[i][0].priority = pri;
                    }
                }

                // Query old iRules for selected VIPs (to look for matching priorities)
                iControl.LocalLBVirtualServerVirtualServerRule[][] existing_rules =
                    Clients.VirtualServer.get_rule(vs_list);

                for (int i = 0; i < vs_list.Length; i++)
                {
                    for (int j = 0; j < existing_rules[i].Length; j++)
                    {
                        if (rules[i][0].priority == existing_rules[i][j].priority)
                        {
                            // Increment it and try again...
                            rules[i][0].priority++;
                            j = -1;
                            continue;
                        }
                    }
                }

                // Apply the iRules to the selected Virtuals
                try
                {
                    Clients.VirtualServer.add_rule(vs_list, rules);
                    for (int i = 0; i < selItems.Count; i++)
                    {
                        listBox_VirtualServersNotUsing.Items.RemoveAt(selItems[i]);
                        listBox_VirtualServersUsing.Items.Add(vs_list[i]);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error Occurred");
                }
            }
        }