SDK
最新
バナーの背景画像
開発者ガイド
最終更新日 2024年3月23日

アクティビティ プロジェクト設定の構成

オフィシャル フィード ( ) の UiPath.Activities.APIhttps://pkgs.dev.azure.com/uipath/Public.Feeds/_packaging/UiPath-Official/nuget/v3/index.json パッケージを使用すると、Studio で独自のカスタム アクティビティのプロジェクト設定を作成および追加できます。API の使用方法の詳細については、「 Studio アクティビティ SDK」をご覧ください。
注: カスタム プロジェクトでは開発依存関係として UiPath.Activities.API パッケージを使用する必要があります。開発依存関係については、こちらをご覧ください。

アクティビティのプロジェクト設定には、[プロジェクト設定] ウィンドウから直接、プロジェクト レベルで調整可能な一連のオプションが含まれます。



アクティビティ設定の作成

以下のサンプルでは、音楽プレイヤーのサンプル アクティビティで使用する一連の設定を作成します。

タブとセクションの追加

using UiPath.Studio.Activities.Api;
using UiPath.Studio.Activities.Api.Settings;
namespace MyCustomActivityPack
{
    public static class SettingsCreator
    {
        // This is the key used to reference a tab, even across packages.
        internal const string CategoryKey = "DemoTabUniqueKey";
        // This is the key used to reference the setting, even across packages.
        internal const string CommentTextKey = CategoryKey + ".Comment";
        internal const string PresetKey = CategoryKey + ".Preset";
        internal const string ShuffleKey = CategoryKey + ".Shuffle";
        public static void CreateSettings(IWorkflowDesignApi workflowDesignApi)
        {
            var settingsApi = workflowDesignApi.Settings;
            // Add the category (a tab in the settings page)
            var category = new SettingsCategory()
            {
                Description = "Settings Sample",
                Header = "Settings Sample",
                Key = CategoryKey
            };
            settingsApi.AddCategory(category);
            AddMusicPlayerSection(settingsApi, category);
            AddMiscSettings(settingsApi, category);using UiPath.Studio.Activities.Api;
using UiPath.Studio.Activities.Api.Settings;
namespace MyCustomActivityPack
{
    public static class SettingsCreator
    {
        // This is the key used to reference a tab, even across packages.
        internal const string CategoryKey = "DemoTabUniqueKey";
        // This is the key used to reference the setting, even across packages.
        internal const string CommentTextKey = CategoryKey + ".Comment";
        internal const string PresetKey = CategoryKey + ".Preset";
        internal const string ShuffleKey = CategoryKey + ".Shuffle";
        public static void CreateSettings(IWorkflowDesignApi workflowDesignApi)
        {
            var settingsApi = workflowDesignApi.Settings;
            // Add the category (a tab in the settings page)
            var category = new SettingsCategory()
            {
                Description = "Settings Sample",
                Header = "Settings Sample",
                Key = CategoryKey
            };
            settingsApi.AddCategory(category);
            AddMusicPlayerSection(settingsApi, category);
            AddMiscSettings(settingsApi, category);

上記のコードは、[アクティビティのプロジェクト設定] ウィンドウにタブとセクションを追加します。タブのツールチップ上にカーソルを置くと、タブについての説明が表示されます。



設定の追加

  • 展開可能な設定セクション

    private static SettingsSection AddMusicPlayerSection(IActivitiesSettingsService settingsApi, SettingsCategory category)
            {
                var section = new SettingsSection()
                {
                    Description = "Settings for a music player",
                    IsExpanded = true, //set this to control default expansion
                    Title = "Music Player Settings",
                    // the key of a section has to be unique only within the category
                    Key = "Player"
                };
                settingsApi.AddSection(category, section);
                AddSimpleBoolean(settingsApi, section);
                AddSingleChoice(settingsApi, section);
                return section;
            }private static SettingsSection AddMusicPlayerSection(IActivitiesSettingsService settingsApi, SettingsCategory category)
            {
                var section = new SettingsSection()
                {
                    Description = "Settings for a music player",
                    IsExpanded = true, //set this to control default expansion
                    Title = "Music Player Settings",
                    // the key of a section has to be unique only within the category
                    Key = "Player"
                };
                settingsApi.AddSection(category, section);
                AddSimpleBoolean(settingsApi, section);
                AddSingleChoice(settingsApi, section);
                return section;
            }

次のような結果が得られます。



  • Boolean 値のラジオ ボタン

    private static void AddSimpleBoolean(IActivitiesSettingsService settingsApi, SettingsSection section)
            {
                var booleanSetting = new SingleValueEditorDescription<bool>
                {
                    DefaultValue = true,
                    Description = "If active, the playlist is shuffled",
                    // The value returned by GetDisplayValue should be localized
                    GetDisplayValue = b => b ? "On" : "Off",
                    Key = ShuffleKey,
                    Label = "Shuffle"
                };
                settingsApi.AddSetting(section, booleanSetting);
            }private static void AddSimpleBoolean(IActivitiesSettingsService settingsApi, SettingsSection section)
            {
                var booleanSetting = new SingleValueEditorDescription<bool>
                {
                    DefaultValue = true,
                    Description = "If active, the playlist is shuffled",
                    // The value returned by GetDisplayValue should be localized
                    GetDisplayValue = b => b ? "On" : "Off",
                    Key = ShuffleKey,
                    Label = "Shuffle"
                };
                settingsApi.AddSetting(section, booleanSetting);
            }

次のような結果が得られます。



  • 複数の値選択リスト

    private static void AddSingleChoice(IActivitiesSettingsService settingsApi, SettingsSection category)
            {
                var booleanSetting = new SingleValueSelectorDescription
                {
                    DefaultValue = "pop",
                    Values = new[] { "classic", "pop", "rock" },
                    Description = "Sample single choice setting",
                    // The value returned by GetDisplayValue should be localized
                    GetDisplayValue = choice => choice + " music",
                    Key = PresetKey,
                    Label = "Mixer Preset"
                };
                settingsApi.AddSetting(category, booleanSetting);
            }private static void AddSingleChoice(IActivitiesSettingsService settingsApi, SettingsSection category)
            {
                var booleanSetting = new SingleValueSelectorDescription
                {
                    DefaultValue = "pop",
                    Values = new[] { "classic", "pop", "rock" },
                    Description = "Sample single choice setting",
                    // The value returned by GetDisplayValue should be localized
                    GetDisplayValue = choice => choice + " music",
                    Key = PresetKey,
                    Label = "Mixer Preset"
                };
                settingsApi.AddSetting(category, booleanSetting);
            }

次のような結果が得られます。



  • 検証機能付きのテキスト入力フィールド

    private static void AddSimpleString(IActivitiesSettingsService settingsApi, SettingsSection section)
            {
                var simpleStringSetting = new SingleValueEditorDescription<string>()
                {
                    Description = "A free text comment that can't contain the word 'invalid'",
                    // The GetDisplayValue obtains a localized screen representation of the underlying setting value.
                    GetDisplayValue = LocalizeSimpleSettingValue,
                    IsReadOnly = false,
                    DefaultValue = "There is no comment",
                    Label = "Comment",
                    Validate = ValidateSimpleStringSetting,
                    Key = CommentTextKey
                };
                // Add the setting to the section.
                // A setting may also be directly added on a category. It will appear as a setting without a section (top level setting)
                settingsApi.AddSetting(section, simpleStringSetting);
            }
    private static string LocalizeSimpleSettingValue(string s) => $"A localized value of <code>{s}</code>";
    private static string ValidateSimpleStringSetting(string arg)
            {
                if (arg?.ToLowerInvariant().Contains("invalid") == true)
                {
                    return "The sample string setting is invalid if it contains the <code>invalid</code> keyword";
                }
                return string.Empty;
            }private static void AddSimpleString(IActivitiesSettingsService settingsApi, SettingsSection section)
            {
                var simpleStringSetting = new SingleValueEditorDescription<string>()
                {
                    Description = "A free text comment that can't contain the word 'invalid'",
                    // The GetDisplayValue obtains a localized screen representation of the underlying setting value.
                    GetDisplayValue = LocalizeSimpleSettingValue,
                    IsReadOnly = false,
                    DefaultValue = "There is no comment",
                    Label = "Comment",
                    Validate = ValidateSimpleStringSetting,
                    Key = CommentTextKey
                };
                // Add the setting to the section.
                // A setting may also be directly added on a category. It will appear as a setting without a section (top level setting)
                settingsApi.AddSetting(section, simpleStringSetting);
            }
    private static string LocalizeSimpleSettingValue(string s) => $"A localized value of <code>{s}</code>";
    private static string ValidateSimpleStringSetting(string arg)
            {
                if (arg?.ToLowerInvariant().Contains("invalid") == true)
                {
                    return "The sample string setting is invalid if it contains the <code>invalid</code> keyword";
                }
                return string.Empty;
            }

次のような結果が得られます。



プロセス ID とログを取得する

IExecutorRuntime 参照に適用されるメソッドを使用して、ロボットが実行中のプロセスの ID 情報と実行ログを取得できます。以下のメソッドを使用できます。
  • IRunningJobInformation - 実行中のプロセスに関する情報を収集します。以下のプロパティをサポートしています。
    • JobID - プロセス ID を取得します。
    • ProcessName - プロセス名を取得します。
    • ProcessVersion - プロセスのバージョンを取得します。
    • WorkflowFilePath - プロセスのフル パスを取得します。
    • InitiatedBy - ジョブのソース (Robot、Studio、Orchestrator など) を取得します。
    • FolderId - プロセスのフォルダー ID を取得します。
    • FolderName - プロセスのフォルダー名を取得します。
    • TenantId - テナント ID を取得します。
    • TenantKey - テナント キーを取得します。
    • TenantName - テナント名を取得します。
    • RobotName - ロボット名を取得します。
    • LicenseType - ロボットのライセンスの種類を取得します。
    • RuntimeGovernanceEnabled - ランタイム ガバナンスが有効化されているかどうかを確認する情報を提供します。
    • InternalArguments - プロセスの内部引数を取得します。
    • OrganizationId - 組織 ID を取得します。
    • PictureInPictureMode - 使用するピクチャ イン ピクチャ モードの種類を取得します。 次の値を使用できます。
      • Main - プロセスはメインの Windows セッションで実行されます。
      • PictureInPictureSession - プロセスは PiP セッションで実行されます。
      • PictureInPictureDesktop - プロセスが PiP 仮想デスクトップ モードで実行されます。
    • LogMessage - 指定した ログ レベルに基づいてロボット実行ログを生成します。ログの詳細については、こちらのページをご覧ください。以下のプロパティがサポートされています。
    • EventType - 取得するログ レベルです。
    • Message - 表示するメッセージです。
次のコードは、LogMessage メソッドの使用例です。
public class MyLogMessageActivity : CodeActivity
{
    protected override void Execute(CodeActivityContext context)
    {
        var executorRuntime = context.GetExtension<IExecutorRuntime>();
        var jobInfo = executorRuntime.RunningJobInformation;
        executorRuntime.LogMessage(new LogMessage
        {
            EventType = TraceEventType.Warning,
            Message = $"Job {jobInfo.JobId}: My log message from workflow {jobInfo.WorkflowFilePath}"
        });
    }
}public class MyLogMessageActivity : CodeActivity
{
    protected override void Execute(CodeActivityContext context)
    {
        var executorRuntime = context.GetExtension<IExecutorRuntime>();
        var jobInfo = executorRuntime.RunningJobInformation;
        executorRuntime.LogMessage(new LogMessage
        {
            EventType = TraceEventType.Warning,
            Message = $"Job {jobInfo.JobId}: My log message from workflow {jobInfo.WorkflowFilePath}"
        });
    }
}

Studio へのプロジェクトの追加

Studio の [アクティビティのプロジェクト設定] ウィンドウに設定を表示させるには、カスタム アクティビティを NuGet パッケージにパブリッシュして、このパッケージを Studio バージョン 2019.10.1 以降で定義したフィードで利用できるようにする必要があります。

NuGet パッケージの作成



  1. NuGet Package Explorer を起動します。
  2. [Create a new package] (Ctrl + N) をクリックします。[Package metadata] と、[Package contents] を示す分割ウィンドウが表示されます。後者のセクションに、すべての依存関係を追加する必要があります。
  3. [Package contents] セクションを右クリックします。コンテキスト メニューが表示されます。
  4. [Add lib folder] をクリックします。新しい [lib] 項目が、[Package contents] セクションに作成されます。
  5. [lib] を右クリックして、[Add Existing File…] を選択します。
  6. プロジェクトの外部アセンブリ (.dll) を読み込みます。
  7. [Edit] > [Edit Metadata] をクリックします。[Package metadata] セクションが表示されます。
  8. プロジェクトの適切な説明をフィールドに入力します。
  9. [Id] フィールドに入力し、キーワード Activities が含まれていることを確認します。これにより、Studio の [パッケージを管理] ウィンドウにパッケージが表示されるようになります。
  10. Click File > Save. In our case, the .nupkg file is created.
    Note: Be sure to create an intuitive folder structure for your activities. All empty folders inside the custom activity get removed when used with Orchestrator.

UiPath Studio への NuGet パッケージのインストール

.nupkg ファイルを作成したら、こちらの説明に従い、これを Studio のカスタム フィードに追加します。

[パッケージを管理] ウィンドウを開き、パッケージをインストールします。カスタム フィードが Studio で有効化されていることを確認します。

設定例

上記で作成したタブ、セクション、および設定をまとめて、[アクティビティのプロジェクト設定] ウィンドウに表示します。



以下のリンクに従ってサンプルをダウンロードします。このサンプルには、 カスタム ウィザードの作成例も含まれています。

Was this page helpful?

サポートを受ける
RPA について学ぶ - オートメーション コース
UiPath コミュニティ フォーラム
UiPath ロゴ (白)
信頼とセキュリティ
© 2005-2024 UiPath. All rights reserved.