Пример #1
0
        private static void comandoAlmacenSetInventario(string uuid, string msg, DBStorage db, bool searchByMinecraftId)
        {
            // articulo@cantidad@oreName;articulo@cantidad@oreName;articulo@cantidad@oreName...
            string[] data = msg.Split(';');
            List <AlmacenInventarioSet> setInventario = new List <AlmacenInventarioSet>();

            foreach (string slot in data)
            {
                string[] slotInfo = slot.Split('@');
                if (slotInfo.Length == 3)
                {
                    short cantidad = Int16.Parse(slotInfo[1]);
                    if (slotInfo[0].Length == 0 || cantidad < 0)
                    {
                        continue;
                    }
                    try
                    {
                        setInventario.Add(new AlmacenInventarioSet(slotInfo[0], cantidad, slotInfo[2]));
                    }
                    catch (Exception) { }
                }
            }

            if (searchByMinecraftId)
            {
                // this is a chest, and not an ME network, so the items are in stacks that repeat, por example,
                // one slot with 64 cobblestone and another stack with 32, not a single stack with 96 as an ME network would send
                reducirStacks(setInventario);
            }

            db.setInventarioAlmacen(db.getAlmacenId(Guid.Parse(uuid)), setInventario, searchByMinecraftId);
        }
Пример #2
0
        private static void comandoDroneInventario(string uuid, string msg, DBStorage db)
        {
            // articulo:cantidad;articulo:cantidad;articulo:cantidad...
            string[] data = msg.Split(';');
            List <DroneInventarioSet> setInventario = new List <DroneInventarioSet>();

            foreach (string slot in data)
            {
                string[] slotInfo = slot.Split('@');
                if (slotInfo.Length == 3)
                {
                    short cantidad = Int16.Parse(slotInfo[1]);
                    if (slotInfo[0].Length == 0 || cantidad < 0)
                    {
                        continue;
                    }
                    try
                    {
                        setInventario.Add(new DroneInventarioSet(slotInfo[0], cantidad, slotInfo[2]));
                    }
                    catch (Exception) { }
                }
            }

            db.setDroneInventario(Guid.Parse(uuid), setInventario);
        }
Пример #3
0
        private static string addOrdenesMinado(DBStorage db, string message)
        {
            List <OrdenMinado> ordenes;

            try
            {
                ordenes = (List <OrdenMinado>)JsonConvert.DeserializeObject(message, typeof(List <OrdenMinado>));
            }
            catch (Exception) { return("ERR"); }
            foreach (OrdenMinado orden in ordenes)
            {
                if (orden == null)
                {
                    return("ERR");
                }

                orden.descripcion    = string.Empty;
                orden.unidadRecarga  = '%';
                orden.energiaRecarga = 10;
                orden.chestSide      = '1';

                if (!orden.isValid())
                {
                    return("ERR");
                }
            }

            return(db.addOrdenesDeMinado(ordenes) ? "OK" : "ERR");
        }
Пример #4
0
        private static void comandoOrdenMinadoInventario(string uuid, string msg, DBStorage db)
        {
            // articulo@cantidad@oreName;articulo@cantidad@oreName;articulo@cantidad@oreName...
            string[] data = msg.Split(';');
            List <OrdenMinadoInventarioSet> setInventario = new List <OrdenMinadoInventarioSet>();

            foreach (string slot in data)
            {
                string[] slotInfo = slot.Split('@');
                if (slotInfo.Length == 3)
                {
                    try
                    {
                        short cantidad = Int16.Parse(slotInfo[1]);
                        if (cantidad == 0)
                        {
                            continue;
                        }
                        setInventario.Add(new OrdenMinadoInventarioSet(slotInfo[0], cantidad, slotInfo[2]));
                    }
                    catch (Exception) { }
                }
            }

            db.setOrdenMinadoInventario(Guid.Parse(uuid), setInventario);
        }
Пример #5
0
        // API KEY

        public static string apiKeyCommand(DBStorage db, string command, string message)
        {
            switch (command)
            {
            case "get":
            {
                return(getApiKeys(db));
            }

            case "add":
            {
                return(addApiKeys(db, message));
            }

            case "reset":
            {
                return(resetApiKey(db, message));
            }

            case "delete":
            {
                return(deleteApiKey(db, message));
            }
            }

            return("ERR");
        }
Пример #6
0
        /* FABRICACIÓN */

        private static void comandoGetOrdenesFabricacion(string uuid, DBStorage db, TcpClient server)
        {
            Fabricacion fabricacion = db.getFabricacion(Guid.Parse(uuid));

            if (fabricacion == null)
            {
                return;
            }

            OrdenFabricacion ordenFabricacion = db.getNextOrdenFabricacion(fabricacion.idAlmacen, fabricacion.id);

            if (ordenFabricacion == null)
            {
                enviarMensaje(server, "MSG$$" + uuid + "&&IDLE");
                return;
            }

            if (fabricacion.tipo == 'R')
            {
                robotGetOrdenesFabricacion(uuid, db, server, fabricacion, ordenFabricacion);
            }
            else if (fabricacion.tipo == 'A')
            {
                meGetOrdenesFabricacion(db, ordenFabricacion, uuid, server);
            }
        }
Пример #7
0
        // ÓRDENES DE MINADO

        private static void comandoOrdenMinado(TcpClient client, string uuid, DBStorage db)
        {
            OrdenMinado orden = db.getRobotOrdenMinado(Guid.Parse(uuid));

            if (orden == null)
            {
                enviarMensaje(client, "IDLE");
                return;
            }
            short energiaRecarga;

            if (orden.unidadRecarga == '=') // la energía en la que el robot parará a recargar está en valor absoluto
            {
                energiaRecarga = orden.energiaRecarga;
            }
            else if (orden.unidadRecarga == '%') // la energía en la que el robot parará a recargar está en porcentaje. calcular en base a la energía total del robot
            {
                energiaRecarga = (short)((db.getRobot(Guid.Parse(uuid)).totalEnergia / ((short)100)) * orden.energiaRecarga);
            }
            else
            {
                return;
            }

            string str = "MSG$$" + uuid + "&&" + orden.size + ";" + orden.posX + ";" + orden.posY + ";" + orden.posZ + ";" + orden.facing + ";"
                         + orden.gpsX + ";" + orden.gpsY + ";" + orden.gpsZ + ";" + energiaRecarga + ";" + orden.modoMinado + ";" + (orden.shutdown ? 1 : 0)
                         + ";" + orden.chestSide;

            enviarMensaje(client, str);
        }
Пример #8
0
        // SERVERS

        public static string serverCommand(DBStorage db, string command, string message)
        {
            switch (command)
            {
            case "get":
            {
                return(getServers(db));
            }

            case "add":
            {
                return(addServer(db, message));
            }

            case "update":
            {
                return(updateServer(db, message));
            }

            case "delete":
            {
                return(deleteServer(db, message));
            }

            case "pwd":
            {
                return(changePwdServer(db, message));
            }
            }

            return("ERR");
        }
Пример #9
0
 public ServerController(TcpClient server)
 {
     this.server   = server;
     this.robots   = new List <DeviceController>();
     this.db       = new DBStorage(Program.config);
     this.lastPong = DateTime.Now;
 }
Пример #10
0
        private static string passwordUsuario(DBStorage db, string message)
        {
            UsuarioPwd usuario;

            try
            {
                usuario = (UsuarioPwd)JsonConvert.DeserializeObject(message, typeof(UsuarioPwd));
            }
            catch (Exception e) { Console.WriteLine(e); return("ERR"); }
            if (usuario == null || !usuario.isValid())
            {
                return("ERR");
            }

            Usuario usr = db.getUsuario(usuario.id);

            if (usr == null)
            {
                return("ERR");
            }

            bool loggedIn = Usuario.verifyHash(usr.pwd, (usr.salt + usuario.pwdActual), usr.iteraciones);

            if (!loggedIn)
            {
                return("ERR");
            }

            string salt = Usuario.generateSalt();
            string hash = Usuario.hash(salt + usuario.pwdNuevo, Program.ajuste.hashIteraciones);

            return(db.updateUsuario(usuario.id, hash, salt, Program.ajuste.hashIteraciones) ? "OK" : "ERR");
        }
        public static string movimientosAlmacenCommands(DBStorage db, string command, string message)
        {
            switch (command)
            {
            case "get":
            {
                return(getMovimientosAlmacen(db, message));
            }

            case "search":
            {
                return(searchMovimientosAlmacen(db, message));
            }

            case "add":
            {
                return(addMovimientoAlmacen(db, message));
            }

            case "update":
            {
                return(updateMovimientoAlmacen(db, message));
            }
            }

            return("ERR");
        }
Пример #12
0
        private void ItemReturnClick(object sender, EventArgs e)
        {
            ServiceItem serviceItem = new ServiceItem();
            CloseItem   closeItem   = new CloseItem();

            serviceItem.IdServiceItem = _reestrForm.IDServiceItem;
            DBStorage   db   = new DBStorage();
            ServiceItem test = db.ServiceItems.Where(p => p.IdServiceItem == _reestrForm.IDServiceItem).First();

            serviceItem.IdSpecification = test.IdSpecification;
            serviceItem.NameServiceItem = test.NameServiceItem;
            serviceItem.FinishDate      = test.FinishDate.Date;
            serviceItem.StartSate       = test.StartSate.Date;
            serviceItem.Total           = test.Total + test.Price;
            serviceItem.Price           = test.Price;
            serviceItem.Coun            = test.Coun + 1;
            UnitOfWork.RepositoryServiceItem.Update(serviceItem);
            closeItem.CloseDate      = _reestrForm.CloseDate;
            closeItem.PerformanceSum = _reestrForm.PerformanceSum;
            closeItem.IdWorker       = _reestrForm.IDWorker;
            closeItem.IdServiceItem  = _reestrForm.IDServiceItem;
            closeItem.IdCloseItem    = _reestrForm.IDCloseItem;
            UnitOfWork.RepositoryCloseItem.Delete(closeItem);
            _reestrForm.CloseItems = UnitOfWork.RepositoryCloseItem.GetAll();
            _reestrForm.AllSum     = UnitOfWork.RepositoryCloseItem.SummCloseItem(_reestrForm.StartD, _reestrForm.FinishD);
            MessageBox.Show("Задача возвращена");
            main.ServiceItems = null;
            main.ServiceItems = UnitOfWork.RepositoryServiceItem.GetAll();
            _reestrForm.Close();
        }
Пример #13
0
        static void Main(string[] args)
        {
            Console.WriteLine("*** ERPCRAFT - Control your Minecraft world from the real world, anywhere, realtime. ***");
            Console.WriteLine("[[[ https://github.com/Itzanh/ERPCraft ]]]");
            Console.WriteLine("");
            config = Configuracion.readConfiguracion();
            db     = new DBStorage(config);
            // clean the database on start - allow the program to be called from a cron command to clean the DB
            if (args.Length > 0 && args[0].Equals("clean"))
            {
                ajuste = db.getAjuste();
                Console.WriteLine("CLEANING THE DATABASE FOLLOWING THE ACTIVE CONFIG...");
                db.limpiar();
                Console.WriteLine("OK!");
                return;
            }
            db.createDB();
            initDb();

            websocketPubSub = new PubSub(new string[] { "robots", "articulos", "articulosImg", "electrico", "generador", "bateria", "ordenMinado", "almacen", "drones", "usuarios", "config", "apiKeys", "servers", "notificaciones" });

            // admin management (web)
            Thread threadWS = new Thread(new ThreadStart(WaitForWebSocket.Run));

            threadWS.Start();

            // accept OC communication
            GameController.Run();
        }
Пример #14
0
 private static void comandoBateriaSet(string uuid, string msg, DBStorage db)
 {
     try
     {
         db.updateBateriaRedElectrica(Guid.Parse(uuid), Int64.Parse(msg));
     }
     catch (Exception) { return; }
 }
Пример #15
0
 private static string addApiKeys(DBStorage db, string message)
 {
     if (message.Length == 0)
     {
         return("ERR");
     }
     db.addApiKey(message);
     return("OK");
 }
Пример #16
0
        public DBStructureForm(String connectionString)
        {
            _storage = new DBStorage(connectionString);

            InitializeComponent();

            _categoriesList.DisplayMember = "Name";
            _scriptsList.DisplayMember    = "Name";
        }
Пример #17
0
        public static string droneCommands(DBStorage db, string command, string message)
        {
            switch (command)
            {
            case "get":
            {
                return(getDrones(db));
            }

            case "search":
            {
                return(searchDrones(db, message));
            }

            case "add":
            {
                return(addDrone(db, message));
            }

            case "update":
            {
                return(updateDrone(db, message));
            }

            case "delete":
            {
                return(deleteDrone(db, message));
            }

            case "getGPS":
            {
                return(getDroneGPS(db, message));
            }

            case "getInventario":
            {
                return(getDroneInventario(db, message));
            }

            case "getLog":
            {
                return(getDroneLogs(db, message));
            }

            case "clearLogs":
            {
                return(clearLogs(db, message));
            }

            case "clearLogsBetween":
            {
                return(clearLogsBetween(db, message));
            }
            }

            return("ERR");
        }
Пример #18
0
        private static void comandoDroneLog(string uuid, string msg, DBStorage db)
        {
            int separatorPos = msg.IndexOf("@@");

            if (separatorPos == -1)
            {
                return;
            }

            db.addDroneLog(Guid.Parse(uuid), new DroneLog(msg.Substring(0, separatorPos), msg.Substring(separatorPos + 2)));
        }
Пример #19
0
        private static void comandoRobBat(string uuid, string msg, DBStorage db)
        {
            int energiaActual;

            try
            {
                energiaActual = Int32.Parse(msg);
            }
            catch (Exception) { return; }

            db.updateRobotBateria(uuid, energiaActual);
        }
Пример #20
0
 private static void comandoDroneGps(string uuid, string msg, DBStorage db)
 {
     string[] data = msg.Split('@');
     if (data.Length == 3)
     {
         try
         {
             db.addDroneGps(Guid.Parse(uuid), Int16.Parse(data[0]), Int16.Parse(data[1]), Int16.Parse(data[2]));
         }
         catch (Exception) { return; }
     }
 }
Пример #21
0
        private static string deleteServer(DBStorage db, string message)
        {
            Guid guid;

            try
            {
                guid = Guid.Parse(message);
            }
            catch (Exception) { return("ERR"); }

            return(db.deleteServer(guid) ? "OK" : "ERR");
        }
Пример #22
0
        private static void comandoSetOrdenFabricacion(string uuid, DBStorage db, string msg)
        {
            Fabricacion fabricacion = db.getFabricacion(Guid.Parse(uuid));

            if (fabricacion == null)
            {
                return;
            }

            string[] data = msg.Split(';');
            if (data.Length != 3)
            {
                return;
            }

            int id;

            try
            {
                id = Int32.Parse(data[0]);
            }
            catch (Exception) { return; }
            if (id <= 0)
            {
                return;
            }

            if (data[1].Equals("OK"))
            {
                db.setResultadoOrdenFabricaicon(id, fabricacion.idAlmacen, fabricacion.id, true);
            }
            else if (data[1].Equals("ERR"))
            {
                short errorCode;
                try
                {
                    errorCode = Int16.Parse(data[2]);
                }
                catch (Exception) { return; }
                if (errorCode <= 0)
                {
                    return;
                }

                db.setResultadoOrdenFabricaicon(id, fabricacion.idAlmacen, fabricacion.id, false, errorCode);
            }
            else
            {
                return;
            }
        }
Пример #23
0
        private static void comandoOrdenMinadoUpdate(string uuid, string msg, DBStorage db)
        {
            string[] data = msg.Split(';');
            if (data.Length != 4)
            {
                return;
            }

            try
            {
                db.updateProgresoOrdenDeMinado(Guid.Parse(uuid), Int16.Parse(data[0]), Int16.Parse(data[1]), Int16.Parse(data[2]), Int16.Parse(data[3]));
            }
            catch (Exception) { return; }
        }
Пример #24
0
        /* RED ELECTRICA */

        private static void comandoBateriaInit(string uuid, string msg, DBStorage db)
        {
            string[] data = msg.Split('@');
            if (data.Length != 2)
            {
                return;
            }

            try
            {
                db.updateBateriaRedElectrica(Guid.Parse(uuid), Int64.Parse(data[0]), Int64.Parse(data[1]));
            }
            catch (Exception) { return; }
        }
Пример #25
0
        private static string deleteSmelting(DBStorage db, string message)
        {
            int id;

            try
            {
                id = Int32.Parse(message);
            }
            catch (Exception) { return("ERR"); }
            if (id <= 0)
            {
                return("ERR");
            }

            return(db.deleteSmelting(id) ? "OK" : "ERR");
        }
Пример #26
0
        private static string editSmelting(DBStorage db, string message)
        {
            Smelting smelting;

            try
            {
                smelting = (Smelting)JsonConvert.DeserializeObject(message, typeof(Smelting));
            }
            catch (Exception) { return("ERR"); }
            if (smelting == null || smelting.id <= 0 || !smelting.isValid())
            {
                return("ERR");
            }

            return(db.updateSmelting(smelting) ? "OK" : "ERR");
        }
Пример #27
0
        private static string editCraft(DBStorage db, string message)
        {
            Crafteo crafteo;

            try
            {
                crafteo = (Crafteo)JsonConvert.DeserializeObject(message, typeof(Crafteo));
            }
            catch (Exception) { return("ERR"); }
            if (crafteo == null || crafteo.id <= 0 || !crafteo.isValid())
            {
                return("ERR");
            }

            return(db.updateCrafteo(crafteo) ? "OK" : "ERR");
        }
Пример #28
0
        // CRAFTS

        private static string getCrafts(DBStorage db, string message)
        {
            CrafteoQuery query;

            try
            {
                query = (CrafteoQuery)JsonConvert.DeserializeObject(message, typeof(CrafteoQuery));
            }
            catch (Exception) { return("ERR"); }
            if (query == null || query.offset < 0 || query.limit <= 0)
            {
                return("ERR");
            }

            return(JsonConvert.SerializeObject(db.getCrafteos(query.offset, query.limit)));
        }
Пример #29
0
        private static string deleteArticulo(DBStorage db, string message)
        {
            short id;

            try
            {
                id = Int16.Parse(message);
            }
            catch (Exception) { return("ERR"); }
            if (id <= 0)
            {
                return("ERR");
            }

            return(db.deleteArticulo(id) ? "OK" : "ERR");
        }
Пример #30
0
        private static string editArticulos(DBStorage db, string message)
        {
            Articulo articulo;

            try
            {
                articulo = (Articulo)JsonConvert.DeserializeObject(message, typeof(Articulo));
            }
            catch (Exception) { return("ERR"); }
            if (articulo == null || articulo.id <= 0 || !articulo.isValid())
            {
                return("ERR");
            }

            return(db.updateArticulo(articulo) ? "OK" : "ERR");
        }
Пример #31
0
 /// <summary>
 /// Deletes itself from corresponding datatable
 /// Override this method in derived class to perform specific deletion logic
 /// </summary>
 public virtual void Delete()
 {
     Storage.Delete(this);
     this.Storage = null;
     this._bindedRow = null;
 }
Пример #32
0
        private void SetupStorage()
        {
            this.Storage = GetStorage(this.GetType());

            if (this.Storage == null)
            {
                Type thisRealType = this.GetType();
                this.Storage = InitStorage(thisRealType);
            }
        }