private void refreshVersion_LinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { Cursor = Cursors.WaitCursor; try { // Compare that list to what's already in the PrintDriverProduct table, and add any new entries using (AssetInventoryContext context = DbConnect.AssetInventoryContext()) { // Using List<> as opposed to IQueryable<> or IEnumerable<> as they are attached // to the context and causing problems across different contexts List <string> existing = null; List <string> missing = null; existing = context.PrintDriverVersions.Select(x => x.Value).Distinct().ToList(); List <string> versions = new List <string>(); foreach (var item in context.PrintDriverPackages.Select(x => x.Name).Distinct()) { string splitItem = item.Split('\\').First(); if (!versions.Contains <string>(splitItem)) { versions.Add(splitItem); } } missing = versions.Except(existing).ToList(); foreach (var version in missing) { // Add the new product to the database PrintDriverVersion newVersion = new PrintDriverVersion(); newVersion.Value = version; newVersion.PrintDriverVersionId = SequentialGuid.NewGuid(); context.PrintDriverVersions.Add(newVersion); } if (missing.Count > 0) { context.SaveChanges(); LoadVersionCheckList(); RefreshVersionCheckList(); } } } finally { Cursor = Cursors.Default; } }
private bool LoadPrintDriverVersionsMombi() { string pattern = @"evo\\.*?([\d\.]+).*$"; bool successful = true; try { using (AssetInventoryContext context = DbConnect.AssetInventoryContext()) { Collection <string> versions = new Collection <string>(); foreach (var directory in Directory.GetDirectories(GlobalSettings.Items[Setting.UniversalPrintDriverBaseLocation])) { // Parse the directory name and find the version number Match match = Regex.Match(directory, pattern); if (match.Success) { string version = match.Groups[1].Value; if (!context.PrintDriverVersions.Any(x => x.Value.Equals(version)) && !versions.Any(x => x.Equals(version))) { versions.Add(version); } } } if (versions.Count > 0) { foreach (var version in versions) { PrintDriverVersion newVersion = new PrintDriverVersion(); newVersion.Value = version; newVersion.PrintDriverVersionId = SequentialGuid.NewGuid(); context.PrintDriverVersions.Add(newVersion); } context.SaveChanges(); LoadVersionCheckList(); RefreshVersionCheckList(); } } } catch (IOException) { // Prompt the user for credentials. using (PrintDriverCredentialForm credentialForm = new PrintDriverCredentialForm()) { credentialForm.ShareLocation = GlobalSettings.Items[Setting.UniversalPrintDriverBaseLocation]; if (credentialForm.ShowDialog() == DialogResult.OK) { successful = LoadPrintDriverVersionsMombi(); } else { successful = false; } } } return(successful); }