Skip to content

Commit

Permalink
Merge branch 'Excercise05-after'
Browse files Browse the repository at this point in the history
  • Loading branch information
pluskal committed Nov 24, 2017
2 parents 834dbff + 9e5e05e commit 5dcd5ab
Show file tree
Hide file tree
Showing 121 changed files with 4,655 additions and 29 deletions.
29 changes: 0 additions & 29 deletions Labs/IW5-Excercise-02/README.md

This file was deleted.

3 changes: 3 additions & 0 deletions Labs/IW5-Excercise-03/CleanCode.pptx
Git LFS file not shown
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CleanCodeSample", "CleanCodeSample\CleanCodeSample.csproj", "{3E9DD469-D148-4AB9-A00B-7843B6B6DC0E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3E9DD469-D148-4AB9-A00B-7843B6B6DC0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3E9DD469-D148-4AB9-A00B-7843B6B6DC0E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3E9DD469-D148-4AB9-A00B-7843B6B6DC0E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3E9DD469-D148-4AB9-A00B-7843B6B6DC0E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?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>{3E9DD469-D148-4AB9-A00B-7843B6B6DC0E}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CleanCodeSample</RootNamespace>
<AssemblyName>CleanCodeSample</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="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ConsoleHelper.cs" />
<Compile Include="MathExcercisesProgram.cs" />
<Compile Include="MathExcercise\AdditionMathExcercise.cs" />
<Compile Include="MathExcercise\IMathExcercise.cs" />
<Compile Include="MathExcercise\MathExcerciseRunner.cs" />
<Compile Include="MathExcercise\MultiplicationMathExcercise.cs" />
<Compile Include="MathExcercise\SubstractionMathExcercise.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;

namespace CleanCodeSample
{
public class ConsoleHelper
{

public int ReadNumber(string message)
{
Console.Write(message);
int input;
if (!int.TryParse(Console.ReadLine(), out input))
{
return ReadNumber(message);
}
return input;
}

public void WriteColorLine(ConsoleColor foregroundColor, string message)
{
var previouslyForegroundColor = Console.ForegroundColor;
Console.ForegroundColor = foregroundColor;
Console.WriteLine(message);
Console.ForegroundColor = previouslyForegroundColor;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace CleanCodeSample.MathExcercise
{
class AdditionMathExcercise : IMathExcercise
{
public char Operand { get; } = '+';
public string OperationName { get; } = "sčítání";

public int GetCorrectResult(int leftOperand, int rightOperand)
{
return leftOperand + rightOperand;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace CleanCodeSample.MathExcercise
{
public interface IMathExcercise
{
char Operand { get; }
string OperationName { get; }
int GetCorrectResult(int leftOperand, int rightOperand);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;

namespace CleanCodeSample.MathExcercise
{
class MathExcerciseRunner
{
protected ConsoleHelper consoleHelper = new ConsoleHelper();

public void Test(IMathExcercise mathExcercise)
{
var leftOperand = consoleHelper.ReadNumber($"Zadejte 1. číslo pro {mathExcercise.OperationName}: ");
var rightOperand = consoleHelper.ReadNumber($"Zadejte 2. číslo pro {mathExcercise.OperationName}: ");

var askForSolution = $"{leftOperand} {mathExcercise.Operand} {rightOperand} = ";
var userAnswer = consoleHelper.ReadNumber(askForSolution);

var correctResult = mathExcercise.GetCorrectResult(leftOperand, rightOperand);
WriteResultMessage(correctResult, userAnswer);
}

private void WriteResultMessage(int correctResult, int userAnswer)
{
var wasUserAnswerCorrect = correctResult == userAnswer;
var wasAnswerCorrectMessage = GetWasAnswerCorrectMessage(wasUserAnswerCorrect);
var messageColor = GetMessageColor(wasUserAnswerCorrect);

string message = $"Vaše odpověď \"{userAnswer}\" {wasAnswerCorrectMessage}";
consoleHelper.WriteColorLine(messageColor, message);
}

private static ConsoleColor GetMessageColor(bool wasUserAnswerCorrect)
{
return wasUserAnswerCorrect ? ConsoleColor.Green : ConsoleColor.Red;
}

private static string GetWasAnswerCorrectMessage(bool wasUserAnswerCorrect)
{
return wasUserAnswerCorrect ? "byla správná" : "nebyla správná";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace CleanCodeSample.MathExcercise
{
class MultiplicationMathExcercise : IMathExcercise
{
public char Operand { get; } = '*';
public string OperationName { get; } = "násobení";

public int GetCorrectResult(int leftOperand, int rightOperand)
{
return leftOperand * rightOperand;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace CleanCodeSample.MathExcercise
{
class SubstractionMathExcercise : IMathExcercise
{
public char Operand { get; } = '-';
public string OperationName { get; } = "odčítání";

public int GetCorrectResult(int leftOperand, int rightOperand)
{
return leftOperand - rightOperand;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections.Generic;
using CleanCodeSample.MathExcercise;

namespace CleanCodeSample
{
class MathExcercisesProgram
{
private readonly List<IMathExcercise> mathExcercises = new List<IMathExcercise>
{
new AdditionMathExcercise(),
new SubstractionMathExcercise(),
new MultiplicationMathExcercise()
};

public void Run()
{
var mathExcerciseRunner = new MathExcerciseRunner();
foreach (var mathExcercise in mathExcercises)
{
mathExcerciseRunner.Test(mathExcercise);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CleanCodeSample
{
class Program
{
static void Main(string[] args)
{
var mathExcercisesProgram = new MathExcercisesProgram();
mathExcercisesProgram.Run();

Console.ReadKey();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("CleanCodeSample")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CleanCodeSample")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("39b2ae37-4084-4a0a-9f83-938ea370bb67")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
23 changes: 23 additions & 0 deletions Labs/IW5-Excercise-05/CookBook.App/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<add name="CookBookContext" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=CookBookDB;MultipleActiveResultSets=True;Integrated Security=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
12 changes: 12 additions & 0 deletions Labs/IW5-Excercise-05/CookBook.App/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Application x:Class="CookBook.App.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:CookBook.App.Converters"
xmlns:app="clr-namespace:CookBook.App"
StartupUri="Views/MainWindow.xaml">
<Application.Resources>
<converters:TimeSpanToMinutesConverter x:Key="TimeSpanToMinutesConverter"/>
<converters:NullToVisibilityConverter x:Key="NullToVisibilityConverter"/>
<app:ViewModelLocator x:Key="ViewModelLocator" />
</Application.Resources>
</Application>
11 changes: 11 additions & 0 deletions Labs/IW5-Excercise-05/CookBook.App/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Windows;

namespace CookBook.App
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}
Loading

0 comments on commit 5dcd5ab

Please sign in to comment.