protected override void LoadChildren()
        {
            base.Children.Add(new ObjectViewModel(m_databaseLocation, this, m_databaseLocation.GetSession()));
            IOrderedEnumerable <Database> dbs;

            if (!m_databaseLocation.GetSession().InTransaction)
            {
                m_databaseLocation.GetSession().BeginRead();
            }
            if (m_orderDatabasesByName)
            {
                dbs = m_databaseLocation.GetSession().OpenLocationDatabases(m_databaseLocation, false).OrderBy(db => db.Name);
            }
            else
            {
                dbs = m_databaseLocation.GetSession().OpenLocationDatabases(m_databaseLocation, false).OrderBy(db => db.Id);
            }
            using (System.Windows.Application.Current.Dispatcher.DisableProcessing())
            {
                foreach (Database database in dbs)
                {
                    base.Children.Add(new DatabaseViewModel(this, database));
                }
            }
        }
Esempio n. 2
0
        private void RemoveDatabaseLocationMenuItem_Click(object sender, RoutedEventArgs e)
        {
            MenuItem menuItem = (MenuItem)sender;
            DatabaseLocationViewModel view       = (DatabaseLocationViewModel)menuItem.DataContext;
            DatabaseLocation          dbLocation = view.DatabaseLocation;
            SessionBase session = dbLocation.GetSession();

            if (session.InTransaction)
            {
                session.Commit();
            }
            session.BeginUpdate();
            try
            {
                session.DeleteLocation(dbLocation);
                session.Commit();
                m_viewModel      = new AllFederationsViewModel();
                base.DataContext = m_viewModel;
            }
            catch (Exception ex)
            {
                session.Abort();
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 3
0
        private void EditDatabaseLocationMenuItem_Click(object sender, RoutedEventArgs e)
        {
            MenuItem menuItem = (MenuItem)sender;
            DatabaseLocationViewModel view             = (DatabaseLocationViewModel)menuItem.DataContext;
            DatabaseLocation          dbLocation       = view.DatabaseLocation;
            SessionBase             session            = dbLocation.GetSession();
            DatabaseLocationMutable newLocationMutable = new DatabaseLocationMutable(session);

            newLocationMutable.BackupOfOrForLocation = dbLocation.BackupOfOrForLocation;
            newLocationMutable.CompressPages         = dbLocation.CompressPages;
            newLocationMutable.PageEncryption        = dbLocation.PageEncryption;
            newLocationMutable.StartDatabaseNumber   = dbLocation.StartDatabaseNumber;
            newLocationMutable.EndDatabaseNumber     = dbLocation.EndDatabaseNumber;
            newLocationMutable.IsBackupLocation      = dbLocation.IsBackupLocation;
            newLocationMutable.DirectoryPath         = dbLocation.DirectoryPath;
            newLocationMutable.HostName = dbLocation.HostName;
            if (dbLocation.DesKey != null)
            {
                newLocationMutable.DesKey = SessionBase.TextEncoding.GetString(dbLocation.DesKey, 0, dbLocation.DesKey.Length);
            }

            var  popup  = new NewDatabaseLocationDialog(newLocationMutable, dbLocation);
            bool?result = popup.ShowDialog();

            if (result != null && result.Value)
            {
                try
                {
                    DatabaseLocation newLocation = new DatabaseLocation(newLocationMutable.HostName, newLocationMutable.DirectoryPath, newLocationMutable.StartDatabaseNumber,
                                                                        newLocationMutable.EndDatabaseNumber, session, newLocationMutable.CompressPages, newLocationMutable.PageEncryption, newLocationMutable.IsBackupLocation,
                                                                        newLocationMutable.IsBackupLocation ? newLocationMutable.BackupOfOrForLocation : dbLocation.BackupOfOrForLocation);
                    if (session.InTransaction)
                    {
                        session.Commit();
                    }
                    session.BeginUpdate();
                    newLocation        = session.NewLocation(newLocation);
                    newLocation.DesKey = SessionBase.TextEncoding.GetBytes(newLocationMutable.DesKey);
                    session.Commit();
                    m_viewModel      = new AllFederationsViewModel();
                    base.DataContext = m_viewModel;
                }
                catch (Exception ex)
                {
                    session.Abort();
                    MessageBox.Show(ex.Message);
                }
            }
        }
Esempio n. 4
0
        private void RestoreDatabaseLocationMenuItem_Click(object sender, RoutedEventArgs e)
        {
            MenuItem menuItem = (MenuItem)sender;
            DatabaseLocationViewModel view       = (DatabaseLocationViewModel)menuItem.DataContext;
            DatabaseLocation          dbLocation = view.DatabaseLocation;
            SessionBase session = dbLocation.GetSession();

            if (session.InTransaction)
            {
                session.Commit();
            }
            //DatabaseLocationMutable newLocationMutable = new DatabaseLocationMutable(session);
            //newLocationMutable.DirectoryPath = dbLocation.DirectoryPath;
            //newLocationMutable.HostName = dbLocation.HostName;
            //var popup = new RestoreDialog(newLocationMutable);
            //bool? result = popup.ShowDialog();
            //if (result != null && result.Value)
            {
                dbLocation.SetPage(null); // fake it as a transient object before restore !
                dbLocation.Id = 0;        // be careful about doing this kind of make transient tricks, references from objects like this are still persistent.
                // if (session.OptimisticLocking) // && session.GetType() == typeof(ServerClientSession))
                {
                    // session.Dispose();
                    // session = new ServerClientSession(session.SystemDirectory, session.SystemHostName, 2000, false, false); // need to use pessimstic locking for restore
                    // = new SessionNoServer(session.SystemDirectory); // need to use pessimstic locking for restore
                }
                session.BeginUpdate();
                try
                {
                    session.RestoreFrom(dbLocation, DateTime.Now);
                    session.Commit(false, true); // special flags when commit of a restore ...
                    m_viewModel      = new AllFederationsViewModel();
                    base.DataContext = m_viewModel;
                }
                catch (Exception ex)
                {
                    session.Abort();
                    MessageBox.Show(ex.Message);
                }
            }
        }