Beispiel #1
0
        public List <IDlo> GetData(DbTransaction transaction, int pageNumber = -1)
        {
            var ret = new List <IDlo>();

            SetSchemaTableIfNull();
            SetPrimaryKeyIfNull();

            using (DbCommand cmd = MRC.GetCommand(CNN))
            {
                cmd.CommandText = SqlGenerator.GetSql(Sql, Where, SqlGenerator.GetOrderByClause(OrderItems), pageNumber, PageSize);
                cmd.Transaction = transaction;

                using (DbDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var dlo = new Dlo();
                        for (int i = 0; i < reader.FieldCount; i++)
                        {
                            // CONSIDER - treba li poslusati best practices dbreadera (Stringove vracati s reader.GetString, decimali reader.GetDecimal, itd.) testirati performance profilerom
                            dlo.ColumnValues.Add(reader.GetName(i), reader.GetValue(i));
                        }
                        ret.Add(dlo);
                    }
                }
            }
            return(ret);
        }
Beispiel #2
0
        public FormMain()
        {
            InitializeComponent();

            MRC.GetInstance().ProviderName = Properties.Settings.Default.Provider;
            PersistingSettings.Instance.SqlGeneratorFactory = new Framework.Persisting.Implementation.SqlGeneratorFactory();

            TempConnect();
        }
Beispiel #3
0
        public void KeepAlive(AbstractTransport t, Destination address)
        {
            T.TRACE(0, "Solicitando keep alive.");
            var pdu = new PDU
            {
                CH          = (byte)Decoder.ComandoH.KeepAlive,
                DeviceId    = IdDispositivo,
                Transport   = t,
                Destination = address,
            };
            var keep_alive_mrc = new MRC(pdu, pdu.Transport, this);

            pdu.Transport.NuevaTransaccion(keep_alive_mrc, pdu);
            keep_alive_mrc.Seq = pdu.Seq;
            keep_alive_mrc.Start();
        }
Beispiel #4
0
        public void AutoReport(AbstractTransport t, Destination address, List <GPSPoint> puntos, int idQueue)
        {
            var req = new Posicion
            {
                DeviceId    = IdDispositivo,
                IdQueue     = idQueue,
                Transport   = t,
                Destination = address
            };

            req.AddPoints(puntos);
            var mrc = new MRC(req, t, this);

            // Seq: automatico aqui.
            t.NuevaTransaccion(mrc, req);
            mrc.Start();
        }
Beispiel #5
0
        public void LoginRequest(AbstractTransport t, Destination address, string IMEI, string password, short tableversion, string firmware)
        {
            var req = new LoginRequest
            {
                DeviceId     = IdDispositivo,
                IMEI         = IMEI,
                Password     = password,
                Firmware     = firmware,
                TableVersion = tableversion,
                Destination  = address
            };
            var mrc = new MRC(req, t, this);

            // Seq, automatico aqui.
            t.NuevaTransaccion(mrc, req);
            mrc.Start();
        }
Beispiel #6
0
        public void Command(short devid, Transporte t, byte tipo, byte[] datos)
        {
            var d = Devices.I().FindById(devid);

            if (d == null)
            {
                throw new NullReferenceException(String.Format("COMMAND: El dispositivo no existe dev_id={0}.", devid));
            }
            var req = new Command(tipo)
            {
                IdDispositivo = devid,
                Datos         = datos,
                Destino       = d.Destino
            };
            var mrc = new MRC(req, t, this);

            // Seq, automatico aqui.
            t.NuevaTransaccion(mrc, req);
            mrc.Start();
        }
Beispiel #7
0
 public void Connect(string connectionString)
 {
     MRC.GetInstance().ConnectionString = connectionString;
     try
     {
         using (DbConnection cnn = MRC.GetConnection())
         {
             cnn.Open();
             object test = null;
             using (IDbCommand cmd = MRC.GetCommand(cnn))
             {
                 cmd.CommandText = "SELECT Test = 1";
                 test            = cmd.ExecuteScalar();
             }
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Cannot connect to database.\n", ex);
     }
 }
Beispiel #8
0
        public void LoadCustomizers()
        {
            Customizers.Clear();

            List <IDlo> customizations = null;

            using (DbConnection cnn = MRC.GetConnection())
            {
                var p = new Persisters.DBCustomizationPersister();
                p.Where = "Active = 1";
                p.CNN   = MRC.GetConnection();
                p.CNN.Open();

                customizations = p.GetData(null);
            }
            var files = Directory.GetFiles(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "*.dll");

            foreach (string fileName in files)
            {
                var ass = Assembly.LoadFile(fileName);
                List <System.Type> types = new List <System.Type>();
                types.AddRange(ass.GetTypes());
                foreach (System.Type typ in types)
                {
                    var customizationAttrib = typ.GetCustomAttribute <Attributes.CustomizationAttribute>();
                    if (customizationAttrib != null && (customizations.Find(dlo => (string)dlo.ColumnValues["CustomizationKey"] == customizationAttrib.CustomizationKey)) != null)
                    {
                        Customizer customizer = (Customizer)System.Activator.CreateInstance(typ);
                        customizer.CustomizationKey = customizationAttrib.CustomizationKey;
                        Customizers.Add(customizer);

                        OnCustomizationLoaded(this, new CustomizationLoadedEventArgs()
                        {
                            Message = "Customizer loaded (CustomizationKey: " + customizationAttrib.CustomizationKey + ").", Customizer = customizer
                        });
                    }
                }
            }
        }
Beispiel #9
0
        public List <IDBModule> LoadModulesFromDB(DBTimeLiner dBTimeLiner)
        {
            //var ret = New List(Of IDBModule);
            var ret = new List <IDBModule>();

            using (DbConnection cnn = MRC.GetConnection())
            {
                try
                {
                    cnn.Open();

                    var per = new Persisters.DBModulePersister();
                    per.Where = "Active = 1";
                    per.CNN   = cnn;
                    List <IDlo> res = per.GetData(null);

                    foreach (IDlo module in res)
                    {
                        string errorMessage      = "";
                        string message           = "";
                        string className         = "";
                        string assemblyName      = "DBTimeLiners.DBModules";
                        string defaultSchemaName = "";
                        string description       = "";
                        try
                        {
                            className         = (string)module.ColumnValues["ClassName"];
                            defaultSchemaName = (string)module.ColumnValues["DefaultSchemaName"];
                            description       = (string)module.ColumnValues["Description"];

                            IDBModule m = (IDBModule)Activator.CreateInstance(assemblyName, assemblyName + "." + className).Unwrap();
                            m.DefaultSchemaName = defaultSchemaName;
                            m.Parent            = dBTimeLiner;

                            message = string.Format(
                                @"Successfully instanced module (ClassName: {0}, AssemblyName: {1}, DefaultSchemaName: {2}, Description: {3}).", className, assemblyName, defaultSchemaName, description);

                            ret.Add(m);
                        }
                        catch (Exception ex)
                        {
                            errorMessage = string.Format(
                                @"Error instancing module from database config (ClassName: {0}, AssemblyName: {1}, DefaultSchemaName: {2}, DefaultSchemaName: {3}),
ErrorMessage: 
{4}", className, assemblyName, defaultSchemaName, description, ex.Message);

                            ret.Clear();
                            break;
                        }
                        finally
                        {
                            OnModuleLoaded(this, new ModuleLoadedEventArgs()
                            {
                                ErrorMessage = errorMessage, Message = message
                            });
                        }
                    }
                }
                catch (Exception)
                {
                    // CONSIDER - do some logging
                    throw;
                }
                foreach (IDBModule m in ret)
                {
                    DBModules.Add(m);
                    dBTimeLiner.DBModules.Add(m);
                }
            }

            return(ret);
        }