diff options
Diffstat (limited to 'src/WixToolset.WixBA/ProgressViewModel.cs')
| -rw-r--r-- | src/WixToolset.WixBA/ProgressViewModel.cs | 194 |
1 files changed, 194 insertions, 0 deletions
diff --git a/src/WixToolset.WixBA/ProgressViewModel.cs b/src/WixToolset.WixBA/ProgressViewModel.cs new file mode 100644 index 00000000..30aee5f1 --- /dev/null +++ b/src/WixToolset.WixBA/ProgressViewModel.cs | |||
| @@ -0,0 +1,194 @@ | |||
| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
| 2 | |||
| 3 | using System; | ||
| 4 | using System.Collections.Generic; | ||
| 5 | using System.ComponentModel; | ||
| 6 | using System.Diagnostics; | ||
| 7 | using System.Text.RegularExpressions; | ||
| 8 | using WixToolset.Bootstrapper; | ||
| 9 | |||
| 10 | namespace WixToolset.UX | ||
| 11 | { | ||
| 12 | public class ProgressViewModel : PropertyNotifyBase | ||
| 13 | { | ||
| 14 | private static readonly Regex TrimActionTimeFromMessage = new Regex(@"^\w+\s+\d+:\d+:\d+:\s+", RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture | RegexOptions.Singleline); | ||
| 15 | |||
| 16 | private RootViewModel root; | ||
| 17 | private Dictionary<string, int> executingPackageOrderIndex; | ||
| 18 | |||
| 19 | private int progressPhases; | ||
| 20 | private int progress; | ||
| 21 | private int cacheProgress; | ||
| 22 | private int executeProgress; | ||
| 23 | private string package; | ||
| 24 | private string message; | ||
| 25 | |||
| 26 | public ProgressViewModel(RootViewModel root) | ||
| 27 | { | ||
| 28 | this.root = root; | ||
| 29 | this.executingPackageOrderIndex = new Dictionary<string, int>(); | ||
| 30 | |||
| 31 | this.root.PropertyChanged += this.RootPropertyChanged; | ||
| 32 | |||
| 33 | WixBA.Model.Bootstrapper.ExecutePackageBegin += this.ExecutePackageBegin; | ||
| 34 | WixBA.Model.Bootstrapper.ExecutePackageComplete += this.ExecutePackageComplete; | ||
| 35 | WixBA.Model.Bootstrapper.ExecuteProgress += this.ApplyExecuteProgress; | ||
| 36 | WixBA.Model.Bootstrapper.PlanBegin += this.PlanBegin; | ||
| 37 | WixBA.Model.Bootstrapper.PlanPackageComplete += this.PlanPackageComplete; | ||
| 38 | WixBA.Model.Bootstrapper.ApplyBegin += this.ApplyBegin; | ||
| 39 | WixBA.Model.Bootstrapper.Progress += this.ApplyProgress; | ||
| 40 | WixBA.Model.Bootstrapper.CacheAcquireProgress += this.CacheAcquireProgress; | ||
| 41 | WixBA.Model.Bootstrapper.CacheComplete += this.CacheComplete; | ||
| 42 | } | ||
| 43 | |||
| 44 | public bool ProgressEnabled | ||
| 45 | { | ||
| 46 | get { return this.root.InstallState == InstallationState.Applying; } | ||
| 47 | } | ||
| 48 | |||
| 49 | public int Progress | ||
| 50 | { | ||
| 51 | get | ||
| 52 | { | ||
| 53 | return this.progress; | ||
| 54 | } | ||
| 55 | |||
| 56 | set | ||
| 57 | { | ||
| 58 | if (this.progress != value) | ||
| 59 | { | ||
| 60 | this.progress = value; | ||
| 61 | base.OnPropertyChanged("Progress"); | ||
| 62 | } | ||
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 66 | public string Package | ||
| 67 | { | ||
| 68 | get | ||
| 69 | { | ||
| 70 | return this.package; | ||
| 71 | } | ||
| 72 | |||
| 73 | set | ||
| 74 | { | ||
| 75 | if (this.package != value) | ||
| 76 | { | ||
| 77 | this.package = value; | ||
| 78 | base.OnPropertyChanged("Package"); | ||
| 79 | } | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | public string Message | ||
| 84 | { | ||
| 85 | get | ||
| 86 | { | ||
| 87 | return this.message; | ||
| 88 | } | ||
| 89 | |||
| 90 | set | ||
| 91 | { | ||
| 92 | if (this.message != value) | ||
| 93 | { | ||
| 94 | this.message = value; | ||
| 95 | base.OnPropertyChanged("Message"); | ||
| 96 | } | ||
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 | void RootPropertyChanged(object sender, PropertyChangedEventArgs e) | ||
| 101 | { | ||
| 102 | if ("InstallState" == e.PropertyName) | ||
| 103 | { | ||
| 104 | base.OnPropertyChanged("ProgressEnabled"); | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 108 | private void PlanBegin(object sender, PlanBeginEventArgs e) | ||
| 109 | { | ||
| 110 | lock (this) | ||
| 111 | { | ||
| 112 | this.executingPackageOrderIndex.Clear(); | ||
| 113 | } | ||
| 114 | } | ||
| 115 | |||
| 116 | private void PlanPackageComplete(object sender, PlanPackageCompleteEventArgs e) | ||
| 117 | { | ||
| 118 | if (ActionState.None != e.Execute) | ||
| 119 | { | ||
| 120 | lock (this) | ||
| 121 | { | ||
| 122 | Debug.Assert(!this.executingPackageOrderIndex.ContainsKey(e.PackageId)); | ||
| 123 | this.executingPackageOrderIndex.Add(e.PackageId, this.executingPackageOrderIndex.Count); | ||
| 124 | } | ||
| 125 | } | ||
| 126 | } | ||
| 127 | |||
| 128 | private void ExecutePackageBegin(object sender, ExecutePackageBeginEventArgs e) | ||
| 129 | { | ||
| 130 | lock (this) | ||
| 131 | { | ||
| 132 | this.Package = WixBA.Model.GetPackageName(e.PackageId); | ||
| 133 | this.Message = String.Format("Processing: {0}", this.Package); | ||
| 134 | e.Cancel = this.root.Canceled; | ||
| 135 | } | ||
| 136 | } | ||
| 137 | |||
| 138 | private void ExecutePackageComplete(object sender, ExecutePackageCompleteEventArgs e) | ||
| 139 | { | ||
| 140 | lock (this) | ||
| 141 | { // avoid a stale display | ||
| 142 | this.Message = String.Empty; | ||
| 143 | } | ||
| 144 | } | ||
| 145 | |||
| 146 | private void ApplyBegin(object sender, ApplyBeginEventArgs e) | ||
| 147 | { | ||
| 148 | this.progressPhases = e.PhaseCount; | ||
| 149 | } | ||
| 150 | |||
| 151 | private void ApplyProgress(object sender, ProgressEventArgs e) | ||
| 152 | { | ||
| 153 | lock (this) | ||
| 154 | { | ||
| 155 | e.Cancel = this.root.Canceled; | ||
| 156 | } | ||
| 157 | } | ||
| 158 | |||
| 159 | private void CacheAcquireProgress(object sender, CacheAcquireProgressEventArgs e) | ||
| 160 | { | ||
| 161 | lock (this) | ||
| 162 | { | ||
| 163 | this.cacheProgress = e.OverallPercentage; | ||
| 164 | this.Progress = (this.cacheProgress + this.executeProgress) / this.progressPhases; | ||
| 165 | e.Cancel = this.root.Canceled; | ||
| 166 | } | ||
| 167 | } | ||
| 168 | |||
| 169 | private void CacheComplete(object sender, CacheCompleteEventArgs e) | ||
| 170 | { | ||
| 171 | lock (this) | ||
| 172 | { | ||
| 173 | this.cacheProgress = 100; | ||
| 174 | this.Progress = (this.cacheProgress + this.executeProgress) / this.progressPhases; | ||
| 175 | } | ||
| 176 | } | ||
| 177 | |||
| 178 | private void ApplyExecuteProgress(object sender, ExecuteProgressEventArgs e) | ||
| 179 | { | ||
| 180 | lock (this) | ||
| 181 | { | ||
| 182 | this.executeProgress = e.OverallPercentage; | ||
| 183 | this.Progress = (this.cacheProgress + this.executeProgress) / this.progressPhases; | ||
| 184 | |||
| 185 | if (WixBA.Model.Command.Display == Display.Embedded) | ||
| 186 | { | ||
| 187 | WixBA.Model.Engine.SendEmbeddedProgress(e.ProgressPercentage, this.Progress); | ||
| 188 | } | ||
| 189 | |||
| 190 | e.Cancel = this.root.Canceled; | ||
| 191 | } | ||
| 192 | } | ||
| 193 | } | ||
| 194 | } | ||
