Beispiel #1
0
        public Context(string path)
        {
            var p = Path.Combine(@"C:\Databases\", path);
            var s = Path.Combine(Path.GetDirectoryName(p), "4.odb");
            var d = Path.Combine(p, "4.odb");

            SessionBase.DefaultStringComparer = StringComparer.Ordinal;

            //            _session = GetSessionPool(p).GetSession(out _);
            _session = new SessionNoServerShared(p);
            _session.BeginUpdate(true);
            _session.RegisterClass(typeof(Investigation));
            _session.RegisterClass(typeof(Device));
            _session.RegisterClass(typeof(ArtifactCommunication));
            _session.RegisterClass(typeof(ArtifactPerson));
            _session.RegisterClass(typeof(Node));
            _session.RegisterClass(typeof(Relation));

            if (File.Exists(s) && File.Exists(d) == false)  // Om licensen "4.odb" finns under roten, kopiera den till db-katalogen.
            {
                File.Copy(s, d);
            }

            _investigation = _session.AllObjects <Investigation>().FirstOrDefault() ?? SessionPersist(new Investigation());

            Trace.Listeners.Add(new ConsoleTraceListener());
        }
Beispiel #2
0
 public static HashSet<GeoObj> SearchGeoHashIndex(SessionBase session, double lat, double lon, double radius)
 {
   HashSet<GeoObj> resultSet = new HashSet<GeoObj>();
   WGS84Point center = new WGS84Point(lat, lon);
   GeoHashCircleQuery query = new GeoHashCircleQuery(center, radius); // radius in meters
   BoundingBox bbox = query.BoundingBox;
   var btreeSet = session.AllObjects<BTreeSet<GeoObj>>().FirstOrDefault();
   foreach (GeoHash hash in query.SearchHashes)
   {
     var itr = btreeSet.Iterator();
     itr.GoTo(new GeoObj(hash.LongValue));
     var current = itr.Current();
     while (current != null)
     {
       GeoHash geoHash = GeoHash.FromLongValue(current.GeoHash);
       if ((geoHash.SignificantBits >= hash.SignificantBits && geoHash.Within(hash)) || (geoHash.SignificantBits < hash.SignificantBits && hash.Within(geoHash)))
       {
         if (!(current.Latitude < bbox.MinLat || current.Latitude > bbox.MaxLat || current.Longitude < bbox.MinLon || current.Longitude > bbox.MaxLon))
           resultSet.Add(current);
         current = itr.Next();
       }
       else
         break;
     }
   }
   return resultSet;
 }
Beispiel #3
0
        public static HashSet <GeoObj> SearchGeoHashIndex(SessionBase session, double lat, double lon, double radius)
        {
            HashSet <GeoObj>   resultSet = new HashSet <GeoObj>();
            WGS84Point         center    = new WGS84Point(lat, lon);
            GeoHashCircleQuery query     = new GeoHashCircleQuery(center, radius); // radius in meters
            BoundingBox        bbox      = query.BoundingBox;
            var btreeSet = session.AllObjects <BTreeSet <GeoObj> >().FirstOrDefault();

            foreach (GeoHash hash in query.SearchHashes)
            {
                var itr = btreeSet.Iterator();
                itr.GoTo(new GeoObj(hash.LongValue));
                var current = itr.Current();
                while (current != null)
                {
                    GeoHash geoHash = GeoHash.FromLongValue(current.GeoHashAsLong);
                    if ((geoHash.SignificantBits >= hash.SignificantBits && geoHash.Within(hash)) || (geoHash.SignificantBits < hash.SignificantBits && hash.Within(geoHash)))
                    {
                        if (!(current.Latitude < bbox.MinLat || current.Latitude > bbox.MaxLat || current.Longitude < bbox.MinLon || current.Longitude > bbox.MaxLon))
                        {
                            resultSet.Add(current);
                        }
                        current = itr.Next();
                    }
                    else
                    {
                        break;
                    }
                }
            }
            return(resultSet);
        }
Beispiel #4
0
        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;
            }
        }
 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();
     }
   }
 }
Beispiel #6
0
        MitchellClaimType ReadClaim(string claimNumber, SessionBase session)
        {
            MitchellClaimType claim = (from c in session.AllObjects <MitchellClaimType>() where c.ClaimNumber == claimNumber select c).FirstOrDefault();

            if (claim == null)
            {
                Console.WriteLine("Invalid claim read, claim with claim number: " + claimNumber + " does not exist in database");
            }
            return(claim);
        }
 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();
 }
Beispiel #8
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();
 }
Beispiel #9
0
            public void TestAllObjects()
            {
                var obj1 = new PersistentClass("OBJ1");

                _session.Persist(obj1);
                var obj2 = new PersistentClass("OBJ2");

                _session.Persist(obj2);
                _session.Checkpoint();
                var list          = _session.AllObjects <PersistentClass>();
                var computedCount = Enumerable.Count(list);

                Assert.AreEqual(2, computedCount);
                Assert.AreEqual(2, list.Count);
            }
Beispiel #10
0
        static public IEnumerable <string> ExportToJson <T>(this SessionBase session, bool includeSubclasses = false, bool databasePerType = true)
        {
            JsonSerializerSettings jsonSettings = new JsonSerializerSettings();

            jsonSettings.TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple;
            jsonSettings.TypeNameHandling           = TypeNameHandling.All;
            jsonSettings.PreserveReferencesHandling = PreserveReferencesHandling.Objects;
            jsonSettings.ContractResolver           = new FieldsOnlyContractResolver();
            var e = session.AllObjects <T>(includeSubclasses, databasePerType);

            foreach (T t in e)
            {
                yield return(JsonConvert.SerializeObject(t, jsonSettings));
            }
        }
Beispiel #11
0
        public static HashSet <GeoObj> SearchGeoHashIndex(SessionBase session, double minLat, double minLon, double maxLat, double maxLon)
        {
            HashSet <GeoObj> resultSet = new HashSet <GeoObj>();

            if (minLat > maxLat)
            {
                double t = minLat;
                minLat = maxLat;
                maxLat = t;
            }
            if (minLon > maxLon)
            {
                double t = minLon;
                minLon = maxLon;
                maxLon = t;
            }
            WGS84Point              min   = new WGS84Point(minLat, minLon);
            WGS84Point              max   = new WGS84Point(maxLat, maxLon);
            BoundingBox             bbox  = new BoundingBox(min, max);
            GeoHashBoundingBoxQuery query = new GeoHashBoundingBoxQuery(bbox);
            var btreeSet = session.AllObjects <BTreeSet <GeoObj> >().FirstOrDefault();

            foreach (GeoHash hash in query.SearchHashes)
            {
                var itr = btreeSet.Iterator();
                itr.GoTo(new GeoObj(hash.LongValue));
                var current = itr.Current();
                while (current != null)
                {
                    GeoHash geoHash = GeoHash.FromLongValue(current.GeoHashAsLong);
                    if ((geoHash.SignificantBits >= hash.SignificantBits && geoHash.Within(hash)) || (geoHash.SignificantBits < hash.SignificantBits && hash.Within(geoHash)))
                    {
                        if (!(current.Latitude < bbox.MinLat || current.Latitude > bbox.MaxLat || current.Longitude < bbox.MinLon || current.Longitude > bbox.MaxLon))
                        {
                            resultSet.Add(current);
                        }
                        current = itr.Next();
                    }
                    else
                    {
                        break;
                    }
                }
            }
            return(resultSet);
        }
 protected override void LoadChildren()
 {
     if (VelocityGraphMode)
     {
         foreach (var graph in m_session.AllObjects <VelocityGraph.Graph>())
         {
             base.Children.Add(new VelocityGraphViewModel(graph));
         }
     }
     else
     {
         base.Children.Add(new ObjectViewModel(m_federationInfo, this, m_session));
         DatabaseLocations locations = m_session.DatabaseLocations;
         foreach (DatabaseLocation location in locations)
         {
             base.Children.Add(new DatabaseLocationViewModel(location, Properties.Settings.Default.OrderDatabasesByName));
         }
     }
 }
        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);
        }
Beispiel #14
0
 public static HashSet<GeoObj> SearchGeoHashIndex(SessionBase session, double minLat, double minLon, double maxLat, double maxLon)
 {
   HashSet<GeoObj> resultSet = new HashSet<GeoObj>();
   if (minLat > maxLat)
   {
     double t = minLat;
     minLat = maxLat;
     maxLat = t;
   }
   if (minLon > maxLon)
   {
     double t = minLon;
     minLon = maxLon;
     maxLon = t;
   }
   WGS84Point min = new WGS84Point(minLat, minLon);
   WGS84Point max = new WGS84Point(maxLat, maxLon);
   BoundingBox bbox = new BoundingBox(min, max);
   GeoHashBoundingBoxQuery query = new GeoHashBoundingBoxQuery(bbox);
   var btreeSet = session.AllObjects<BTreeSet<GeoObj>>().FirstOrDefault();
   foreach (GeoHash hash in query.SearchHashes)
   {
     var itr = btreeSet.Iterator();
     itr.GoTo(new GeoObj(hash.LongValue));
     var current = itr.Current();
     while (current != null)
     {
       GeoHash geoHash = GeoHash.FromLongValue(current.GeoHash);
       if ((geoHash.SignificantBits >= hash.SignificantBits && geoHash.Within(hash)) || (geoHash.SignificantBits < hash.SignificantBits && hash.Within(geoHash)))
       {
         if (!(current.Latitude < bbox.MinLat || current.Latitude > bbox.MaxLat || current.Longitude < bbox.MinLon || current.Longitude > bbox.MaxLon))
           resultSet.Add(current);
         current = itr.Next();
       }
       else
         break;
     }
   }
   return resultSet;
 }
 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);
 }
Beispiel #16
0
        static public void SyncWith(this SessionBase sessionToUpdate, SessionBase sessionToRead, Func <SessionBase, UInt64, Change, bool> doUpdate)
        {
            UInt64 currentVersion;
            UInt64 pageToReadVersion;
            bool   conflictFound = false;

            using (var reader = sessionToRead.BeginRead())
            {
                Changes changes = (Changes)sessionToRead.Open(5, 1, 1, false);
                if (changes != null)
                {
                    using (var updater = sessionToUpdate.BeginUpdate())
                    {
                        var         dbs = sessionToUpdate.OpenAllDatabases();
                        ReplicaSync matchingReplicaSync = null;
                        foreach (ReplicaSync sync in sessionToUpdate.AllObjects <ReplicaSync>())
                        {
                            if (sync.SyncFromHost == sessionToRead.SystemHostName && sync.SyncFromPath == sessionToRead.SystemDirectory)
                            {
                                matchingReplicaSync = sync;
                                break;
                            }
                        }
                        if (changes.ChangeList.Count > 0)
                        {
                            foreach (TransactionChanges transactionChanges in changes.ChangeList)
                            {
                                if (matchingReplicaSync == null || matchingReplicaSync.TransactionNumber < transactionChanges.TransactionNumber)
                                {
                                    foreach (Change change in transactionChanges.ChangeList)
                                    {
                                        Database dbToUpdate = sessionToUpdate.OpenDatabase(change.DatabaseId, false, false);
                                        Database dbToRead   = sessionToRead.OpenDatabase(change.DatabaseId, false, false);
                                        string   dbName     = dbToRead != null ? dbToRead.Name : null;
                                        if (change.Deleted)
                                        {
                                            if (dbToUpdate == null) // does not exist
                                            {
                                                continue;
                                            }
                                            if (change.PageId == 0) // Database delete
                                            {
                                                currentVersion = dbToUpdate.Page.PageInfo.VersionNumber;
                                                if (currentVersion < change.Version)
                                                {
                                                    sessionToUpdate.DeleteDatabase(dbToUpdate);
                                                }
                                                else
                                                {
                                                    conflictFound = true;
                                                    if (doUpdate(sessionToUpdate, currentVersion, change))
                                                    {
                                                        sessionToUpdate.DeleteDatabase(dbToUpdate);
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                Page page = sessionToUpdate.OpenPage(dbToUpdate, change.PageId);
                                                if (page == null) // page does not exist
                                                {
                                                    continue;
                                                }
                                                currentVersion = page.PageInfo.VersionNumber;
                                                if (currentVersion < change.Version)
                                                {
                                                    sessionToUpdate.DeletePage(dbToUpdate, page);
                                                }
                                                else
                                                {
                                                    conflictFound = true;
                                                    if (doUpdate(sessionToUpdate, currentVersion, change))
                                                    {
                                                        sessionToUpdate.DeleteDatabase(dbToUpdate);
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (dbToUpdate == null) // does not exist
                                            {
                                                dbToUpdate = sessionToUpdate.NewDatabase(change.DatabaseId, 0, dbName);
                                            }
                                            if (change.PageId > 0)
                                            {
                                                Page pageToUpdate = sessionToUpdate.OpenPage(dbToUpdate, change.PageId);
                                                Page pageToRead   = sessionToRead.OpenPage(dbToRead, change.PageId);
                                                if (pageToRead == null) // upcoming (not yet processed) changes must have deleted this page
                                                {
                                                    continue;
                                                }
                                                currentVersion    = pageToUpdate == null ? 0 : pageToUpdate.PageInfo.VersionNumber;
                                                pageToReadVersion = pageToRead.PageInfo.VersionNumber;
                                                if (currentVersion < pageToReadVersion || dbToUpdate.IsNew)
                                                {
                                                    sessionToUpdate.ReplacePage(dbToUpdate, pageToUpdate, pageToRead);
                                                }
                                                else
                                                {
                                                    conflictFound = true;
                                                    if (doUpdate(sessionToUpdate, currentVersion, change))
                                                    {
                                                        sessionToUpdate.ReplacePage(dbToUpdate, pageToUpdate, pageToRead);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            UInt64 lastTransactionNumber = changes.ChangeList.Last().TransactionNumber;
                            if (matchingReplicaSync != null)
                            {
                                matchingReplicaSync.TransactionNumber = lastTransactionNumber;
                            }
                            if (conflictFound)
                            {
                                sessionToUpdate.Verify();
                            }
                            sessionToUpdate.Commit();
                            if (matchingReplicaSync == null)
                            {
                                sessionToUpdate.BeginUpdate(); // separate transaction or else gets confused with databases added by sync
                                matchingReplicaSync = new ReplicaSync(sessionToRead, lastTransactionNumber);
                                sessionToUpdate.Persist(matchingReplicaSync);
                                sessionToUpdate.Commit();
                            }
                        }
                    }
                }
            }
        }
Beispiel #17
0
        public void IndexSample(bool useServerSession)
        {
            string           brandName              = "Toyota";
            string           color                  = "Blue";
            int              maxPassengers          = 5;
            int              fuelCapacity           = 40;
            double           litresPer100Kilometers = 5;
            DateTime         modelYear              = new DateTime(2003, 1, 1);
            string           modelName              = "Highlander";
            int              maxSpeed               = 200;
            int              odometer               = 100000;
            string           registrationState      = "Texas";
            string           registrationPlate      = "TX343434";
            string           insurancePolicy        = "CAA7878787";
            DriversLicense   license                = new DriversLicense("California", "B7788888", DateTime.Now + new TimeSpan(1825, 0, 0, 0));
            Person           person                 = new Person("Mats Persson", license);
            InsuranceCompany insuranceCompany       = new InsuranceCompany("Allstate", "858727878");
            Car              car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, maxSpeed,
                                           odometer, registrationState, registrationPlate, insuranceCompany, insurancePolicy);

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                foreach (Database db in session.OpenAllDatabases(true))
                {
                    if (db.DatabaseNumber >= 10 || db.DatabaseNumber == SessionBase.IndexDescriptorDatabaseNumber)
                    {
                        session.DeleteDatabase(db);
                    }
                }
                session.Commit();

                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();
                CreateDirectoryAndCopyLicenseDb();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginRead();
                int ct     = 0;
                var mIndex = session.Index <Motorcycle>();
                if (mIndex != null)
                {
                    foreach (Motorcycle mc in session.Index <Motorcycle>())
                    {
                        Assert.NotNull(mc);
                        ++ct;
                    }
                }
                Assert.AreEqual(ct, 0);
                session.Commit();
            }
            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                for (int i = 0; i < 10000; i++)
                {
                    Motorcycle mc = new Motorcycle();
                    session.Persist(mc);
                }
                session.Commit();
                session.BeginUpdate();
                int ct     = 0;
                var mIndex = session.Index <Car>();
                if (mIndex != null)
                {
                    foreach (Car c in mIndex)
                    {
                        Assert.NotNull(c);
                        ++ct;
                    }
                }
                Assert.AreEqual(ct, 0);
                ct = 0;
                session.RegisterClass(typeof(Person));
                foreach (Person p in session.AllObjects <Person>(true, false))
                {
                    Assert.NotNull(p);
                    ++ct;
                }
                session.Commit();
                session.BeginRead();
                ct = 0;
                foreach (Motorcycle mc in session.AllObjects <Motorcycle>(false, true))
                {
                    Assert.NotNull(mc);
                    ++ct;
                }
                Assert.AreEqual(ct, 10000);
                session.Commit();
                session.BeginRead();
                ct = 0;
                foreach (Motorcycle mc in session.AllObjects <Motorcycle>(false, true))
                {
                    Assert.NotNull(mc);
                    ++ct;
                }
                Assert.AreEqual(ct, 10000);
                session.Abort();
                session.BeginRead();
                ct = 0;
                foreach (Motorcycle mc in session.AllObjects <Motorcycle>(false, true))
                {
                    Assert.NotNull(mc);
                    ++ct;
                }
                Assert.AreEqual(ct, 10000);
                session.Commit();
                session.BeginRead();
                ct = 0;
                foreach (Motorcycle mc in session.Index <Motorcycle>())
                {
                    Assert.NotNull(mc);
                    ++ct;
                }
                Assert.AreEqual(ct, 10000);
                session.Abort();
                session.BeginRead();
                ct = 0;
                foreach (Motorcycle mc in session.Index <Motorcycle>())
                {
                    Assert.NotNull(mc);
                    ++ct;
                }
                Assert.AreEqual(ct, 10000);
                session.Commit();
                try
                {
                    ct = 0;
                    foreach (Motorcycle mc in session.Index <Motorcycle>())
                    {
                        Assert.NotNull(mc);
                        ++ct;
                    }
                    Assert.AreEqual(ct, 10000);
                }
                catch (NotInTransactionException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                session.BeginUpdate();
                ct = 0;
                foreach (Motorcycle mc in session.AllObjects <Motorcycle>(false, true))
                {
                    if (++ct % 2 == 0)
                    {
                        mc.Unpersist(session);
                    }
                }
                ct = 0;
                foreach (Motorcycle mc in session.Index <Motorcycle>())
                {
                    ++ct;
                }
                Assert.AreEqual(ct, 5000);
                session.Abort();
                session.BeginUpdate();
                ct = 0;
                foreach (Motorcycle mc in session.AllObjects <Motorcycle>(false, true))
                {
                    if (++ct % 2 == 0)
                    {
                        mc.Unpersist(session);
                    }
                }
                ct = 0;
                foreach (Motorcycle mc in session.Index <Motorcycle>())
                {
                    Assert.NotNull(mc);
                    ++ct;
                }
                Assert.AreEqual(ct, 5000);
                ct = 0;
                foreach (Motorcycle mc in session.Index <Motorcycle>("cc"))
                {
                    Assert.NotNull(mc);
                    ++ct;
                }
                Assert.AreEqual(ct, 5000);
                ct = 0;
                try
                {
                    foreach (Motorcycle mc in session.Index <Motorcycle>("ccx"))
                    {
                        Assert.NotNull(mc);
                        ++ct;
                    }
                    Assert.AreEqual(ct, 5000);
                }
                catch (FieldDoesNotExistException)
                {
                }
                session.Commit();
                session.BeginUpdate();
                ct = 0;
                double prior = -44.0;
                foreach (Motorcycle mc in session.Index <Motorcycle>("cc"))
                {
                    Assert.NotNull(mc);
                    mc.CC = mc.CC - prior;
                    prior = mc.CC;
                    ++ct;
                }
                Assert.AreEqual(ct, 2500);
                for (int i = 0; i < 95000; i++)
                {
                    Motorcycle mc = new Motorcycle();
                    session.Persist(mc);
                }
                session.FlushUpdates();
                ct = 0;
                foreach (Motorcycle mc in session.Index <Motorcycle>())
                {
                    Assert.NotNull(mc);
                    ++ct;
                }
                Assert.AreEqual(ct, 100000);
                session.Abort();
                session.BeginUpdate();
                ct    = 0;
                prior = double.MinValue;
                foreach (Motorcycle mc in session.Index <Motorcycle>("cc"))
                {
                    Assert.NotNull(mc);
                    Assert.GreaterOrEqual(mc.CC, prior);
                    prior = mc.CC;
                    ++ct;
                    if (ct < 25)
                    {
                        Console.Write(prior.ToString() + " ");
                    }
                }
                ct    = 0;
                prior = -44.0;
                foreach (Motorcycle mc in session.Index <Motorcycle>("cc"))
                {
                    Assert.NotNull(mc);
                    mc.CC = mc.CC - prior;
                    prior = mc.CC;
                    ++ct;
                }
                Assert.AreEqual(ct, 2500);
                session.Commit();
                session.BeginUpdate();
                ct    = 0;
                prior = double.MinValue;
                foreach (Motorcycle mc in session.Index <Motorcycle>("cc"))
                {
                    Assert.NotNull(mc);
                    Assert.GreaterOrEqual(mc.CC, prior);
                    prior = mc.CC;
                    ++ct;
                }
                for (int i = 0; i < 95000; i++)
                {
                    Motorcycle mc = new Motorcycle();
                    session.Persist(mc);
                    DataBaseFileEntry dbEntry = new DataBaseFileEntry {
                        Something = "Something"
                    };
                    session.Persist(dbEntry);
                    mc.AddChild(dbEntry);
                    mc.AddChild(dbEntry);
                }
                session.FlushUpdates();
                ct = 0;
                foreach (Motorcycle mc in session.Index <Motorcycle>())
                {
                    Assert.NotNull(mc);
                    ++ct;
                }
                Assert.AreEqual(ct, 100000);
                session.Commit();
                session.BeginRead();
                session.Abort();
                session.BeginUpdate();
                foreach (Motorcycle mc in session.Index <Motorcycle>())
                {
                    Assert.NotNull(mc);
                    VelocityDbList <DataBaseFileEntry> children = mc.Children;
                    if (children != null && children.Count > 0)
                    {
                        mc.RemoveChild(children[0]);
                    }
                    ++ct;
                }
                session.Commit();
                session.BeginRead();
                ct    = 0;
                prior = double.MinValue;
                foreach (Motorcycle mc in session.Index <Motorcycle>("cc"))
                {
                    Assert.NotNull(mc);
                    Assert.GreaterOrEqual(mc.CC, prior);
                    prior = mc.CC;
                    ++ct;
                }
                Assert.AreEqual(ct, 100000);
                session.Commit();
                Console.WriteLine("Motorcycle index Test OK");
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                session.Persist(car);
                registrationState = "Maine";
                car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, maxSpeed,
                              odometer, registrationState, registrationPlate, insuranceCompany, insurancePolicy);
                session.Persist(car);
                color                  = "Red";
                maxPassengers          = 5;
                fuelCapacity           = 50;
                litresPer100Kilometers = 8;
                modelYear              = new DateTime(2006, 1, 1);
                brandName              = "Toyota";
                modelName              = "Tacoma";
                maxSpeed               = 210;
                odometer               = 50000;
                registrationState      = "Texas";
                registrationPlate      = "TX343433";
                insurancePolicy        = "CAA7878777";
                car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, maxSpeed,
                              odometer, registrationState, registrationPlate, insuranceCompany, insurancePolicy);
                session.Persist(car);
                color                  = "Black";
                maxPassengers          = 5;
                fuelCapacity           = 60;
                litresPer100Kilometers = 3;
                modelYear              = new DateTime(2001, 1, 1);
                brandName              = "Lincoln";
                modelName              = "Town Car";
                maxSpeed               = 220;
                odometer               = 250000;
                registrationState      = "Texas";
                registrationPlate      = "TX543433";
                insurancePolicy        = "CAA7878775";
                for (int i = 0; i < 1; i++)
                {
                    registrationState = RandomString(2);
                    registrationPlate = RandomString(12);
                    car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, maxSpeed, odometer, registrationState, registrationPlate, insuranceCompany, insurancePolicy);
                    session.Persist(car);
                    color                  = null;
                    maxPassengers          = i;
                    fuelCapacity           = 60;
                    litresPer100Kilometers = 3;
                    modelYear              = new DateTime(2001, 1, 1);
                    brandName              = "Null Car";
                    modelName              = null;
                    maxSpeed               = 220;
                    odometer               = 250000;
                    insurancePolicy        = null;
                }
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginRead();
                Console.WriteLine("Blue Cars");
                BTreeSet <Car> bTree = session.Index <Car>("color");
                foreach (Car c in (from aCar in bTree where aCar.Color == "Blue" select aCar))
                {
                    Console.WriteLine(c.ToStringDetails(session));
                }
                Console.WriteLine("Cars in fuel efficierncy order");
                foreach (Car c in session.Index <Car>("litresPer100Kilometers"))
                {
                    Console.WriteLine(c.ToStringDetails(session));
                }
                Console.WriteLine("Vehicles ordered modelYear, brandName, modelName, color");
                foreach (Vehicle v in session.Index <Vehicle>())
                {
                    Console.WriteLine(v.ToStringDetails(session));
                }
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                // these LINQ statements will trigger a binary search lookup (not a linear serach) of the matching Car objects in the BTreeSet
                Car c = (from aCar in session.Index <Car>("color") where aCar.Color == "Blue" select aCar).First();
                c.Color = "Green";
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                // these LINQ statements will trigger a binary search lookup (not a linear serach) of the matching Car objects in the BTreeSet
                Car    c  = (from aCar in session.Index <Car>("color") where aCar.Color == "Green" select aCar).First();
                UInt64 id = c.Id;
                session.DeleteObject(id);
                session.Abort();
                session.BeginUpdate();
                session.DeleteObject(id);
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                session.BeginRead();
                // these LINQ statements will trigger a binary search lookup (not a linear serach) of the matching Car objects in the BTreeSet
                Console.WriteLine("Blue Cars");
                foreach (Car c in (from aCar in session.Index <Car>("color") where aCar.Color == "Blue" select aCar))
                {
                    Console.WriteLine(c.ToStringDetails(session));
                }
                session.Commit();
                sw.Stop();
                Console.WriteLine(sw.Elapsed);
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                for (int i = 0; i < 10000; i++)
                { // add some junk to make search harder
                    car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, i,
                                  odometer, registrationState, registrationPlate + i, insuranceCompany, insurancePolicy);
                    session.Persist(car);
                }
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginRead();
                // these LINQ statements will trigger a binary search lookup (not a linear serach) of the matching Car objects in the BTreeSet
                Console.WriteLine("Blue Cars");
                foreach (Car c in (from aCar in session.Index <Car>("color") where aCar.Color == "Blue" select aCar))
                {
                    Console.WriteLine(c.ToStringDetails(session));
                }
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                Car c = (from aCar in session.Index <Car>("color") where aCar.Color == "Blue" select aCar).First();
                c.Unpersist(session);
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginRead();
                foreach (Car c in session.Index <Car>())
                {
                    Console.WriteLine(c.ToStringDetails(session));
                }
                Console.WriteLine("Blue Cars");
                foreach (Car c in (from aCar in session.Index <Car>() where aCar.Color == "Blue" select aCar))
                {
                    Console.WriteLine(c.ToStringDetails(session));
                }
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                InsuranceCompany prior = insuranceCompany;
                try
                {
                    for (int i = 0; i < 100000; i++)
                    {
                        insuranceCompany = new InsuranceCompany("AAA", "858787878");
                        insuranceCompany.Persist(session, prior);
                        prior = insuranceCompany;
                    }
                    Assert.IsTrue(false); // should not get here
                }
                catch (UniqueConstraintException)
                {
                }
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginRead();
                Database db = session.OpenDatabase(session.DatabaseNumberOf(typeof(InsuranceCompany)));
                var      q  = from company in session.Index <InsuranceCompany>("name", db) where company.Name == "AAA" select company;
                foreach (InsuranceCompany company in q)
                {
                    Console.WriteLine(company.ToStringDetails(session)); // only one will match
                }
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                InsuranceCompany prior = insuranceCompany;
                try
                {
                    for (int i = 0; i < 100000; i++)
                    {
                        insuranceCompany = new InsuranceCompany("AAA", "858787878");
                        session.Persist(insuranceCompany);
                    }
                    Assert.IsTrue(false); // should not get here
                }
                catch (UniqueConstraintException)
                {
                }
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginRead();
                Database db = session.OpenDatabase(session.DatabaseNumberOf(typeof(InsuranceCompany)));
                var      q  = from company in session.Index <InsuranceCompany>("name", db) where company.Name == "AAA" select company;
                foreach (InsuranceCompany company in q)
                {
                    Console.WriteLine(company.ToStringDetails(session)); // only one will match
                }
                bool exists = (from anEntry in session.Index <InsuranceCompany>("name", db) where anEntry.Name == "AAA" select 0).Any();
                Assert.IsTrue(exists);
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                try
                {
                    for (int i = 0; i < 100000; i++)
                    {
                        insuranceCompany = new InsuranceCompanySpecial("AAA", "858787878");
                        session.Persist(insuranceCompany);
                    }
                    Assert.IsTrue(false); // should not get here
                }
                catch (UniqueConstraintException)
                {
                }
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                try
                {
                    for (int i = 0; i < 100000; i++)
                    {
                        insuranceCompany = new InsuranceCompanySpecial2("AAA", "858787878");
                        session.Persist(insuranceCompany);
                    }
                    Assert.IsTrue(false); // should not get here
                }
                catch (UniqueConstraintException)
                {
                }
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginRead();
                Database db = session.OpenDatabase(session.DatabaseNumberOf(typeof(InsuranceCompanySpecial)));
                var      q  = from company in session.Index <InsuranceCompany>("name", db) where company.Name == "AAA" select company;
                foreach (InsuranceCompany company in q)
                {
                    Console.WriteLine(company.ToStringDetails(session)); // only one will match
                }
                bool exists = (from anEntry in session.Index <InsuranceCompanySpecial>("name", db) where anEntry.Name == "AAA" select 0).Any();
                Assert.IsTrue(exists);
                session.Commit();
            }
        }
Beispiel #18
0
        public IDevice GetDevice(ulong?uid = null, ulong?ownerUid = null)
        {
            IEnumerable <Device> e;
            Predicate <Device>   p = x =>
                                     (uid == null || x.Uid == uid) &&
                                     (ownerUid == null || x.OwnerUid == ownerUid);

            if (uid != null)
            {
                e = _session.Index <Device>("_uid").Where(x => x.Uid == uid);
            }
            else if (ownerUid != null)
            {
                e = _session.Index <Device>("_ownerUid").Where(x => x.OwnerUid == ownerUid);
            }
            else
            {
                e = _session.AllObjects <Device>();
            }

            lock (_session)
            {
                return(e.Where(x => p(x)).SingleOrDefault());
            }
        }
 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;
   }
 }
Beispiel #20
0
        public void sessionPoolTest()
        {
            const int numberOfSessions = 5;

            using (SessionPool pool = new SessionPool(numberOfSessions, () => new SessionNoServer(systemDir)))
            {
                {
                    int         sessionId = -1;
                    SessionBase session   = null;
                    try
                    {
                        session = pool.GetSession(out sessionId);
                        using (SessionBase.Transaction transaction = session.BeginUpdate())
                        {
                            for (int i = 0; i < 1000; i++)
                            {
                                Man man = new Man();
                                session.Persist(man);
                            }
                            session.Commit();
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        throw e;
                    }
                    finally
                    {
                        pool.FreeSession(sessionId, session);
                    }
                }

                Parallel.ForEach(Enumerable.Range(0, numberOfSessions * 5),
                                 x =>
                {
                    int sessionId       = -1;
                    SessionBase session = null;
                    try
                    {
                        session = pool.GetSession(out sessionId);
                        if (session.InTransaction == false)
                        {
                            session.BeginRead();
                        }
                        var allMen     = session.AllObjects <Man>();
                        ulong allMenCt = allMen.Count();
                        foreach (Man man in allMen)
                        {
                            double lat = man.Latitude;
                        }
                        Console.WriteLine("Man Count is: " + allMenCt + " Session Id is: " + sessionId + " Current task id is: " + (Task.CurrentId.HasValue ? Task.CurrentId.Value.ToString() : "unknown"));
                    }
                    catch (Exception e)
                    {
                        session?.Abort();
                        Console.WriteLine(e.Message);
                        throw e;
                    }
                    finally
                    {
                        pool.FreeSession(sessionId, session);
                    }
                });
            }
        }
 void Initialize()
 {
     SessionBase.BaseDatabasePath = Properties.Settings.Default.BaseDatabasePath;
     m_session = new SessionNoServer(Properties.Settings.Default.DatabaseManagerDirectory);
     try
     {
         m_session.BeginUpdate();
         List <FederationSchemaViewModel> federationInfos         = new List <FederationSchemaViewModel>();
         List <FederationInfo>            federationInfosToRemove = new List <FederationInfo>();
         foreach (FederationInfo info in m_session.AllObjects <FederationInfo>())
         {
             try
             {
                 federationInfos.Add(new FederationSchemaViewModel(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 FederationSchemaViewModel(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();
         }
     }
 }