/// <summary>
        /// Gets the Mikrotik connection.
        /// </summary>
        /// <returns></returns>
        private ITikConnection GetConnection()
        {
            PackageHost.WriteInfo("Connecting to {0} ...", PackageHost.GetSettingValue("Host"));
            ITikConnection connection = ConnectionFactory.CreateConnection(TikConnectionType.Api);

            try
            {
                connection.Open(PackageHost.GetSettingValue("Host"), PackageHost.GetSettingValue("Username"), PackageHost.GetSettingValue("Password"));
                PackageHost.WriteInfo("Connected!");
            }
            catch (Exception ex)
            {
                PackageHost.WriteError($"Unable to connect to {PackageHost.GetSettingValue("Host")} : {ex.Message}");
                connection.Dispose();
                connection = null;
            }
            return(connection);
        }
Exemple #2
0
 public void Cleanup()
 {
     _connection.Dispose();
 }
Exemple #3
0
 public void Dispose()
 {
     _connection.Close();
     _connection.Dispose();
 }