Exemplo n.º 1
0
        private void AlarmDataGridView_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 1 & this.AlarmDataGridView.Columns[1].ReadOnly == false)
            {
                var alarm = new StaticValuesDll.AlarmList();
                alarm.Name    = this.AlarmDataGridView.Rows[e.RowIndex].Cells[0].ToString();
                alarm.Execute = Convert.ToInt32(this.AlarmDataGridView.Rows[e.RowIndex].Cells[1].Value);

                var serviceContext = new WaterGateServiceContext();
                serviceContext.ChangeAlarmAsync(alarm, (result, error) =>
                {
                    if (error != null)
                    {
                        Invoke(new Action(() => MessageBox.Show("Произошла ошибка при соединении с сервером, проверьте наличие соединения.",
                                                                "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error)));
                    }
                    else if (result)
                    {
                        //Invoke(new Action(() => this.AlarmDataGridView.Rows[e.RowIndex].Cells[1].Value = result));
                    }
                    else
                    {
                        Invoke(new Action(() => MessageBox.Show("Что-то пошло не так.", "Что-то пошло не так.", MessageBoxButtons.OK, MessageBoxIcon.Information)));
                    }

                    Invoke(new Action(() =>
                    {
                        Cursor = Cursors.Arrow;
                    }));
                });


                MessageBox.Show(alarm.Execute.ToString());
            }
        }
Exemplo n.º 2
0
        private void UpdateJDSUIP(IPCom jdsuIP, Action continueWith)
        {
            ChangeButtonsEnabledState(false);
            Cursor = Cursors.AppStarting;

            var serviceContext = new WaterGateServiceContext();

            serviceContext.UpdateJDSUIP(jdsuIP, (error) =>
            {
                if (error != null)
                {
                    MessageBox.Show("Произошла ошибка при соединении с сервером, проверьте наличие соединения.",
                                    "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    Invoke(new Action(() =>
                    {
                        MessageBox.Show("Запись успешно изменена.",
                                        "Готово", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        continueWith();
                    }));
                }


                Invoke(new Action(() =>
                {
                    ChangeButtonsEnabledState(true);
                    Cursor = Cursors.Arrow;
                }));
            });
        }
Exemplo n.º 3
0
        private void alarms_Load(object sender, EventArgs e)
        {
            var serviceContext = new WaterGateServiceContext();


            serviceContext.GetAlarmAsync((result, error) =>
            {
                if (error != null)
                {
                    MessageBox.Show("Произошла ошибка при соединении с сервером, проверьте наличие соединения.",
                                    "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    Invoke(new Action(this.Close));
                    return;
                }

                Invoke(new Action(() =>
                {
                    foreach (var alarm in result)
                    {
                        if (alarm.Execute == 1)
                        {
                            this.AlarmDataGridView.Rows.Add(alarm.Name, true);
                        }
                        else
                        {
                            this.AlarmDataGridView.Rows.Add(alarm.Name, false);
                        }
                    }

                    Cursor = Cursors.Arrow;
                    this.AlarmDataGridView.ReadOnly = false;
                }));
            });
        }
Exemplo n.º 4
0
        private void UsersManage_Load(object sender, EventArgs e)
        {
            Cursor = Cursors.AppStarting;
            var serviceContext = new WaterGateServiceContext();

            serviceContext.GetUsersAsync((result, error) =>
            {
                if (error != null)
                {
                    MessageBox.Show("Произошла ошибка при соединении с сервером, проверьте наличие соединения.",
                                    "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    Invoke(new Action(this.Close));
                    return;
                }

                Invoke(new Action(() =>
                {
                    foreach (var user in result)
                    {
                        usersDataGridView.Rows.Add(user.Login, ConvertPermissionsToString(user.Permissions));
                    }

                    Cursor = Cursors.Arrow;

                    AddButton.Enabled = true;
                    if (result.Length > 1)
                    {
                        RemoveButton.Enabled = true;
                    }
                }));
            });
        }
Exemplo n.º 5
0
        private void CheckDelayButton_Click(object sender, EventArgs e)
        {
            var inputBox = new InputBox();

            var dialogResult = inputBox.ShowDialog(this);

            if (dialogResult == DialogResult.OK)
            {
                double value = 0;
                try
                {
                    value = double.Parse(inputBox.InputBoxText.Trim(), CultureInfo.InvariantCulture);
                    if (value < 0)
                    {
                        throw new ArgumentException();
                    }
                }
                catch
                {
                    MessageBox.Show("Значение должно быть положительным числом.", "Некорректное значение", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }


                ChangeButtonsEnabledState(false);
                Cursor = Cursors.AppStarting;

                var serviceContext = new WaterGateServiceContext();
                serviceContext.UpdateCheckDelayAsync(value, (error) =>
                {
                    if (error != null)
                    {
                        MessageBox.Show("Произошла ошибка при соединении с сервером, проверьте наличие соединения.",
                                        "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    Invoke(new Action(() =>
                    {
                        MessageBox.Show("Запись успешно изменена.",
                                        "Готово", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        CheckDelayLabel.Text    = value.ToString(CultureInfo.InvariantCulture);
                        StaticValues.CheckDelay = value;
                    }));

                    Invoke(new Action(() =>
                    {
                        ChangeButtonsEnabledState(true);
                        Cursor = Cursors.Arrow;
                    }));
                });
            }
        }
Exemplo n.º 6
0
        private void RemoveButton_Click(object sender, EventArgs e)
        {
            if (usersDataGridView.SelectedCells.Count == 0)
            {
                MessageBox.Show("Требуется выбрать строку для удаления.", "Выберите строку", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            var index = usersDataGridView.SelectedCells[0].RowIndex;

            AddButton.Enabled    = false;
            RemoveButton.Enabled = false;
            Cursor = Cursors.AppStarting;

            var serviceContext = new WaterGateServiceContext();

            serviceContext.RemoveUserAsync(usersDataGridView.Rows[index].Cells[0].Value as string, (result, error) =>
            {
                if (error != null)
                {
                    Invoke(new Action(() => MessageBox.Show("Произошла ошибка при соединении с сервером, проверьте наличие соединения.",
                                                            "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error)));
                }
                else if (result)
                {
                    Invoke(new Action(() => usersDataGridView.Rows.RemoveAt(index)));
                }
                else
                {
                    Invoke(new Action(() => MessageBox.Show("Должен остаться хотя бы один администратор.",
                                                            "Нельзя удалить единственного администратора", MessageBoxButtons.OK, MessageBoxIcon.Information)));
                }

                Invoke(new Action(() =>
                {
                    Cursor = Cursors.Arrow;

                    AddButton.Enabled = true;
                    if (usersDataGridView.RowCount > 1)
                    {
                        RemoveButton.Enabled = true;
                    }
                }));
            });
        }
Exemplo n.º 7
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            var user = (new UserDialog()).GetUser();

            if (user == null)
            {
                return;
            }

            AddButton.Enabled    = false;
            RemoveButton.Enabled = false;
            Cursor = Cursors.AppStarting;

            var serviceContext = new WaterGateServiceContext();

            serviceContext.AddUserAsync(user, (result, error) =>
            {
                if (error != null)
                {
                    Invoke(new Action(() => MessageBox.Show("Произошла ошибка при соединении с сервером, проверьте наличие соединения.",
                                                            "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error)));
                }
                else if (result)
                {
                    Invoke(new Action(() => usersDataGridView.Rows.Add(user.Login, ConvertPermissionsToString(user.Permissions))));
                }
                else
                {
                    Invoke(new Action(() => MessageBox.Show("Пользователь с данным логином уже существует.",
                                                            "Логин занят", MessageBoxButtons.OK, MessageBoxIcon.Information)));
                }

                Invoke(new Action(() =>
                {
                    Cursor = Cursors.Arrow;

                    AddButton.Enabled = true;
                    if (usersDataGridView.RowCount > 1)
                    {
                        RemoveButton.Enabled = true;
                    }
                }));
            });
        }
Exemplo n.º 8
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            SaveButton.Enabled   = false;
            AddButton.Enabled    = false;
            RemoveButton.Enabled = false;

            Cursor = Cursors.AppStarting;

            var serviceContext = new WaterGateServiceContext();

            serviceContext.UpdatePorts(StaticValues.JDSUCiscoArray, (error) =>
            {
                if (error != null)
                {
                    Invoke(new Action(() =>
                                      MessageBox.Show(
                                          "Произошла ошибка при соединении с сервером, проверьте наличие соединения.",
                                          "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error)));
                }
                else
                {
                    Invoke(new Action(() =>
                                      MessageBox.Show(
                                          "Настройки успешно сохранены.",
                                          "Готово", MessageBoxButtons.OK, MessageBoxIcon.Information)));
                }

                Invoke(new Action(() =>
                {
                    Cursor               = Cursors.Arrow;
                    SaveButton.Enabled   = true;
                    AddButton.Enabled    = true;
                    RemoveButton.Enabled = true;
                }));
            });
        }
Exemplo n.º 9
0
        private void mainDataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1)
            {
                return;
            }

            switch (e.ColumnIndex)
            {
            case 3:
            {
                var objectValue = mainDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
                var value       = objectValue == null ? null : objectValue.ToString();
                var jdsuCisco   = GetJdsuCiscoClass(mainDataGridView[0, e.RowIndex].Value.ToString());
                jdsuCisco.Description = value;

                mainDataGridView.Cursor = Cursors.AppStarting;

                var serviceContext = new WaterGateServiceContext();
                serviceContext.UpdatePortDescriptionAsync(jdsuCisco, (error) =>
                    {
                        if (error != null)
                        {
                            Invoke(new Action(() =>
                            {
                                MessageBox.Show("Ошибка при соединении с сервисом. Проверьте подключение к сети.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }));
                        }

                        Invoke(new Action(() =>
                        {
                            mainDataGridView.Cursor = Cursors.Arrow;
                        }));
                    });

                break;
            }

            case 4:
            {
                var objectValue = mainDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
                var value       = objectValue == null ? null : objectValue.ToString();
                var jdsuCisco   = GetJdsuCiscoClass(mainDataGridView[0, e.RowIndex].Value.ToString());
                jdsuCisco.Note = value;

                mainDataGridView.Cursor = Cursors.AppStarting;

                var serviceContext = new WaterGateServiceContext();
                serviceContext.UpdatePortNoteAsync(jdsuCisco, (error) =>
                    {
                        if (error != null)
                        {
                            Invoke(new Action(() =>
                            {
                                MessageBox.Show("Ошибка при соединении с сервисом. Проверьте подключение к сети.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }));
                        }

                        Invoke(new Action(() =>
                        {
                            mainDataGridView.Cursor = Cursors.Arrow;
                        }));
                    });
                break;
            }
            }
        }
Exemplo n.º 10
0
        private void mainDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            this.mainDataGridView.Rows[e.RowIndex].Selected = false;

            switch (e.ColumnIndex)
            {
            //включить порт
            case 6:
            {
                if (e.RowIndex == -1)
                {
                    break;
                }
                var jdsuCisco = GetJdsuCiscoClass(mainDataGridView[0, e.RowIndex].Value.ToString());

                var serviceContext = new WaterGateServiceContext();
                serviceContext.LogUnlockingPortAsync(jdsuCisco, UnlockingPortStatus.Starting);

                string host      = jdsuCisco.CiscoIPCom.IP;
                string community = jdsuCisco.CiscoIPCom.Com;
                var    port      = jdsuCisco.CiscoPort;
                var    portCell  = this.mainDataGridView.Rows[e.RowIndex].Cells[2];
                var    ipCell    = this.mainDataGridView.Rows[e.RowIndex].Cells[1];


                var imageCell = (DataGridViewImageCell)mainDataGridView[e.ColumnIndex, e.RowIndex];
                if (imageCell.Description == "OnButton")
                {
                    ShowToolTrayTooltipActive(port + " " + host);
                    return;
                }



                mainDataGridView.Cursor = Cursors.AppStarting;
                var asyncAction = new Action(() =>
                    {
                        SimpleSnmp snmp = new SimpleSnmp(host, community);
                        if (!snmp.Valid)
                        {
                            Invoke(new Action(() => mainDataGridView.Cursor = Cursors.Arrow));

                            serviceContext.LogUnlockingPortAsync(jdsuCisco, UnlockingPortStatus.InvalidSmnp);
                            MessageBox.Show("Snmp isn't valid");
                            return;
                        }

                        Pdu pdu = new Pdu(PduType.Set);
                        pdu.VbList.Add(new Oid(".1.3.6.1.2.1.2.2.1.7" + port.PortID), new Integer32(1));
                        snmp.Set(SnmpVersion.Ver2, pdu);

                        Dictionary <Oid, AsnType> result = snmp.Get(SnmpVersion.Ver2, new[]
                        {
                            ".1.3.6.1.2.1.2.2.1.7" + port.PortID
                        });


                        if (result == null)
                        {
                            Invoke(new Action(() => mainDataGridView.Cursor = Cursors.Arrow));

                            serviceContext.LogUnlockingPortAsync(jdsuCisco, UnlockingPortStatus.NoResponse);
                            MessageBox.Show("Нет ответа от " + host + " / возможно указанный IP адрес не является IP адресом коммутационного оборудования Cisco");

                            return;
                        }

                        Invoke(new Action(() =>
                        {
                            mainDataGridView.Cursor = Cursors.Arrow;
                            foreach (var kvp in result)
                            {
                                if (kvp.Value.ToString() == "1")
                                {
                                    serviceContext.LogUnlockingPortAsync(jdsuCisco, UnlockingPortStatus.Active);

                                    MarkPortCellAsEnabled(imageCell);
                                    ShowToolTrayTooltipActive(portCell.Value + " " + ipCell.Value);
                                }
                                else
                                {
                                    serviceContext.LogUnlockingPortAsync(jdsuCisco, UnlockingPortStatus.NotActive);

                                    MarkPortCellAsDisabled(imageCell);
                                    ShowToolTrayTooltip(portCell.Value + " " + ipCell.Value);
                                }
                            }
                        }));
                    });

                asyncAction.BeginInvoke(null, null);

                break;
            }

            //проверить порт
            case 5:
            {
                if (e.RowIndex == -1)
                {
                    break;
                }
                var jdsuCisco = GetJdsuCiscoClass(mainDataGridView[0, e.RowIndex].Value.ToString());
                var cisco     = jdsuCisco.CiscoIPCom;

                //var cisco = GetJdsuCiscoClass(mainDataGridView[0, e.RowIndex].Value.ToString()).CiscoIPCom;
                if (cisco == null)
                {
                    return;
                }



                mainDataGridView.Cursor = Cursors.AppStarting;

                var asyncAction = new Action(() =>
                    {
                        try
                        {
                            if (IsCiscoActive(cisco))
                            {
                                ShowToolTrayTooltipActive(jdsuCisco.CiscoPort.PortName + "" + jdsuCisco.CiscoIPCom.IP);
                            }
                        }

                        catch (Exception ex)
                        {
                            foreach (DataGridViewRow label in this.mainDataGridView.Rows)
                            {
                                if (label.Cells[1].Value.ToString() == cisco.IP)
                                {
                                    if (!IsPortDisabled(label))
                                    {
                                        ShowToolTrayTooltip(cisco.IP + " " + cisco.Com);
                                    }
                                    paintCiscoIP(label, System.Drawing.Color.Red);
                                    Invoke(
                                        new Action(() => MarkPortCellAsDisabled((DataGridViewImageCell)label.Cells[6])));
                                }
                            }
                            Functions.AddTempLog(cisco.IP, ex.Message);
                        }
                        finally
                        {
                            Invoke(new Action(() => mainDataGridView.Cursor = Cursors.Arrow));
                        }
                    });

                asyncAction.BeginInvoke(null, null);

                break;
            }
            }
        }
Exemplo n.º 11
0
        private void Save_Click(object sender, EventArgs e)
        {
            IPAddress address;

            if (!IPAddress.TryParse(ComboBoxIpAddressCisco.Text, out address))
            {
                MessageBox.Show("Введите корректно IP адрес");
                return;
            }

            //Проверяем существует ли такой ip адрес
            if (ComboBoxIpAddressCisco.FindString(ComboBoxIpAddressCisco.Text) != -1)
            {
                MessageBox.Show("Cisco с таким IPадресом уже добавлена");
                return;
            }

            //идет ли пинг
            try
            {
                Ping      pingSender = new Ping();
                PingReply reply      = pingSender.Send(ComboBoxIpAddressCisco.Text);
            }

            catch
            {
                MessageBox.Show("IP адрес не доступен");
                return;
            }

            //правильно ли указан community, то бишь может ли она получить доступ по SNMP
            UdpTarget target = new UdpTarget((IPAddress) new IpAddress(ComboBoxIpAddressCisco.Text), 161, 500, 0);
            Pdu       pdu    = new Pdu(PduType.Get);

            pdu.VbList.Add(".1.3.6.1.2.1.1.6.0");
            AgentParameters aparam = new AgentParameters(SnmpVersion.Ver2, new OctetString(TextBoxCommunity.Text));
            SnmpV2Packet    response;

            try
            {
                response = target.Request(pdu, aparam) as SnmpV2Packet;
            }

            catch (Exception ex)
            {
                MessageBox.Show("connection failed");
                MessageBox.Show(ex.Message);
                target.Close();
                return;
            }


            var value = new IPCom(ComboBoxIpAddressCisco.Text, TextBoxCommunity.Text);

            var serviceContext = new WaterGateServiceContext();
            var list           = StaticValues.CiscoList.ToList();

            list.Add(value);

            Save.Enabled   = false;
            Delete.Enabled = false;
            Change.Enabled = false;
            Cursor         = Cursors.AppStarting;
            serviceContext.UpdateCiscoRouters(list, (error) =>
            {
                if (error != null)
                {
                    MessageBox.Show("Произошла ошибка при соединении с сервером, проверьте наличие соединения.",
                                    "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    Invoke(new Action(() =>
                    {
                        MessageBox.Show("Запись успешно добавлена.",
                                        "Готово", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        //добавляем в наш массив
                        StaticValues.CiscoList.Add(value);

                        //добавляем в Combobox
                        this.ComboBoxIpAddressCisco.Items.Add(ComboBoxIpAddressCisco.Text);

                        TextBoxCommunity.Clear();
                        ComboBoxIpAddressCisco.ResetText();
                    }));
                }


                Invoke(new Action(() =>
                {
                    Save.Enabled   = true;
                    Delete.Enabled = true;
                    Change.Enabled = true;
                    Cursor         = Cursors.Arrow;
                }));
            });
        }
Exemplo n.º 12
0
        private void Change_Click(object sender, EventArgs e)
        {
            //правильно ли указан community, то бишь может ли она получить доступ по SNMP
            UdpTarget target = new UdpTarget((IPAddress) new IpAddress(ComboBoxIpAddressCisco.Text), 161, 500, 0);
            Pdu       pdu    = new Pdu(PduType.Get);

            pdu.VbList.Add(".1.3.6.1.2.1.1.6.0");
            AgentParameters aparam = new AgentParameters(SnmpVersion.Ver2, new OctetString(TextBoxCommunity.Text));
            SnmpV2Packet    response;

            try
            {
                response = target.Request(pdu, aparam) as SnmpV2Packet;
            }

            catch (Exception ex)
            {
                MessageBox.Show("Скорее всего введен неверный Community");
                MessageBox.Show(ex.Message);
                target.Close();
                this.ComboBoxIpAddressCisco.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDown;
                return;
            }



            var oldValue = StaticValues.CiscoList.FirstOrDefault(item => item.IP.Contains(ComboBoxIpAddressCisco.Text));

            if (oldValue == null)
            {
                return;
            }

            var newValue = new IPCom(ComboBoxIpAddressCisco.Text, TextBoxCommunity.Text);


            var serviceContext = new WaterGateServiceContext();
            var list           = StaticValues.CiscoList.ToList();

            list.Remove(oldValue);
            list.Add(newValue);

            Save.Enabled   = false;
            Delete.Enabled = false;
            Change.Enabled = false;
            Cursor         = Cursors.AppStarting;



            foreach (var item in StaticValues.JDSUCiscoArray)
            {
                if (item.CiscoIPCom.IP == ComboBoxIpAddressCisco.Text)
                {
                    item.CiscoIPCom.Com = TextBoxCommunity.Text;
                }
            }

            //   var serviceContext = new WaterGateServiceContext();
            serviceContext.UpdatePorts(StaticValues.JDSUCiscoArray, (error) =>
            {
                if (error != null)
                {
                    Invoke(new Action(() =>
                                      MessageBox.Show(
                                          "Произошла ошибка при соединении с сервером, проверьте наличие соединения.",
                                          "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error)));
                }
            });



            serviceContext.UpdateCiscoRouters(list, (error) =>
            {
                if (error != null)
                {
                    MessageBox.Show("Произошла ошибка при соединении с сервером, проверьте наличие соединения.",
                                    "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                Invoke(new Action(() =>
                {
                    MessageBox.Show("Запись успешно изменена.",
                                    "Готово", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    //удаляем старый ip и community
                    StaticValues.CiscoList.Remove(oldValue);

                    //и добавляем в наш массив новые данные и все должно работать =)
                    StaticValues.CiscoList.Add(newValue);


                    ComboBoxIpAddressCisco.SelectedIndex      = -1;
                    this.ComboBoxIpAddressCisco.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDown;
                    TextBoxCommunity.Clear();
                }));

                Invoke(new Action(() =>
                {
                    Save.Enabled   = true;
                    Delete.Enabled = true;
                    Change.Enabled = true;
                    Cursor         = Cursors.Arrow;
                }));
            });
        }
Exemplo n.º 13
0
        private void Delete_Click(object sender, EventArgs e)
        {
            if (StaticValues.JDSUCiscoArray.Any(exampl => exampl.CiscoIPCom.IP == ComboBoxIpAddressCisco.Text))
            {
                // MessageBox.Show(StaticValues.JDSUCiscoArray.First(exampl => exampl.CiscoIPCom.IP == ComboBoxIpAddressCisco.Text).JDSUPort.ToString());
                MessageBox.Show("элемент коммутационного оборудования используется в конфигурации. Привязан к порту:",
                                StaticValues.JDSUCiscoArray.First(exampl => exampl.CiscoIPCom.IP == ComboBoxIpAddressCisco.Text)
                                .JDSUPort.ToString());
                return;
            }
            else
            {
                var value = StaticValues.CiscoList.FirstOrDefault(item => item.IP.Contains(ComboBoxIpAddressCisco.Text));
                if (value == null)
                {
                    return;
                }

                var serviceContext = new WaterGateServiceContext();
                var list           = StaticValues.CiscoList.ToList();

                list.Remove(value);

                Save.Enabled   = false;
                Delete.Enabled = false;
                Change.Enabled = false;
                Cursor         = Cursors.AppStarting;
                serviceContext.UpdateCiscoRouters(list, (error) =>
                {
                    if (error != null)
                    {
                        MessageBox.Show("Произошла ошибка при соединении с сервером, проверьте наличие соединения.",
                                        "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    Invoke(new Action(() =>
                    {
                        MessageBox.Show("Запись успешно удалена.",
                                        "Готово", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        //удаляем старый ip и community из combobox'а
                        StaticValues.CiscoList.Remove(value);

                        //удаляем из Combobox
                        this.ComboBoxIpAddressCisco.Items.Remove(ComboBoxIpAddressCisco.Text);


                        TextBoxCommunity.Clear();
                        ComboBoxIpAddressCisco.SelectedIndex      = -1;
                        this.ComboBoxIpAddressCisco.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDown;
                    }));


                    Invoke(new Action(() =>
                    {
                        Save.Enabled   = true;
                        Delete.Enabled = true;
                        Change.Enabled = true;
                        Cursor         = Cursors.Arrow;
                    }));
                });
            }
        }
Exemplo n.º 14
0
        private void LoginButton_Click(object sender, EventArgs e)
        {
            if (!IsInputDataValid())
            {
                return;
            }
            LoginButton.Enabled = false;
            Cursor = Cursors.AppStarting;

            if (!string.IsNullOrEmpty(ProxyAddressTextBox.Text.Trim()))
            {
                SetManualSettingProxyServer();
            }
            else
            {
                DisableProxyServer();
            }

            Settings.Initialize(ServerAddressTextBox.Text.Trim(), PortTextBox.Text.Trim());
            var serviceContext = new WaterGateServiceContext();

            const string errorText = "Отсутствует соединение к серверу. Проверьте правильно адреса сервера.";

            try
            {
                serviceContext.SignInAsync(LoginTextBox.Text.Trim(), PasswordTextBox.Text.Trim(), (result, error) =>
                {
                    if (error != null)
                    {
                        Invoke(new Action(() =>
                        {
                            MessageBox.Show(errorText, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            LoginButton.Enabled = true;
                            Cursor = Cursors.Arrow;
                        }));
                        return;
                    }

                    if (result.User.Permissions == Permissions.None)
                    {
                        Invoke(new Action(() =>
                        {
                            MessageBox.Show("Пользователя с данным логином и паролем не существует.", "В доступе отказано", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            LoginButton.Enabled = true;
                            Cursor = Cursors.Arrow;
                        }));
                        return;
                    }

                    _authorizationToken = result;

                    SaveSettings();

                    Invoke(new Action(() =>
                    {
                        DialogResult = DialogResult.OK;
                    }));
                });
            }
            catch (Exception)
            {
                MessageBox.Show(errorText, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                LoginButton.Enabled = true;
                Cursor = Cursors.Arrow;
            }
        }