예제 #1
0
        /// <summary>
        /// State changed event handler running in UI thread.
        /// </summary>
        /// <param name="e"></param>
        private void XapInstallStateChanged(object sender, XapReaderViewModel.XapInstallEventArgs e)
        {
            var error = e.error;
            double progress;

            if (e.error > 0)
            {
                MessageBox.Show(LocalizedResources.txtInstallError, LocalizedResources.txtError, MessageBoxButton.OK);
                VisualStateManager.GoToState(this, "ShowInformation", true);
                SetProgress(false);
                viewModel.IsInProgress = false;
                return;
            }
            if (e.progress > 0)
            {
                if (lowBoundary == 0)
                {
                    lowBoundary = e.progress;
                }
            }
            progress = Math.Floor((double)(e.progress - lowBoundary) / (double)(100 - lowBoundary) * 100);
            if (lowBoundary == 100)
                progress = 100;

            string text = "";
            switch (e.state)
            {
                case InstallationState.AppInstallStarted:
                    progress = 0;
                    text = LocalizedResources.txtInstalling + " 0%";
                    break;
                case InstallationState.AppInstallProgress:
                    text = LocalizedResources.txtInstalling + " " + progress.ToString() + "%";
                    break;
                case InstallationState.AppInstallCompleted:
                    text = LocalizedResources.txtInstalling + " 100%";
                    break;
                case InstallationState.AppUpdateStarted:
                    progress = 0;
                    text = LocalizedResources.txtUpdating + " 0%";
                    break;
                case InstallationState.AppUpdateProgress:
                    text = LocalizedResources.txtUpdating + " " + progress.ToString() + "%";
                    break;
                case InstallationState.AppUpdateCompleted:
                    text = LocalizedResources.txtUpdating + " 100%";
                    break;
                case InstallationState.AppRemoveStarted:
                    progress = 0;
                    text = LocalizedResources.txtUninstalling + " 0%";
                    break;
                case InstallationState.AppRemoveCompleted:
                    text = LocalizedResources.txtUninstalling + " 100%";
                    break;
            }
            bool bShow = true;
            if (e.state == InstallationState.AppInstallCompleted ||
                    e.state == InstallationState.AppUpdateCompleted ||
                    e.state == InstallationState.AppRemoveCompleted)
            {
                bShow = false;
                progress = 100;
                viewModel.IsInProgress = false;
            }
            else
            {
                viewModel.IsInProgress = true;
            }
            SetProgress(bShow, text, progress);
            if (bShow == false)
                VisualStateManager.GoToState(this, "ShowInformation", true);
                //HideProgressBarAnimation.Begin();
            if (e.state == InstallationState.AppInstallCompleted ||
                e.state == InstallationState.AppUpdateCompleted)
            {
                viewModel.IsInstalled = true;
            }
            else if (e.state == InstallationState.AppRemoveCompleted)
            {
                viewModel.IsInstalled = false;
            }
        }
예제 #2
0
        private void PreloadXapThread(object parameter)
        {
            string path = parameter as string;

            MyXapReader = new XapReaderViewModel(path);

            MyXapReader.Read();
            MyXapReader.StateChanged += XapInstallStateChanged;

            this.Dispatcher.BeginInvoke(delegate()
            {

                viewModel.XapReaderContext = MyXapReader;

                picApplicationIcon.Source = MyXapReader.Icon;
                MyXapReader.CreateInstallationContext(MyXapReader.ProductID);

                viewModel.RefreshInstalledState();
                VisualStateManager.GoToState(this, "ShowInformation", true);
            }
            );
        }