public void GetVersion_returns_version_part_of_filename()
        {
            var namingConvention = new DefaultNamingConvention();

            var version = namingConvention.GetVersionFromFilename("Test.App-1.0.0.1.zip");

            Assert.That(version, Is.EqualTo(new Version(1, 0, 0, 1)));
        }
Ejemplo n.º 2
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            initializeLogging();

            // Workflow

            // 1. read configuration
            var config = new ConfigurationReader().Read();

            // 2. check whether there is a new version or not
            var updatesProvider = new UpdatesProviderFactory(config).Create();
            var namingConvention = new DefaultNamingConvention();

            try
            {
                var lastVersionFilename = updatesProvider.GetLastVersionFilename(namingConvention);
                var lastVersion = namingConvention.GetVersionFromFilename(lastVersionFilename);
                var currentVersion = new CurrentVersionProvider(config).GetCurrentVersion();

                if (lastVersion > currentVersion)
                {
                    log.InfoFormat("Current version: {0}", currentVersion);
                    log.InfoFormat("Last version available: {0}", lastVersion);

                    // 3. if there is a new version, download it
                    var downloadProgressNotificator = new DownloadProgressForm();
                    var localFilename = updatesProvider.Download(lastVersionFilename,
                                                                 downloadProgressNotificator);

                    // 4. then activate it
                    var activator = new DefaultActivator(config, null);
                    activator.Activate(localFilename);
                }

            }
            catch (UpdatesProviderInaccessibleException ex)
            {
                // ignore errors when updates provider is inaccessible
            }
            catch (Exception ex)
            {
                log.Error("Error updating", ex);
            }

            try
            {
                Process.Start(config.ApplicationExe);
            }
            catch (Exception ex)
            {
                log.Fatal("Cannot start application", ex);
            }
        }
        public void GetLastVersionFilename_returns_last_version_filename_that_verifies_convention()
        {
            var namingConvention = new DefaultNamingConvention();
            var configuration = new LauncherConfiguration {ApplicationExe = "Test.App.exe"};
            var fileList = new[]
                {
                    "Test.App-1.0.0.0.zip",
                    "Test.App-1.0.2.0.zip",
                    "Test.Other-2.0.2.0.zip",
                };

            var lastVersionFilename = namingConvention.GetLastVersionFilename(fileList, configuration);

            Assert.That(lastVersionFilename, Is.EqualTo("Test.App-1.0.2.0.zip"));
        }