void Initialize() { SessionBase.BaseDatabasePath = Properties.Settings.Default.BaseDatabasePath; m_session = new SessionNoServer(Properties.Settings.Default.DatabaseManagerDirectory); try { m_session.BeginUpdate(); List<FederationViewModel> federationInfos = new List<FederationViewModel>(); List<FederationInfo> federationInfosToRemove = new List<FederationInfo>(); foreach (FederationInfo info in m_session.AllObjects<FederationInfo>()) { try { federationInfos.Add(new FederationViewModel(info)); } catch (Exception ex) { if (MessageBox.Show(ex.Message + " for " + info.HostName + " " + info.SystemDbsPath + " Remove this Database?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) federationInfosToRemove.Add(info); } } foreach (FederationInfo info in federationInfosToRemove) info.Unpersist(m_session); if (federationInfos.Count() == 0) { string host = Properties.Settings.Default.DatabaseManagerHost; if (host == null || host.Length == 0) host = Dns.GetHostName(); FederationInfo info = new FederationInfo(host, Properties.Settings.Default.DatabaseManagerDirectory, Properties.Settings.Default.TcpIpPortNumber, Properties.Settings.Default.DoWindowsAuthentication, null, Properties.Settings.Default.WaitForLockMilliseconds, Properties.Settings.Default.UseClientServer, "Database Manager"); m_session.Persist(info); m_session.Commit(); federationInfos.Add(new FederationViewModel(info)); } if (m_session.InTransaction) m_session.Commit(); m_federationViews = federationInfos; } catch (Exception ex) { if (m_session.InTransaction) m_session.Abort(); if (MessageBox.Show(ex.Message + " for " + SessionBase.LocalHost + " " + Properties.Settings.Default.DatabaseManagerDirectory + " Remove this Database?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { DirectoryInfo dir = new DirectoryInfo(Properties.Settings.Default.DatabaseManagerDirectory); dir.Delete(true); Initialize(); } } }
public void UpdateRecordTest(SessionBase session) { session.BeginUpdate(); var rec = new StringRecord2(); rec.Fields["Title"] = "Simple Title"; rec.Persist(session, rec); session.Commit(); session.BeginUpdate(); rec.Fields["Title"] = "Different title text"; var rec2 = rec.Copy(); rec2.Persist(session, rec2); session.Commit(); }
/// <summary> /// A shutdown function is required to properly close the graph. /// This is important for implementations that utilize disk-based serializations. /// </summary> public void Shutdown() { if (Session.InTransaction) { Session.Commit(); } }
public void TestAllObjects() { var obj1 = new PersistentClass("OBJ1"); _session.Persist(obj1); var obj2 = new PersistentClass("OBJ2"); _session.Persist(obj2); _session.Commit(); _session.BeginUpdate(); var list = _session.AllObjects <PersistentClass>(); var computedCount = Enumerable.Count(list); Assert.AreEqual(2, computedCount); Assert.AreEqual(2, list.Count); }
private void SyncFederationMenuItem_Click(object sender, RoutedEventArgs e) { MenuItem menuItem = (MenuItem)sender; FederationViewModel view = (FederationViewModel)menuItem.DataContext; FederationInfo info = view.Federationinfo; SessionBase session = view.Session; var lDialog = new System.Windows.Forms.FolderBrowserDialog() { Description = "Choose Federation Sync Destination Folder", }; if (lDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string destdir = lDialog.SelectedPath; if (session.InTransaction) { session.Commit(); // must not be in transaction while copying databases } using (SessionBase sessionDestination = new SessionNoServer(destdir)) { sessionDestination.SyncWith(session); } m_viewModel = new AllFederationsViewModel(); base.DataContext = m_viewModel; MessageBox.Show("Databases synced with " + destdir + " at " + DateTime.Now); } }
public void IndexSample2(bool useServerSession) { CreateDirectoryAndCopyLicenseDb(); Random rd = new Random(); using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginUpdate(); for (int i = 0; i < 100; i++) { MeasurePoint p = new MeasurePoint(i + 1) { Data = new List <float>() }; for (int j = 0; j < 440000; j++) { p.Data.Add(rd.Next(100)); } session.Persist(p); } var value = session.DatabaseNumberOf(typeof(MeasurePoint)); Database db = session.OpenDatabase(value, false, false); if (db != null) { var q = from point in session.Index <MeasurePoint>("key", db) where point.Key == 10 select point; foreach (MeasurePoint obj in q) { Console.WriteLine(obj.Key + " " + obj.Data.Count); } } session.Commit(); } }
public void IOptimizedPersistableField(bool useServerSession) { using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginUpdate(); for (int i = 0; i < 10; i++) { var dict = new PersistableDynamicDictionary(); session.Persist(dict); } session.Commit(); } using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginRead(); session.TraceIndexUsage = true; DateTime now = DateTime.UtcNow; var q = from dict in session.Index <PersistableDynamicDictionary>("m_creationTime") where dict.CreationTime < now && dict.CreationTime >= now.AddYears(-1) select dict; Assert.GreaterOrEqual(q.Count(), 10); q = from dict in session.Index <PersistableDynamicDictionary>("m_creationTime") where dict.CreationTime > DateTime.UtcNow.AddYears(-1) select dict; Assert.GreaterOrEqual(q.Count(), 10); session.Commit(); } }
public void aaaFakeLicenseDatabaseCleanup(bool deleteLocationProperly, bool useServerSession) { if (deleteLocationProperly) { using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginUpdate(); DatabaseLocation defaultLocation = session.DatabaseLocations.Default(); List <Database> dbList = session.OpenLocationDatabases(defaultLocation, true); foreach (Database db in dbList) { if (db.DatabaseNumber > Database.InitialReservedDatabaseNumbers) { session.DeleteDatabase(db); } } session.DeleteLocation(defaultLocation); session.Commit(); } } foreach (string s in Directory.GetFiles(systemDir)) { File.Delete(s); } using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { session.BeginUpdate(); UInt32 dbNum = session.DatabaseNumberOf(typeof(NotSharingPage)); session.NewDatabase(dbNum); session.Commit(); } File.Copy(licenseDbFile, Path.Combine(systemDir, "4.odb")); }
public void BTreeMap1Populate() { int sessionId = 0; SessionBase session = null; try { session = SessionManager.SessionPool.GetSession(out sessionId); session.BeginUpdate(); var bTreeMap = new BTreeMapOwner(); _id = session.Persist(bTreeMap); for (int i = 0; i < numberOfZipCodes; i++) { string str = i.ToString(); var bTree = new BTreeSet <LocationWithinUSA>(); for (int j = 0; j < Math.Min(i, 1000); j++) { var loc = new LocationWithinUSA(); session.Persist(loc); bTree.AddFast(loc); } bTreeMap.LocationByZipCode.AddFast(str, bTree); } session.Commit(); } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } finally { SessionManager.SessionPool.FreeSession(sessionId, session); } }
void LockConflict(SessionBase sharedReadSession) { string host = null; Random r = new Random(5); SessionPool sessionPool = new SessionPool(3, () => new ServerClientSession(systemDir, host, 2000, false)); try { int iCounter = 0; int sessionId1 = -1; SessionBase session1 = null; for (int i = 0; i < 50; i++) { try { session1 = sessionPool.GetSession(out sessionId1); session1.BeginUpdate(); Dokument Doc_A = new Dokument(); Doc_A.Name = "Test A"; session1.Persist(Doc_A); Console.WriteLine(Doc_A.ToString()); int sessionId2 = -1; SessionBase session2 = null; try { session2 = sessionPool.GetSession(out sessionId2); session2.BeginUpdate(); Dokument Doc_B = new Dokument(); Doc_B.Name = "Test_B"; session2.Persist(Doc_B); Console.WriteLine(Doc_B.ToString()); session2.Commit(); } finally { sessionPool.FreeSession(sessionId2, session2); } session1.Commit(); sharedReadSession.ForceDatabaseCacheValidation(); session1.BeginRead(); ulong ct = session1.AllObjects <Dokument>(false).Count; Console.WriteLine("Number of Dokument found by normal session: " + ct); session1.Commit(); ct = sharedReadSession.AllObjects <Dokument>(false).Count; Console.WriteLine("Number of Dokument found by shared read session: " + ct); } finally { sessionPool.FreeSession(sessionId1, session1); } iCounter++; Console.WriteLine(" -> " + iCounter.ToString()); } } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } }
public void createDatabaseLocations(SessionBase session) { session.BeginUpdate(); Person person = new Person("Mats", "Persson", 54); session.Persist(person); session.Commit(); verifyDatabaseLocations(session); }
void VersionManagerTest(SessionBase sess) { VelocityDbSchema.Samples.Sample1.Person person; sess.BeginUpdate(); foreach (DatabaseLocation loc in sess.DatabaseLocations) { Console.WriteLine(loc.ToStringDetails(sess, false)); } Console.WriteLine(); var count = 10000; var vm = GetVersionManager(sess) ?? new VersionManager <VelocityDbSchema.Samples.Sample1.Person>(RecordType.Person); var startCount = vm.Count; var tw = new Stopwatch(); tw.Start(); for (int i = startCount; i < count + startCount; i++) { person = new VelocityDbSchema.Samples.Sample1.Person("Bill" + i, "Gates", 56); person.Persist(sess, person); vm.Add(new WeakIOptimizedPersistableReference <VelocityDbSchema.Samples.Sample1.Person>(person)); } vm.Persist(sess, vm); tw.Stop(); Console.WriteLine("{0} records in {1} ms.", count, tw.ElapsedMilliseconds); sess.Commit(); // Now go get the vm and lookup the items if (sess is SessionNoServer) { sess = new SessionNoServer(systemDir); } else { sess = new ServerClientSession(systemDir); } sess.BeginRead(); var vm2 = GetVersionManager(sess); if (vm2 != null) { Assert.IsTrue(vm2.Count > count - 1); person = vm2.Tip.GetTarget(false, sess); Assert.IsNotNull(person); var person2 = vm2.Tip.GetTarget(false, sess); Assert.AreSame(person, person2); Console.WriteLine("{0} records in version manager and tip is {1}.", vm2.Count, person2); } sess.Commit(); sess.BeginUpdate(); Database db = sess.OpenDatabase(VersionManager <VelocityDbSchema.Samples.Sample1.Person> .versionMangerDatabase, false, false); if (db != null) { sess.DeleteDatabase(db); } sess.Dispose(); }
public void moveDatabaseLocations(SessionBase session, string updatedHostName, string newPath) { session.BeginUpdate(false); DatabaseLocation bootLocation = session.DatabaseLocations.LocationForDb(0); DatabaseLocation locationNew = new DatabaseLocation(updatedHostName, newPath, bootLocation.StartDatabaseNumber, bootLocation.EndDatabaseNumber, session, bootLocation.CompressPages, bootLocation.PageEncryption, bootLocation.IsBackupLocation, bootLocation.BackupOfOrForLocation); bootLocation = session.NewLocation(locationNew); session.Commit(false); }
public void SimpleTest1_0_0(bool bGenerateUnique, bool useServerSession) { using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir)) { try { session.BeginUpdate(); session.CrossTransactionCacheAllDatabases(); //session.RegisterClass(typeof(RDerby1)); //Assert.True(session.Index<RDerby1>().Count == 0); // enter five records into data base Random random = new Random(); for (int i = 0; i < 5; i++) { RDerby1 classData; string added = "added" + i; if (bGenerateUnique) { classData = new RDerby1("test" + i + "_" + random.Next(), "name2" + i.ToString() + "_" + random.Next(), added); session.Persist(classData); } else { try { classData = new RDerby1("test" + i, "name2" + i.ToString(), added); session.Persist(classData); } catch (UniqueConstraintException) { Assert.Greater(i, 0); } } } try { session.Commit(); } catch (Exception ex) { throw new Exception("Exception occured while commiting records: " + ex.Message); } } catch (Exception ex) { // examine problem using breakpoint. throw new Exception("Exception occured while persisting records: " + ex.Message); } finally { } } Console.WriteLine(DisplayData(useServerSession)); }
public AllFederationsViewModel() { SessionBase.BaseDatabasePath = Properties.Settings.Default.BaseDatabasePath; m_session = new SessionNoServer(Properties.Settings.Default.DatabaseManagerDirectory); m_session.BeginUpdate(); List <FederationViewModel> federationInfos = new List <FederationViewModel>(); foreach (FederationInfo info in m_session.AllObjects <FederationInfo>()) { try { federationInfos.Add(new FederationViewModel(info)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } if (federationInfos.Count() == 0) { string host = Properties.Settings.Default.DatabaseManagerHost; if (host == null || host.Length == 0) { host = Dns.GetHostName(); } FederationInfo info = new FederationInfo(host, Properties.Settings.Default.DatabaseManagerDirectory, Properties.Settings.Default.TcpIpPortNumber, Properties.Settings.Default.DoWindowsAuthentication, null, Properties.Settings.Default.UseClientServer, "Database Manager"); m_session.Persist(info); m_session.Commit(); federationInfos.Add(new FederationViewModel(info)); } if (m_session.InTransaction) { m_session.Commit(); } m_federationViews = new ReadOnlyCollection <FederationViewModel>(federationInfos); }
/// <summary> /// Removes a claim from a user. /// </summary> /// <param name="user">The user.</param> /// <param name="claim">The claim.</param> /// <returns></returns> public Task RemoveClaimAsync(T user, Claim claim) { SessionBase session = Session; bool inUpdate = session.InUpdateTransaction; if (inUpdate == false) { if (session.InTransaction) { session.Commit(); } session.BeginUpdate(); } user.Claims.Remove(claim); if (inUpdate == false) { session.Commit(); } return(Task.FromResult(0)); }
public void verifyDatabaseLocations(SessionBase session) { session.BeginRead(); foreach (Person person in session.AllObjects <Person>()) { Console.WriteLine(person.ToString()); Assert.AreEqual(person.FirstName, "Mats"); } session.Commit(); session.Verify(); }
/// <inheritdoc /> public override void EndSession(SyncSessionContext syncSessionContext) { if (syncSessionContext.IsCanceled()) { m_session.Abort(); } else { m_session.Commit(); } }
/// <summary> /// Sets the user's email confirmed flag. /// </summary> /// <param name="user">The user.</param> /// <param name="confirmed">if set to <c>true</c> the user's email has been confirmed.</param> /// <returns></returns> /// <exception cref="NullObjectException">if user is null.</exception> /// <exception cref="Exception">Any client error condition.</exception> public Task SetEmailConfirmedAsync(T user, bool confirmed) { SessionBase session = Session; bool inUpdate = session.InUpdateTransaction; if (inUpdate == false) { if (session.InTransaction) { session.Commit(); } session.BeginUpdate(); } user.EmailConfirmed = confirmed; if (inUpdate == false) { session.Commit(); } return(Task.FromResult(0)); }
public void verifyDatabaseLocations(SessionBase session) { session.BeginRead(); foreach (Person person in session.AllObjects<Person>()) { Console.WriteLine(person.ToString()); Assert.AreEqual(person.FirstName, "Mats"); } session.Commit(); session.Verify(); }
/// <summary> /// Sets the user's email. /// </summary> /// <param name="user">The user's email.</param> /// <param name="email">The email to set to the user's identity.</param> /// <returns></returns> /// <exception cref="NullObjectException">If user is null.</exception> /// <exception cref="Exception">Any client error condition.</exception> public Task SetEmailAsync(T user, string email) { SessionBase session = Session; bool inUpdate = session.InUpdateTransaction; if (inUpdate == false) { if (session.InTransaction) { session.Commit(); } session.BeginUpdate(); } user.Email = email; if (inUpdate == false) { session.Commit(); } return(Task.FromResult(0)); }
/// <summary> /// Sets a flag indicating two factor authentication is enabled for a user. /// </summary> /// <param name="user">The user.</param> /// <param name="enabled">if set to <c>true</c> <see cref="IdentityUser.TwoFactorEnabled"/>enabled.</param> /// <returns></returns> /// <exception cref="NullObjectException">If user is null.</exception> /// <exception cref="Exception">Any client error condition.</exception> public Task SetTwoFactorEnabledAsync(T user, bool enabled) { SessionBase session = Session; bool inUpdate = session.InUpdateTransaction; if (inUpdate == false) { if (session.InTransaction) { session.Commit(); } session.BeginUpdate(); } user.TwoFactorEnabled = enabled; if (inUpdate == false) { session.Commit(); } return(Task.FromResult(0)); }
/// <summary> /// Increments the access failed count for a user. /// </summary> /// <param name="user">The user.</param> /// <returns></returns> /// <exception cref="NullObjectException">If user is null.</exception> /// <exception cref="Exception">Any client error condition.</exception> public async Task <int> IncrementAccessFailedCountAsync(T user) { SessionBase session = Session; bool inUpdate = session.InUpdateTransaction; if (inUpdate == false) { if (session.InTransaction) { session.Commit(); } session.BeginUpdate(); } user.AccessFailedCount = user.AccessFailedCount + 1; if (inUpdate == false) { session.Commit(); } return(await Task.FromResult(user.AccessFailedCount)); }
/// <summary> /// Sets the lockout end date. /// </summary> /// <param name="user">The user.</param> /// <param name="lockoutEnd">The lockout end.</param> /// <returns></returns> /// <exception cref="NullObjectException">If user is null.</exception> /// <exception cref="Exception">Any client error condition.</exception> public Task SetLockoutEndDateAsync(T user, DateTimeOffset lockoutEnd) { SessionBase session = Session; bool inUpdate = session.InUpdateTransaction; if (inUpdate == false) { if (session.InTransaction) { session.Commit(); } session.BeginUpdate(); } user.LockoutEndDateUtc = lockoutEnd.UtcDateTime; if (inUpdate == false) { session.Commit(); } return(Task.FromResult(0)); }
/// <summary> /// Sets the phone number for a user. /// </summary> /// <param name="user">The user.</param> /// <param name="phoneNumber">The phone number.</param> /// <returns></returns> /// <exception cref="NullObjectException">If user is null.</exception> /// <exception cref="Exception">Any client error condition.</exception> public Task SetPhoneNumberAsync(T user, string phoneNumber) { SessionBase session = Session; bool inUpdate = session.InUpdateTransaction; if (inUpdate == false) { if (session.InTransaction) { session.Commit(); } session.BeginUpdate(); } user.PhoneNumber = phoneNumber; if (inUpdate == false) { session.Commit(); } return(Task.FromResult(0)); }
/// <summary> /// Sets the security stamp. /// </summary> /// <param name="user">The user.</param> /// <param name="stamp">The stamp.</param> /// <returns></returns> public Task SetSecurityStampAsync(T user, string stamp) { SessionBase session = Session; bool inUpdate = session.InUpdateTransaction; if (inUpdate == false) { if (session.InTransaction) { session.Commit(); } session.BeginUpdate(); } user.SecurityStamp = stamp; if (inUpdate == false) { session.Commit(); } return(Task.FromResult(0)); }
/// <summary> /// Adds a user to a role. /// </summary> /// <param name="user">The user.</param> /// <param name="roleName">Name of the role.</param> /// <returns></returns> public Task AddToRoleAsync(T user, string roleName) { SessionBase session = Session; bool inUpdate = session.InUpdateTransaction; if (inUpdate == false) { if (session.InTransaction) { session.Commit(); } session.BeginUpdate(); } user.Roles.Add(new IdentityRole(roleName)); if (inUpdate == false) { session.Commit(); } return(Task.FromResult(0)); }
/// <summary> /// Deletes a role as an asynchronous operation. /// </summary> /// <param name="role">The role.</param> /// <returns></returns> /// <exception cref="VelocityDBAspNetIdentityException"></exception> public async Task DeleteAsync(T role) { SessionBase session = Session; bool inUpdate = session.InUpdateTransaction; if (inUpdate == false) { if (session.InTransaction) { session.Commit(); } session.BeginUpdate(); } await Task.FromResult(m_aspNetIdentity.RoleSet.Remove(role)); if (inUpdate == false) { session.Commit(); } }
/// <summary> /// Sets the password hash for a user. /// </summary> /// <param name="user">The user.</param> /// <param name="passwordHash">The password hash.</param> /// <returns></returns> /// <exception cref="KeyNotFoundException">All server responses other than Success.</exception> /// <exception cref="Exception">Any client error condition.</exception> public Task SetPasswordHashAsync(T user, string passwordHash) { SessionBase session = Session; bool inUpdate = session.InUpdateTransaction; if (inUpdate == false) { if (session.InTransaction) { session.Commit(); } session.BeginUpdate(); } user.PasswordHash = passwordHash; if (inUpdate == false) { session.Commit(); } return(Task.FromResult(0)); }
public object Get([BindRequired, FromQuery] string path, [BindRequired, FromQuery] string id) { if (path == null) { return("Path no set"); } if (id == null) { return("object Id not specified (as string)"); } try { var pool = GetSessionPool(path); int sessionId = -1; SessionBase session = null; try { session = pool.GetSession(out sessionId); UInt64 Id; if (id.Contains('-')) { Id = Oid.IdFromString(id); } else { UInt64.TryParse(id, out Id); } if (Id != 0) { session.BeginRead(); var obj = session.Open <IOptimizedPersistable>(Id); session.Commit(); if (obj == null) { return($"object with id {id} does not exist"); } return(new TypePlusObj(obj)); } return(null); } finally { if (session != null) { pool.FreeSession(sessionId, session); } } } catch (Exception ex) { return(ex.Message); } }
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); } } }
/// <summary> /// Updates a user. /// </summary> /// <param name="user">The user.</param> /// <returns></returns> /// <exception cref="KeyNotFoundException">Any client error condition.</exception> public async Task UpdateAsync(T user) { SessionBase session = Session; bool inUpdate = session.InUpdateTransaction; if (inUpdate == false) { if (session.InTransaction) { session.Commit(); } session.BeginUpdate(); } m_aspNetIdentity.UserSet.Remove(user); await Task.FromResult(m_aspNetIdentity.UserSet.Add(user)); if (inUpdate == false) { session.Commit(); } }
public AllFederationsViewModel() { SessionBase.BaseDatabasePath = Properties.Settings.Default.BaseDatabasePath; m_session = new SessionNoServer(Properties.Settings.Default.DatabaseManagerDirectory); m_session.BeginUpdate(); List<FederationViewModel> federationInfos = new List<FederationViewModel>(); foreach (FederationInfo info in m_session.AllObjects<FederationInfo>()) { try { federationInfos.Add(new FederationViewModel(info)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } if (federationInfos.Count() == 0) { string host = Properties.Settings.Default.DatabaseManagerHost; if (host == null || host.Length == 0) host = Dns.GetHostName(); FederationInfo info = new FederationInfo(host, Properties.Settings.Default.DatabaseManagerDirectory, Properties.Settings.Default.TcpIpPortNumber, Properties.Settings.Default.DoWindowsAuthentication, null, Properties.Settings.Default.UseClientServer, "Database Manager"); m_session.Persist(info); m_session.Commit(); federationInfos.Add(new FederationViewModel(info)); } if (m_session.InTransaction) m_session.Commit(); m_federationViews = new ReadOnlyCollection<FederationViewModel>(federationInfos); }
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); } } }
public void Recover1(SessionBase session) { Database db = null; session.BeginUpdate(); db = session.OpenDatabase(88, true, false); if (db != null) session.DeleteDatabase(db); db = session.OpenDatabase(89, true, false); if (db != null) session.DeleteDatabase(db); session.Commit(); session.BeginUpdate(); db = session.NewDatabase(88); session.FlushUpdates(); session.Abort(); session.BeginUpdate(); db = session.NewDatabase(88); SortedSetAny<float> floatSet; Oid floatSetOid; string dbPath = System.IO.Path.Combine(systemDir, "89.odb"); Placement place = new Placement(88); for (int i = 0; i < 10; i++) { floatSet = new SortedSetAny<float>(); floatSet.Persist(place, session); floatSetOid = floatSet.Oid; } db = session.NewDatabase(89); session.Commit(); File.Delete(dbPath); session.BeginUpdate(); db = session.NewDatabase(89); session.Commit(); FileInfo info = new FileInfo(dbPath); info.CopyTo(dbPath + "X"); session.BeginUpdate(); SortedSetAny<int> intSet; place = new Placement(89); for (int i = 0; i < 10; i++) { intSet = new SortedSetAny<int>(); intSet.Persist(place, session); } db = session.OpenDatabase(88); var list = db.AllObjects<SortedSetAny<float>>(); foreach (SortedSetAny<float> set in list) set.Unpersist(session); db = session.OpenDatabase(89); session.Commit(); intSet = null; db = null; // release refs so that cached data isn't stale File.Delete(dbPath); info = new FileInfo(dbPath + "X"); info.MoveTo(dbPath); session.BeginUpdate(); intSet = (SortedSetAny<int>)session.Open(89, 1, 1, false); Debug.Assert(intSet == null); object o = session.Open(88, 1, 1, false); floatSet = (SortedSetAny<float>)o; Debug.Assert(floatSet != null); session.Commit(); session.BeginUpdate(); db = session.OpenDatabase(88); session.DeleteDatabase(db); db = session.OpenDatabase(89); session.DeleteDatabase(db); session.Commit(); }