Exemplo n.º 1
0
 public YbpEngine(
     IServiceProvider services,
     IYbpContextStorage ctxStorage,
     YbpUserContext userContext
     )
 {
     _services    = services;
     _ctxStorage  = ctxStorage;
     _userContext = userContext;
 }
Exemplo n.º 2
0
        public void Save <TProcess>(YbpContext <TProcess> ctx, YbpUserContext userContext)
            where TProcess : YbpProcessBase, new()
        {
            var dflags = _db
                         .YbpFlags
                         .Where(x => x.ProcessId == ctx.StoredId)
                         .ToArray();

            foreach (var f in ctx.Flags)
            {
                var df = dflags.FirstOrDefault(x => x.Key == f.Key);
                if (df == null)
                {
                    df = new YbpFlag
                    {
                        ProcessId  = ctx.StoredId,
                        Key        = f.Key,
                        IsSet      = f.Value,
                        UpdatedUTC = DateTime.UtcNow,
                        UserId     = (int)userContext["UserId"]
                    };

                    _db.YbpFlags.Add(df);

                    var dfh = new YbpFlagHistory
                    {
                        Flag       = df,
                        IsSet      = df.IsSet,
                        UpdatedUTC = df.UpdatedUTC,
                        UserId     = df.UserId
                    };

                    _db.YbpFlagHistory.Add(dfh);
                }
                else if (df.IsSet != f.Value)
                {
                    df.IsSet      = f.Value;
                    df.UpdatedUTC = DateTime.UtcNow;
                    df.UserId     = (int)userContext["UserId"];

                    var dfh = new YbpFlagHistory
                    {
                        Flag       = df,
                        IsSet      = df.IsSet,
                        UpdatedUTC = df.UpdatedUTC,
                        UserId     = df.UserId
                    };

                    _db.YbpFlagHistory.Add(dfh);
                }
            }

            _db.SaveChanges();
        }
Exemplo n.º 3
0
 public virtual bool CanExecute(YbpUserContext user)
 {
     return(true);
 }