Exemple #1
0
        public async void RemoveInstanceForeverAsync(CollectionResult result, ISLogger logger)
        {
            logger.Debug("Removing forever instance id=" + result.InstanceID);

            try
            {
                MsSqlMonitorEntities context  = new MsSqlMonitorEntities();
                Instance             instance = context.Instances.Find(result.InstanceID);

                instance.Assigns.ToList().ForEach(i => context.Assigns.Remove(i));


                instance.Roles.ToList().ForEach(r => { r.RefuseAllLogins(); context.Entry(r).State = EntityState.Deleted; });
                // Delete all users before update.
                instance.Logins.ToList().ForEach(l => context.Entry(l).State = EntityState.Deleted);
                // Delete all roles from databases
                instance.Databases.ToList().ForEach(db => db.Roles.ToList().ForEach(role => { role.RefuseAllUsers(); context.Entry(role).State = EntityState.Deleted; }));
                instance.Databases.ToList().ForEach(db => db.Users.ToList().ForEach(user => { user.RefuseAllRoles(); context.Entry(user).State = EntityState.Deleted; }));
                // Delete all databases
                instance.Databases.ToList().ForEach(db => context.Entry(db).State = EntityState.Deleted);


                context.Entry(instance).State = EntityState.Deleted;

                await context.SaveChangesAsync().ConfigureAwait(false);
            }
            catch (Exception e)
            {
                logger.Error(e.StackTrace);
            }
        }
 private void ClearInstances(List <Tuple <Instance, InstanceInfo> > linkedInfo, MsSqlMonitorEntities context)
 {
     // Delete all roles before update.
     linkedInfo.ForEach(li => li.Item1.Roles.ToList().ForEach(r => { r.RefuseAllLogins(); context.Entry(r).State = EntityState.Deleted; }));
     // Delete all users before update.
     linkedInfo.ForEach(li => li.Item1.Logins.ToList().ForEach(l => context.Entry(l).State = EntityState.Deleted));
     // Delete all roles from databases
     linkedInfo.ForEach(li => li.Item1.Databases.ToList().ForEach(db => db.Roles.ToList().ForEach(role => { role.RefuseAllUsers(); context.Entry(role).State = EntityState.Deleted; })));
     linkedInfo.ForEach(li => li.Item1.Databases.ToList().ForEach(db => db.Users.ToList().ForEach(user => { user.RefuseAllRoles(); context.Entry(user).State = EntityState.Deleted; })));
     // Delete all databases
     linkedInfo.ForEach(li => li.Item1.Databases.ToList().ForEach(db => context.Entry(db).State = EntityState.Deleted));
 }
        public async Task RevokeInstanceAccess(int instanceId, int userId)
        {
            using (MsSqlMonitorEntities context = new MsSqlMonitorEntities())
            {
                Assign assign = await context.Assigns.FirstOrDefaultAsync(a => a.InstanceId == instanceId && a.UserId == userId);

                if (assign == null)
                {
                    throw new EntityNotExistException($"Assignment of user '{userId}' to instance '{instanceId}' doesn't exist");
                }
                context.Entry(assign).State = EntityState.Deleted;
                await context.SaveChangesAsync();
            }
        }
Exemple #4
0
 public virtual T Update(T item)
 {
     context.Entry(item).State = EntityState.Modified;
     return(item);
 }