Permalink
Browse files

SPRNET-1536 add SPRNET-CODECONFIG migration sample to reinforce the docs

  • Loading branch information...
1 parent 805d384 commit 8faaf64c7c1c14cc91f609570baf94506926e84c @sbohlen sbohlen committed Jan 8, 2013
Showing with 1,334 additions and 0 deletions.
  1. +32 −0 examples/Spring/Spring.CodeConfig.Migration/Spring.CodeConfig.Migration.2008.sln
  2. +32 −0 examples/Spring/Spring.CodeConfig.Migration/Spring.CodeConfig.Migration.2010.sln
  3. +40 −0 examples/Spring/Spring.CodeConfig.Migration/src/Primes/ConsoleReport.cs
  4. +9 −0 examples/Spring/Spring.CodeConfig.Migration/src/Primes/IOutputFormatter.cs
  5. +8 −0 examples/Spring/Spring.CodeConfig.Migration/src/Primes/IPrimeGenerator.cs
  6. +45 −0 examples/Spring/Spring.CodeConfig.Migration/src/Primes/LinqPrimeGenerator.cs
  7. +50 −0 examples/Spring/Spring.CodeConfig.Migration/src/Primes/OutputFormatter.cs
  8. +28 −0 examples/Spring/Spring.CodeConfig.Migration/src/Primes/PrimeEvaluationEngine.cs
  9. +37 −0 examples/Spring/Spring.CodeConfig.Migration/src/Primes/PrimeGenerator.cs
  10. +69 −0 examples/Spring/Spring.CodeConfig.Migration/src/Primes/Primes.2008.csproj
  11. +70 −0 examples/Spring/Spring.CodeConfig.Migration/src/Primes/Primes.2010.csproj
  12. +36 −0 examples/Spring/Spring.CodeConfig.Migration/src/Primes/Properties/AssemblyInfo.cs
  13. +6 −0 examples/Spring/Spring.CodeConfig.Migration/src/SpringApp/App.config
  14. +32 −0 examples/Spring/Spring.CodeConfig.Migration/src/SpringApp/PrimesConfiguration.cs
  15. +47 −0 examples/Spring/Spring.CodeConfig.Migration/src/SpringApp/Program.cs
  16. +36 −0 examples/Spring/Spring.CodeConfig.Migration/src/SpringApp/Properties/AssemblyInfo.cs
  17. +113 −0 examples/Spring/Spring.CodeConfig.Migration/src/SpringApp/SpringApp.2008.csproj
  18. +114 −0 examples/Spring/Spring.CodeConfig.Migration/src/SpringApp/SpringApp.2010.csproj
  19. +19 −0 examples/Spring/Spring.CodeConfig.Migration/src/SpringApp/application-context.xml
  20. +105 −0 examples/Spring/Spring.CodeConfig.Migration/test/Primes.Tests/Primes.Tests.2008.csproj
  21. +106 −0 examples/Spring/Spring.CodeConfig.Migration/test/Primes.Tests/Primes.Tests.2010.csproj
  22. +17 −0 ...g/Spring.CodeConfig.Migration/test/Primes.Tests/Primes/EvaluationEngine/When_Candidate_Is_Even.cs
  23. +17 −0 ...ring.CodeConfig.Migration/test/Primes.Tests/Primes/EvaluationEngine/When_Candidate_Is_Negative.cs
  24. +17 −0 ...ng/Spring.CodeConfig.Migration/test/Primes.Tests/Primes/EvaluationEngine/When_Candidate_Is_One.cs
  25. +17 −0 ...ng/Spring.CodeConfig.Migration/test/Primes.Tests/Primes/EvaluationEngine/When_Candidate_Is_Two.cs
  26. +17 −0 ...g/Spring.CodeConfig.Migration/test/Primes.Tests/Primes/EvaluationEngine/When_Candidate_Is_Zero.cs
  27. +17 −0 ...odeConfig.Migration/test/Primes.Tests/Primes/EvaluationEngine/When_Constructing_PrimeEvaluator.cs
  28. +29 −0 ...Spring.CodeConfig.Migration/test/Primes.Tests/Primes/EvaluationEngine/When_Number_is_evaluated.cs
  29. +17 −0 ...ing/Spring.CodeConfig.Migration/test/Primes.Tests/Primes/Formatter/When_Constructing_Formatter.cs
  30. +63 −0 ...s/Spring/Spring.CodeConfig.Migration/test/Primes.Tests/Primes/Formatter/When_Formatting_Output.cs
  31. +19 −0 ...pring.CodeConfig.Migration/test/Primes.Tests/Primes/Generator/When_Calculating_Range_Of_Primes.cs
  32. +17 −0 ...ing/Spring.CodeConfig.Migration/test/Primes.Tests/Primes/Generator/When_Constructing_Generator.cs
  33. +17 −0 ...g/Spring.CodeConfig.Migration/test/Primes.Tests/Primes/Generator/When_No_Primes_Found_In_Range.cs
  34. +36 −0 examples/Spring/Spring.CodeConfig.Migration/test/Primes.Tests/Properties/AssemblyInfo.cs
@@ -0,0 +1,32 @@
+
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Primes", "src\Primes\Primes.2008.csproj", "{865E1A8E-88F3-48D8-869F-B584C5A36740}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Primes.Tests", "test\Primes.Tests\Primes.Tests.2008.csproj", "{32476935-0852-4A11-B938-4D202D8B4454}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpringApp", "src\SpringApp\SpringApp.2008.csproj", "{08A8AC17-E5E1-48FC-9958-76ECA8C08D71}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {865E1A8E-88F3-48D8-869F-B584C5A36740}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {865E1A8E-88F3-48D8-869F-B584C5A36740}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {865E1A8E-88F3-48D8-869F-B584C5A36740}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {865E1A8E-88F3-48D8-869F-B584C5A36740}.Release|Any CPU.Build.0 = Release|Any CPU
+ {32476935-0852-4A11-B938-4D202D8B4454}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {32476935-0852-4A11-B938-4D202D8B4454}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {32476935-0852-4A11-B938-4D202D8B4454}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {32476935-0852-4A11-B938-4D202D8B4454}.Release|Any CPU.Build.0 = Release|Any CPU
+ {08A8AC17-E5E1-48FC-9958-76ECA8C08D71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {08A8AC17-E5E1-48FC-9958-76ECA8C08D71}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {08A8AC17-E5E1-48FC-9958-76ECA8C08D71}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {08A8AC17-E5E1-48FC-9958-76ECA8C08D71}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
@@ -0,0 +1,32 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Primes", "src\Primes\Primes.2010.csproj", "{865E1A8E-88F3-48D8-869F-B584C5A36740}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Primes.Tests", "test\Primes.Tests\Primes.Tests.2010.csproj", "{32476935-0852-4A11-B938-4D202D8B4454}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpringApp", "src\SpringApp\SpringApp.2010.csproj", "{08A8AC17-E5E1-48FC-9958-76ECA8C08D71}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {865E1A8E-88F3-48D8-869F-B584C5A36740}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {865E1A8E-88F3-48D8-869F-B584C5A36740}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {865E1A8E-88F3-48D8-869F-B584C5A36740}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {865E1A8E-88F3-48D8-869F-B584C5A36740}.Release|Any CPU.Build.0 = Release|Any CPU
+ {32476935-0852-4A11-B938-4D202D8B4454}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {32476935-0852-4A11-B938-4D202D8B4454}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {32476935-0852-4A11-B938-4D202D8B4454}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {32476935-0852-4A11-B938-4D202D8B4454}.Release|Any CPU.Build.0 = Release|Any CPU
+ {08A8AC17-E5E1-48FC-9958-76ECA8C08D71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {08A8AC17-E5E1-48FC-9958-76ECA8C08D71}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {08A8AC17-E5E1-48FC-9958-76ECA8C08D71}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {08A8AC17-E5E1-48FC-9958-76ECA8C08D71}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+
+namespace Primes
+{
+ public class ConsoleReport
+ {
+ private IOutputFormatter _outputFormatter;
+
+ private IPrimeGenerator _primeGenerator;
+
+ private int _maxNumber;
+
+ public ConsoleReport(IOutputFormatter outputFormatter, IPrimeGenerator primeGenerator)
+ {
+ _outputFormatter = outputFormatter;
+ _primeGenerator = primeGenerator;
+ }
+ public IOutputFormatter OutputFormatter
+ {
+ set { _outputFormatter = value; }
+ }
+
+ public int MaxNumber
+ {
+ get { return _maxNumber; }
+ set { _maxNumber = value; }
+ }
+
+ public void Write()
+ {
+ IList<string> results = _outputFormatter.Format(_primeGenerator.GeneratePrimesUpTo(_maxNumber));
+
+ foreach (string item in results)
+ {
+ Console.WriteLine(item);
+ }
+ }
+ }
+}
@@ -0,0 +1,9 @@
+using System.Collections.Generic;
+
+namespace Primes
+{
+ public interface IOutputFormatter
+ {
+ IList<string> Format(string input);
+ }
+}
@@ -0,0 +1,8 @@
+namespace Primes
+{
+ public interface IPrimeGenerator
+ {
+ string GeneratePrimesUpTo(int max);
+ }
+
+}
@@ -0,0 +1,45 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Primes
+{
+ public class LinqPrimeGenerator : IPrimeGenerator
+ {
+ #region IPrimeGenerator Members
+
+ public string GeneratePrimesUpTo(int maxNumber)
+ {
+
+ var sb = new StringBuilder();
+
+ if (maxNumber <= 0)
+ {
+ return sb.ToString();
+ }
+
+ Func<int, IEnumerable<int>> primeNumbers = max =>
+ from i in Enumerable.Range(2, max - 1)
+ where Enumerable.Range(2, i - 2).All(j => i%j != 0)
+ select i;
+
+ IEnumerable<int> result = primeNumbers(maxNumber);
+
+ foreach (int i in result)
+ {
+ sb.Append(i.ToString());
+ sb.Append(",");
+ }
+
+ string theString = sb.ToString();
+
+ if (theString.Contains(","))
+ theString = theString.Remove(theString.LastIndexOf(","));
+
+ return theString;
+ }
+
+ #endregion
+ }
+}
@@ -0,0 +1,50 @@
+using System.Collections.Generic;
+using System.Text;
+
+namespace Primes
+{
+ public class OutputFormatter : IOutputFormatter
+ {
+ public IList<string> Format(string input)
+ {
+ string[] elements = input.Split(",".ToCharArray());
+
+ IList<string> result = new List<string>();
+
+ int lineCount = 0;
+
+ for (int i = 0; i < elements.Length; i += 5)
+ {
+
+ var sb = new StringBuilder();
+
+ for (int j = i; j < i + 5; j++)
+ {
+ sb.Append(elements[j]);
+ sb.Append(",");
+ if (j == elements.Length - 1)
+ break;
+ }
+
+ string theString = sb.ToString();
+
+ if (theString.EndsWith(","))
+ theString = theString.Substring(0, theString.Length - 1);
+
+ if (lineCount > 0 && (lineCount % 10 == 0))
+ result.Add("Count: " + i);
+
+ lineCount += 1;
+
+ result.Add(theString);
+ }
+
+
+ return result;
+ }
+
+
+
+
+ }
+}
@@ -0,0 +1,28 @@
+using System;
+
+namespace Primes
+{
+ public class PrimeEvaluationEngine
+ {
+ public bool IsPrime(int candidate)
+ {
+ if (candidate <= 1)
+ return false;
+
+ if (candidate == 2)
+ return true;
+
+ if (candidate % 2 == 0)
+ return false;
+
+ for (int i = 3; i < Math.Sqrt(candidate); i += 2)
+ {
+ if (candidate % i == 0)
+ return false;
+ }
+
+
+ return true;
+ }
+ }
+}
@@ -0,0 +1,37 @@
+using System.Text;
+
+namespace Primes
+{
+ public class PrimeGenerator : IPrimeGenerator
+ {
+ private PrimeEvaluationEngine _primeEvaluationEngine;
+
+ public string GeneratePrimesUpTo(int max)
+ {
+
+ var sb = new StringBuilder();
+
+ for (int i = 0; i < max; i++)
+ {
+ if (_primeEvaluationEngine.IsPrime(i))
+ {
+ sb.Append(i.ToString());
+ sb.Append(",");
+ }
+ }
+
+ string theString = sb.ToString();
+
+ if (theString.Contains(","))
+ theString = theString.Remove(theString.LastIndexOf(","));
+
+ return theString;
+ }
+
+
+ public PrimeGenerator(PrimeEvaluationEngine primeEvaluationEngine)
+ {
+ _primeEvaluationEngine = primeEvaluationEngine;
+ }
+ }
+}
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{865E1A8E-88F3-48D8-869F-B584C5A36740}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Primes</RootNamespace>
+ <AssemblyName>Primes</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <FileUpgradeFlags>
+ </FileUpgradeFlags>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <UpgradeBackupLocation />
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <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' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Core">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Xml.Linq">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Data.DataSetExtensions">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="IOutputFormatter.cs" />
+ <Compile Include="IPrimeGenerator.cs" />
+ <Compile Include="LinqPrimeGenerator.cs" />
+ <Compile Include="OutputFormatter.cs" />
+ <Compile Include="PrimeEvaluationEngine.cs" />
+ <Compile Include="PrimeGenerator.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="ConsoleReport.cs" />
+ </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>
Oops, something went wrong.

0 comments on commit 8faaf64

Please sign in to comment.