本文整理汇总了C#中Microsoft.Tools.WindowsInstallerXml.Msi.Database.OpenView方法的典型用法代码示例。如果您正苦于以下问题:C# Database.OpenView方法的具体用法?C# Database.OpenView怎么用?C# Database.OpenView使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Tools.WindowsInstallerXml.Msi.Database
的用法示例。
在下文中一共展示了Database.OpenView方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadPreviousPackage
/// <summary>
/// Opens the previous package (.msi or .exe) and reads the interesting information from it.
/// </summary>
/// <param name="filePath">Path to the package.</param>
private void ReadPreviousPackage(string filePath)
{
using (Database db = new Database(filePath, OpenDatabase.ReadOnly))
{
using (View view = db.OpenView("SELECT `Value` FROM `Property` WHERE `Property`=?"))
{
string propertyValue;
// get the UpgradeCode
propertyValue = this.FetchPropertyValue(view, "UpgradeCode");
if (propertyValue != null)
{
this.previousUpgradeCode = new Guid(propertyValue);
}
// get the Version
propertyValue = this.FetchPropertyValue(view, "ProductVersion");
if (propertyValue != null)
{
this.previousVersion = new Version(propertyValue);
}
// get the Update URL
propertyValue = this.FetchPropertyValue(view, "ARPURLUPDATEINFO");
if (propertyValue != null)
{
this.previousUri = new Uri(propertyValue);
}
}
}
}
示例2: MergeModules
//.........这里部分代码省略.........
}
}
// query for merge module actions in suppressed sequences and drop them
foreach (string tableName in suppressedTableNames)
{
if (!db.TableExists(tableName))
{
continue;
}
using (View view = db.OpenExecuteView(String.Concat("SELECT `Action` FROM ", tableName)))
{
while (true)
{
using (Record resultRecord = view.Fetch())
{
if (null == resultRecord)
{
break;
}
this.core.OnMessage(WixWarnings.SuppressMergedAction(resultRecord.GetString(1), tableName));
}
}
}
// drop suppressed sequences
using (View view = db.OpenExecuteView(String.Concat("DROP TABLE ", tableName)))
{
}
// delete the validation rows
using (View view = db.OpenView(String.Concat("DELETE FROM _Validation WHERE `Table` = ?")))
{
using (Record record = new Record(1))
{
record.SetString(1, tableName);
view.Execute(record);
}
}
}
// now update the Attributes column for the files from the Merge Modules
this.core.OnMessage(WixVerboses.ResequencingMergeModuleFiles());
using (View view = db.OpenView("SELECT `Sequence`, `Attributes` FROM `File` WHERE `File`=?"))
{
foreach (FileRow fileRow in fileRows)
{
if (!fileRow.FromModule)
{
continue;
}
using (Record record = new Record(1))
{
record.SetString(1, fileRow.File);
view.Execute(record);
}
using (Record recordUpdate = view.Fetch())
{
if (null == recordUpdate)
{
throw new InvalidOperationException("Failed to fetch a File row from the database that was merged in from a module.");
}
示例3: ProcessUncompressedFiles
/// <summary>
/// Process uncompressed files.
/// </summary>
/// <param name="tempDatabaseFile">The temporary database file.</param>
/// <param name="fileRows">The collection of files to copy into the image.</param>
/// <param name="fileTransfers">Array of files to be transfered.</param>
/// <param name="mediaRows">The indexed media rows.</param>
/// <param name="layoutDirectory">The directory in which the image should be layed out.</param>
/// <param name="compressed">Flag if source image should be compressed.</param>
/// <param name="longNamesInImage">Flag if long names should be used.</param>
private void ProcessUncompressedFiles(string tempDatabaseFile, FileRowCollection fileRows, ArrayList fileTransfers, MediaRowCollection mediaRows, string layoutDirectory, bool compressed, bool longNamesInImage)
{
if (0 == fileRows.Count || this.core.EncounteredError)
{
return;
}
Hashtable directories = new Hashtable();
using (Database db = new Database(tempDatabaseFile, OpenDatabase.ReadOnly))
{
using (View directoryView = db.OpenExecuteView("SELECT `Directory`, `Directory_Parent`, `DefaultDir` FROM `Directory`"))
{
while (true)
{
using (Record directoryRecord = directoryView.Fetch())
{
if (null == directoryRecord)
{
break;
}
string sourceName = Installer.GetName(directoryRecord.GetString(3), true, longNamesInImage);
directories.Add(directoryRecord.GetString(1), new ResolvedDirectory(directoryRecord.GetString(2), sourceName));
}
}
}
using (View fileView = db.OpenView("SELECT `Directory_`, `FileName` FROM `Component`, `File` WHERE `Component`.`Component`=`File`.`Component_` AND `File`.`File`=?"))
{
using (Record fileQueryRecord = new Record(1))
{
// for each file in the array of uncompressed files
foreach (FileRow fileRow in fileRows)
{
string relativeFileLayoutPath = null;
string mediaLayoutDirectory = this.FileManager.ResolveMedia(mediaRows[fileRow.DiskId], layoutDirectory);
// setup up the query record and find the appropriate file in the
// previously executed file view
fileQueryRecord[1] = fileRow.File;
fileView.Execute(fileQueryRecord);
using (Record fileRecord = fileView.Fetch())
{
if (null == fileRecord)
{
throw new WixException(WixErrors.FileIdentifierNotFound(fileRow.SourceLineNumbers, fileRow.File));
}
relativeFileLayoutPath = Binder.GetFileSourcePath(directories, fileRecord[1], fileRecord[2], compressed, longNamesInImage);
}
// finally put together the base media layout path and the relative file layout path
string fileLayoutPath = Path.Combine(mediaLayoutDirectory, relativeFileLayoutPath);
FileTransfer transfer;
if (FileTransfer.TryCreate(fileRow.Source, fileLayoutPath, false, "File", fileRow.SourceLineNumbers, out transfer))
{
fileTransfers.Add(transfer);
}
}
}
}
}
}
示例4: UnbindDatabase
/// <summary>
/// Unbind an MSI database file.
/// </summary>
/// <param name="databaseFile">The database file.</param>
/// <param name="database">The opened database.</param>
/// <param name="outputType">The type of output to create.</param>
/// <param name="exportBasePath">The path where files should be exported.</param>
/// <param name="skipSummaryInfo">Option to skip unbinding the _SummaryInformation table.</param>
/// <returns>The output representing the database.</returns>
private Output UnbindDatabase(string databaseFile, Database database, OutputType outputType, string exportBasePath, bool skipSummaryInfo)
{
string modularizationGuid = null;
Output output = new Output(SourceLineNumberCollection.FromFileName(databaseFile));
View validationView = null;
// set the output type
output.Type = outputType;
// get the codepage
database.Export("_ForceCodepage", this.TempFilesLocation, "_ForceCodepage.idt");
using (StreamReader sr = File.OpenText(Path.Combine(this.TempFilesLocation, "_ForceCodepage.idt")))
{
string line;
while (null != (line = sr.ReadLine()))
{
string[] data = line.Split('\t');
if (2 == data.Length)
{
output.Codepage = Convert.ToInt32(data[0], CultureInfo.InvariantCulture);
}
}
}
// get the summary information table if it exists; it won't if unbinding a transform
if (!skipSummaryInfo)
{
using (SummaryInformation summaryInformation = new SummaryInformation(database))
{
Table table = new Table(null, this.tableDefinitions["_SummaryInformation"]);
for (int i = 1; 19 >= i; i++)
{
string value = summaryInformation.GetProperty(i);
if (0 < value.Length)
{
Row row = table.CreateRow(output.SourceLineNumbers);
row[0] = i;
row[1] = value;
}
}
output.Tables.Add(table);
}
}
try
{
// open a view on the validation table if it exists
if (database.TableExists("_Validation"))
{
validationView = database.OpenView("SELECT * FROM `_Validation` WHERE `Table` = ? AND `Column` = ?");
}
// get the normal tables
using (View tablesView = database.OpenExecuteView("SELECT * FROM _Tables"))
{
while (true)
{
using (Record tableRecord = tablesView.Fetch())
{
if (null == tableRecord)
{
break;
}
string tableName = tableRecord.GetString(1);
using (View tableView = database.OpenExecuteView(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM `{0}`", tableName)))
{
TableDefinition tableDefinition = new TableDefinition(tableName, false, false);
Hashtable tablePrimaryKeys = new Hashtable();
using (Record columnNameRecord = tableView.GetColumnInfo(MsiInterop.MSICOLINFONAMES),
columnTypeRecord = tableView.GetColumnInfo(MsiInterop.MSICOLINFOTYPES))
{
int columnCount = columnNameRecord.GetFieldCount();
// index the primary keys
using (Record primaryKeysRecord = database.PrimaryKeys(tableName))
{
int primaryKeysFieldCount = primaryKeysRecord.GetFieldCount();
for (int i = 1; i <= primaryKeysFieldCount; i++)
{
tablePrimaryKeys[primaryKeysRecord.GetString(i)] = null;
}
}
//.........这里部分代码省略.........
示例5: ExtractCabinets
/// <summary>
/// Extract the cabinets from a database.
/// </summary>
/// <param name="output">The output to use when finding cabinets.</param>
/// <param name="database">The database containing the cabinets.</param>
/// <param name="databaseFile">The location of the database file.</param>
/// <param name="exportBasePath">The path where the files should be exported.</param>
private void ExtractCabinets(Output output, Database database, string databaseFile, string exportBasePath)
{
string databaseBasePath = Path.GetDirectoryName(databaseFile);
StringCollection cabinetFiles = new StringCollection();
SortedList embeddedCabinets = new SortedList();
// index all of the cabinet files
if (OutputType.Module == output.Type)
{
embeddedCabinets.Add(0, "MergeModule.CABinet");
}
else if (null != output.Tables["Media"])
{
foreach (MediaRow mediaRow in output.Tables["Media"].Rows)
{
if (null != mediaRow.Cabinet)
{
if (OutputType.Product == output.Type ||
(OutputType.Transform == output.Type && RowOperation.Add == mediaRow.Operation))
{
if (mediaRow.Cabinet.StartsWith("#", StringComparison.Ordinal))
{
embeddedCabinets.Add(mediaRow.DiskId, mediaRow.Cabinet.Substring(1));
}
else
{
cabinetFiles.Add(Path.Combine(databaseBasePath, mediaRow.Cabinet));
}
}
}
}
}
// extract the embedded cabinet files from the database
if (0 < embeddedCabinets.Count)
{
using (View streamsView = database.OpenView("SELECT `Data` FROM `_Streams` WHERE `Name` = ?"))
{
foreach (int diskId in embeddedCabinets.Keys)
{
using(Record record = new Record(1))
{
record.SetString(1, (string)embeddedCabinets[diskId]);
streamsView.Execute(record);
}
using (Record record = streamsView.Fetch())
{
if (null != record)
{
// since the cabinets are stored in case-sensitive streams inside the msi, but the file system is not case-sensitive,
// embedded cabinets must be extracted to a canonical file name (like their diskid) to ensure extraction will always work
string cabinetFile = Path.Combine(this.TempFilesLocation, String.Concat("Media", Path.DirectorySeparatorChar, diskId.ToString(CultureInfo.InvariantCulture), ".cab"));
// ensure the parent directory exists
System.IO.Directory.CreateDirectory(Path.GetDirectoryName(cabinetFile));
using (FileStream fs = System.IO.File.Create(cabinetFile))
{
int bytesRead;
byte[] buffer = new byte[512];
while (0 != (bytesRead = record.GetStream(1, buffer, buffer.Length)))
{
fs.Write(buffer, 0, bytesRead);
}
}
cabinetFiles.Add(cabinetFile);
}
else
{
// TODO: warning about missing embedded cabinet
}
}
}
}
}
// extract the cabinet files
if (0 < cabinetFiles.Count)
{
string fileDirectory = Path.Combine(exportBasePath, "File");
// delete the directory and its files to prevent cab extraction due to an existing file
if (Directory.Exists(fileDirectory))
{
Directory.Delete(fileDirectory, true);
}
// ensure the directory exists or extraction will fail
Directory.CreateDirectory(fileDirectory);
//.........这里部分代码省略.........
示例6: CreateUncompressedImage
/// <summary>
/// Lays out the binaries for the uncompressed portion of a source image.
/// </summary>
/// <param name="databasePath">Path to database.</param>
/// <param name="output">Output being created.</param>
/// <param name="files">Array of files to copy into image.</param>
/// <param name="packageCompressed">Flag if package is compressed.</param>
/// <param name="fileTransfers">Array of files to be transfered.</param>
private void CreateUncompressedImage(string databasePath, Output output, ArrayList files, bool packageCompressed, ArrayList fileTransfers)
{
if (0 == files.Count || this.foundError)
{
return;
}
bool longNamesInImage = output.LongFileNames;
Hashtable directories = new Hashtable();
using (Database db = new Database(databasePath, OpenDatabase.ReadOnly))
{
using (View directoryView = db.OpenExecuteView("SELECT `Directory`, `Directory_Parent`, `DefaultDir` FROM `Directory`"))
{
Record directoryRecord;
while (directoryView.Fetch(out directoryRecord))
{
string sourceName = GetSourceName(directoryRecord.GetString(3), longNamesInImage);
directories.Add(directoryRecord.GetString(1), new ResolvedDirectory(directoryRecord.GetString(2), sourceName));
}
}
using (View fileView = db.OpenView("SELECT `Directory_`, `FileName` FROM `Component`, `File` WHERE `Component`.`Component`=`File`.`Component_` AND `File`.`File`=?"))
{
// if an output path was specified for our image, use that as our default base,
// otherwise use the directory where the output is being placed
string defaultBaseOuputPath = null != this.imagebaseOutputPath ? this.imagebaseOutputPath : Path.GetDirectoryName(output.Path);
using (Record fileQueryRecord = new Record(1))
{
// for each file in the array of uncompressed files
foreach (FileMediaInformation fmi in files)
{
string currentSourcePath = null;
string relativeSourcePath = null;
// determine what the base of the file should be. If there was
// no src specified in the Media element (the default) then just
// use the default output path (usually the same directory as the
// output file). If there was a build directory specified then
// check if it is a absolute path, and if not add the default
// output path to the root
MediaRow mediaRow = output.MediaRows[fmi.Media];
string baseRelativeSourcePath = mediaRow.Layout;
if (null == baseRelativeSourcePath)
{
baseRelativeSourcePath = defaultBaseOuputPath;
}
else if (!Path.IsPathRooted(baseRelativeSourcePath))
{
baseRelativeSourcePath = Path.Combine(defaultBaseOuputPath, baseRelativeSourcePath);
}
// setup up the query record and find the appropriate file in the
// previously executed file view
fileQueryRecord[1] = fmi.File;
fileView.Execute(fileQueryRecord);
Record fileRecord;
if (!fileView.Fetch(out fileRecord))
{
throw new WixFileMediaInformationKeyNotFoundException(fmi.File);
}
string fileName = GetSourceName(fileRecord[2], longNamesInImage);
if (packageCompressed)
{
// use just the file name of the file since all uncompressed files must appear
// in the root of the image in a compressed package
relativeSourcePath = fileName;
}
else
{
// get the relative path of where we want the source to be as specified
// in the Directory table
string directoryPath = GetDirectoryPath(directories, fileRecord[1], longNamesInImage);
relativeSourcePath = Path.Combine(directoryPath, fileName);
}
// if the relative source path was not resolved above then we have to bail
if (null == relativeSourcePath)
{
throw new WixFileMediaInformationKeyNotFoundException(fmi.File);
}
// strip off "SourceDir" if it's still on there
if (relativeSourcePath.StartsWith("SourceDir\\"))
{
relativeSourcePath = relativeSourcePath.Substring(10);
}
//.........这里部分代码省略.........
示例7: MergeModules
//.........这里部分代码省略.........
this.OnMessage(WixWarnings.SuppressMergedAction((string)row[1], row[0].ToString()));
view.Modify(ModifyView.Delete, record);
record.Close();
}
}
}
}
}
// query for merge module actions in suppressed sequences and drop them
foreach (string tableName in suppressedTableNames.Keys)
{
if (!db.TableExists(tableName))
{
continue;
}
using (View view = db.OpenExecuteView(String.Concat("SELECT `Action` FROM ", tableName)))
{
Record resultRecord;
while (view.Fetch(out resultRecord))
{
this.OnMessage(WixWarnings.SuppressMergedAction(resultRecord.GetString(1), tableName));
resultRecord.Close();
}
}
// drop suppressed sequences
using (View view = db.OpenExecuteView(String.Concat("DROP TABLE ", tableName)))
{
}
// delete the validation rows
using (View view = db.OpenView(String.Concat("DELETE FROM _Validation WHERE `Table` = ?")))
{
Record record = new Record(1);
record.SetString(1, tableName);
view.Execute(record);
}
}
// now update the Attributes column for the files from the Merge Modules
using (View view = db.OpenView("SELECT `Sequence`, `Attributes` FROM `File` WHERE `File`=?"))
{
foreach (FileMediaInformation fmi in output.FileMediaInformationCollection)
{
if (!fmi.IsInModule)
{
continue;
}
Record record = new Record(1);
record.SetString(1, fmi.File);
view.Execute(record);
Record recordUpdate;
view.Fetch(out recordUpdate);
if (null == recordUpdate)
{
throw new WixMergeFailureException(null, this.tempFiles.BasePath, 1, null);
}
recordUpdate.SetInteger(1, fmi.Sequence);
// update the file attributes to match the compression specified
示例8: ReadPreviousPackage
/// <summary>
/// Opens the previous package (.msi or .exe) and reads the interesting information from it.
/// </summary>
/// <param name="filePath">Path to the package.</param>
/// <param name="previousUpgradeCode">Upgrade code of the package.</param>
/// <param name="previousVersion">Version of the package.</param>
/// <param name="previousUri">Update URL of the package.</param>
private void ReadPreviousPackage(string filePath, out Guid previousUpgradeCode, out Version previousVersion, out Uri previousUri)
{
// assume nothing about the previous package
previousUpgradeCode = Guid.Empty;
previousVersion = null;
previousUri = null;
string tempFileName = null;
Database db = null;
View view = null;
try
{
string msiPath = filePath; // assume the file path is the path to the MSI
// if the extension on the file path is ".exe" try to extract the MSI out of it
if (String.Compare(Path.GetExtension(filePath), ".exe", true) == 0)
{
tempFileName = Path.GetTempFileName();
Process process = new Process();
process.StartInfo.FileName = filePath;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.Arguments = String.Concat("-out ", tempFileName);
process.Start();
process.WaitForExit();
if (process.ExitCode != 0)
{
throw new ApplicationException(String.Concat("Failed to extract MSI from ", process.StartInfo.FileName));
}
msiPath = tempFileName; // the MSI is now at the temp filename location
}
db = new Database(msiPath, OpenDatabase.ReadOnly);
view = db.OpenView("SELECT `Value` FROM `Property` WHERE `Property`=?");
string propertyValue;
// get the UpgradeCode
propertyValue = this.FetchPropertyValue(view, "UpgradeCode");
if (propertyValue != null)
{
previousUpgradeCode = new Guid(propertyValue);
}
// get the Version
propertyValue = this.FetchPropertyValue(view, "ProductVersion");
if (propertyValue != null)
{
previousVersion = new Version(propertyValue);
}
// get the Update URL
propertyValue = this.FetchPropertyValue(view, "ARPURLUPDATEINFO");
if (propertyValue != null)
{
previousUri = new Uri(propertyValue);
}
}
finally
{
if (view != null)
{
view.Close();
}
if (db != null)
{
db.Close();
}
if (tempFileName != null)
{
File.Delete(tempFileName);
}
}
}