From 4d4ed75f640dfa540d16e1c270653c4532a42512 Mon Sep 17 00:00:00 2001 From: Hristo Bogdanov Date: Tue, 18 Feb 2025 15:42:08 +0200 Subject: [PATCH] Update to handle the new RouterOS v7.18 api syntax with empty responses - Added handling for `ApiEmptySentence` in `ApiCommand.cs` to return an empty list when the first response is empty. - Introduced `!empty` case in `ApiConnection.cs` to process empty responses. - Created `ApiEmptySentence` class to manage empty response types, enhancing API functionality. --- tik4net/Api/ApiCommand.cs | 2 ++ tik4net/Api/ApiConnection.cs | 1 + tik4net/Api/ApiEmptySentence.cs | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 tik4net/Api/ApiEmptySentence.cs diff --git a/tik4net/Api/ApiCommand.cs b/tik4net/Api/ApiCommand.cs index 32ecd95..e8084df 100644 --- a/tik4net/Api/ApiCommand.cs +++ b/tik4net/Api/ApiCommand.cs @@ -403,6 +403,8 @@ private IEnumerable ExecuteListInternal(params string[] proplist EnsureReReponse(response.Take(response.Count() - 1).ToArray()); //!re - reapeating EnsureDoneResponse(response.Last()); //!done + if (response.First() is ApiEmptySentence) + return new List(); return response.Take(response.Count() - 1).Cast().ToList(); } finally diff --git a/tik4net/Api/ApiConnection.cs b/tik4net/Api/ApiConnection.cs index 59e9eab..c82d28e 100644 --- a/tik4net/Api/ApiConnection.cs +++ b/tik4net/Api/ApiConnection.cs @@ -354,6 +354,7 @@ private ITikSentence ReadSentence() case "!trap": return new ApiTrapSentence(sentenceWords); case "!re": return new ApiReSentence(sentenceWords); case "!fatal": return new ApiFatalSentence(sentenceWords); + case "!empty": return new ApiEmptySentence(); case "": throw new IOException("Can not read sentence from connection"); // With SSL possibly not logged in (SSL and new router with SSL_V2) default: throw new NotImplementedException(string.Format("Response type '{0}' not supported", sentenceName)); } diff --git a/tik4net/Api/ApiEmptySentence.cs b/tik4net/Api/ApiEmptySentence.cs new file mode 100644 index 0000000..5082baf --- /dev/null +++ b/tik4net/Api/ApiEmptySentence.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace tik4net.Api +{ + internal class ApiEmptySentence : ApiReSentence, ITikDoneSentence + { + public ApiEmptySentence() + : base(Array.Empty()) + { + } + + public string GetResponseWord() + { + return GetWordValue(TikSpecialProperties.Ret); + } + + public string GetResponseWordOrDefault(string defaultValue) + { + return GetWordValueOrDefault(TikSpecialProperties.Ret, defaultValue); + } + } +}