public ProcessingResult LaunchMsi(string msiPath)
        {
            using (var package = new MsiPackage(msiPath))
            {
                var session = package.Session;
                session["Installed"] = null;
                var directories       = package.GetDirectories();
                var initialProperties = package.GetRuntimeProperties().ToPropertyDictionary();
                var sequenceItems     = package.GetUiSequence()
                                        .Where(x => string.IsNullOrWhiteSpace(x.Condition) || session.EvaluateCondition(x.Condition))
                                        .TakeWhile(x => x.Action != "ExecuteAction");
                var results         = sequenceItems.Select(x => ExecuteAction(package, x.Action)).ToArray();
                var finalProperties = package.GetRuntimeProperties().ToPropertyDictionary();
                var result          = new ProcessingResult
                {
                    AddedProperties   = GetAddedProperties(initialProperties, finalProperties).ToList(),
                    ChangedProperties = GetChangedProperties(initialProperties, finalProperties).ToList(),
                    Errors            = results.OfType <ActionError>().Select(x => x.Message).ToList(),
                    Directories       = directories.ToList(),
                    Features          = PopulateStates(package.GetFeatures(), session).ToList()
                };

                var initialDirectories = results.OfType <ActionCostsFinalized>().SingleOrDefault();
                if (initialDirectories != null)
                {
                    result.ChangedDirectories = GetChangedDirectoryProperties(initialDirectories.Properties,
                                                                              finalProperties, directories).ToList();
                }

                return(result);
            }
        }
 private static IActionResult ExecuteAction(MsiPackage package, string name)
 {
     try
     {
         package.Session.DoAction(name);
         return(name != "CostFinalize"
             ? (IActionResult) new ActionExecuted()
             : new ActionCostsFinalized {
             Properties = package.GetRuntimeProperties().ToPropertyDictionary()
         });
     }
     catch (Exception ex)
     {
         return(new ActionError {
             Message = $"Action '{name}' failed with message: '{ex.Message}'"
         });
     }
 }
Exemple #3
0
 internal static IEnumerable <FeatureItem> GetFeatures(this MsiPackage package)
 => GetFeatures(package.Database);
Exemple #4
0
 internal static IEnumerable <PropertyItem> GetRuntimeProperties(this MsiPackage package)
 => GetRuntimeProperties(package.Database);
Exemple #5
0
 internal static IEnumerable <DirectoryItem> GetDirectories(this MsiPackage package)
 => GetDirectories(package.Database);
Exemple #6
0
 internal static IEnumerable <SequenceItem> GetUiSequence(this MsiPackage package)
 => GetUiSequence(package.Database);