■Webアプリケーションのサンプル
ASP.NETのWebアプリケーションからサーバスクリプトを呼び出すサンプルです。ホストとの接続、キー入力などのサーバスクリプトのメソッドを呼び出す例を記載しています。一時的にエミュレータ画面を表示したり、WSMGRマクロを呼び出すサンプル例も含まれます。
サンプルアプリケーションの画面例

サンプルHTMLの格納先は次のようになります。
<インストール先フォルダ配下>\wwwroot\sample\ServerAPI\ 例) C:\wsmgrweb\wwwroot\sample\ServerAPI\
C#のサンプルHTMLのURLは次のようになります。
<WebサーバのURL>/<仮想ディレクトリ>/sample/ServerAPI/Sample1/cs/Sample1.aspx 例) http://www.example/wsmgrweb/sample/ServerAPI/Sample1/cs/Sample1.aspx
VBのサンプルHTMLのURLは次のようになります。
<WebサーバのURL>/<仮想ディレクトリ>/sample/ServerAPI/Sample1/vb/Sample1.aspx 例) http://www.example/wsmgrweb/sample/ServerAPI/Sample1/vb/Sample1.aspx
サンプルの構成は以下のとおりです。
Webアプリケーションの実装 | Sample1.aspx |
WSMGRマクロ | zaiko.scr |
Webアプリケーションの実装例(C#版Sample1.aspx)
<%@ Page Language="C#" AutoEventWireup="true" ClassName="ScriptSample" %>
<%@ Register TagPrefix="wsmgrweb"
Namespace="Fujitsu.Wsmgrweb.ServerApi"
Assembly="Fujitsu.Wsmgrweb.Emulator, Version=1.0.0.0, PublicKeyToken=43bd721f4ef10ce7, Culture=neutral" %>
<%@ Import Namespace="Fujitsu.Wsmgrweb.ServerApi" %>
<%@ Import Namespace="System.Threading" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>ユーザスクリプトサンプル</title>
<script runat="server">
public delegate void SetLabelDelegate(string text);
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
else
{
}
}
private WsmgrDspemu dspemu = null;
//起動
protected void ButtonConnect_Click(object sender, EventArgs e)
{
try
{
WsmgrConnectInfo info = new WsmgrConnectInfo();
info.User = UserName.Value;
info.Icon = IconName.Value;
info.Pw = Password.Value;
if (info.Init() != 0)
{
SetLabel("WsmgrConnectInfo 認証失敗");
return;
}
dspemu = new WsmgrDspemu(info);
if (dspemu.GetError() == 0)
{
SetLabel("WsmgrDspemu 初期化成功");
}
else
{
SetLabel("WsmgrDspemu 初期化失敗");
info.Uninit();
return;
}
if (dspemu.Session.Connect(1))
{
SetLabel("WsmgrDspemu 接続成功");
}
else
{
SetLabel("WsmgrDspemu 接続失敗");
info.Uninit();
}
SetInfo(Context, info);
SetDspemu(Context, dspemu);
}
catch (Exception ex)
{
SetLabel(string.Format("WsmgrDspemu初期化例外 {0}:{1}", ex.GetType(), ex.Message));
}
}
protected void ButtonDisconnect_Click(object sender, EventArgs e)
{
dspemu = GetDspemu(Context);
try
{
if (dspemu != null)
{
if (dspemu.Session.Disconnect())
{
SetLabel("WsmgrDspemu 切断成功");
string varName = getVarName() + "info";
WsmgrConnectInfo info = GetInfo(Context);
if (info != null)
{
info.Uninit();
SetLabel("WsmgrDspemu Uninit");
}
}
else
{
SetLabel("WsmgrDspemu 切断失敗");
}
}
else
{
SetLabel("WsmgrDspemu = null");
}
}
catch (Exception ex)
{
SetLabel(string.Format("WsmgrDspemu切断例外 {0}:{1}", ex.GetType(), ex.Message));
}
}
// Type
protected void ButtonType_Click(object sender, EventArgs e)
{
dspemu = GetDspemu(Context);
try
{
dspemu.Macro.Type(TypeText.Value);
dspemu.Macro.Wait();
SetTable(dspemu.Screen.ToTable());
}
catch (Exception ex)
{
SetLabel(string.Format("WsmgrDspemu例外 {0}:{1}", ex.GetType(), ex.Message));
}
}
// 画面取得
protected void ButtonGetScreen_Click(object sender, EventArgs e)
{
dspemu = GetDspemu(Context);
try
{
int row1 = int.Parse(ScreenRow1.Value);
int col1 = int.Parse(ScreenCol1.Value);
int row2 = int.Parse(ScreenRow2.Value);
int col2 = int.Parse(ScreenCol2.Value);
SetTable(dspemu.Screen.ToTable(row1, col1, row2, col2));
}
catch (Exception ex)
{
SetLabel(string.Format("WsmgrDspemu例外 {0}:{1}", ex.GetType(), ex.Message));
}
}
// Forward
protected void ButtonForward_Click(object sender, EventArgs e)
{
dspemu = GetDspemu(Context);
try
{
dspemu.Document.Forward(ForwardUrl.Value, Server, Context);
}
catch (Exception ex)
{
SetLabel(string.Format("WsmgrDspemu例外 {0}:{1}", ex.GetType(), ex.Message));
}
}
// ExecMacro
protected void ButtonExecMacro_Click(object sender, EventArgs e)
{
dspemu = GetDspemu(Context);
try
{
if (dspemu != null)
{
if (dspemu.Macro.ExecMacro(MacroName.Value))
SetLabel("ExecMacro 実行成功");
else
SetLabel("ExecMacro 実行失敗");
SetTable(dspemu.Screen.ToTable());
}
else
{
SetLabel("WsmgrDspemu = null");
}
}
catch (Exception ex)
{
SetLabel(string.Format("WsmgrDspemuマクロ実行失敗例外 {0}:{1}", ex.GetType(), ex.Message));
}
}
// ExecMacro2
protected void ButtonExecMacro2_Click(object sender, EventArgs e)
{
dspemu = GetDspemu(Context);
try
{
if (dspemu != null)
{
dspemu.Macro.SetPrivateValue("hostid", "hostid1");
dspemu.Macro.SetPrivateValue("hostpw", "hostpw1");
dspemu.Macro.SetPrivateValue("customer", CustomerName.Value);
if (dspemu.Macro.ExecMacro("zaiko"))
{
// マクロの実行結果を取得
SetLabel("zaiko: error: " + dspemu.Macro.GetPrivateValue("error"));
SetLabel("zaiko: message: " + dspemu.Macro.GetPrivateValue("message"));
String[][] zaiko = (String[][])dspemu.Macro.GetPrivateValue("zaiko");
SetTable(zaiko);
}
}
else
{
SetLabel("WsmgrDspemu = null");
}
}
catch (Exception ex)
{
SetLabel(string.Format("WsmgrDspemuマクロ実行失敗例外 {0}:{1}", ex.GetType(), ex.Message));
}
}
public void SetLabel(string text, bool clear = false)
{
if (clear)
Label1.Text = text + "<br>";
else
Label1.Text += text + "<br>";
}
public void SetTable(string[][] data)
{
foreach (string[] cols in data)
{
TableRow tr = new TableRow();
foreach (string col in cols)
{
TableCell tc = new TableCell();
tc.Text = col;
tr.Cells.Add(tc);
}
Table1.Rows.Add(tr);
}
}
private string getVarName()
{
string varName = string.Format("WsmgrDspemu_{0}_{1}", UserName.Value, IconName.Value);
return varName;
}
public WsmgrConnectInfo GetInfo(HttpContext context)
{
string varName = getVarName() + "_info";
return (WsmgrConnectInfo)context.Session[varName];
}
public void SetInfo(HttpContext context, WsmgrConnectInfo info)
{
string varName = getVarName() + "_info";
context.Session[varName] = info;
}
public WsmgrDspemu GetDspemu(HttpContext context)
{
string varName = getVarName();
return (WsmgrDspemu)context.Session[varName];
}
public void SetDspemu(HttpContext context, WsmgrDspemu dspemu)
{
string varName = getVarName();
context.Session[varName] = dspemu;
}
</script>
<style type="text/css">
.auto-style1
{
width: 100%;
}
.auto-style2
{
height: 23px;
}
</style>
</head>
<body>
<form id="form2" runat="server">
サーバスクリプトサンプル<br />
<br />
WsmgrConnectInfo<table bgcolor="#EEEEEE" class="auto-style1">
<tr>
<td width="25%">ユーザ名</td>
<td width="50%">
<input id="UserName" type="text" value="user1" runat="server" /></td>
<td rowspan="3">
<asp:Button ID="ButtonConnect" runat="server" OnClick="ButtonConnect_Click" Text="Connect" />
<br />
<asp:Button ID="ButtonDisconnect" runat="server"
OnClick="ButtonDisconnect_Click" Text="Disconnect" />
</td>
</tr>
<tr>
<td class="auto-style2" width="25%">パスワード</td>
<td class="auto-style2" width="50%">
<input id="Password" type="text" value="" runat="server" /></td>
</tr>
<tr>
<td width="25%">接続アイコン</td>
<td width="50%">
<input id="IconName" type="text" value="接続" runat="server"/></td>
</tr>
</table>
<br />
Dspemuオブジェクト<table bgcolor="#EEEEEE" class="auto-style1">
<tr>
<td width="25%">入力キー</td>
<td width="50%">
<input id="TypeText" type="text" value="[ENTER]" runat="server" /></td>
<td>
<asp:Button ID="ButtonType0" runat="server" OnClick="ButtonType_Click" Text="Type" />
</td>
</tr>
<tr>
<td width="25%">エミュレータ座標</td>
<td width="50%">
<input id="ScreenRow1" type="text" runat="server" size="2" value="1" /><input
id="ScreenCol1" type="text" runat="server" size="2" value="1" /><input
id="ScreenRow2" type="text" runat="server" size="2" value="24" /><input
id="ScreenCol2" type="text" runat="server" size="2" value="80" /></td>
<td>
<asp:Button ID="ButtonGetScreen0" runat="server" OnClick="ButtonGetScreen_Click" Text="画面取得" />
</td>
</tr>
<tr>
<td width="25%">エミュレータ画面</td>
<td width="50%">
<input id="ForwardUrl" type="text" value="/wsmgrweb/emu/Emulator.aspx" runat="server" /></td>
<td>
<asp:Button ID="ButtonForward" runat="server" OnClick="ButtonForward_Click" Text="Forward" Height="21px" />
</td>
</tr>
<tr>
<td width="25%">マクロ名</td>
<td width="50%">
<input id="MacroName" type="text" value="Macro1" runat="server" /></td>
<td>
<asp:Button ID="ButtonExecMacro" runat="server" OnClick="ButtonExecMacro_Click" Text="ExecMacro" />
</td>
</tr>
</table>
<br />
マクロ連携サンプル<table bgcolor="#EEEEEE" class="auto-style1">
<tr>
<td width="25%">検索顧客名</td>
<td width="50%">
<input id="CustomerName" type="text" value="顧客" runat="server" /></td>
<td>
<asp:Button ID="ButtonExecMacro2" runat="server" OnClick="ButtonExecMacro2_Click" Text="在庫検索" />
</td>
</tr>
</table>
<%--<wsmgrweb:Emulator ID="Emulator1" runat="server" />--%>
<asp:Table ID="Table1" runat="server" BorderStyle="Solid">
</asp:Table>
<br />
状態<asp:Label ID="Label1" runat="server"></asp:Label>
</form>
</body>
</html>WSMGRのマクロ例(zaiko.scr)
PROC MAIN
; 処理結果の格納領域
CrtString(zaiko[][]) ; 在庫情報(2次元配列)
CrtString(message) ; ホスト画面上のメッセージ
CrtInt(error, 0) ; マクロ実行結果
; スクリプトから渡された情報
CrtString(hostid) ; ホストログオンID
CrtString(hostpw) ; ホストログオンパスワード
CrtString(customer) ; 検索対象の顧客名
PutValue(hostid, GetPrivateValue("hostid"))
PutValue(hostpw, GetPrivateValue("hostpw"))
PutValue(customer, GetPrivateValue("customer"))
; キーアンロックタイムの調整(ログオンするまでは長めに設定)
SetKeyUnlockTime(0, 200)
; ログオン処理
Wait("SYSTEM READY")
CrtString(str)
PutValue(str, "LOGON AIM,,PROC1,")
PutValue(str, Att(str, hostid))
PutValue(str, Att(str, ","))
PutValue(str, Att(str, hostpw))
PutValue(str, Att(str, "[ENTER]"))
Type(str);
Wait("*** 業務メニュー ***")
IF(Large(GetError(), 0)
; ログオンエラー時の処理
PutValue(error, GetError()) ; エラー番号
PutValue(message, GetString(22, 1, 22, 80)) ; ホスト画面上のエラーメッセージ
GOTO(EXIT1)
ENDIF
; キーアンロックタイムを調整(ログオン成功後は短く調整)
SetKeyUnlockTime(0, 10)
; メニュー番号の入力
Type("2[ENTER]")
Wait("*** 検索条件 ***")
PutValue(str, customer)
PutValue(str, Att(str, "[ENTER]"))
Type(str);
Wait("*** 在庫照会 ***");
CrtString(totalPage) ; すべてのページ数
CrtString(currentPage) ; 現在のページ番号
PutValue(totalPage, GetString(21, 72, 21, 72))
WHILE(TRUE)
CrtString(work[][])
PutValue(work, GetTable(8, 11, 19, 71))
AppendArray(zaiko, work)
; 終了ページまで繰り返す
PutValue(currentPage, GetString(21, 69, 21, 69))
IF(Equ(totalPage, currentPage))
Type("[PF12]" ; 終了
PutValue(message, "検索正常終了")
BREAKWHILE
ELSEIF
Type("[PF7]") ; 次ページへ
ENDIF
ENDWHILE
EXIT1:
;スクリプトへ処理結果を返却
SetPrivateValue("zaiko", zaiko)
SetPrivateValue("message", message)
SetPrivateValue("error", error)
ENDPROC