Ejemplo n.º 1
0
        public void SaveOrUpdateResults(PackageScanResult result, Package package)
        {
            var scanResult = _scanRepository.GetAll()
                             .Include(pr => pr.Packages)
                             .SingleOrDefault(s => s.Sha256Checksum == result.Sha256Checksum);

            if (scanResult == null)
            {
                scanResult = new ScanResult();
                _scanRepository.InsertOnCommit(scanResult);
            }

            scanResult.Sha256Checksum = result.Sha256Checksum.to_string();
            scanResult.FileName       = result.FileName.to_string();
            scanResult.ScanData       = result.ScanData.to_string();
            scanResult.ScanDetailsUrl = result.ScanDetailsUrl.to_string();

            int positives = 0;

            int.TryParse(result.Positives.to_string(), out positives);
            scanResult.Positives = positives;

            int totalScans = 0;

            int.TryParse(result.TotalScans.to_string(), out totalScans);
            scanResult.TotalScans = totalScans;

            var scanDate = DateTime.MinValue;

            DateTime.TryParse(result.ScanDate.to_string(), out scanDate);
            if (scanDate != DateTime.MinValue)
            {
                scanResult.ScanDate = scanDate;
            }

            var packageLinked = false;

            foreach (var existingPackage in scanResult.Packages.OrEmptyListIfNull())
            {
                if (package.Key == existingPackage.Key)
                {
                    packageLinked = true;
                }
            }

            if (!packageLinked)
            {
                scanResult.Packages.Add(package);
            }

            _scanRepository.CommitChanges();
        }
Ejemplo n.º 2
0
        public void SaveOrUpdateResults(PackageScanResult result, Package package)
        {
            var scanResult = _scanRepository.GetAll()
                .Include(pr => pr.Packages)
                .SingleOrDefault(s => s.Sha256Checksum == result.Sha256Checksum);

            if (scanResult == null)
            {
                scanResult = new ScanResult();
                _scanRepository.InsertOnCommit(scanResult);
            }

            scanResult.Sha256Checksum = result.Sha256Checksum.to_string();
            scanResult.FileName = result.FileName.to_string();
            scanResult.ScanData = result.ScanData.to_string();
            scanResult.ScanDetailsUrl = result.ScanDetailsUrl.to_string();

            int positives = 0;
            int.TryParse(result.Positives.to_string(), out positives);
            scanResult.Positives = positives;

            int totalScans = 0;
            int.TryParse(result.TotalScans.to_string(), out totalScans);
            scanResult.TotalScans = totalScans;

            var scanDate = DateTime.MinValue;
            DateTime.TryParse(result.ScanDate.to_string(), out scanDate);
            if (scanDate != DateTime.MinValue)
            {
                scanResult.ScanDate = scanDate;
            }

            var packageLinked = false;
            foreach (var existingPackage in scanResult.Packages.OrEmptyListIfNull())
            {
                if (package.Key == existingPackage.Key) packageLinked = true;
            }

            if (!packageLinked)
            {
                scanResult.Packages.Add(package);
            }

            _scanRepository.CommitChanges();
        }