Exemplo n.º 1
0
        public Dictionary<string, long> LoadUserProfiles(List<string> usernames)
        {
            long userTypeId = ItemKey.GetTypeId(core, typeof(User));

            List<string> usernameList = new List<string>();
            Dictionary<string, long> userIds = new Dictionary<string, long>(8, StringComparer.Ordinal);
            foreach (string username in usernames)
            {
                PrimitiveKey key = new PrimitiveKey(username.ToLower(), userTypeId);
                if (!primitivesKeysCached.ContainsKey(key))
                {
                    usernameList.Add(username.ToLower());
                }
            }

            if (usernameList.Count > 0)
            {
                SelectQuery query = new SelectQuery("user_keys");
                query.AddFields(User.GetFieldsPrefixed(core, typeof(User)));
                query.AddFields(UserInfo.GetFieldsPrefixed(core, typeof(UserInfo)));
                query.AddFields(UserProfile.GetFieldsPrefixed(core, typeof(UserProfile)));
                query.AddJoin(JoinTypes.Inner, UserInfo.GetTable(typeof(UserInfo)), "user_id", "user_id");
                query.AddJoin(JoinTypes.Inner, UserProfile.GetTable(typeof(UserProfile)), "user_id", "user_id");
                query.AddJoin(JoinTypes.Left, new DataField("user_profile", "profile_country"), new DataField("countries", "country_iso"));
                query.AddJoin(JoinTypes.Left, new DataField("user_profile", "profile_religion"), new DataField("religions", "religion_id"));
                query.AddCondition(new DataField("user_keys", "user_name_lower"), ConditionEquality.In, usernameList);

                System.Data.Common.DbDataReader usersReader = db.ReaderQuery(query);

                while(usersReader.Read())
                {
                    User newUser = new User(core, usersReader, UserLoadOptions.All);
                    // This will automatically cache itself when loadUser is called

                    PrimitiveId pid = new PrimitiveId(newUser.Id, userTypeId);
                    PrimitiveKey kid = new PrimitiveKey(newUser.UserName.ToLower(), userTypeId);

                    if (!userIds.ContainsValue(newUser.Id))
                    {
                        userIds.Add(newUser.UserName, newUser.Id);
                    }
                }

                usersReader.Close();
                usersReader.Dispose();
            }

            return userIds;
        }
Exemplo n.º 2
0
        public void RegisterItem(Primitive item)
        {
            PrimitiveKey kid = new PrimitiveKey(item.Key.ToLower(), item.TypeId);

            if (!primitivesKeysCached.ContainsKey(kid))
            {
                primitivesKeysCached.Add(kid, new PrimitiveId(item.Id, item.TypeId));
            }
        }
Exemplo n.º 3
0
        public long LoadUserProfile(string username)
        {
            PrimitiveKey key = new PrimitiveKey(username, ItemKey.GetTypeId(core, typeof(User)));
            PrimitiveId pid = null;
            if (primitivesKeysCached.TryGetValue(key, out pid))
            {
                return pid.Id;
            }

            try
            {
                User newUser = new User(core, username, UserLoadOptions.All);
                // This will automatically cache itself when loadUser is called

                return newUser.Id;
            }
            catch (InvalidUserException)
            {
                return 0;
            }
        }