Celin.AIS - Start with Sessions

CSharp · Console

/Program.cs

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

namespace Celin
{
	public class Program
	{
		public static async Task Main()
		{
			// Set up the logging Infrastructure
            var loggerFactory = LoggerFactory.Create(builder =>
            {
                builder
                    .SetMinimumLevel(LogLevel.Error)
                    .AddConsole();
            });
            var logger = loggerFactory.CreateLogger<Program>();
            logger.LogInformation("Start program...");

			// Initialise the E1 AIS Client
            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
				await e1.AuthenticateAsync();
				Console.WriteLine("{0}, Welcome to {1}", e1.AuthResponse.userInfo.alphaName, e1.AuthResponse.environment);
				// Submit 'Work With Addresses' as StackFormRequest
				var w01012b = await e1.RequestAsync<W01012B.Response>(
					new AIS.StackFormRequest
					{
						// We are opening a new form
						action = AIS.StackFormRequest.open,
						// the form to open
						formRequest = new W01012B.Request
						{
							// Look up AN8 2006 using a query
							query = new AIS.Query
							{
								// AND Query
								matchType = AIS.Query.MATCH_ALL,
								// Autofind
								autoFind = true,
								// Set Query Conditions
								condition = new []
								{
									new AIS.Condition
									{
										// Grid Control Id for AN8
										controlId = "1.19",
										@operator = AIS.Condition.EQUAL,
										value = new []
										{
											new AIS.Value
											{
												content = "2006",
												specialValueId = AIS.Value.LITERAL
											}
										}
									}
								}
							}
						}
					});
				// Get the Form Parameter, semantics simplicity
				var form = w01012b.fs_P01012_W01012B;
				// Output the Form
				Console.WriteLine("{0} ({1})", form.title, w01012b.currentApp);
				Console.WriteLine("Returned {0} row(s)", form.data.gridData.summary.records);
				// Output the Grid Row
				foreach (var row in form.data.gridData.rowset)
				{
					Console.WriteLine("{0,-10} {1}", row.z_AN8_19, row.z_ALPH_20);
					// Now select the Row
					var w01012a = await e1.RequestAsync<W01012A.Response>(
						new AIS.StackFormRequest
						{
							// We are executing an existing open form
							action = AIS.StackFormRequest.execute,
							// We need to pass in the session parameters
							// from the previous call
							stackId = w01012b.stackId,
							stateId = w01012b.stateId,
							rid = w01012b.rid,
							// And the action request
							actionRequest = new AIS.ActionRequest
							{
								// The form making the Request
								formOID = "W01012B",
								formActions = new []
								{
									new AIS.FormAction
									{
										// The Grid ID and Zero-Index Row#
										controlID = "1.0",
										command = AIS.FormAction.SelectRow,
									},
									new AIS.FormAction
									{
										// The Select/OK button
										controlID = "14",
										command = AIS.FormAction.DoAction
									}
								}
							}
						});
					// Write out some details
					var data = w01012a.fs_P01012_W01012A.data;
					Console.WriteLine("{0} ({1})", w01012a.fs_P01012_W01012A.title, w01012a.currentApp);
					Console.WriteLine("{0} {1} {2}", data.z_AN8_21.value, data.z_AT1_36.value, data.z_ALPH_28.value);
					Console.WriteLine("{0} {1}", data.z_ADD1_40.value, data.z_ADD2_42.value);
					
					// Close the Form (press the Cancel button)
					w01012b = await e1.RequestAsync<W01012B.Response>(
						new AIS.StackFormRequest
						{
							action = AIS.StackFormRequest.execute,
							// Parameters from last call
							stackId = w01012a.stackId,
							stateId = w01012a.stateId,
							rid = w01012a.rid,
							actionRequest = new AIS.ActionRequest
							{
								formOID = "W01012A",
								formActions = new []
								{
									new AIS.FormAction
									{
										controlID = "12",
										command = AIS.FormAction.DoAction
									}
								}
							}
						});
					// Check out the returned Form
					Console.WriteLine("Back to: {0} ({1})", w01012b.fs_P01012_W01012B.title, w01012b.currentApp);
					
					// Finally close the Session
					var close = await e1.RequestAsync<AIS.FormResponse>(
						new AIS.StackFormRequest
						{
							action = AIS.StackFormRequest.close,
							stackId = w01012b.stackId,
							stateId = w01012b.stateId,
							rid = w01012b.rid
						});
					// The return should have blank session parameters
					Console.WriteLine("StackId: {0}, StateId: {1}, Rid: {2}", close.stackId, close.stateId, close.rid);
					
					// Break out of the foreach statement, just in case
					break;
				}
				// Sign-out
				await e1.LogoutAsync();
				Console.WriteLine("Goodbye!");
			}
			catch (Exception ex)
			{
				logger.LogCritical(ex, "Ooobs, some bad shite happened!!");
			}
		}
	}
	// 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]";
			}
		}
	}
	// Namespace for the Address Fix Inspect Form
	namespace W01012A
	{
		public class FormData : AIS.FormData<AIS.Row>
		{
			public AIS.FormField<string> z_AC20_411 { get; set; }
			public AIS.FormField<string> z_EXCHG_300 { get; set; }
			public AIS.FormField<string> z_YEARSTAR_303 { get; set; }
			public AIS.FormField<string> z_REVRNG_305 { get; set; }
			public AIS.FormField<string> z_AC17_402 { get; set; }
			public AIS.FormField<string> z_AC18_405 { get; set; }
			public AIS.FormField<string> z_AC19_408 { get; set; }
			public AIS.FormField<string> z_TICKER_298 { get; set; }
			public AIS.FormField<string> z_ALPH_28 { get; set; }
			public AIS.FormField<int> z_AN8_21 { get; set; }
			public AIS.FormField<string> z_MLNM_38 { get; set; }
			public AIS.FormField<string> z_AT1_36 { get; set; }
			public AIS.FormField<string> z_TAX_34 { get; set; }
			public AIS.FormField<string> z_CLASS01_284 { get; set; }
			public AIS.FormField<string> z_AC15_396 { get; set; }
			public AIS.FormField<string> z_AC16_399 { get; set; }
			public AIS.FormField<string> z_ALKY_32 { get; set; }
			public AIS.FormField<string> z_ADD4_46 { get; set; }
			public AIS.FormField<string> z_CLASS04_290 { get; set; }
			public AIS.FormField<string> z_CLASS05_292 { get; set; }
			public AIS.FormField<string> z_CLASS03_286 { get; set; }
			public AIS.FormField<string> z_CLASS02_288 { get; set; }
			public AIS.FormField<string> z_ADD3_44 { get; set; }
			public AIS.FormField<string> z_ADD2_42 { get; set; }
			public AIS.FormField<string> z_ADD1_40 { get; set; }
			public AIS.FormField<string> z_COUN_58 { get; set; }
			public AIS.FormField<string> z_CTR_56 { get; set; }
			public AIS.FormField<string> z_AC10_381 { get; set; }
			public AIS.FormField<string> z_CM_140 { get; set; }
			public AIS.FormField<string> z_SBLI_132 { get; set; }
			public AIS.FormField<string> z_AC08_375 { get; set; }
			public AIS.FormField<string> z_TAXC_134 { get; set; }
			public AIS.FormField<string> z_SIC_136 { get; set; }
			public AIS.FormField<string> z_AC09_378 { get; set; }
			public AIS.FormField<string> z_LNGP_138 { get; set; }
			public AIS.FormField<string> z_ADDS_54 { get; set; }
			public AIS.FormField<string> z_CTY1_52 { get; set; }
			public AIS.FormField<string> z_ADDZ_50 { get; set; }
			public AIS.FormField<string> z_ATR_67 { get; set; }
			public AIS.FormField<string> z_AC13_390 { get; set; }
			public AIS.FormField<string> z_AC14_393 { get; set; }
			public AIS.FormField<string> z_AC11_384 { get; set; }
			public AIS.FormField<string> z_AC12_387 { get; set; }
			public AIS.FormField<string> z_TX2_146 { get; set; }
			public AIS.FormField<string> z_TXCT_148 { get; set; }
			public AIS.FormField<string> z_ATP_64 { get; set; }
			public AIS.FormField<string> z_MCU_62 { get; set; }
			public AIS.FormField<string> z_AC03_360 { get; set; }
			public AIS.FormField<string> z_AC27_481 { get; set; }
			public AIS.FormField<string> z_AC24_472 { get; set; }
			public AIS.FormField<string> z_AC01_354 { get; set; }
			public AIS.FormField<string> z_AC25_475 { get; set; }
			public AIS.FormField<string> z_AC02_356 { get; set; }
			public AIS.FormField<string> z_AC26_478 { get; set; }
			public AIS.FormField<string> z_AC30_490 { get; set; }
			public AIS.FormField<char> z_ATPR_130 { get; set; }
			public AIS.FormField<char> z_AT3_251 { get; set; }
			public AIS.FormField<string> z_AC07_372 { get; set; }
			public AIS.FormField<string> z_AC04_363 { get; set; }
			public AIS.FormField<string> z_AC28_484 { get; set; }
			public AIS.FormField<string> z_AC05_366 { get; set; }
			public AIS.FormField<string> z_AC29_487 { get; set; }
			public AIS.FormField<string> z_AC06_369 { get; set; }
			public AIS.FormField<char> z_ATE_129 { get; set; }
			public AIS.FormField<int> z_AN86_330 { get; set; }
			public AIS.FormField<string> z_DUNS01_456 { get; set; }
			public AIS.FormField<string> z_DUNS02_457 { get; set; }
			public AIS.FormField<string> z_DUNS03_458 { get; set; }
			public AIS.FormField<string> z_AC21_463 { get; set; }
			public AIS.FormField<string> z_AC22_466 { get; set; }
			public AIS.FormField<string> z_AC23_469 { get; set; }
			public AIS.FormField<int> z_GROWTHR_311 { get; set; }
			public AIS.FormField<int> z_NOE_313 { get; set; }
			public AIS.FormField<string> z_AEMPGP_316 { get; set; }
			public AIS.FormField<int> z_PA8_318 { get; set; }
			public AIS.FormField<int> z_AN82_320 { get; set; }
			public AIS.FormField<int> z_AN81_322 { get; set; }
			public AIS.FormField<char> z_AT2_444 { get; set; }
			public AIS.FormField<int> z_AN83_324 { get; set; }
			public AIS.FormField<int> z_AN84_326 { get; set; }
			public AIS.FormField<int> z_AN85_328 { get; set; }
		}
		// Form Response
		public class Response : AIS.FormResponse
		{
			// Form Parameter
			public AIS.Form<FormData> fs_P01012_W01012A { get; set; }
		}
	}
}
;