public static SimulationCore.Environment.Configuration ConfigurationConverter(ResultContext resultCtx, int id) { var validCommands = Commands.GetAllValidCommands; var config = new SimulationCore.Environment.Configuration(); ICommand command = validCommands.Single(x => x.ArgLong == "SimulationId"); command.Action(config, id.ToString()); var configurationItems = resultCtx.ConfigurationRelations .Include(x => x.ChildItem) .Where(x => x.Id == id).Select(x => x.ChildItem).ToList(); if (id != 1) { configurationItems = AddDefaultItems(resultCtx, configurationItems); } foreach (var item in configurationItems) { if (!IsArg(validCommands: validCommands, argument: "--" + item.Property, command: ref command)) { throw new InvalidOperationException("No command found that is equal to:" + item.Property); } //else command.Action(arg1: config, arg2: item.PropertyValue); } return(config); }
static void Main(string[] args) { Console.WriteLine(value: "Welcome to AkkaSim Cli"); var masterDb = ProductionDomainContext.GetContext(defaultCon: ConfigurationManager.AppSettings[index: 0]); var validCommands = new Commands(); var command = validCommands.Single(predicate: x => x.ArgLong == "Help"); var lastArg = 0; var config = new SimulationCore.Environment.Configuration(); for (; lastArg < args.Length; lastArg++) { if (args[lastArg] == "-?" || args[lastArg] == "/?") { command.Action(arg1: null, arg2: null); return; } if (IsArg(validCommands: validCommands, argument: args[lastArg], command: ref command)) { if (command.HasProperty) { lastArg++; command.Action(arg1: config, arg2: args[lastArg]); } else { command.Action(arg1: config, arg2: null); } } } RunSimulationTask(masterDb: masterDb, config: config).Wait(); }
public void CreateOrders() { long currentTime = 0; int orderCount = 100; var dataBase = Dbms.GetNewMasterDataBase(dbName: "Master40"); var productIds = dataBase.DbContext.Articles.Include(x => x.ArticleType).Where(x => x.ArticleType.Name.Equals("Product")).Select(x => x.Id).ToList(); var simConfig = new SimulationCore.Environment.Configuration(); simConfig.AddOption(new Seed(169)); simConfig.AddOption(new OrderArrivalRate(0.015)); simConfig.AddOption(new MinDeliveryTime(1920)); simConfig.AddOption(new MaxDeliveryTime(2880)); var _orderGenerator = new SimulationCore.Helper.DistributionProvider.OrderGenerator(simConfig, dataBase.DbContext, productIds); for (int i = 0; i < orderCount; i++) { var order = _orderGenerator.GetNewRandomOrder(time: currentTime); currentTime = order.CreationTime; if (order.CreationTime > 10080) { break; } dataBase.DbContext.CustomerOrders.Add(order); } dataBase.DbContext.SaveChanges(); }
static void Main(string[] args) { Console.WriteLine(value: "Welcome to AkkaSim Cli"); // has to be Installed here other wise it would attach a new log listener every time a simulation is called. LogConfiguration.LogTo(TargetTypes.Console, TargetNames.LOG_AGENTS, LogLevel.Info, LogLevel.Info); //LogConfiguration.LogTo(TargetTypes.File, TargetNames.LOG_AGENTS, LogLevel.Debug, LogLevel.Debug); //LogConfiguration.LogTo(TargetTypes.File, TargetNames.LOG_AKKA, LogLevel.Trace); //LogConfiguration.LogTo(TargetTypes.Console, TargetNames.LOG_AKKA, LogLevel.Warn); //LogConfiguration.LogTo(TargetTypes.Debugger, TargetNames.LOG_AKKA, LogLevel.Warn); var masterDb = ProductionDomainContext.GetContext(ConfigurationManager.AppSettings[AgentCore.DEFAULT_CONNECTION]); var validCommands = Commands.GetAllValidCommands; var command = validCommands.Single(predicate: x => x.ArgLong == "Help"); var lastArg = 0; var config = new SimulationCore.Environment.Configuration(); for (; lastArg < args.Length; lastArg++) { if (args[lastArg] == "-?" || args[lastArg] == "/?") { command.Action(arg1: null, arg2: null); return; } if (ArgumentConverter.IsArg(validCommands: validCommands, argument: args[lastArg], command: ref command)) { if (command.HasProperty) { lastArg++; command.Action(arg1: config, arg2: args[lastArg]); } else { command.Action(arg1: config, arg2: null); } } } if (config.TryGetValue(typeof(StartHangfire), out object startHangfire)) { StartHangfire(((StartHangfire)startHangfire).Silent).Wait(); } else { RunSimulationTask(masterDb: masterDb, config: config).Wait(); Console.WriteLine(value: "Simulation Run Finished."); } }
private static async Task RunSimulationTask(ProductionDomainContext masterDb , SimulationCore.Environment.Configuration config) { foreach (var item in config) { Console.WriteLine(item.Key + " " + ((dynamic)item.Value).Value.ToString()); } try { Console.WriteLine(value: "Starting AkkaSim."); var agentCore = new AgentCore(context: masterDb, messageHub: new ConsoleHub()); await agentCore.RunAkkaSimulation(configuration : config); } catch (Exception) { Console.WriteLine(value: "Ooops. Something went wrong!"); throw; } }