public BoxViewModel(LEDBox box) { _box = box; _COMIndex = _box.COMIndex; _senderIndex = (byte)(_box.SenderIndex + 1); _portIndex = (byte)(_box.PortIndex + 1); _connectIndex = (byte)(_box.ConnectIndex + 1); _width = _box.Width; _height = _box.Height; _x = _box.X; _y = _box.Y; _xInPort = _box.XInPort; _yInPort = _box.YInPort; _indexLocation = GetIndexLocation(_box); SelectBoxCommand = new DelegateCommand<object>(SelectBox); _eventAggregator = ServiceLocator.Current.GetInstance<IEventAggregator>(); _brightnessService = ServiceLocator.Current.GetInstance<IBrightnessService>(); _readDataTimer = new Timer(ReadData, null, 0, 1000 * 30); }
public Task<IList<LEDBoxGroup>> GetBoxGroupsAsync() { var tcs = new TaskCompletionSource<IList<LEDBoxGroup>>(); _boxes.Clear(); _groups.Clear(); _LCTService.ReadCOMHWBaseInfoAsync((info, o) => { if (info == null || info.AllInfo == null || info.AllInfo.AllInfoDict == null) { //_waitForReadData.Set(); return; } //_eventAggregator.GetEvent<MessageUpdateEvent>().Publish(new MessageUpdateEvent() { Message = "Get LED Boxes Data" }); var currentCOMAndHWBaseInfo = info.AllInfo.AllInfoDict.ElementAt(0); var currentHWBaseInfo = currentCOMAndHWBaseInfo.Value; if (currentHWBaseInfo == null || currentHWBaseInfo.LEDDisplayInfoList == null) { // _waitForReadData.Set(); return; } foreach (var item in currentHWBaseInfo.LEDDisplayInfoList) { foreach (var receivingCardItem in item.GetAreaScanBdList(new System.Drawing.Rectangle(item.GetScreenPosition(), item.GetScreenSize()))) { LEDBox box = new LEDBox(); box.Height = receivingCardItem.Height; box.Width = receivingCardItem.Width; box.X = receivingCardItem.X; box.Y = receivingCardItem.Y; box.XInPort = receivingCardItem.XInPort; box.YInPort = receivingCardItem.YInPort; box.COMIndex = currentCOMAndHWBaseInfo.Key; box.SenderIndex = (byte)(receivingCardItem.SenderIndex); box.PortIndex = (byte)(receivingCardItem.PortIndex); box.ConnectIndex = (byte)(receivingCardItem.ConnectIndex); _boxes.Add(box); } } var boxGroupList = _boxes.GroupBy(x => new { x.COMIndex, x.SenderIndex, x.PortIndex }) .Select(y => new LEDBoxGroup() { COMIndex = y.Key.COMIndex, SenderIndex = y.Key.SenderIndex, PortIndex = y.Key.PortIndex, Boxes = y.ToList() }); _groups = new List<LEDBoxGroup>(boxGroupList); tcs.SetResult(_groups); // _waitForReadData.Set(); }); return tcs.Task; }
private string GetIndexLocation(LEDBox box) { return string.Format("{0}-S{1}-P{2}-{3}", box.COMIndex, box.SenderIndex + 1, box.PortIndex + 1, box.ConnectIndex + 1); }
private static ObservableCollection<BoxGroupViewModel> LoadComponentXml(string filePath) { var boxGroupViewModelList = new ObservableCollection<BoxGroupViewModel>(); XDocument doc = XDocument.Load(filePath); if (doc != null) { IEnumerable<XElement> elementlist = doc.Root.Elements("BoxGroup"); foreach (var item in elementlist) { ObservableCollection<BoxViewModel> boxViewModelList = new ObservableCollection<BoxViewModel>(); List<XElement> infoElementList = item.Elements("BoxGroupInfo").ToList(); List<XElement> pointElementList = item.Elements("Boxes").ToList(); for (int count = 0; count < infoElementList.Count; count++) { LEDBoxGroup boxGroup = new LEDBoxGroup(); List<LEDBox> boxList = new List<LEDBox>(); foreach (var point in pointElementList[count].Elements("Box")) { XAttribute COMIndexAttr = point.Attribute("COMIndex"); XAttribute SenderIndexAttr = point.Attribute("SenderIndex"); XAttribute PortIndexAttr = point.Attribute("PortIndex"); XAttribute ConnectIndexAttr = point.Attribute("ConnectIndex"); XAttribute WidthAttr = point.Attribute("Width"); XAttribute HeightAttr = point.Attribute("Height"); XAttribute XInPortAttr = point.Attribute("XInPort"); XAttribute YInPortAttr = point.Attribute("YInPort"); XAttribute XAttr = point.Attribute("X"); XAttribute YAttr = point.Attribute("Y"); LEDBox box = new LEDBox(); box.COMIndex = COMIndexAttr.Value; box.SenderIndex = Convert.ToByte(SenderIndexAttr.Value); box.PortIndex = Convert.ToByte(PortIndexAttr.Value); box.ConnectIndex = Convert.ToByte(ConnectIndexAttr.Value); box.Width = Convert.ToDouble(WidthAttr.Value); box.Height = Convert.ToDouble(HeightAttr.Value); box.XInPort = Convert.ToUInt16(XInPortAttr.Value); box.YInPort = Convert.ToUInt16(YInPortAttr.Value); box.X = Convert.ToUInt16(XAttr.Value); box.Y = Convert.ToUInt16(YAttr.Value); boxList.Add(box); //BoxViewModel boxViewModel = new BoxViewModel(box); //boxViewModelList.Add(boxViewModel); } boxGroup.COMIndex = boxList[0].COMIndex; boxGroup.SenderIndex = boxList[0].SenderIndex; boxGroup.PortIndex = boxList[0].PortIndex; boxGroup.Boxes = boxList; BoxGroupViewModel elementViewModel = new BoxGroupViewModel(boxGroup); XAttribute sysIndexLocationAttr = infoElementList[count].Attribute("IndexLocation"); if (sysIndexLocationAttr != null) elementViewModel.IndexLocation = sysIndexLocationAttr.Value; XAttribute sysElementPxPointXAttr = infoElementList[count].Attribute("ElementPxPointX"); if (sysElementPxPointXAttr != null) elementViewModel.ElementPxPointX = double.Parse(sysElementPxPointXAttr.Value); XAttribute elementPxPointYAttr = infoElementList[count].Attribute("ElementPxPointY"); if (elementPxPointYAttr != null) elementViewModel.ElementPxPointY = double.Parse(elementPxPointYAttr.Value); boxGroupViewModelList.Add(elementViewModel); } #region load //foreach (var infoElement in infoElementList) //{ // LEDBoxGroup groupitem = new LEDBoxGroup(); // XAttribute sysIndexLocationAttr = infoElement.Attribute("IndexLocation"); // if (sysIndexLocationAttr != null) // elementViewModel.IndexLocation = sysIndexLocationAttr.Value; // XAttribute sysElementPxPointXAttr = infoElement.Attribute("ElementPxPointX"); // if (sysElementPxPointXAttr != null) // elementViewModel.ElementPxPointX = double.Parse(sysElementPxPointXAttr.Value); // XAttribute elementPxPointYAttr = infoElement.Attribute("ElementPxPointY"); // if (elementPxPointYAttr != null) // elementViewModel.ElementPxPointY = double.Parse(elementPxPointYAttr.Value); //} //IEnumerable<XElement> pointElementList = item.Elements("Boxes"); //foreach (var pointElement in pointElementList) //{ // foreach (var point in pointElement.Elements("Box")) // { // XAttribute COMIndexAttr = point.Attribute("COMIndex"); // XAttribute SenderIndexAttr = point.Attribute("SenderIndex"); // XAttribute PortIndexAttr = point.Attribute("PortIndex"); // XAttribute ConnectIndexAttr = point.Attribute("ConnectIndex"); // XAttribute WidthAttr = point.Attribute("Width"); // XAttribute HeightAttr = point.Attribute("Height"); // XAttribute XInPortAttr = point.Attribute("XInPort"); // XAttribute YInPortAttr = point.Attribute("YInPort"); // XAttribute XAttr = point.Attribute("X"); // XAttribute YAttr = point.Attribute("Y"); // LEDBox box = new LEDBox(); // box.COMIndex = COMIndexAttr.Value; // box.SenderIndex = Convert.ToByte(SenderIndexAttr.Value); // box.PortIndex = Convert.ToByte(PortIndexAttr.Value); // box.ConnectIndex = Convert.ToByte(ConnectIndexAttr.Value); // box.Width = Convert.ToDouble(WidthAttr.Value); // box.Height = Convert.ToDouble(HeightAttr.Value); // box.XInPort = Convert.ToUInt16(XInPortAttr.Value); // box.YInPort = Convert.ToUInt16(YInPortAttr.Value); // box.X = Convert.ToUInt16(XAttr.Value); // box.Y = Convert.ToUInt16(YAttr.Value); // BoxViewModel boxViewModel = new BoxViewModel(box); // boxViewModelList.Add(boxViewModel); // } //} #endregion //elementViewModel.LEDBoxes = boxViewModelList; //boxGroupViewModelList.Add(elementViewModel); } } return boxGroupViewModelList; }