2016-04-09 22 views
0

Wixを使用してブートストラップインストーラを作成しました。しかし、私はアプリケーションを実行すると、インストーラは常に "初期化"状態で立ち往生しています。したがって、インストールおよびアンインストールボタンは無効になります。以下は、私がinstallコマンドの値をチェックする行です。プログラムが実行されたときにWix PlanActionメソッドが呼び出されない

コードをデバッグすると、model.PlanActionメソッドが呼び出されません。私はステップを押しても、このメソッドを実行します。また、PlanActionメソッドのデバッグポイントはヒットしません。私はここで間違って何をしていますか?以下は私のViewModelクラスです。

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; 
     } 
    } 

以下は、呼び出されているはずのPlanActionメソッドを含むmy Modelクラスです。

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); 
     } 

以下は、必要に応じて私のBootstrapperApplicationクラスです。

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); 
     } 
    } 

答えて

0

以下のいずれかが機能する場合は、私はあなたのコードで試してみませんでしたが、過去に同様の問題がありました。

オプション1:コード​​3210の直後に以下のコードを入れてください。呼び出されない場合は、DetectPackageCompleteイベントを呼び出す必要があります。

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

オプション2:私はあなたがあなたのbundle.wxs

のid = "MyInstaller" を与えられたであろうと想定してDetectPackageCompleteイベントでは、パッケージIdは、 "MyInstaller" ではなく "MyInstaller.msi" でなければなりません

これが役立つことを願っています。

+0

回答ありがとうございます。私はイベントハンドラを接続した後にEngine.Detect行を渡すとインストーラがクラッシュし、 "エラー報告を送る" UIが表示されますが、ログには何も見つかりませんでした。 – mayooran

+0

CustomBootstrapperApplicationクラスのthis.Engine.Detect();コードを削除して、もう一度やり直してください。DetectPackageCompleteメソッドにデバッガーを置き、DetectPackageCompleteEventArgs eに入っている状態を確認してください –

関連する問題