sdk
latest
false
- 概述
- 自定义活动
- 将活动迁移到 .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
重要 :
请注意此内容已使用机器翻译进行了部分本地化。
新发布内容的本地化可能需要 1-2 周的时间才能完成。
开发者指南
上次更新日期 2024年10月25日
构建活动项目设置
使用 官方 订阅源 ( ) 中的 UiPath.Activities.API
https://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; }
结果为:
-
布尔值单选按钮:
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; }
结果为:
通过使用适用于引用
IExecutorRuntime
的方法,您可以获得有关机器人正在执行的流程 ID 的信息,以及执行日志。可以使用以下方法:
-
IRunningJobInformation
- 收集正在执行的进程的相关信息,并支持以下属性:JobID
- 检索流程 IDProcessName
- 检索流程名称ProcessVersion
- 检索流程版本WorkflowFilePath
- 检索流程的完整路径InitiatedBy
- 检索作业的来源(机器人、Studio、Orchestrator 等)FolderId
- 检索流程的文件夹 IDFolderName
- 检索流程的文件夹名称TenantId
- 检索租户 IDTenantKey
- 检索租户密钥TenantName
- 检索租户名称RobotName
- 检索机器人名称LicenseType
- 检索机器人许可证类型RuntimeGovernanceEnabled
- 提供是否启用 Runtime 监管的信息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 的“活动项目设置'”窗口可见,您需要将自定义活动发布到 NuGet 包中,并向 2019.10.1 或更高版本 Studio 中定义的订阅源提供该包。
- Launch NuGet Package Explorer.
- 单击“创建新包 (Ctrl + N)”。随即会出现一个分割窗口,其中显示“包元数据”和“包内容”。我们需要在窗口的后一部分中添加所有依赖项。
- 右键单击“包内容”部分。系统随即会显示一个上下文菜单。
- 单击 “添加库文件夹”。 请注意,系统会在“ 包内容 ”部分中创建一个新的库项目。
- 右键单击“ 库 ”,然后选择“ 添加现有文件…”。
- 加载项目的外部程序集 (.dll)。
- 单击 “编辑” >“编辑元数据”。 系统将显示“ 包元数据 ” 部分。
- 根据需要填写字段,以更好地描述项目。
- 填写“ID”字段,并确保包含关键字“活动”,以便在 Studio 的“管理包”窗口中显示该包。
-
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.