Beispiel #1
0
 public DataStreamFunction(VehicleDB db, IChannel chn, IFormat format)
     : base(db, chn, format)
 {
     stopRead = true;
     stopCalc = true;
     readExp = false;
     lds = null;
     readInterval = Timer.FromMilliseconds(10);
     calcInterval = Timer.FromMilliseconds(1);
     readMutex = new Mutex();
     calcMutex = new Mutex();
     taskFactory = new TaskFactory();
     tasks = null;
     readBuff = new byte[128];
     historyBuff = new Dictionary<string, byte[]>();
     BeginRead = null;
     EndRead = null;
     BeginCalc = null;
     EndCalc = null;
 }
Beispiel #2
0
        public LiveDataList QueryLiveData(string cls)
        {
            Action ThrowException = () =>
            {
                throw new DatabaseException(String.Format("Query live data fail by class = {0}", cls));
            };

            try
            {
                liveDataCommand.Prepare();

                liveDataCommand.Parameters[0].Value = EncryptLang;
                liveDataCommand.Parameters[1].Value = Encrypt(cls);

                using (var reader = liveDataCommand.ExecuteReader())
                {
                    LiveDataList list = new LiveDataList();
                    while (reader.Read())
                    {
                        LiveDataItem item = new LiveDataItem();

                        item.ShortName = DBCrypto.DecryptToString(reader.GetFieldValue<byte[]>(0));

                        item.Content = DBCrypto.DecryptToString(reader.GetFieldValue<byte[]>(1));

                        item.Unit = reader.IsDBNull(2) ? "" : DBCrypto.DecryptToString(reader.GetFieldValue<byte[]>(2));

                        item.DefaultValue = reader.IsDBNull(3) ? "" : DBCrypto.DecryptToString(reader.GetFieldValue<byte[]>(3));

                        if (!reader.IsDBNull(4) && !reader.IsDBNull(5))
                        {
                            item.CmdName = DBCrypto.DecryptToString(reader.GetFieldValue<byte[]>(4));
                            item.CmdClass = DBCrypto.DecryptToString(reader.GetFieldValue<byte[]>(5));
                            item.Command = QueryCommand(item.CmdName, item.CmdClass);
                        }

                        item.Description = reader.IsDBNull(6) ? "" : DBCrypto.DecryptToString(reader.GetFieldValue<byte[]>(6));
                        byte[] indexArray = DBCrypto.DecryptToBytes(reader.GetFieldValue<byte[]>(7));
                        int index = ((indexArray[3] & 0xFF) << 24) +
                        ((indexArray[2] & 0xFF) << 16) +
                        ((indexArray[1] & 0xFF) << 8) +
                        (indexArray[0] & 0xFF);

                        item.IndexForSort = index;

                        list.Add(item);
                    }

                    return list;
                }
            }
            catch
            {
                ThrowException();
            }

            ThrowException();
            return null;
        }
Beispiel #3
0
 public bool QueryLiveData(string cls)
 {
     try
     {
         lds = Database.QueryLiveData(cls);
         InitCalcDelegates();
         return true;
     }
     catch
     {
     }
     return false;
 }