Skip to content

Commit 748431c

Browse files
creation.
0 parents  commit 748431c

File tree

7 files changed

+209
-0
lines changed

7 files changed

+209
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bin
2+
obj
3+
.vs

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# RobotApi
2+
3+
Robot API を使ったサンプルプログラムを収録します。
4+
5+
## RunInParallel
6+
7+
コマンド行引数で与えられたプロセス名のプロセスを並列実行するコンソールアプリケーションです。
8+
9+
なお、フォアグラウンドプロセスは1個まで実行できます。2個目の実行を試みるとエラーとなります。
10+
11+
バックグランドプロセスは1個以上実行できます。

RobotApi.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.27703.2035
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RunInParallel", "RunInParallel\RunInParallel.csproj", "{6906D12B-E7BB-484E-AEEF-BC41DED994F8}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{6906D12B-E7BB-484E-AEEF-BC41DED994F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{6906D12B-E7BB-484E-AEEF-BC41DED994F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{6906D12B-E7BB-484E-AEEF-BC41DED994F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{6906D12B-E7BB-484E-AEEF-BC41DED994F8}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {01BC7F3A-32B2-47C5-9656-8986198BA437}
24+
EndGlobalSection
25+
EndGlobal

RunInParallel/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
5+
</startup>
6+
</configuration>

RunInParallel/Program.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using UiPath.Robot.Api;
6+
7+
namespace RunInParallel
8+
{
9+
class Program
10+
{
11+
/// <summary>
12+
/// Runs the designated process asynchronously.
13+
/// </summary>
14+
/// <param name="processName">Name of the process to run</param>
15+
/// <returns>Task with JobOutput</returns>
16+
private static async Task<JobOutput> RunAsync(string processName)
17+
{
18+
try
19+
{
20+
var client = new RobotClient();
21+
var processes = await client.GetProcesses();
22+
var myProcess = processes.Single(process => process.Name == processName);
23+
var job = myProcess.ToJob();
24+
return await client.RunJob(job);
25+
}
26+
catch (Exception ex)
27+
{
28+
Console.Error.WriteLine("{0}", ex.ToString());
29+
return null;
30+
}
31+
}
32+
33+
/// <summary>
34+
/// Writes the output parameters in a JSON-like format to the standard output.
35+
/// </summary>
36+
/// <param name="output">JobOutput returned by the completed task</param>
37+
private static void PrintOutput(JobOutput output)
38+
{
39+
if (output == null || output.Arguments == null || output.Arguments.Count <= 0)
40+
{
41+
return;
42+
}
43+
int index = 0;
44+
Console.Write("{");
45+
foreach (KeyValuePair<string, object> kv in output.Arguments)
46+
{
47+
Console.Write("{0}\"{1}\": \"{2}\"", index++ == 0 ? " " : ", ", kv.Key, kv.Value);
48+
}
49+
Console.WriteLine(" }");
50+
}
51+
52+
/// <summary>
53+
/// Runs processes asynchronously and writes the output parameters to the standard output.
54+
/// Processes should be given at the command line.
55+
/// </summary>
56+
/// <param name="args">Names of the process to run asynchronously</param>
57+
static void Main(string[] args)
58+
{
59+
var tasks = new List<Task<JobOutput>>();
60+
foreach (var processName in args)
61+
{
62+
tasks.Add(RunAsync(processName));
63+
}
64+
while (tasks.Count > 0)
65+
{
66+
var index = Task.WaitAny(tasks.ToArray());
67+
var task = tasks[index];
68+
PrintOutput(task.Result);
69+
tasks.RemoveAt(index);
70+
}
71+
}
72+
}
73+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// アセンブリに関する一般情報は以下の属性セットをとおして制御されます。
6+
// アセンブリに関連付けられている情報を変更するには、
7+
// これらの属性値を変更してください。
8+
[assembly: AssemblyTitle("RunInParallel")]
9+
[assembly: AssemblyDescription("Starts UiPath Robot to run processes (workflows) in parallel")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("UiPath")]
12+
[assembly: AssemblyProduct("RunInParallel")]
13+
[assembly: AssemblyCopyright("Copyright © 2019 UiPath")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// ComVisible を false に設定すると、このアセンブリ内の型は COM コンポーネントから
18+
// 参照できなくなります。COM からこのアセンブリ内の型にアクセスする必要がある場合は、
19+
// その型の ComVisible 属性を true に設定してください。
20+
[assembly: ComVisible(false)]
21+
22+
// このプロジェクトが COM に公開される場合、次の GUID が typelib の ID になります
23+
[assembly: Guid("6906d12b-e7bb-484e-aeef-bc41ded994f8")]
24+
25+
// アセンブリのバージョン情報は次の 4 つの値で構成されています:
26+
//
27+
// メジャー バージョン
28+
// マイナー バージョン
29+
// ビルド番号
30+
// Revision
31+
//
32+
// すべての値を指定するか、次を使用してビルド番号とリビジョン番号を既定に設定できます
33+
// 既定値にすることができます:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

RunInParallel/RunInParallel.csproj

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{6906D12B-E7BB-484E-AEEF-BC41DED994F8}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>UiPathTeam.RunInParallel</RootNamespace>
10+
<AssemblyName>RunInParallel</AssemblyName>
11+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<PlatformTarget>AnyCPU</PlatformTarget>
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="System" />
36+
<Reference Include="System.Core" />
37+
<Reference Include="System.Xml.Linq" />
38+
<Reference Include="System.Data.DataSetExtensions" />
39+
<Reference Include="Microsoft.CSharp" />
40+
<Reference Include="System.Data" />
41+
<Reference Include="System.Net.Http" />
42+
<Reference Include="System.Xml" />
43+
<Reference Include="UiPath.Robot.Api">
44+
<HintPath>..\..\..\..\Program Files (x86)\UiPath\Studio\UiPath.Robot.Api.dll</HintPath>
45+
</Reference>
46+
</ItemGroup>
47+
<ItemGroup>
48+
<Compile Include="Program.cs" />
49+
<Compile Include="Properties\AssemblyInfo.cs" />
50+
</ItemGroup>
51+
<ItemGroup>
52+
<None Include="App.config" />
53+
</ItemGroup>
54+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
55+
</Project>

0 commit comments

Comments
 (0)