protected virtual bool CheckRegistry(RemoteAppcast appcast) { if (IsThisFirstRun) { EnsureNotFirstRun(); _logger.Log("App is running for the first time. Skipping further checks."); return(false); } _logger.Log("This is not app's first run. Continuing with other registry checks."); var skipVersion = SkipVersion; if (!string.IsNullOrWhiteSpace(skipVersion)) { Version ver; if (Version.TryParse(skipVersion, out ver) && appcast.Version == ver) { _logger.Log(string.Format("User has asked to skip version: {0}. Skipping further checks.", ver)); return(false); } } _logger.Log("Seems like user doesn\'t want to skip this version. Continuing with other registry checks."); var lastCheckDate = LastCheckDate; if (DateTime.Now.Subtract(lastCheckDate).TotalDays < 1) { _logger.Log("Last check was done less than a day ago. Skipping further checks"); return(false); } _logger.Log(string.Format("Last check was done on: {0}", lastCheckDate.ToShortDateString())); return(true); }
protected virtual bool CheckVersion(RemoteAppcast appcast) { var curVer = Assembly.GetEntryAssembly().GetName().Version; var isHigherVersionAvailable = appcast.Version.IsHigherThan(curVer); _logger.Log(string.Format("Higher version of app is {0}available", isHigherVersionAvailable ? "" : "not ")); return(isHigherVersionAvailable); }
public void MakeFromJsonReturnsEmptyAppcastForEmptyJson() { var appcast = RemoteAppcast.MakeFromJson(string.Empty); Assert.IsNotNull(appcast); Assert.AreEqual(0, appcast.Channels.Count); Assert.AreEqual(0, appcast.RawDictionary.Count); }
public void AllValuesAreAddedToRawDictionary() { var appcast = RemoteAppcast.MakeFromJson(_oneChannelJson); Assert.AreEqual(2, appcast.RawDictionary.Count); Assert.IsTrue(appcast.RawDictionary.ContainsKey("foo")); Assert.AreEqual("bar", appcast.RawDictionary["foo"]); }
internal async Task StartAsync(RemoteAppcast appcast) { InitializeCommands(appcast); Title = string.Format(Resources.NewVersionAvailable, appcast.Title).ToUpperInvariant(); OldVersion = GetOldVersion(); NewVersion = appcast.Version.ToString(); ReleaseNotes = await FetchReleaseNotesAsync(appcast.ReleaseNotesUrl).ConfigureAwait(false); }
private RemoteAppcast ParseAppcast(string content) { _logger.Log("Started deserializing remote channel content"); var appcast = RemoteAppcast.MakeFromJson(content); _logger.Log("Finished deserializing remote channel content"); return(appcast); }
public void WhenChannelsHaveNoIdsReturnsChannelWithHighestVersion() { var sut = new BestChannelFinder(Substitute.For <IDebuggingInfoLogger>()); var appcast = RemoteAppcast.MakeFromJson(_twoChannelJson); var selectedChannel = sut.Find(4, appcast.Channels); Assert.IsNotNull(selectedChannel); Assert.AreEqual(appcast.Channels[1], selectedChannel); }
private RemoteAppcast ParseAppcast(string content) { _logger.Log("Started deserializing remote channel content"); var appcast = RemoteAppcast.MakeFromJson(content); _logger.Log("Finished deserializing remote channel content"); OnRemoteAppcastAvailableEvent(new SingleEventArgs <RemoteAppcast>(appcast)); return(appcast); }
private async Task DownloadArtifact(RemoteAppcast appcast, string destinationPath) { _logger.Log("Starting to download artifact"); using (var client = new WebClient()) { client.DownloadProgressChanged += (sender, args) => { ProgressPercent = args.ProgressPercentage; }; await _contentDownloader.DownloadFile(appcast.ArtifactUrl, destinationPath, client).ConfigureAwait(false); _logger.Log(string.Format("Artifact downloaded to {0}", destinationPath)); } }
private bool FailedToEnroll(RemoteAppcast appcast, int channelId) { var channel = appcast.Channels.FirstOrDefault(c => c.Id == channelId); var enrollment = new Enrollment(channel); if (channel != null && channel.RequiresEnrollment) { enrollment.IsRequired = true; ShowEnrollmentWindow(enrollment); } _analyticsLogger.LogEnrollment(enrollment); OnEnrollmentAvailableEvent(new SingleEventArgs <Enrollment>(enrollment)); return(enrollment.IsRequired && !enrollment.IsEnrolled); }
public void WhenChannelsHaveMixIdsReturnsChannelWithHighestVersionLessThanSubscribedId() { var sut = new BestChannelFinder(Substitute.For <IDebuggingInfoLogger>()); var appcast = RemoteAppcast.MakeFromJson(_threeChannelJson); // subscribed to 3, and there is an id of 2 in the json var selectedChannel = sut.Find(3, appcast.Channels); Assert.IsNotNull(selectedChannel); Assert.AreEqual(appcast.Channels[1], selectedChannel); // subscribed to 1, but because there is id that matches it, it returns the highest version of all selectedChannel = sut.Find(1, appcast.Channels); Assert.IsNotNull(selectedChannel); Assert.AreEqual(appcast.Channels[2], selectedChannel); }
public void CanBeSerializedFromJsonWithMultipleChannelInfo() { var appcast = RemoteAppcast.MakeFromJson(_twoChannelJson); Assert.AreEqual(2, appcast.Channels.Count); var channel = appcast.Channels[1]; Assert.AreEqual(3, channel.Id); Assert.AreEqual("5.9.9", channel.Version.ToString()); Assert.AreEqual("release_notes_url_http_3", channel.ReleaseNotesUrl); Assert.AreEqual("artifact_url_http_3", channel.ArtifactUrl); Assert.AreEqual(02, channel.BuildDate.Month); Assert.AreEqual(18, channel.BuildDate.Day); Assert.AreEqual(2017, channel.BuildDate.Year); }
public void CanBeSerializedFromJsonWithOnlyOneChannelInfo() { var appcast = RemoteAppcast.MakeFromJson(_oneChannelJson); Assert.AreEqual(1, appcast.Channels.Count); var channel = appcast.Channels.First(); Assert.AreEqual(2, channel.Id); Assert.AreEqual("5.8.8", channel.Version.ToString()); Assert.AreEqual("release_notes_url_http", channel.ReleaseNotesUrl); Assert.AreEqual("artifact_url_http", channel.ArtifactUrl); Assert.AreEqual(01, channel.BuildDate.Month); Assert.AreEqual(28, channel.BuildDate.Day); Assert.AreEqual(2017, channel.BuildDate.Year); }
protected virtual async void ShowUpdateWindow(RemoteAppcast appcast) { var viewModel = new MainWindowViewModel(_appInfo, _logger, RemoteContentDownloader, _analyticsLogger); await viewModel.StartAsync(appcast).ConfigureAwait(true); var window = new MainWindow { ViewModel = viewModel }; viewModel.DownloadNowCommand = new DelegateCommand(e => { _analyticsLogger.LogDownloadNow(); _logger.Log("Continuing with downloading the artifact"); window.Close(); ShowDownloadWindow(appcast); }); SetOwner(window); window.ShowDialog(); }
internal bool ShouldUpdate(RemoteAppcast appcast, bool shouldIgnoreRegistryChecks = false) { if (!shouldIgnoreRegistryChecks) { _logger.Log("Checking registry entries for updates."); if (!CheckRegistry(appcast)) { _logger.Log("Registry entries says not to tell if there is an update available."); return(false); } _logger.Log("Registry entries says go and tell if there is an update available."); } else { _logger.Log("Skipping registry checks. This probably means we are doing forced update checks."); } UpdateCheckDate(); var higherVersion = CheckVersion(appcast); return(higherVersion); }
private bool ShouldOpenArtifact(RemoteAppcast appcast, string artifactPath) { if (string.IsNullOrEmpty(appcast.DSASignature)) { _logger.Log("No DSASignature provided. Skipping signature verification"); return(true); } _logger.Log("DSASignature provided. Verifying artifact's signature"); if (VerifyArtifact(appcast, artifactPath)) { _logger.Log("Successfully verified artifact's signature"); return(true); } _logger.Log("Couldn't verify artifact's signature. The artifact will now be deleted."); var signatureWindowViewModel = new SignatureVerificationWindowViewModel(_appInfo, appcast); var signatureWindow = new SignatureVerificationWindow { DataContext = signatureWindowViewModel }; signatureWindowViewModel.ContinueCommand = new DelegateCommand(e => { signatureWindow.Close(); }); SetOwner(signatureWindow); signatureWindow.ShowDialog(); return(false); }
protected virtual void ShowDownloadWindow(RemoteAppcast appcast) { var viewModel = new DownloadWindowViewModel(_appInfo, _logger, RemoteContentDownloader); var artifactPath = CreateTempPath(appcast.ArtifactUrl); var window = new DownloadWindow { DataContext = viewModel }; viewModel.ContinueWithInstallationCommand = new DelegateCommand(e => { _logger.Log("Continue after downloading artifact"); _analyticsLogger.LogContinueWithInstallation(); OnArtifactDownloadedEvent(new SingleEventArgs <string>(artifactPath)); window.Close(); if (ShouldOpenArtifact(appcast, artifactPath)) { OpenArtifact(artifactPath); _logger.Log("Opened artifact"); } }); SetOwner(window); viewModel.StartAsync(appcast, artifactPath); window.ShowDialog(); }
protected override void ShowUpdateWindow(RemoteAppcast appcast) { // can't do in tests _showUpdateWindowFlag = true; }
protected virtual bool VerifyArtifact(RemoteAppcast appcast, string artifactPath) { var verifer = new SignatureVerifier(_appInfo.PublicSignatureFilename); return(verifer.VerifyDSASignature(appcast.DSASignature, artifactPath)); }
internal async void StartAsync(RemoteAppcast appcast, string destinationPath) { Title = string.Format(Properties.Resources.DownloadingInstaller, appcast.Title); await DownloadArtifact(appcast, destinationPath).ConfigureAwait(true); }
public SignatureVerificationWindowViewModel(AppInfo appInfo, RemoteAppcast appcast) { AppIconPath = appInfo.AppIconPath; Title = string.Format(Properties.Resources.SignatureErrorTitle, appcast.Title); }
protected override void OnRemoteAppcastAvailableEvent(SingleEventArgs <RemoteAppcast> args) { RemoteAppcast = args.Payload; base.OnRemoteAppcastAvailableEvent(args); }
private void InitializeCommands(RemoteAppcast appcast) { _remoteVersion = appcast.Version.ToString(); SkipThisVersionCommand = new DelegateCommand(SkipThisVersionCommandHandler); RemindMeLaterCommand = new DelegateCommand(RemindMeLaterCommandHandler); }