コード例 #1
0
        public static async Task <IList <Player> > LoadRandom(
            SocialGamificationAssetContext db,
            Player player,
            IList <CustomDataBase> customData,
            bool alliancesOnly = false,
            int limit          = 1)
        {
            var query = db.Players.Where(a => a.Role == AccountType.Player);

            if (alliancesOnly)
            {
                var alliancesList = Alliance.GetAllianceIds(db, player.Id, AllianceState.Accepted);

                query = query.Where(p => alliancesList.Contains(p.Id));
            }
            else
            {
                query = query.Where(p => p.Id != player.Id);
            }

            // CustomData conditions
            var customDataQuery = Models.CustomData.ConditionBuilder(db, customData, CustomDataType.Player);

            if (customDataQuery != null)
            {
                IList <Guid> similarPlayers = await customDataQuery.Select(c => c.ObjectId).Distinct().ToListAsync();

                // Check if Players satisfy CustomData constraints
                query = query.Where(p => similarPlayers.Contains(p.Id));
            }

            IList <Player> players = await query.ToListAsync();

            return(GenericHelper.Shuffle(players, limit));
        }
コード例 #2
0
ファイル: Player.cs プロジェクト: playgenhub/rage-sga-server
        public static async Task<IList<Player>> LoadRandom(
            SocialGamificationAssetContext db,
            Player player,
            IList<CustomDataBase> customData,
            bool alliancesOnly = false,
            int limit = 1)
        {
            var query = db.Players.Where(a => a.Role == AccountType.Player);

            if (alliancesOnly)
            {
                var alliancesList = Alliance.GetAllianceIds(db, player.Id, AllianceState.Accepted);

                query = query.Where(p => alliancesList.Contains(p.Id));
            }
            else
            {
                query = query.Where(p => p.Id != player.Id);
            }

            // CustomData conditions
            var customDataQuery = Models.CustomData.ConditionBuilder(db, customData, CustomDataType.Player);
            if (customDataQuery != null)
            {
                IList<Guid> similarPlayers = await customDataQuery.Select(c => c.ObjectId).Distinct().ToListAsync();

                // Check if Players satisfy CustomData constraints
                query = query.Where(p => similarPlayers.Contains(p.Id));
            }

            IList<Player> players = await query.ToListAsync();

            return GenericHelper.Shuffle(players, limit);
        }
コード例 #3
0
ファイル: Goal.cs プロジェクト: playgenhub/rage-sga-server
        public async Task<Reward> CalculateRewardFromAction(SocialGamificationAssetContext context, string actionVerb)
        {
            var actionMatch = Actions.FirstOrDefault(a => a.Verb.Equals(actionVerb));

            if (actionMatch != null)
            {
                actionMatch.Relations =
                    await
                    context.ActionRelations.Where(a => a.ActionId.Equals(actionMatch.Id))
                           .Include(ar => ar.AttributeChanges.Select(ac => ac.AttributeType))
                           .ToListAsync();

                foreach (var ar in actionMatch.Relations)
                {
                    foreach (var reward in ar.AttributeChanges)
                    {
                        var rewardMatch =
                            Rewards.Where(r => r.TypeReward.Equals(RewardType.Store))
                                   .Where(r => r.AttributeType.Name.Equals(reward.AttributeType.Name))
                                   .FirstOrDefault();

                        if (rewardMatch != null)
                        {
                            rewardMatch.Value += reward.Value;
                            return rewardMatch;
                        }
                    }
                }
            }

            return null;
        }
コード例 #4
0
ファイル: Group.cs プロジェクト: playgenhub/rage-sga-server
        public static async Task<IList<Group>> LoadRandom(
            SocialGamificationAssetContext db,
            Group group,
            IList<CustomDataBase> customData,
            bool alliancesOnly = false,
            int limit = 1)
        {
            IQueryable<Group> query = db.Groups;

            if (alliancesOnly)
            {
                var alliancesList = Alliance.GetAllianceIds(db, group.Id, AllianceState.Accepted);

                query = query.Where(a => alliancesList.Contains(group.Id));
            }
            else
            {
                query = query.Where(g => g.Id != group.Id).Where(g => g.Type == GroupVisibility.Public);
            }

            // CustomData conditions
            var cQuery = Models.CustomData.ConditionBuilder(db, customData, CustomDataType.Group);
            IList<Guid> similarGroups = await cQuery.Select(c => c.ObjectId).Distinct().ToListAsync();

            // Check if Group satisfy CustomData constraints
            IList<Group> groups = await query.Where(g => similarGroups.Contains(g.Id)).ToListAsync();

            return GenericHelper.Shuffle(groups, limit);
        }
コード例 #5
0
ファイル: Group.cs プロジェクト: ahirmayur/rage-sga-server
        public static async Task <IList <Group> > LoadRandom(
            SocialGamificationAssetContext db,
            Group group,
            IList <CustomDataBase> customData,
            bool alliancesOnly = false,
            int limit          = 1)
        {
            IQueryable <Group> query = db.Groups;

            if (alliancesOnly)
            {
                var alliancesList = Alliance.GetAllianceIds(db, group.Id, AllianceState.Accepted);

                query = query.Where(a => alliancesList.Contains(group.Id));
            }
            else
            {
                query = query.Where(g => g.Id != group.Id).Where(g => g.Type == GroupVisibility.Public);
            }

            // CustomData conditions
            var          cQuery        = Models.CustomData.ConditionBuilder(db, customData, CustomDataType.Group);
            IList <Guid> similarGroups = await cQuery.Select(c => c.ObjectId).Distinct().ToListAsync();

            // Check if Group satisfy CustomData constraints
            IList <Group> groups = await query.Where(g => similarGroups.Contains(g.Id)).ToListAsync();

            return(GenericHelper.Shuffle(groups, limit));
        }
コード例 #6
0
        public async Task <Reward> CalculateRewardFromAction(SocialGamificationAssetContext context, string actionVerb)
        {
            var actionMatch = Actions.FirstOrDefault(a => a.Verb.Equals(actionVerb));

            if (actionMatch != null)
            {
                actionMatch.Relations =
                    await
                    context.ActionRelations.Where(a => a.ActionId.Equals(actionMatch.Id))
                    .Include(ar => ar.AttributeChanges.Select(ac => ac.AttributeType))
                    .ToListAsync();

                foreach (var ar in actionMatch.Relations)
                {
                    foreach (var reward in ar.AttributeChanges)
                    {
                        var rewardMatch =
                            Rewards.Where(r => r.TypeReward.Equals(RewardType.Store))
                            .Where(r => r.AttributeType.Name.Equals(reward.AttributeType.Name))
                            .FirstOrDefault();

                        if (rewardMatch != null)
                        {
                            rewardMatch.Value += reward.Value;
                            return(rewardMatch);
                        }
                    }
                }
            }

            return(null);
        }
コード例 #7
0
        public static async Task<ContentResult> Add(SocialGamificationAssetContext db, Match match, Actor actor)
        {
            // Add actors to this match
            var matchActor = new MatchActor { MatchId = match.Id, ActorId = actor.Id };

            db.MatchActors.Add(matchActor);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbEntityValidationException e)
            {
                return HttpResponseHelper.ErrorContentResult(e.Message, StatusCodes.Status500InternalServerError);
            }

            for (var i = 1; i <= match.TotalRounds; ++i)
            {
                // Add round(s) entry for each Actor
                var matchRound = new MatchRound { MatchActorId = matchActor.Id, RoundNumber = i };

                db.MatchRounds.Add(matchRound);

                try
                {
                    await db.SaveChangesAsync();
                }
                catch (DbEntityValidationException e)
                {
                    return HttpResponseHelper.ErrorContentResult(e.Message, StatusCodes.Status500InternalServerError);
                }
            }

            return null;
        }
コード例 #8
0
        /// <summary>
        ///     <para>
        ///         Assign <see cref="SocialGamificationAsset.Models.Player.Groups" />
        ///     </para>
        ///     <para>to the Player.</para>
        /// </summary>
        public void AddGroups(SocialGamificationAssetContext db, ICollection <Player> groupsList)
        {
            var groupIds = groupsList.Select(a => a.Id).ToList();

            var groups = db.Groups.Where(g => groupIds.Contains(g.Id)).ToList();

            Groups = new List <Group>(groups);
        }
コード例 #9
0
        public ApiController(SocialGamificationAssetContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            _context = context;
        }
コード例 #10
0
        /**
         * Get the current session of Logged account
         *
         * @return Session
         */

        public static async Task <Session> GetSession(SocialGamificationAssetContext db, Guid playerId)
        {
            var session =
                await
                db.Players.Where(p => p.Id.Equals(playerId))
                .Include(p => p.Sessions.Where(s => s.IsExpired.Equals(false)).OrderByDescending(s => s.UpdatedDate))
                .Select(p => p.Sessions)
                .FirstOrDefaultAsync() as Session;

            return(session);
        }
コード例 #11
0
ファイル: Group.cs プロジェクト: playgenhub/rage-sga-server
        /// <summary>
        ///     <para>
        ///         Assign <see cref="SocialGamificationAsset.Models.Group.Players" />
        ///     </para>
        ///     <para>to the Group.</para>
        /// </summary>
        public void AddPlayers(SocialGamificationAssetContext db, ICollection<Player> playersList)
        {
            if (playersList.Count < 2)
            {
                Console.WriteLine("At least two Players are required to create a Group.");
                return;
            }

            var playerIds = playersList.Select(a => a.Id).ToList();

            var players = db.Players.Where(p => playerIds.Contains(p.Id)).ToList();

            Players = new List<Player>(players);
        }
コード例 #12
0
ファイル: Group.cs プロジェクト: ahirmayur/rage-sga-server
        /// <summary>
        ///     <para>
        ///         Assign <see cref="SocialGamificationAsset.Models.Group.Players" />
        ///     </para>
        ///     <para>to the Group.</para>
        /// </summary>
        public void AddPlayers(SocialGamificationAssetContext db, ICollection <Player> playersList)
        {
            if (playersList.Count < 2)
            {
                Console.WriteLine("At least two Players are required to create a Group.");
                return;
            }

            var playerIds = playersList.Select(a => a.Id).ToList();

            var players = db.Players.Where(p => playerIds.Contains(p.Id)).ToList();

            Players = new List <Player>(players);
        }
コード例 #13
0
 protected static async Task SaveChanges(SocialGamificationAssetContext _context, bool isAsync = false)
 {
     try
     {
         if (isAsync)
         {
             await _context.SaveChangesAsync();
         }
         else
         {
             _context.SaveChanges();
         }
     }
     catch (DbUpdateException e)
     {
         throw e;
     }
 }
コード例 #14
0
        public static async Task<ContentResult> AddOrUpdate(
            SocialGamificationAssetContext db,
            IList<CustomDataBase> sourceData,
            Guid objectId,
            CustomDataType objectType)
        {
            // Build the filter by CustomData
            if (sourceData != null && sourceData.Count > 0)
            {
                foreach (var data in sourceData)
                {
                    var customData =
                        await
                        db.CustomData.Where(c => c.Key.Equals(data.Key))
                          .Where(c => c.ObjectId.Equals(objectId))
                          .Where(c => c.ObjectType == objectType)
                          .FirstOrDefaultAsync();

                    if (customData != null)
                    {
                        db.Entry(customData).State = EntityState.Modified;
                        customData.Value = data.Value;
                    }
                    else
                    {
                        customData = new CustomData
                        {
                            Key = data.Key,
                            Value = data.Value,
                            ObjectId = objectId,
                            ObjectType = objectType
                        };

                        db.CustomData.Add(customData);
                    }
                }
            }

            return await SaveChanges(db, true);
        }
コード例 #15
0
        public static async Task <ContentResult> AddOrUpdate(
            SocialGamificationAssetContext db,
            IList <CustomDataBase> sourceData,
            Guid objectId,
            CustomDataType objectType)
        {
            // Build the filter by CustomData
            if (sourceData != null && sourceData.Count > 0)
            {
                foreach (var data in sourceData)
                {
                    var customData =
                        await
                        db.CustomData.Where(c => c.Key.Equals(data.Key))
                        .Where(c => c.ObjectId.Equals(objectId))
                        .Where(c => c.ObjectType == objectType)
                        .FirstOrDefaultAsync();

                    if (customData != null)
                    {
                        db.Entry(customData).State = EntityState.Modified;
                        customData.Value           = data.Value;
                    }
                    else
                    {
                        customData = new CustomData
                        {
                            Key        = data.Key,
                            Value      = data.Value,
                            ObjectId   = objectId,
                            ObjectType = objectType
                        };

                        db.CustomData.Add(customData);
                    }
                }
            }

            return(await SaveChanges(db, true));
        }
コード例 #16
0
        public static async Task <ContentResult> Add(SocialGamificationAssetContext db, Match match, Actor actor)
        {
            // Add actors to this match
            var matchActor = new MatchActor {
                MatchId = match.Id, ActorId = actor.Id
            };

            db.MatchActors.Add(matchActor);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbEntityValidationException e)
            {
                return(HttpResponseHelper.ErrorContentResult(e.Message, StatusCodes.Status500InternalServerError));
            }

            for (var i = 1; i <= match.TotalRounds; ++i)
            {
                // Add round(s) entry for each Actor
                var matchRound = new MatchRound {
                    MatchActorId = matchActor.Id, RoundNumber = i
                };

                db.MatchRounds.Add(matchRound);

                try
                {
                    await db.SaveChangesAsync();
                }
                catch (DbEntityValidationException e)
                {
                    return(HttpResponseHelper.ErrorContentResult(e.Message, StatusCodes.Status500InternalServerError));
                }
            }

            return(null);
        }
コード例 #17
0
        public static IQueryable <CustomData> ConditionBuilder(
            SocialGamificationAssetContext db,
            IList <CustomDataBase> sourceData,
            CustomDataType objectType)
        {
            var query = db.CustomData.Where(c => c.ObjectType == objectType);

            if (sourceData == null || sourceData.Count <= 0)
            {
                return(null);
            }

            foreach (var data in sourceData)
            {
                query = query.Where(c => c.Key.Equals(data.Key));

                if (!AllowedOperators.Contains(data.Operator))
                {
                    continue;
                }

                switch (data.Operator)
                {
                case "=":
                    query = query.Where(c => c.Value.Equals(data.Value));
                    break;

                case "!":
                    query = query.Where(c => c.Value != data.Value);
                    break;

                case "%":
                    query = query.Where(c => c.Value.Contains(data.Value));
                    break;
                }
            }

            return(query);
        }
コード例 #18
0
        protected static async Task SeedGames(SocialGamificationAssetContext _context, bool isAsync = false)
        {
            if (!_context.GameRegistry.Any())
            {
                IList <GameRegistry> games = new List <GameRegistry>
                {
                    new GameRegistry {
                        Name = "ButtonGame", DeveloperName = "PlayGen"
                    },
                    new GameRegistry {
                        Name = "TankGame", DeveloperName = "PlayGen"
                    }
                };

                _context.GameRegistry.AddRange(games);

                await SaveChanges(_context, isAsync);

                Debug.WriteLine("Games Seeded.");

                // GameRegistry Game = await _context.GameRegistry.Where(g => g.Username.Equals("ButtonGame")).FirstOrDefaultAsync();
            }
        }
コード例 #19
0
        protected static async Task SeedAlliances(SocialGamificationAssetContext _context, bool isAsync = false)
        {
            if (!_context.Alliances.Any())
            {
                var mayur = await _context.Players.Where(a => a.Username.Equals("mayur")).FirstOrDefaultAsync();

                var matt = await _context.Players.Where(a => a.Username.Equals("matt")).FirstOrDefaultAsync();

                var jack = await _context.Players.Where(a => a.Username.Equals("jack")).FirstOrDefaultAsync();

                var kam = await _context.Players.Where(a => a.Username.Equals("kam")).FirstOrDefaultAsync();

                var ben = await _context.Players.Where(a => a.Username.Equals("ben")).FirstOrDefaultAsync();

                IList <Alliance> alliances = new List <Alliance>
                {
                    new Alliance {
                        RequesterId = mayur.Id, RequesteeId = matt.Id, State = AllianceState.Pending
                    },
                    new Alliance {
                        RequesterId = mayur.Id, RequesteeId = jack.Id, State = AllianceState.Accepted
                    },
                    new Alliance {
                        RequesterId = jack.Id, RequesteeId = matt.Id, State = AllianceState.Declined
                    },
                    new Alliance {
                        RequesterId = kam.Id, RequesteeId = mayur.Id, State = AllianceState.Accepted
                    }
                };

                _context.Alliances.AddRange(alliances);

                await SaveChanges(_context, isAsync);

                Debug.WriteLine("Alliances Seeded.");
            }
        }
コード例 #20
0
ファイル: DbEntity.cs プロジェクト: ahirmayur/rage-sga-server
        /// <summary>
        ///     Asynchronously save data
        /// </summary>
        /// <returns>
        ///     <para>
        ///         ErrorContentResult if
        ///         <see cref="System.Data.Entity.Infrastructure.DbUpdateException" />
        ///     </para>
        ///     <para>exception occurs</para>
        /// </returns>
        public static async Task <ContentResult> SaveChanges(
            SocialGamificationAssetContext _context,
            bool isAsync = false)
        {
            try
            {
                if (isAsync)
                {
                    await _context.SaveChangesAsync();
                }
                else
                {
                    _context.SaveChanges();
                }
            }
            catch (DbUpdateException e)
            {
                return(HttpResponseHelper.ErrorContentResult(
                           GetExceptionString(e),
                           StatusCodes.Status500InternalServerError));
            }

            return(null);
        }
コード例 #21
0
        /// <summary>
        ///     Asynchronously save data
        /// </summary>
        /// <returns>
        ///     <para>
        ///         ErrorContentResult if
        ///         <see cref="System.Data.Entity.Infrastructure.DbUpdateException" />
        ///     </para>
        ///     <para>exception occurs</para>
        /// </returns>
        public static async Task<ContentResult> SaveChanges(
            SocialGamificationAssetContext _context,
            bool isAsync = false)
        {
            try
            {
                if (isAsync)
                {
                    await _context.SaveChangesAsync();
                }
                else
                {
                    _context.SaveChanges();
                }
            }
            catch (DbUpdateException e)
            {
                return HttpResponseHelper.ErrorContentResult(
                    GetExceptionString(e),
                    StatusCodes.Status500InternalServerError);
            }

            return null;
        }
コード例 #22
0
        protected static async Task SeedGroups(SocialGamificationAssetContext _context, bool isAsync = false)
        {
            if (!_context.Alliances.Any())
            {
                IList <Group> groups = new List <Group>
                {
                    new Group {
                        Username = "******"
                    },
                    new Group {
                        Username = "******"
                    },
                    new Group {
                        Username = "******"
                    }
                };

                _context.Groups.AddRange(groups);

                await SaveChanges(_context, isAsync);

                Debug.WriteLine("Groups Seeded.");
            }
        }
コード例 #23
0
ファイル: Actor.cs プロジェクト: ahirmayur/rage-sga-server
 public IQueryable <Actor> Alliances(SocialGamificationAssetContext db, AllianceState state)
 {
     return(Alliances(db, Id, state));
 }
コード例 #24
0
        /**
         * Check if the current Username already exists
         *
         * @return boolean Returns TRUE if Username exists
         */

        public static async Task <bool> ExistsUsername(SocialGamificationAssetContext db, string username)
        {
            var player = await db.Players.Where(p => p.Username.Equals(username)).FirstOrDefaultAsync();

            return(player != null);
        }
コード例 #25
0
ファイル: Group.cs プロジェクト: ahirmayur/rage-sga-server
 public async Task <ContentResult> AddOrUpdateCustomData(
     SocialGamificationAssetContext db,
     IList <CustomDataBase> sourceData)
 {
     return(await Models.CustomData.AddOrUpdate(db, sourceData, Id, CustomDataType.Group));
 }
コード例 #26
0
 public async Task <Session> GetSession(SocialGamificationAssetContext db)
 {
     return(await GetSession(db, Id));
 }
コード例 #27
0
 public TargetsController(SocialGamificationAssetContext context)
     : base(context)
 {
 }
コード例 #28
0
 public AchievementsController(SocialGamificationAssetContext context)
     : base(context)
 {
 }
コード例 #29
0
 public InventoryController(SocialGamificationAssetContext context)
     : base(context)
 {
 }
コード例 #30
0
        protected static async Task SeedAlliances(SocialGamificationAssetContext _context, bool isAsync = false)
        {
            if (!_context.Alliances.Any())
            {
                var mayur = await _context.Players.Where(a => a.Username.Equals("mayur")).FirstOrDefaultAsync();
                var matt = await _context.Players.Where(a => a.Username.Equals("matt")).FirstOrDefaultAsync();
                var jack = await _context.Players.Where(a => a.Username.Equals("jack")).FirstOrDefaultAsync();
                var kam = await _context.Players.Where(a => a.Username.Equals("kam")).FirstOrDefaultAsync();
                var ben = await _context.Players.Where(a => a.Username.Equals("ben")).FirstOrDefaultAsync();

                IList<Alliance> alliances = new List<Alliance>
                {
                    new Alliance { RequesterId = mayur.Id, RequesteeId = matt.Id, State = AllianceState.Pending },
                    new Alliance { RequesterId = mayur.Id, RequesteeId = jack.Id, State = AllianceState.Accepted },
                    new Alliance { RequesterId = jack.Id, RequesteeId = matt.Id, State = AllianceState.Declined },
                    new Alliance { RequesterId = kam.Id, RequesteeId = mayur.Id, State = AllianceState.Accepted }
                };

                _context.Alliances.AddRange(alliances);

                await SaveChanges(_context, isAsync);

                Debug.WriteLine("Alliances Seeded.");
            }
        }
コード例 #31
0
        protected static async Task SeedCustomData(SocialGamificationAssetContext _context, bool isAsync = false)
        {
            if (!_context.CustomData.Any())
            {
                var mayur = await _context.Players.Where(a => a.Username.Equals("mayur")).FirstOrDefaultAsync();
                var matt = await _context.Players.Where(a => a.Username.Equals("matt")).FirstOrDefaultAsync();
                var jack = await _context.Players.Where(a => a.Username.Equals("jack")).FirstOrDefaultAsync();
                var kam = await _context.Players.Where(a => a.Username.Equals("kam")).FirstOrDefaultAsync();
                var ben = await _context.Players.Where(a => a.Username.Equals("ben")).FirstOrDefaultAsync();

                IList<CustomData> customData = new List<CustomData>
                {
                    new CustomData
                    {
                        Key = "ip",
                        Value = "127.0.0.1",
                        ObjectId = mayur.Id,
                        ObjectType = CustomDataType.Player
                    },
                    new CustomData
                    {
                        Key = "ip",
                        Value = "127.0.0.1",
                        ObjectId = matt.Id,
                        ObjectType = CustomDataType.Player
                    },
                    new CustomData
                    {
                        Key = "ip",
                        Value = "127.0.0.1",
                        ObjectId = jack.Id,
                        ObjectType = CustomDataType.Player
                    },
                    new CustomData
                    {
                        Key = "ip",
                        Value = "127.0.0.1",
                        ObjectId = ben.Id,
                        ObjectType = CustomDataType.Player
                    },
                    new CustomData
                    {
                        Key = "video_id",
                        Value = "1234",
                        ObjectId = mayur.Id,
                        ObjectType = CustomDataType.Player
                    },
                    new CustomData
                    {
                        Key = "video_id",
                        Value = "1234",
                        ObjectId = matt.Id,
                        ObjectType = CustomDataType.Player
                    },
                    new CustomData
                    {
                        Key = "video_id",
                        Value = "1234",
                        ObjectId = jack.Id,
                        ObjectType = CustomDataType.Player
                    },
                    new CustomData
                    {
                        Key = "chat_id",
                        Value = "235f73ea-e54f-4150-8dc3-3eb9995d0728",
                        ObjectId = mayur.Id,
                        ObjectType = CustomDataType.Player
                    },
                    new CustomData
                    {
                        Key = "chat_id",
                        Value = "235f73ea-e54f-4150-8dc3-3eb9995d0728",
                        ObjectId = matt.Id,
                        ObjectType = CustomDataType.Player
                    }
                };

                _context.CustomData.AddRange(customData);

                await SaveChanges(_context, isAsync);

                Debug.WriteLine("CustomData Seeded.");
            }
        }
コード例 #32
0
        protected static async Task SeedPlayerSessions(SocialGamificationAssetContext _context, bool isAsync = false)
        {
            if (!_context.Sessions.Any())
            {
                var boardgame = await _context.Groups.Where(a => a.Username.Equals("boardgame")).FirstOrDefaultAsync();
                var gameideas = await _context.Groups.Where(a => a.Username.Equals("gameideas")).FirstOrDefaultAsync();
                var rage = await _context.Groups.Where(a => a.Username.Equals("rage")).FirstOrDefaultAsync();

                IList<Session> sessions = new List<Session>
                {
                    new Session
                    {
                        Player =
                            new Player
                            {
                                Username = "******",
                                Password = PasswordHelper.HashPassword("admin"),
                                Role = AccountType.Admin
                            }
                    },
                    new Session
                    {
                        Player =
                            new Player
                            {
                                Username = "******",
                                Password = PasswordHelper.HashPassword("playgen"),
                                Role = AccountType.Admin
                            }
                    },
                    new Session
                    {
                        Player =
                            new Player
                            {
                                Username = "******",
                                Email = "*****@*****.**",
                                Password = PasswordHelper.HashPassword("mayur"),
                                Groups = new List<Group> { boardgame, gameideas, rage }
                            }
                    },
                    new Session
                    {
                        Player =
                            new Player
                            {
                                Username = "******",
                                Email = "*****@*****.**",
                                Password = PasswordHelper.HashPassword("jack"),
                                Groups = new List<Group> { gameideas, rage }
                            }
                    },
                    new Session
                    {
                        Player =
                            new Player
                            {
                                Username = "******",
                                Email = "*****@*****.**",
                                Password = PasswordHelper.HashPassword("matt"),
                                Groups = new List<Group> { boardgame, rage }
                            }
                    },
                    new Session
                    {
                        Player =
                            new Player
                            {
                                Username = "******",
                                Password = PasswordHelper.HashPassword("ben"),
                                Groups = new List<Group> { boardgame, gameideas }
                            }
                    },
                    new Session
                    {
                        Player =
                            new Player
                            {
                                Username = "******",
                                Password = PasswordHelper.HashPassword("kam"),
                                Groups = new List<Group> { gameideas }
                            }
                    }
                };

                _context.Sessions.AddRange(sessions);

                await SaveChanges(_context, isAsync);

                Debug.WriteLine("Players & Sessions Seeded.");
            }
        }
コード例 #33
0
        protected static async Task SeedGroups(SocialGamificationAssetContext _context, bool isAsync = false)
        {
            if (!_context.Alliances.Any())
            {
                IList<Group> groups = new List<Group>
                {
                    new Group { Username = "******" },
                    new Group { Username = "******" },
                    new Group { Username = "******" }
                };

                _context.Groups.AddRange(groups);

                await SaveChanges(_context, isAsync);

                Debug.WriteLine("Groups Seeded.");
            }
        }
コード例 #34
0
 /// <summary>
 ///     <see cref="Player" /> API
 /// </summary>
 /// <param name="context"></param>
 public PlayersController(SocialGamificationAssetContext context)
     : base(context)
 {
 }
コード例 #35
0
 public async Task <bool> IsOnline(SocialGamificationAssetContext db)
 {
     return(await IsOnline(db, Id));
 }
コード例 #36
0
        protected static async Task SeedGoals(SocialGamificationAssetContext _context, bool isAsync = false)
        {
            if (!_context.ActorGoal.Any())
            {
                var mayur = await _context.Players.Where(a => a.Username.Equals("mayur")).FirstOrDefaultAsync();

                var goal = new Goal
                {
                    Concern = new ConcernMatrix {
                        Coordinates = new Matrix {
                            X = 0, Y = 0
                        }, Category = 0
                    },
                    RewardResource =
                        new RewardResourceMatrix {
                        Coordinates = new Matrix {
                            X = 0, Y = 0
                        }, Category = 0
                    },
                    Feedback = new GoalFeedback {
                        Threshold = 0, Target = 0, Direction = 0
                    },
                    Description = "Test"
                };
                var attributeType = new AttributeType {
                    Name = "testAttribute", DefaultValue = 0f, Type = 0
                };

                var activity = new Activity {
                    Name = "Testing"
                };

                IList <ActorGoal> goals = new List <ActorGoal>
                {
                    new ActorGoal
                    {
                        Actor          = mayur,
                        Goal           = goal,
                        Status         = 0,
                        ConcernOutcome = new ConcernMatrix {
                            Coordinates = new Matrix {
                                X = 0, Y = 0
                            }, Category = 0
                        },
                        RewardResourceOutcome =
                            new RewardResourceMatrix {
                            Coordinates = new Matrix {
                                X = 0, Y = 0
                            }, Category = 0
                        },
                        Activity = activity,
                        Role     = new Role {
                            Name = "Testing", Goal = goal, Activity = activity
                        }
                    }
                };

                _context.ActorGoal.AddRange(goals);

                IList <Reward> rewards = new List <Reward>
                {
                    new Reward
                    {
                        AttributeType = attributeType,
                        TypeReward    = RewardType.Store,
                        Value         = 1.5f,
                        Status        = 0,
                        Goal          = goal
                    },
                    new Reward
                    {
                        AttributeType  = attributeType,
                        Value          = 3.5f,
                        Status         = 0,
                        Goal           = goal,
                        TypeReward     = RewardType.Modify,
                        ActionRelation =
                            new ActionRelation
                        {
                            Action = new Action {
                                Verb = "testVerb", Activity = activity, Goal = goal
                            },
                            Relationship  = 0,
                            ConcernChange = new Matrix {
                                X = 0, Y = 0
                            },
                            RewardResourceChange = new Matrix {
                                X = 0, Y = 0
                            }
                        }
                    }
                };

                _context.Rewards.AddRange(rewards);

                await SaveChanges(_context, isAsync);

                Debug.WriteLine("Goals & related Seeded.");
            }
        }
コード例 #37
0
        /**
         * Verify if this account is online (with Last session being marked active)
         *
         * @return bool Returns TRUE if the account is online
         */

        public static async Task <bool> IsOnline(SocialGamificationAssetContext db, Guid playerId)
        {
            var session = await GetSession(db, playerId);

            return(session != null);
        }
コード例 #38
0
ファイル: Group.cs プロジェクト: playgenhub/rage-sga-server
 public async Task<ContentResult> AddOrUpdateCustomData(
     SocialGamificationAssetContext db,
     IList<CustomDataBase> sourceData)
 {
     return await Models.CustomData.AddOrUpdate(db, sourceData, Id, CustomDataType.Group);
 }
コード例 #39
0
        protected static async Task SeedGoals(SocialGamificationAssetContext _context, bool isAsync = false)
        {
            if (!_context.ActorGoal.Any())
            {
                var mayur = await _context.Players.Where(a => a.Username.Equals("mayur")).FirstOrDefaultAsync();
                var goal = new Goal
                {
                    Concern = new ConcernMatrix { Coordinates = new Matrix { X = 0, Y = 0 }, Category = 0 },
                    RewardResource =
                        new RewardResourceMatrix { Coordinates = new Matrix { X = 0, Y = 0 }, Category = 0 },
                    Feedback = new GoalFeedback { Threshold = 0, Target = 0, Direction = 0 },
                    Description = "Test"
                };
                var attributeType = new AttributeType { Name = "testAttribute", DefaultValue = 0f, Type = 0 };

                var activity = new Activity { Name = "Testing" };

                IList<ActorGoal> goals = new List<ActorGoal>
                {
                    new ActorGoal
                    {
                        Actor = mayur,
                        Goal = goal,
                        Status = 0,
                        ConcernOutcome = new ConcernMatrix { Coordinates = new Matrix { X = 0, Y = 0 }, Category = 0 },
                        RewardResourceOutcome =
                            new RewardResourceMatrix { Coordinates = new Matrix { X = 0, Y = 0 }, Category = 0 },
                        Activity = activity,
                        Role = new Role { Name = "Testing", Goal = goal, Activity = activity }
                    }
                };

                _context.ActorGoal.AddRange(goals);

                IList<Reward> rewards = new List<Reward>
                {
                    new Reward
                    {
                        AttributeType = attributeType,
                        TypeReward = RewardType.Store,
                        Value = 1.5f,
                        Status = 0,
                        Goal = goal
                    },
                    new Reward
                    {
                        AttributeType = attributeType,
                        Value = 3.5f,
                        Status = 0,
                        Goal = goal,
                        TypeReward = RewardType.Modify,
                        ActionRelation =
                            new ActionRelation
                            {
                                Action = new Action { Verb = "testVerb", Activity = activity, Goal = goal },
                                Relationship = 0,
                                ConcernChange = new Matrix { X = 0, Y = 0 },
                                RewardResourceChange = new Matrix { X = 0, Y = 0 }
                            }
                    }
                };

                _context.Rewards.AddRange(rewards);

                await SaveChanges(_context, isAsync);
                Debug.WriteLine("Goals & related Seeded.");
            }
        }
コード例 #40
0
ファイル: Alliance.cs プロジェクト: ahirmayur/rage-sga-server
        public static IList <Guid> GetAllianceIds(SocialGamificationAssetContext db, Guid actorId, AllianceState state)
        {
            IList <Alliance> alliances = db.Alliances.Where(IsAlliance(actorId)).Where(f => f.State == state).ToList();

            return(AlliancesList(alliances, actorId));
        }
コード例 #41
0
ファイル: Group.cs プロジェクト: playgenhub/rage-sga-server
        /**
		 * Check if the current Username already exists
         *
         * @return boolean Returns TRUE if Username exists
         */

        public static async Task<bool> ExistsUsername(SocialGamificationAssetContext db, string username)
        {
            var group = await db.Groups.Where(g => g.Username.Equals(username)).FirstOrDefaultAsync();

            return group != null;
        }
コード例 #42
0
ファイル: Actor.cs プロジェクト: ahirmayur/rage-sga-server
 public IQueryable <Actor> Alliances(SocialGamificationAssetContext db)
 {
     return(Alliances(db, Id));
 }
コード例 #43
0
        protected static async Task SeedCustomData(SocialGamificationAssetContext _context, bool isAsync = false)
        {
            if (!_context.CustomData.Any())
            {
                var mayur = await _context.Players.Where(a => a.Username.Equals("mayur")).FirstOrDefaultAsync();

                var matt = await _context.Players.Where(a => a.Username.Equals("matt")).FirstOrDefaultAsync();

                var jack = await _context.Players.Where(a => a.Username.Equals("jack")).FirstOrDefaultAsync();

                var kam = await _context.Players.Where(a => a.Username.Equals("kam")).FirstOrDefaultAsync();

                var ben = await _context.Players.Where(a => a.Username.Equals("ben")).FirstOrDefaultAsync();

                IList <CustomData> customData = new List <CustomData>
                {
                    new CustomData
                    {
                        Key        = "ip",
                        Value      = "127.0.0.1",
                        ObjectId   = mayur.Id,
                        ObjectType = CustomDataType.Player
                    },
                    new CustomData
                    {
                        Key        = "ip",
                        Value      = "127.0.0.1",
                        ObjectId   = matt.Id,
                        ObjectType = CustomDataType.Player
                    },
                    new CustomData
                    {
                        Key        = "ip",
                        Value      = "127.0.0.1",
                        ObjectId   = jack.Id,
                        ObjectType = CustomDataType.Player
                    },
                    new CustomData
                    {
                        Key        = "ip",
                        Value      = "127.0.0.1",
                        ObjectId   = ben.Id,
                        ObjectType = CustomDataType.Player
                    },
                    new CustomData
                    {
                        Key        = "video_id",
                        Value      = "1234",
                        ObjectId   = mayur.Id,
                        ObjectType = CustomDataType.Player
                    },
                    new CustomData
                    {
                        Key        = "video_id",
                        Value      = "1234",
                        ObjectId   = matt.Id,
                        ObjectType = CustomDataType.Player
                    },
                    new CustomData
                    {
                        Key        = "video_id",
                        Value      = "1234",
                        ObjectId   = jack.Id,
                        ObjectType = CustomDataType.Player
                    },
                    new CustomData
                    {
                        Key        = "chat_id",
                        Value      = "235f73ea-e54f-4150-8dc3-3eb9995d0728",
                        ObjectId   = mayur.Id,
                        ObjectType = CustomDataType.Player
                    },
                    new CustomData
                    {
                        Key        = "chat_id",
                        Value      = "235f73ea-e54f-4150-8dc3-3eb9995d0728",
                        ObjectId   = matt.Id,
                        ObjectType = CustomDataType.Player
                    }
                };

                _context.CustomData.AddRange(customData);

                await SaveChanges(_context, isAsync);

                Debug.WriteLine("CustomData Seeded.");
            }
        }
コード例 #44
0
        protected static async Task SeedGames(SocialGamificationAssetContext _context, bool isAsync = false)
        {
            if (!_context.GameRegistry.Any())
            {
                IList<GameRegistry> games = new List<GameRegistry>
                {
                    new GameRegistry { Name = "ButtonGame", DeveloperName = "PlayGen" },
                    new GameRegistry { Name = "TankGame", DeveloperName = "PlayGen" }
                };

                _context.GameRegistry.AddRange(games);

                await SaveChanges(_context, isAsync);

                Debug.WriteLine("Games Seeded.");

                // GameRegistry Game = await _context.GameRegistry.Where(g => g.Username.Equals("ButtonGame")).FirstOrDefaultAsync();
            }
        }
コード例 #45
0
 public SessionsController(SocialGamificationAssetContext context)
     : base(context)
 {
 }
コード例 #46
0
 public TournamentsController(SocialGamificationAssetContext context)
     : base(context)
 {
 }
コード例 #47
0
ファイル: Group.cs プロジェクト: ahirmayur/rage-sga-server
        /**
         * Check if the current Username already exists
         *
         * @return boolean Returns TRUE if Username exists
         */

        public static async Task <bool> ExistsUsername(SocialGamificationAssetContext db, string username)
        {
            var group = await db.Groups.Where(g => g.Username.Equals(username)).FirstOrDefaultAsync();

            return(group != null);
        }
コード例 #48
0
 public AlliancesController(SocialGamificationAssetContext context)
     : base(context)
 {
 }
コード例 #49
0
        protected static async Task SeedPlayerSessions(SocialGamificationAssetContext _context, bool isAsync = false)
        {
            if (!_context.Sessions.Any())
            {
                var boardgame = await _context.Groups.Where(a => a.Username.Equals("boardgame")).FirstOrDefaultAsync();

                var gameideas = await _context.Groups.Where(a => a.Username.Equals("gameideas")).FirstOrDefaultAsync();

                var rage = await _context.Groups.Where(a => a.Username.Equals("rage")).FirstOrDefaultAsync();

                IList <Session> sessions = new List <Session>
                {
                    new Session
                    {
                        Player =
                            new Player
                        {
                            Username = "******",
                            Password = PasswordHelper.HashPassword("admin"),
                            Role     = AccountType.Admin
                        }
                    },
                    new Session
                    {
                        Player =
                            new Player
                        {
                            Username = "******",
                            Password = PasswordHelper.HashPassword("playgen"),
                            Role     = AccountType.Admin
                        }
                    },
                    new Session
                    {
                        Player =
                            new Player
                        {
                            Username = "******",
                            Email    = "*****@*****.**",
                            Password = PasswordHelper.HashPassword("mayur"),
                            Groups   = new List <Group> {
                                boardgame, gameideas, rage
                            }
                        }
                    },
                    new Session
                    {
                        Player =
                            new Player
                        {
                            Username = "******",
                            Email    = "*****@*****.**",
                            Password = PasswordHelper.HashPassword("jack"),
                            Groups   = new List <Group> {
                                gameideas, rage
                            }
                        }
                    },
                    new Session
                    {
                        Player =
                            new Player
                        {
                            Username = "******",
                            Email    = "*****@*****.**",
                            Password = PasswordHelper.HashPassword("matt"),
                            Groups   = new List <Group> {
                                boardgame, rage
                            }
                        }
                    },
                    new Session
                    {
                        Player =
                            new Player
                        {
                            Username = "******",
                            Password = PasswordHelper.HashPassword("ben"),
                            Groups   = new List <Group> {
                                boardgame, gameideas
                            }
                        }
                    },
                    new Session
                    {
                        Player =
                            new Player
                        {
                            Username = "******",
                            Password = PasswordHelper.HashPassword("kam"),
                            Groups   = new List <Group> {
                                gameideas
                            }
                        }
                    }
                };

                _context.Sessions.AddRange(sessions);

                await SaveChanges(_context, isAsync);

                Debug.WriteLine("Players & Sessions Seeded.");
            }
        }
コード例 #50
0
 public AttributesController(SocialGamificationAssetContext context)
     : base(context)
 {
 }
コード例 #51
0
 public ActivitiesController(SocialGamificationAssetContext context)
     : base(context)
 {
 }
コード例 #52
0
ファイル: Actor.cs プロジェクト: playgenhub/rage-sga-server
 public IQueryable<Actor> Alliances(SocialGamificationAssetContext db)
 {
     return Alliances(db, Id);
 }
コード例 #53
0
        public static IQueryable<CustomData> ConditionBuilder(
            SocialGamificationAssetContext db,
            IList<CustomDataBase> sourceData,
            CustomDataType objectType)
        {
            var query = db.CustomData.Where(c => c.ObjectType == objectType);

            if (sourceData == null || sourceData.Count <= 0)
            {
                return null;
            }

            foreach (var data in sourceData)
            {
                query = query.Where(c => c.Key.Equals(data.Key));

                if (!AllowedOperators.Contains(data.Operator))
                {
                    continue;
                }

                switch (data.Operator)
                {
                    case "=":
                        query = query.Where(c => c.Value.Equals(data.Value));
                        break;
                    case "!":
                        query = query.Where(c => c.Value != data.Value);
                        break;
                    case "%":
                        query = query.Where(c => c.Value.Contains(data.Value));
                        break;
                }
            }

            return query;
        }
コード例 #54
0
ファイル: Actor.cs プロジェクト: playgenhub/rage-sga-server
        public static IQueryable<Actor> Alliances(SocialGamificationAssetContext db, Guid id, AllianceState state)
        {
            var alliancesList = Alliance.GetAllianceIds(db, id, state);

            return db.Actors.Where(a => alliancesList.Contains(a.Id));
        }
コード例 #55
0
ファイル: Actor.cs プロジェクト: ahirmayur/rage-sga-server
        public static IQueryable <Actor> Alliances(SocialGamificationAssetContext db, Guid id, AllianceState state)
        {
            var alliancesList = Alliance.GetAllianceIds(db, id, state);

            return(db.Actors.Where(a => alliancesList.Contains(a.Id)));
        }
コード例 #56
0
ファイル: Actor.cs プロジェクト: playgenhub/rage-sga-server
 public IQueryable<Actor> Alliances(SocialGamificationAssetContext db, AllianceState state)
 {
     return Alliances(db, Id, state);
 }
コード例 #57
0
 protected static async Task SaveChanges(SocialGamificationAssetContext _context, bool isAsync = false)
 {
     try
     {
         if (isAsync)
         {
             await _context.SaveChangesAsync();
         }
         else
         {
             _context.SaveChanges();
         }
     }
     catch (DbUpdateException e)
     {
         throw e;
     }
 }
コード例 #58
0
        /**
         * Check if the current Email already exists
         *
         * @return boolean Returns TRUE if Username exists
         */

        public static async Task <bool> ExistsEmail(SocialGamificationAssetContext db, string email)
        {
            var player = await db.Players.Where(p => p.Email.Equals(email)).FirstOrDefaultAsync();

            return(player != null);
        }