Пример #1
0
        public static ICollection <UserProfile> FetchAllProfiles(Boolean eager)
        {
            var before = Stopwatch.StartNew();

            if (ProfileCache.Count != 0)
            {
                return(ProfileCache.Values);
            }

            using (var session = SWDBHibernateDAO.CurrentSession()) {
                using (var transaction = session.BeginTransaction()) {
                    var query      = DAO.BuildQuery("from UserProfile", (object[])null, session);
                    var dbProfiles = query.List();
                    var profiles   = new Dictionary <string, UserProfile>();
                    foreach (var profile in dbProfiles)
                    {
                        var userProfile = (UserProfile)profile;
                        if (eager)
                        {
                            NHibernateUtil.Initialize(userProfile.Roles);
                            NHibernateUtil.Initialize(userProfile.DataConstraints);
                        }
                        profiles.Add(userProfile.Name, userProfile);
                        ProfileCache.Add(userProfile.Id, userProfile);
                    }
                    Log.Info(LoggingUtil.BaseDurationMessage("Profiles Loaded in {0}", before));
                    return(profiles.Values);
                }
            }
        }
Пример #2
0
 //TODO: remove customUserRoles and customUSerCOnstraints which were exclusions from this profile ==> They don´t make sense anymore (tough,they are useless anyway)
 public static void DeleteProfile(UserProfile profile)
 {
     using (ISession session = SWDBHibernateDAO.CurrentSession()) {
         using (ITransaction transaction = session.BeginTransaction()) {
             DAO.Delete(profile);
             if (ProfileCache.ContainsKey(profile.Id))
             {
                 ProfileCache.Remove(profile.Id);
             }
         }
     }
 }
Пример #3
0
 public static void DeleteRole(Role role)
 {
     using (ISession session = SWDBHibernateDAO.CurrentSession()) {
         using (ITransaction transaction = session.BeginTransaction()) {
             DAO.ExecuteSql("delete from sw_userprofile_role");
             DAO.ExecuteSql("delete from sw_user_customrole");
             DAO.Delete(role);
             Role oldRole = _activeRoles.FirstOrDefault(r => r.Id == role.Id);
             if (oldRole != null)
             {
                 _activeRoles.Remove(oldRole);
             }
         }
     }
 }
Пример #4
0
        public List <PersonGroup> UpdateCacheOnSync(IEnumerable <PersonGroup> personGroupsToIntegrate)
        {
            var toInsert = new List <PersonGroup>();
            var toUpdate = new List <PersonGroup>();

            foreach (var group in personGroupsToIntegrate)
            {
                if (!AllGroupsCached.ContainsKey(group.Name))
                {
                    AllGroupsCached.Add(group.Name, group);
                    toInsert.Add(group);
                }
                else if (AllGroupsCached[group.Name].Rowstamp != group.Rowstamp)
                {
                    group.Id = AllGroupsCached[group.Name].Id;
                    AllGroupsCached[group.Name] = group;
                    toUpdate.Add(group);
                }
            }

            _dao.BulkSave(toInsert);



            using (var session = SWDBHibernateDAO.CurrentSession()) {
                using (var transaction = session.BeginTransaction()) {
                    foreach (var personGrop in toUpdate)
                    {
                        var dbGroup = _dao.FindByPK <PersonGroup>(typeof(PersonGroup), personGrop.Id);
                        dbGroup.Description = personGrop.Description;
                        dbGroup.Rowstamp    = personGrop.Rowstamp;
                        _dao.Save(dbGroup);
                    }
                    transaction.Commit();
                }
            }

            toInsert.AddRange(toUpdate);
            return(toInsert);
        }