private bool modifyClass()
        {
            // TODO: Add data value support
            bool bModified = false;
            //int num_members = listBox_Members.Items.Count;
            int num_members = listView_Members.Items.Count;
            String sItem = "";
            switch (m_type)
            {
                case iControl.LocalLBClassClassType.CLASS_TYPE_ADDRESS:
                    {
                        iControl.LocalLBClassAddressClass[] class_list = new iControl.LocalLBClassAddressClass[1];
                        class_list[0] = new iControl.LocalLBClassAddressClass();
                        class_list[0].name = textBox_Name.Text;
                        class_list[0].members = new iControl.LocalLBClassAddressEntry[num_members];

                        String[][] data_values = new String[1][];
                        data_values[0] = new String[num_members];

                        for (int i = 0; i < num_members; i++)
                        {
                            //String[] tokens = listBox_Members.Items[i].ToString().Split(new String[] { " := " }, StringSplitOptions.RemoveEmptyEntries);
                            //sItem = tokens[0];
                            ////sItem = listBox_Members.Items[i].ToString();
                            //String[] sSplit = sItem.Split(new char[] { '/' });

                            //class_list[0].members[i] = new iControl.LocalLBClassAddressEntry();
                            //class_list[0].members[i].address = sSplit[0];
                            //class_list[0].members[i].netmask = "255.255.255.255";
                            //if (sSplit.Length > 1)
                            //{
                            //    if (isAddress(sSplit[1]))
                            //    {
                            //        class_list[0].members[i].netmask = sSplit[1];
                            //    }
                            //    else
                            //    {
                            //        class_list[0].members[i].netmask = CIDRHelper.getMask(Convert.ToInt32(sSplit[1]));
                            //    }
                            //}
                            //data_values[0][i] = (tokens.Length > 1) ? tokens[1] : "";

                            sItem = listView_Members.Items[i].Text.ToString();
                            String[] sSplit = sItem.Split(new char[] { '/' });
                            class_list[0].members[i] = new iControl.LocalLBClassAddressEntry();
                            class_list[0].members[i].address = sSplit[0];
                            class_list[0].members[i].netmask = "255.255.255.255";
                            if (sSplit.Length > 1)
                            {
                                if (isAddress(sSplit[1]))
                                {
                                    class_list[0].members[i].netmask = getAddress(sSplit[1]);
                                }
                                else
                                {
                                    class_list[0].members[i].netmask = CIDRHelper.getMask(Convert.ToInt32(sSplit[1]));
                                }
                            }
                            if (listView_Members.Items[i].SubItems.Count > 1)
                            {
                                data_values[0][i] = listView_Members.Items[i].SubItems[1].Text.ToString();
                            }
                            else
                            {
                                data_values[0][i] = "";
                            }
                        }
                        try
                        {
                            //try
                            //{
                            //    Clients.Class.delete_class(new String[] { textBox_Name.Text });
                            //}
                            //catch (Exception) { }

                            //Clients.Class.create_address_class(class_list);
                            Clients.Class.modify_address_class(class_list);
                            if (m_bLTMSupportsValues)
                            {
                                Clients.Class.set_address_class_member_data_value(class_list, data_values);
                            }
                            bModified = true;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message.ToString(), "Error");
                        }
                    }
                    break;
                case iControl.LocalLBClassClassType.CLASS_TYPE_VALUE:
                    {
                        iControl.LocalLBClassValueClass[] class_list = new iControl.LocalLBClassValueClass[1];
                        class_list[0] = new iControl.LocalLBClassValueClass();
                        class_list[0].name = textBox_Name.Text;
                        class_list[0].members = new long[num_members];

                        String[][] data_values = new String[1][];
                        data_values[0] = new String[num_members];

                        for (int i = 0; i < num_members; i++)
                        {
                            //String[] tokens = listBox_Members.Items[i].ToString().Split(new String[] { " := " }, StringSplitOptions.RemoveEmptyEntries);
                            //sItem = tokens[0];
                            //class_list[0].members[i] = Convert.ToInt32(sItem);
                            //data_values[0][i] = (tokens.Length > 1) ? tokens[1] : "";

                            class_list[0].members[i] = Convert.ToInt32(listView_Members.Items[i].Text.ToString());
                            if (listView_Members.Items[i].SubItems.Count > 1)
                            {
                                data_values[0][i] = listView_Members.Items[i].SubItems[1].Text.ToString();
                            }
                            else
                            {
                                data_values[0][i] = "";
                            }
                        }
                        try
                        {
                            //Clients.Class.delete_class(new String[] { textBox_Name.Text });
                            //Clients.Class.create_value_class(class_list);
                            Clients.Class.modify_value_class(class_list);
                            if (m_bLTMSupportsValues)
                            {
                                Clients.Class.set_value_class_member_data_value(class_list, data_values);
                            }
                            bModified = true;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message.ToString(), "Error");
                        }
                    }
                    break;
                case iControl.LocalLBClassClassType.CLASS_TYPE_STRING:
                    {
                        iControl.LocalLBClassStringClass[] class_list = new iControl.LocalLBClassStringClass[1];
                        class_list[0] = new iControl.LocalLBClassStringClass();
                        class_list[0].name = textBox_Name.Text;
                        class_list[0].members = new String[num_members];

                        String[][] data_values = new String[1][];
                        data_values[0] = new String[num_members];
                        for (int i = 0; i < num_members; i++)
                        {
                            //String[] tokens = listBox_Members.Items[i].ToString().Split(new String[] { " := " }, StringSplitOptions.RemoveEmptyEntries);
                            //sItem = tokens[0];
                            //class_list[0].members[i] = sItem;
                            //data_values[0][i] = (tokens.Length > 1) ? tokens[1] : "";

                            class_list[0].members[i] = listView_Members.Items[i].Text.ToString();
                            if (listView_Members.Items[i].SubItems.Count > 1)
                            {
                                data_values[0][i] = listView_Members.Items[i].SubItems[1].Text.ToString();
                            }
                            else
                            {
                                data_values[0][i] = "";
                            }
                        }
                        try
                        {
                            //Clients.Class.delete_class(new String[] { textBox_Name.Text });
                            //Clients.Class.create_string_class(class_list);
                            Clients.Class.modify_string_class(class_list);
                            if (m_bLTMSupportsValues)
                            {
                                Clients.Class.set_string_class_member_data_value(class_list, data_values);
                            }
                            bModified = true;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message.ToString(), "Error");
                        }
                    }
                    break;
            }
            if (bModified)
            {
                try
                {
                    Clients.ConfigSync.save_configuration("", iControl.SystemConfigSyncSaveMode.SAVE_HIGH_LEVEL_CONFIG);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error Saving Configuration");
                }
            }
            return bModified;
        }
Esempio n. 2
0
        private bool modifyClass()
        {
            // TODO: Add data value support
            bool bModified = false;
            //int num_members = listBox_Members.Items.Count;
            int    num_members = listView_Members.Items.Count;
            String sItem       = "";

            switch (m_type)
            {
            case iControl.LocalLBClassClassType.CLASS_TYPE_ADDRESS:
            {
                iControl.LocalLBClassAddressClass[] class_list = new iControl.LocalLBClassAddressClass[1];
                class_list[0]         = new iControl.LocalLBClassAddressClass();
                class_list[0].name    = textBox_Name.Text;
                class_list[0].members = new iControl.LocalLBClassAddressEntry[num_members];

                String[][] data_values = new String[1][];
                data_values[0] = new String[num_members];

                for (int i = 0; i < num_members; i++)
                {
                    //String[] tokens = listBox_Members.Items[i].ToString().Split(new String[] { " := " }, StringSplitOptions.RemoveEmptyEntries);
                    //sItem = tokens[0];
                    ////sItem = listBox_Members.Items[i].ToString();
                    //String[] sSplit = sItem.Split(new char[] { '/' });

                    //class_list[0].members[i] = new iControl.LocalLBClassAddressEntry();
                    //class_list[0].members[i].address = sSplit[0];
                    //class_list[0].members[i].netmask = "255.255.255.255";
                    //if (sSplit.Length > 1)
                    //{
                    //    if (isAddress(sSplit[1]))
                    //    {
                    //        class_list[0].members[i].netmask = sSplit[1];
                    //    }
                    //    else
                    //    {
                    //        class_list[0].members[i].netmask = CIDRHelper.getMask(Convert.ToInt32(sSplit[1]));
                    //    }
                    //}
                    //data_values[0][i] = (tokens.Length > 1) ? tokens[1] : "";

                    sItem = listView_Members.Items[i].Text.ToString();
                    String[] sSplit = sItem.Split(new char[] { '/' });
                    class_list[0].members[i]         = new iControl.LocalLBClassAddressEntry();
                    class_list[0].members[i].address = sSplit[0];
                    class_list[0].members[i].netmask = "255.255.255.255";
                    if (sSplit.Length > 1)
                    {
                        if (isAddress(sSplit[1]))
                        {
                            class_list[0].members[i].netmask = getAddress(sSplit[1]);
                        }
                        else
                        {
                            class_list[0].members[i].netmask = CIDRHelper.getMask(Convert.ToInt32(sSplit[1]));
                        }
                    }
                    if (listView_Members.Items[i].SubItems.Count > 1)
                    {
                        data_values[0][i] = listView_Members.Items[i].SubItems[1].Text.ToString();
                    }
                    else
                    {
                        data_values[0][i] = "";
                    }
                }
                try
                {
                    //try
                    //{
                    //    Clients.Class.delete_class(new String[] { textBox_Name.Text });
                    //}
                    //catch (Exception) { }

                    //Clients.Class.create_address_class(class_list);
                    Clients.Class.modify_address_class(class_list);
                    if (m_bLTMSupportsValues)
                    {
                        Clients.Class.set_address_class_member_data_value(class_list, data_values);
                    }
                    bModified = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString(), "Error");
                }
            }
            break;

            case iControl.LocalLBClassClassType.CLASS_TYPE_VALUE:
            {
                iControl.LocalLBClassValueClass[] class_list = new iControl.LocalLBClassValueClass[1];
                class_list[0]         = new iControl.LocalLBClassValueClass();
                class_list[0].name    = textBox_Name.Text;
                class_list[0].members = new long[num_members];

                String[][] data_values = new String[1][];
                data_values[0] = new String[num_members];

                for (int i = 0; i < num_members; i++)
                {
                    //String[] tokens = listBox_Members.Items[i].ToString().Split(new String[] { " := " }, StringSplitOptions.RemoveEmptyEntries);
                    //sItem = tokens[0];
                    //class_list[0].members[i] = Convert.ToInt32(sItem);
                    //data_values[0][i] = (tokens.Length > 1) ? tokens[1] : "";

                    class_list[0].members[i] = Convert.ToInt32(listView_Members.Items[i].Text.ToString());
                    if (listView_Members.Items[i].SubItems.Count > 1)
                    {
                        data_values[0][i] = listView_Members.Items[i].SubItems[1].Text.ToString();
                    }
                    else
                    {
                        data_values[0][i] = "";
                    }
                }
                try
                {
                    //Clients.Class.delete_class(new String[] { textBox_Name.Text });
                    //Clients.Class.create_value_class(class_list);
                    Clients.Class.modify_value_class(class_list);
                    if (m_bLTMSupportsValues)
                    {
                        Clients.Class.set_value_class_member_data_value(class_list, data_values);
                    }
                    bModified = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString(), "Error");
                }
            }
            break;

            case iControl.LocalLBClassClassType.CLASS_TYPE_STRING:
            {
                iControl.LocalLBClassStringClass[] class_list = new iControl.LocalLBClassStringClass[1];
                class_list[0]         = new iControl.LocalLBClassStringClass();
                class_list[0].name    = textBox_Name.Text;
                class_list[0].members = new String[num_members];

                String[][] data_values = new String[1][];
                data_values[0] = new String[num_members];
                for (int i = 0; i < num_members; i++)
                {
                    //String[] tokens = listBox_Members.Items[i].ToString().Split(new String[] { " := " }, StringSplitOptions.RemoveEmptyEntries);
                    //sItem = tokens[0];
                    //class_list[0].members[i] = sItem;
                    //data_values[0][i] = (tokens.Length > 1) ? tokens[1] : "";

                    class_list[0].members[i] = listView_Members.Items[i].Text.ToString();
                    if (listView_Members.Items[i].SubItems.Count > 1)
                    {
                        data_values[0][i] = listView_Members.Items[i].SubItems[1].Text.ToString();
                    }
                    else
                    {
                        data_values[0][i] = "";
                    }
                }
                try
                {
                    //Clients.Class.delete_class(new String[] { textBox_Name.Text });
                    //Clients.Class.create_string_class(class_list);
                    Clients.Class.modify_string_class(class_list);
                    if (m_bLTMSupportsValues)
                    {
                        Clients.Class.set_string_class_member_data_value(class_list, data_values);
                    }
                    bModified = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString(), "Error");
                }
            }
            break;
            }
            if (bModified)
            {
                try
                {
                    Clients.ConfigSync.save_configuration("", iControl.SystemConfigSyncSaveMode.SAVE_HIGH_LEVEL_CONFIG);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error Saving Configuration");
                }
            }
            return(bModified);
        }