我尝试让控制台应用程序使用NAppUpdate从服务器自行更新。我在Windows上测试了一个示例控制台应用程序,以确保它正常工作,现在已经过验证,它可以正确下载文件。但是在我的Rapsberry Pi上运行相同的程序时,我收到以下错误:
[UpdateHandler] : Preparing Update Source
[UpdateHandler] : Checking for updates
[UpdateHandler] : Check updates Completed
[UpdateHandler] : Updating
[UpdateHandler] : 100%
[UpdateHandler] : 100%
[UpdateHandler] : ERROR | System.TypeInitializationException: An exception was thrown by the type initializer for NAppUpdate.Framework.Utils.PermissionsCheck ---> System.NotImplementedException: The requested feature is not implemented.
at System.Security.Principal.WindowsIdentity.get_Groups () [0x00000] in <filename unknown>:0
at NAppUpdate.Framework.Utils.PermissionsCheck..cctor () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at NAppUpdate.Framework.UpdateManager.ApplyUpdates (Boolean relaunchApplication, Boolean updaterDoLogging, Boolean updaterShowConsole) [0x00000] in <filename unknown>:0
at NAppUpdate.Framework.UpdateManager.ApplyUpdates (Boolean relaunchApplication) [0x00000] in <filename unknown>:0
at RunControl.Update.UpdateHandler+<>c.<TryUpdate>b__5_1 (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
我在Raspberry Pi 3上运行控制台应用程序,安装了Raspbian Jessie Lite。单声道版本为3.2.8
(我只安装了mono-runtime
)
示例代码在这里:
public bool CheckUpdate()
{
try
{
UpdateManager _UpdateManager = UpdateManager.Instance;
_UpdateManager.UpdateSource = PrepareUpdateSource();
_UpdateManager.Config.TempFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "TMP");
_UpdateManager.ReinstateIfRestarted();
if (UpdateManager.Instance.State == UpdateManager.UpdateProcessState.Checked ||
UpdateManager.Instance.State == UpdateManager.UpdateProcessState.AfterRestart ||
UpdateManager.Instance.State == UpdateManager.UpdateProcessState.AppliedSuccessfully)
UpdateManager.Instance.CleanUp();
UpdateCheck();
return true;
}
catch (Exception e)
{
Console.WriteLine("[UpdateHandler] : ERROR | " + e.ToString());
return false;
}
}
private IUpdateSource PrepareUpdateSource()
{
Console.WriteLine("[UpdateHandler] : Preparing Update Source");
return new NAppUpdate.Framework.Sources.SimpleWebSource(source);
}
protected void UpdateCheck()
{
UpdateManager _UpdateManager = UpdateManager.Instance;
Console.WriteLine("[UpdateHandler] : Checking for updates");
_UpdateManager.BeginCheckForUpdates(asyncResult =>
{
if (asyncResult.IsCompleted)
{
Console.WriteLine("[UpdateHandler] : Check updates Completed");
//still need to check for caught exceptions if any and rethrow
((UpdateProcessAsyncResult)asyncResult).EndInvoke();
//no updates were found, or an error has occured...
if(_UpdateManager.UpdatesAvailable == 0)
{
Console.WriteLine("[UpdateHandler] : No update available");
return;
}
}
TryUpdate();
}, null);
}
private void TryUpdate()
{
Console.Writelin("[UpdateHandler] : Updating");
UpdateManager.Instance.ReportProgress += status =>
{
Console.WriteLine("[UpdateHandler] : " + status.Percentage + "%");
};
UpdateManager.Instance.BeginPrepareUpdates(asyncResult =>
{
try
{
UpdateManager.Instance.ApplyUpdates(false);
}
catch(Exception e)
{
Console.WriteLine("[UpdateHandler] : ERROR ON UPDATE | " + e.ToString());
}
if (UpdateManager.Instance.State == UpdateManager.UpdateProcessState.RollbackRequired)
UpdateManager.Instance.RollbackUpdates();
}, null);
}
如错误所示,它会找到可用的更新,但在CheckUpdate()
函数中失败。