Following are two code examples for a Host Responder class in C# and Perl.
Example 1 C# code for a DBOverwrite Responder
The following code example shows how to code a Responder class as part of a C# Console Application project:
// Copyright © 2002 Unisys Corporation. All rights reserved. UNISYS CONFIDENTIAL
// It contains two examples to check for the host prompts to confirm overwriting
// the database (auto-response set to YES) and reorganizing the database (auto-response set to NO).
using System;
using System.Text.RegularExpressions;
namespace SampleResponder
{
/// <summary>
/// Summary description for SampleResponderClass.
/// </summary>
public class SampleResponderClass
{
/// <summary>
/// Main method reads log entries from standard input.
/// If it finds any of interest it writes a response to Standard Output.
//<DB name> CONTROL FILE IN USE -- WHEN DB CLOSED,ENTER OK
//Regex DBExistsPattern = new Regex(CONTROL FILE IN USE -- WHEN DB CLOSED,ENTER OK);
// Other messages to process...
// ** WHEN DATABASE CLOSED , ENTER <MIX> OK
// POP. OPTIONS WARNING - SEE CFG REPORT MIX
/// </summary>
[STAThread]
static void Main(string[] args)
{
// Create regular expressions for the following two host queries.
// Also create the regular expressions for the valid reply patterns
// for these two host queries.
//
// 14:57:20 *** DATABASE ALREADY EXISTS, TO OVERWRITE ENTER AX YES ELSE NO.
// 14:57:20 Valid Reply: 5903 & one of AX {reply option},DS
//
// NOTE: The \\* is simply a * because the star char is a Regexp special char
// See the MS documentation on Regex class.
Regex DBExistsPattern = new Regex( \\*\\*\\* DATABASE ALREADY EXISTS, TO OVERWRITE ENTER AX YES
ELSE NO);
// Note: the brackets () below indicate groups we want to extract from the text
Regex ValidDBExistsReplyPattern = new Regex( Valid Reply: ([0-9]*) & one of AX {reply option},DS );
Regex DBReorgPattern = new Regex(\\*\\* DO YOU WISH TO RESTART THIS REORG,AX YES OR NO \\*);
Regex ValidDBReorgReplyPattern = new Regex( Valid Reply: ([0-9]*) & one of AX {reply option},DS );
bool DBExistQuestionMatch = false;
bool DBReorgQuestionMatch = false;
// YOU CAN EDIT HERE --> Initialize a boolean variable to indicate if
// the message list consists the host query of interest.
// bool HostQueryQuestionMatch = false;
String sMsg = System.Console.ReadLine();
// For each of the log lines check against the pattern(s) of interest
while ( sMsg != null )
{
// Did we match the DB Exists Pattern?
Match m = DBExistsPattern.Match( sMsg );
if ( m.Success )
{
DBExistQuestionMatch = true;
}
// Did we match the Valid Reply Pattern?
m = ValidDBExistsReplyPattern.Match( sMsg );
if ( m.Success )
{
if ( DBExistQuestionMatch )
{
// Write response to standard output
System.Console.WriteLine(m.Groups[1].ToString() + AX YES);
}
}
// Did we match the DB Reorg pattern?
m = DBReorgPattern.Match( sMsg );
if ( m.Success )
{
DBReorgQuestionMatch = true;
}
// Did we match the Valid Reply Pattern?
m = ValidDBReorgReplyPattern.Match( sMsg );
if ( m.Success )
{
if ( DBReorgQuestionMatch )
{
// Write response to standard output
System.Console.WriteLine( m.Groups[1].ToString() + AX NO );
}
}
// read the next line from Standard Input
sMsg = System.Console.ReadLine();
}
// If we didn't detect a response then return nothing allow manual response
}
}
} Example 2 Perl Code for a Host Responder
Here is similar code written as a Perl script:
# This is a perl overwrite responder for the MCP host build
# Read the log information from the host via STDIN – the standard input
my(@LogLines) = <STDIN>;
my($FoundDBExists) = 0;
my($LogLine) = ;
# Loop through the lines and match on loglines of interest...
foreach $LogLine ( @LogLines )
{
# scan for DB exists message
if( $LogLine =~ /\*\*\* DATABASE ALREADY EXISTS, TO OVERWRITE ENTER AX YES ELSE NO/ )
{
$FoundDBExists = 1;
next;
}
if( $FoundDBExists )
{
if( $LogLine =~ /Valid Reply: ([0-9]*) & one of AX \{reply option\},DS/)
{
print $1 AX YES; # write response to STDOUT
exit(0); # done!
}
}
}
# No Response
print ;