Here is a full example that demonstrates all options
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using FSCProLib;
namespace FVMacros
{
public class TestServerMacro: ServerMacro
{
public override string description
{
get
{
return "Will Logon with full prompting";
}
}
public override string name
{
get
{
return "NiceLogon";
}
}
public override string runFromScreenID
{
get
{
return "Start";
}
}
/// <summary>
/// Required constructor calling the base ServerMacro class with the MacroHost object
/// </summary>
/// <param name="host">The MacroHost class manages the interface between FVTerm and Server macros</param>
public TestServerMacro(MacroHost host):base(host)
{
}
/// <summary>
/// Required constructor to enable enumeration of available macros and their properties
/// </summary>
public TestServerMacro()
{
}
public override MacroRunResult run()
{
OrderedDictionary options = new OrderedDictionary();
options.Add("msg", "Simple MessageBox Sample");
options.Add("prompt", "Prompt for Logon Password Sample");
options.Add("parms", "Prompt for full Logon Information Sample");
options.Add("files", "Test File Send/Receive");
this.parms = new MacroParms("Server Macro Samples",
"Please Select a Sample for Logging On Insure SimHost",
new MacroParm[]
{
new MacroParm("Sample","opt","msg","Select the Sample to Run",
FVInpEnum.radioButtons, options)
});
MacroDialogRC rc = this.ClientParms(MacroButtons.ok | MacroButtons.cancel, MacroMessageType.question);
if (rc == MacroDialogRC.ok)
{
switch(parms["opt"].text)
{
case "msg":
return this.runMessageBox();
case "prompt":
return this.runPrompt();
case "parms":
return this.runParms();
case "files":
return this.runFileTest();
default:
this.ClientMessageBox("The selected Radio Button is unknown! ("
+ parms["opt"].text + ")",
"Unknown Selection", MacroMessageType.error);
break;
}
}
return MacroRunResult.error;
}
public MacroRunResult runMessageBox()
{
MacroDialogRC rc = this.ClientMessageBox("Would you like me to Logon?", "Sample Logon",
MacroMessageType.info, MacroButtons.yes | MacroButtons.no | MacroButtons.cancel);
if (rc == MacroDialogRC.yes)
{
this.oScreen.putCommand("simmy[enter]", 2000);
this.oScreen.putCommand("2[enter]", 2000);
this.oScreen.putCommand("simmy[tab]host[enter]", 2000);
this.oScreen.putCommand("[clear]", 1000);
this.oScreen.putCommand("info[enter]");
}
return MacroRunResult.ok;
}
public MacroRunResult runPrompt()
{
string pw = null;
MacroDialogRC rc = this.ClientPrompt("Insure System Password: ", ref pw, "The password to signon with...",
"Signon Password Entry", FVInpEnum.password, MacroMessageType.question,
MacroButtons.ok | MacroButtons.cancel);
if (rc == MacroDialogRC.ok)
{
this.oScreen.putCommand("simmy[enter]", 2000);
this.oScreen.putCommand("2[enter]", 2000);
this.oScreen.putCommand("simmy[tab]"+pw+"[enter]", 2000);
// Only continue if password advanced the screen successfully
if (oScreen.getText(1,1,3)=="DFH")
{
this.oScreen.putCommand("[clear]", 1000);
this.oScreen.putCommand("info[enter]");
}
}
return MacroRunResult.ok;
}
public override MacroRunResult runParms()
{
OrderedDictionary options = new OrderedDictionary();
options.Add("stop", "Stop after signing On to View Signon Message");
options.Add("go", "Complete all Initial Screens");
this.parms = new MacroParms("Logon Parameters", "Please Enter your UserID and Password",
new MacroParm[]
{
new MacroParm("UserID","uid","Simmy","Enter the UserID"),
new MacroParm("Password","pw",null,"Enter the Password-hint: host",FVInpEnum.password)
new MacroParm("Options","opt","stop",
"Select how far the logic runs",FVInpEnum.radioButtons,options),
new MacroParm("End Message","msg","false","Display Message at End", FVInpEnum.checkbox)
});
MacroDialogRC rc = this.ClientParms(MacroButtons.ok | MacroButtons.cancel, MacroMessageType.info);
if (rc == MacroDialogRC.ok)
{
this.oScreen.putCommand(parms["uid"].text+"[enter]", 2000);
this.oScreen.putCommand("2[enter]", 2000);
this.oScreen.putCommand(parms["uid"].text+"[tab]"+parms["pw"].text+"[enter]", 2000);
if (oScreen.getText(1,1,3)=="DFH")
{
this.oScreen.putCommand("[clear]", 1000);
this.oScreen.putCommand("info[enter]");
}
}
if (parms["msg"].text == "true")
this.ClientMessageBox("The Parameter-based Logon Server Macro has completed...", "Macro Completed");
return MacroRunResult.ok;
}
public MacroRunResult runFileTest()
{
string fileName = "Test.txt";
bool ok = this.GetClientFile(fileName, "Please upload the Text File", "Text Input Upload", false);
if (ok)
{
if (File.Exists(this.xferReceiveFile))
{
this.ClientMessageBox("File \"" + this.xferReceiveFile
+ "\" was uploaded OK!!!", "File " + this.xferReceiveName
+ " Upload Complete", MacroMessageType.info, MacroButtons.ok);
using (StreamWriter sw = new StreamWriter(this.xferReceiveFile, true))
{
sw.WriteLine("New Line " + DateTime.Now.ToLongDateString() + "-"
+ DateTime.Now.ToLongTimeString());
}
MacroDialogRC rc = this.PutClientFile(this.xferReceiveFile,
"The File has been sent back to you--did you download it OK?",
"File Updated and Returned", MacroMessageType.question,
MacroButtons.yes | MacroButtons.no);
if (rc == MacroDialogRC.yes)
this.ClientMessageBox("That's great, thanks for trusting the file appending service!",
"Good News", MacroMessageType.info, MacroButtons.ok);
else
this.ClientMessageBox("Sorry you were unable to trust the file appending service!",
"BAD News", MacroMessageType.info, MacroButtons.ok);
}
else
this.ClientMessageBox("File \"" + this.xferReceiveFile + "\" was NOT FOUND!!!", "File "
+ this.xferReceiveName + " Upload Failed", MacroMessageType.error, MacroButtons.ok);
}
else
this.ClientMessageBox("File upload failed or was cancelled!!!",
"File " + fileName + " Upload Failed", MacroMessageType.error, MacroButtons.ok);
return MacroRunResult.ok;
}
}
}