public static async Task Run(string metadataFileName, string connectionString) { if (!File.Exists(metadataFileName)) { throw new ArgumentException($"File {metadataFileName} doesn't exist"); } try { Initialize(metadataFileName, connectionString); var startTime = _cursor.GetCursorTime(); Log.LogMessage($"Start time: {startTime.ToString("u")}"); var packagesRepository = new EntityRepository <Package>(_context); var packages = packagesRepository.GetAll().Include(p => p.PackageRegistration); int counter = 0; var result = await TryReadNextMetadata(); RepositoryMetadataLog metadata = null; while (result.success) { metadata = result.metadata; // Skip packages with create date that we already processed in a previous run. if (metadata.CreationDate >= startTime) { var package = packages.FirstOrDefault(p => p.PackageRegistration.Id == metadata.PackageId && p.NormalizedVersion == metadata.PackageVersion); if (package != null) { package.RepositoryUrl = metadata.RepositoryMetadata.Url; if (metadata.RepositoryMetadata.Type.Length >= 100) { await _log.LogError(metadata.PackageId, metadata.PackageVersion, $"Repository type too long: {metadata.RepositoryMetadata.Type}"); } else { package.RepositoryType = metadata.RepositoryMetadata.Type; } counter++; Console.Write("."); } else { await _log.LogError(metadata.PackageId, metadata.PackageVersion, "Couldn't find in DB"); } } if (counter >= BatchSize) { await CommitBatch(metadata.CreationDate); counter = 0; } result = await TryReadNextMetadata(); } if (counter > 0) { await CommitBatch(metadata.CreationDate); } } finally { Dispose(); } Console.Read(); }
private static async Task WriteMetadata(RepositoryMetadataLog metadata) { _csvWriter.WriteRecord(metadata); await _csvWriter.NextRecordAsync(); }