예제 #1
0
 public ModelDevice[] GetAvailableDevices(ModelInterface modelInterface)
 {
     var result = new ModelDevice[] { };
     var hwDetector = GenerateHardwareDetector();
     if (hwDetector != null)
     {
         var intfc = modelInterface as ModelInterfaceSample;
         if (intfc != null)
         {
             var devices = hwDetector.GetConnectedInstruments(intfc);
             result = devices.ToArray();
         }
     }
     return result;
 }
예제 #2
0
        public ModelDevice[] GetAvailableDevices(ModelInterface modelInterface)
        {
            var result     = new ModelDevice[] { };
            var hwDetector = GenerateHardwareDetector();

            if (hwDetector != null)
            {
                var intfc = modelInterface as ModelInterfaceSample;
                if (intfc != null)
                {
                    var devices = hwDetector.GetConnectedInstruments(intfc);
                    result = devices.ToArray();
                }
            }
            return(result);
        }
예제 #3
0
        public DeviceDataRecord CreateDeviceRepresentation(ModelDevice device)
        {
            if (device == null)
            {
                return(null);
            }
            DeviceDataRecord raw = new DeviceDataRecord(device.ParentId);

            if (device is ModelDevice)
            {
                AddCommonDevicePropertiesAsNVPairs(device, raw);
                raw.AddProperty(AgentKeys.AgentName, AgentId);    // mark it as mine

                var specificDevice = device as ModelDeviceSample;
                if (specificDevice != null)
                {
                    AddInfoToDevice(raw, specificDevice);
                }
            }
            return(raw);
        }
예제 #4
0
        private void AddNewDevice(object sender, RoutedEventArgs e)
        {
            if ((BrandComboBox.Text == "") || (TypeDevice.Text == "") || (ModelDevice.Text == ""))
            {
                attention.Visibility = Visibility.Visible;
            }
            else
            {
                //ищем название бренда в соответствуюущей таблице
                attention.Visibility = Visibility.Hidden;
                string           dbcon = @"Data Source = AddOrder.db; Version=3;";
                string           query_search_brand = "SELECT BrandName FROM Brands WHERE BrandName = @BrandName;";
                string           query_brand        = "INSERT INTO Brands (BrandName) VALUES (@BrandName);";
                SQLiteConnection connection         = new SQLiteConnection(dbcon);
                connection.Open();
                SQLiteCommand command_search = new SQLiteCommand(query_search_brand, connection);
                command_search.Parameters.Add("@BrandName", DbType.String).Value = BrandComboBox.Text;
                SQLiteDataAdapter da = new SQLiteDataAdapter(command_search);
                DataTable         dt = new DataTable();
                da.Fill(dt);

                if (dt.Rows.Count > 0) //если есть, то не добавляем
                {
                }
                else //в противном случае - добавляем
                {
                    SQLiteCommand command_brands = new SQLiteCommand(query_brand, connection);
                    command_brands.Connection = connection;
                    command_brands.Parameters.Add("@BrandName", DbType.String).Value = BrandComboBox.Text;
                    command_brands.ExecuteNonQuery();
                    //System.Windows.Forms.MessageBox.Show("Бренд добавлен");
                }


                //ищем название типа устройства в соответсвующей таблице
                string        query_search_type    = "SELECT Name FROM Types WHERE Name = @TypeName;";
                string        query_type           = "INSERT INTO Types (Name) VALUES (@Name);";
                SQLiteCommand command_search_types = new SQLiteCommand(query_search_type, connection);
                command_search_types.Parameters.Add("@TypeName", DbType.String).Value = TypeDevice.Text;
                SQLiteDataAdapter da_2 = new SQLiteDataAdapter(command_search_types);
                DataTable         dt_2 = new DataTable();
                da_2.Fill(dt_2);

                if (dt.Rows.Count > 0) //если есть, то не добавляем
                {
                }
                else //в противном случае - добавляем
                {
                    SQLiteCommand command_types = new SQLiteCommand(query_type, connection);
                    command_types.Connection = connection;
                    command_types.Parameters.Add("@BrandName", DbType.String).Value = BrandComboBox.Text;
                    command_types.ExecuteNonQuery();
                    //System.Windows.Forms.MessageBox.Show("Тип добавлен");
                }


                //достаем id бренда, чтобы загрузить его в таблицу девайсов
                string        query_search_brand_id   = "SELECT id FROM Brands WHERE BrandName = @BrandName;";
                SQLiteCommand command_search_brand_id = new SQLiteCommand(query_search_brand_id, connection);
                command_search_brand_id.Parameters.Add("@BrandName", DbType.String).Value = BrandComboBox.Text;
                SQLiteDataReader reader_id = command_search_brand_id.ExecuteReader();
                reader_id.Read();
                int BrandID = reader_id.GetInt32(0);


                //достаем id типа устройства, чтобы загрузить его в таблицу девайсов
                string        query_search_type_id   = "SELECT id FROM Types WHERE Name = @TypeName;";
                SQLiteCommand command_search_type_id = new SQLiteCommand(query_search_type_id, connection);
                command_search_type_id.Parameters.Add("@TypeName", DbType.String).Value = TypeDevice.Text;
                SQLiteDataReader reader_id_type = command_search_type_id.ExecuteReader();
                reader_id_type.Read();
                int TypeID = reader_id_type.GetInt32(0);


                //достаем название модели устройства
                string Model = ModelDevice.Text;


                //добавляем устройство в таблицу устройств
                string        query_device_search   = "SELECT TypeId,BrandId,Model FROM Devices WHERE TypeId = @TypeId AND BrandID = @BrandID AND Model = @Model;";
                string        query_device_Add      = "INSERT INTO Devices (TypeId,BrandId,Model) VALUES (@TypeId,@BrandId,@Model);";
                SQLiteCommand command_search_device = new SQLiteCommand(query_device_search, connection);
                command_search_device.Parameters.Add("@TypeId", DbType.Int32).Value  = TypeID;
                command_search_device.Parameters.Add("@BrandId", DbType.Int32).Value = BrandID;
                command_search_device.Parameters.Add("@Model", DbType.String).Value  = Model;
                SQLiteDataAdapter da_device = new SQLiteDataAdapter(command_search_device);
                DataTable         dt_device = new DataTable();
                da_device.Fill(dt_device);

                if (dt_device.Rows.Count > 0)
                {
                    System.Windows.Forms.MessageBox.Show("Данное устройство уже есть в базе данных");
                }
                else
                {
                    SQLiteCommand command_device_add = new SQLiteCommand(query_device_Add, connection);
                    command_device_add.Parameters.Add("@TypeId", DbType.Int32).Value  = TypeID;
                    command_device_add.Parameters.Add("@BrandId", DbType.Int32).Value = BrandID;
                    command_device_add.Parameters.Add("@Model", DbType.String).Value  = Model;
                    command_device_add.ExecuteNonQuery();
                    connection.Close();
                    BrandComboBox.Text = "";
                    TypeDevice.Text    = "";
                    ModelDevice.Clear();
                    System.Windows.Forms.MessageBox.Show("Устройство добавлено");
                }
            }
        }
예제 #5
0
    public override void Test()
    {
        RoomSourceSelection selection = new RoomSourceSelection();

        selection.EEventSelectionChanged += EventSelectionChanged;

        // test that no subscription occurs for room/source after 200ms
        selection.SetPendingRoom(-1, null);
        Thread.Sleep(100);
        TEST(iNumEventsReceived == 0);    // after 100ms no event should have occured
        Thread.Sleep(150);
        TEST(iNumEventsReceived == 0);    // after 250ms no event should have occured

        selection.SetPendingSource(-1, null, true);
        Thread.Sleep(100);
        TEST(iNumEventsReceived == 0);    // after 100ms no event should have occured
        Thread.Sleep(150);
        TEST(iNumEventsReceived == 0);    // after 250ms no event should have occured

        ModelRoom room = new ModelRoom("TestRoom");

        // test that a subscription occurs for room/source after 200ms
        selection.SetPendingRoom(0, room);
        Thread.Sleep(100);
        TEST(iNumEventsReceived == 0);    // after 100ms no event should have occured
        Thread.Sleep(200);
        TEST(iNumEventsReceived == 1);    // after 250ms 1 event should have occured
        iNumEventsReceived = 0;
        int             roomIndex       = -1;
        ModelRoom       modelRoom       = null;
        int             sourceIndex     = -1;
        ModelRoomSource modelRoomSource = null;

        selection.GetRoomAndSource(ref roomIndex, ref modelRoom, ref sourceIndex, ref modelRoomSource);
        TEST(roomIndex == 0);
        TEST(modelRoom == room);
        TEST(sourceIndex == -1);
        TEST(modelRoomSource == null);
        ModelRoomSource source      = new ModelRoomSource();
        ModelDevice     modelDevice = new ModelDevice("TestRoom", "TestSource", "Auxiliary");

        source.ModelAuxiliarySource           = new ModelDeviceSourceAuxiliary(modelDevice);
        source.ModelAuxiliarySource.ModelRoom = room;
        selection.SetPendingSource(1, source, true);
        Thread.Sleep(100);
        TEST(iNumEventsReceived == 0);    // after 100ms no event should have occured
        Thread.Sleep(200);
        TEST(iNumEventsReceived == 1);    // after 250ms 1 event should have occured
        iNumEventsReceived = 0;
        selection.GetRoomAndSource(ref roomIndex, ref modelRoom, ref sourceIndex, ref modelRoomSource);
        TEST(roomIndex == 0);
        TEST(modelRoom == room);
        TEST(sourceIndex == 1);
        TEST(modelRoomSource == source);

        // unsubscribe from source
        selection.SetPendingSource(-1, null, true);
        Thread.Sleep(250);
        TEST(iNumEventsReceived == 1);    // after 250ms 1 event should have occured
        iNumEventsReceived = 0;
        selection.GetRoomAndSource(ref roomIndex, ref modelRoom, ref sourceIndex, ref modelRoomSource);
        TEST(roomIndex == 0);
        TEST(modelRoom == room);
        TEST(sourceIndex == -1);
        TEST(modelRoomSource == null);

        // unsubscribe from room when subscribed to room and source
        selection.SetPendingSource(1, source, true);
        Thread.Sleep(250);
        selection.SetPendingRoom(-1, null);
        Thread.Sleep(250);
        TEST(iNumEventsReceived == 2);    // after 500ms 2 events should have occured
        iNumEventsReceived = 0;
        selection.GetRoomAndSource(ref roomIndex, ref modelRoom, ref sourceIndex, ref modelRoomSource);
        TEST(roomIndex == -1);
        TEST(modelRoom == null);
        TEST(sourceIndex == -1);
        TEST(modelRoomSource == null);
    }
예제 #6
0
        public DeviceDataRecord CreateDeviceRepresentation(ModelDevice device)
        {
            if (device == null) return null;
            DeviceDataRecord raw = new DeviceDataRecord(device.ParentId);
            if (device is ModelDevice)
            {
                AddCommonDevicePropertiesAsNVPairs(device, raw);
                raw.AddProperty(AgentKeys.AgentName, AgentId);    // mark it as mine

                var specificDevice = device as ModelDeviceSample;
                if (specificDevice != null)
                {
                    AddInfoToDevice(raw, specificDevice);
                }
            }
            return raw;
        }