#include "StdAfx.h"
#include ".\resultsfilewriter.h"
#using <mscorlib.dll>

void ResultsFileWriter::updateStep(){}
void ResultsFileWriter::updateMultipleSimulations(){}
void ResultsFileWriter::updateSimulation(){
	AbstractSimulationResultDTO* result = simulationResult;
	SingleSimulationResultDTO* simulationResultDTO = dynamic_cast<SingleSimulationResultDTO*>(result);
	DTOIterator* iterator = ResultDTOIteratorFactory::createGeneralIterator(simulationResultDTO);
	bool print = false;
	ofstream myfile;
	myfile.open ("SingleSimulationResult.txt");
	while(iterator->hasNextResult()){
		AbstractSimulationResultDTO* element = iterator->nextResult();
		myfile << "\n ID: " << element->getID() << "\n";
		if (element->getID().compare(string("0"))){
			print = true;
		}
		if (print){
			if (element->getID().compare(string("arrivals")) == 0){
				myfile << "\nArrivals:\n";
				ArrivalsInfoDTO* service = dynamic_cast<ArrivalsInfoDTO*>(element);
				myfile << "Number Of Arrivals: "  << service->getNumberOfArrivals() << "\n";
			}
			if (element->getID().compare(string("service1")) == 0){
				myfile << "\nServico 1:\n";
				ServiceInfoDTO* service = dynamic_cast<ServiceInfoDTO*>(element);
				myfile << "Tamanho Actual da fila: "  << service->getServiceActualQueueSize() << "\n";
				myfile << "Tamanho Medio da fila: "  << service->getServiceAvgQueueSize() << "\n";
				myfile << "Tamanho Maximo da fila: "  << service->getMaximumQueueSize() << "\n";
				myfile << "Taxa de Utilizacao do Servico: : "  << service->getServiceUseRate() << "\n";
			}
			if (element->getID().compare(string("service2")) == 0){
				myfile << "\nServico 2:\n";
				ServiceInfoDTO* service = dynamic_cast<ServiceInfoDTO*>(element);
				myfile << "Tamanho Actual da fila: "  << service->getServiceActualQueueSize() << "\n";
				myfile << "Tamanho Medio da fila: "  << service->getServiceAvgQueueSize() << "\n";
				myfile << "Tamanho Maximo da fila: "  << service->getMaximumQueueSize() << "\n";
				myfile << "Taxa de Utilizacao do Servico: : "  << service->getServiceUseRate() << "\n";
			}
			if (element->getID().compare(string("service3")) == 0){
				myfile << "\nServic0 3:\n";
				ServiceInfoDTO* service = dynamic_cast<ServiceInfoDTO*>(element);
				myfile << "Tamanho Actual da fila: "  << service->getServiceActualQueueSize() << "\n";
				myfile << "Tamanho Medio da fila: "  << service->getServiceAvgQueueSize() << "\n";
				myfile << "Tamanho Maximo da fila: "  << service->getMaximumQueueSize() << "\n";
				myfile << "Taxa de Utilizacao do Servico: : "  << service->getServiceUseRate() << "\n";
			}
			if (element->getID().compare(string("service4Coats")) == 0){
				myfile << "\nServico 4 - Casacos:\n";
				ServiceInfoDTO* service = dynamic_cast<ServiceInfoDTO*>(element);
				myfile << "Tamanho Actual da fila: "  << service->getServiceActualQueueSize() << "\n";
				myfile << "Tamanho Medio da fila: "  << service->getServiceAvgQueueSize() << "\n";
				myfile << "Tamanho Maximo da fila: "  << service->getMaximumQueueSize() << "\n";
				myfile << "Taxa de Utilizacao do Servico: : "  << service->getServiceUseRate() << "\n";
			}
			if (element->getID().compare(string("service4Pants")) == 0){
				myfile << "\nServico 4 - Calcas:\n";
				ServiceInfoDTO* service = dynamic_cast<ServiceInfoDTO*>(element);
				myfile << "Tamanho Actual da fila: "  << service->getServiceActualQueueSize() << "\n";
				myfile << "Tamanho Medio da fila: "  << service->getServiceAvgQueueSize() << "\n";
				myfile << "Tamanho Maximo da fila: "  << service->getMaximumQueueSize() << "\n";
				myfile << "Taxa de Utilizacao do Servico: : "  << service->getServiceUseRate() << "\n";
			}
			if (element->getID().compare(string("service4Suits")) == 0){
				myfile << "\nServico 4 - Fatos:\n";
				ServiceInfoDTO* service = dynamic_cast<ServiceInfoDTO*>(element);
				myfile << "Tamanho Actual da fila: "  << service->getServiceActualQueueSize() << "\n";
				myfile << "Tamanho Medio da fila: "  << service->getServiceAvgQueueSize() << "\n";
				myfile << "Tamanho Maximo da fila: "  << service->getMaximumQueueSize() << "\n";
				myfile << "Taxa de Utilizacao do Servico: : "  << service->getServiceUseRate() << "\n";
			}
			if (element->getID().compare(string("service5")) == 0){
				myfile << "\nServico 5:\n";
				ServiceInfoDTO* service = dynamic_cast<ServiceInfoDTO*>(element);
				myfile << "Tamanho Actual da fila: "  << service->getServiceActualQueueSize() << "\n";
				myfile << "Tamanho Medio da fila: "  << service->getServiceAvgQueueSize() << "\n";
				myfile << "Tamanho Maximo da fila: "  << service->getMaximumQueueSize() << "\n";
				myfile << "Taxa de Utilizacao do Servico: : "  << service->getServiceUseRate() << "\n";
			}
			if (element->getID().compare(string("exits")) == 0){
				myfile << "\nExits:\n";
				ExitsInfoDTO* service = dynamic_cast<ExitsInfoDTO*>(element);
				myfile << "Number Of Exits Without Flaw: "  << service->getNumberOfExitsWithoutFlaw() << "\n";
				myfile << "Number Of Exits With Flaw: "  << service->getNumberOfExitsWithFlaw() << "\n";
				myfile << "Average Time Without Flaw: "  << service->getAverageTimeWithoutFlaw() << "\n";
				myfile << "Average Time With Flaw: "  << service->getAverageTimeWithFlaw() << "\n";
			}
		}
	}
	myfile.close();
}
void ResultsFileWriter::setSimulationResultDTO(AbstractSimulationResultDTO* _simulationResult){
	simulationResult = _simulationResult;
}