예제 #1
0
        IEnumerable <ShortcutCreationRequest> cleanUpOldVersions(Version newCurrentVersion)
        {
            var directory = fileSystem.GetDirectoryInfo(rootAppDirectory);

            if (!directory.Exists)
            {
                log.Warn("The directory '{0}' does not exist", rootAppDirectory);
                return(Enumerable.Empty <ShortcutCreationRequest>());
            }

            return(directory.GetDirectories()
                   .Where(x => x.Name.StartsWith("app-", StringComparison.InvariantCultureIgnoreCase))
                   .Where(x => x.Name != "app-" + newCurrentVersion)
                   .OrderBy(x => x.Name)
                   .SelectMany(oldAppRoot => {
                var path = oldAppRoot.FullName;
                var installerHooks = new InstallerHookOperations(fileSystem, applicationName);

                var ret = AppDomainHelper.ExecuteInNewAppDomain(path, installerHooks.RunAppSetupCleanups);

                try {
                    Utility.DeleteDirectoryAtNextReboot(oldAppRoot.FullName);
                } catch (Exception ex) {
                    var message = String.Format("Couldn't delete old app directory on next reboot {0}",
                                                oldAppRoot.FullName);
                    log.WarnException(message, ex);
                }
                return ret;
            }));
        }
예제 #2
0
        List <string> runPostInstallOnDirectory(string newAppDirectoryRoot, bool isFirstInstall, Version newCurrentVersion, IEnumerable <ShortcutCreationRequest> shortcutRequestsToIgnore)
        {
            var postInstallInfo = new PostInstallInfo {
                NewAppDirectoryRoot      = newAppDirectoryRoot,
                IsFirstInstall           = isFirstInstall,
                NewCurrentVersion        = newCurrentVersion,
                ShortcutRequestsToIgnore = shortcutRequestsToIgnore.ToArray()
            };

            return(AppDomainHelper.ExecuteInNewAppDomain(postInstallInfo, info => {
                var appSetups = default(IEnumerable <IAppSetup>);

                try {
                    appSetups = findAppSetupsToRun(info.NewAppDirectoryRoot);
                } catch (UnauthorizedAccessException ex) {
                    log.ErrorException("Failed to load IAppSetups in post-install due to access denied", ex);
                    return new string[0];
                }

                return appSetups
                .Select(app => installAppVersion(app, info.NewCurrentVersion, info.ShortcutRequestsToIgnore, info.IsFirstInstall))
                .Where(x => x != null)
                .ToArray();
            }).ToList());
        }
            public void ExecutesCodeInNewAppDomain()
            {
                int currentAppDomainId = AppDomain.CurrentDomain.Id;

                bool isDifferent = AppDomainHelper.ExecuteInNewAppDomain(currentAppDomainId, currentId => AppDomain.CurrentDomain.Id != currentId);

                Assert.True(isDifferent);
            }
            public void ExecutesCodeInNewAppDomain()
            {
                int currentAppDomainId = AppDomain.CurrentDomain.Id;

                int newAppDomainId = AppDomainHelper.ExecuteInNewAppDomain(0, _ => AppDomain.CurrentDomain.Id);

                Assert.NotEqual(currentAppDomainId, newAppDomainId);
            }
예제 #5
0
        List <string> runPostInstallOnDirectory(string newAppDirectoryRoot, bool isFirstInstall, Version newCurrentVersion, IEnumerable <ShortcutCreationRequest> shortcutRequestsToIgnore)
        {
            var postInstallInfo = new PostInstallInfo {
                NewAppDirectoryRoot      = newAppDirectoryRoot,
                IsFirstInstall           = isFirstInstall,
                NewCurrentVersion        = newCurrentVersion,
                ShortcutRequestsToIgnore = shortcutRequestsToIgnore.ToArray()
            };

            var installerHooks = new InstallerHookOperations(fileSystem, applicationName);

            return(AppDomainHelper.ExecuteInNewAppDomain(postInstallInfo, installerHooks.RunAppSetupInstallers).ToList());
        }
예제 #6
0
        IEnumerable <ShortcutCreationRequest> runAppUninstall(string path)
        {
            var installerHooks = new InstallerHookOperations(fileSystem, applicationName);

            var ret = AppDomainHelper.ExecuteInNewAppDomain(path, installerHooks.RunAppUninstall);

            try {
                Utility.DeleteDirectoryAtNextReboot(path);
            } catch (Exception ex) {
                var message = String.Format("Couldn't delete old app directory on next reboot {0}", path);
                log.WarnException(message, ex);
            }
            return(ret);
        }
예제 #7
0
        IEnumerable <ShortcutCreationRequest> cleanUpOldVersions(Version newCurrentVersion)
        {
            return(fileSystem.GetDirectoryInfo(rootAppDirectory).GetDirectories()
                   .Where(x => x.Name.StartsWith("app-", StringComparison.InvariantCultureIgnoreCase))
                   .Where(x => x.Name != "app-" + newCurrentVersion)
                   .OrderBy(x => x.Name)
                   .SelectMany(oldAppRoot => {
                var path = oldAppRoot.FullName;
                var ret = AppDomainHelper.ExecuteInNewAppDomain(path, runAppSetupCleanups);

                try {
                    Utility.DeleteDirectoryAtNextReboot(oldAppRoot.FullName);
                } catch (Exception ex) {
                    log.WarnException("Couldn't delete old app directory on next reboot", ex);
                }
                return ret;
            }));
        }
        public static void ResolvedFromLoadedTypes_typeRepresentation___Should_return_resolved_type___When_assembly_is_not_loaded_prior_to_call_but_can_be_loaded_by_call()
        {
            // Arrange, Act, Assert
            var resolvedType = AppDomainHelper.ExecuteInNewAppDomain(() =>
            {
                var typeRepresentation = "OBeautifulCode.AutoFakeItEasy.NegativeInteger, OBeautifulCode.AutoFakeItEasy".ToTypeRepresentationFromAssemblyQualifiedName();

                var loadedAssemblyNamesBeforeResolvingType = AssemblyLoader.GetLoadedAssemblies().Select(_ => _.GetName().Name).ToList();

                loadedAssemblyNamesBeforeResolvingType.AsTest().Must().NotContainElement("OBeautifulCode.AutoFakeItEasy");

                var result = typeRepresentation.ResolveFromLoadedTypes();

                result.AsTest().Must().NotBeNull();

                var loadedAssemblyNamesAfterResolvingType = AssemblyLoader.GetLoadedAssemblies().Select(_ => _.GetName().Name).ToList();

                loadedAssemblyNamesAfterResolvingType.AsTest().Must().ContainElement("OBeautifulCode.AutoFakeItEasy");

                return(result);
            });

            resolvedType.AsTest().Must().BeEqualTo(typeof(NegativeInteger));
        }