Ejemplo n.º 1
0
 private bool CompareModels(ThreatModel a, ThreatModel b)
 {
     if (a.Name != b.Name)
     {
         return(false);
     }
     if (a.Description != b.Description)
     {
         return(false);
     }
     if (a.ThreatSource != b.ThreatSource)
     {
         return(false);
     }
     if (a.Target != b.Target)
     {
         return(false);
     }
     if (!a.Breaches.All(x => b.Breaches.Contains(x)) || b.Breaches.All(x => a.Breaches.Contains(x)))
     {
         return(false);
     }
     //if (a.UpdateDate != b.UpdateDate) return false;
     return(true);
 }
Ejemplo n.º 2
0
 public bool Equals(ThreatModel b)
 {
     if (Name != b.Name)
     {
         return(false);
     }
     if (Description != b.Description)
     {
         return(false);
     }
     if (ThreatSource != b.ThreatSource)
     {
         return(false);
     }
     if (Target != b.Target)
     {
         return(false);
     }
     if (!Breaches.All(x => b.Breaches.Contains(x)) || !b.Breaches.All(x => Breaches.Contains(x)))
     {
         return(false);
     }
     if (UpdateDate != b.UpdateDate)
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 3
0
        private void UpdateThreats(object sender, RoutedEventArgs e)
        {
            if (AllModels.Count == 0)
            {
                DownloadDB();
                LoadDataToTable();
                Update.Content = "Обновить";
                CheckRange();
                return;
            }
            File.Delete(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\old.xlsx");
            System.IO.File.Move(LocalDBPath, System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\old.xlsx");
            DownloadDB();
            List <ThreatModel> oldThreats = AllModels;
            List <ThreatModel> newThreats = RawDataToModels(GetDataFromXLSX());
            // <old, new>
            List <ThreatModel> differenceModels = new List <ThreatModel>();
            List <ThreatModel> newModels        = new List <ThreatModel>();

            foreach (ThreatModel newThreat in newThreats)
            {
                if (oldThreats.Where(x => x.Identificator == newThreat.Identificator).Any())
                {
                    ThreatModel founded = oldThreats.Where(x => x.Identificator == newThreat.Identificator).FirstOrDefault();
                    if (!founded.Equals(newThreat))
                    {
                        newThreat.PreviousVersion = founded;
                        differenceModels.Add(newThreat);
                    }
                }
                else
                {
                    newModels.Add(newThreat);
                }
            }
            AllModels             = newThreats;
            dgThreats.ItemsSource = AllModels;
            new Window1(differenceModels, newModels).Show();
        }
Ejemplo n.º 4
0
        private List <ThreatModel> RawDataToModels(DataSet dataSet)
        {
            List <ThreatModel> threats = new List <ThreatModel>();

            dataSet.Tables[0].Rows.RemoveAt(0);
            dataSet.Tables[0].Rows.RemoveAt(0);
            foreach (DataRow row in dataSet.Tables[0].Rows)
            {
                int           identificator         = Int32.Parse(row[0].ToString());
                string        name                  = (string)row[1];
                string        description           = (string)row[2];
                string        source                = ((string)row[3]).Replace("; ", "\n");
                string        target                = (string)row[4];
                bool          breachConfidentiality = BinaryToBool(Int32.Parse(row[5].ToString()));
                bool          breachIntegrity       = BinaryToBool(Int32.Parse(row[6].ToString()));
                bool          breachAvailability    = BinaryToBool(Int32.Parse(row[7].ToString()));
                List <string> breaches              = GetBreaches(breachConfidentiality, breachIntegrity, breachAvailability);
                DateTime      inclusionDate         = Convert.ToDateTime(row[8]);
                DateTime      updateDate            = Convert.ToDateTime(row[9]);
                ThreatModel   model                 = new ThreatModel(identificator, name, description, source, target, breaches, inclusionDate, updateDate);
                threats.Add(model);
            }
            return(threats);
        }