sdk
latest
false
- 概要
- カスタム アクティビティ
- アクティビティを .NET 6 に移行する
- リリース ノート
- Building Workflow Analyzer Rules
- アクティビティ プロジェクト設定の構成
- カスタム ウィザードの作成
- スコープによるアクティビティの優先度設定
- 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
重要 :
このコンテンツの一部は機械翻訳によって処理されており、完全な翻訳を保証するものではありません。
新しいコンテンツの翻訳は、およそ 1 ~ 2 週間で公開されます。

開発者ガイド
最終更新日時 2025年10月30日
この例では、アクティビティ コードの記述を示すために、
UiPath.Examples.Activities GitHub の ソリューションから単純な [ 計算機能] アクティビティを再作成します。このアクティビティは、以下のとおりです。
-
2 つの数値と 1 つの演算 (加算、減算、乗算、または除算) を入力として受け取ります
-
選択した操作の結果を返します
アクティビティ コードは、次の 2 つの部分で構成されます。
UiPath.Activities.Templateから開始し、ソリューションの名前と、関連するすべてのファイルと参照の名前を変更しますUiPath.Examples.Activities.- アクティビティ ロジックを保持するファイルの名前を
ActivityTemplate.csからCalculator.csに変更します。 -
参照と名前空間を次のように更新します。
using System.Activities; using System.Diagnostics; using UiPath.Examples.Activities.Helpers; namespace UiPath.Examples.Activities { }using System.Activities; using System.Diagnostics; using UiPath.Examples.Activities.Helpers; namespace UiPath.Examples.Activities { } -
入力引数を宣言します。2 つの数値 (
FirstNumberとSecondNumberはintとして)、実行する操作 (SelectedOperationはenumとして宣言します。オプションの既定値はMultiplyに設定されています。[RequiredArgument]属性を使用して、3 つの引数すべてを必須としてマークします。戻り値は、Result引数の値を設定するために使用されます。public class Calculator : CodeActivity<int> // This base class exposes an OutArgument named Result { [RequiredArgument] public InArgument<int> FirstNumber { get; set; } //InArgument allows a varriable to be set from the workflow [RequiredArgument] public InArgument<int> SecondNumber { get; set; } [RequiredArgument] public Operation SelectedOperation { get; set; } = Operation.Multiply; // default value is optional /* * The returned value will be used to set the value of the Result argument */ }public class Calculator : CodeActivity<int> // This base class exposes an OutArgument named Result { [RequiredArgument] public InArgument<int> FirstNumber { get; set; } //InArgument allows a varriable to be set from the workflow [RequiredArgument] public InArgument<int> SecondNumber { get; set; } [RequiredArgument] public Operation SelectedOperation { get; set; } = Operation.Multiply; // default value is optional /* * The returned value will be used to set the value of the Result argument */ } -
実行部分を開始し、ログ記録を追加して、ワークフロー コンテキストから数値の値を取得し、ゼロ除算のシナリオを処理するロジックを追加します。
protected override int Execute(CodeActivityContext context) { // This is how you can log messages from your activity. logs are sent to the Robot which will forward them to Orchestrator context.GetExecutorRuntime().LogMessage(new Robot.Activities.Api.LogMessage() { EventType = TraceEventType.Information, Message = "Executing Calculator activity" }); var firstNumber = FirstNumber.Get(context); //get the value from the workflow context (remember, this can be a variable) var secondNumber = SecondNumber.Get(context); if (secondNumber == 0 && SelectedOperation == Operation.Divide) { throw new DivideByZeroException("Second number should not be zero when the selected operation is divide"); } return ExecuteInternal(firstNumber, secondNumber); }protected override int Execute(CodeActivityContext context) { // This is how you can log messages from your activity. logs are sent to the Robot which will forward them to Orchestrator context.GetExecutorRuntime().LogMessage(new Robot.Activities.Api.LogMessage() { EventType = TraceEventType.Information, Message = "Executing Calculator activity" }); var firstNumber = FirstNumber.Get(context); //get the value from the workflow context (remember, this can be a variable) var secondNumber = SecondNumber.Get(context); if (secondNumber == 0 && SelectedOperation == Operation.Divide) { throw new DivideByZeroException("Second number should not be zero when the selected operation is divide"); } return ExecuteInternal(firstNumber, secondNumber); } -
選択した操作ごとに実行する計算を追加します。
public int ExecuteInternal(int firstNumber, int secondNumber) { return SelectedOperation switch { Operation.Add => firstNumber + secondNumber, Operation.Subtract => firstNumber - secondNumber, Operation.Multiply => firstNumber * secondNumber, Operation.Divide => firstNumber / secondNumber, _ => throw new NotSupportedException("Operation not supported"), }; }public int ExecuteInternal(int firstNumber, int secondNumber) { return SelectedOperation switch { Operation.Add => firstNumber + secondNumber, Operation.Subtract => firstNumber - secondNumber, Operation.Multiply => firstNumber * secondNumber, Operation.Divide => firstNumber / secondNumber, _ => throw new NotSupportedException("Operation not supported"), }; } -
操作を定義します。
public enum Operation { Add, Subtract, Multiply, Divide }public enum Operation { Add, Subtract, Multiply, Divide }
アクティビティで使用できる入力は、プロパティのデータ型によって決まります。サンプルの [計算機能] アクティビティで、以下の手順を実行します。
-
FirstNumberプロパティとSecondNumberプロパティのデータ型がintであるため、これらのプロパティには数値エディターの入力フィールドが表示されます。 -
データ型が
enumであるOperationプロパティの場合、アクティビティにドロップダウン メニューがあります。
これらのデータ型は、ユーザーがアクティビティの入力をどのように操作するかに直接影響します。
プロパティのラベルとツールチップは
Resources.resx ファイルで定義できます。
次の表で、各アクティビティ プロパティで使用できる最も一般的なプロパティについて説明します。
| プロパティ | 説明 |
|---|---|
| 表示名 | プロパティのラベル。 |
| ツールチップ | プロパティ上でホバーしたときに表示するテキスト。 |
| IsRequired1 | プロパティが必須かどうか。 必須プロパティは、アクティビティ内で [RequiredArgument] 属性を使用してマークする必要もあります。
|
| IsPrincipal2 | プロパティをアクティビティのメイン カテゴリに常に表示するかどうか。 [false] に設定すると、既定では折りたたまれた [詳細オプションを表示] メニューの下にプロパティが表示されます。
|
| OrderIndex | プロパティを表示する順序。 |
1 必須になることのない出力プロパティでは使用できません。
2 慣例により、出力プロパティは詳細オプションにおいてアクティビティの最後に配置されます。
[計算機能] アクティビティのデザインを作成する
- ファイル
ActivityTemplateViewModel.csの名前をCalculatorViewModel.csに変更し、アクティビティのユーザー インターフェイスのコードを追加します。 -
参照と名前空間を次のように更新します。
using System.Activities.DesignViewModels; using System.Diagnostics; namespace UiPath.Examples.Activities.ViewModels { }using System.Activities.DesignViewModels; using System.Diagnostics; namespace UiPath.Examples.Activities.ViewModels { } -
入力プロパティを宣言します。result プロパティは、アクティビティの基本クラスから取得されます。名前と型引数は、アクティビティのものと一致する必要があります。
public class CalculatorViewModel : DesignPropertiesViewModel { /* * Properties names must match the names and generic type arguments of the properties in the activity * Use DesignInArgument for properties that accept a variable */ public DesignInArgument<int> FirstNumber { get; set; } public DesignInArgument<int> SecondNumber { get; set; } /* * Use DesignProperty for properties that accept a constant value */ public DesignProperty<Operation> SelectedOperation { get; set; } /* * The result property comes from the activity's base class */ public DesignOutArgument<int> Result { get; set; } public CalculatorViewModel(IDesignServices services) : base(services) { } }public class CalculatorViewModel : DesignPropertiesViewModel { /* * Properties names must match the names and generic type arguments of the properties in the activity * Use DesignInArgument for properties that accept a variable */ public DesignInArgument<int> FirstNumber { get; set; } public DesignInArgument<int> SecondNumber { get; set; } /* * Use DesignProperty for properties that accept a constant value */ public DesignProperty<Operation> SelectedOperation { get; set; } /* * The result property comes from the activity's base class */ public DesignOutArgument<int> Result { get; set; } public CalculatorViewModel(IDesignServices services) : base(services) { } } -
アクティビティ デザインのコードを追加します。必要に応じて、
ViewModel初期化をデバッグするには、Debugger.Break();を含む行のコメントを解除してブレークポイントを追加します。次のコード スニペットは、ViewModelのプロパティを初期化し、初期化中にプロパティ値を変更するときに必須のPersistValuesChangedDuringInit()呼び出しを追加し、アクティビティの入力プロパティと出力プロパティを定義します。protected override void InitializeModel() { //Debugger.Break(); /* * The base call will initialize the properties of the view model with the values from the xaml or with the default values from the activity */ base.InitializeModel(); PersistValuesChangedDuringInit(); // just for heads-up here; it's a mandatory call only when you change the values of properties during initialization var orderIndex = 0; FirstNumber.DisplayName = Resources.Calculator_FirstNumber_DisplayName; FirstNumber.Tooltip = Resources.Calculator_FirstNumber_Tooltip; /* * Required fields will automatically raise validation errors when empty. * Unless you do custom validation, required activity properties should be marked as such both in the view model and in the activity: * -> in the view model use the IsRequired property * -> in the activity use the [RequiredArgument] attribute. */ FirstNumber.IsRequired = true; FirstNumber.IsPrincipal = true; // specifies if it belongs to the main category (which cannot be collapsed) FirstNumber.OrderIndex = orderIndex++; // indicates the order in which the fields appear in the designer (i.e. the line number); SecondNumber.DisplayName = Resources.Calculator_SecondNumber_DisplayName; SecondNumber.Tooltip = Resources.Calculator_SecondNumber_Tooltip; SecondNumber.IsRequired = true; SecondNumber.IsPrincipal = true; SecondNumber.OrderIndex = orderIndex++; SelectedOperation.DisplayName = Resources.Calculator_SelectedOperation_DisplayName; SelectedOperation.Tooltip = Resources.Calculator_SelectedOperation_Tooltip; SelectedOperation.IsRequired = true; SelectedOperation.IsPrincipal = true; SelectedOperation.OrderIndex = orderIndex++; /* * Output properties are never mandatory. * By convention, they are not principal and they are placed at the end of the activity. */ Result.DisplayName = Resources.Calculator_Result_DisplayName; Result.Tooltip = Resources.Calculator_Result_Tooltip; Result.OrderIndex = orderIndex; }protected override void InitializeModel() { //Debugger.Break(); /* * The base call will initialize the properties of the view model with the values from the xaml or with the default values from the activity */ base.InitializeModel(); PersistValuesChangedDuringInit(); // just for heads-up here; it's a mandatory call only when you change the values of properties during initialization var orderIndex = 0; FirstNumber.DisplayName = Resources.Calculator_FirstNumber_DisplayName; FirstNumber.Tooltip = Resources.Calculator_FirstNumber_Tooltip; /* * Required fields will automatically raise validation errors when empty. * Unless you do custom validation, required activity properties should be marked as such both in the view model and in the activity: * -> in the view model use the IsRequired property * -> in the activity use the [RequiredArgument] attribute. */ FirstNumber.IsRequired = true; FirstNumber.IsPrincipal = true; // specifies if it belongs to the main category (which cannot be collapsed) FirstNumber.OrderIndex = orderIndex++; // indicates the order in which the fields appear in the designer (i.e. the line number); SecondNumber.DisplayName = Resources.Calculator_SecondNumber_DisplayName; SecondNumber.Tooltip = Resources.Calculator_SecondNumber_Tooltip; SecondNumber.IsRequired = true; SecondNumber.IsPrincipal = true; SecondNumber.OrderIndex = orderIndex++; SelectedOperation.DisplayName = Resources.Calculator_SelectedOperation_DisplayName; SelectedOperation.Tooltip = Resources.Calculator_SelectedOperation_Tooltip; SelectedOperation.IsRequired = true; SelectedOperation.IsPrincipal = true; SelectedOperation.OrderIndex = orderIndex++; /* * Output properties are never mandatory. * By convention, they are not principal and they are placed at the end of the activity. */ Result.DisplayName = Resources.Calculator_Result_DisplayName; Result.Tooltip = Resources.Calculator_Result_Tooltip; Result.OrderIndex = orderIndex; } - ラベルとツールチップの文字列値を
Resources.resxファイルに追加します。ローカリゼーションに向けて、アクティビティ名 (Activity name) とアクティビティの説明 (Activity description) には具体的なコメントを使用する必要があります。その他の文字列については、コメントを追加することをお勧めします。
次の図は、UiPath Studio で表示されたアクティビティの設定を示しています。
1 - 3 つの入力プロパティのラベル (表示名) です。
2 -
FirstNumber プロパティのツールチップです。