forked from petabridge/akka-bootcamp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request petabridge#30 from Aaronontheweb/unit2
Akka.NET Bootcamp Unit 2!
- Loading branch information
Showing
132 changed files
with
8,634 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} | ||
} |
Oops, something went wrong.