예제 #1
0
        //---------------------------------------------
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="network">ref for MainController</param>
        /// <param name="deviceType">type of device</param>
        public DeviceController(MainController network, DeviceType deviceType)
        {
            this.network = network;
            network.Devices.Add(this);
            this.deviceType = deviceType;
            //init device's interface;)
            this.interfaceDescription = new List<string>();
            this.interfaceName = new List<string>();
            this.ipAdresses = new List<string>();
            this.masksOctets = new List<string>();
            this.connected = new List<LinkController>();
            countEthernet = 0;
            countSerial = 0;

            deviceView = new DeviceView(this, deviceType);

            int count = 0;
            for (int i = 0; i < network.Devices.Count; i++)
            {
                if (network.Devices[i].deviceType == deviceType)
                    count++;
            }

            this.deviceIndex = count++;
            if (deviceType == DeviceType.dPc)
            {
                deviceView.label1.Content = "PC-" + this.deviceIndex;
                this.deviceValue = "PC-" + this.deviceIndex;
            }
            else if (deviceType == DeviceType.dRouter)
            {
                deviceView.label1.Content = "Router-" + this.deviceIndex;
                this.deviceValue = "Router-" + this.deviceIndex;
            }
            else
            {
                deviceView.label1.Content = "Switch-" + this.deviceIndex;
                this.deviceValue = "Switch-" + this.deviceIndex;
            }

            network.GraphCanvas.Children.Add(deviceView);
            DevicePositionChange += network.OnPointPositionChanged;
        }
예제 #2
0
        //---------------------------------------------
        /// <summary>
        /// Constructor
        /// </summary>
        public MainView()
        {
            InitializeComponent();
            mainController = new MainController(canvas);
            mainController.OnUpdateDatagrid += new UpdateDeviceData(FillDeviceData);
            mainController.OnCreateCallExpand += new OpenExand(openExpand);
            mainController.OnHistoryMessage += new HistoryMessage(AddHistory);
            mainController.OnMessage += new StatusMessage(OnAlgoMessage);
            this.OnAlgoMessage("Готово");
            //History
            log = new History();
            log.OnMessage += new StatusMessage(OnAlgoMessage);
            //Stupid fixes
            expander1.Height = 0;
            expander2.Height = 0;
            //DataGrid
            var col = new DataGridTextColumn();
            col.Header = "Интерфейс";
            col.Binding = new Binding("[0]");
            col.IsReadOnly = true;
            dataGrid1.Columns.Add(col);

            col = new DataGridTextColumn();
            col.Header = "IP адресс";
            col.Binding = new Binding("[1]");
            dataGrid1.Columns.Add(col);

            col = new DataGridTextColumn();
            col.Header = "Маска подсети";
            col.Binding = new Binding("[2]");
            dataGrid1.Columns.Add(col);

            col = new DataGridTextColumn();
            col.Header = "Описание";
            col.Binding = new Binding("[3]");
            //col. = true;
            dataGrid1.Columns.Add(col);

            //list init
            currentIndex = new List<int>();
        }
예제 #3
0
        //---------------------------------------------------------------------------------------
        /// <summary>
        /// Load network project
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void image6_MouseUp(object sender, MouseButtonEventArgs e)
        {
            Clear();
            CloseExpander(this.expander1);
            bool if_error = false;
            OnAlgoMessage("Загрузка проекта сети...");
            Microsoft.Win32.OpenFileDialog ofn = new Microsoft.Win32.OpenFileDialog();
            ofn.FileName = "Network project";
            ofn.DefaultExt = ".network";
            ofn.Filter = "Network saves (.network)|*.network";
            ofn.Multiselect = false;
            if (ofn.ShowDialog() == true)
            {
                FileStream fs = new FileStream(ofn.FileName, FileMode.Open);
                BinaryFormatter bf = new BinaryFormatter();
                try
                {
                    MainController model = (MainController)bf.Deserialize(fs);
                    mainController = model;
                    // model.OnAlgoMessage += new StatusAlgoMessage(OnAlgoMessage);
                    mainController.OnUpdateDatagrid += new UpdateDeviceData(FillDeviceData);
                    mainController.OnCreateCallExpand += new OpenExand(openExpand);
                    mainController.OnHistoryMessage += new HistoryMessage(AddHistory);
                    mainController.OnMessage += new StatusMessage(OnAlgoMessage);

                    mainController.GraphCanvas = canvas;
                    mainController.OnDeserialized();
                }
                catch (Exception ex)
                {
                    OnAlgoMessage("Ошибка загрузки файла: " + ex.Message);
                    AddHistory("Ошибка загрузки сети!", false);
                    if_error = true;
                    canvas.Children.Clear();
                    mainController.Clear();
                }
                finally
                {
                    fs.Close();
                    if (!if_error)
                    {
                        OnAlgoMessage("Загрузка ранее сохраненной сети успешно завершена!");
                        AddHistory("Загрузка ранее сохраненной сети : Количество устройств : " + (mainController.Devices.Count) + ". Количество соединений : " + (mainController.Links.Count), true);
                    }
                }
            }
        }