Skip to content

High level API entities

Daniel Frantik edited this page Jul 8, 2016 · 5 revisions

Data entities are normal classes with properties. Each class corespond to some entity on mikroptik router, each property coresponds to some field of item on mikrotik router.

For example: API: /interface

[admin@MikroTik] /interface> print
Flags: D - dynamic, X - disabled, R - running, S - slave 
 #     NAME                                TYPE         MTU
 0  R  ether1                              ether       1500
 1     wlan1                               wlan        1500

C# entity: tik4net.Objects.Interface.Interface

public class Interface
{
  public string Id { get; private set; }
  public string Name { get; set; }
  public string Type { get; set; }
  public string Mtu { get; set; }}
}

To enable O/R mapper functionality we must tell engine names of the fields corresponding to our properties. We have to tell API url as well. So - we have to decorate our entity with attributes:

[TikEntity("/interface", IncludeDetails = true)]
public class Interface
{
    [TikProperty(".id", IsReadOnly = true, IsMandatory = true)]
    public string Id { get; private set; }

    [TikProperty("name", IsMandatory = true)]
    public string Name { get; set; }
 
   // ...
}

Finally we could use this entity with O/R mapper:

var list = connection.LoadAll<Interface>();

See this wiki page for details.

NOTE: See How to create custom entity if you are missing some entity in tik4net projekt. You can clone the github repository, create your own entity and share it via "pull request" feature with others.

Clone this wiki locally