- 概要
- カスタム アクティビティ
- アクティビティを .NET 6 に移行する
- リリース ノート
- ワークフロー アナライザーのルールを構築する
- アクティビティ プロジェクト設定の構成
- カスタム ウィザードの作成
- スコープによるアクティビティの優先度設定
- UiPath.Activities.Api.Base
- UiPath.Studio.Activities.Api
- UiPath.Studio.Activities.Api.Activities
- UiPath.Studio.Activities.Api.BusyService
- UiPath.Studio.Activities.Api.ExpressionEditor
- UiPath.Studio.Activities.Api.Expressions
- UiPath.Studio.Activities.Api.Licensing
- UiPath.Studio.Activities.Api.Mocking
- UiPath.Studio.Activities.Api.ObjectLibrary
- UiPath.Studio.Activities.Api.PackageBindings
- UiPath.Studio.Activities.Api.ProjectProperties
- UiPath.Studio.Activities.Api.ScopedActivities
- UiPath.Studio.Activities.Api.Settings
- UiPath.Studio.Activities.Api.Wizards
- UiPath.Studio.Activities.Api.Workflow
- UiPath.Studio.Api.Controls
- UiPath.Studio.Api.Telemetry
- UiPath.Studio.Api.Theme
- Robot JavaScript SDK
- トリガー SDK
- カスタム トリガーの作成方法
- エージェント SDK

開発者ガイド
カスタム トリガーの作成方法
オートメーション プロジェクトでトリガーの機能を利用できるようになりました。トリガーは、特定のアクションを発生させるためにマシンのアクティビティで特定のイベントがないか監視します。 トリガーは [イベントを監視] フレームワークを使用して設定できますが、このガイドで説明しているようにカスタム トリガーを構築することもできます。
前提条件
カスタム トリガーを作成するには、以下が必要です。
- Microsoft Visual Studio
- Microsoft .NET Framework v4.6.1 以降
プロジェクトを作成および構成する
-
Microsoft Visual Studio を開き、新しいプロジェクトを作成することを選択します。 [プロジェクト] 選択ウィンドウが表示されます。
-
[クラス ライブラリ (.NET Framework)] を選択し、[次へ] をクリックします。[ 新しいプロジェクトを設定] ウィンドウが表示されます。
-
プロジェクト名、場所、ソリューション名、フレームワークを入力します。必ず .NET Framework 4.6.1 以降のフレームワークを選択してください。すべてのフィールドに入力したら、[ 作成] をクリックします。新しいプロジェクトが作成され、デザイナー ウィンドウが表示されます。

-
[ツール] メニューから [オプション] を選択します。[オプション] ウィンドウが表示されます。
-
[ NuGet パッケージ マネージャー ] のエントリを展開し、[ パッケージ ソース] を選択します。
-
新しいパッケージ ソースを追加し、[ 名前 ] フィールドに UiPath のオフィシャル フィード と入力し、[ ソース ] フィールドに
https://pkgs.dev.azure.com/uipath/Public.Feeds/_packaging/UiPath-Official/nuget/v3/index.jsonを入力します。[ OK ] をクリックして確認し、変更を保存します。
-
[ ツール ] メニューをクリックし、[ NuGet パッケージ マネージャー ] エントリから [ ソリューションの NuGet パッケージの管理] を選択します。[NuGet - ソリューション] タブが表示されます。
-
UiPath.Platform の参照を検索して選択します。右側のパネルで、参照を追加するプロジェクトを選択し、[ インストール] をクリックします。[ プレリリースを含める ] ボックスをオンにして、 UiPath.Platform v20.8 以降のリファレンス パッケージをインストールしてください。
トリガー コードを記述する
Once the references are added to the project, it's time to write the code, which should look something like this:
using System;
using System.Activities;
using System.Threading;
using UiPath.Platform.Triggers;
public class TimerTrigger : TriggerBase<TimerTriggerArgs>
{
//it is recommended to use Variable to store fields in order for
//activities like Parallel For Each to work correctly
private readonly Variable<Timer> _timer = new Variable<Timer>();
public InArgument<TimeSpan> Period { get; set; }
protected override void CacheMetadata(NativeActivityMetadata metadata)
{
metadata.AddImplementationVariable(_timer);
base.CacheMetadata(metadata);
}
//in this method you can subscribe to events. It is called when the trigger starts execution
protected override void StartMonitor(NativeActivityContext context, Action<TimerTriggerArgs> sendTrigger)
{
var eventIndex = 0;
var period = Period.Get(context);
_timer.Set(context, new Timer(OnTick, state: null, dueTime: period, period: period));
return;
void OnTick(object state) => sendTrigger(new TimerTriggerArgs(eventIndex++));
}
//this is used for cleanup. It is called when the trigger is Cancelled or Aborted
protected override void StopMonitor(ActivityContext context) => _timer.Get(context).Dispose();
}
//Each trigger may declare a type that sub-classes TriggerArgs
//that corresponds to the “args” item in Trigger Scope activity. If no extra info
//needs to be passed along, TriggerArgs can be used directly
public class TimerTriggerArgs : TriggerArgs
{
public int EventIndex { get; }
public TimerTriggerArgs(int eventIndex) => EventIndex = eventIndex;
}
using System;
using System.Activities;
using System.Threading;
using UiPath.Platform.Triggers;
public class TimerTrigger : TriggerBase<TimerTriggerArgs>
{
//it is recommended to use Variable to store fields in order for
//activities like Parallel For Each to work correctly
private readonly Variable<Timer> _timer = new Variable<Timer>();
public InArgument<TimeSpan> Period { get; set; }
protected override void CacheMetadata(NativeActivityMetadata metadata)
{
metadata.AddImplementationVariable(_timer);
base.CacheMetadata(metadata);
}
//in this method you can subscribe to events. It is called when the trigger starts execution
protected override void StartMonitor(NativeActivityContext context, Action<TimerTriggerArgs> sendTrigger)
{
var eventIndex = 0;
var period = Period.Get(context);
_timer.Set(context, new Timer(OnTick, state: null, dueTime: period, period: period));
return;
void OnTick(object state) => sendTrigger(new TimerTriggerArgs(eventIndex++));
}
//this is used for cleanup. It is called when the trigger is Cancelled or Aborted
protected override void StopMonitor(ActivityContext context) => _timer.Get(context).Dispose();
}
//Each trigger may declare a type that sub-classes TriggerArgs
//that corresponds to the “args” item in Trigger Scope activity. If no extra info
//needs to be passed along, TriggerArgs can be used directly
public class TimerTriggerArgs : TriggerArgs
{
public int EventIndex { get; }
public TimerTriggerArgs(int eventIndex) => EventIndex = eventIndex;
}
次に、 StartMonitor メソッドと StopMonitor メソッドを実装します。 これは、特定のイベントを監視するためのトリガーの動作を決定するために行われます。
イベント ハンドラーでトリガーの使用法を拡張するための引数を指定する場合は、デザイナーに <Custom>TriggerArgs クラスを追加して設定する必要があることに注意してください。
最後の手順では、 ライブラリを構築し、 Studio で使用する NuGet パッケージを作成します 。これで、新しいトリガーを [トリガー スコープ] アクティビティ内で使用できるようになりました。