/// <summary> /// Get countries, the user interface remains responsive /// </summary> /// <returns></returns> public static async Task GetCountries() { using (var cn = new SqlConnection { ConnectionString = _connectionString }) { using (var cmd = new SqlCommand { Connection = cn }) { await cn.OpenAsync(); cmd.CommandText = "SELECT CountryIdentifier, Name FROM dbo.Countries;"; var reader = await cmd.ExecuteReaderAsync(); while (await reader.ReadAsync()) { /* * Since there are only a few records let's act like more is going on, * otherwise the operation here will happen in less than a second. */ await Task.Delay(200); var country = new Countries() { CountryIdentifier = reader.GetInt32(0), Name = reader.GetString(1) }; DisplayInformationHandler?.Invoke(country); } } } }
/// <summary> /// Partly done method to create a git table for readme markdown file /// </summary> public static void BuilderPackageTable(string solutionFolder, string projectType) { string[] exclude = { ".git", ".vs", "packages" }; var solutionName = Directory.GetFiles(solutionFolder, "*.sln"); Solution = new Solution() { Folder = solutionFolder, SolutionName = solutionName.Length == 1 ? Path.GetFileName(solutionName[0]) : "???" }; var folders = Directory.GetDirectories(solutionFolder). Where(path => !exclude.Contains(path.Split('\\').Last())); foreach (var folder in folders) { var fileName = (Path.Combine(folder, "packages.config")); var package = new Package(); // {SolutionFolder = solutionFolder }; if (File.Exists(fileName)) { var projectFiles = Directory.GetFiles(folder, projectType); if (projectFiles.Length == 0) { continue; } var projectNameWithoutExtension = Path.GetFileNameWithoutExtension(projectFiles[0]); DisplayInformationHandler?.Invoke(projectNameWithoutExtension); package.ProjectName = projectNameWithoutExtension; var document = XDocument.Load(fileName); foreach (var packageNode in document.XPathSelectElements("/packages/package")) { string packageName = packageNode.Attribute("id").Value; string version = packageNode.Attribute("version").Value; DisplayInformationHandler?.Invoke($" {packageName}, {version}"); package.PackageItems.Add(new PackageItem() { Name = packageName, Version = version }); } Solution.Packages.Add(package); DisplayInformationHandler?.Invoke(""); } } }
public static void GetCorePackages(string projectFileName, Package package) { if (!File.Exists(projectFileName)) { return; } var doc = XDocument.Load(projectFileName); var packageReferences = doc.XPathSelectElements("//PackageReference") .Select(pr => new PackageReference { Include = pr.Attribute("Include").Value, Version = new Version(pr.Attribute("Version").Value) }); if (!packageReferences.Any()) { return; } package.ProjectName = Path.GetFileNameWithoutExtension(projectFileName); DisplayInformationHandler?.Invoke(Path.GetFileNameWithoutExtension(projectFileName), true); foreach (PackageReference packageReference in packageReferences) { package.PackageItems.Add(new PackageItem() { Name = packageReference.Include, Version = packageReference.Version }); DisplayInformationHandler? .Invoke($" {packageReference.Include}, {packageReference.Version}", false); } Solution.Packages.Add(package); }