public void AddDevice(DeviceViewModel entity) { var model = _mapper.Map <Device>(entity); _repository.Add(model); _unitOfWork.Commit(); }
private void SetupNetworkDeviceDetails(DeviceViewModel deviceViewModel) { serialTitleLabel.Visible = deviceViewModel.Kind != DeviceKind.NET; serialValueLabel.Visible = deviceViewModel.Kind != DeviceKind.NET; processorsTitleLabel.Visible = deviceViewModel.Kind != DeviceKind.NET; processorsValueLabel.Visible = deviceViewModel.Kind != DeviceKind.NET; if (deviceViewModel.Kind == DeviceKind.NET) { pathValueLabel.Width = Width - pathValueLabel.Left - 6; nameLabel.Cursor = Cursors.Hand; nameLabel.Font = new Font(nameLabel.Font, FontStyle.Underline); nameLabel.ForeColor = Color.Blue; statusLabel.Text = String.Format("{0}{1}{2}", deviceViewModel.ChainStatus[0], Environment.NewLine, deviceViewModel.ChainStatus[1]); } else { pathValueLabel.Width = serialTitleLabel.Left - pathValueLabel.Left - 6; nameLabel.Cursor = Cursors.Default; nameLabel.Font = new Font(nameLabel.Font, FontStyle.Regular); nameLabel.ForeColor = Color.FromArgb(30, 57, 91); statusLabel.Text = String.Empty; } }
public DirectionDeviceSelectorViewModel(Direction direction, DriverType driverType) { Title = "Выбор устройства"; var devices = new HashSet<Device>(); foreach (var device in FiresecManager.Devices) { if (device.Driver.DriverType == driverType) { if (device.Parent.Children.Any(x => x.Driver.IsZoneDevice && x.ZoneUID != Guid.Empty && direction.ZoneUIDs.Contains(x.ZoneUID))) { device.AllParents.ForEach(x => { devices.Add(x); }); devices.Add(device); } } } Devices = new ObservableCollection<DeviceViewModel>(); foreach (var device in devices) { var deviceViewModel = new DeviceViewModel(device); deviceViewModel.IsExpanded = true; Devices.Add(deviceViewModel); } foreach (var device in Devices.Where(x => x.Device.Parent != null)) { var parent = Devices.FirstOrDefault(x => x.Device.UID == device.Device.Parent.UID); parent.AddChild(device); } SelectedDevice = Devices.FirstOrDefault(x => x.HasChildren == false); }
public IActionResult Edit(int?id) { // Make sure we have a valid ID if (id == null) { return(NotFound()); } // Find the correct device using the ID var device = _context.Devices.Include(d => d.Room).Single(m => m.Id == id.Value); if (device == null) { // If no device could be found, show a 404 page return(NotFound()); } // Create the device viewmodel var vm = new DeviceViewModel() { Id = device.Id, Name = device.Name, RoomId = device.Room.Id, AvailableRooms = _context.Rooms.ToList(), DeviceAddress = device.DeviceAddress, NetworkAddress = device.NetworkAddress, NetworkKey = device.NetworkKey }; // Render the edit view using the viewmodel return(View(vm)); }
public void GetAllDevicesWithinLiquidated_Test() { //Arrange var mock = new Mock <IDbContext>(); mock.Setup(x => x.Set <Device>()) .Returns(new FakeDbSet <Device> { new Device() { UniqueNumber = "1111111111" }, new Device() { UniqueNumber = "3233233323", DateOfLiquidation = new DateTime() } }); DeviceViewModel dvm = new DeviceViewModel(mock.Object); // Act var allDevices = dvm.GetAllDevicesFromDb(); // Assert Assert.AreEqual(2, allDevices.Count()); }
private void NavigateToDeviceDetails(DeviceViewModel device) { try { ProgressUtility.SafeShow("Getting Device Details", async() => { var response = await ServiceContainer.DeviceService.RequestDevice(device.Device, () => { NavigateToDeviceDetails(device); }); MainThreadUtility.InvokeOnMain(() => { if (response != null && response.IsSuccessful) { var d = response.Body.Devices.Items.FirstOrDefault().Value; if (d == null) { ProgressUtility.Dismiss(); AlertUtility.ShowErrorAlert(StringLiterals.Error, StringLiterals.DeviceNotFoundErrorTitle); } else { this.Predecessor = null; ProgressUtility.Dismiss(); this.NavigateTo(DeviceDetailsViewController.CreateInstance(d.Id)); } } }); }); } catch (Exception e) { LogUtility.LogException(e); } }
//删除设备 public ResponseData DeleteDevice(DeviceViewModel dvm) { ResponseData rd = new ResponseData(); //获取设备信息 DeviceModel dm = _dr.Find(dvm.DeviceSn, dvm.Token); if (dm == null) { rd.Success = false; rd.Message = "不存在此设备,请确认"; return(rd); } #region 验证用户权限 bool bRet = CheckDeviceAuth(dm, dvm.Account, dvm.Token, 2); if (!bRet) { rd.Success = false; rd.Message = "用户没有权限删除设备"; return(rd); } #endregion //删除设备,连带删除设备的其他信息 try { _dr.Remove(dvm.DeviceSn); rd.Success = true; rd.Message = "删除设备成功"; } catch (Exception) { rd.Success = false; rd.Message = "删除设备失败"; } return(rd); }
public ActionResult Details(Guid policyId) { var policyModel = _policyService.GetById(policyId); var viewModel = new DeviceViewModel(policyModel); return(View(viewModel)); }
public async Task <bool> SaveDevice(DeviceViewModel model) { using (LockerDBContext db = new LockerDBContext()) { Device device = db.Device.Where(x => x.DeviceId == model.DeviceId).FirstOrDefault(); if (device == null) { device = new Device() { DeviceName = model.DeviceName, DeviceId = model.DeviceId, Status = model.Status, LockerId = model.LockerId }; db.Device.Add(device); } else { device.DeviceName = model.DeviceName; device.DeviceId = model.DeviceId; device.Status = model.Status; device.LockerId = model.LockerId; } return(await db.SaveChangesAsync() >= 1); } }
public ActionResult Edit(int idUser, int idDevice) { WSRequest request = new WSRequest("/users/" + idUser + "/devices/" + idDevice); request.AddAuthorization(Session["token"].ToString()); var response = request.Get(); if (response.Code != 200) { return(RedirectToAction("Index", "Home", new { message = "Não foi possível buscar o device" })); } var body = response.Body; var model = new DeviceViewModel { IdDevice = (int)body["id_device"], Alias = body["alias"].ToString(), Color = body["color"].ToString(), FrequencyUpdate = (int)body["frequency_update"], IdUser = (int)body["id_user"] }; return(View(model)); }
public DeviceList(User user, IAdapter adapter, IBluetoothLE ble) { InitializeComponent(); DeviceViewModel deviceViewmodel = new DeviceViewModel(user, adapter, ble, Navigation); BindingContext = deviceViewmodel; }
public ActionResult Edit(Guid id) { CacheHelper.SetPreviousPage(_cache, Request.Headers["Referer"].ToString()); DeviceViewModel mmodel = new DeviceViewModel(_cache, id); return(View(mmodel)); }
private static void RequestUri(MasterViewModel masterVM, string def = "http://enterAdressOrIP") { var input = new InputBox() { Title = "Connect...", Label = "_Device address", Text = def }; if (input.ShowDialog().GetValueOrDefault()) { if (Uri.IsWellFormedUriString(input.Text, UriKind.Absolute)) { var vm = new DeviceViewModel(new Uri(input.Text)); masterVM.Devices.Add(vm); _ = masterVM.UpdateStatus(vm); _ = masterVM.UpdateHistory(false); } else { MessageBox.Show($"\"{input.Text}\" isn't a valid device address.", "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly); RequestUri(masterVM, input.Text); } } }
public IActionResult LoadDevice(int?id) { var model = new DeviceViewModel { //WareHouseId = inventory.Warehouse.Id, //WareHouseManagerId = inventory.WarehouseManager.Id, //DateInventary = DateTime.Today, //ListDevices = _combosHelper.GetComboDevices(), //ListBrands = _combosHelper.GetComboBrands(), //ListMovements = _combosHelper.GetComboMovementTypes(), //InventoryId = inventory.Id }; return(View(model)); //if (ModelState.IsValid) //{ // var inventory = await _converterHelper.ToInventoryAsync(model, true); // _dataContext.Inventories.Add(inventory); // await _dataContext.SaveChangesAsync(); // return RedirectToAction($"{nameof(Details)}/{model.Warehouse.Id}"); //} ////model.Lessees = _combosHelper.GetComboLessees(); //return View(model); }
public async Task <IActionResult> UpdateDevice(int id, [FromBody] DeviceViewModel entity) { if (ModelState.IsValid) { if (entity == null) { return(BadRequest($"{nameof(entity)} cannot be found")); } if (id != entity.Id) { return(BadRequest("Conflicting device id in parameter")); } var device = _unitOfWork.Devices.Get(id); if (device == null) { return(NotFound()); } #if DEBUG Debug.WriteLine("UpdateDevice entity.LastUpdate = " + entity.LastUpdate.ToString()); #endif _mapper.Map <DeviceViewModel, Device>(entity, device); _unitOfWork.Devices.Update(device); _unitOfWork.SaveChanges(); return(NoContent()); } return(BadRequest(ModelState)); }
public LightPage(DeviceViewModel deviceViewModel) { InitializeComponent(); _deviceViewModel = deviceViewModel; Text = _deviceViewModel.ToString(); LightBulbIndicator.State = _deviceViewModel.IsOn == "on" ? UILightState.On : UILightState.Off; }
public DevicePropertiesViewModel(DevicesViewModel devicesViewModel, ElementDevice elementDevice) { Title = "Свойства фигуры: Устройство"; _elementDevice = elementDevice; _devicesViewModel = devicesViewModel; Devices = new ObservableCollection<DeviceViewModel>(); foreach (var device in FiresecManager.Devices) { var deviceViewModel = new DeviceViewModel(device); deviceViewModel.IsExpanded = true; Devices.Add(deviceViewModel); } foreach (var device in Devices) { if (device.Device.Parent != null) { var parent = Devices.FirstOrDefault(x => x.Device.UID == device.Device.Parent.UID); parent.AddChild(device); } } if (Devices.Count > 0) { CollapseChild(Devices[0]); ExpandChild(Devices[0]); } SelectedDriver = FiresecManager.DeviceLibraryConfiguration.Devices.FirstOrDefault(x => x.DriverId == _elementDevice.AlternativeLibraryDeviceUID); Select(elementDevice.DeviceUID); }
//void AddChildPlainDevices(DeviceViewModel parentViewModel) //{ // AllDevices.Add(parentViewModel); // foreach (var childViewModel in parentViewModel.Children) // { // AddChildPlainDevices(childViewModel); // } //} public void Select(Guid deviceUID) { var deviceViewModel = AllDevices.FirstOrDefault(x => x.Device.UID == deviceUID); if (deviceViewModel != null) deviceViewModel.ExpantToThis(); SelectedDevice = deviceViewModel; }
public IActionResult Create(DeviceViewModel deviceViewModel) { // Make sure the model is valid if (ModelState.IsValid) { // Create the device var device = new Device() { Name = deviceViewModel.Name, Room = _context.Rooms.Single(m => m.Id == deviceViewModel.RoomId), DeviceAddress = deviceViewModel.DeviceAddress, NetworkAddress = deviceViewModel.NetworkAddress, NetworkKey = deviceViewModel.NetworkKey }; // Add the device _context.Devices.Add(device); _context.SaveChanges(); // Redirect the user back to the index page return(RedirectToAction("Index")); } // If the viewmodel is not valid, show the view again with the errors return(View(deviceViewModel)); }
private void SetupDevicePicture(DeviceViewModel deviceViewModel) { switch (deviceViewModel.Kind) { case DeviceKind.CPU: pictureBox1.Image = imageList1.Images[3]; break; case DeviceKind.GPU: pictureBox1.Image = imageList1.Images[0]; break; case DeviceKind.USB: pictureBox1.Image = imageList1.Images[1]; break; case DeviceKind.PXY: pictureBox1.Image = imageList1.Images[2]; break; case DeviceKind.NET: pictureBox1.Image = imageList1.Images[4]; break; } }
public async Task <IActionResult> PutDevice([FromRoute] int id, [FromBody] DeviceViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var device = _deviceRepository.Find(id); var gateway = _gatewayRepository.Find(model.DeviceGatewayId); device.Gateway = gateway; device.Status = model.DeviceStatus; device.UID = model.DeviceUID; device.Vendor = model.DeviceVendor; _deviceRepository.Update(device); await _unitOfWork.SaveChangesAsync(); } catch (Exception e) { return(BadRequest(e.Message)); } return(Ok()); }
public void SetDeviceAsDone_Test() { // Arrange Device d = new Device() { UniqueNumber = "1111111111", Client = new Client() { ID = 1 }, ClientId = 1, Place = new Place() { ID = 1, State = "Test1", City = "Test1", Street = "Test1" }, PlaceId = 1, DateOfLiquidation = null }; var mock = new Mock <IDbContext>(); var mockDbSet = new Mock <IDbSet <Device> >(); mock.Setup(x => x.Set <Device>()).Returns(new FakeDbSet <Device>() { d }); DeviceViewModel dvm = new DeviceViewModel(mock.Object); // Act dvm.SetDateOfLiquidation(d); // Assert Assert.IsNotNull(mock.Object.Set <Device>().FirstOrDefault().DateOfLiquidation); }
public ActionResult DeviceDetails(Guid policyId) { var deviceDomainModel = _policyService.GetByPolicyId(policyId); var deviceViewModel = new DeviceViewModel(deviceDomainModel); return(View(deviceViewModel)); }
public ActionResult Details(Guid id) { var domainModel = _policyService.GetById(id); var model = new DeviceViewModel(domainModel); return(View(model)); }
public async Task <ResponseDataModel <string> > Create(DeviceViewModel electricModel) { try { _logger.LogInformation($"Processing Create Device"); var message = new HttpRequestBuilder(_settings.BaseAddress) .SetPath(_settings.GateWayPath) .HttpMethod(HttpMethod.Post) .GetHttpMessage(); var json = JsonConvert.SerializeObject(electricModel); message.Content = new StringContent(json, Encoding.UTF8, "application/json"); return(await SendRequest <ResponseDataModel <string> >(message)); } //Todo: should catch specific exeption catch (Exception ex) { if (ex.Message.Contains("409")) { _logger.LogError($"Duplicated Item Error: {ex.Message}"); return(new ResponseDataModel <string> { Data = null, ErrorMessage = "Duplicated Record Found" }); } throw; } }
/// <summary> /// 开通设备WiFi功能 /// </summary> /// <param name="deviceId"></param> /// <param name="deviceType"></param> private void OpenDeviceWiFi(string deviceId, string deviceType) { var servs = new Dictionary <string, object>(); var status = new Dictionary <string, object>(); status.Add("status", 1); servs.Add("operation_status", status); var deviceModel = new DeviceViewModel(); deviceModel.user = "******"; deviceModel.device_id = deviceId; deviceModel.device_type = deviceType; deviceModel.services = servs; deviceModel.data = string.Empty; var retModel = SingleInstance <DeviceService> .Instance.SetDevice(deviceModel); if (retModel == null) { throw new MessageException("请求微信硬件控制硬件接口失败"); } if (!string.IsNullOrWhiteSpace(retModel.error_msg)) { throw new MessageException(retModel.error_msg); } }
}//Lấy device theo ID //Lấy danh sách device theo UserID public static List <DeviceViewModel> GetListDeviceByUserID(int UserID) { List <DeviceViewModel> lst = null; var reader = SqlHelper.ExecuteReader(ConnectData.ConnectionString, "sp_GetListDeviceByUserID", UserID); if (reader.HasRows) { lst = new List <DeviceViewModel>(); while (reader.Read()) { var data = new DeviceViewModel() { DeviceID = Convert.ToInt32(reader["DeviceID"]), DeviceNo = reader["DeviceNo"].ToString(), DeviceName = reader["DeviceName"].ToString(), DeviceImei = reader["DeviceImei"].ToString(), DeviceVersion = reader["DeviceVersion"].ToString(), DeviceGroup = reader["DeviceGroup"].ToString(), DeviceNote = reader["DeviceNote"].ToString(), DateExpired = (reader["DateExpired"].ToString()), StatusDevice = Convert.ToInt32(reader["StatusDevice"]), ExpireDate = Convert.ToDateTime(reader["DateExpired"].ToString()), ExpireStatus = DateTime.Compare(Convert.ToDateTime(reader["DateExpired"]), DateTime.Now) > 0 ? 1 : -1 }; lst.Add(data); } } return(lst); }
/// <inheritdoc /> public void UpdateDevice(Guid deviceId, DeviceViewModel deviceViewModel) { // Validate input deviceValidationService .Validate(deviceViewModel) .ValidateDeviceId(deviceId); // Construct repository var deviceRepository = unitOfWork.GetRepository <Device>(); // Get device Device device = deviceRepository.Get(deviceId); if (device == null) { throw new NullReferenceException(); } device.DeviceTitle = deviceViewModel.Title; deviceRepository.Update(device); // Commit changes unitOfWork.Commit(); }
}//Lấy danh sách tất cả device public static DeviceViewModel GetDeviceByID(int deviceID) { DeviceViewModel device = null; var reader = SqlHelper.ExecuteReader(ConnectData.ConnectionString, "sp_GetDeviceByID", deviceID); if (reader.HasRows) { while (reader.Read()) { var data = new DeviceViewModel() { DeviceID = Convert.ToInt32(reader["DeviceID"]), DeviceNo = reader["DeviceNo"].ToString(), DeviceName = reader["DeviceName"].ToString(), DeviceImei = reader["DeviceImei"].ToString(), DeviceVersion = reader["DeviceVersion"].ToString(), DeviceGroup = reader["DeviceGroup"].ToString(), DeviceNote = reader["DeviceNote"].ToString(), DateExpired = (reader["DateExpired"].ToString()), ExpireDate = Convert.ToDateTime(reader["DateExpired"].ToString()) }; device = data; } } return(device); }//Lấy device theo ID
public async Task <ActionResult> Index(string id, int type) { var result = new DeviceViewModel { Type = (int)ElectricType.Electric }; if (!string.IsNullOrEmpty(id)) { if (type == (int)ElectricType.Electric) { result = await _electricService.GetDetail(id); } else if (type == (int)ElectricType.Water) { result = await _waterService.GetDetail(id); } else if (type == (int)ElectricType.GateWay) { result = await _gateWayService.GetDetail(id); } return(View("Edit", result)); } return(View("Index", result)); }
private void openInfoDevicePage(DeviceViewModel deviceViewModel) { var _deviceInfoPagee = new DeviceInfoPage(deviceViewModel); Navigation.PushModalAsync(_deviceInfoPagee); this.DeviceListView.ResetSwipe(); }
public DevicePage(Model.Device device) { InitializeComponent(); if (this.Width > this.Height) { outerStack.Orientation = StackOrientation.Horizontal; } else { outerStack.Orientation = StackOrientation.Vertical; } viewModel = new DeviceViewModel(); viewModel.Device = device; BindingContext = this.viewModel; int i = 0; foreach (var item in device.CategoryList) { if (item.Id == device.ManagedDeviceCategoryId) { this.DeviceCategory.SelectedIndex = i; } i++; } }
public void DeviceDataGridLoaded() { if (_loadExecuted == true) { return; } else { _loadExecuted = true; } foreach (var device in _machineRecordService.GetDevicesForClient(ClientId)) { Devices.Add(device); } if (!string.IsNullOrEmpty(_deviceToSelect)) { SelectedDevice = Devices.First(r => r.SerialNumber == _deviceToSelect); _deviceToSelect = null; } else { SelectedDevice = Devices.FirstOrDefault(); } }
void CollapseChild(DeviceViewModel parentDeviceViewModel) { parentDeviceViewModel.IsExpanded = false; foreach (var deviceViewModel in parentDeviceViewModel.Children) { CollapseChild(deviceViewModel); } }
void AddChildPlainDevices(DeviceViewModel parentViewModel) { AllDevices.Add(parentViewModel); foreach (DeviceViewModel childViewModel in parentViewModel.Children) { AddChildPlainDevices(childViewModel); } }
public AutoDetectedDevicesViewModel(List<Device> devices) { Devices = new ObservableCollection<DeviceViewModel>(); foreach (var device in devices) { var deviceViewModel = new DeviceViewModel(device); Devices.Add(deviceViewModel); } }
void InitializeDevices() { Devices = new ObservableCollection<DeviceViewModel>(); foreach (var device in SelectedDevices) { var deviceViewModel = new DeviceViewModel(device); Devices.Add(deviceViewModel); } SelectedDevice = Devices.FirstOrDefault(); }
DeviceViewModel AddDeviceInternal(GKDevice device, DeviceViewModel parentDeviceViewModel) { var deviceViewModel = new DeviceViewModel(device); if (parentDeviceViewModel != null) parentDeviceViewModel.AddChild(deviceViewModel); foreach (var childDevice in device.Children) AddDeviceInternal(childDevice, deviceViewModel); return deviceViewModel; }
private static DeviceViewModel AddDeviceInternal(Device device, TreeItemViewModel<DeviceViewModel> parentDeviceViewModel) { var deviceViewModel = new DeviceViewModel(device); if (parentDeviceViewModel != null) parentDeviceViewModel.Children.Add(deviceViewModel); foreach (var childDevice in device.Children) AddDeviceInternal(childDevice, deviceViewModel); return deviceViewModel; }
void InitializeAvailableDevices() { var devices = new HashSet<Device>(); foreach (var device in FiresecManager.Devices) { if (Devices.Any(x => x.Device.UID == device.UID)) continue; if (device.ParentChannel != null && device.ParentChannel.UID != Device.ParentChannel.UID) continue; if (Device.Parent.Driver.DriverType == DriverType.PDU) { if ( (device.Driver.DriverType == DriverType.RM_1) || (device.Driver.DriverType == DriverType.MDU) || (device.Driver.DriverType == DriverType.MRO) || ((device.Driver.DriverType == DriverType.MRO_2) && !FiresecManager.FiresecConfiguration.IsChildMRO2(device)) || (device.Driver.DriverType == DriverType.AM1_T) ) { device.AllParents.ForEach(x => { devices.Add(x); }); devices.Add(device); } } if (Device.Parent.Driver.DriverType == DriverType.PDU_PT) { if (device.Driver.DriverType == DriverType.MPT && !FiresecManager.FiresecConfiguration.IsChildMPT(device)) { device.AllParents.ForEach(x => { devices.Add(x); }); devices.Add(device); } } } AvailableDevices = new ObservableCollection<DeviceViewModel>(); foreach (var device in devices) { var deviceViewModel = new DeviceViewModel(device); deviceViewModel.IsExpanded = true; AvailableDevices.Add(deviceViewModel); } foreach (var device in AvailableDevices) { if (device.Device.Parent != null) { var parent = AvailableDevices.FirstOrDefault(x => x.Device.UID == device.Device.Parent.UID); parent.AddChild(device); } } SelectedAvailableDevice = AvailableDevices.FirstOrDefault(x => x.ChildrenCount == 0); }
void ExpandChild(DeviceViewModel parentDeviceViewModel) { if (parentDeviceViewModel.Device.Driver.Category != DeviceCategoryType.Device) { parentDeviceViewModel.IsExpanded = true; foreach (var deviceViewModel in parentDeviceViewModel.Children) { ExpandChild(deviceViewModel); } } }
public static DeviceViewModel AddDevice(Device device, DeviceViewModel parentDeviceViewModel) { var deviceViewModel = new DeviceViewModel(device); parentDeviceViewModel.AddChild(deviceViewModel); foreach (var childDevice in device.Children) { AddDevice(childDevice, deviceViewModel); } return deviceViewModel; }
private DeviceViewModel AddDeviceInternal(Device device, DeviceViewModel parentDeviceViewModel, List<Guid> exceptDeviceUids) { var deviceViewModel = new DeviceViewModel(device); foreach (var childDevice in device.Children) { if (!exceptDeviceUids.Any(x => x == childDevice.UID)) AddDeviceInternal(childDevice, deviceViewModel, exceptDeviceUids); } if (parentDeviceViewModel != null && (deviceViewModel.ChildrenCount > 0 || device.Children.Count == 0)) parentDeviceViewModel.AddChild(deviceViewModel); return deviceViewModel; }
public DeviceViewModel AddDevice(Device device, DeviceViewModel parentDeviceViewModel) { var deviceViewModel = new DeviceViewModel(device, Devices); deviceViewModel.Parent = parentDeviceViewModel; foreach (var childDevice in device.Children) { var childDeviceViewModel = AddDevice(childDevice, deviceViewModel); deviceViewModel.Children.Add(childDeviceViewModel); } return deviceViewModel; }
public static void AddDevice(Device device, DeviceViewModel parentDeviceViewModel) { var deviceViewModel = new DeviceViewModel(device, parentDeviceViewModel.Source) { Parent = parentDeviceViewModel }; parentDeviceViewModel.Children.Add(deviceViewModel); foreach (var childDevice in device.Children) { AddDevice(childDevice, deviceViewModel); } }
public NewDeviceViewModel(DeviceViewModel parent) { Title = "Новые устройства"; _parentDeviceViewModel = parent; _parent = _parentDeviceViewModel.Device; Drivers = new List<Driver>( from Driver driver in FiresecManager.Drivers where (_parent.Driver.AvaliableChildren.Contains(driver.UID)) select driver); SelectedDriver = Drivers.FirstOrDefault(); Count = 1; }
DeviceViewModel AddDevice(Device device, DeviceViewModel parentDeviceViewModel) { var deviceViewModel = new DeviceViewModel(device); var indexOf = Devices.IndexOf(parentDeviceViewModel); Devices.Insert(indexOf + 1, deviceViewModel); foreach (var childDevice in device.Children) { var childDeviceViewModel = AddDevice(childDevice, deviceViewModel); deviceViewModel.Children.Add(childDeviceViewModel); } return deviceViewModel; }
DeviceViewModel AddDevice(Device device, DeviceViewModel parentDeviceViewModel) { var deviceViewModel = new DeviceViewModel(device); deviceViewModel.XXXPresentationZone = device.DeviceConfiguration.GetPresentationZone(device); var indexOf = Devices.IndexOf(parentDeviceViewModel); Devices.Insert(indexOf + 1, deviceViewModel); foreach (var childDevice in device.Children) { var childDeviceViewModel = AddDevice(childDevice, deviceViewModel); deviceViewModel.AddChild(childDeviceViewModel); } return deviceViewModel; }
void AddAutoDevice(AutoSearchDeviceViewModel autoDetectedDevice) { var device = autoDetectedDevice.Device; var parentDevice = FiresecManager.Devices.FirstOrDefault(x => x.PathId == device.Parent.PathId); parentDevice.Children.Add(device); var parentDeviceViewModel = DeviceViewModels.FirstOrDefault(x => x.Device.UID == parentDevice.UID); var deviceViewModel = new DeviceViewModel(device, parentDeviceViewModel.Source); deviceViewModel.Parent = parentDeviceViewModel; parentDeviceViewModel.Children.Add(deviceViewModel); parentDeviceViewModel.Update(); FiresecManager.FiresecConfiguration.DeviceConfiguration.Update(); }
void InitializeAvailableDevices() { var devices = new HashSet<Device>(); foreach (var device in FiresecManager.Devices) { if (Devices.Any(x => x.Device.UID == device.UID)) continue; if (ZoneLogicState == ZoneLogicState.AM1TOn && (device.Driver.DriverType == DriverType.AM1_T || device.Driver.DriverType == DriverType.MDU || device.Driver.DriverType == DriverType.ShuzOffButton || device.Driver.DriverType == DriverType.ShuzOnButton || device.Driver.DriverType == DriverType.ShuzUnblockButton)) { if (device.ParentPanel != null && device.ParentPanel.UID == Device.ParentPanel.UID) { device.AllParents.ForEach(x => { devices.Add(x); }); devices.Add(device); } } if (ZoneLogicState == ZoneLogicState.ShuzOn && device.Driver.DriverType == DriverType.Valve) { if (device.ParentPanel != null && device.ParentPanel.UID == Device.ParentPanel.UID) { device.AllParents.ForEach(x => { devices.Add(x); }); devices.Add(device); } } } AvailableDevices = new ObservableCollection<DeviceViewModel>(); foreach (var device in devices) { var deviceViewModel = new DeviceViewModel(device); deviceViewModel.IsExpanded = true; AvailableDevices.Add(deviceViewModel); } foreach (var device in AvailableDevices) { if (device.Device.Parent != null) { var parent = AvailableDevices.FirstOrDefault(x => x.Device.UID == device.Device.Parent.UID); parent.AddChild(device); } } SelectedAvailableDevice = AvailableDevices.FirstOrDefault(x => x.ChildrenCount == 0); }
void InitializeDevices() { var devices = new HashSet<Device>(); foreach (var device in FiresecManager.Devices) { if (device.Driver.DriverType == DriverType.Exit) continue; if ((device.Driver.IsOutDevice) || (device.Driver.IsZoneLogicDevice) || (device.Driver.DriverType == DriverType.AM1_T) || (device.Driver.DriverType == DriverType.Pump) || (device.Driver.DriverType == DriverType.JokeyPump) || (device.Driver.DriverType == DriverType.Compressor) || (device.Driver.DriverType == DriverType.DrenazhPump) || (device.Driver.DriverType == DriverType.CompensationPump) ) { device.AllParents.ForEach(x => { devices.Add(x); }); devices.Add(device); } } Devices = new ObservableCollection<DeviceViewModel>(); foreach (var device in devices) { var deviceViewModel = new DeviceViewModel(device, Devices); deviceViewModel.IsExpanded = true; Devices.Add(deviceViewModel); } foreach (var device in Devices) { if (device.Device.Parent != null) { var parent = Devices.FirstOrDefault(x => x.Device.UID == device.Device.Parent.UID); device.Parent = parent; parent.Children.Add(device); } } }
public async Task<ActionResult> UpdateLayout(DeviceViewModel model) { try { var isNew = model.Id == default(int); if (!ModelState.IsValid) { AddRedirectMessage(ModelState); return View("Layouts", model); } await _deviceViewModels.Execute(model); AddRedirectMessage(ServerResponseStatus.SUCCESS, string.Format("Device '{0}' {1}!", model.FriendlyName, (isNew) ? "created" : "updated")); return RedirectToAction("Layouts", "Devices", new { id = model.Id }); } catch (Exception ex) { AddRedirectMessage(ex); return RedirectToAction("Layouts", "Devices", null); } }
void AddAutoDevice(Device device) { var parentDevice = FiresecManager.Devices.FirstOrDefault(x => x.PathId == device.Parent.PathId); if (parentDevice != null) { if (!parentDevice.Children.Any(x => x.UID == device.UID)) { parentDevice.Children.Add(device); FiresecManager.FiresecConfiguration.DeviceConfiguration.Update(); } } var parentDeviceViewModel = DevicesViewModel.Current.AllDevices.FirstOrDefault(x => x.Device.PathId == device.Parent.PathId); if (parentDeviceViewModel != null) { var deviceViewModel = new DeviceViewModel(device); parentDeviceViewModel.AddChild(deviceViewModel); DevicesViewModel.Current.AllDevices.Add(deviceViewModel); parentDeviceViewModel.Update(); } }
public NewDeviceViewModel(DeviceViewModel parent) { Title = "Новые устройства"; ParentDeviceViewModel = parent; ParentDevice = ParentDeviceViewModel.Device; AvailableShleifs = new ObservableCollection<int>(); var sortedDrivers = SortDrivers(); Drivers = new ObservableCollection<Driver>( from Driver driver in sortedDrivers where (ParentDevice.Driver.AvaliableChildren.Contains(driver.UID)) select driver); if (parent.Device.Driver.DriverType != DriverType.Rubezh_2OP && parent.Device.Driver.DriverType != DriverType.USB_Rubezh_2OP) { var am1_o_Driver = Drivers.FirstOrDefault(x => x.DriverType == DriverType.AM1_O); if (am1_o_Driver != null) { Drivers.Remove(am1_o_Driver); } } SelectedDriver = Drivers.FirstOrDefault(); Count = 1; }
public DeviceView(IUnityContainer container, DeviceViewModel vm) { this.DataContext = vm; InitializeComponent(); var actView = new SerialDisposable(); disposables.Add( vm.GetPropertyChangedEvents(m => m.Current) .ObserveOnDispatcher() .Subscribe(state => { switch (state) { case DeviceViewModel.States.Loading: content.Content = new ProgressView(LocalDevice.instance.loading); break; case DeviceViewModel.States.Error: content.Content = new ErrorView(vm.ErrorMessage); break; default: actView.Disposable = null; content.Content = deviceView; break; }; }) ); }
void OnRemoveDevice(DeviceViewModel device) { Devices.Remove(device); }
public void Initialize(Zone zone) { Zone = zone; var devices = new HashSet<Device>(); var availableDevices = new HashSet<Device>(); foreach (var device in FiresecManager.Devices) { if (device.Driver.IsZoneDevice) { if (device.ZoneUID == Guid.Empty) { device.AllParents.ForEach(x => { availableDevices.Add(x); }); availableDevices.Add(device); } if (device.ZoneUID != Guid.Empty && device.ZoneUID == Zone.UID) { device.AllParents.ForEach(x => { devices.Add(x); }); devices.Add(device); } } if (device.Driver.IsZoneLogicDevice && device.ZoneLogic != null && device.ZoneLogic.Clauses.IsNotNullOrEmpty()) { foreach (var clause in device.ZoneLogic.Clauses.Where(x => x.ZoneUIDs.Contains(Zone.UID))) { device.AllParents.ForEach(x => { devices.Add(x); }); devices.Add(device); } } } deviceViewModels = new List<DeviceViewModel>(); foreach (var device in devices) { var deviceViewModel = new DeviceViewModel(device, false) { IsExpanded = true, IsBold = device.Driver.IsZoneDevice || device.Driver.IsZoneLogicDevice }; deviceViewModels.Add(deviceViewModel); } foreach (var device in deviceViewModels.Where(x => x.Device.Parent != null)) { var parent = deviceViewModels.FirstOrDefault(x => x.Device.UID == device.Device.Parent.UID); parent.Children.Add(device); } availableDeviceViewModels = new List<DeviceViewModel>(); foreach (var device in availableDevices) { var deviceViewModel = new DeviceViewModel(device, false) { IsExpanded = true, IsBold = device.Driver.IsZoneDevice }; availableDeviceViewModels.Add(deviceViewModel); } foreach (var device in availableDeviceViewModels.Where(x => x.Device.Parent != null)) { var parent = availableDeviceViewModels.FirstOrDefault(x => x.Device.UID == device.Device.Parent.UID); parent.Children.Add(device); } RootDevice = deviceViewModels.FirstOrDefault(x => x.Parent == null); AvailableRootDevice = availableDeviceViewModels.FirstOrDefault(x => x.Parent == null); OnPropertyChanged("RootDevices"); OnPropertyChanged("AvailableRootDevices"); }
bool DeviceValidation(DeviceViewModel selectedDeivice) { return selectedDeivice != null && selectedDeivice.Device.Driver.IsPanel; }
void OnAdd() { var parent = SelectedDevice; if (parent.Device.Driver.Children.Count == 0) parent = SelectedDevice.Parent; bool isCreateDevice = true; var driverType = new DriverType(); if (parent.Device.Driver.Children.Count > 1) { var driverTypesViewModel = new DriverTypesViewModel(parent.Device.DriverType); if (DialogService.ShowModalWindow(driverTypesViewModel)) { driverType = driverTypesViewModel.SelectedDriverType; } else isCreateDevice = false; } else driverType = parent.Device.Driver.Children.FirstOrDefault(); if(isCreateDevice) { var deviceDetailsViewModel = new DeviceDetailsViewModel(driverType, parent.Device); if (DialogService.ShowModalWindow(deviceDetailsViewModel)) { var deviceViewModel = new DeviceViewModel(deviceDetailsViewModel.Device); parent.AddChild(deviceViewModel); parent.IsExpanded = true; AllDevices.Add(deviceViewModel); SelectedDevice = deviceViewModel; DeviceProcessor.Instance.AddToMonitoring(deviceViewModel.Device); UpdateConsumerDetailsViewModels(SelectedDevice.Device); } } }
public DeviceViewModel AddDevice(Device device, DeviceViewModel parentDeviceViewModel) { var deviceViewModel = AddDeviceInternal(device, parentDeviceViewModel); FillAllDevices(); return deviceViewModel; }