Community discussions

 
giguard
just joined
Topic Author
Posts: 18
Joined: Mon Oct 01, 2018 7:10 pm

c# tik4net 3.3.0 How do I convert '/ip ipsec remote-peer remove [ find id="blah" ]' to c#?

Thu Oct 11, 2018 4:13 pm

Hi,

Searching through the forum I can't seem to find any previous post regarding to the question in the topic.
This is the command I'm running at the terminal

/ip ipsec remote-peer remove [ find id="blah" ]

I'm using tik4net 3.3.0 and using it in Visual Studio and writing C# code.

Among many things I've tried, I'm pasting in my last attempt.
            ITikCommand printcmd = connection.CreateCommandAndParameters("/ip/ipsec/remote-peer/remove");
            printcmd.AddParameter("=find", "");
            printcmd.AddParameter("Id", "blah");
I know above code is wrong... (I had to try:P) but you get the picture.

So, how should I go about doing this ?
Thank you,

Daniel
 
nescafe2002
Long time Member
Long time Member
Posts: 622
Joined: Tue Aug 11, 2015 12:46 pm
Location: Netherlands

Re: c# tik4net 3.3.0 How do I convert '/ip ipsec remote-peer remove [ find id="blah" ]' to c#?

Thu Oct 11, 2018 5:03 pm

Only print command supports query words, so split your program into a print with query then iterate the result.
  var cmd = conn.CreateCommandAndParameters("/ip/ipsec/remote-peers/print");
  cmd.AddParameter("id", "blah");
  cmd.AddParameter(".proplist", ".id", TikCommandParameterFormat.NameValue);
  var list = cmd.ExecuteList();

  foreach (var item in list)
  {
    conn.CreateCommandAndParameters("/ip/ipsec/remote-peers/remove", ".id", item.GetId()).ExecuteNonQuery();
  }

Who is online

Users browsing this forum: No registered users and 17 guests