Jump to content

TCAdmin C# Wrapper


Alexr03
Message added by Dennis

NOTICE: TCADMIN & The developer of 3rd party tools are not responsible or held liable for you the end user using 3rd party software or tools from within our forums.

Recommended Posts

Hi All!

 

So i've decided to just throw out a TCAdmin Wrapper for the community to use to create custom applications that integrate with TCAdmin, at least until a REST API comes around from Luis. But for now we have to either stick with the limitations of the Billing API or take full advantage of the TCAdmin SDK. (Duh! I used the latter).

 

The possibilities are probably endless using this library, I've currently made custom Discord bots that I posted here on the forums a few months back using it.

Here is the project, it is open source, so feel free to contribute to it if you wish: https://gitlab.openshift.alexr03.dev/Alex/tcadmin-wrapper

You can download the binary here: https://cloud.openshift.alexr03.dev/s/a9dGbZZrKCsWP4W

Make sure to read the "README.md", it has examples on how to use the library and how to install the TCAdmin dependencies. 

 

If you need some help i'll be lurking around on the new TCAdmin discord, so just ping me there and if I have some time i'll help you out.

http://discord.gg/invite/Bpe574k

 

I may also release a boilerplate for creating custom endpoints on TCAdmin MVC webpages if you are interested in that too, let me know.

 

README.md

 

TCAdmin-Wrapper

A Wrapper for the TCAdmin SDK. Easily create a TCAdmin instance without using a configuration file.

Notes

  • Host the custom application as close as possible to the master MySQL server that hosts the TCAdmin database. This majorly reduces latency and much faster response times between commands.
    • Connecting to a MySQL slave is supported but functionality is reduced due to read only access.
    • Specifically saving custom variables or properties on a TCAdmin object will not work as data is not synced between the two databases.
    • You only need to initialize TCAdminClient once in the program, after this, you can then access all of TCAdmins SDK which will be configured already to use.

Dependencies

Please ensure that you have these libraries installed either inside the program you are creating or installed on the OS itself.

  • MySQL Connector (6.6.4)
  • TCAdmin is installed locally and added to the System PATH variable. (Not required if using NuGet)

Getting started

  1. Install MySQL.Data 6.6.4 (optional)
  2. Add https://nexus-repository.openshift.alexr03.dev/repository/tcadmin/ as a source to your NuGet/Package Manager. (optional)
  3. Install TCAdminWrapper into your project via NuGet: Install-Package TCAdminWrapper -Source https://nexus-repository.openshift.alexr03.dev/repository/tcadmin/
  4. Open TCAdmin.Monitor.Config on your master server (Located in TCAdmin/Monitor) find TCAdmin.Database.MySql.ConnectionString and copy its value. DO NOT SHARE THIS VALUE ANYWHERE IT WILL ALLOW ACCESS TO YOUR TCADMIN DATABASE
  5. Follow the examples below

Examples

Basic Example:

This example will show you how to initialize the TCAdminClient class. You only need to do this once in the program. And then will get the Server in TCAdmin with ID 1, and print the name to the console

        public static void Main(string[] args)
        {
            string sqlString =
                "SQL_STRING_HERE";
            TCAdminClientConfiguration configuration = new TCAdminClientConfiguration(sqlString, 
                true, 
                "TCAdminWrapperTest", new TCAdminSettings());
            TcAdminClient client = new TcAdminClient(configuration);

            Console.WriteLine("Name: " + new TCAdmin.SDK.Objects.Server(1));
        }

Debug Configuration

If you'd like to take advantage of using TCAdmin's debug messages like seeing what SQL commands are being executed for debugging, you can do this:

When running this you will see more messages in the console until it finally prints out the server name.

        public static void Main(string[] args)
        {
            string sqlString =
                "SQL_STRING_HERE";

            TCAdminSettings settings = new TCAdminSettings(debug: true, debugSql: true);

            TCAdminClientConfiguration configuration = new TCAdminClientConfiguration(sqlString, 
                true, 
                "TCAdminWrapperTest", settings);
            TcAdminClient client = new TcAdminClient(configuration);

            Console.WriteLine("Name: " + new TCAdmin.SDK.Objects.Server(1));
        }

Restarting a service

You can easily restart a service by using the TCAdmin SDK. Grab the service object by creating a new instance using the serviceId constructor and proceed to call the Restart() method.

        public static void Main(string[] args)
        {
            string sqlString = 
                "SQL_STRING_HERE";

            TCAdminClientConfiguration configuration = new TCAdminClientConfiguration(sqlString,
                true,
                "TCAdminWrapperTest", settings);
            TcAdminClient client = new TcAdminClient(configuration);

            Service service = new Service(1);
            Console.WriteLine("Service: " + service.NameNoHtml);
            Console.WriteLine("Restarting service.");
            service.Restart();
            Console.WriteLine("Restarted service.");
        }

Thats all for now! ?

Edited by alexr03
Update repo url
Link to comment
Share on other sites

  • Dennis pinned this topic

Good release. *Releases LYHMEHook* lol 

We have also got up-to-date TCAdmin binaries you can install into your projects using:

nuget install TCAdmin -Source "https://gitlab.com/api/v4/projects/17210103/packages/nuget/index.json"

This is useful as the alternative would be to copy all the files needed from your own installations.

Edited by M0RG4N
Added Words
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Terms of Use