Skip to content

Commit

Permalink
Merge pull request #23 from IndicoDataSolutions/meg/timeout2
Browse files Browse the repository at this point in the history
[CAT-230] Incorporate new UIPath shared code to address timeouts.
  • Loading branch information
goatrocks authored May 19, 2022
2 parents ed9df05 + d632c4a commit 4e7d093
Show file tree
Hide file tree
Showing 88 changed files with 2,040 additions and 386 deletions.
25 changes: 9 additions & 16 deletions Indico-RPAActivities.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,20 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Indico.RPAActivities.Activi
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Indico.RPAActivities.Activities.Design", "Indico.RPAActivities\Indico.RPAActivities.Activities.Design\Indico.RPAActivities.Activities.Design.csproj", "{86F25D09-FAC6-4472-B6C9-11511CFB6D4F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{B1C368CB-01F3-4BC4-B81D-9B382D2567EA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Indico.RPAActivities.IntegrationTests", "Indico.RPAActivities\Indico.RPAActivities.IntegrationTests\Indico.RPAActivities.IntegrationTests.csproj", "{BA50C5C3-35C0-4988-9437-D3200C5CEA49}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Indico.UiPath.Shared.Activities.Tests", "Shared\Indico.UiPath.Shared.Activities.Tests\Indico.UiPath.Shared.Activities.Tests.csproj", "{0264EE69-D015-4AAC-908E-AED8E4EF71FD}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{6CE429F6-E855-49B9-BF24-0449E5FE1FC8}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Indico.UiPath.Shared.Activities", "Shared\Indico.UiPath.Shared.Activities\Indico.UiPath.Shared.Activities.shproj", "{4546856D-EA50-45C6-9419-EEEACB5A80AA}"
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "UiPath.Shared.Activities", "Shared\UiPath.Shared.Activities\UiPath.Shared.Activities.shproj", "{4546856D-EA50-45C6-9419-EEEACB5A80AA}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Indico.UiPath.Shared.Activities.Design", "Shared\Indico.UiPath.Shared.Activities.Design\Indico.UiPath.Shared.Activities.Design.shproj", "{DF9C43F0-ADD3-4FBF-995E-84B92F9CBF25}"
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "UiPath.Shared.Activities.Design", "Shared\UiPath.Shared.Activities.Design\UiPath.Shared.Activities.Design.shproj", "{DF9C43F0-ADD3-4FBF-995E-84B92F9CBF25}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Shared\Indico.UiPath.Shared.Activities\Indico.UiPath.Shared.Activities.projitems*{4546856d-ea50-45c6-9419-eeeacb5a80aa}*SharedItemsImports = 13
Shared\Indico.UiPath.Shared.Activities\Indico.UiPath.Shared.Activities.projitems*{51f8b27e-a131-47d6-a8dc-2e57f29172b8}*SharedItemsImports = 5
Shared\Indico.UiPath.Shared.Activities.Design\Indico.UiPath.Shared.Activities.Design.projitems*{86f25d09-fac6-4472-b6c9-11511cfb6d4f}*SharedItemsImports = 5
Shared\Indico.UiPath.Shared.Activities.Design\Indico.UiPath.Shared.Activities.Design.projitems*{df9c43f0-add3-4fbf-995e-84b92f9cbf25}*SharedItemsImports = 13
Shared\UiPath.Shared.Activities\UiPath.Shared.Activities.projitems*{4546856d-ea50-45c6-9419-eeeacb5a80aa}*SharedItemsImports = 13
Shared\UiPath.Shared.Activities\UiPath.Shared.Activities.projitems*{51f8b27e-a131-47d6-a8dc-2e57f29172b8}*SharedItemsImports = 5
Shared\UiPath.Shared.Activities.Design\UiPath.Shared.Activities.Design.projitems*{86f25d09-fac6-4472-b6c9-11511cfb6d4f}*SharedItemsImports = 5
Shared\UiPath.Shared.Activities.Design\UiPath.Shared.Activities.Design.projitems*{df9c43f0-add3-4fbf-995e-84b92f9cbf25}*SharedItemsImports = 13
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -49,10 +47,6 @@ Global
{BA50C5C3-35C0-4988-9437-D3200C5CEA49}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BA50C5C3-35C0-4988-9437-D3200C5CEA49}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BA50C5C3-35C0-4988-9437-D3200C5CEA49}.Release|Any CPU.Build.0 = Release|Any CPU
{0264EE69-D015-4AAC-908E-AED8E4EF71FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0264EE69-D015-4AAC-908E-AED8E4EF71FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0264EE69-D015-4AAC-908E-AED8E4EF71FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0264EE69-D015-4AAC-908E-AED8E4EF71FD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -62,9 +56,8 @@ Global
{51F8B27E-A131-47D6-A8DC-2E57F29172B8} = {48DE06B4-1D5A-4D7B-837C-56EBDB9FDC80}
{86F25D09-FAC6-4472-B6C9-11511CFB6D4F} = {48DE06B4-1D5A-4D7B-837C-56EBDB9FDC80}
{BA50C5C3-35C0-4988-9437-D3200C5CEA49} = {48DE06B4-1D5A-4D7B-837C-56EBDB9FDC80}
{0264EE69-D015-4AAC-908E-AED8E4EF71FD} = {B1C368CB-01F3-4BC4-B81D-9B382D2567EA}
{4546856D-EA50-45C6-9419-EEEACB5A80AA} = {B1C368CB-01F3-4BC4-B81D-9B382D2567EA}
{DF9C43F0-ADD3-4FBF-995E-84B92F9CBF25} = {B1C368CB-01F3-4BC4-B81D-9B382D2567EA}
{4546856D-EA50-45C6-9419-EEEACB5A80AA} = {6CE429F6-E855-49B9-BF24-0449E5FE1FC8}
{DF9C43F0-ADD3-4FBF-995E-84B92F9CBF25} = {6CE429F6-E855-49B9-BF24-0449E5FE1FC8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AB6B0D92-AB63-4156-A537-B946B44D2A53}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public void Register()
builder.AddCustomAttributes(typeof(SubmitReview), new DesignerAttribute(typeof(SubmitReviewDesigner)));
builder.AddCustomAttributes(typeof(SubmitReview), new HelpKeywordAttribute(""));

builder.AddCustomAttributes(typeof(MarkSubmissionRetrieved), new DesignerAttribute(typeof(MarkSubmissionRetrievedDesigner)));
builder.AddCustomAttributes(typeof(MarkSubmissionRetrieved), new HelpKeywordAttribute(""));


MetadataStore.AddAttributeTable(builder.CreateTable());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sa="http://schemas.microsoft.com/netfx/2009/xaml/activities"
xmlns:p="clr-namespace:Indico.RPAActivities.Activities.Design.Properties"
xmlns:sharedres="clr-namespace:UiPath.Shared.Localization"
xmlns:sharedres="clr-namespace:Indico.UiPath.Shared.Localization"
xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"
xmlns:converters="clr-namespace:Indico.UiPath.Shared.Activities.Design.Converters"
xmlns:uip="clr-namespace:Indico.UiPath.Shared.Activities.Design.Controls">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sa="http://schemas.microsoft.com/netfx/2009/xaml/activities"
xmlns:p="clr-namespace:Indico.RPAActivities.Activities.Design.Properties"
xmlns:sharedres="clr-namespace:UiPath.Shared.Localization"
xmlns:sharedres="clr-namespace:Indico.UiPath.Shared.Localization"
xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"
xmlns:converters="clr-namespace:Indico.UiPath.Shared.Activities.Design.Converters"
xmlns:uip="clr-namespace:Indico.UiPath.Shared.Activities.Design.Controls">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<sap:ActivityDesigner x:Class="Indico.RPAActivities.Activities.Design.Designers.MarkSubmissionRetrievedDesigner"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:activity="clr-namespace:Indico.RPAActivities.Activities.Properties;assembly=Indico.RPAActivities.Activities"
xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"
xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation"
xmlns:sapc="clr-namespace:System.Activities.Presentation.Converters;assembly=System.Activities.Presentation"
xmlns:converters="clr-namespace:Indico.UiPath.Shared.Activities.Design.Converters"
xmlns:uip="clr-namespace:Indico.UiPath.Shared.Activities.Design.Controls">

<sap:ActivityDesigner.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="..\Themes\Generic.xaml" />
</ResourceDictionary.MergedDictionaries>
<sapc:ArgumentToExpressionConverter x:Key="ArgumentToExpressionConverter" />
<converters:ActivityIconConverter x:Key="ActivityIconConverter" />
</ResourceDictionary>
</sap:ActivityDesigner.Resources>

<sap:ActivityDesigner.Icon>
<DrawingBrush Stretch="Uniform" Drawing="{Binding Path=ModelItem, Converter={StaticResource ActivityIconConverter}, ConverterParameter=pack://application:\,\,\,/Indico.RPAActivities.Activities.Design;component/themes/icons.xaml}" />
</sap:ActivityDesigner.Icon>

</sap:ActivityDesigner>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Indico.RPAActivities.Activities.Design.Designers
{
/// <summary>
/// Interaction logic for MarkSubmissionRetrievedDesigner.xaml
/// </summary>
public partial class MarkSubmissionRetrievedDesigner
{
public MarkSubmissionRetrievedDesigner()
{
InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
</PropertyGroup>
<!-- Package Versions -->
<PropertyGroup Condition="'$(Configuration)' == 'Debug' AND '$(DesignTimeBuild)' != 'true'">
<PackageVersion>2.3.3.$([System.DateTime]::UtcNow.ToString(MMddHHmm))</PackageVersion>
<PackageVersion>2.5.0.$([System.DateTime]::UtcNow.ToString(MMddHHmm))</PackageVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<PackageVersion>2.3.4</PackageVersion>
<PackageVersion>2.5.0</PackageVersion>
</PropertyGroup>
<ItemGroup>
<None Remove="Designers\DocumentExtractionDesigner.xaml" />
Expand All @@ -38,6 +38,7 @@
<None Remove="Designers\ListDatasetsDesigner.xaml" />
<None Remove="Designers\ListSubmissionsDesigner.xaml" />
<None Remove="Designers\ListWorkflowsDesigner.xaml" />
<None Remove="Designers\MarkSubmissionRetrievedDesigner.xaml" />
<None Remove="Designers\SubmissionResultDesigner.xaml" />
<None Remove="Designers\SubmitReviewDesigner.xaml" />
<None Remove="Designers\WorkflowSubmissionDesigner.xaml" />
Expand Down Expand Up @@ -109,6 +110,9 @@
<Page Include="Designers\ListWorkflowsDesigner.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</Page>
<Page Include="Designers\MarkSubmissionRetrievedDesigner.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</Page>
<Page Include="Designers\SubmissionResultDesigner.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</Page>
Expand All @@ -132,7 +136,7 @@
<ItemGroup>
<!--workaround: required so nuget packages have all required dependencies-->
<ProjectReference Include="..\Indico.RPAActivities\Indico.RPAActivities.csproj" PrivateAssets="All" />
<PackageReference Include="IndicoClient" Version="2.1.0" />
<PackageReference Include="IndicoClient" Version="2.4.0-alpha1" />
<!--workaround: required so nuget packages have all required dependencies-->
</ItemGroup>

Expand All @@ -152,5 +156,5 @@
<DependentUpon>Resources.resx</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="..\..\Shared\Indico.UiPath.Shared.Activities.Design\Indico.UiPath.Shared.Activities.Design.projitems" Label="Shared" />
<Import Project="..\..\Shared\UiPath.Shared.Activities.Design\UiPath.Shared.Activities.Design.projitems" Label="Shared" />
</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace UiPath.Shared.Localization
namespace Indico.UiPath.Shared.Localization
{
class SharedResources : Indico.RPAActivities.Activities.Design.Properties.Resources
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,72 @@
using System.Activities;
using System;
using System.Activities;
using System.Threading;
using System.Threading.Tasks;
using Indico.RPAActivities.Activities.Properties;
using Indico.UiPath.Shared.Activities;
using Indico.UiPath.Shared.Activities.RuntimeSimple;
using Indico.UiPath.Shared.Activities.Localization;
using Indico.UiPath.Shared.Activities.Utilities;

namespace Indico.RPAActivities.Activities.Activities
{
public abstract class IndicoActivityBase<TInput, TOutput> : TaskActivity<TInput, TOutput>
public abstract class IndicoActivityBase<TInput, TOutput> : ContinuableAsyncCodeActivity
{
protected Application Application { get; private set; }
/// <summary>
/// If set, continue executing the remaining activities even if the current activity has failed.
/// </summary>
[LocalizedCategory(nameof(Resources.Common_Category))]
[LocalizedDisplayName(nameof(Resources.ContinueOnError_DisplayName))]
[LocalizedDescription(nameof(Resources.ContinueOnError_Description))]
public override InArgument<bool> ContinueOnError { get; set; }

[LocalizedCategory(nameof(Resources.Common_Category))]
[LocalizedDisplayName(nameof(Resources.Timeout_DisplayName))]
[LocalizedDescription(nameof(Resources.Timeout_Description))]
public InArgument<int> TimeoutMS { get; set; } = 60000;

protected IndicoActivityBase()
{
Constraints.Add(ActivityConstraints.HasParentType<IndicoActivityBase<TInput, TOutput>, IndicoScope>(string.Format(Resources.ValidationScope_Error, Resources.IndicoScope_DisplayName)));
}

protected override void Init(AsyncCodeActivityContext context)
{
base.Init(context);
protected abstract TInput GetInputs(AsyncCodeActivityContext ctx);

var objectContainer = context.GetFromContext<IObjectContainer>(IndicoScope.ParentContainerPropertyTag);
protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
{
IObjectContainer objectContainer = context.GetFromContext<IObjectContainer>(IndicoScope.ParentContainerPropertyTag);
Application = objectContainer.Get<Application>();
return base.BeginExecute(context, callback, state);
}

protected override async Task<Action<AsyncCodeActivityContext>> ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
{
// Inputs
int timeout = TimeoutMS.Get(context);

CancellationTokenSource cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
cts.CancelAfter(timeout);

// Set a timeout on the execution
Task<TOutput> task = ExecuteWithTimeout(GetInputs(context), cts.Token);
Task timer = Task.Delay(timeout, cts.Token);
Task completedTask = await Task.WhenAny(task, timer);
if (completedTask == task)
{
// Outputs
return (ctx) =>
{
SetResults(ctx, task.Result);
};
}

else
{
throw new TimeoutException(Resources.Timeout_Error);
}

}
protected abstract void SetResults(AsyncCodeActivityContext context, TOutput result);
protected abstract Task<TOutput> ExecuteWithTimeout(TInput inputs, CancellationToken cancellationToken = default);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace Indico.RPAActivities.Activities
{
[LocalizedCategory(nameof(Resources.OCRCategory))]
[LocalizedDisplayName(nameof(Resources.DocumentExtraction_DisplayName))]
[LocalizedDescription(nameof(Resources.DocumentExtraction_Description))]
public class DocumentExtraction : IndicoActivityBase<(DocumentExtractionPreset Preset, string Document), string>
Expand All @@ -28,14 +27,14 @@ public class DocumentExtraction : IndicoActivityBase<(DocumentExtractionPreset P
[LocalizedDescription(nameof(Resources.DocumentExtraction_Results_Description))]
[LocalizedCategory(nameof(Resources.Output_Category))]
public OutArgument<string> Results { get; set; }

protected override (DocumentExtractionPreset Preset, string Document) GetInputs(AsyncCodeActivityContext ctx) =>
(Preset.Get(ctx), Document.Get(ctx));

protected override async Task<string> ExecuteAsync((DocumentExtractionPreset Preset, string Document) input, CancellationToken cancellationToken)
protected override async Task<string> ExecuteWithTimeout((DocumentExtractionPreset Preset, string Document) input, CancellationToken cancellationToken)
=> await Application.ExtractDocument(input.Document, input.Preset, cancellationToken);

protected override void SetOutputs(AsyncCodeActivityContext ctx, string output) => Results.Set(ctx, output);
protected override void SetResults(AsyncCodeActivityContext ctx, string output) => Results.Set(ctx, output);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

namespace Indico.RPAActivities.Activities
{
[LocalizedCategory(nameof(Resources.SubmissionCategory))]
[LocalizedDisplayName(nameof(Resources.GenerateSubmissionResult_DisplayName))]
[LocalizedDescription(nameof(Resources.GenerateSubmissionResult_Description))]
public class GenerateSubmissionResult : IndicoActivityBase<int, string>
Expand All @@ -29,10 +28,10 @@ public class GenerateSubmissionResult : IndicoActivityBase<int, string>
protected override int GetInputs(AsyncCodeActivityContext ctx) =>
SubmissionID.Get(ctx);

protected override Task<string> ExecuteAsync(int input, CancellationToken cancellationToken) =>
Application.GenerateSubmissionResult(input, cancellationToken);
protected async override Task<string> ExecuteWithTimeout(int input, CancellationToken cancellationToken) =>
await Application.GenerateSubmissionResult(input, cancellationToken);

protected override void SetOutputs(AsyncCodeActivityContext ctx, string output) => Result.Set(ctx, output);
protected override void SetResults(AsyncCodeActivityContext ctx, string output) => Result.Set(ctx, output);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace Indico.RPAActivities.Activities
{
[LocalizedCategory(nameof(Resources.RootCategory))]
[LocalizedDisplayName(nameof(Resources.IndicoScope_DisplayName))]
[LocalizedDescription(nameof(Resources.IndicoScope_Description))]
public class IndicoScope : NativeActivity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@

namespace Indico.RPAActivities.Activities
{
[LocalizedCategory(nameof(Resources.PreparationCategory))]

[LocalizedDisplayName(nameof(Resources.ListDatasets_DisplayName))]
[LocalizedDescription(nameof(Resources.ListDatasets_Description))]
public class ListDatasets : IndicoActivityBase<bool, List<IDataSetFull>>
public class ListDatasets : IndicoActivityBase<bool, IEnumerable<IDataSetFull>>
{
[LocalizedDisplayName(nameof(Resources.ListDatasets_Datasets_DisplayName))]
[LocalizedDescription(nameof(Resources.ListDatasets_Datasets_Description))]
[LocalizedCategory(nameof(Resources.Output_Category))]
public OutArgument<List<IDataSetFull>> Datasets { get; set; }

protected override bool GetInputs(AsyncCodeActivityContext ctx) => true; // no input, using dummy bool

protected override async Task<List<IDataSetFull>> ExecuteAsync(bool input, CancellationToken cancellationToken) =>
(await Application.ListDatasets(cancellationToken)).ToList();
protected override async Task<IEnumerable<IDataSetFull>> ExecuteWithTimeout(bool input, CancellationToken cancellationToken) =>
await Application.ListDatasets(cancellationToken);

protected override void SetOutputs(AsyncCodeActivityContext ctx, List<IDataSetFull> output) =>
Datasets.Set(ctx, output);
protected override void SetResults(AsyncCodeActivityContext ctx, IEnumerable<IDataSetFull> output) =>
Datasets.Set(ctx, output.ToList());
}
}

Loading

0 comments on commit 4e7d093

Please sign in to comment.