package de.ugoe.cs.eventbench.commands;

import java.security.InvalidParameterException;
import java.util.List;

import de.ugoe.cs.eventbench.LogParser;
import de.ugoe.cs.eventbench.data.Event;
import de.ugoe.cs.eventbench.data.GlobalDataContainer;
import de.ugoe.cs.eventbench.data.WindowsMessage;
import de.ugoe.cs.util.console.Command;
import de.ugoe.cs.util.console.Console;

public class CMDparseXML implements Command {

	@Override
	public void help() {
		Console.println("Usage: parseXML <filename> {<countMessageOccurences}");
	}

	@Override
	public void run(List<Object> parameters) {
		String filename;
		boolean countMessageOccurences = false;
		
		try {
			filename = (String) parameters.get(0);
			if( parameters.size()==2 ) {
				countMessageOccurences = Boolean.parseBoolean((String) parameters.get(1));
			}
		} catch (Exception e) {
			throw new InvalidParameterException();
		}
		
		LogParser parser = new LogParser(countMessageOccurences);
		parser.parseFile(filename);
		
		List<List<Event<WindowsMessage>>> sequences = parser.getSequences();
		
		GlobalDataContainer.getInstance().addData("sequences", sequences);		
	}

}
