- Visão geral
- Atividades personalizadas
- Migração de atividades para o. NET 6
- Notas de versão
- Como Criar Regras do Analisador de Fluxo de Trabalho
- Como criar as configurações de projeto de atividades
- Como criar assistentes personalizados
- Priorizar atividades por escopo
- 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
- Gatilhos SDK
- Como criar um gatilho personalizado
- SDKs de agentes

Guia do desenvolvedor
Como criar um gatilho personalizado
Os projetos de automação se beneficiam dos gatilhos, que monitoram a atividade da máquina em busca de eventos específicos para disparar Actionsespecíficas . Os gatilhos podem ser configurados por meio da estrutura do Monitor Events, mas você também pode criar gatilhos personalizados, conforme explicado neste guia.
Pré-requisitos
Para criar um disparador personalizado, é necessário o seguinte:
- Microsoft Visual Studio
- Microsoft .NET Framework v4.6.1 ou posterior
Criação e configuração do projeto
-
Abra o Microsoft Visual Studio e escolha Criar um novo projeto. A janela Seleção de Projeto é exibida.
-
Selecione Biblioteca de classes (.NET Framework) e clique em Avançar. A janela Configurar seu novo projeto é exibida.
-
Forneça um nome do projeto, local, nome da solução e estrutura. Certifique-se de selecionar a estrutura do .NET Framework 4.6.1 ou superior. Quando todos os campos estiverem preenchidos, clique em Criar. O novo projeto é criado e a janela Designer é exibida.

-
No menu Ferramentas , selecione Opções. A janela Opções é exibida agora.
-
Expanda a entrada Gerenciador de pacotes NuGet e selecione Origens de pacotes.
-
Adicione uma nova origem de pacote e preencha o campo Nome com Feed Oficial da UiPath e o campo Origem com
https://pkgs.dev.azure.com/uipath/Public.Feeds/_packaging/UiPath-Official/nuget/v3/index.json. Clique em OK para confirmar e salvar as alterações.
-
Clique no menu Ferramentas e, na entrada Gerenciador de pacotes do NuGet, selecione Gerenciar pacotes do NuGet para a solução.... A guia NuGet - Soluções é exibida.
-
Procure a referência UiPath.Platform e selecione-a. No painel à direita, selecione o projeto para o qual adicionar a referência e clique em Instalar. Certifique-se de marcar a caixa Incluir pré-lançamento e instalar a referência UiPath.Platform v20.8 ou superior.
Escrevendo o código do gatilho
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;
}
A próxima etapa é implementar os métodos StartMonitor e StopMonitor . Isso é feito para determinar o comportamento do disparador para monitorar eventos específicos.
É importante observar que, se você quiser fornecer argumentos para expandir o uso do gatilho no gerenciador de eventos, será necessário adicionar e configurar uma classe <Custom>TriggerArgs no designer.
A última etapa é construir a biblioteca e criar o pacote NuGet para usar no Studio. O novo gatilho agora pode ser usado dentro de uma atividade Trigger Scope .