Advertisement
Guest User

Untitled

a guest
Feb 15th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 KB | None | 0 0
  1. using System;
  2.  
  3. using OlympicGames.Core.Contracts;
  4. using OlympicGames.Core.Factories;
  5. using OlympicGames.Core.Providers;
  6.  
  7. namespace OlympicGames.Core
  8. {
  9.     public class Engine : IEngine
  10.     {
  11.         private static IEngine instance;
  12.  
  13.         private readonly ICommandParser parser;
  14.         private readonly ICommandProcessor commandProcessor;
  15.         private readonly IOlympicsFactory factory;
  16.         private readonly IOlympicCommittee commitee;
  17.  
  18.         private const string Delimiter = "####################";
  19.  
  20.         private Engine()
  21.         {
  22.             this.parser = CommandParser.Instance;
  23.             this.commandProcessor = CommandProcessor.Instance;
  24.             this.factory = OlympicsFactory.Instance;
  25.             this.commitee = OlympicCommittee.Instance;
  26.         }
  27.  
  28.         public virtual void Run()
  29.         {
  30.             string commandLine = null;
  31.  
  32.             while ((commandLine = Console.ReadLine()) != "end")
  33.             {
  34.                 try
  35.                 {
  36.                     var command = this.parser.ParseCommand(commandLine);
  37.                     if (command != null)
  38.                     {
  39.                         this.commandProcessor.ProcessSingleCommand(command);
  40.                         Console.WriteLine(Delimiter);
  41.                     }
  42.                 }
  43.                 catch (Exception ex)
  44.                 {
  45.                     while (ex.InnerException != null)
  46.                     {
  47.                         ex = ex.InnerException;
  48.                     }
  49.  
  50.                     Console.WriteLine("ERROR: {0}", ex.Message);
  51.                 }
  52.             }
  53.         }
  54.  
  55.         public static IEngine Instance
  56.         {
  57.             get
  58.             {
  59.                 if (instance == null)
  60.                 {
  61.                     instance = new Engine();
  62.                 }
  63.  
  64.                 return instance;
  65.             }
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement