public int Uninstall(Package package)
        {
            Logger.Log(String.Format(CultureInfo.InvariantCulture, "Package uninstall initiated: {0}", package.ProductName), Logger.MessageLevel.Information, AppName);
            var exitcode = -1;

            try
            {
                if (!DoNotExecuteProcess)
                {
                    Logger.Log(String.Format(CultureInfo.InvariantCulture, "Package uninstall method called"), Logger.MessageLevel.Verbose, AppName);
                    exitcode = package.Uninstall();
                }
                else
                {
                    Logger.Log(String.Format(CultureInfo.InvariantCulture, "Package uninstall method bypassed - DoNotExecute is true"), Logger.MessageLevel.Verbose, AppName);
                    exitcode = 0;
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex, AppName);
            }

            return exitcode;
        }
        private void GetUniquePackages(HashSet<string> upgradeCodeHash, 
            HashSet<string> noUpgradeCodeProductCodeHash,
            Wix.Table chainmsipackageTable,
            Wix.Table uxPackageBehavior)
        {
            try
            {
                Dictionary<string, string> uxPackageBehaviorDict = new Dictionary<string, string>();
                if (uxPackageBehavior != null)
                {
                    foreach (Wix.Row msirow in uxPackageBehavior.Rows)
                    {
                        string packageId = string.Empty;
                        string reallyPerm = string.Empty;
                        foreach (Wix.Field field in msirow.Fields)
                        {
                            switch (field.Column.Name.ToString(CultureInfo.InvariantCulture).ToUpperInvariant())
                            {
                                case "PackageId":
                                    packageId = field.Data.ToString();
                                    break;
                                case "ReallyPermanent": // nullable.
                                    if (field.Data != null)
                                    {
                                        reallyPerm = field.Data.ToString();
                                    }
                                    break;

                            }
                        }
                        if (!string.IsNullOrEmpty(packageId) && !uxPackageBehaviorDict.ContainsKey(packageId))
                        {
                            uxPackageBehaviorDict.Add(packageId, reallyPerm);
                        }
                    }
                }

                foreach (Wix.Row msirow in chainmsipackageTable.Rows)
                {
                    var msi = new Package();

                    foreach (Wix.Field field in msirow.Fields)
                    {
                        switch (field.Column.Name.ToString(CultureInfo.InvariantCulture).ToUpperInvariant())
                        {
                            case "CHAINPACKAGE_":
                                msi.ChainingPackage = field.Data.ToString();
                                break;

                            case "PRODUCTCODE": // id 23
                                msi.ProductCode = field.Data.ToString();
                                break;

                            case "UPGRADECODE": // nullable.
                                if (field.Data != null)
                                {
                                    msi.UpgradeCode = field.Data.ToString();
                                }
                                break;
                            case "PRODUCTVERSION":
                                msi.ProductVersion = field.Data.ToString();
                                break;

                            case "PRODUCTNAME":
                                msi.ProductName = field.Data.ToString();
                                break;
                            case "PACKAGETYPE":
                                msi.Type = Package.PackageType.MSI;
                                break;
                            default:
                                break;
                        }
                    }

                    // if the package is really perm, then, don't uninstall it.
                    if (!string.IsNullOrEmpty(msi.ChainingPackage)
                        && uxPackageBehaviorDict.ContainsKey(msi.ChainingPackage)
                        && uxPackageBehaviorDict[msi.ChainingPackage].Equals("yes", StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(msi.UpgradeCode))
                    {
                        noUpgradeCodeProductCodeHash.Add(msi.ProductCode);
                    }
                    else
                    {
                        if (!upgradeCodeHash.Contains(msi.UpgradeCode))
                        {
                            upgradeCodeHash.Add(msi.UpgradeCode);
                        }
                    }
                }
                // We should not be uninstalling MSU because they are usually perm and they are windows comp.
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
        }
        private static ICollection<Package> GetMSIDataFromTable(Bundle bundle, Wix.Table chainmsipackageTable, Wix.Table cpiTable)
        {
            try {
                foreach (Wix.Row msirow in chainmsipackageTable.Rows)
                {
                    var msi = new Package();

                    foreach (Wix.Field field in msirow.Fields)
                    {
                        switch (field.Column.Name.ToString(CultureInfo.InvariantCulture).ToUpperInvariant())
                        {
                            case "CHAINPACKAGE_":
                                msi.ChainingPackage = field.Data.ToString();
                                break;

                            case "PRODUCTCODE": // id 23
                                msi.ProductCode = field.Data.ToString();
                                break;

                            case "PRODUCTVERSION":
                                msi.ProductVersion = field.Data.ToString();
                                break;

                            case "PRODUCTNAME":
                                msi.ProductName = field.Data.ToString();
                                break;
                            case "PACKAGETYPE":
                                msi.Type = Package.PackageType.MSI;
                                break;
                            default:
                                break;
                        }
                    }
                    bundle.Packages.Add(msi);
                }

                if (cpiTable != null)
                {
                    foreach (Wix.Row packageinforow in cpiTable.Rows)
                    {
                        if (packageinforow.Fields[1].Data.ToString().ToUpperInvariant() == "MSU")
                        {
                            var msu = new Package();

                            foreach (Wix.Field field in packageinforow.Fields)
                            {
                                switch (field.Column.Name.ToString(CultureInfo.InvariantCulture).ToUpperInvariant())
                                {
                                    case "ID": // id 0
                                        msu.ChainingPackage = field.Data.ToString();
                                        break;

                                    case "MSUKB": // id 13
                                        msu.ProductCode = field.Data.ToString().Replace("KB", "");
                                        break;

                                    case "VERSION": // id 25
                                        msu.ProductVersion = (field.Data != null) ? field.Data.ToString() : "";
                                        break;

                                    case "DISPLAYNAME": // id 27
                                        msu.ProductName = (field.Data != null) ? field.Data.ToString() : "";
                                        break;
                                    case "PACKAGETYPE": // id 1
                                        msu.Type = Package.PackageType.MSU;
                                        break;
                                    default:
                                        break;
                                }
                            }

                            bundle.Packages.Add(msu);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }

            return bundle.Packages;
        }