public NewDatabaseLocationDialog(DatabaseLocationMutable newLocation, DatabaseLocation existingLocation)
 {
   InitializeComponent();
   m_existingLocation = existingLocation;
   if (m_existingLocation != null)
     Title = "Edit " + m_existingLocation.ToString();
   m_newLocation = newLocation;
   if (m_newLocation.IsBackupLocation)
   {
     BackupOfLocationLabel.Content = "Backup";
     BackupOfLocationBox.IsReadOnly = true;
   }
   base.DataContext = this;
 }
 void AddDatabaseLocation(SessionBase session, string directory)
 {
   DatabaseLocationMutable newLocationMutable = new DatabaseLocationMutable(session);
   newLocationMutable.DirectoryPath = directory;
   var popup = new NewDatabaseLocationDialog(newLocationMutable, null);
   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.BackupOfOrForLocation != null,
         newLocationMutable.BackupOfOrForLocation);
       if (session.InTransaction)
         session.Commit();
       session.BeginUpdate();
       session.NewLocation(newLocation);
       session.Commit();
       m_viewModel = new AllFederationsViewModel();
       base.DataContext = m_viewModel;
     }
     catch (Exception ex)
     {
       session.Abort();
       MessageBox.Show(ex.Message);
     }
   }
 }
    private void EditDatabaseLocationMenuItem_Click(object sender, RoutedEventArgs e)
    {
      MenuItem menuItem = (MenuItem)sender;
      DatabaseLocationViewModel view = (DatabaseLocationViewModel)menuItem.DataContext;
      DatabaseLocation dbLocation = view.DatabaseLocation;
      SessionBase session = dbLocation.Session;
      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);
        }
      }
    }
 private void NewDatabaseLocationMenuItem_Click(object sender, RoutedEventArgs e)
 {
   MenuItem menuItem = (MenuItem)sender;
   FederationViewModel view = (FederationViewModel)menuItem.DataContext;
   FederationInfo info = view.Federationinfo;
   SessionBase session = view.Session;
   DatabaseLocationMutable newLocationMutable = new DatabaseLocationMutable(session);
   var popup = new NewDatabaseLocationDialog(newLocationMutable, null);
   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.BackupOfOrForLocation != null,
         newLocationMutable.BackupOfOrForLocation);
       if (session.InTransaction)
         session.Commit();
       session.BeginUpdate();
       session.NewLocation(newLocation);
       session.Commit();
       m_viewModel = new AllFederationsViewModel();
       base.DataContext = m_viewModel;
     }
     catch (Exception ex)
     {
       session.Abort();
       MessageBox.Show(ex.Message);
     }
   }
 }
 public RestoreDialog(DatabaseLocationMutable newLocation)
 {
   InitializeComponent();
   m_newLocation = newLocation;
 }