internal static void CreateDomain(string domainName, string domainXml, IEnumerable <XmlFile> variants) { NegotiationContainer cont = new NegotiationContainer(); var domainVariants = variants.Select(x => new DomainVariant() { Name = x.Name, VariantXML = x.Content }).ToList(); cont.DomainVariantSet.AddRange(domainVariants); cont.GameDomainSet.Add(new GameDomain() { Name = domainName, DomainXML = domainXml, DomainVariant = domainVariants }); cont.SaveChanges(); if (GameDomain == null) { SetNewDomain(cont.GameDomainSet.First().Id); } }
public static AiConfig GetAiConfig() { NegotiationContainer cont = new NegotiationContainer(); var gameConfig = cont.GameDomainConfigSet.FirstOrDefault(); if (gameConfig == null) { return(new AiConfig() { Side = "", Variant = "", Type = UserType.Agent, StrategyId = 0 }); } var strat = cont.StrategyConfigSet.FirstOrDefault(); return(new AiConfig { Side = gameConfig.AiSide, Variant = gameConfig.AiVariant, Type = UserType.Agent, StrategyId = strat != null ? strat.Id : 0 }); }
private static void SetupStrategy() { NegotiationContainer cont = new NegotiationContainer(); var strat = cont.StrategyConfigSet.FirstOrDefault(); if (strat != null) { m_currentStrategyDirPath = Path.GetDirectoryName(HttpContext.Current.Server.MapPath(strat.Strategy.DllPath)); } }
static void LoadDbData() { var domainConfig = new NegotiationContainer().GameDomainConfigSet.FirstOrDefault(); if (domainConfig != null) { Config = domainConfig; GameDomain = domainConfig.GameDomain; LoadDomain(); } }
internal static void SetDomainVariants(string humanSide, string humanVariant, string aiVariant) { NegotiationContainer cont = new NegotiationContainer(); var domainConfig = cont.GameDomainConfigSet.First(); domainConfig.HumanSide = humanSide; domainConfig.HumanVariant = humanVariant; domainConfig.AiSide = Domain.OwnerVariantDict.Keys.Except(humanSide).First(); domainConfig.AiVariant = aiVariant; cont.SaveChanges(); Config = domainConfig; }
internal static void SaveNegotiationEnd(String negotiationId, int humanScore, int agentScore, DateTime negotiationEndTime) { NegotiationContainer cont = new NegotiationContainer(); var game = cont.GameSet.Find(negotiationId); if (game == null) { return; } game.Users.First(x => x.Type == UserType.Agent).Score = agentScore; game.Users.First(x => x.Type == UserType.Human).Score = humanScore; game.Endtime = negotiationEndTime; cont.SaveChanges(); }
internal static IAgentStrategy GetStrategy(int strategyId, out String strategyName) { NegotiationContainer cont = new NegotiationContainer(); var strat = cont.StrategySet.Find(strategyId); String dllPath = HttpContext.Current.Server.MapPath(strat.DllPath); String dllDir = System.IO.Path.GetDirectoryName(dllPath); Assembly assembly = Assembly.LoadFile(dllPath); Type type = assembly.GetTypes().First(x => x.GetInterface("IAgentStrategy") != null); IAgentStrategy example = assembly.CreateInstance(type.FullName) as IAgentStrategy; strategyName = strat.StrategyName; return(example); }
internal static void CreateStrategy(string strategyName, string DllPath) { NegotiationContainer cont = new NegotiationContainer(); cont.StrategySet.Add(new Strategy() { StrategyName = strategyName, DllPath = DllPath }); cont.SaveChanges(); if (!cont.StrategyConfigSet.Any()) { SetNewStrategy(cont.StrategySet.First().Id); } }
private static void SaveAction(NegotiationEngine engine, SideConfig side, NegotiationActionType type, String value = "") { NegotiationContainer cont = new NegotiationContainer(); var game = cont.GameSet.Find(engine.NegotiationId); var user = game.Users.First(x => x.Type == side.Type); cont.NegotiationActionSet.Add(new NegotiationAction() { GameId = engine.NegotiationId, Type = type, User = user, RemainingTime = engine.Status.RemainingTime, UserId = user.Id, Value = value }); cont.SaveChanges(); }
internal static void SetNewStrategy(int newActiveStrategy) { NegotiationContainer cont = new NegotiationContainer(); var stratId = GetAiConfig().StrategyId; if (stratId != 0) { cont.StrategyConfigSet.Remove(cont.StrategyConfigSet.Find(stratId)); } cont.StrategyConfigSet.Add(new StrategyConfig() { Id = newActiveStrategy }); cont.SaveChanges(); SetupStrategy(); }
internal static void SetNewDomain(int newActiveDomain) { NegotiationContainer cont = new NegotiationContainer(); if (GameDomain != null) { var activeConfig = cont.GameDomainConfigSet.Find(GameDomain.Id); if (activeConfig != null) { cont.GameDomainConfigSet.Remove(activeConfig); } } GameDomain = cont.GameDomainSet.Find(newActiveDomain); LoadDomain(); string humanSide = Domain.OwnerVariantDict.Keys.First(); string aiSide = Domain.OwnerVariantDict.Keys.ElementAt(1); Config = new GameDomainConfig() { Id = newActiveDomain, HumanSide = humanSide, HumanVariant = Domain.OwnerVariantDict[humanSide].Keys.First(), AiSide = aiSide, AiVariant = Domain.OwnerVariantDict[aiSide].Keys.First() }; cont.GameDomainConfigSet.Add(Config); try { cont.SaveChanges(); } catch (Exception ex) { throw; } LoadDbData(); }
internal static void SaveNegotiationEnd(String negotiationId, int humanScore, int agentScore, DateTime negotiationEndTime) { NegotiationContainer cont = new NegotiationContainer(); var game = cont.GameSet.Find(negotiationId); if (game == null) return; game.Users.First(x => x.Type == UserType.Agent).Score = agentScore; game.Users.First(x => x.Type == UserType.Human).Score = humanScore; game.Endtime = negotiationEndTime; cont.SaveChanges(); }
internal static object GetUser(string userId) { NegotiationContainer cont = new NegotiationContainer(); return cont.UserSet.Find(userId); }
internal static IAgentStrategy GetStrategy(int strategyId, out String strategyName) { NegotiationContainer cont = new NegotiationContainer(); var strat = cont.StrategySet.Find(strategyId); String dllPath = HttpContext.Current.Server.MapPath(strat.DllPath); String dllDir = System.IO.Path.GetDirectoryName(dllPath); Assembly assembly = Assembly.LoadFile(dllPath); Type type = assembly.GetTypes().First(x => x.GetInterface("IAgentStrategy") != null); IAgentStrategy example = assembly.CreateInstance(type.FullName) as IAgentStrategy; strategyName = strat.StrategyName; return example; }
internal static IEnumerable<Game> GetGames() { NegotiationContainer cont = new NegotiationContainer(); return cont.GameSet; }
internal static object GetGame(string gameId) { NegotiationContainer cont = new NegotiationContainer(); return cont.GameSet.Find(gameId); }
internal static IEnumerable <Game> GetGames() { NegotiationContainer cont = new NegotiationContainer(); return(cont.GameSet); }
internal static void SaveNewNegotiation(NegotiationEngine engine, PreNegotiationQuestionnaireViewModel model) { NegotiationContainer cont = new NegotiationContainer(); #region Human User UserRole humanRole = new UserRole() { Description = engine.HumanConfig.Side, Variant = engine.HumanConfig.Variant }; UserData humanData = new UserData() { AgeRange = model.AgeRange, Country = model.BirthCountry, DegreeField = model.DegreeField, Education = model.Education, Gender = model.Gender, StudentId = model.ID, Name = model.Name, University = model.University }; User humanUser = new User() { Id = engine.NegotiationId, Type = UserType.Human, UserData = humanData, UserRole = humanRole, GameId = engine.NegotiationId }; #endregion #region Ai User UserRole aiRole = new UserRole() { Description = engine.AiConfig.Side, Variant = engine.AiConfig.Variant }; User aiUser = new User() { Id = engine.StrategyName + "|" + DateTime.Now, Type = UserType.Agent, StrategyId = engine.AiConfig.StrategyId, UserRole = aiRole, GameId = engine.NegotiationId, }; #endregion cont.GameSet.Add(new Game() { Id = engine.NegotiationId, GameDomainId = GameDomain.Id, StartTime = DateTime.Now }); cont.UserDataSet.Add(humanData); cont.UserRoleSet.Add(humanRole); cont.UserRoleSet.Add(aiRole); cont.UserSet.Add(humanUser); cont.UserSet.Add(aiUser); try { cont.SaveChanges(); } catch (Exception) { throw; } }
internal static object GetUser(string userId) { NegotiationContainer cont = new NegotiationContainer(); return(cont.UserSet.Find(userId)); }
internal static object GetGame(string gameId) { NegotiationContainer cont = new NegotiationContainer(); return(cont.GameSet.Find(gameId)); }
private static void SetupStrategy() { NegotiationContainer cont = new NegotiationContainer(); var strat = cont.StrategyConfigSet.FirstOrDefault(); m_currentStrategyDirPath = Path.GetDirectoryName(HttpContext.Current.Server.MapPath(strat.Strategy.DllPath)); }
public static AiConfig GetAiConfig() { NegotiationContainer cont = new NegotiationContainer(); var gameConfig = cont.GameDomainConfigSet.First(); var strat = cont.StrategyConfigSet.FirstOrDefault(); return new AiConfig { Side = gameConfig.AiSide, Variant = gameConfig.AiVariant, Type = UserType.Agent, StrategyId = strat != null ? strat.Id : 0 }; }
internal static void CreateDomain(string domainName, string domainXml, IEnumerable<XmlFile> variants) { NegotiationContainer cont = new NegotiationContainer(); var domainVariants = variants.Select(x => new DomainVariant() { Name = x.Name, VariantXML = x.Content }).ToList(); cont.DomainVariantSet.AddRange(domainVariants); cont.GameDomainSet.Add(new GameDomain() { Name = domainName, DomainXML = domainXml, DomainVariant = domainVariants }); cont.SaveChanges(); if (GameDomain == null) { SetNewDomain(cont.GameDomainSet.First().Id); } }