示例#1
0
        protected void Ok_Click(object sender, EventArgs e)
        {
            double sizefactor = double.Parse(SizeFactor.Text);
            string postfix = String.Empty;

            DatabaseVersion rs = new DatabaseVersion(RegistryContext);
            rs.Guid = new Guid(databaseVersionList.SelectedValue);
            rs.Load();

            int q = 0;
            for (int sli = 0; sli < slices.Count; sli++)
            {
                for (int ssi = 0; ssi < serverInstances.Count; ssi++)
                {
                    CheckBox cb = (CheckBox)FindControlRecursive(string.Format("cb_{0}_{1}", sli, ssi));
                    if (cb.Checked)
                    {
                        switch (item.LayoutType)
                        {
                            case DatabaseLayoutType.Sliced:
                                break;
                            default:
                                postfix = String.Format("{0}", q.ToString("00"));
                                break;
                        }

                        var dii = new DatabaseInstanceInstaller(item);

                        dii.GenerateDatabaseInstance(serverInstances[ssi], slices[sli], rs, NamePattern.Text.Replace("[$Number]", postfix), DatabaseNamePattern.Text.Replace("[$Number]", postfix), sizefactor, GenerateFileGroups.Checked);

                        q++;
                    }
                }
            }

            Response.Redirect(item.GetDetailsUrl(EntityGroup.Layout));
        }
        public UserDatabaseInstance GenerateUserDatabaseInstance(DatabaseVersion databaseVersion)
        {
            // TODO: this part probably needs some optimization

            // Load server instances that can store user databases
            var ef = new EntityFactory(Context);
            var sis = ef.FindAll<ServerInstance>()
                .Where(i => i.ServerVersionReference.Guid == databaseVersion.ServerVersionReference.Guid)
                .OrderBy(i => i.Machine.Number)
                .ToArray();

            if (sis.Length == 0)
            {
                throw new InvalidOperationException("At least one server instance has to configured for the database version.");    // TODO
            }

            // Get current number of user databases
            var dd = databaseVersion.DatabaseDefinition;
            dd.LoadDatabaseInstances(false);
            var dbnum = dd.DatabaseInstances.Count;

            // Find a server that is available
            int off = 0;
            int sin = 0;
            while (off < sis.Length)
            {
                sin = (dbnum + 1 + off) % sis.Length;
                bool ok = true;

                var diag = sis[sin].RunDiagnostics();

                foreach (var d in diag)
                {
                    if (d.Status != DiagnosticMessageStatus.OK)
                    {
                        ok = false;
                        break;
                    }
                }

                if (ok)
                {
                    break;
                }

                off++;
            }

            // Default slice (FULL)
            dd.LoadSlices(false);
            var sl = dd.Slices[Constants.FullSliceName];

            // Create physical database instance
            var ddi = new DatabaseInstanceInstaller(databaseVersion.DatabaseDefinition);
            var di = ddi.GenerateDatabaseInstance(
                sis[sin],
                sl,
                databaseVersion);

            di.Save();

            // Add user database mapping
            var udi = new UserDatabaseInstance(user);
            udi.DatabaseVersion = databaseVersion;
            udi.DatabaseInstance = di;

            udi.Save();

            return udi;
        }
示例#3
0
        public UserDatabaseInstance GenerateUserDatabaseInstance(DatabaseVersion databaseVersion)
        {
            // TODO: this part probably needs some optimization

            // Load server instances that can store user databases
            var ef  = new EntityFactory(Context);
            var sis = ef.FindAll <ServerInstance>()
                      .Where(i => i.ServerVersionReference.Guid == databaseVersion.ServerVersionReference.Guid)
                      .OrderBy(i => i.Machine.Number)
                      .ToArray();

            if (sis.Length == 0)
            {
                throw new InvalidOperationException("At least one server instance has to configured for the database version.");    // TODO
            }

            // Get current number of user databases
            var dd = databaseVersion.DatabaseDefinition;

            dd.LoadDatabaseInstances(false);
            var dbnum = dd.DatabaseInstances.Count;

            // Find a server that is available
            int off = 0;
            int sin = 0;

            while (off < sis.Length)
            {
                sin = (dbnum + 1 + off) % sis.Length;
                bool ok = true;

                var diag = sis[sin].RunDiagnostics();

                foreach (var d in diag)
                {
                    if (d.Status != DiagnosticMessageStatus.OK)
                    {
                        ok = false;
                        break;
                    }
                }


                if (ok)
                {
                    break;
                }

                off++;
            }

            // Default slice (FULL)
            dd.LoadSlices(false);
            var sl = dd.Slices[Constants.FullSliceName];

            // Create physical database instance
            var ddi = new DatabaseInstanceInstaller(databaseVersion.DatabaseDefinition);
            var di  = ddi.GenerateDatabaseInstance(
                sis[sin],
                sl,
                databaseVersion);

            di.Save();

            // Add user database mapping
            var udi = new UserDatabaseInstance(databaseVersion)
            {
                Name             = String.Format("{0}_{1}_", user.Name, di.DatabaseDefinition.Federation.Name, di.DatabaseDefinition.Name),
                User             = user,
                DatabaseInstance = di,
            };

            udi.Save();

            return(udi);
        }