Ejemplo n.º 1
0
 public void Dispose()
 {
     if (_engine != null)
     {
         _engine.Dispose();
     }
 }
Ejemplo n.º 2
0
 public void Execute(ref LiteEngine db, StringScanner s, Display display)
 {
     if (db != null)
     {
         db.Dispose();
         db = null;
     }
 }
Ejemplo n.º 3
0
 public void Execute(LiteEngine engine, StringScanner s, Display display, InputCommand input, Env env)
 {
     if (engine != null)
     {
         engine.Dispose();
     }
     input.Running = false;
 }
Ejemplo n.º 4
0
 public void Close()
 {
     if (_engine != null)
     {
         _engine.Dispose();
         _engine = null;
     }
 }
Ejemplo n.º 5
0
        public void Execute(ref LiteEngine db, StringScanner s, Display display)
        {
            if (db != null)
            {
                db.Dispose();
            }

            db = new LiteEngine(s.Scan(".*"));
        }
Ejemplo n.º 6
0
 public void Dispose()
 {
     _db.Dispose();
 }
Ejemplo n.º 7
0
 public void Dispose()
 {
     _db.Dispose();
     File.Delete(_filename);
 }
Ejemplo n.º 8
0
 public void Execute(LiteEngine db, StringScanner s, Display display)
 {
     db.Dispose();
 }
Ejemplo n.º 9
0
Archivo: Quit.cs Proyecto: apkd/LiteDB
 public void Execute(LiteEngine engine, StringScanner s, Display display, InputCommand input, Env env)
 {
     if(engine != null) engine.Dispose();
     input.Running = false;
 }
Ejemplo n.º 10
0
        //[TestMethod]
        public void Stress_Test()
        {
            // The most important test:
            // - Create 3 task read/write operations in same file.
            // - Insert, update, delete same documents
            // - Insert big files
            // - Delete all documents
            // - Insert a big file (use all pages)
            // - Read this big file and test md5
            var file = DB.Path(true, "stress.db");
            var rnd  = new Random(DateTime.Now.Second);
            var N    = 100;

            var a = new LiteEngine(file);
            var b = new LiteEngine(file);
            var c = new LiteEngine(file);
            var d = new LiteEngine(file);

            // Task A -> Insert 100 documents
            var ta = Task.Factory.StartNew(() =>
            {
                var col = a.GetCollection("col1");
                for (var i = 1; i <= N; i++)
                {
                    col.Insert(CreateDoc(i, "My String Guided " + Guid.NewGuid().ToString("n")));
                }
            });

            // Task B -> Update 100 documents
            var tb = Task.Factory.StartNew(() =>
            {
                var col = b.GetCollection("col1");
                var i   = 1;

                while (i < N)
                {
                    //Task.Delay(rnd.Next(100, 500));
                    var success = col.Update(CreateDoc(i, "update value"));
                    if (success)
                    {
                        i++;
                    }
                }
            });

            //// TasK C -> Delete 99 documents (keep only _id = 1)
            //var tc = Task.Factory.StartNew(() =>
            //{
            //    var col = c.GetCollection("col1");
            //    var i = 2;

            //    while (i < N)
            //    {
            //        Task.Delay(rnd.Next(100, 500));
            //        var success = col.Delete(i);
            //        if (success) i++;
            //    }
            //});

            // Task D -> Upload 20 files

            // Now, test data
            Task.WaitAll(ta, tb); //, tb, tc);

            using (var db = new LiteEngine(file))
            {
                var col = db.GetCollection("col1");
                Assert.AreEqual(1, col.Count());
                var doc = col.FindById(1);
                Assert.AreEqual("update value", doc["Name"].AsString);
            }


            a.Dispose();
            b.Dispose();
            c.Dispose();
        }
Ejemplo n.º 11
0
        public static void Start(InputCommand input, Display display)
        {
            var commands = new List <ICommand>();
            var env      = new Env();

            LiteEngine engine = null;

            // register commands
            RegisterCommands(commands);

            display.TextWriters.Add(Console.Out);

            // show welcome message
            display.WriteWelcome();

            while (input.Running)
            {
                // read next command from user or queue
                var cmd = input.ReadCommand();

                if (string.IsNullOrEmpty(cmd))
                {
                    continue;
                }

                try
                {
                    var s = new StringScanner(cmd);

                    var found = false;

                    // test all commands
                    foreach (var command in commands)
                    {
                        if (!command.IsCommand(s))
                        {
                            continue;
                        }

                        // open datafile before execute
                        if (command.Access != DataAccess.None)
                        {
                            engine = env.CreateEngine(command.Access);
                        }

                        command.Execute(engine, s, display, input, env);

                        // close datafile to be always disconnected
                        if (engine != null)
                        {
                            engine.Dispose();
                            engine = null;
                        }

                        found = true;
                        break;
                    }

                    if (!found)
                    {
                        throw new ShellException("Command not found");
                    }
                }
                catch (Exception ex)
                {
                    display.WriteError(ex.Message);
                }
            }
        }