Skip to content

Commit

Permalink
Merge pull request petabridge#30 from Aaronontheweb/unit2
Browse files Browse the repository at this point in the history
Akka.NET Bootcamp Unit 2!
  • Loading branch information
Aaronontheweb committed Feb 28, 2015
2 parents 436479a + 06da81b commit 0a7c0a6
Show file tree
Hide file tree
Showing 132 changed files with 8,634 additions and 265 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,20 @@ In Unit 1 you will learn:

**[Begin Unit 1](src/Unit-1)**.

### Unit 2 (TBA)
### Unit 2
In Unit 2, we're going to get into some more of the intermediate Akka.NET features to build a more sophisticated application than what we accomplished at the end of unit 1.

In Unit 2 you will learn:

1. How to use `ReceiveActor` to handle more complex message matches;
2. How (and why) to change your actors' behaviors at run-time;
3. How to use `Stash` with your actors to defer processing of messages until they're ready;
3. How to handle system failures gracefully;
4. How to configure and use logging inside your actors; and
5. How to use HOCON configuration inside your `ActorSystem`.
1. How to use [HOCON configuration](http://getakka.net/wiki/Configuration "Akka.NET HOCON Configurations") to configure your actors via App.config and Web.config;
1. How to configure your actor's [Dispatcher](http://getakka.net/wiki/Dispatchers) to run on the Windows Forms UI thread, so actors can make operations directly on UI elements without needing to change contexts;
1. How to handle more sophisticated types of pattern matching using `ReceiveActor`;
1. How to use the `Scheduler` to send recurring messages to actors;
1. How to use the [Publish-subscribe (pub-sub) pattern](http://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern) between actors;
1. How and why to switch actor's behavior at run-time; and
2. How to `Stash` messages for deferred processing.

> NOTE: Unit 2 is not yet available.
**[Begin Unit 2](src/Unit-2)**.

### Unit 3 (TBA)
In Unit 3, we will learn to make our system more scalable and resilient.
Expand Down
4 changes: 2 additions & 2 deletions src/Unit-1/lesson6/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ That's it! Hit `F5` to run the solution and it should work exactly the same as b
Compare your code to the solution in the [Completed](Completed/) folder to see what the instructors included in their samples.

## Great job!
### WOW! YOU WIN! Phenomenal work finishing Unit 1. Now go enjoy a well-deserved break, and gear up for Unit 2!
### WOW! YOU WIN! Phenomenal work finishing Unit 1.

[Sign up here for email updates for when Unit 2 is ready](http://learnakka.net/)!
**Ready for more? [Start Unit 2 now](../../Unit-2 "Akka.NET Bootcamp Unit 2").**

## Any questions?
[Create an issue](/issues) and let us know. We'll get right on it, and it will benefit other people going through Bootcamp.
Expand Down
74 changes: 74 additions & 0 deletions src/Unit-2/DoThis/Actors/ChartingActor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms.DataVisualization.Charting;
using Akka.Actor;

namespace ChartApp.Actors
{
public class ChartingActor : UntypedActor
{
#region Messages

public class InitializeChart
{
public InitializeChart(Dictionary<string, Series> initialSeries)
{
InitialSeries = initialSeries;
}

public Dictionary<string, Series> InitialSeries { get; private set; }
}

#endregion

private readonly Chart _chart;
private Dictionary<string, Series> _seriesIndex;

public ChartingActor(Chart chart) : this(chart, new Dictionary<string, Series>())
{
}

public ChartingActor(Chart chart, Dictionary<string, Series> seriesIndex)
{
_chart = chart;
_seriesIndex = seriesIndex;
}

protected override void OnReceive(object message)
{
if (message is InitializeChart)
{
var ic = message as InitializeChart;
HandleInitialize(ic);
}
}

#region Individual Message Type Handlers

private void HandleInitialize(InitializeChart ic)
{
if (ic.InitialSeries != null)
{
//swap the two series out
_seriesIndex = ic.InitialSeries;
}

//delete any existing series
_chart.Series.Clear();

//attempt to render the initial chart
if (_seriesIndex.Any())
{
foreach (var series in _seriesIndex)
{
//force both the chart and the internal index to use the same names
series.Value.Name = series.Key;
_chart.Series.Add(series.Value);
}
}
}

#endregion
}
}
14 changes: 14 additions & 0 deletions src/Unit-2/DoThis/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
102 changes: 102 additions & 0 deletions src/Unit-2/DoThis/ChartApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{0868BCA7-9A52-4DFC-956E-AC048862C828}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ChartApp</RootNamespace>
<AssemblyName>ChartApp</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Akka, Version=0.8.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>packages\Akka.0.8.0\lib\net45\Akka.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Windows.Forms.DataVisualization" />
<Reference Include="System.Windows.Forms.DataVisualization.Design" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Actors\ChartingActor.cs" />
<Compile Include="ChartDataHelper.cs" />
<Compile Include="Main.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Main.Designer.cs">
<DependentUpon>Main.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Main.resx">
<DependentUpon>Main.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
25 changes: 25 additions & 0 deletions src/Unit-2/DoThis/ChartDataHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Linq;
using System.Windows.Forms.DataVisualization.Charting;
using Akka.Util;

namespace ChartApp
{
/// <summary>
/// Helper class for creating random data for chart plots
/// </summary>
public static class ChartDataHelper
{
public static Series RandomSeries(string seriesName, SeriesChartType type = SeriesChartType.Line, int points = 100)
{
var series = new Series(seriesName) {ChartType = type};
foreach (var i in Enumerable.Range(0, points))
{
var rng = ThreadLocalRandom.Current.NextDouble();
series.Points.Add(new DataPoint(i, 2.0*Math.Sin(rng) + Math.Sin(rng/4.5)));
}
series.BorderWidth = 3;
return series;
}
}
}
74 changes: 74 additions & 0 deletions src/Unit-2/DoThis/Main.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions src/Unit-2/DoThis/Main.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using Akka.Actor;
using Akka.Util.Internal;
using ChartApp.Actors;

namespace ChartApp
{
public partial class Main : Form
{
private ActorRef _chartActor;
private readonly AtomicCounter _seriesCounter = new AtomicCounter(1);

public Main()
{
InitializeComponent();
}

#region Initialization


private void Main_Load(object sender, EventArgs e)
{
_chartActor = Program.ChartActors.ActorOf(Props.Create(() => new ChartingActor(sysChart)), "charting");
var series = ChartDataHelper.RandomSeries("FakeSeries" + _seriesCounter.GetAndIncrement());
_chartActor.Tell(new ChartingActor.InitializeChart(new Dictionary<string, Series>()
{
{series.Name, series}
}));
}

#endregion

}
}
Loading

0 comments on commit 0a7c0a6

Please sign in to comment.