2016-04-09 19 views
0

Wix kullanarak bir bootstrapper yükleyici yazdım. Ancak uygulamayı çalıştırdığımda, yükleyici her zaman "Başlatma" durumunda kalır. Bu nedenle, yükleme ve kaldırma düğmeleri devre dışı bırakılmıştır. Aşağıda, kurulum komutunun değerini kontrol ettiğim satır var.Wix PlanAction yöntemi, program çalıştırıldığında çağrılmıyor

this.InstallCommand = new DelegateCommand(() => 
     model.PlanAction(LaunchAction.Install), 
     () => this.State == InstallState.NotPresent); 

Kodu ayıkladığımda, model.PlanAction yöntemi çağrılmıyor. Adım adım basmamıza rağmen, bu yöntemin üzerinden geçiyor. Ayrıca, PlanAction yöntemindeki hata ayıklama noktası vurulmadı. Burada neyi yanlış yapıyorum? Aşağıda benim ViewModel sınıfım var.

public class InstallViewModel : NotificationObject 
    { 
     public enum InstallState 
     { 
      Initializing, 
      Present, 
      NotPresent, 
      Applying, 
      Cancelled 
     } 
     private InstallState state; 
     private string message; 
     private BootstrapperApplicationModel model; 
     public ICommand InstallCommand { get; private set; } 
     public ICommand UninstallCommand { get; private set; } 
     public ICommand CancelCommand { get; private set; } 
     public string Message 
     { 
      get 
      { 
       return this.message; 
      } 
      set 
      { 
       if (this.message != value) 
       { 
        this.message = value; 
        this.RaisePropertyChanged(() => this.Message); 
       } 
      } 
     } 
     public InstallState State 
     { 
      get 
      { 
       return this.state; 
      } 
      set 
      { 
       if (this.state != value) 
       { 
        this.state = value; 
        this.Message = this.state.ToString(); 
        this.RaisePropertyChanged(() => this.State); 
        this.Refresh(); 
       } 
      } 
     } 
     public InstallViewModel(
     BootstrapperApplicationModel model) 
     { 
      this.model = model; 
      this.State = InstallState.Initializing; 
      this.WireUpEventHandlers(); 
      this.InstallCommand = new DelegateCommand(() => 
      this.model.PlanAction(LaunchAction.Install), 
      () => this.State == InstallState.NotPresent); 
      this.UninstallCommand = new DelegateCommand(() => 
      this.model.PlanAction(LaunchAction.Uninstall), 
      () => this.State == InstallState.Present); 
      this.CancelCommand = new DelegateCommand(() => 
     { 
      this.model.LogMessage("Cancelling..."); 
      if (this.State == InstallState.Applying) 
      { 
       this.State = InstallState.Cancelled; 
      } 
      else 
      { 
       CustomBootstrapperApplication.Dispatcher 
       .InvokeShutdown(); 
      } 
     },() => this.State != InstallState.Cancelled); 
     } 
     protected void DetectPackageComplete(
     object sender, 
     DetectPackageCompleteEventArgs e) 
     { 
      if (e.PackageId.Equals(
     "MyInstaller.msi", StringComparison.Ordinal)) 
      { 
       this.State = e.State == PackageState.Present ? 
        InstallState.Present : InstallState.NotPresent; 
      } 
     } 
     protected void PlanComplete(
     object sender, PlanCompleteEventArgs e) 
     { 
      if (this.State == InstallState.Cancelled) 
      { 
       CustomBootstrapperApplication.Dispatcher 
       .InvokeShutdown(); 
       return; 
      } 
      this.model.ApplyAction(); 
     } 
     protected void ApplyBegin(
     object sender, ApplyBeginEventArgs e) 
     { 
      this.State = InstallState.Applying; 
     } 
     protected void ExecutePackageBegin(
     object sender, ExecutePackageBeginEventArgs e) 
     { 
      if (this.State == InstallState.Cancelled) 
      { 
       e.Result = Result.Cancel; 
      } 
     } 
     protected void ExecutePackageComplete(
     object sender, ExecutePackageCompleteEventArgs e) 
     { 
      if (this.State == InstallState.Cancelled) 
      { 
       e.Result = Result.Cancel; 
      } 
     } 
     protected void ApplyComplete(
     object sender, ApplyCompleteEventArgs e) 
     { 
      this.model.FinalResult = e.Status; 
      CustomBootstrapperApplication.Dispatcher 
      .InvokeShutdown(); 
     } 
     private void Refresh() 
     { 
      CustomBootstrapperApplication.Dispatcher.Invoke(
      (Action)(() => 
      { 
       ((DelegateCommand)this.InstallCommand) 
       .RaiseCanExecuteChanged(); 
       ((DelegateCommand)this.UninstallCommand) 
       .RaiseCanExecuteChanged(); 
       ((DelegateCommand)this.CancelCommand) 
       .RaiseCanExecuteChanged(); 
      })); 
     } 
     private void WireUpEventHandlers() 
     { 
      this.model.BootstrapperApplication.DetectPackageComplete 
      += this.DetectPackageComplete; 
      this.model.BootstrapperApplication.PlanComplete += this. 
     PlanComplete; 
      this.model.BootstrapperApplication.ApplyComplete += this. 
      ApplyComplete; 
      this.model.BootstrapperApplication.ApplyBegin += this. 
      ApplyBegin; 
      this.model.BootstrapperApplication.ExecutePackageBegin += 
      this.ExecutePackageBegin; 
      this.model.BootstrapperApplication.ExecutePackageComplete 
      += this.ExecutePackageComplete; 
     } 
    } 

Aşağıda, çağrılması gereken PlanAction yöntemini içeren Model sınıfım yer almaktadır.

public class BootstrapperApplicationModel 
    { 
     private IntPtr hwnd; 
     public BootstrapperApplicationModel(
     BootstrapperApplication bootstrapperApplication) 
     { 
      this.BootstrapperApplication = 
      bootstrapperApplication; 
      this.hwnd = IntPtr.Zero; 
     } 
     public BootstrapperApplication BootstrapperApplication 
     { 
      get; 
      private set; 
     } 
     public int FinalResult { get; set; } 
     public void SetWindowHandle(Window view) 
     { 
      this.hwnd = new WindowInteropHelper(view).Handle; 
     } 
     public void PlanAction(LaunchAction action) 
     { 
      this.BootstrapperApplication.Engine.Plan(action); 
     } 
     public void ApplyAction() 
     { 
      this.BootstrapperApplication.Engine.Apply(this.hwnd); 
     } 
     public void LogMessage(string message) 
     { 
      this.BootstrapperApplication.Engine.Log(
      LogLevel.Standard, 
      message); 
     } 

Eğer ihtiyacınız olursa, BootstrapperApplication sınıfım aşağıdadır.

public class CustomBootstrapperApplication : 
BootstrapperApplication 
    { 
     public static Dispatcher Dispatcher { get; set; } 
     protected override void Run() 
     { 
      Dispatcher = Dispatcher.CurrentDispatcher; 
      var model = new BootstrapperApplicationModel(this); 
      var viewModel = new InstallViewModel(model); 
      var view = new InstallView(viewModel); 
      model.SetWindowHandle(view); 
      this.Engine.Detect(); 
      view.Show(); 
      Dispatcher.Run(); 
      this.Engine.Quit(model.FinalResult); 
     } 
    } 

cevap

0

Aşağıdaki herhangi bir şey çalışıp çalışmadığını deneyin, kodunuzla denemedim, ancak geçmişte benzer bir sorunla karşılaştık.

Seçenek1: kodun hemen ardından this.WireUpEventHandlers(); kodun altına koymayı deneyin ve çağrılmıyorsa, DetectPackageComplete olayınızı çağırmalıdır.

this.model.BootstrapperApplication.Engine.Detect(); 

2. seçenek: Ben size bundle.wxs Id = "MyInstaller" verilir olacağını varsaymak olarak DetectPackageComplete durumunda, paket kimliği, "MyInstaller" değil "MyInstaller.msi" olmalıdır

Umarım bu yardımcı olur.

+0

Cevap mate için teşekkürler. Her ikisini de denedim, hala hayır şansı :(olay işleyicileri bağladıktan sonra Engine.Detect satırını verdiğimde, yükleyici "hata raporu" UI ile birlikte çöküyor. Ancak günlüklerde bulabileceğim hiçbir şey yok. – mayooran

+0

Lütfen Custom.Endine.Detect(); kodunu, CustomBootstrapperApplication sınıfından kaldırın ve yeniden deneyin. DetectPackageComplete yöntemine bir hata ayıklayıcısını koyun ve DetectPackageCompleteEventArgs e'de aldığınız durumu öğrenin. –