CSharp · Console
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
namespace Celin
{
// Attachment DSTR as class name
class ABGT
{
// Factory Method accepts the AN8 and optional sequence
public static T Create<T>(int an8, int seq = 0)
// The Generic must be type MoRequest,
// and we want to create a new instance
where T : AIS.MoRequest, new()
=> new T
{
// Use class name for DSTR
moStructure = nameof(ABGT),
formName = "FIDDLE",
// The Key is passed in as an array of strings
moKey = new string[] { an8.ToString() },
sequence = seq
};
}
class Program
{
static async Task Main(string[] args)
{
var loggerFactory = LoggerFactory.Create(builder =>
{
builder
.SetMinimumLevel(LogLevel.Error)
.AddConsole();
});
var logger = loggerFactory.CreateLogger<Program>();
logger.LogInformation("Start program...");
var e1 = new AIS.Server("https://demo.steltix.com/jderest/v2/", loggerFactory.CreateLogger<AIS.Server>());
e1.AuthRequest.username = "demo";
e1.AuthRequest.password = "demo";
try
{
// Add an attachment for AN8 4242
var gtAdd = ABGT.Create<AIS.MoAddText>(4242);
// We used the Factory method to create a MoAddText request
gtAdd.inputText = "Some attachment text...";
var rs = await e1.RequestAsync(gtAdd);
// Store the sequence# of the Attachment
var seq = rs.sequence;
// Get the text
var gtGet = ABGT.Create<AIS.MoGetText>(4242, seq);
// We used the same Factory method to create a MoGetText request
rs = await e1.RequestAsync(gtGet);
Console.WriteLine("AFTER ADD:\n{0}", rs.text);
// Let's add some text
var gtEdit = ABGT.Create<AIS.MoUpdateText>(4242, seq);
// And the same Factory method used to create a MoAddText request
// Flag the text for append
gtEdit.appendText = true;
gtEdit.inputText = "Something more to say...";
_ = await e1.RequestAsync(gtEdit);
// Check the text again
rs = await e1.RequestAsync(gtGet);
Console.WriteLine("AFTER UPDATE:\n{0}", rs.text);
// Delete the attachment
var gtDel = ABGT.Create<AIS.MoDelete>(4242, seq);
// And finally, the same Factory method used to create the MoDelete request
_ = await e1.RequestAsync(gtDel);
// Check after delete
rs = await e1.RequestAsync(gtGet);
Console.WriteLine("AFTER DEL:\n{0}", rs.error);
}
catch (Exception ex)
{
logger.LogCritical(ex, "Something bad happened!");
}
await e1.LogoutAsync();
logger.LogInformation("Program end!");
}
}
}