/// <summary> /// Imports all database tables, streams, and summary information from archive files. /// </summary> /// <param name="directoryPath">Path to the directory from which archive files will be imported</param> /// <exception cref="FileNotFoundException">the directory path is invalid</exception> /// <exception cref="InvalidHandleException">the Database handle is invalid</exception> /// <remarks><p> /// Win32 MSI API: /// <a href="http://msdn.microsoft.com/library/en-us/msi/setup/msidatabaseimport.asp">MsiDatabaseImport</a> /// </p></remarks> public void ImportAll(string directoryPath) { if (String.IsNullOrEmpty(directoryPath)) { throw new ArgumentNullException("directoryPath"); } if (File.Exists(Path.Combine(directoryPath, "_SummaryInformation.idt"))) { this.Import(Path.Combine(directoryPath, "_SummaryInformation.idt")); } string[] idtFiles = Directory.GetFiles(directoryPath, "*.idt"); foreach (string file in idtFiles) { if (Path.GetFileName(file) != "_SummaryInformation.idt") { this.Import(file); } } if (Directory.Exists(Path.Combine(directoryPath, "_Streams"))) { View view = this.OpenView("SELECT `Name`, `Data` FROM `_Streams`"); Record rec = null; try { view.Execute(); string[] streamFiles = Directory.GetFiles(Path.Combine(directoryPath, "_Streams")); foreach (string file in streamFiles) { rec = this.CreateRecord(2); rec[1] = Path.GetFileName(file); rec.SetStream(2, file); view.Insert(rec); rec.Close(); rec = null; } } finally { if (rec != null) { rec.Close(); } view.Close(); } } }
public void InsertRecordThenTryFormatString() { string dbFile = "InsertRecordThenTryFormatString.msi"; using (Database db = new Database(dbFile, DatabaseOpenMode.CreateDirect)) { WindowsInstallerUtils.InitializeProductDatabase(db); WindowsInstallerUtils.CreateTestProduct(db); string parameterFormatString = "[1]"; string[] properties = new string[] { "SonGoku", "Over 9000", }; string query = "SELECT `Property`, `Value` FROM `Property`"; using (View view = db.OpenView(query)) { using (Record rec = new Record(2)) { rec[1] = properties[0]; rec[2] = properties[1]; rec.FormatString = parameterFormatString; Console.WriteLine("Format String before inserting: " + rec.FormatString); view.Insert(rec); Console.WriteLine("Format String after inserting: " + rec.FormatString); // After inserting, the format string is invalid. Assert.AreEqual(String.Empty, rec.ToString()); // Setting the format string manually makes it valid again. rec.FormatString = parameterFormatString; Assert.AreEqual(properties[0], rec.ToString()); } } } }