Dodano Stepa na wysypywanie smieci
This commit is contained in:
parent
e9476f7b2d
commit
e61eb1a87c
@ -41,6 +41,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Exceptions.cs" />
|
||||
<Compile Include="Interfaces\Enums\Directions.cs" />
|
||||
<Compile Include="Interfaces\GarbageCollector\AGarbageCollector.cs" />
|
||||
<Compile Include="Interfaces\GarbageCollector\IGarbageCollector.cs" />
|
||||
@ -52,11 +53,12 @@
|
||||
<Compile Include="Interfaces\RoutePlanningEngine\IRoutePlanningEngine.cs" />
|
||||
<Compile Include="Interfaces\TrashCans\AGarbageCollectorContainer.cs" />
|
||||
<Compile Include="Interfaces\TrashCans\ATrashCan.cs" />
|
||||
<Compile Include="Interfaces\TrashCans\IStep.cs" />
|
||||
<Compile Include="Interfaces\IStep.cs" />
|
||||
<Compile Include="Models\Coords.cs" />
|
||||
<Compile Include="Models\Map.cs" />
|
||||
<Compile Include="Models\Steps\CollectStep.cs" />
|
||||
<Compile Include="Models\Steps\MoveStep.cs" />
|
||||
<Compile Include="Models\Steps\SpillStep.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
29
Trunk/Components/CzokoŚmieciarka.DataModels/Exceptions.cs
Normal file
29
Trunk/Components/CzokoŚmieciarka.DataModels/Exceptions.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CzokoŚmieciarka.DataModels
|
||||
{
|
||||
public class WrongPositionException : Exception
|
||||
{
|
||||
public WrongPositionException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
public WrongPositionException(string message,Exception innerException) : base(message,innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class TrashContainerNotFound : Exception
|
||||
{
|
||||
public TrashContainerNotFound(string message) : base(message)
|
||||
{
|
||||
}
|
||||
public TrashContainerNotFound(string message, Exception innerException) : base(message, innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
namespace CzokoŚmieciarka.DataModels.Interfaces
|
||||
{
|
||||
public interface IStep
|
||||
{
|
||||
void Invoke();
|
||||
}
|
||||
}
|
@ -15,6 +15,6 @@ namespace CzokoŚmieciarka.DataModels.Interfaces
|
||||
this.Localization = localization;
|
||||
}
|
||||
|
||||
Coords Localization { get; }
|
||||
public Coords Localization { get; }
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ namespace CzokoŚmieciarka.DataModels.Interfaces.TrashCans
|
||||
get { return Garbage.Volume / this.MaxVolume; }
|
||||
}
|
||||
|
||||
public virtual bool AddGarbage(AGarbage garbage)
|
||||
public virtual bool AddGarbage(IGarbage garbage)
|
||||
{
|
||||
if (this.TypeOfGarbage != garbage.TypeOfGarbage)
|
||||
throw new Exception("You cannot add up different type garbage!");
|
||||
|
@ -1,13 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CzokoŚmieciarka.DataModels.Interfaces.TrashCans
|
||||
{
|
||||
public interface IStep
|
||||
{
|
||||
void Invoke();
|
||||
}
|
||||
}
|
@ -24,15 +24,15 @@ namespace CzokoŚmieciarka.DataModels.Models.Steps
|
||||
public void Invoke()
|
||||
{
|
||||
if(_garbageCollector.Position != _garbageLocalization.Coords)
|
||||
throw new Exception("Śmieciarka nie jest w miejscu odebrania śmieci");
|
||||
throw new WrongPositionException("Śmieciarka nie jest w miejscu oderbania śmieci");
|
||||
|
||||
var trashCans = _garbageLocalization.TrashCans.Where(t => t.TypeOfGarbage == _typeOfGarbage);
|
||||
var garbage = trashCans.Select(t => t.TakeGarbage()).Aggregate((a,b)=>a+b);
|
||||
|
||||
if (!_garbageCollector.TrashContainers.Any(c => c.TypeOfGarbage == _typeOfGarbage))
|
||||
throw new Exception("Ta śmieciarka nie może zebrać żądanych śmieci.");
|
||||
if (_garbageCollector.TrashContainers.All(c => c.TypeOfGarbage != _typeOfGarbage))
|
||||
throw new TrashContainerNotFound($"Nie znaleziono kontenera na {_typeOfGarbage.GarbageType}.");
|
||||
|
||||
_garbageCollector.TrashContainers.FirstOrDefault(t => t.TypeOfGarbage == _typeOfGarbage).AddGarbage(garbage);
|
||||
_garbageCollector.TrashContainers.First(t => t.TypeOfGarbage == _typeOfGarbage).AddGarbage(garbage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CzokoŚmieciarka.DataModels.Interfaces;
|
||||
|
||||
namespace CzokoŚmieciarka.DataModels.Models.Steps
|
||||
{
|
||||
public class SpillStep : IStep
|
||||
{
|
||||
public SpillStep(IGarbageCollector garbageCollector, ADump dump, ITypeOfGarbage typeOfGarbage)
|
||||
{
|
||||
this._garbageCollector = garbageCollector;
|
||||
this._dump = dump;
|
||||
this._typeOfGarbage = typeOfGarbage;
|
||||
}
|
||||
|
||||
private IGarbageCollector _garbageCollector;
|
||||
private ADump _dump;
|
||||
private ITypeOfGarbage _typeOfGarbage;
|
||||
|
||||
public void Invoke()
|
||||
{
|
||||
if(_garbageCollector.Position != _dump.Localization)
|
||||
throw new WrongPositionException("Śmieciarka nie na terenie podanego wyspiska");
|
||||
|
||||
if(_dump.TypeOfGarbage != _typeOfGarbage)
|
||||
throw new TrashContainerNotFound($"Wysypisko nie przyjmuje smieci typu {_typeOfGarbage.GarbageType}");
|
||||
|
||||
if(_garbageCollector.TrashContainers.All(c => c.TypeOfGarbage != _typeOfGarbage))
|
||||
throw new TrashContainerNotFound($"Smieciarka nie ma pojemnika na {_typeOfGarbage.GarbageType}!");
|
||||
|
||||
var garbage = _garbageCollector.TrashContainers.Where(t => t.TypeOfGarbage == _typeOfGarbage)
|
||||
.Select(t => t.TakeGarbage())
|
||||
.Aggregate((a, b) => a + b);
|
||||
|
||||
_dump.AddGarbage(garbage);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user