Community discussions

MikroTik App
 
e066377
just joined
Topic Author
Posts: 8
Joined: Sun May 13, 2018 12:11 am

Translate Command Line Command to C#

Tue May 15, 2018 1:51 pm

Hi,
I want to change the following command line working command in to C# code, how can i do that?

system logging action set memory memory-lines = 1000

Tried tik4net and mikrotik low level api:
using (ITikConnection connection = ConnectionFactory.CreateConnection(TikConnectionType.Api))
{
	connection.Open(RouterIpAddress, RouterUserName, RouterPassword);
	var command = connection.CreateCommandAndParameters("/system/logging/action/set", "/memory/memory-lines", "1000");
	command.ExecuteNonQuery();
}

MK mikrotik = new MK(RouterIpAddress);
if (mikrotik.Login(RouterUserName, RouterPassword))
{
	mikrotik.Send("/system/logging/action/set");                                    
	mikrotik.Send("/memory/memory-lines=1000", true);
}
mikrotik.Close();
Neither works.
What am i doing wrong?
 
nescafe2002
Long time Member
Long time Member
Posts: 692
Joined: Tue Aug 11, 2015 12:46 pm
Location: Netherlands

Re: Translate Command Line Command to C#  [SOLVED]

Tue May 15, 2018 3:51 pm

You can use the following C# snippet:
void Main()
{
  using (var conn = ConnectionFactory.CreateConnection(TikConnectionType.Api))
  {
    var actions = conn.LoadAll<LoggingAction>();
    //actions.Dump();
    
    var memoryAction = conn.LoadSingle<LoggingAction>(conn.CreateParameter("name", "memory"));
    //memoryAction.Dump();
    
    memoryAction.Lines = 100;
    conn.Save(memoryAction);
  }
}

[TikEntity("/system/logging/action")]
public class LoggingAction
{
  [TikProperty(".id")]
  public string Id { get; private set; }

  [TikProperty("name")]
  public string Name { get; set; }

  [TikProperty("memory-lines")]
  public int Lines { get; set; }
}
You do not have the required permissions to view the files attached to this post.
 
e066377
just joined
Topic Author
Posts: 8
Joined: Sun May 13, 2018 12:11 am

Re: Translate Command Line Command to C#

Tue May 15, 2018 5:00 pm

Thanks nescafe2002, it works :)

Who is online

Users browsing this forum: No registered users and 21 guests