danikf/tik4net

Reboot/Shutdown causes IOException

Opened this issue · 1 comments

Using the /system/reboot or /system/shutdown command will cause an IOException. Not sure what would be a good solution to this issue.

>/system/reboot
<
<
Exception thrown: 'System.IO.IOException' in tik4net.dll
>/quit
<
<
System.IO.IOException: Can not read sentence from connection
   at tik4net.Api.ApiConnection.ReadSentence()
   at tik4net.Api.ApiConnection.GetOne(String tag)
   at tik4net.Api.ApiConnection.<GetAll>d__54.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at tik4net.Api.ApiConnection.CallCommandSync(String[] commandRows)
   at tik4net.Api.ApiCommand.ExecuteNonQuery()
   at ...

Example code:

TikConnection con = ConnectionFactory.OpenConnection(Type.Api, _host, _username, _password);
ITikCommand cmd = conn.CreateCommand("/system/reboot");
System.Diagnostics.Debug.WriteLine("Executing reboot");
cmd.ExecuteNonQuery();
System.Diagnostics.Debug.WriteLine("Reboot executed");

Found a workaround that seems to work ok.

TikConnection con = ConnectionFactory.OpenConnection(Type.Api, _host, _username, _password);
System.Diagnostics.Debug.WriteLine("Executing reboot");
conn.Connection.CallCommandAsync(new List<string> { "/system/reboot" }, "reboot", null);
System.Diagnostics.Debug.WriteLine("Reboot executed");

Basically using the CallCommandAsync method directly and setting the callback action to null.

Slightly worried that ApiConnection.cs#L503 will result in an infinite loop in the background, but it should stop as long as the connection is closed.