GetEnumerator()
{
using (View compView = this.session.Database.OpenView(
"SELECT `Component` FROM `Component`"))
{
compView.Execute();
foreach (Record compRec in compView) using (compRec)
{
string comp = compRec.GetString(1);
yield return new ComponentInfo(this.session, comp);
}
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
}
///
/// Provides access to information about a component within the context of an installation session.
///
public class ComponentInfo
{
private Session session;
private string name;
internal ComponentInfo(Session session, string name)
{
this.session = session;
this.name = name;
}
///
/// Gets the name of the component (primary key in the Component table).
///
public string Name
{
get
{
return this.name;
}
}
///
/// Gets the current install state of the designated Component.
///
/// the Session handle is invalid
/// an unknown Component was requested
///
/// Win32 MSI API:
/// MsiGetComponentState
///
public InstallState CurrentState
{
get
{
int installedState, actionState;
uint ret = RemotableNativeMethods.MsiGetComponentState((int) this.session.Handle, this.name, out installedState, out actionState);
if (ret != 0)
{
if (ret == (uint) NativeMethods.Error.UNKNOWN_COMPONENT)
{
throw InstallerException.ExceptionFromReturnCode(ret, this.name);
}
else
{
throw InstallerException.ExceptionFromReturnCode(ret);
}
}
return (InstallState) installedState;
}
}
///
/// Gets or sets the action state of the designated Component.
///
/// the Session handle is invalid
/// an unknown Component was requested
/// the user exited the installation
///
/// Win32 MSI APIs:
/// MsiGetComponentState,
/// MsiSetComponentState
///
public InstallState RequestState
{
get
{
int installedState, actionState;
uint ret = RemotableNativeMethods.MsiGetComponentState((int) this.session.Handle, this.name, out installedState, out actionState);
if (ret != 0)
{
if (ret == (uint) NativeMethods.Error.UNKNOWN_COMPONENT)
{
throw InstallerException.ExceptionFromReturnCode(ret, this.name);
}
else
{
throw InstallerException.ExceptionFromReturnCode(ret);
}
}
return (InstallState) actionState;
}
set
{
uint ret = RemotableNativeMethods.MsiSetComponentState((int) this.session.Handle, this.name, (int) value);
if (ret != 0)
{
if (ret == (uint) NativeMethods.Error.UNKNOWN_COMPONENT)
{
throw InstallerException.ExceptionFromReturnCode(ret, this.name);
}
else
{
throw InstallerException.ExceptionFromReturnCode(ret);
}
}
}
}
///
/// Gets disk space per drive required to install a component.
///
/// Requested component state
/// A list of InstallCost structures, specifying the cost for each drive for the component
///
/// Win32 MSI API:
/// MsiEnumComponentCosts
///
public IList GetCost(InstallState installState)
{
IList costs = new List();
StringBuilder driveBuf = new StringBuilder(20);
for (uint i = 0; true; i++)
{
int cost, tempCost;
uint driveBufSize = (uint) driveBuf.Capacity;
uint ret = RemotableNativeMethods.MsiEnumComponentCosts(
(int) this.session.Handle,
this.name,
i,
(int) installState,
driveBuf,
ref driveBufSize,
out cost,
out tempCost);
if (ret == (uint) NativeMethods.Error.NO_MORE_ITEMS) break;
if (ret == (uint) NativeMethods.Error.MORE_DATA)
{
driveBuf.Capacity = (int) ++driveBufSize;
ret = RemotableNativeMethods.MsiEnumComponentCosts(
(int) this.session.Handle,
this.name,
i,
(int) installState,
driveBuf,
ref driveBufSize,
out cost,
out tempCost);
}
if (ret != 0)
{
throw InstallerException.ExceptionFromReturnCode(ret);
}
costs.Add(new InstallCost(driveBuf.ToString(), cost * 512L, tempCost * 512L));
}
return costs;
}
}
}