1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

プリザンターのサーバスクリプトのcontext.Conditionを見てみる

Posted at

はじめに

プリザンターの機能で1つであるサーバスクリプト。この機能の中でユーザIDやサイトIDなどの環境にまつわる値を取得したり設定したりするモデルにcontextがあります。このcontextには「サーバースクリプトの条件の名称」が格納されているConditionがあります。
マニュアルには「サーバースクリプトの条件の名称」とだけ記載されていて実際に取り得る値が分からない状態です。今回はConditionの中身に何が入っているかを紹介します。

実装を見てみる

contextの実装はImplem.Pleasanter.Libraries.ServerScripts.ServerScriptModelContextにあります。

context.Conditionはここになります。

このプロパティにはServerScriptModelContextのコンストラクタで値がセットされています。このコンストラクタ、どこで呼ばれているかと言われるとImplem.Pleasanter.Libraries.ServerScripts.ServerScriptModelです。

Context = new ServerScriptModelContext(
    context: context,
    logBuilder: context.LogBuilder,
    userData: context.UserData,
    responseCollection: context.ResponseCollection,
    messages: context.Messages,
    errorData: context.ErrorData,
    redirectData: context.RedirectData,
    formStringRaw: context.FormStringRaw,
    formString: context.FormString,
    ajax: context.Ajax,
    mobile: context.Mobile,
    applicationPath: context.ApplicationPath,
    absoluteUri: context.AbsoluteUri,
    absolutePath: context.AbsolutePath,
    url: context.Url,
    urlReferrer: context.UrlReferrer,
    controller: context.Controller,
    query: context.Query,
    action: context.Action,
    tenantId: context.TenantId,
    siteId: context.SiteId,
    id: context.Id,
    groupIds: context.Groups,
    tenantTitle: context.TenantTitle,
    siteTitle: context.SiteTitle,
    recordTitle: context.RecordTitle,
    deptId: context.DeptId,
    userId: context.UserId,
    loginId: context.LoginId,
    language: context.Language,
    timeZoneInfo: context.TimeZoneInfo?.ToString(),
    hasPrivilege: context.HasPrivilege,
    apiVersion: context.ApiVersion,
    apiRequestBody: context.ApiRequestBody,
    requestDataString: context.RequestDataString,
    contentType: context.ContentType,
    onTesting: onTesting,
    scriptDepth: context.ServerScriptDepth,
    controlId: context.Forms.ControlId(),
    condition: condition.ToString());//ここです

conditionToString()stringに変換されています。conditionServerScriptModelのコンストラクタに引数で与えられているものになります。

public ServerScriptModel(
    Context context,
    SiteSettings ss,
    GridData gridData,
    IEnumerable<(string Name, object Value)> data,
    IEnumerable<(string Name, object Value)> saved,
    IEnumerable<(string Name, ServerScriptModelColumn Value)> columns,
    View view,
    ServerScriptConditions condition,//これです
    DateTime timeOut,
    bool debug,
    bool onTesting)

型はServerScriptConditionsです。ではこのServerScriptConditionsを見てみます。

public enum ServerScriptConditions
{
    None,
    WhenViewProcessing,
    WhenloadingSiteSettings,
    BeforeOpeningPage,
    BeforeOpeningRow,
    WhenloadingRecord,
    BeforeFormula,
    AfterFormula,
    AfterUpdate,
    BeforeUpdate,
    AfterCreate,
    BeforeCreate,
    AfterDelete,
    BeforeDelete,
    BackgroundServerScript
}

お、列挙体ですね。ということはServerScriptModelContextで行われているToString()では、この列挙体の列挙子がそのまま返されていることになります。これをサーバスクリプトの条件と対比させると下記の表になります。

Condition 条件
None
WhenViewProcessing ビュー処理時
WhenloadingSiteSettings サイト設定の読み込み時
BeforeOpeningPage 画面表示の前
BeforeOpeningRow 行表示の前
WhenloadingRecord 「レコード」読み込み時
BeforeFormula 計算式の前
AfterFormula 計算式の後
AfterUpdate 更新後
BeforeUpdate 更新前
AfterCreate 作成後
BeforeCreate 作成前
AfterDelete 削除後
BeforeDelete 削除前
BackgroundServerScript バックグラウンドサーバスクリプト

これで、context.Conditionで取得出来る「サーバースクリプトの条件の名称」が判明しました。

まとめ

サーバスクリプトがどこで実行されているかを判断するのにcontext.Actionを使うのは一般的な手法です。どの条件で使用されたかをそれに加えて使えるようになると、かなり細かい実行条件制御が出来るようになります。ぜひ、context.Conditionを活用してみてください。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?