Skip to content

Commit

Permalink
docs: include Alice and Bob sample (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dermendzhiev authored Jun 21, 2021
1 parent 593357f commit ce25abd
Show file tree
Hide file tree
Showing 14 changed files with 274 additions and 1 deletion.
22 changes: 21 additions & 1 deletion Perper.sln
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E8B2046D-1D1
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{2724D8E7-2306-4DDD-9ECF-36504B7F9A7B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleAgent.UnitTests", "samples\simple-agent\tests\SimpleAgent.UnitTests\SimpleAgent.UnitTests.csproj", "{A4FAE3F8-8FF9-4629-BE97-2E238D507F77}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleAgent.UnitTests", "samples\simple-agent\tests\SimpleAgent.UnitTests\SimpleAgent.UnitTests.csproj", "{A4FAE3F8-8FF9-4629-BE97-2E238D507F77}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "alice-bob", "alice-bob", "{1381A50E-25E5-4CA4-B0C4-755130ED4123}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{F47BFD77-FCE2-457A-B89F-A8FD1EBCAB3F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Alice", "samples\alice-bob\src\Alice\Alice.csproj", "{131B428D-FEC6-458C-B8DA-AB7591B27C06}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bob", "samples\alice-bob\src\Bob\Bob.csproj", "{D7CE5E8E-7D53-42B1-955B-2528979E466F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -93,6 +101,14 @@ Global
{A4FAE3F8-8FF9-4629-BE97-2E238D507F77}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A4FAE3F8-8FF9-4629-BE97-2E238D507F77}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A4FAE3F8-8FF9-4629-BE97-2E238D507F77}.Release|Any CPU.Build.0 = Release|Any CPU
{131B428D-FEC6-458C-B8DA-AB7591B27C06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{131B428D-FEC6-458C-B8DA-AB7591B27C06}.Debug|Any CPU.Build.0 = Debug|Any CPU
{131B428D-FEC6-458C-B8DA-AB7591B27C06}.Release|Any CPU.ActiveCfg = Release|Any CPU
{131B428D-FEC6-458C-B8DA-AB7591B27C06}.Release|Any CPU.Build.0 = Release|Any CPU
{D7CE5E8E-7D53-42B1-955B-2528979E466F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D7CE5E8E-7D53-42B1-955B-2528979E466F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D7CE5E8E-7D53-42B1-955B-2528979E466F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D7CE5E8E-7D53-42B1-955B-2528979E466F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -116,6 +132,10 @@ Global
{E8B2046D-1D11-4AE3-8C65-761E3EC0F8FA} = {57371717-4EA6-4E88-8C96-3CC486E4EB10}
{2724D8E7-2306-4DDD-9ECF-36504B7F9A7B} = {57371717-4EA6-4E88-8C96-3CC486E4EB10}
{A4FAE3F8-8FF9-4629-BE97-2E238D507F77} = {2724D8E7-2306-4DDD-9ECF-36504B7F9A7B}
{1381A50E-25E5-4CA4-B0C4-755130ED4123} = {5EB01B9B-538D-4FC8-8FBC-90409087ED75}
{F47BFD77-FCE2-457A-B89F-A8FD1EBCAB3F} = {1381A50E-25E5-4CA4-B0C4-755130ED4123}
{131B428D-FEC6-458C-B8DA-AB7591B27C06} = {F47BFD77-FCE2-457A-B89F-A8FD1EBCAB3F}
{D7CE5E8E-7D53-42B1-955B-2528979E466F} = {F47BFD77-FCE2-457A-B89F-A8FD1EBCAB3F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A22B7103-08F7-4159-B4F9-076375D08D7A}
Expand Down
43 changes: 43 additions & 0 deletions samples/alice-bob/AliceBobAgents.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31313.79
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{177DF5E9-4645-4A7D-8988-111DAEAE825D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Alice", "src\Alice\Alice.csproj", "{E883F79F-001B-45A4-A9D3-881FF1746F79}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bob", "src\Bob\Bob.csproj", "{C7EAA8D2-234C-4519-9056-93E03894A0F0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Perper.WebJobs.Extensions", "..\..\functions\runtime\src\Perper.WebJobs.Extensions\Perper.WebJobs.Extensions.csproj", "{1F470F1D-17B6-457C-92BB-B5B271A3ACED}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E883F79F-001B-45A4-A9D3-881FF1746F79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E883F79F-001B-45A4-A9D3-881FF1746F79}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E883F79F-001B-45A4-A9D3-881FF1746F79}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E883F79F-001B-45A4-A9D3-881FF1746F79}.Release|Any CPU.Build.0 = Release|Any CPU
{C7EAA8D2-234C-4519-9056-93E03894A0F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C7EAA8D2-234C-4519-9056-93E03894A0F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C7EAA8D2-234C-4519-9056-93E03894A0F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C7EAA8D2-234C-4519-9056-93E03894A0F0}.Release|Any CPU.Build.0 = Release|Any CPU
{1F470F1D-17B6-457C-92BB-B5B271A3ACED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1F470F1D-17B6-457C-92BB-B5B271A3ACED}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1F470F1D-17B6-457C-92BB-B5B271A3ACED}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1F470F1D-17B6-457C-92BB-B5B271A3ACED}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{E883F79F-001B-45A4-A9D3-881FF1746F79} = {177DF5E9-4645-4A7D-8988-111DAEAE825D}
{C7EAA8D2-234C-4519-9056-93E03894A0F0} = {177DF5E9-4645-4A7D-8988-111DAEAE825D}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0E497321-8F18-458F-88E1-2C2AF584296A}
EndGlobalSection
EndGlobal
27 changes: 27 additions & 0 deletions samples/alice-bob/src/Alice/Alice.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.11" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\functions\runtime\src\Perper.WebJobs.Extensions\Perper.WebJobs.Extensions.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>

</Project>
36 changes: 36 additions & 0 deletions samples/alice-bob/src/Alice/Launcher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using Perper.WebJobs.Extensions.Model;
using Perper.WebJobs.Extensions.Triggers;

namespace Alice
{
public class Launcher
{
[FunctionName("Alice")]
public static async Task RunAsync(
[PerperTrigger] object input,
IContext context,
ILogger logger)
{
const string agentName = "Bob";
const string callerAgentNameParameter = "Alice";

var (agent, greeting) = await context.StartAgentAsync<string>(agentName, callerAgentNameParameter);
logger.LogInformation(greeting);

var randomNumber = await agent.CallFunctionAsync<int>("GetRandomNumber", (0, 100));
logger.LogInformation(randomNumber.ToString());

await agent.CallActionAsync("SaveMagicNumber", randomNumber);

var randomNumbersStream = await agent.CallFunctionAsync<IAsyncEnumerable<int>>("GetRandomNumbers", (0, 100));
await foreach (var number in randomNumbersStream)
{
logger.LogInformation(number.ToString());
}
}
}
}
8 changes: 8 additions & 0 deletions samples/alice-bob/src/Alice/host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"version": "2.0",
"logging": {
"logLevel": {
"Perper.WebJobs.Extensions": "Trace"
}
}
}
9 changes: 9 additions & 0 deletions samples/alice-bob/src/Alice/local.settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"PERPER_AGENT_NAME": "Alice",
"PERPER_ROOT_AGENT": "Alice"
}
}
27 changes: 27 additions & 0 deletions samples/alice-bob/src/Bob/Bob.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.11" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\functions\runtime\src\Perper.WebJobs.Extensions\Perper.WebJobs.Extensions.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>

</Project>
17 changes: 17 additions & 0 deletions samples/alice-bob/src/Bob/Calls/GetRandomNumber.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Perper.WebJobs.Extensions.Triggers;

namespace Bob.Calls
{
public class GetRandomNumber
{
[FunctionName("GetRandomNumber")]
public static async Task<int> RunAsync([PerperTrigger] (int min, int max) parameters)
{
var random = new Random();
return random.Next(parameters.min, parameters.max);
}
}
}
31 changes: 31 additions & 0 deletions samples/alice-bob/src/Bob/Calls/GetRandomNumbers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Perper.WebJobs.Extensions.Model;
using Perper.WebJobs.Extensions.Triggers;

namespace Bob.Calls
{
public class GetRandomNumbers
{
[FunctionName("GetRandomNumbers")]
public static async Task<IAsyncEnumerable<int>> RunAsync([PerperTrigger] (int min, int max) parameters,
IContext context)
{
return await context.StreamFunctionAsync<int>("GetRandomNumbersStream", parameters);
}

[FunctionName("GetRandomNumbersStream")]
public static async IAsyncEnumerable<int> GetRandomNumbersStream([PerperTrigger] (int min, int max) parameters)
{
var random = new Random();

while (true)
{
yield return random.Next(parameters.min, parameters.max);
await Task.Delay(1000);
}
}
}
}
16 changes: 16 additions & 0 deletions samples/alice-bob/src/Bob/Calls/SaveMagicNumber.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using Perper.WebJobs.Extensions.Triggers;

namespace Bob.Calls
{
public class SaveMagicNumber
{
[FunctionName("SaveMagicNumber")]
public static async Task RunAsync([PerperTrigger] int number, ILogger logger)
{
logger.LogInformation(number.ToString());
}
}
}
15 changes: 15 additions & 0 deletions samples/alice-bob/src/Bob/Launcher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Perper.WebJobs.Extensions.Triggers;

namespace Bob
{
public class Launcher
{
[FunctionName("Bob")]
public static async Task<string> RunAsync([PerperTrigger] string callerAgentName)
{
return $"Hello {callerAgentName}";
}
}
}
8 changes: 8 additions & 0 deletions samples/alice-bob/src/Bob/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"Bob": {
"commandName": "Project",
"commandLineArgs": "host start --port 7072 --pause-on-error"
}
}
}
8 changes: 8 additions & 0 deletions samples/alice-bob/src/Bob/host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"version": "2.0",
"logging": {
"logLevel": {
"Perper.WebJobs.Extensions": "Trace"
}
}
}
8 changes: 8 additions & 0 deletions samples/alice-bob/src/Bob/local.settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"PERPER_AGENT_NAME": "Bob"
}
}

0 comments on commit ce25abd

Please sign in to comment.