示例#1
0
        protected ICollection <UserProfile> GetProfiles(Guid?profileId, string name)
        {
            ISQLDatabase database    = ServiceRegistration.Get <ISQLDatabase>();
            ITransaction transaction = database.BeginTransaction();

            try
            {
                int profileIdIndex;
                int nameIndex;
                using (IDbCommand command = UserProfileDataManagement_SubSchema.SelectUserProfilesCommand(transaction, profileId, name,
                                                                                                          out profileIdIndex, out nameIndex))
                {
                    ICollection <UserProfile> result = new List <UserProfile>();
                    using (IDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Guid   profileId_ = database.ReadDBValue <Guid>(reader, profileIdIndex);
                            string name_      = database.ReadDBValue <string>(reader, nameIndex);
                            result.Add(new UserProfile(profileId_, name_));
                        }
                    }
                    return(result);
                }
            }
            finally
            {
                transaction.Dispose();
            }
        }
        //TODO: DbCommand Async call?
        protected Task <ICollection <UserProfile> > GetProfiles(Guid?profileId, string name, bool loadData = true)
        {
            ISQLDatabase database    = ServiceRegistration.Get <ISQLDatabase>();
            ITransaction transaction = database.BeginTransaction();

            try
            {
                int profileIdIndex;
                int nameIndex;
                int idIndex;
                int dataIndex;
                int lastLoginIndex;
                int imageIndex;
                ICollection <UserProfile> result = new List <UserProfile>();
                using (IDbCommand command = UserProfileDataManagement_SubSchema.SelectUserProfilesCommand(transaction, profileId, name,
                                                                                                          out profileIdIndex, out nameIndex, out idIndex, out dataIndex, out lastLoginIndex, out imageIndex))
                {
                    using (IDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            result.Add(new UserProfile(
                                           database.ReadDBValue <Guid>(reader, profileIdIndex),
                                           database.ReadDBValue <string>(reader, nameIndex),
                                           (UserProfileType)database.ReadDBValue <int>(reader, idIndex),
                                           database.ReadDBValue <string>(reader, dataIndex),
                                           database.ReadDBValue <DateTime?>(reader, lastLoginIndex),
                                           database.ReadDBValue <byte[]>(reader, imageIndex))
                                       );
                        }
                    }
                }

                if (loadData)
                {
                    foreach (var user in result)
                    {
                        using (IDbCommand command = UserProfileDataManagement_SubSchema.SelectUserAdditionalDataListCommand(transaction, user.ProfileId, null, false, SortDirection.Ascending,
                                                                                                                            out nameIndex, out profileIdIndex, out dataIndex))
                        {
                            using (IDataReader reader = command.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    string key = database.ReadDBValue <string>(reader, nameIndex);
                                    if (!user.AdditionalData.ContainsKey(key))
                                    {
                                        user.AdditionalData.Add(key, new Dictionary <int, string>());
                                    }
                                    user.AdditionalData[key].Add(database.ReadDBValue <int>(reader, profileIdIndex), database.ReadDBValue <string>(reader, dataIndex));
                                }
                            }
                        }
                    }
                }

                return(Task.FromResult(result));
            }
            finally
            {
                transaction.Dispose();
            }
        }