Celin.AIS - Logging

CSharp · Console

/Program.cs

using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;

namespace Celin
{
	public class Program
	{
		public static async Task Main()
		{
			// Create the Logger Factory
			var loggerFactory = LoggerFactory.Create(builder => 
			{
				builder
					// Set logging level to Trace
					.SetMinimumLevel(LogLevel.Trace)
					// Log to the Console
					.AddConsole();
			});
			// Create a Logger for Program
			var logger = loggerFactory.CreateLogger<Program>();
			logger.LogInformation("Starting Program");
			// Initialise the E1 AIS Client with a new Logger for the Celin.AIS.Server class 
			var e1 = new AIS.Server("https://demo.steltix.com/jderest/v2/", loggerFactory.CreateLogger<AIS.Server>());
			// Set Credentials
			e1.AuthRequest.username = "demo";
			e1.AuthRequest.password = "demo";
			try
			{
				// Authenticate
				logger.LogDebug("Authenticate");
				await e1.AuthenticateAsync();
				Console.WriteLine("{0}, Welcome to {1}", e1.AuthResponse.userInfo.alphaName, e1.AuthResponse.environment);
				// Submit Concrete Request and Response
				logger.LogDebug("Submit Request");
				var p01012 = await e1.RequestAsync<W01012B.Response>(new W01012B.Request());
				// Get the Form Parameter, semantics simplicity
				var form = p01012.fs_P01012_W01012B;
				// Output the Form
				Console.WriteLine("{0} ({1})", form.title, p01012.currentApp);
				Console.WriteLine("{0}: {1}", form.data.z_AT1_54.title, form.data.z_AT1_54.value);
				// Output the Grid Rows
				foreach (var row in form.data.gridData.rowset)
				{
					Console.WriteLine("{0,-10} {1}", row.z_AN8_19, row.z_ALPH_20);
				}
				// Sign-out
				logger.LogDebug("Log out!");
				await e1.LogoutAsync();
				Console.WriteLine("Goodbye!");
			}
			catch (Exception ex)
			{
				Console.WriteLine(ex.Message);
			}
		}
	}
	// Namespace for the Work With Addresses Form
	namespace W01012B
	{
		// The Grid Defintion
		public class Row
		{
			// Grid Columns
			public long z_AN8_19 { get; set; }
			public string z_ALPH_20 { get; set; }
		}
		// The Form Defintion
		public class FormData : AIS.FormData<Row>
		{
			// Form Field "Search Type"
			public AIS.FormField<string> z_AT1_54 { get; set; }
		}
		// Form Response
		public class Response : AIS.FormResponse
		{
			// Form Parameter
			public AIS.Form<FormData> fs_P01012_W01012B { get; set; }
		}
		// Form Request
		public class Request : AIS.FormRequest
		{
			public Request()
			{
				// Form name to call
				formName = "P01012_W01012B";
				// Version
				version = "ZJDE0001";
				// Read-only
				formServiceAction = "R";
				// Return Maximum 10 rows
				maxPageSize = "10";
				// Return Form Field 54 and Grid Columns 19 and 20
				returnControlIDs = "54|1[19,20]";
				// Create Form Action
				formActions = new []
				{
					// Set the Search Type to "C"
					new AIS.FormAction { controlID = "54", command = AIS.FormAction.SetControlValue , value = "C" },
					// Press the Find Button
					new AIS.FormAction { controlID = "15", command = AIS.FormAction.DoAction }
				};
			}
		}
	}
}
;