public void TestUpdateSettings()
        {
            var builder = new AppInstallerBuilder();
            // ReSharper disable once JoinDeclarationAndInitializer
            AppInstallerConfig appInstaller;

            builder.CheckForUpdates = AppInstallerUpdateCheckingMethod.Never;
            appInstaller            = builder.Build();
            Assert.IsNull(appInstaller.UpdateSettings?.OnLaunch);
            Assert.IsNull(appInstaller.UpdateSettings?.AutomaticBackgroundTask);

            builder.CheckForUpdates = AppInstallerUpdateCheckingMethod.Launch;
            appInstaller            = builder.Build();
            Assert.IsNotNull(appInstaller.UpdateSettings?.OnLaunch);
            Assert.IsNull(appInstaller.UpdateSettings?.AutomaticBackgroundTask);

            builder.CheckForUpdates = AppInstallerUpdateCheckingMethod.LaunchAndBackground;
            appInstaller            = builder.Build();
            Assert.IsNotNull(appInstaller.UpdateSettings?.OnLaunch);
            Assert.IsNotNull(appInstaller.UpdateSettings?.AutomaticBackgroundTask);

            builder.CheckForUpdates = AppInstallerUpdateCheckingMethod.Background;
            appInstaller            = builder.Build();
            Assert.IsNull(appInstaller.UpdateSettings?.OnLaunch);
            Assert.IsNotNull(appInstaller.UpdateSettings?.AutomaticBackgroundTask);
        }
        private AppInstallerConfig GetCurrentAppInstallerConfig()
        {
            var prompt = this.PromptMode.CurrentValue;

            var builder = new AppInstallerBuilder
            {
                Version                  = this.Version.CurrentValue,
                MainPackageType          = this.TabPackage.PackageType.CurrentValue,
                MainPackageName          = this.TabPackage.Name.CurrentValue,
                MainPackageArchitecture  = this.TabPackage.Architecture.CurrentValue,
                MainPackagePublisher     = this.TabPackage.Publisher.CurrentValue,
                MainPackageVersion       = this.TabPackage.Version.CurrentValue,
                HoursBetweenUpdateChecks = int.Parse(this.Hours.CurrentValue),
                CheckForUpdates          = this.AppInstallerUpdateCheckingMethod.CurrentValue,
                ShowPrompt               = prompt != ViewModel.PromptMode.Background,
                UpdateBlocksActivation   = prompt == ViewModel.PromptMode.Force,
                AllowDowngrades          = this.AllowDowngrades.CurrentValue,
                RedirectUri              = string.IsNullOrEmpty(this.AppInstallerUri.CurrentValue) ? null : new Uri(this.AppInstallerUri.CurrentValue),
                MainPackageUri           = string.IsNullOrEmpty(this.MainPackageUri.CurrentValue) ? null : new Uri(this.MainPackageUri.CurrentValue),
            };

            var appInstaller = builder.Build();

            if (this.TabOptionalPackages.Items.Any() && appInstaller.Optional == null)
            {
                appInstaller.Optional = new List <AppInstallerBaseEntry>();
            }

            if (this.TabDependencies.Items.Any() && appInstaller.Dependencies == null)
            {
                appInstaller.Dependencies = new List <AppInstallerBaseEntry>();
            }

            if (this.TabRelatedPackages.Items.Any() && appInstaller.Related == null)
            {
                appInstaller.Related = new List <AppInstallerBaseEntry>();
            }

            foreach (var optional in this.TabOptionalPackages.Items)
            {
                var model = optional.ToModel();
                appInstaller.Optional.Add(model);
            }

            foreach (var dependency in this.TabDependencies.Items)
            {
                var model = dependency.ToModel();
                appInstaller.Dependencies.Add(model);
            }

            foreach (var related in this.TabRelatedPackages.Items)
            {
                var model = related.ToModel();
                appInstaller.Related.Add(model);
            }

            return(appInstaller);
        }
示例#3
0
        public AppInstallerViewModel(
            IInteractionService interactionService,
            IConfigurationService configurationService) : base("Create .appinstaller", interactionService)
        {
            this.appInstallerBuilder  = new AppInstallerBuilder();
            this.interactionService   = interactionService;
            this.configurationService = configurationService;

            this.AppInstallerUpdateCheckingMethod = new ChangeableProperty <AppInstallerUpdateCheckingMethod>(Otor.MsixHero.AppInstaller.Entities.AppInstallerUpdateCheckingMethod.LaunchAndBackground);
            this.AllowDowngrades = new ChangeableProperty <bool>();
            this.BlockLaunching  = new ChangeableProperty <bool>();
            this.Version         = new ValidatedChangeableProperty <string>("Version", "1.0.0.0", this.ValidateVersion);
            this.ShowPrompt      = new ChangeableProperty <bool>();
            this.MainPackageUri  = new ValidatedChangeableProperty <string>("Main package URL", true, ValidatorFactory.ValidateUri(true));
            this.AppInstallerUri = new ValidatedChangeableProperty <string>("App installer URL", true, ValidatorFactory.ValidateUri(true));
            this.Hours           = new ValidatedChangeableProperty <string>("Hours between updates", "24", this.ValidateHours);

            this.TabPackage = new PackageSelectorViewModel(
                interactionService,
                PackageSelectorDisplayMode.AllowAllPackageTypes |
                PackageSelectorDisplayMode.ShowTypeSelector |
                PackageSelectorDisplayMode.AllowManifests |
                PackageSelectorDisplayMode.ShowActualName |
                PackageSelectorDisplayMode.RequireFullIdentity |
                PackageSelectorDisplayMode.AllowBrowsing |
                PackageSelectorDisplayMode.AllowChanging)
            {
                CustomPrompt = "What will be targeted by this .appinstaller?"
            };

            this.TabOptions = new ChangeableContainer(
                this.AppInstallerUpdateCheckingMethod,
                this.AllowDowngrades,
                this.BlockLaunching,
                this.ShowPrompt,
                this.Hours);

            this.TabProperties = new ChangeableContainer(
                this.Version,
                this.MainPackageUri,
                this.AppInstallerUri);

            this.AddChildren(
                this.TabPackage,
                this.TabProperties,
                this.TabOptions);

            this.TabPackage.InputPath.ValueChanged             += this.InputPathOnValueChanged;
            this.AppInstallerUpdateCheckingMethod.ValueChanged += this.AppInstallerUpdateCheckingMethodValueChanged;
            this.AllowDowngrades.ValueChanged += this.OnBooleanChanged;
            this.BlockLaunching.ValueChanged  += this.OnBooleanChanged;
            this.ShowPrompt.ValueChanged      += this.OnBooleanChanged;
        }
        public void TestVariousSettings()
        {
            var builder = new AppInstallerBuilder();
            // ReSharper disable once JoinDeclarationAndInitializer
            AppInstallerConfig appInstaller;

            builder.AllowDowngrades = true;
            appInstaller            = builder.Build();
            Assert.IsTrue(appInstaller.UpdateSettings?.ForceUpdateFromAnyVersion);

            builder.AllowDowngrades = false;
            appInstaller            = builder.Build();
            Assert.IsTrue(appInstaller.UpdateSettings?.ForceUpdateFromAnyVersion != true);

            builder.CheckForUpdates        = AppInstallerUpdateCheckingMethod.Launch;
            builder.UpdateBlocksActivation = true;
            appInstaller = builder.Build();
            Assert.IsTrue(appInstaller.UpdateSettings?.OnLaunch?.UpdateBlocksActivation);

            builder.CheckForUpdates        = AppInstallerUpdateCheckingMethod.Launch;
            builder.UpdateBlocksActivation = false;
            appInstaller = builder.Build();
            Assert.IsTrue(appInstaller.UpdateSettings?.OnLaunch?.UpdateBlocksActivation != true);

            builder.CheckForUpdates = AppInstallerUpdateCheckingMethod.Launch;
            builder.ShowPrompt      = true;
            appInstaller            = builder.Build();
            Assert.IsTrue(appInstaller.UpdateSettings?.OnLaunch?.ShowPrompt);

            builder.CheckForUpdates = AppInstallerUpdateCheckingMethod.Launch;
            builder.ShowPrompt      = false;
            appInstaller            = builder.Build();
            Assert.IsTrue(appInstaller.UpdateSettings?.OnLaunch?.ShowPrompt != true);

            builder.HoursBetweenUpdateChecks = 20;
            appInstaller = builder.Build();
            Assert.AreEqual(20, appInstaller.UpdateSettings?.OnLaunch?.HoursBetweenUpdateChecks);

            builder.HoursBetweenUpdateChecks = 24;
            appInstaller = builder.Build();
            Assert.AreNotEqual(24, appInstaller.UpdateSettings?.OnLaunch?.HoursBetweenUpdateChecks, "24 as a default value should be ignored.");
        }
示例#5
0
        private AppInstallerConfig GetCurrentAppInstallerConfig()
        {
            var builder = new AppInstallerBuilder
            {
                Version                  = this.Version.CurrentValue,
                MainPackageType          = this.TabPackage.PackageType.CurrentValue,
                MainPackageName          = this.TabPackage.Name.CurrentValue,
                MainPackageArchitecture  = this.TabPackage.Architecture.CurrentValue,
                MainPackagePublisher     = this.TabPackage.Publisher.CurrentValue,
                MainPackageVersion       = this.TabPackage.Version.CurrentValue,
                HoursBetweenUpdateChecks = int.Parse(this.Hours.CurrentValue),
                CheckForUpdates          = this.AppInstallerUpdateCheckingMethod.CurrentValue,
                ShowPrompt               = this.ShowPrompt.CurrentValue,
                UpdateBlocksActivation   = this.BlockLaunching.CurrentValue,
                AllowDowngrades          = this.AllowDowngrades.CurrentValue,
                RedirectUri              = string.IsNullOrEmpty(this.AppInstallerUri.CurrentValue) ? null : new Uri(this.AppInstallerUri.CurrentValue),
                MainPackageUri           = string.IsNullOrEmpty(this.MainPackageUri.CurrentValue) ? null : new Uri(this.MainPackageUri.CurrentValue),
            };

            var appInstaller = builder.Build();

            return(appInstaller);
        }
示例#6
0
        private async void OpenExecuted(string selected)
        {
            if (selected != null)
            {
                if (!File.Exists(selected))
                {
                    selected = null;
                }
                else
                {
                    previousPath = selected;
                }
            }

            if (selected == null)
            {
                if (this.previousPath != null)
                {
                    var settings = new FileDialogSettings(new DialogFilterBuilder("*" + FileConstants.AppInstallerExtension).BuildFilter(), this.previousPath);
                    if (!this.interactionService.SelectFile(settings, out selected))
                    {
                        return;
                    }
                }
                else if (!this.interactionService.SelectFile(FileDialogSettings.FromFilterString(new DialogFilterBuilder("*" + FileConstants.AppInstallerExtension).BuildFilter()), out selected))
                {
                    return;
                }
            }

            this.previousPath = selected;

            AppInstallerConfig file;

            try
            {
                file = await AppInstallerConfig.FromFile(selected).ConfigureAwait(true);
            }
            catch (Exception e)
            {
                // ReSharper disable once PossibleNullReferenceException
                this.interactionService.ShowError("The selected file is not a valid .appinstaller.", e, InteractionResult.OK);
                return;
            }

            var builder = new AppInstallerBuilder(file);

            this.AllowDowngrades.CurrentValue = builder.AllowDowngrades;
            this.AppInstallerUpdateCheckingMethod.CurrentValue = builder.CheckForUpdates;
            this.AppInstallerUri.CurrentValue = builder.RedirectUri.ToString();

            if (builder.ShowPrompt)
            {
                this.PromptMode.CurrentValue = builder.UpdateBlocksActivation ? ViewModel.PromptMode.Force : ViewModel.PromptMode.Inform;
            }
            else
            {
                this.PromptMode.CurrentValue = ViewModel.PromptMode.Background;
            }

            this.Hours.CurrentValue          = builder.HoursBetweenUpdateChecks.ToString();
            this.MainPackageUri.CurrentValue = builder.MainPackageUri.ToString();
            this.Version.CurrentValue        = builder.Version;

            this.TabPackage.Name.CurrentValue         = builder.MainPackageName;
            this.TabPackage.Version.CurrentValue      = builder.MainPackageVersion;
            this.TabPackage.Publisher.CurrentValue    = builder.MainPackagePublisher;
            this.TabPackage.PackageType.CurrentValue  = builder.MainPackageType;
            this.TabPackage.Architecture.CurrentValue = builder.MainPackageArchitecture;
            this.TabOptionalPackages.SetPackages(file.Optional);
            this.TabRelatedPackages.SetPackages(file.Related);

            this.AllowDowngrades.CurrentValue = builder.AllowDowngrades;

            this.OnPropertyChanged(nameof(ShowLaunchOptions));
            this.OnPropertyChanged(nameof(CompatibleWindows));
        }
示例#7
0
        private void OpenExecuted(string selected)
        {
            if (selected != null)
            {
                if (!File.Exists(selected))
                {
                    selected = null;
                }
                else
                {
                    previousPath = selected;
                }
            }

            if (selected == null)
            {
                if (this.previousPath != null)
                {
                    // ReSharper disable once StringLiteralTypo
                    var settings = new FileDialogSettings(new DialogFilterBuilder("*.appinstaller").BuildFilter(), this.previousPath);
                    if (!this.interactionService.SelectFile(settings, out selected))
                    {
                        return;
                    }
                }
                // ReSharper disable once StringLiteralTypo
                else if (!this.interactionService.SelectFile(FileDialogSettings.FromFilterString(new DialogFilterBuilder("*.appinstaller").BuildFilter()), out selected))
                {
                    return;
                }
            }

            this.previousPath = selected;

            AppInstallerConfig.FromFile(selected).ContinueWith(t =>
            {
                if (t.IsFaulted)
                {
                    // ReSharper disable once PossibleNullReferenceException
                    this.interactionService.ShowError("The selected file is not a valid .appinstaller.", t.Exception.GetBaseException(), InteractionResult.OK);
                    return;
                }

                if (t.IsCanceled)
                {
                    return;
                }

                if (!t.IsCompleted)
                {
                    return;
                }

                var builder = new AppInstallerBuilder(t.Result);

                this.AllowDowngrades.CurrentValue = builder.AllowDowngrades;
                this.AppInstallerUpdateCheckingMethod.CurrentValue = builder.CheckForUpdates;
                this.AppInstallerUri.CurrentValue = builder.RedirectUri.ToString();
                this.BlockLaunching.CurrentValue  = builder.UpdateBlocksActivation;
                this.Hours.CurrentValue           = builder.HoursBetweenUpdateChecks.ToString();
                this.MainPackageUri.CurrentValue  = builder.MainPackageUri.ToString();
                this.Version.CurrentValue         = builder.Version;
                this.ShowPrompt.CurrentValue      = builder.ShowPrompt;

                this.TabPackage.Name.CurrentValue         = builder.MainPackageName;
                this.TabPackage.Version.CurrentValue      = builder.MainPackageVersion;
                this.TabPackage.Publisher.CurrentValue    = builder.MainPackagePublisher;
                this.TabPackage.PackageType.CurrentValue  = builder.MainPackageType;
                this.TabPackage.Architecture.CurrentValue = builder.MainPackageArchitecture;

                this.AllowDowngrades.CurrentValue = builder.AllowDowngrades;

                this.OnPropertyChanged(nameof(ShowLaunchOptions));
                this.OnPropertyChanged(nameof(CompatibleWindows));
            },
                                                               CancellationToken.None,
                                                               TaskContinuationOptions.AttachedToParent | TaskContinuationOptions.ExecuteSynchronously,
                                                               TaskScheduler.FromCurrentSynchronizationContext());
        }