public async Task <ActionResult <List <string> > > GetAsync()
        {
            var search = new EntityValueSearch()
            {
                KeyLike = Keys.VariableKey + "%",
            };

            search.EntityIds.Add(-GetRequesterUid());

            var baseValues = await provider.GetQueryableAsync <EntityValue>();

            var searchValues = provider.ApplyEntityValueSearch(baseValues, search);

            return(await provider.GetListAsync(searchValues.Select(x => x.key.Substring(Keys.VariableKey.Length))));
        }
 public async Task <List <long> > GetRevisionIdsAsync(long packageId)
 {
     return(await provider.GetListAsync(
                from r in await provider.GetQueryableAsync <EntityRelation>()
                where r.entityId1 == packageId && r.type == Keys.HistoryRelation
                select r.entityId2));
 }
Esempio n. 3
0
        public async Task <List <SystemAggregate> > GetSystemAggregate(BaseSearch search)
        {
            var result = new List <SystemAggregate>();

            result.Add(new SystemAggregate()
            {
                id   = await provider.GetMaxAsync(await provider.GetQueryableAsync <EntityRelation>(), x => x.id),
                type = "actionMax"
            });
            result.Add(new SystemAggregate()
            {
                id   = await provider.GetMaxAsync(await provider.GetQueryableAsync <Entity>(), x => x.id),
                type = "contentMax"
            });
            result.Add(new SystemAggregate()
            {
                id   = await provider.GetMaxAsync(await provider.GetQueryableAsync <EntityValue>(), x => x.id),
                type = "valueMax"
            });
            return(result);
        }
Esempio n. 4
0
        public async Task <RelationListenResult> ListenAsync(RelationListenConfig listenConfig, Requester requester, CancellationToken token)
        {
            var result = new RelationListenResult()
            {
                lastId = listenConfig.lastId
            };

            var listenId = new RelationListener()
            {
                userId         = requester.userId,
                listenStatuses = listenConfig.statuses
            };

            var maxId = await provider.GetMaxAsync(await provider.GetQueryableAsync <EntityRelation>(), x => x.id);

            if (result.lastId <= 0)
            {
                result.lastId = maxId + result.lastId; //plus because negative
            }
            //This SERIOUSLY requires INTIMATE knowledge of how each of these systems works, like what entityId1 means etc.
            //That's bad.
            result.Relations = await provider.ListenAsync <EntityRelation>(listenId, (q) =>
                                                                           q.Where(x =>
                                                                                   (x.type == Keys.CommentHack ||
                                                                                    x.type == Keys.ModuleHack ||
                                                                                    x.type == Keys.WatchRelation && x.entityId1 == listenId.userId ||
                                                                                    (x.type == Keys.WatchUpdate ||
                                                                                     x.type == Keys.WatchDelete) && x.value.StartsWith($"{listenId.userId}_") ||
                                                                                    x.type.StartsWith(Keys.ActivityKey) ||
                                                                                    x.type.StartsWith(Keys.ModuleMessageKey) && (x.entityId2 == 0 || x.entityId2 == -listenId.userId) ||
                                                                                    x.type.StartsWith(Keys.CommentDeleteHack) ||
                                                                                    x.type.StartsWith(Keys.CommentHistoryHack)) &&
                                                                                   x.id > result.lastId &&
                                                                                   x.id < result.lastId + config.MaxLookahead),
                                                                           systemConfig.ListenTimeout, token);

            //If the read exited with NOTHING, there's nothing in our range. Need to record that
            //so we don't check that range again. This will ALMOST NEVER EVER happen, but it's good to handle the situation.
            //Yes, the listener will have to wait for the full timeout value to get anything, but... well it should be ok.
            if (result.Relations == null || result.Relations.Count == 0)
            {
                result.lastId += config.MaxLookahead;
            }
            else
            {
                result.lastId = result.Relations.Max(x => x.id);
            }

            return(result);
        }
        /// <summary>
        /// Search for entities, return them packaged
        /// </summary>
        /// <param name="provider"></param>
        /// <param name="search"></param>
        /// <returns></returns>
        public static async Task <List <EntityPackage> > GetEntityPackagesAsync(this IEntityProvider provider, EntitySearch search)
        {
            var entities = await provider.GetQueryableAsync <Entity>();

            return(await LinkAsync(provider, provider.ApplyEntitySearch(entities, search)));
        }
        public async Task <string> ConvertUsersAsync([FromQuery] string secret)
        {
            if (secret != config.SecretKey)
            {
                throw new InvalidOperationException("Need the secret");
            }

            newdb.Open();
            using (var trs = newdb.BeginTransaction())
            {
                try
                {
                    Log("Starting user convert");
                    var users = await userSource.SimpleSearchAsync(new UserSearch());

                    Log($"{users.Count} users found");
                    foreach (var user in users)
                    {
                        var newUser = mapper.Map <Db.User_Convert>(user);
                        //User dapper to store?
                        var id = await newdb.InsertAsync(newUser);

                        Log($"Inserted user {newUser.username}({id})");
                    }
                    var count = newdb.ExecuteScalar <int>("SELECT COUNT(*) FROM users");
                    Log($"Successfully inserted users, {count} in table");

                    Log("Starting ban convert");
                    var bans = await banSource.SimpleSearchAsync(new BanSearch());

                    Log($"{bans.Count} bans found");
                    foreach (var ban in bans)
                    {
                        var newban = mapper.Map <Db.Ban>(ban);
                        //User dapper to store?
                        var id = await newdb.InsertAsync(newban);

                        Log($"Inserted ban for {newban.bannedUserId}({id})");
                    }
                    count = newdb.ExecuteScalar <int>("SELECT COUNT(*) FROM bans");
                    Log($"Successfully inserted bans, {count} in table");

                    Log("Starting user variable convert");
                    //var realKeys = keys.Select(x => Keys.VariableKey + x);

                    var evs = await entityProvider.GetQueryableAsync <EntityValue>();

                    var ens = await entityProvider.GetQueryableAsync <Entity>();

                    var query =
                        from v in evs
                        where EF.Functions.Like(v.key, $"{Keys.VariableKey}%")
                        //where EF.Functions.Like(v.key, Keys.VariableKey + key) && v.entityId == -uid
                        join e in ens on - v.entityId equals e.id
                        where EF.Functions.Like(e.type, $"{Keys.UserType}%")
                        select v;

                    var uvars = await query.ToListAsync();

                    Log($"{uvars.Count} user variables found");

                    foreach (var uvar in uvars)
                    {
                        var newvar = new UserVariable()
                        {
                            id         = uvar.id,
                            userId     = -uvar.entityId,
                            createDate = uvar.createDate ?? DateTime.Now,
                            editCount  = 0,
                            key        = uvar.key.Substring(Keys.VariableKey.Length),
                            value      = uvar.value
                        };
                        newvar.editDate = newvar.createDate;
                        var id = await newdb.InsertAsync(newvar);

                        Log($"Inserted uservariable {newvar.key} for {newvar.userId}({id})");
                    }

                    count = newdb.ExecuteScalar <int>("SELECT COUNT(*) FROM user_variables");
                    Log($"Successfully inserted user variables, {count} in table");
                    trs.Commit();
                }
                catch (Exception ex)
                {
                    Log($"EXCEPTION: {ex}");
                    trs.Rollback();
                }
            }

            return(DumpLog());
        }