Czoko_Smieciarka/Trunk/Components/CzokoŚmieciarka.DataModels/Models/Steps/SpillStep.cs

43 lines
1.5 KiB
C#
Raw Permalink Normal View History

2019-03-13 16:55:34 +01:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CzokoŚmieciarka.DataModels.Interfaces;
2019-03-13 17:23:52 +01:00
using CzokoŚmieciarka.DataModels.Interfaces.TrashCans;
2019-03-13 16:55:34 +01:00
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);
}
}
}