danikf / tik4net

Manage mikrotik routers with .NET C# code via ADO.NET like API or enjoy O/R mapper like highlevel api.
Apache License 2.0
177 stars 94 forks source link

[Request] ExecuteListWithDuration return on !done and ExecuteListUntilDone #48

Open Deantwo opened 6 years ago

Deantwo commented 6 years ago

Attempting to make a simple synchronous traceroute, but none of the execute commands work, except for ExecuteListWithDuration.

I believe that calling the command /tool/traceroute address=8.8.8.8 count=1 would cause RouterOS to return a !done by itself without the need for a /cancel.

Do you think it would be possible to make ExecuteListWithDuration return when it it receive a !done? And maybe a ExecuteListUntilDone would be interesting to have.

Deantwo commented 6 years ago

Some testing shows that maybe ExecuteListWithDuration(1000) does return when it receive a !done. The summary comment does not mention this though. Might want to add that.

So I might be able to use ExecuteListWithDuration anyway, but I would still prefer a timeout exception, rather than a cancel.

danikf commented 6 years ago

Hi, I believe synchronous call is easy, isn't it? Just use synchronous Execute method with count limit.

const string IP = "127.0.0.1";

var cmd = Connection.CreateCommandAndParameters("/tool/traceroute", TikCommandParameterFormat.NameValue,
      "address", IP,
      "count", "1");
var result = cmd.ExecuteList();

Which returns list of two !re rows.

> /tool/traceroute
> =address=127.0.0.1
> =count=1
< !re
< =address=
< =loss=0
< =sent=1
< =last=0
< =status=
< 
< !re
< =address=127.0.0.1
< =loss=0
< =sent=1
< =last=32
< =avg=32
< =best=32
< =worst=32
< =std-dev=0
< =status=
< 
< !done

Is this behavior similar to your expectations?

D

danikf commented 6 years ago

BTW - about ExecuteWithDuration behavior see #41 (I have also updated comments on these methods as you recommended)

D

danikf commented 6 years ago

Hi - version with expected fix seams to be still in development ... I will publish v3.4 soon. D

danikf commented 6 years ago

Added ToolTraceroute object with static Execute method.

Deantwo commented 6 years ago

Testing the changes.

Deantwo commented 6 years ago

ExecuteListWithDuration works, but kinda opposite from what I would want to have in my specific case. Which is why a ExecuteListUntilDone might be interesting. Maybe I should try to implement it.

Deantwo commented 6 years ago

I would suggest that ExecuteListWithDuration(int, out bool, out string) return something else than "canceled" when it received a premature !done. Why not make the abortReason be "Prematurely done" or something? Monitoring the ExecuteAsync's onDoneCallback for a premature !done shouldn't be too hard.

Deantwo commented 5 years ago

I will confess that I haven't used any of these duration execute methods at all out side of my testing back then. So not sure if anything needs to be changed here anymore. The logic behind some of these just seem backwards to me.