public static void Run(params string[] args) { var logger = LoggerFactory(); var config = new ElevatorConfiguration(); var optionSet = new OptionSet(); optionSet.Add("up", option => { config.Direction = option; }); optionSet.Add("assembly=", option => { config.AssemblyIsSpecified = true; config.AssemblyName = option; }); optionSet.Parse(args); if (string.IsNullOrEmpty(config.Direction)) { logger.Log("You have to specify direction:"); logger.Log("\tElevator.exe -up, for going up"); logger.Log("\tElevator.exe -down, for going down (not supported yet)"); } else if (!config.AssemblyIsSpecified) { logger.Log("You have to specify migration assembly:"); logger.Log("\tElevator.exe -up -assembly:name.dll"); } if (config.IsValid()) { var migrationAssembly = Assembly.LoadFrom(Path.Combine(Environment.CurrentDirectory, config.AssemblyName)); var levelDataStorageClasses = new LevelDataStorageClassFinder().Find(migrationAssembly); if (levelDataStorageClasses.Any()) { var levelDataStorage = Activator.CreateInstance(levelDataStorageClasses.First()) as ILevelDataStorage; levelDataStorage.Initialize(); var levelsCalsses = new ElevatorLevelClassFinder().Find(migrationAssembly); var levelFactory = new LevelFactory(); var levels = new List <Level>(); foreach (var levelClass in levelsCalsses) { levels.Add(levelFactory.NewLevel(levelClass)); } var elevator = new Lift(new ConsoleLogger(), levelDataStorage); elevator.AddLevel(levels.ToArray()); elevator.Start(); elevator.Top(); } else { logger.Log("Could not find a class in assembly 'Tests.Empty.dll' that implements the ILevelDataStorage interface."); } } }
public static void Run(params string[] args) { var logger = LoggerFactory(); var config = new ElevatorConfiguration(); var optionSet = new OptionSet(); optionSet.Add("up", option => { config.Direction = option; }); optionSet.Add("assembly=", option => { config.AssemblyIsSpecified = true; config.AssemblyName = option; }); optionSet.Parse(args); if (string.IsNullOrEmpty(config.Direction)) { logger.Log("You have to specify direction:"); logger.Log("\tElevator.exe -up, for going up"); logger.Log("\tElevator.exe -down, for going down (not supported yet)"); } else if (!config.AssemblyIsSpecified) { logger.Log("You have to specify migration assembly:"); logger.Log("\tElevator.exe -up -assembly:name.dll"); } if (config.IsValid()) { var migrationAssembly = Assembly.LoadFrom(Path.Combine(Environment.CurrentDirectory, config.AssemblyName)); var levelDataStorageClasses = new LevelDataStorageClassFinder().Find(migrationAssembly); if (levelDataStorageClasses.Any()) { var levelDataStorage = Activator.CreateInstance(levelDataStorageClasses.First()) as ILevelDataStorage; levelDataStorage.Initialize(); var levelsCalsses = new ElevatorLevelClassFinder().Find(migrationAssembly); var levelFactory = new LevelFactory(); var levels = new List<Level>(); foreach (var levelClass in levelsCalsses) { levels.Add(levelFactory.NewLevel(levelClass)); } var elevator = new Lift(new ConsoleLogger(), levelDataStorage); elevator.AddLevel(levels.ToArray()); elevator.Start(); elevator.Top(); } else { logger.Log("Could not find a class in assembly 'Tests.Empty.dll' that implements the ILevelDataStorage interface."); } } }
protected Elevator(ElevatorConfiguration _elevatorConfiguration, BuildingConfiguration _buildingConfiguration, ElevatorStrategy _elevatorStrategy) { elevatorConfiguration = _elevatorConfiguration; buildingConfiguration = _buildingConfiguration; elevatorStrategy = _elevatorStrategy; m_driver = new ElevatorDriver(_elevatorConfiguration, _buildingConfiguration); }
public ElevatorService(ILogger <ElevatorService> logger, IHubContext <ElevatorTrackingHub> hub, BuildingConfiguration buildingConfiguration, ElevatorConfiguration elevatorConfiguration) { _logger = logger; _hub = hub; _buildingConfiguration = buildingConfiguration; _elevatorConfiguration = elevatorConfiguration; }
public static void Main(String[] args) { System.Diagnostics.Debug.WriteLine("Starting Up"); GameClock clock = new GameClock(100); BuildingConfiguration buildingConfiguration = new BuildingConfiguration("Devonshire Place", -1, 8, 13); ElevatorConfiguration elevatorConfiguration = new ElevatorConfiguration("Elevator 1", 4000); List <ElevatorConfiguration> elevatorConfigurations = new List <ElevatorConfiguration>(); elevatorConfigurations.Add(elevatorConfiguration); ElevatorBankConfiguration bankConfiguration = new ElevatorBankConfiguration("Main Elevators", buildingConfiguration, elevatorConfigurations); Elevator firstElevator = new Elevator(elevatorConfiguration, buildingConfiguration); List <Elevator> elevators = new List <Elevator>(); elevators.Add(firstElevator); ElevatorBank bank = new ElevatorBank(buildingConfiguration, elevators, clock); ElevatorUserGeneration userGenerator = new ElevatorUserGeneration(5, buildingConfiguration.minFloor, buildingConfiguration.maxFloor, bank); StepAction nextAction = new StepAction("SimpleAction", (int stepNumber) => userGenerator.registerUser(stepNumber)); clock.registerStepAction(nextAction); clock.run(); System.Diagnostics.Debug.WriteLine("Successfully executed run. Shutting down"); }
public ElevatorDriver(ElevatorConfiguration _elevator, BuildingConfiguration _building) { m_elevator = _elevator; building = _building; m_state = new ElevatorState( 0, DoorState.Open(), ElevatorMovement.Stopped(), ElevatorMovement.Stopped()); m_action = new ElevatorAction(ElevatorAction.Opening, 0); m_stepAction = new StepAction("ElevatorDriver Action", (stepNumber) => proceedToNextState(stepNumber)); }
public SchedulingService(ILogger <SchedulingService> logger, IHubContext <ElevatorTrackingHub> hub, IServiceProvider serviceProvider, BuildingConfiguration buildingConfiguration, ElevatorConfiguration elevatorConfiguration) { _logger = logger; _serviceProvider = serviceProvider; _buildingConfiguration = buildingConfiguration; _elevatorConfiguration = elevatorConfiguration; for (int i = 0; i < _buildingConfiguration.ElevatorCount; i++) { var elevator = new Elevator(); elevator.Id = i; _elevators.Add(elevator); } _hub = hub; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var buildingConfig = new BuildingConfiguration(); Configuration.Bind("Building", buildingConfig); services.AddSingleton(buildingConfig); var elevatorConfig = new ElevatorConfiguration(); Configuration.Bind("Elevator", elevatorConfig); services.AddSingleton(elevatorConfig); services.AddTransient <IElevatorService>(s => new ElevatorService(logger: s.GetRequiredService <ILogger <ElevatorService> >(), hub: s.GetRequiredService <IHubContext <ElevatorTrackingHub> >(), buildingConfiguration: buildingConfig, elevatorConfiguration: elevatorConfig)); services.AddHostedService <SchedulingService>(); services.AddControllers(); services.AddSignalR(); }
public Elevator(ElevatorConfiguration _elevatorConfiguration, BuildingConfiguration _buildingConfiguration) : this(_elevatorConfiguration, _buildingConfiguration, new ElevatorStrategy()) { }