Ejemplo n.º 1
0
 public IActionResult Get(int tasks)
 {
     for (int i = 0; i < tasks; i++)
     {
         Task.Run(() =>
         {
             var rng = ScavengePadUtils.GetRandomInt();
         });
     }
     return(Json(new
     {
         rng = ScavengePadUtils.GetRandomInt()
     }));
 }
Ejemplo n.º 2
0
        internal static async Task <Operation> ModifyOperation(WebSocketClient client, Operation modifiedOperation)
        {
            Operation dbOperation;
            bool      newOp = false;

            using (var ctx = new ScavengePadDbContext())
            {
                dbOperation = await ctx.Operations
                              .Where(c => c.Id == modifiedOperation.Id)
                              .Where(c => c.TeamId == client.User.TeamId)
                              .AsNoTracking()
                              .FirstOrDefaultAsync();

                if (dbOperation == null)
                {
                    dbOperation = new Operation()
                    {
                        TeamId     = client.User.TeamId,
                        Title      = modifiedOperation.Title,
                        Objectives = modifiedOperation.Objectives
                    };
                    ctx.Operations.Add(dbOperation);
                    newOp = true;
                }
                else
                {
                    ctx.Operations.Update(modifiedOperation);
                    dbOperation = modifiedOperation;
                }
                await ctx.SaveChangesAsync();

                if (newOp)
                {
                    dbOperation.OperationPadSuffix = WebUtility.UrlEncode(ScavengePadUtils.SHA256($"{dbOperation.Id}{ScavengePadUtils.GetRandomInt()}{ScavengePadUtils.GetRandomInt()}{ScavengePadUtils.GetRandomInt()}{ScavengePadUtils.GetRandomInt()}"));
                }
                foreach (var objective in dbOperation.Objectives)
                {
                    if (objective.ObjectivePadSuffix == "default")
                    {
                        objective.ObjectivePadSuffix = WebUtility.UrlEncode(ScavengePadUtils.SHA256($"{objective.Id}{ScavengePadUtils.GetRandomInt()}{ScavengePadUtils.GetRandomInt()}{ScavengePadUtils.GetRandomInt()}{ScavengePadUtils.GetRandomInt()}"));
                    }
                }
                await ctx.SaveChangesAsync();
            }
            return(await GetOperation(dbOperation.Id));
        }