/// <summary> /// Crreates a Rocket and store it into the inventory /// </summary> /// <param name="name"></param> /// <param name="destination"></param> /// <returns></returns> public CargoRocket CreateRocket(string name, string destination) { if (string.IsNullOrWhiteSpace(name)) { throw new System.ArgumentException(Constants.CONST_ARG_EXECPTION, "name"); } if (string.IsNullOrWhiteSpace(destination)) { throw new System.ArgumentException(Constants.CONST_ARG_EXECPTION, "destination"); } var rocket = new CargoRocket { Name = name, Destination = destination }; //Store into inventory if (!_cargorocketInventory.StoreRocket(rocket)) { rocket = null; } return(rocket); }
/// <summary> /// Change destination of a rocket /// </summary> /// <param name="destination"></param> /// <param name="rocketName"></param> /// <returns></returns> public CargoRocket ChangeDestination(string destination, string rocketName) { CargoRocket response = null; if (!string.IsNullOrWhiteSpace(rocketName) && Storage.Storage.CargoRockets != null && Storage.Storage.CargoRockets.Count > 0) { //Logging starts _logger?.LogInformation("{0} - Inventory operation starts at {1}", "ChangeDestination", System.DateTime.Now); foreach (var rocket in Storage.Storage.CargoRockets) { if (rocket != null && rocket.Name.Equals(rocketName)) { if (rocket.satellites != null) { rocket.Destination = destination; response = rocket; } break; } } //logging ends _logger?.LogInformation("{0} - Inventory operation ends at {1}", "ChangeDestination", System.DateTime.Now); } return(response); }
/// <summary> /// Print rocket info /// </summary> private static void PrintRocketInfo(CargoRocket rocket) { if (rocket != null) { Console.WriteLine("Rocket Info:"); Console.WriteLine("Name:{0}", rocket.Name); Console.WriteLine("Destination:{0}", rocket.Destination); Console.WriteLine("Satellite Info"); PrintAllSatellites(rocket.satellites, rocket.Name); } }
/// <summary> /// Print rocket info /// </summary> private static void PrintRocketInfo(CargoRocket rocket) { if (rocket != null) { _userInteraction.WriteLine("Rocket Info:"); _userInteraction.WriteLine(string.Format("Name:{0}", rocket.Name)); _userInteraction.WriteLine(string.Format("Destination:{0}", rocket.Destination)); _userInteraction.WriteLine("Satellite Info"); PrintAllSatellites(rocket.satellites, rocket.Name); } }
/// <summary> /// Store Rockets into the inventory /// </summary> /// <param name="rocket"></param> /// <returns></returns> public bool StoreRocket(CargoRocket rocket) { bool response = false; if (rocket != null && !string.IsNullOrWhiteSpace(rocket.Name) && Storage.Storage.CargoRockets != null) { Storage.Storage.CargoRockets.Add(rocket); response = true; } return(response); }
/// <summary> /// Store Rockets into the inventory /// </summary> /// <param name="rocket"></param> /// <returns></returns> public bool StoreRocket(CargoRocket rocket) { bool response = false; if (rocket != null && !string.IsNullOrWhiteSpace(rocket.Name) && Storage.Storage.CargoRockets != null) { _logger?.LogInformation("{0} - Inventory operation starts at {1}", "StoreRocket", System.DateTime.Now); Storage.Storage.CargoRockets.Add(rocket); _logger?.LogInformation("{0} - Inventory operation ends at {1}", "StoreRocket", System.DateTime.Now); response = true; } return(response); }
public CargoRocket CargoRocketWithSatelliteEntity(string name, string dest, int satelliteCount) { var rocket = new CargoRocket { Name = name, Destination = dest, satellites = new List <Satellite>() }; for (var i = 0; i < satelliteCount; i++) { rocket.satellites.Add(new Satellite { Name = string.Format("Satellite-{0}", i) }); } return(rocket); }
/// <summary> /// Scrap the rocket from inventory /// </summary> /// <param name="rocketName"></param> /// <returns></returns> public bool ScrapRocket(string rocketName) { bool response = false; if (!string.IsNullOrWhiteSpace(rocketName) && Storage.Storage.CargoRockets != null && Storage.Storage.CargoRockets.Count > 0) { CargoRocket rocket = GetRocket(rocketName); if (rocket != null) { Storage.Storage.CargoRockets.Remove(rocket); response = true; } } return(response); }
/// <summary> /// Gets the rocket from inventory /// </summary> /// <param name="rocketName"></param> /// <returns></returns> public CargoRocket GetRocket(string rocketName) { CargoRocket response = null; if (!string.IsNullOrWhiteSpace(rocketName) && Storage.Storage.CargoRockets != null && Storage.Storage.CargoRockets.Count > 0) { foreach (var rocket in Storage.Storage.CargoRockets) { if (rocket != null && rocket.Name.Equals(rocketName)) { response = rocket; break; } } } return(response); }
/// <summary> /// Scrap the rocket from inventory /// </summary> /// <param name="rocketName"></param> /// <returns></returns> public bool ScrapRocket(string rocketName) { bool response = false; if (!string.IsNullOrWhiteSpace(rocketName) && Storage.Storage.CargoRockets != null && Storage.Storage.CargoRockets.Count > 0) { //Logging starts _logger?.LogInformation("{0} - Inventory operation starts at {1}", "ScrapRocket", System.DateTime.Now); CargoRocket rocket = GetRocket(rocketName); if (rocket != null) { Storage.Storage.CargoRockets.Remove(rocket); response = true; } //logging ends _logger?.LogInformation("{0} - Inventory operation ends at {1}", "ScrapRocket", System.DateTime.Now); } return(response); }
/// <summary> /// Change destination of a rocket /// </summary> /// <param name="destination"></param> /// <param name="rocketName"></param> /// <returns></returns> public CargoRocket ChangeDestination(string destination, string rocketName) { CargoRocket response = null; if (!string.IsNullOrWhiteSpace(rocketName) && Storage.Storage.CargoRockets != null && Storage.Storage.CargoRockets.Count > 0) { foreach (var rocket in Storage.Storage.CargoRockets) { if (rocket != null && rocket.Name.Equals(rocketName)) { if (rocket.satellites != null) { rocket.Destination = destination; response = rocket; } break; } } } return(response); }