예제 #1
0
        public DBLayer()
        {
            // Get the platform object for the database
            IPlatform platform = new MarcelloDB.netfx.Platform();

            // Getting the Personal Special Folder. The database will go here.
            var dataPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

            // Creating a database session
            var session = new MarcelloDB.Session(platform, dataPath);

            // Getting a collections file. Each collection in the file is a database table
            var expensesFile = session["expenses.dat"];

            // getting the meta data (count of records) from the meta data file
            var expensesMetaDataFile = session["expensesMetaData.dat"];

            // Getting the expenses table and mapping how it will be given an ID (The expense time stamp)
            _expensesCollection = expensesFile.Collection <Expense, int>("expenses", e => e.ID);

            // Getting the meta data table
            _metaDataCollection = expensesMetaDataFile.Collection <MetaData, String>("metaData", e => e.Name);

            // does this table have an auto incrementing key?
            if (!DataBaseInitialized())
            {
                _expensesCount = new MetaData("expenses:count", 0);
                _metaDataCollection.Persist(_expensesCount);
            }
        }
예제 #2
0
        public static MarcelloDB.Session CreateSession()
        {
            var platform = new MarcelloDB.netfx.Platform();
            var session  = new MarcelloDB.Session(platform, @".");

            return(session);
        }
예제 #3
0
        public void Add_1000_ToFile()
        {
            EnsureFolder("data");
            var platform = new MarcelloDB.netfx.Platform();

            using (var session = new Session(platform, "./data/"))
            {
                var articles = session["data"].Collection <Article, int>("articles", a => a.ID);
                var ids      = new List <int>();
                for (int i = 1; i < 1000; i++)
                {
                    ids.Add(i);
                    var a = new Article {
                        ID = i, Name = "Article " + i.ToString()
                    };
                    articles.Persist(a);
                }

                for (int i = 1; i < 1000; i++)
                {
                    var a = articles.Find(i);
                    Assert.NotNull(a, "Article with ID: " + i.ToString() + " Should have been found");
                    Assert.AreEqual(i, a.ID, "Article " + i.ToString() + " Should have been found.");
                }

                var savedIds = articles.All.Select(a => a.ID);
                Assert.AreEqual(ids, savedIds);
            }
        }
예제 #4
0
        public static Session CreateSession()
        {
            var platform      = new MarcelloDB.netfx.Platform();
            var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); // Documents folder
            var libraryPath   = Path.Combine(documentsPath, "..", "Library");                  // Library folder
            var path          = Path.Combine(libraryPath, "DbFiles");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            return(new Session(platform, path));
        }
예제 #5
0
        public static Session CreateSession()
        {
            var    platform      = new MarcelloDB.netfx.Platform();
            string documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); // Documents folder

            var path = Path.Combine(documentsPath, "dbfiles");

            var directory = new DirectoryInfo(path);

            if (!directory.Exists)
            {
                directory.Create();
            }

            return(new Session(platform, path));
        }
예제 #6
0
        public TimeSpan Run()
        {
            Stopwatch w;
            var       dataPath = Path.Combine(Environment.CurrentDirectory, "data");

            EnsureFolder(dataPath);
            var platform = new MarcelloDB.netfx.Platform();

            using (var session = new Session(platform, dataPath))
            {
                this.Collection = session["data"].Collection <Person, int, PersonIndexes>("persons", p => p.ID);
                OnSetup();

                w = Stopwatch.StartNew();
                OnRun();
            }

            w.Stop();
            return(w.Elapsed);
        }
예제 #7
0
        public void Save_To_File_Stream()
        {
            EnsureFolder("data");
            var platform = new MarcelloDB.netfx.Platform();

            using (var session = new Session(platform, "./data/"))
            {
                var articles = session["data"].Collection <Article, int>("articles", a => a.ID);

                var toiletPaper  = Article.ToiletPaper;
                var spinalTapDvd = Article.SpinalTapDvd;
                var barbieDoll   = Article.BarbieDoll;

                articles.Persist(toiletPaper);
                articles.Persist(spinalTapDvd);
                articles.Persist(barbieDoll);

                var articleNames = articles.All.Select(a => a.Name).ToList();

                Assert.AreEqual(new List <string> {
                    toiletPaper.Name, spinalTapDvd.Name, barbieDoll.Name
                }, articleNames);
            }
        }