コード例 #1
0
        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();
        }
コード例 #2
0
 internal static void SaveUserOptionChange(NegotiationEngine engine, string topic, string option)
 {
     SaveAction(engine, engine.HumanConfig, NegotiationActionType.MakeChange, String.Format("{{\"{0}\":\"{1}\"}}", topic, option));
 }
コード例 #3
0
 internal static void SaveTimeout(NegotiationEngine engine)
 {
     SaveAction(engine, engine.HumanConfig, NegotiationActionType.Timeout);
 }
コード例 #4
0
 internal static void SaveAgreementSigned(NegotiationEngine engine, SideConfig side)
 {
     SaveAction(engine, side, NegotiationActionType.Sign);
 }
コード例 #5
0
 internal static void SaveOfferRejected(NegotiationEngine engine, SideConfig side)
 {
     SaveAction(engine, side, NegotiationActionType.RejectOffer);
 }
コード例 #6
0
 internal static void SaveOptOut(NegotiationEngine engine, SideConfig side)
 {
     SaveAction(engine, side, NegotiationActionType.Optout);
 }
コード例 #7
0
 internal static void SaveNewOffer(NegotiationEngine engine, SideConfig side, string negotiationOffer)
 {
     SaveAction(engine, side, NegotiationActionType.MakeOffer, negotiationOffer);
 }
コード例 #8
0
        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;
            }
        }