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 Create_returns_instance_of_FtpUpdatesProvider_when_protocol_configuration_is_ftp() { var config = new LauncherConfiguration { Protocol = "ftp", UpdatesLocation = "ftp://server" }; var factory = new UpdatesProviderFactory(config); var updatesProvider = factory.Create(); Assert.That(updatesProvider, Is.TypeOf(typeof(FtpUpdatesProvider))); Assert.That(updatesProvider, Is.Not.Null); }