Пример #1
0
        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);
            }
        }
Пример #2
0
 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}'"
         });
     }
 }
Пример #3
0
 internal static IEnumerable <FeatureItem> GetFeatures(this MsiPackage package)
 => GetFeatures(package.Database);
Пример #4
0
 internal static IEnumerable <PropertyItem> GetRuntimeProperties(this MsiPackage package)
 => GetRuntimeProperties(package.Database);
Пример #5
0
 internal static IEnumerable <DirectoryItem> GetDirectories(this MsiPackage package)
 => GetDirectories(package.Database);
Пример #6
0
 internal static IEnumerable <SequenceItem> GetUiSequence(this MsiPackage package)
 => GetUiSequence(package.Database);