TBC.Extensions.Auxiliary 1.2.0

dotnet add package TBC.Extensions.Auxiliary --version 1.2.0                
NuGet\Install-Package TBC.Extensions.Auxiliary -Version 1.2.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TBC.Extensions.Auxiliary" Version="1.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TBC.Extensions.Auxiliary --version 1.2.0                
#r "nuget: TBC.Extensions.Auxiliary, 1.2.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TBC.Extensions.Auxiliary as a Cake Addin
#addin nuget:?package=TBC.Extensions.Auxiliary&version=1.2.0

// Install TBC.Extensions.Auxiliary as a Cake Tool
#tool nuget:?package=TBC.Extensions.Auxiliary&version=1.2.0                

📚 Auxiliary

Auxiliary is a tool for Terraria servers to make database interaction, configuration management, packet handling, events & logging much easier for plugin developers.

⚙️ Configuration

Auxiliary has a static handler for configuration that integrates into the default tshock design without added effort. It is incredibly straight forward to implement.

🏗️ Building your configurations

Defining the settings
public class PluginSettings : ISettings
{
  [JsonPropertyName("mysettingvalue")]
  public string Value { get; set; }
}

You can populate as many values as you wish, and the following step will automatically handle the creation and reading of the file.

Reading the settings
public override void Initialize()
{
  Configuration<PluginSettings>.Load(nameof(Plugin));

  GeneralHooks.ReloadEvent += (x) =>
  {
    Configuration<PluginSettings>.Load(nameof(Plugin));
    x.Player.SendSuccessMessage("[Plugin] Reloaded configuration.");
  };
}

By adding the following code in your initialize method, it will automatically load the configuration for use, and the ability to reload configuration at runtime. Call the Loaded property to ensure the configuration is loaded if you plan to access it in events you are not sure run before initialize or not.

Using the settings
var value = Configuration<PluginSettings>.Settings.Value;

♻️ Auxiliaries own configuration

Auxiliary has its own auto generated configuration file it needs to connect to the database and define a path for both mongodb and the local file system to write to.

{
  "connectionstring": "",
  "mongopath": "",
  "localpath": ""
}
  • connectionstring is the value used to connect to the database. This has to be a mongodb:// prefixed string.
  • mongopath represents the database name used after connecting to the database.
  • localpath is the local relative path to the execution environment Auxiliary is allowed to use to read and write json.

📑 Data Models

🗃️ Json

Json integrates in a file pattern, keeping a file reference and reading/writing to it actively during model modification. These models can be used for smaller data storage, for example for keeping data for specific actions.

A Json model:
public class PluginValue : JsonModel
{
  private int _value;
  public int Value 
  {
    get
      => _value;
    set
    {
      _value = value;
      _ = this.SaveAsync();
    }
}

By allowing the getter to save the model after modifying its underlying field, it will be able to dynamically save on all edits, eliminating the need for self written SaveAsync implementations. This design should not persist on models that are concurrently operated on, as it will cause concurrency errors. If models are frequently modified, the Bson design should be preferred.

Fetching our model:
var guaranteedModel = await IModel.GetAsync(GetRequest.Json<PluginValue>(x => x.Value == 1), x => x.Value = 1);

var nullIfNotFound = await IModel.GetAsync(GetRequest.Json<PluginValue>(x => x.Value == 1));

The guaranteedModel writes to a property called creationAction. If this property is populated at the moment you make a get request, it will automatically create a new PluginValue with the provided values, push it into the local file, and return it.

The nullIfNotFound keeps the creationAction empty. If Auxiliary does not see a creation action present, it will ignore creation patterns and return null if the model cannot be found in the local file.

Creating a model:

If you prefer to create a model without the getter design, it is possible to do so through the CreateAsync member.

var createdModel = await IModel.CreateAsync(CreateRequest.Json<PluginValue>(x => x.Value = 2));

🗄️ Bson

MongoDB integrates seamlessly into Auxiliary, offering a mutual design to json models. Only this time, we use a different reference to fetch and create models.

A Bson model:
public class PluginUser : BsonModel 
{

  private string _name = string.Empty;
  public string Name
  {
    get
      => _name;   
    set
    {
      _ = this.SaveAsync(x => x.Name, value);
      _name = value;
    }
  }
}

Every time the setter of this object is called, it makes an atomic call to the database and updates the value in the database model. Because of this, data can be concurrently handled and run effortlessly in async context. All state handling is done in the background.

Fetching our model:
var guaranteedModel = await IModel.GetAsync(GetRequest.Bson<PluginUser>(x => x.Name == "name"), x => x.Name = "name");

var nullIfNotFound = await IModel.GetAsync(GetRequest.Bson<PluginUser>(x => x.Name == "name"));
Creating new models:
var createdModel = await IModel.CreateAsync(CreateRequest.Bson<PluginUser>(x => x.Name = "silly goose"));
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on TBC.Extensions.Auxiliary:

Package Downloads
Banker

Package Description

Appointer

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.0 634 2/12/2023
1.1.4 246 2/12/2023
1.1.3 294 2/8/2023
1.1.2 259 2/7/2023
1.1.1 256 2/7/2023
1.1.0 256 2/7/2023
1.0.0 472 12/15/2022

Version 1.2; Made for Terraria.