public int Save(SimulationModel model) { ProjectBroker projectBroker = new ProjectBroker(); SupplierBroker supplierBroker = new SupplierBroker(); ShopBroker shopBroker = new ShopBroker(); BuyerBroker buyerBroker = new BuyerBroker(); ConnectionBroker connectionBroker = new ConnectionBroker(); //najpierw zapis podczas ktorego zbieram using (IDbConnection connection = new ConnectionProvider().GetConnection(true)) { IDbTransaction transaction = connection.BeginTransaction(); try { if (model.Project.Id != 0) { buyerBroker.RemoveNotExistingFromProject(connection, model.Project.Id, model.GetListOfBuyersIds()); shopBroker.RemoveNotExistingFromProject(connection, model.Project.Id, model.GetListOfShopsIds()); supplierBroker.RemoveNotExistingFromProject(connection, model.Project.Id, model.GetListOfSuppliersIds()); connectionBroker.RemoveNotExistingFromProject(connection, model.Project.Id, model.GetListOfConnectionsIds()); } projectBroker.Save(connection, model.Project, transaction); foreach (Buyer buyer in model.Buyers) { buyer.ProjectId = model.Project.Id; buyerBroker.Save(connection, buyer, transaction); } foreach (Shop shop in model.Shops) { shop.ProjectId = model.Project.Id; shopBroker.Save(connection, shop, transaction); } foreach (Supplier supplier in model.Suppliers) { supplier.ProjectId = model.Project.Id; supplierBroker.Save(connection, supplier, transaction); } foreach (Connection conn in model.Connections) { conn.ProjectId = model.Project.Id; conn.ActorAId = conn.ActorA.Id; conn.ActorBId = conn.ActorB.Id; connectionBroker.Save(connection, conn, transaction); } transaction.Commit(); } catch (Exception) { transaction.Rollback(); throw; } } return(1); }
public int SaveAs(SimulationModel model) { int oldId = model.Project.Id; ProjectBroker projectBroker = new ProjectBroker(); SupplierBroker supplierBroker = new SupplierBroker(); ShopBroker shopBroker = new ShopBroker(); BuyerBroker buyerBroker = new BuyerBroker(); ConnectionBroker connectionBroker = new ConnectionBroker(); //I will set all ids to 0, so it wil add new rows and inserts function //set id to proper one. using (IDbConnection connection = new ConnectionProvider().GetConnection(true)) { IDbTransaction transaction = connection.BeginTransaction(); try { model.Project.Id = 0; projectBroker.Save(connection, model.Project, transaction); foreach (Buyer buyer in model.Buyers) { buyer.Id = 0; buyer.ProjectId = model.Project.Id; buyerBroker.Save(connection, buyer, transaction); } foreach (Shop shop in model.Shops) { shop.Id = 0; shop.ProjectId = model.Project.Id; shopBroker.Save(connection, shop, transaction); } foreach (Supplier supplier in model.Suppliers) { supplier.Id = 0; supplier.ProjectId = model.Project.Id; supplierBroker.Save(connection, supplier, transaction); } foreach (Connection conn in model.Connections) { conn.Id = 0; conn.ProjectId = model.Project.Id; conn.ActorAId = conn.ActorA.Id; conn.ActorBId = conn.ActorB.Id; connectionBroker.Save(connection, conn, transaction); } transaction.Commit(); } catch (Exception) { model.Project.Id = oldId; transaction.Rollback(); throw; } } return(1); }
private static void Main(string[] args) { ConnectionBroker connectionBroker = new ConnectionBroker(); Router.Router router = new Router.Router(); Orchestrator.Orchestrator orchestrator = new Orchestrator.Orchestrator(connectionBroker, router); Communication.API.Program.Main(Array.Empty <string>()); }
/// <summary> /// Initializes a new instance of the <see cref="Lobby"/> class. /// </summary> /// <param name="name">Name of the new <see cref="Lobby"/>.</param> /// <param name="password">Password of the new <see cref="Lobby"/>.</param> /// <param name="connectionBroker"><see cref="ConnectionBroker"/> that this <see cref="Lobby"/> should get open connections from.</param> /// <param name="router">Router the new <see cref="Lobby"/> should connect to.</param> public Lobby(string name, string password, ConnectionBroker connectionBroker, Router.Router router) { this.Broadcaster = new Broadcaster(connectionBroker); this.Id = router.Register(this); this.Name = name; this.Password = password; this.Router = router; this.ResetInactivityTimer(); }
/// <summary> /// Initializes a new instance of the <see cref="Orchestrator"/> class. /// </summary> /// <param name="connectionBroker">The <see cref="ConnectionBroker"/> that lobbies created by this <see cref="Orchestrator"/> should request sockets from.</param> /// <param name="router">Router to connect new lobbies to.</param> internal Orchestrator(ConnectionBroker connectionBroker, Router.Router router) { this.ConnectionBroker = connectionBroker; this.Router = router; API.Instance.AttachCreateLobbyHandler(this); API.Instance.AttachHighScoreListHandler(this); API.Instance.AttachLobbyHandler(this); API.Instance.AttachLobbyListHandler(this); API.Instance.AttachVerifyVersionHandler(this); }
public SimulationModel Get(Project project) { SimulationModel model = new SimulationModel(); SupplierBroker supplierBroker = new SupplierBroker(); ShopBroker shopBroker = new ShopBroker(); BuyerBroker buyerBroker = new BuyerBroker(); ConnectionBroker connectionBroker = new ConnectionBroker(); model.Project = project; using (IDbConnection connection = new ConnectionProvider().GetConnection(true)) { model.Buyers = buyerBroker.GetAllFromProject(connection, model.Project.Id).ToList(); model.Shops = shopBroker.GetAllFromProject(connection, model.Project.Id).ToList(); model.Suppliers = supplierBroker.GetAllFromProject(connection, model.Project.Id).ToList(); model.Connections = connectionBroker.GetAllFromProject(connection, model.Project.Id).ToList(); } foreach (Connection conn in model.Connections) { switch (conn.ConnectionType) { case DataModel.EnumTypes.ConnectionTypes.ShopToBuyer: conn.ActorA = model.Shops.Find(x => x.Id == conn.ActorAId); conn.ActorB = model.Buyers.Find(x => x.Id == conn.ActorBId); break; case DataModel.EnumTypes.ConnectionTypes.ShopToShop: conn.ActorA = model.Shops.Find(x => x.Id == conn.ActorAId); conn.ActorB = model.Shops.Find(x => x.Id == conn.ActorBId); break; case DataModel.EnumTypes.ConnectionTypes.SupplierToShop: conn.ActorA = model.Suppliers.Find(x => x.Id == conn.ActorAId); conn.ActorB = model.Shops.Find(x => x.Id == conn.ActorBId); break; default: break; } } return(model); }