TheTechIdea OilGas - Developer guide User guide →

Extending

A custom track

Derive from WellTrack, give it a stable type key and save its own payload. It then lays out, prints, validates and round-trips like a built-in track.

/// <summary>A customer track: annulus pressure readings by depth, saved with the document like any built-in track.</summary>
[WellTrackType("acme.annulus-pressure")]
public sealed class AnnulusPressureTrack : WellTrack
{
    public override string TypeKey => "acme.annulus-pressure";
    public List<(float depth, float psi)> Readings { get; } = new List<(float depth, float psi)>();

    public override void DrawContent(SKCanvas canvas, WellTrackContext context)
    {
        using var dot = new SKPaint { IsAntialias = true, Color = EnvironmentBridge.Status("AboveMawop", new SKColor(210, 120, 0)) };   // colours from the environment
        foreach (var (depth, psi) in Readings)
            canvas.DrawCircle(context.Layout.PlotBounds.Left + psi / 20f, context.Mapper.ToY(depth), 3f, dot);
    }

    public override System.Text.Json.Nodes.JsonObject SavePayload()
    {
        var arr = new System.Text.Json.Nodes.JsonArray();
        foreach (var (d, p) in Readings) arr.Add(new System.Text.Json.Nodes.JsonArray(d, p));
        return new System.Text.Json.Nodes.JsonObject { ["readings"] = arr };
    }

    public override void LoadPayload(System.Text.Json.Nodes.JsonObject? payload)
    {
        Readings.Clear();
        if (payload?["readings"] is System.Text.Json.Nodes.JsonArray arr)
            foreach (var r in arr.OfType<System.Text.Json.Nodes.JsonArray>()) Readings.Add((r[0]!.GetValue<float>(), r[1]!.GetValue<float>()));
    }
}

A custom data source and a custom contract

Any database becomes a source by answering table queries (ITabularSource); a mapping profile maps its columns. Any contract can be implemented directly - here a company code table as the vocabulary.

/// <summary>Any database as a source: answer table queries with rows; a mapping profile maps the columns.</summary>
public sealed class InMemoryDatabase : ITabularSource
{
    public Dictionary<string, List<DataRow>> Tables { get; } = new Dictionary<string, List<DataRow>>(StringComparer.OrdinalIgnoreCase);

    public Task<IReadOnlyList<DataRow>> QueryAsync(string table, IReadOnlyDictionary<string, object?> equals, CancellationToken cancellationToken = default)
    {
        IReadOnlyList<DataRow> rows = Tables.TryGetValue(table, out var t)
            ? t.Where(r => equals.All(kv => string.Equals(r.TryGetValue(kv.Key, out var v) ? v?.ToString() : null, kv.Value?.ToString(), StringComparison.OrdinalIgnoreCase))).ToList()
            : new List<DataRow>();
        return Task.FromResult(rows);
    }
}

/// <summary>A vocabulary backed by a company code table (database, service, ...): implement one method.</summary>
public sealed class CompanyCodeTable : ICodeVocabulary
{
    private readonly Dictionary<(string, string), string> _codes = new Dictionary<(string, string), string>();
    public CompanyCodeTable Add(string domain, string code, string canonical) { _codes[(domain, code.ToUpperInvariant())] = canonical; return this; }
    public string? ToCanonical(string domain, string? sourceCode) =>
        sourceCode != null && _codes.TryGetValue((domain, sourceCode.ToUpperInvariant()), out var c) ? c : null;
}

Using them

// Register the custom track (or WellTrackRegistry.RegisterAssembly(typeof(AnnulusPressureTrack).Assembly)).
WellTrackRegistry.Register("acme.annulus-pressure", () => new AnnulusPressureTrack());
var view = new WellboreDocument();
var track = new AnnulusPressureTrack(); track.Readings.Add((500, 1200)); view.Tracks.Add(track);
var reloaded = WellboreDocument.FromJson(view.ToJson());                              // round-trips like built-in tracks

// A database source + the company code table as the environment's vocabulary.
var db = new InMemoryDatabase();
db.Tables["wells"] = new List<DataRow> { new DataRow { ["well_id"] = "DB-1", ["name"] = "Database well", ["depth_unit"] = "ft" } };
db.Tables["strings"] = new List<DataRow> { new DataRow { ["well_id"] = "DB-1", ["string_id"] = "S1", ["kind"] = "PROD CSG", ["name"] = "9-5/8in", ["top"] = 0, ["bottom"] = 9000, ["depth_unit"] = "ft" } };
var services = new WellboreServices { Vocabulary = new CompanyCodeTable().Add(VocabularyDomains.StringKind, "PROD CSG", "Production") };
using (WellboreServices.Scope(services))
{
    var model = (await new MappedWellDataProvider(db, MappingProfile.Load("csv")).LoadWellAsync("DB-1")).Model;
    Console.WriteLine($"{model.Header.Name}: {model.Strings[0].Kind}");

Other extension points

Extension How
Track type discovery [WellTrackType] + WellTrackRegistry.RegisterAssembly(assembly) or Register(key, factory)
Leak-path network build a LeakPathNetwork (cavities + barrier-element links) and pass it to LeakPathTemplates.Analyze(doc, network) or LeakPathTrack.Network; P&A checks: AbandonmentCheck.Analyze(doc) / AbandonmentTrack
Barrier templates build a WellBarrierSet, or start from BarrierTemplates.ProductionWell, InjectionWell, DrillingWell, WorkoverWell or PermanentAbandonment; LeakPathTemplates.ForSet(set) picks the matching network
Live transport implement IGrowingLogSource (or wrap your store call with WitsmlGrowingLogSource)
Symbols and lithologies environment resources.componentSymbolsFile, resources.symbolCatalogFile, resources.lithologyFile