示例#1
0
        private void OpenFile(object sender, RoutedEventArgs e)
        {
            custdata = ThreatDataFromExcel.GetData();

            if (custdata.Count >= 20)
            {
                for (int i = 0; i < 20; i++)
                {
                    currentData.Add(custdata[i]);
                    shortData.Add(new ShortThreatModel(custdata[i].Id, custdata[i].Name));
                }
            }
            else
            {
                try
                {
                    MessageBox.Show("This file isn't exist. I will to download it from the Internet");
                    WebClient webClient = new WebClient();
                    webClient.DownloadFile("https://bdu.fstec.ru/files/documents/thrlist.xlsx", Excel.GetPath() + "thrlist.xlsx");

                    OpenFile(sender, e);
                }
                catch
                {
                    MessageBox.Show("Perhaps you have internet problems((\nTry again later");
                }
            }

            DataFromExcel.ItemsSource = currentData;
        }
示例#2
0
        private void UpdateData(object sender, RoutedEventArgs e)
        {
            ObservableCollection <ThreatModel> newData        = ThreatDataFromExcel.GetData();
            ObservableCollection <ThreatModel> changedDataOld = new ObservableCollection <ThreatModel>();
            ObservableCollection <ThreatModel> changedDataNew = new ObservableCollection <ThreatModel>();


            int min = Math.Min(custdata.Count, newData.Count);

            for (int i = 0; i < min; i++)
            {
                if (custdata[i].Id != newData[i].Id || custdata[i].Name != newData[i].Name || custdata[i].Capture != newData[i].Capture || custdata[i].ThreatSource != newData[i].ThreatSource || custdata[i].ThreatTarget != newData[i].ThreatTarget || custdata[i].Confidentiality != newData[i].Confidentiality || custdata[i].Integrity != newData[i].Integrity || custdata[i].Availability != newData[i].Availability)
                {
                    changedDataOld.Add(custdata[i]);
                    changedDataNew.Add(newData[i]);
                    custdata[i] = newData[i];
                }
            }
            if (newData.Count > min)
            {
                for (int i = min; i < newData.Count; i++)
                {
                    changedDataNew.Add(newData[i]);
                }
            }
            UpdatePage up = new UpdatePage(changedDataOld, changedDataNew);

            up.Show();

            if (newData.Count >= 20)
            {
                for (int i = 0; i < 20; i++)
                {
                    currentData.Add(newData[i]);
                    shortData.Add(new ShortThreatModel(newData[i].Id, newData[i].Name));
                }
            }
            else
            {
                try
                {
                    MessageBox.Show("Mistake. The update was unsuccessful.\nThis file isn't exist. I will to download it from the Internet");
                    WebClient webClient = new WebClient();
                    webClient.DownloadFile("https://bdu.fstec.ru/files/documents/thrlist.xlsx", Excel.GetPath() + "thrlist.xlsx");

                    UpdateData(sender, e);
                }
                catch
                {
                    MessageBox.Show("Perhaps you have internet problems((\nTry again later");
                }
            }

            DataFromExcel.ItemsSource = currentData;
        }