本文整理汇总了C#中Squirrel.UpdateManager.CheckForUpdate方法的典型用法代码示例。如果您正苦于以下问题:C# UpdateManager.CheckForUpdate方法的具体用法?C# UpdateManager.CheckForUpdate怎么用?C# UpdateManager.CheckForUpdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Squirrel.UpdateManager
的用法示例。
在下文中一共展示了UpdateManager.CheckForUpdate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
private static async Task Update()
{
try
{
using (var mgr = new UpdateManager("http://lunyx.net/CasualMeter"))
{
Logger.Info("Checking for updates.");
if (mgr.IsInstalledApp)
{
Logger.Info($"Current Version: v{mgr.CurrentlyInstalledVersion()}");
var updates = await mgr.CheckForUpdate();
if (updates.ReleasesToApply.Any())
{
Logger.Info("Updates found. Applying updates.");
var release = await mgr.UpdateApp();
MessageBox.Show(CleanReleaseNotes(release.GetReleaseNotes(Path.Combine(mgr.RootAppDirectory, "packages"))),
$"Casual Meter Update - v{release.Version}");
Logger.Info("Updates applied. Restarting app.");
UpdateManager.RestartApp();
}
}
}
}
catch (Exception e)
{ //log exception and move on
HandleException(e);
}
}
示例2: ScheduleApplicationUpdates
private async void ScheduleApplicationUpdates(Object o)
{
var location = UpdateHelper.AppUpdateCheckLocation;
var appName = Assembly.GetExecutingAssembly().GetName().Name;
using (var mgr = new UpdateManager(location, appName, FrameworkVersion.Net45))
{
try
{
UpdateInfo updateInfo = await mgr.CheckForUpdate();
if (updateInfo.FutureReleaseEntry != null)
{
if (updateInfo.CurrentlyInstalledVersion.Version == updateInfo.FutureReleaseEntry.Version) return;
await mgr.UpdateApp();
// This will show a button that will let the user restart the app
Dispatcher.Invoke(ShowUpdateIsAvailable);
// This will restart the app automatically
//Dispatcher.InvokeAsync<Task>(ShutdownApp);
}
}
catch (Exception ex)
{
var a = ex;
}
}
}
示例3: CheckAndUpdate
/// <summary>
/// Squirrel check and update.
/// </summary>
private async Task CheckAndUpdate(bool checkOnly = false)
{
// 6/27/15 - Task.Wait always times out. Seems to be an issue with the return of Squirrel's async methods.
try
{
AddMessage("Start of CheckAndUpdate");
using (var updateManager = new UpdateManager(Program.PackageUrl, Program.PackageId))
{
// Check
AddMessage(String.Format("UpdateManager: {0}", JsonConvert.SerializeObject(updateManager, Formatting.Indented)));
AddMessage("Calling UpdateManager.CheckForUpdate");
var updateInfo = await updateManager.CheckForUpdate();
AddMessage(String.Format(
"UpdateManager.CheckForUpdate returned UpdateInfo: {0}",
JsonConvert.SerializeObject(updateInfo, Formatting.Indented)));
if (checkOnly) { return; }
// Update
if (updateInfo.ReleasesToApply.Count > 0)
{
AddMessage("Calling UpdateManager.UpdateApp");
var releaseEntry = await updateManager.UpdateApp();
AddMessage(String.Format(
"UpdateManager.UpdateApp returned ReleaseEntry: {0}",
JsonConvert.SerializeObject(releaseEntry, Formatting.Indented)));
}
else { AddMessage("No updates to apply"); }
}
}
catch (Exception exception)
{
Log.Error("Exception in CheckAndUpdate", exception);
throw;
}
}
示例4: Update
private static async void Update(Task<string> result)
{
if (result.Result == null || result.Result != "1")
return;
try
{
using (var mgr = new UpdateManager(@"https://releases.noelpush.com/", "NoelPush"))
{
var updates = await mgr.CheckForUpdate();
if (updates.ReleasesToApply.Any())
{
var lastVersion = updates.ReleasesToApply.OrderBy(x => x.Version).Last();
await mgr.DownloadReleases(updates.ReleasesToApply);
await mgr.ApplyReleases(updates);
var latestExe = Path.Combine(mgr.RootAppDirectory, string.Concat("app-", lastVersion.Version), "NoelPush.exe");
mgr.Dispose();
RestartAppEvent();
UpdateManager.RestartApp(latestExe);
}
mgr.Dispose();
}
}
catch (Exception e)
{
LogManager.GetCurrentClassLogger().Error(e.Message);
}
}
示例5: ButtonUpdateQuestion_OnClick
private async void ButtonUpdateQuestion_OnClick(object sender, RoutedEventArgs e)
{
try
{
using (var mgr = new UpdateManager(ConfigurationManager.AppSettings["UpdatePath"]))
{
var release = await mgr.CheckForUpdate();
this.UpdateQuestionResult.Text = "Possible Update: " + release.FutureReleaseEntry.Version.ToString();
}
}
catch (Exception test)
{
this.UpdateQuestionResult.Text = test.Message;
}
}
示例6: Main
private static void Main()
{
Task.Run(async () =>
{
var upgraded = false;
while (!upgraded)
{
await Task.Delay(TimeSpan.FromSeconds(5));
using (
var mgr = new UpdateManager(@"http://distribute.klonmaschine.de/metrothing/", "metrothing",
FrameworkVersion.Net45))
{
SquirrelAwareApp.HandleEvents(
v => mgr.CreateShortcutForThisExe(),
v => mgr.CreateShortcutForThisExe(),
onAppUninstall: v => mgr.RemoveShortcutForThisExe());
// Try the update
try
{
var updateInfo = await mgr.CheckForUpdate();
if (updateInfo != null && updateInfo.ReleasesToApply.Count > 0)
{
#if !DEBUG
await mgr.UpdateApp();
#endif
upgraded = true;
Singleton<InstallationManager>.Instance.Updated(
updateInfo.FutureReleaseEntry.Version.ToString(),
String.Join("", updateInfo.FetchReleaseNotes().Values));
}
}
catch (Exception e)
{
Trace.WriteLine("Squirrel update failed: " + e.Message);
}
}
if (!upgraded)
await Task.Delay(TimeSpan.FromHours(12));
}
});
MetroThing.Program.Main();
}
示例7: bw_DoWork
async void bw_DoWork(object sender, DoWorkEventArgs e) {
do {
try {
using (var mgr = new UpdateManager(@"C:\dev\helloworld\HelloWorld\Releases", "HelloWorldSquirrel")) {
var updateInfo = await mgr.CheckForUpdate(false, progress => { });
if (updateInfo != null && updateInfo.ReleasesToApply.Count != 0) {
await mgr.UpdateApp();
Restart = true;
}
}
} catch (Exception ex) {
Console.WriteLine(ex.StackTrace);
}
Console.WriteLine("I am running");
Thread.Sleep(2000);
} while (true);
}
示例8: UpdateApp
public async Task UpdateApp()
{
var updatePath = ConfigurationManager.AppSettings["UpdatePathFolder"];
var packageId = ConfigurationManager.AppSettings["PackageID"];
using (var mgr = new UpdateManager(updatePath, packageId, FrameworkVersion.Net45))
{
var updates = await mgr.CheckForUpdate();
if (updates.ReleasesToApply.Any())
{
var lastVersion = updates.ReleasesToApply.OrderBy(x => x.Version).Last();
await mgr.DownloadReleases(new[] { lastVersion });
await mgr.ApplyReleases(updates);
await mgr.UpdateApp();
MessageBox.Show("The application has been updated - please close and restart.");
}
else
{
MessageBox.Show("No Updates are available at this time.");
}
}
}
示例9: Download
public async Task<string> Download(string updateUrl, string appName = null)
{
appName = appName ?? getAppNameFromDirectory();
this.Log().Info("Fetching update information, downloading from " + updateUrl);
using (var mgr = new UpdateManager(updateUrl, appName)) {
var updateInfo = await mgr.CheckForUpdate(progress: x => Console.WriteLine(x / 3));
await mgr.DownloadReleases(updateInfo.ReleasesToApply, x => Console.WriteLine(33 + x / 3));
var releaseNotes = updateInfo.FetchReleaseNotes();
var sanitizedUpdateInfo = new {
currentVersion = updateInfo.CurrentlyInstalledVersion.Version.ToString(),
futureVersion = updateInfo.FutureReleaseEntry.Version.ToString(),
releasesToApply = updateInfo.ReleasesToApply.Select(x => new {
version = x.Version.ToString(),
releaseNotes = releaseNotes.ContainsKey(x) ? releaseNotes[x] : "",
}).ToArray(),
};
return SimpleJson.SerializeObject(sanitizedUpdateInfo);
}
}
示例10: ButtonUpdate_Click
/// <summary>
/// Handles the Click event of the buttonUpdate control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
private async void ButtonUpdate_Click(object sender, EventArgs e)
{
string updateUrl = @"http://journaley.s3.amazonaws.com/stable";
string updateSrcFile = Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"UpdateSource");
if (File.Exists(updateSrcFile))
{
updateUrl = File.ReadAllText(updateSrcFile, System.Text.Encoding.UTF8).Trim();
}
// Update Check
if (this.Owner is MainForm)
{
++((MainForm)this.Owner).UpdateProcessCount;
}
try
{
using (var mgr = new UpdateManager(updateUrl))
{
// Disable update check when in develop mode.
if (!mgr.IsInstalledApp)
{
MessageBox.Show("Checking for update is disabled in develop mode.", "Update Journaley");
return;
}
var updateInfo = await mgr.CheckForUpdate();
if (updateInfo == null)
{
MessageBox.Show("Failed to check for update.", "Update Journaley");
return;
}
if (updateInfo.ReleasesToApply.Any())
{
await mgr.DownloadReleases(updateInfo.ReleasesToApply);
await mgr.ApplyReleases(updateInfo);
MessageBox.Show(
"Journaley has been updated to v" +
updateInfo.ReleasesToApply.Max(x => x.Version) + ".\n" +
"Restart Journaley to use the new version.",
"Update Journaley");
this.UpdateAvailable = false;
if (this.Owner is MainForm)
{
((MainForm)this.Owner).UpdateAvailable = false;
}
}
else
{
MessageBox.Show("Journaley is already up to date!", "Update Journaley");
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error occurred while updating.", "Update Journaley");
Logger.Log(ex.Message);
Logger.Log(ex.StackTrace);
}
finally
{
if (this.Owner is MainForm)
{
--((MainForm)this.Owner).UpdateProcessCount;
}
}
}
示例11: Update
public async Task Update(string updateUrl, string appName = null)
{
appName = appName ?? getAppNameFromDirectory();
this.Log().Info("Starting update, downloading from " + updateUrl);
using (var mgr = new UpdateManager(updateUrl, appName)) {
bool ignoreDeltaUpdates = false;
this.Log().Info("About to update to: " + mgr.RootAppDirectory);
retry:
try {
var updateInfo = await mgr.CheckForUpdate(ignoreDeltaUpdates: ignoreDeltaUpdates, progress: x => Console.WriteLine(x / 3));
await mgr.DownloadReleases(updateInfo.ReleasesToApply, x => Console.WriteLine(33 + x / 3));
await mgr.ApplyReleases(updateInfo, x => Console.WriteLine(66 + x / 3));
} catch (Exception ex) {
if (ignoreDeltaUpdates) {
this.Log().ErrorException("Really couldn't apply updates!", ex);
throw;
}
this.Log().WarnException("Failed to apply updates, falling back to full updates", ex);
ignoreDeltaUpdates = true;
goto retry;
}
var updateTarget = Path.Combine(mgr.RootAppDirectory, "Update.exe");
await this.ErrorIfThrows(() =>
mgr.CreateUninstallerRegistryEntry(),
"Failed to create uninstaller registry entry");
}
}
示例12: CheckForUpdateAsync
/// <summary>
/// Check for updates using Squirrel UpdateManager and return the UpdateInfo result.
/// </summary>
/// <returns></returns>
public static async Task<UpdateInfo> CheckForUpdateAsync()
{
var appName = GetAppName();
var updateLocation = GetUpdateLocation();
object ret = null;
_log.Debug("Checking for update. Called " + Utilities.GetCallerName() + " with UpdateLocation = \"" + updateLocation + "\" and AppName = " + appName + "\".");
using (var mgr = new Squirrel.UpdateManager(updateLocation, appName, Squirrel.FrameworkVersion.Net45))
{
try
{
var updateInfo = await mgr.CheckForUpdate().ConfigureAwait(false);
ret = updateInfo;
}
catch (Exception)
{
throw;
}
return (UpdateInfo)ret;
}
}
示例13: WhenReleasesFileIsBlankReturnNull
public async Task WhenReleasesFileIsBlankReturnNull()
{
string tempDir;
using (Utility.WithTempDirectory(out tempDir)) {
var fixture = new UpdateManager(tempDir, "MyAppName", FrameworkVersion.Net40);
File.WriteAllText(Path.Combine(tempDir, "RELEASES"), "");
using (fixture) {
Assert.Null(await fixture.CheckForUpdate());
}
}
}
示例14: Download
public async Task<string> Download(string updateUrl, string appName = null)
{
appName = appName ?? getAppNameFromDirectory();
// NB: Always basing the rootAppDirectory relative to ours allows us to create Portable
// Applications
var ourDir = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "..");
this.Log().Info("Fetching update information, downloading from " + updateUrl);
using (var mgr = new UpdateManager(updateUrl, appName, FrameworkVersion.Net45, ourDir)) {
var updateInfo = await mgr.CheckForUpdate(progress: x => Console.WriteLine(x / 3));
await mgr.DownloadReleases(updateInfo.ReleasesToApply, x => Console.WriteLine(33 + x / 3));
var releaseNotes = updateInfo.FetchReleaseNotes();
var sanitizedUpdateInfo = new {
currentVersion = updateInfo.CurrentlyInstalledVersion.Version.ToString(),
futureVersion = updateInfo.FutureReleaseEntry.Version.ToString(),
releasesToApply = updateInfo.ReleasesToApply.Select(x => new {
version = x.Version.ToString(),
releaseNotes = releaseNotes.ContainsKey(x) ? releaseNotes[x] : "",
}).ToArray(),
};
return SimpleJson.SerializeObject(sanitizedUpdateInfo);
}
}
示例15: SquirrelUpdate
private static async Task<bool> SquirrelUpdate(SplashScreenWindow splashScreenWindow, UpdateManager mgr, bool ignoreDelta = false)
{
try
{
Log.Info($"Checking for updates (ignoreDelta={ignoreDelta})");
splashScreenWindow.StartSkipTimer();
var updateInfo = await mgr.CheckForUpdate(ignoreDelta);
if(!updateInfo.ReleasesToApply.Any())
{
Log.Info("No new updated available");
return false;
}
var latest = updateInfo.ReleasesToApply.LastOrDefault()?.Version;
var current = mgr.CurrentlyInstalledVersion();
if(latest <= current)
{
Log.Info($"Installed version ({current}) is greater than latest release found ({latest}). Not downloading updates.");
return false;
}
if(IsRevisionIncrement(current?.Version, latest?.Version))
{
Log.Info($"Latest update ({latest}) is revision increment. Updating in background.");
splashScreenWindow.SkipUpdate = true;
}
Log.Info($"Downloading {updateInfo.ReleasesToApply.Count} {(ignoreDelta ? "" : "delta ")}releases, latest={latest?.Version}");
await mgr.DownloadReleases(updateInfo.ReleasesToApply, splashScreenWindow.Updating);
Log.Info("Applying releases");
await mgr.ApplyReleases(updateInfo, splashScreenWindow.Installing);
await mgr.CreateUninstallerRegistryEntry();
Log.Info("Done");
return true;
}
catch(Exception ex)
{
if(ignoreDelta)
return false;
if(ex is Win32Exception)
Log.Info("Not able to apply deltas, downloading full release");
return await SquirrelUpdate(splashScreenWindow, mgr, true);
}
}