Exemplo n.º 1
0
        private void SomeFileWasChangedAfterWait(object state)
        {
            var finder = new VersionDirectoryFinder(log);

            DirectoryInfo versionDirectory = finder.GetVersionDirectory(path);

            if (versionDirectory == null)
                return;

            if (IsVersionHigherThanCurrent(versionDirectory.Name) && UpdateAvailable != null)
            {
                log.Success(string.Format("Updating to version: {0}, Thread: {1}, Guid: {2}", versionDirectory.Name, Thread.CurrentThread.ManagedThreadId, guid));
                UpdateAvailable();
            }
        }
Exemplo n.º 2
0
        private void Run()
        {
            string assemblyFile = Assembly.GetEntryAssembly().Location;
            string assemblyFolder = Path.GetDirectoryName(assemblyFile);
            string assemblyFileName = Path.GetFileNameWithoutExtension(assemblyFile);

            var versionDirectory = new VersionDirectoryFinder(log).GetVersionDirectory(assemblyFolder);

            if (versionDirectory == null)
            {
                log.Error("Cannot find any valid directory, which has a name with version pattern.");
                Console.ReadKey();
                return;
            }

            var exeDirectory = new DirectoryInfo(Path.Combine(versionDirectory.FullName, assemblyFileName));
            var files = exeDirectory.GetFiles("*.exe");
            if (files.Length == 0)
                throw new FileNotFoundException(string.Format("Cannot find a file with 'exe' extension inside '{0}'",
                                                              exeDirectory.FullName));
            if (files.Length > 1)
                throw new InvalidOperationException(string.Format("There is more than 1 file with 'exe' extension inside '{0}'",
                                                                  exeDirectory.FullName));

            var targetFile = files[0].FullName;
            var targetFolder = Path.GetDirectoryName(targetFile);

            var targetFileConfig = GetConfigurationFilename(targetFile);

            var currentFileConfig = GetConfigurationFilename(assemblyFile);

            //targetFileConfig = new ConfigurationFileMerger().MergeFiles(targetFileConfig, currentFileConfig);

            try
            {
                domain = AppDomain.CreateDomain(AppDomain.CurrentDomain.FriendlyName + "_bootstrapped",
                                                    AppDomain.CurrentDomain.Evidence,
                                                    new AppDomainSetup
                                                        {
                                                            ConfigurationFile = targetFileConfig,
                                                            ApplicationBase = targetFolder,
                                                        });

                var logger = (UnhandledExceptionLogger)domain.CreateInstanceFromAndUnwrap(Assembly.GetExecutingAssembly().Location,
                                                   typeof(UnhandledExceptionLogger).FullName,
                                                   false, BindingFlags.Default, null, null,
                                                   Thread.CurrentThread.CurrentCulture, null);
                logger.ProcessUnhandledExceptions();

                BootstrapperParameters.WriteToDomain(new BootstrapperParameters
                    {
                        BootstrapperFile = assemblyFile,
                        ConfigurationFile = currentFileConfig,
                    }, domain);

            //				var newArgs = new List<string>(args);
            //				newArgs.AddRange(.ToArray());
                var returnValue = domain.ExecuteAssembly(targetFile, args);
                AppDomain.Unload(domain);
                if (returnValue == (int) ReturnCodes.RestartDueToAvailableUpdate || returnValue == (int) ReturnCodes.RestartDueToConfigChange)
                    Main(args);
            }
            catch (Exception ex)
            {
                log.Error("An error occurred while running bootstrapped program", ex);
                Console.ReadLine();
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UpdateReceiver"/> class.
 /// </summary>
 /// <param name="finder">The finder.</param>
 /// <param name="parameters">The parameters.</param>
 /// <param name="zip">The zip.</param>
 public UpdateReceiver(VersionDirectoryFinder finder, BootstrapperParameters parameters, ZipSource zip)
 {
     this.finder = finder;
     this.parameters = parameters;
     this.zip = zip;
 }