/// <summary> /// Upload the driver to the repository /// </summary> /// <param name="infFile"></param> private void UploadFolder(DriverInf infFile, PrintDriverPackage printDriverPackage) { string discreteDriverRepo = PrintDriversManager.DriverRepositoryLocation; var path = Path.Combine(discreteDriverRepo, printDriverPackage.Name); try { //this will take some time depending upon size of the driver package FileSystem.CopyDirectory(Path.GetDirectoryName(infFile.Location), path); } catch (Exception ex) { MessageBox.Show("Error saving driver {0} to Driver Repository. {1}".FormatWith(printDriverPackage.Name, ex.Message), "Save Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Import the driver from a pre-installed directory location. /// </summary> private bool ImportFromFolder() { string source = _welcomeControl.PrintDriverPaths.FirstOrDefault(); string destination = _completionControl.DestinationPaths.FirstOrDefault(); var path = Path.Combine(PrintDriversManager.DriverRepositoryLocation, destination); if (!CheckDestination(path)) { return(false); } PrintDriverPackage printDriverPackage = null; using (AssetInventoryContext context = DbConnect.AssetInventoryContext()) { //add the drivers using (DriverInfReader reader = new DriverInfReader(source)) { DriverInfParser parser = new DriverInfParser(reader); DriverInf inf = parser.BuildInf(); string driverName = parser.GetDiscreteDriverName(); //if this is a fax driver, ignore it if (!driverName.Contains("fax", StringComparison.OrdinalIgnoreCase)) { printDriverPackage = UpdateRepositoryDatabase(inf, driverName, destination, context); UploadFolder(inf, printDriverPackage); } } context.SaveChanges(); } return(true); }
private void UploadDiscreteDriver(DriverInf infFile, string driverName) { string discreteDriverRepo = GlobalSettings.Items[Setting.PrintDriverServer]; PrintDriverPackage newDiscretePrintDriverPackage = new PrintDriverPackage(); newDiscretePrintDriverPackage.Name = new DirectoryInfo(Path.GetDirectoryName(infFile.Location)).Name; //if this is a fax driver, ignore it if (driverName.Contains("fax", StringComparison.OrdinalIgnoreCase)) { return; } using (AssetInventoryContext context = DbConnect.AssetInventoryContext()) { //if the driver package already exist just update the x86 or x64 driver inf file var discreteDriver = context.PrintDriverPackages.Include("PrintDrivers").FirstOrDefault(n => n.Name == newDiscretePrintDriverPackage.Name); if (discreteDriver != null) { newDiscretePrintDriverPackage = discreteDriver; if (infFile.Drivers.Any(n => n.Architecture == DriverArchitecture.NTAMD64)) { //passing only the path relative to the repository newDiscretePrintDriverPackage.InfX64 = Path.Combine(newDiscretePrintDriverPackage.Name, Path.GetFileName(infFile.Location)); } if (infFile.Drivers.Any(n => n.Architecture == DriverArchitecture.NTx86)) { //passing only the path relative to the repository newDiscretePrintDriverPackage.InfX86 = Path.Combine(newDiscretePrintDriverPackage.Name, Path.GetFileName(infFile.Location)); } } else { //this is a new upload, add the necessary details newDiscretePrintDriverPackage.PrintDriverPackageId = SequentialGuid.NewGuid(); newDiscretePrintDriverPackage.InfX64 = string.Empty; newDiscretePrintDriverPackage.InfX86 = string.Empty; if (infFile.Drivers.Any(n => n.Architecture == DriverArchitecture.NTAMD64)) { //passing only the path relative to the repository newDiscretePrintDriverPackage.InfX64 = Path.Combine(newDiscretePrintDriverPackage.Name, Path.GetFileName(infFile.Location)); } if (infFile.Drivers.Any(n => n.Architecture == DriverArchitecture.NTx86)) { //passing only the path relative to the repository newDiscretePrintDriverPackage.InfX86 = Path.Combine(newDiscretePrintDriverPackage.Name, Path.GetFileName(infFile.Location)); } //the folder does not exist, add them up to the repository if (Directory.Exists(Path.Combine(discreteDriverRepo, newDiscretePrintDriverPackage.Name))) { TraceFactory.Logger.Debug("Driver Package already exists"); } else { //this will take sometime depending upon size of the driver package FileSystem.CopyDirectory(Path.GetDirectoryName(infFile.Location), Path.Combine(discreteDriverRepo, newDiscretePrintDriverPackage.Name)); } context.PrintDriverPackages.Add(newDiscretePrintDriverPackage); } PrintDriver newdiscreteDriver = null; newdiscreteDriver = context.PrintDrivers.FirstOrDefault(n => n.Name.Equals(driverName)); if (newdiscreteDriver == null || !newdiscreteDriver.PrintDriverPackage.Name.EqualsIgnoreCase(newDiscretePrintDriverPackage.Name)) { newdiscreteDriver = new PrintDriver(); newdiscreteDriver.Name = driverName; newdiscreteDriver.PrintDriverId = SequentialGuid.NewGuid(); newdiscreteDriver.PrintDriverPackage = newDiscretePrintDriverPackage; newdiscreteDriver.PrintProcessor = infFile.Drivers.FirstOrDefault().PrintProcessor; context.PrintDrivers.Add(newdiscreteDriver); } context.SaveChanges(); } }
/// <summary> /// Copis the specified print driver package to the environment and adds all necessary database entires to the database. /// </summary> /// <param name="drivers">The package to be added.</param> /// <param name="basePath">The path of the print driver package network store.</param> /// <param name="overwrite">if set to <c>true</c>, overwrite existing files.</param> /// <returns></returns> public static void AddToFrameworkRepository(this PrintDeviceDriverCollection drivers, string basePath, bool overwrite = false) { if (drivers == null) { throw new ArgumentNullException("drivers"); } using (AssetInventoryContext context = DbConnect.AssetInventoryContext()) { var dbDriverPackage = GetDatabaseDriverPackage(context, drivers, basePath, overwrite); CopyDrivers(drivers, basePath); // Return a new instance of PrintDriverPackage that contains the correct INF file locations. PrintDeviceDriverCollection reloadedDrivers = LoadDrivers(Path.Combine(basePath, drivers.Version), basePath); // Get a distinct list of x86 and x64 INF paths joined by the common driver name var infPathQuery = ( from d1 in reloadedDrivers where d1.Architecture == DriverArchitecture.NTAMD64 join d2 in reloadedDrivers on d1.Name equals d2.Name into driverItems from d3 in driverItems where d3.Architecture == DriverArchitecture.NTx86 select new { x64Path = d1.InfPath, x86Path = d3.InfPath } ).Distinct(); // For each distinct combination of INF paths, create a new entry in the print driver package table. // NOTE: that for now if more than one row is added for the same version, this could be a problem // as the backend won't support it. But the database will be fixed in the future to support // multiple entries. foreach (var item in infPathQuery) { // Create new database entries for this print driver package. dbDriverPackage = new PrintDriverPackage { PrintDriverPackageId = SequentialGuid.NewGuid(), Name = reloadedDrivers.Version, InfX86 = TrimPath(item.x86Path, basePath), InfX64 = TrimPath(item.x64Path, basePath) }; context.PrintDriverPackages.Add(dbDriverPackage); var driverQuery = ( from d in reloadedDrivers select new { d.Name, Processor = d.PrintProcessor.ToLowerInvariant() } ).Distinct(); foreach (var properties in driverQuery) { var printDriver = new PrintDriver { PrintDriverId = SequentialGuid.NewGuid(), PrintDriverPackage = dbDriverPackage, Name = properties.Name, PrintProcessor = properties.Processor }; dbDriverPackage.PrintDrivers.Add(printDriver); } } context.SaveChanges(); } }
private PrintDriverPackage UpdateRepositoryDatabase(DriverInf infFile, string driverName, string packageVersion, AssetInventoryContext context) { string driverRepo = PrintDriversManager.DriverRepositoryLocation; PrintDriverPackage printDriverPackage = new PrintDriverPackage(); printDriverPackage.Name = packageVersion; //new DirectoryInfo(Path.GetDirectoryName(infFile.Location)).Name; //if the driver package already exists just update the x86 or x64 driver inf file PrintDriverPackage existingDriverPackage = context.PrintDriverPackages.Include("PrintDrivers").FirstOrDefault(n => n.Name == printDriverPackage.Name); if (existingDriverPackage != null) { printDriverPackage = existingDriverPackage; if (infFile.Drivers.Any(n => n.Architecture == DriverArchitecture.NTAMD64)) { //passing only the path relative to the repository printDriverPackage.InfX64 = Path.Combine(printDriverPackage.Name, Path.GetFileName(infFile.Location)); } if (infFile.Drivers.Any(n => n.Architecture == DriverArchitecture.NTx86)) { //passing only the path relative to the repository printDriverPackage.InfX86 = Path.Combine(printDriverPackage.Name, Path.GetFileName(infFile.Location)); } } else { //this is a new upload, add the necessary details printDriverPackage.PrintDriverPackageId = SequentialGuid.NewGuid(); printDriverPackage.InfX64 = string.Empty; printDriverPackage.InfX86 = string.Empty; if (infFile.Drivers.Any(n => n.Architecture == DriverArchitecture.NTAMD64)) { //passing only the path relative to the repository printDriverPackage.InfX64 = Path.Combine(printDriverPackage.Name, Path.GetFileName(infFile.Location)); } if (infFile.Drivers.Any(n => n.Architecture == DriverArchitecture.NTx86)) { //passing only the path relative to the repository printDriverPackage.InfX86 = Path.Combine(printDriverPackage.Name, Path.GetFileName(infFile.Location)); } context.PrintDriverPackages.Add(printDriverPackage); } PrintDriver newPrintDriver = context.PrintDrivers.FirstOrDefault(n => n.Name.Equals(driverName)); if (newPrintDriver == null || !newPrintDriver.PrintDriverPackage.Name.EqualsIgnoreCase(printDriverPackage.Name)) { newPrintDriver = new PrintDriver(); newPrintDriver.Name = driverName; newPrintDriver.PrintDriverId = SequentialGuid.NewGuid(); newPrintDriver.PrintDriverPackage = printDriverPackage; newPrintDriver.PrintProcessor = infFile.Drivers.FirstOrDefault().PrintProcessor; context.PrintDrivers.Add(newPrintDriver); } return(printDriverPackage); }