Exemplo n.º 1
0
//INTERFACE
    /// <summary>
    /// Load statistics configuration from given file.
    /// Creates gatheres writing configuration to files.
    /// </summary>
    /// <param name="statisticsFileName">Name of file to read configuration from.</param>
    public static void Load(string statisticsFileName)
    {
        string progressText = string.Format("Reading statistics gatherers from {0}.", Configuration.Files.StatisticsFile);

        ProgressLogger.Starting(progressText);
        gatherers = new List <Gatherer>();
        XmlDocument document = new XmlDocument();

        document.Load(statisticsFileName);
        XmlNode main = document[statisticsTag];

        foreach (XmlNode node in main.ChildNodes)
        {
            switch (node.Name)
            {
            case Gatherer.GathererTag:
                gatherers.Add(Gatherer.Create(node));
                break;

            default:
                throw new ArgumentException("Unknown XML node: " + node.Name);
            }
        }
        ProgressLogger.Finished(progressText);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Runs event loop till either current time is greater than passed endTime or there are no more scheduled events.
    /// </summary>
    /// <param name="endTime">Simulation time indicating when to stop simulation.</param>
    public static void Run()
    {
        whenStarted = DateTime.Now;
        const string progressText = "Simulating.";
        ProgressLogger.Starting(progressText);
        ProgressLogger.Progress();
        lastShown = DateTime.Now;
        while(events.Count>0 && currentTime <= simulationTime)
        {
            //show progress
            if (lastShown + showingDelay < DateTime.Now)
            {
                ProgressLogger.Progress();
                lastShown = DateTime.Now;
            }
            ++loopNumber;

            //next event;

            TimerEntryImplementation entry = events.DeleteMin();
            currentTime = entry.Time;
            entry.Method(entry);
        }
        if (events.Count == 0)
        {
            Console.WriteLine("No more events to handle.");
        }
        if (currentTime > simulationTime)
        {
            Console.WriteLine("Simulation came to its end time.");
        }
        ProgressLogger.Finished(progressText);
    }
Exemplo n.º 3
0
//HELPERS
    static void loadElements()
    {
        string progressText = string.Format("Loading network elements from {0}.", Configuration.Files.NetworkFile);

        ProgressLogger.Starting(progressText);
        XmlDocument document = new XmlDocument();

        document.Load(Configuration.Files.NetworkFile);
        XmlNode network = XmlParser.GetChildNode(document, networkTag);

        foreach (XmlNode element in network.ChildNodes)
        {
            switch (element.Name)
            {
            case Node.NodeTag:
                new Node(element);
                break;

            case Link.LinkTag:
                new Link(element);
                break;

            default:
                XmlParser.ThrowUnknownNode(element);
                break;
            }
        }
        ProgressLogger.Finished(progressText);
    }
Exemplo n.º 4
0
//INTERFACE
    /// <summary>
    /// Some parameters can be passed in console command. Analyze them here before moving to reading configuration from XML files.
    /// </summary>
    /// <param name="arguments">Aguments passed to Main method.</param>
    public static void AnalyzeConsoleInput(string[] arguments)
    {
        const string progressText = "Analyzing console arguments.";

        ProgressLogger.Starting(progressText);
        Files.AnalyzeConsoleArguments(arguments);
        ProgressLogger.Finished(progressText);
    }
Exemplo n.º 5
0
    public static void ShutDown()
    {
        const string progressText = "Shutting down network.";

        ProgressLogger.Starting(progressText);
        identificables.Clear();
        ProgressLogger.Finished(progressText);
    }
Exemplo n.º 6
0
//HELPERS
    static void Main(string[] arguments)
    {
        try
        {
            //set some console parameters and write a big "Welcome" :)
            Console.ForegroundColor = ConsoleColor.White;
            Console.BackgroundColor = ConsoleColor.Black;
            Console.WriteLine("Welcome to {0}!", programName);
            Console.WriteLine();
            //the default color of displayed informations is green
            Console.ForegroundColor = ConsoleColor.Green;

            string progressText = "Running application.";
            ProgressLogger.Starting(progressText);

            //load all services
            Configuration.AnalyzeConsoleInput(arguments);
            Configuration.Load(Configuration.Files.ConfigurationFile);
            Timer.SimulationTime = Configuration.Simulation.SimulationTime;
            Logger.Initialize(Configuration.Files.LogFile);
            Network.Load(Configuration.Files.NetworkFile);
            Statistics.Load(Configuration.Files.StatisticsFile);

            //run simulation
            Timer.Run();

            //shut down all services
            Statistics.ShutDown();
            Network.ShutDown();
            Logger.ShutDown();

            //log end
            ProgressLogger.Finished(progressText);
            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Bye!");
        }
#if (!DEBUG)
        catch (Exception exception)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("An exception occured:");
            Console.WriteLine();
            Console.WriteLine(exception.Message);
            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine(exception.StackTrace);
            Logger.ShutDown();
        }
#endif
        finally
        {
            //reset console to normal state
            Console.ResetColor();
        }
    }
Exemplo n.º 7
0
    public static void Initialize(string logFileName)
    {
        const string progressText = "Initializing logging.";

        ProgressLogger.Starting(progressText);
        logFile           = new StreamWriter(logFileName, false);
        logFile.AutoFlush = true;
        ProgressLogger.Finished(progressText);
    }
Exemplo n.º 8
0
//INTERFACE
    public static void Load(string networkFileName)
    {
        const string progressText = "Loading network.";

        ProgressLogger.Starting(progressText);
        loadElements();
        connectElements();
        configureElements();
        ProgressLogger.Finished(progressText);
    }
Exemplo n.º 9
0
    public static void ShutDown()
    {
        const string progressText = "Shutting down logging.";

        ProgressLogger.Starting(progressText);
        if (logFile != null)
        {
            logFile.Close();
            logFile = null;
        }
        ProgressLogger.Finished(progressText);
    }
Exemplo n.º 10
0
    /// <summary>
    /// Shuts down all gatheres (saves data in buffers).
    /// </summary>
    public static void ShutDown()
    {
        const string progressText = "Shutting down statistics gatherers.";

        ProgressLogger.Starting(progressText);
        foreach (Gatherer gatherer in gatherers)
        {
            gatherer.Close();
        }
        gatherers = null;
        ProgressLogger.Finished(progressText);
    }
Exemplo n.º 11
0
    static void connectElements()
    {
        const string progressText = "Connecting network elements.";

        ProgressLogger.Starting(progressText);
        foreach (IConnectable connectable in connectables)
        {
            connectable.Connect();
        }
        connectables = null;//free memory
        ProgressLogger.Finished(progressText);
    }
Exemplo n.º 12
0
    static void configureElements()
    {
        const string progressText = "Configuring network elements.";

        ProgressLogger.Starting(progressText);
        foreach (Identificable identificable in identificables.Values)
        {
            IConfigurable configurable = identificable as IConfigurable;
            if (configurable != null)
            {
                Logger.Log(identificable, "Configuring.");
                configurable.Configure();
            }
        }
        ProgressLogger.Finished(progressText);
    }
Exemplo n.º 13
0
    /// <summary>
    /// Main configuraiton is read from an XML file.
    /// All variables have their default values that can be overwritten by values found in configuration.
    /// No XML nodes are obligatory(except the main node), all are analyzed when found.
    /// </summary>
    /// <param name="configurationFileName">Name of file to read configuration from.</param>
    public static void Load(string configurationFileName)
    {
        string progressText = string.Format("Reading configuration from {0}.", configurationFileName);

        ProgressLogger.Starting(progressText);

        XmlDocument xmlDocument = new XmlDocument();

        xmlDocument.Load(configurationFileName);
        XmlNode configuration = XmlParser.GetChildNode(xmlDocument, configurationTag);

        //find intresting elements and pass XML nodes to them
        XmlNode files = configuration[Files.FilesTag];

        if (files != null)
        {
            Files.Configure(files);
        }
        XmlNode protocols = configuration[Protocols.ProtocolsTag];

        if (protocols != null)
        {
            Protocols.Configure(protocols);
        }
        XmlNode network = configuration[Network.NetworkTag];

        if (network != null)
        {
            Network.Configure(network);
        }

        XmlNode simulation = configuration[Simulation.SimulationTag];

        if (simulation != null)
        {
            Simulation.Configre(simulation);
        }

        ProgressLogger.Finished(progressText);
    }