示例#1
0
        public void SaveStatusOnly(InstanceInfo[] newInfo)
        {
            MsSqlMonitorEntities context = new MsSqlMonitorEntities();

            MapBaseInstanceDataToContext(newInfo, context);
            context.SaveChanges();
        }
示例#2
0
        private void MapWholeInstanceDataToContext(MsSqlMonitorEntities context, InstanceInfo[] newInfo)
        {
            context.Configuration.AutoDetectChangesEnabled = false;
            // Link InstanceInfo to instance, information for which it contains.
            var linkedInstanceInfo = LinkInstancesByAssociatedId(newInfo, context);

            // Get rid of offline instances.
            linkedInstanceInfo = MarkAndRemoveOfflineInstances(linkedInstanceInfo);
            // Update instance information
            SetNewInstanceInfo(linkedInstanceInfo);
            // Clear instance before adding new information.
            ClearInstances(linkedInstanceInfo, context);
            // Add to instances logins and roles.
            AddPrincipalsToInstance(linkedInstanceInfo);
            // Add to instances databases with their users and roles.
            AddDatabasesAndTheirPrincipals(linkedInstanceInfo);
            // Set permissions for instance principals.
            SetInstancePrincipalsPermissions(linkedInstanceInfo, context);
            // Set permissions for database principals.
            SetDatabasePrinciaplsPermissions(linkedInstanceInfo, context);
            // Map principals (users to roles)
            MapPrincipals(linkedInstanceInfo);

            context.ChangeTracker.DetectChanges();
            context.SaveChanges();
        }
示例#3
0
 public void SaveInstances(InstanceInfo[] newInfo)
 {
     using (MsSqlMonitorEntities context = new MsSqlMonitorEntities())
     {
         MapWholeInstanceDataToContext(context, newInfo);
         context.SaveChanges();
     }
 }
示例#4
0
 public void SaveStatusOnly(InstanceInfo[] newInfo, ISLogger logger)
 {
     try
     {
         MsSqlMonitorEntities context = new MsSqlMonitorEntities();
         MapBaseInstanceDataToContext(newInfo, context);
         context.SaveChanges();
     }catch (Exception e)
     {
         logger.Error("LocalDb.SaveSatusOnly " + e.Message);
         logger.Error(e.StackTrace);
     }
 }
示例#5
0
        private void CreateJobTypeInDataBase(JobType.UpdateInfoType type, int repeatTime)
        {
            JobType jobType = new JobType();

            jobType.Type             = type;
            jobType.MaxMutualWrites  = Environment.ProcessorCount;
            jobType.MaxParallelReads = Environment.ProcessorCount;
            jobType.RepeatTimeSec    = repeatTime;

            // DALLib.EF.MsSqlMonitorEntities dbContext = new DALLib.EF.MsSqlMonitorEntities();
            context.JobTypes.Add(jobType);
            context.SaveChanges();
        }
示例#6
0
 public void SaveInstances(InstanceInfo[] newInfo, ISLogger logger)
 {
     try
     {
         using (MsSqlMonitorEntities context = new MsSqlMonitorEntities())
         {
             MapWholeInstanceDataToContext(context, newInfo);
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         logger.Error("LocalDb.SaveSatusOnly " + e.Message);
         logger.Error(e.StackTrace);
     }
 }
示例#7
0
        static void  addDataForTesting()
        {
            List <BrowsableInstance> list = CommonLib.BrowsableInstance.GetInstances();
            MsSqlMonitorEntities     db   = new MsSqlMonitorEntities();

            //db.SaveChanges();

            /*
             * User user;
             * if (db.Users.LongCount<User>() == 0)
             * {
             *  user = new User();
             *  user.Login = "******";
             *  user.Password = "******";
             *  user.Role = UserRole.Admin;
             *  db.Users.Add(user);
             *  db.SaveChanges();
             *
             *  user = new User();
             *  user.Login = "******";
             *  user.Password = "******";
             *  user.Role = UserRole.User;
             *  db.Users.Add(user);
             *  db.SaveChanges();
             *
             *
             * } else
             * {
             *  user = db.Users.First<User>();
             * }
             */

            foreach (var browsableInstance in list)
            {
                if (db.Instances.Where <Instance>(x => x.InstanceName.Equals(browsableInstance.InstanceName)).LongCount() != 0)
                {
                    continue;
                }

                Instance newInst = new Instance();
                newInst.Authentication = AuthenticationType.Sql;
                newInst.InstanceName   = browsableInstance.InstanceName;
                newInst.ServerName     = browsableInstance.ServerName;
                newInst.Login          = "******";
                newInst.Password       = "******";
                newInst.IsDeleted      = false;

                db.Instances.Add(newInst);
                //  db.
                ///////////////////////////////////////////////////

                /*
                 * Assign assign = new Assign();
                 * assign.User = user;
                 * assign.UserId = user.Id;
                 * assign.Instance = newInst;
                 * assign.InstanceId = newInst.Id;
                 *
                 * db.Assigns.Add(assign);
                 */

                db.SaveChanges();
                //////////////////////////////////////////////

                /*
                 * InstanceUpdateJob updateJob = new InstanceUpdateJob();
                 * updateJob.Instance = newInst;
                 * updateJob.InstanceId = newInst.Id;
                 *
                 * JobType  jobType = db.JobTypes.Where<JobType>(i => i.Type == JobType.UpdateInfoType.Full).First<JobType>();
                 *
                 * updateJob.JobType = jobType;
                 * updateJob.JobTypeId = jobType.Type;
                 *
                 *
                 * db.InstanceUpdateJobs.Add(updateJob);
                 *
                 *
                 * db.SaveChanges();
                 *
                 * //////////////////////////////////////////////
                 *
                 * InstanceUpdateJob updateJob2 = new InstanceUpdateJob();
                 * updateJob2.Instance = newInst;
                 * updateJob2.InstanceId = newInst.Id;
                 *
                 * JobType jobType2 = db.JobTypes.Where<JobType>(i => i.Type == JobType.UpdateInfoType.CheckStatus).First<JobType>();
                 *
                 * updateJob2.JobType = jobType2;
                 * updateJob2.JobTypeId = jobType.Type;
                 *
                 *
                 * db.InstanceUpdateJobs.Add(updateJob2);
                 *
                 */

                db.SaveChanges();


                //////////////////////////////////////////////
            }
            // db.SaveChanges();



            //  db.SaveChanges();
        }
示例#8
0
 public int Save()
 {
     return(context.SaveChanges());
 }