Exemple #1
0
        public IHttpActionResult Accion(int id, string accion)
        {
            using (Model.Context db = new Model.Context())
            {
                switch (accion)
                {
                case "iniciar":
                    CambiarEstado(id, Model.EstadoMonitorEnum.Iniciado, db);
                    break;

                case "detener":
                    CambiarEstado(id, Model.EstadoMonitorEnum.Detenido, db);
                    break;

                case "limpiar":
                    LimpiarLogs(id, db);
                    return(Ok(new List <SimpleMonitorDTO>()));

                default:
                    return(NotFound());
                }
            }

            return(Get());
        }
        public void TestBasicCRUD()
        {
            using (Model.Context db = new Model.Context("mdbConnectionString"))
            {
                Note n = new Note();
                n.Content = "Test content";
                n.Created = DateTime.UtcNow.Date;
                n.Modified = DateTime.UtcNow.Date;

                db.InsertOnSubmit<Note>(n);
                db.SubmitChanges();

                Assert.AreNotEqual(n.Codigo, 0);

                Note result = db.Connection.Query<Note>("SELECT * FROM Notes WHERE Codigo = @Id", new { Id = n.Codigo }).FirstOrDefault();
                Assert.AreNotEqual(result, null);
                Assert.AreEqual(result.Content, n.Content);
                Assert.AreEqual(result.Created, n.Created);
                Assert.AreEqual(result.Modified, n.Modified);

                db.DeleteOnSubmit<Note>(result);
                db.SubmitChanges();

                Assert.IsFalse(db.Connection.Query<Post>("SELECT * FROM Notes WHERE Codigo = @Id", new { Id = n.Codigo }).Any());
            }
        }
Exemple #3
0
 // GET: api/Monitor/5
 public Model.Monitor Get(int id)
 {
     using (Model.Context db = new Model.Context())
     {
         return(db.Monitors.FirstOrDefault(x => x.Id == id));
     }
 }
Exemple #4
0
        public IHttpActionResult Delete(int id)
        {
            using (Model.Context db = new Model.Context())
            {
                Eliminar(id, db);
            }

            return(Get());
        }
        public static bool IsConfigurado()
        {
            var lista = new List <string>();
            var db    = new Model.Context();

            Model.ConfiguraçõesBanco b = BuscarConfig();
            lista.Add(b.timer.ToString());
            lista.Add(b.CaminhoEntradaUnimake);
            lista.Add(b.Saida);

            return(!lista.Any(string.IsNullOrWhiteSpace));
        }
Exemple #6
0
        public void TestFind()
        {
            using (Model.Context db = new Model.Context("mdbConnectionString"))
            {
                Post p = new Post();
                p.Content = "Dummy post";

                db.InsertOnSubmit <Post>(p);
                db.SubmitChanges();

                Post found = db.Find <Post>(x => { return(x.Content == "Dummy post"); }).FirstOrDefault();

                Assert.AreNotEqual(found, null);
                Assert.AreEqual(found.Content, p.Content);
                Assert.IsTrue(found.Id > 0);
            }
        }
Exemple #7
0
        // GET: api/Monitor
        public IHttpActionResult Get()
        {
            List <SimpleMonitorDTO> listaMonitor = new List <SimpleMonitorDTO>();

            using (Context db = new Model.Context())
            {
                var monitores = db.Monitors.ToList();
                foreach (var mon in monitores)
                {
                    var dto = Mapper.Map <SimpleMonitorDTO>(mon);

                    /*var ultimo = db.MonitorLogs.Where(m => m.Monitor.Id == mon.Id).OrderByDescending(m => m.Fecha).ToList().FirstOrDefault();
                     *
                     * if (ultimo != null)
                     *  dto.UltimaEjecucion = string.Format("{0:dd/MM/yyyy HH:mm:ss} - {1}", ultimo.Fecha, ultimo.Resultado);
                     */
                    listaMonitor.Add(dto);
                }
            }

            return(Ok(listaMonitor));
        }
Exemple #8
0
        public void TestChainedInsertUsingCollection()
        {
            using (Model.Context db = new Model.Context("mdbConnectionString"))
            {
                Post p = new Post();
                p.Content = "Test content 'n' escapes!";

                Author a = new Author();
                a.Username = "******";
                a.Posts    = new List <Post>();
                a.Posts.Add(p);

                int id = db.InsertOnSubmit <Author>(a);

                Assert.AreEqual(a.Id, id);
                Assert.AreEqual(a.Posts.First(), p);

                db.DeleteOnSubmit <Author>(a, Context.CascadeStyle.Collection); // force cascading delete

                db.SubmitChanges();
            }
        }
        public void TestChainedInsertSimple()
        {
            using (Model.Context db = new Model.Context("mdbConnectionString"))
            {
                Author a = new Author();
                a.Username = "******";

                Post p = new Post();
                p.Content = "Test content";
                p.Author = a;

                int id = db.InsertOnSubmit<Post>(p);

                Assert.AreEqual(id, p.Id);
                Assert.AreEqual(p.Author, a);
                Assert.AreNotEqual(p.Author.Id, 0);

                db.DeleteOnSubmit<Post>(p, Context.CascadeStyle.Single); // force cascading delete

                db.SubmitChanges();
            }
        }
Exemple #10
0
        public static void EjecutarTarea(int monitorId)
        {
            Model.Monitor monitor = null;

            using (var db = new Model.Context())
            {
                monitor = db.Monitors.FirstOrDefault(x => x.Id == monitorId);

                if (monitor.Estado == EstadoMonitorEnum.Detenido)
                {
                    return;
                }

                if (_tests.ContainsKey(monitor.Tipo))
                {
                    var monitorLog = _tests[monitor.Tipo].Ejecutar(monitor);
                    monitorLog.Monitor = monitor;
                    db.MonitorLogs.Add(monitorLog);
                    db.SaveChanges();
                }
            }
        }
        public void TestChainedInsertUsingCollection()
        {
            using (Model.Context db = new Model.Context("mdbConnectionString"))
            {
                Post p = new Post();
                p.Content = "Test content 'n' escapes!";

                Author a = new Author();
                a.Username = "******";
                a.Posts = new List<Post>();
                a.Posts.Add(p);

                int id = db.InsertOnSubmit<Author>(a);

                Assert.AreEqual(a.Id, id);
                Assert.AreEqual(a.Posts.First(), p);

                db.DeleteOnSubmit<Author>(a, Context.CascadeStyle.Collection); // force cascading delete

                db.SubmitChanges();
            }
        }
Exemple #12
0
        public void TestUpdateSingle()
        {
            using (Model.Context db = new Model.Context("mdbConnectionString"))
            {
                Author a = new Author();
                a.Username = "******";

                // Now let's use the inserted author
                Post p = new Post();
                p.Content = "Test";
                p.Author  = a;

                db.InsertOnSubmit <Post>(p);
                db.SubmitChanges();

                //db.UpdateOnSubmit<Post>(test);
                //db.SubmitChanges();

                //Author compare = db.Connection.Query<Author>("SELECT * FROM Authors WHERE Id = " + test.Author.Id).FirstOrDefault();
                //Assert.AreEqual(compare, test.Author);
            }
        }
Exemple #13
0
        public void TestChainedInsertSimple()
        {
            using (Model.Context db = new Model.Context("mdbConnectionString"))
            {
                Author a = new Author();
                a.Username = "******";

                Post p = new Post();
                p.Content = "Test content";
                p.Author  = a;

                int id = db.InsertOnSubmit <Post>(p);

                Assert.AreEqual(id, p.Id);
                Assert.AreEqual(p.Author, a);
                Assert.AreNotEqual(p.Author.Id, 0);

                db.DeleteOnSubmit <Post>(p, Context.CascadeStyle.Single); // force cascading delete

                db.SubmitChanges();
            }
        }
Exemple #14
0
        public void TestUpdateSimple()
        {
            using (Model.Context db = new Model.Context("mdbConnectionString"))
            {
                Note n = new Note();
                n.Content  = "Prueba";
                n.Created  = DateTime.UtcNow.Date;
                n.Modified = DateTime.UtcNow.Date;

                db.InsertOnSubmit <Note>(n);
                db.SubmitChanges();

                n.Content = "Test";
                db.UpdateOnSubmit <Note>(n);
                db.SubmitChanges();

                Note newNote = db.Connection.Query <Note>("SELECT * FROM Notes WHERE Codigo = " + n.Codigo).FirstOrDefault();

                Assert.AreEqual(newNote.Content, "Test");

                db.DeleteOnSubmit <Note>(newNote);
                db.SubmitChanges();
            }
        }
 public void TestConnection()
 {
     using (Model.Context db = new Model.Context("mdbConnectionString"))
     {
         Assert.AreNotEqual(db, null);
     }
 }
        public void TestUpdateCollection()
        {
            using (Model.Context db = new Model.Context("mdbConnectionString"))
            {
                Author a = new Author();
                a.Username = "******";
                a.Posts = new List<Post>();

                Post p = new Post();
                p.Content = "Test post content";

                Post pp = new Post();
                pp.Content = "Another test content";

                a.Posts.Add(p);
                a.Posts.Add(pp);

                db.InsertOnSubmit<Author>(a); // assume it works, tested on other methods
                db.SubmitChanges();

                a.Posts.First().Content = "Last content";
                db.UpdateOnSubmit<Author>(a, Context.CascadeStyle.All);
                db.SubmitChanges();

                Post compare = db.Connection.Query<Post>("SELECT * FROM Posts WHERE Id = " + a.Posts.First().Id).FirstOrDefault();

                Assert.AreEqual(compare.Content, a.Posts.First().Content);

                db.DeleteOnSubmit<Author>(a, Context.CascadeStyle.All);
                db.SubmitChanges();
            }
        }
        public void TestFind()
        {
            using (Model.Context db = new Model.Context("mdbConnectionString"))
            {
                Post p = new Post();
                p.Content = "Dummy post";

                db.InsertOnSubmit<Post>(p);
                db.SubmitChanges();

                Post found = db.Find<Post>(x => { return x.Content == "Dummy post"; }).FirstOrDefault();

                Assert.AreNotEqual(found, null);
                Assert.AreEqual(found.Content, p.Content);
                Assert.IsTrue(found.Id > 0);
            }
        }
Exemple #18
0
 public CategoryQuery(Context context)
 {
     _context = context;
 }
Exemple #19
0
        static void Main(string[] args)
        {
            var a = new Model.Context();

            a.Categories.ToList();
        }
Exemple #20
0
 public ProductQuery(Context context)
 {
     _context = context;
 }
Exemple #21
0
 public CommandCommand(Context context)
 {
     _context = context;
 }
        public void TestUpdateSimple()
        {
            using (Model.Context db = new Model.Context("mdbConnectionString"))
            {
                Note n = new Note();
                n.Content = "Prueba";
                n.Created = DateTime.UtcNow.Date;
                n.Modified = DateTime.UtcNow.Date;

                db.InsertOnSubmit<Note>(n);
                db.SubmitChanges();

                n.Content = "Test";
                db.UpdateOnSubmit<Note>(n);
                db.SubmitChanges();

                Note newNote = db.Connection.Query<Note>("SELECT * FROM Notes WHERE Codigo = " + n.Codigo).FirstOrDefault();

                Assert.AreEqual(newNote.Content, "Test");

                db.DeleteOnSubmit<Note>(newNote);
                db.SubmitChanges();
            }
        }
Exemple #23
0
 public ProductCommand(Context context)
 {
     _context = context;
 }
Exemple #24
0
 public CommandQuery(Context context)
 {
     _context = context;
 }
        public void TestUpdateSingle()
        {
            using (Model.Context db = new Model.Context("mdbConnectionString"))
            {
                Author a = new Author();
                a.Username = "******";

                // Now let's use the inserted author
                Post p = new Post();
                p.Content = "Test";
                p.Author = a;

                db.InsertOnSubmit<Post>(p);
                db.SubmitChanges();

                //db.UpdateOnSubmit<Post>(test);
                //db.SubmitChanges();

                //Author compare = db.Connection.Query<Author>("SELECT * FROM Authors WHERE Id = " + test.Author.Id).FirstOrDefault();
                //Assert.AreEqual(compare, test.Author);
            }
        }
Exemple #26
0
 private void CambiarEstado(int id, Model.EstadoMonitorEnum estado, Model.Context db)
 {
     db.Monitors.First(x => x.Id == id).Estado = estado;
     db.SaveChanges();
 }
Exemple #27
0
 private BusinessManager()
 {
     AppDomain.CurrentDomain.SetData("DataDirectory", AppDomain.CurrentDomain.BaseDirectory);
     context = new Context();
 }