Example #1
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="_model"></param>
        public InstallViewModel(BootstrapperApplicationModel _model)
        {
            model = _model;
            executingPackageOrderIndex = new Dictionary <string, int>();

            State = InstallState.Initializing;
            //处理由bootstrapper触发的事件
            WireUpEventHandlers();
            //初始化命令 第一个参数是命令要触发的方法,第二个匿名函数是命令执行的条件
            InstallCommand = new RelayCommand(param => model.PlanAction(LaunchAction.Install), param => State == InstallState.NotPresent);

            UninstallCommand = new RelayCommand(param =>
            {
                model.PlanAction(LaunchAction.Uninstall);
                isUnstalling = true;
            }, param => State == InstallState.Present);

            CancelCommand = new RelayCommand(param =>
            {
                model.LogMessage("Cancelling...");
                if (State == InstallState.Applying)
                {
                    State = InstallState.Cancelled;
                }
                else
                {
                    CustomBootstrapperApplication.Dispatcher.InvokeShutdown();
                }
            }, param => State != InstallState.Cancelled);


            model.BootstrapperApplication.DetectComplete += DetectComplete;



            //进度条相关事件绑定
            //this.model.BootstrapperApplication.CacheAcquireProgress +=
            //(sender, args) =>
            //{
            //    this.cacheProgress = args.OverallPercentage;
            //    this.Progress = (this.cacheProgress + this.executeProgress) / 2;
            //};
            //this.model.BootstrapperApplication.ExecuteProgress +=
            //(sender, args) =>
            //{
            //    this.executeProgress = args.OverallPercentage;
            //    this.Progress = (this.cacheProgress + this.executeProgress) / 2;
            //};
            model.BootstrapperApplication.CacheAcquireProgress += CacheAcquireProgress;
            model.BootstrapperApplication.ExecuteProgress      += ApplyExecuteProgress;
            model.BootstrapperApplication.ExecuteMsiMessage    += ExecuteMsiMessage;
            model.BootstrapperApplication.PlanBegin            += PlanBegin;
            model.BootstrapperApplication.PlanPackageComplete  += PlanPackageComplete;
            model.BootstrapperApplication.Progress             += ApplyProgress;
            model.BootstrapperApplication.CacheComplete        += CacheComplete;
        }
        protected override void Run()
        {
            Model      = new DiaViewModel(this);
            Dispatcher = Dispatcher.CurrentDispatcher;
            var model     = new BootstrapperApplicationModel(this);
            var viewModel = new InstallViewModel(model);

            View = new InstallView(viewModel);
            model.SetWindowHandle(View);
            this.Engine.Detect();
            View.Show();
            Dispatcher.Run();
            this.Engine.Quit(model.FinalResult);
        }