Exemplo n.º 1
0
        /// <summary>Adds multiple entities.</summary>
        /// <param name="items">The entities.</param>
        public void AddRange(IEnumerable <TEntity> items)
        {
            foreach (var item in items)
            {
                var c = Get(item.Id);
                if (c != null)
                {
                    _collection.Remove(c);
                }
            }

            _collection.AddRange(items);
        }
        /// <summary>
        /// Reloading collection and calling subscribers - changing collection items
        /// </summary>
        /// <param name="collection"></param>
        /// <param name="data"></param>
        /// <typeparam name="T"></typeparam>
        public static void ReUpload <T>(this MtObservableCollection <T> collection, IEnumerable <T> data)
            where T : AbstractListItem
        {
            foreach (var item in collection.ToArray())
            {
                collection.Remove(item);
            }

            foreach (var item in data)
            {
                collection.Add(item);
            }
        }
Exemplo n.º 3
0
        public void When_item_removed_then_event_is_triggered_with_it()
        {
            //// Arrange
            Given_a_collection_with_multiple_items();

            //// Act
            _collection.Remove("b");

            //// Assert
            Assert.AreEqual(3, _collection.Count);
            Assert.AreEqual(0, _addedItems.Count);
            Assert.AreEqual(1, _removedItems.Count);
            Assert.AreEqual("b", _removedItems[0]);
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="curRollerVo"></param>
        private void running3(RunningRollerVo curRollerVo)
        {
            if (curRollerVo == null)
            {
                throw new Exception("参数 curRollerVo == null");
            }
            if (curRollerVo.BandProduct == null)
            {
                throw new Exception("参数 curRollerVo.BandProduct == null");
            }

            //
            var currentRollerViewModel = curRollerVo.Roller;
            var currentBandingProduct  = curRollerVo.BandProduct;

            // 准备离开
            if (currentRollerViewModel?.BeginOutTrigger != null)
            {
                curRollerVo.StatusDesc = $"等待{curRollerVo.BandProduct.Id}【准备离开】通讯";
                var result =
                    currentRollerViewModel.BeginOutTrigger.GetTargetNode(currentBandingProduct.Product,
                                                                         curRollerVo.RollerKey);
                if (result == null)
                {
                    throw new Exception("返回值为空");
                }
                curRollerVo.StatusDesc = $"完成{curRollerVo.BandProduct.Id}【准备离开】通讯";

                running2_sub(result, currentBandingProduct);
            }

            // 进入下一节滚筒判定
            if (currentBandingProduct.IsPause)
            {
                return;                                                                   // 暂停
            }
            if (currentBandingProduct.CurrentRollerKey == currentBandingProduct.NextNode) // 暂停
            {
                return;
            }

            // 结束(当前的滚筒为结束)
            if (isExit(currentBandingProduct.CurrentRollerKey))
            {
                if (currentBandingProduct?.NextNode != null)
                {
                    throw new Exception(
                              $"板件({currentBandingProduct.Product.ToString()}), 已经到达了出口{currentBandingProduct.CurrentRollerKey},但是下节滚筒为{currentBandingProduct.NextNode}");
                }

                // 离开
                if (currentRollerViewModel?.OutTrigger != null)
                {
                    curRollerVo.StatusDesc = $"等待{curRollerVo.BandProduct.Id}【离开】通讯";
                    var result =
                        currentRollerViewModel.OutTrigger.GetTargetNode(currentBandingProduct.Product,
                                                                        curRollerVo.RollerKey);
                    if (result == null)
                    {
                        throw new Exception($"{curRollerVo.BandProduct.Id}【离开】通讯返回结果为空");
                    }
                    curRollerVo.StatusDesc = $"完成{curRollerVo.BandProduct.Id}【离开】通讯";
                }

                // 离开动作
                curRollerVo.BandProduct = null;
                lock (_lockRunningProducts)
                {
                    if (_runningProducts.Contains(currentBandingProduct) == false)
                    {
                        throw new Exception($"{currentBandingProduct.ToString()} 剔除失败");
                    }
                    _runningProducts.Remove(currentBandingProduct);
                }
                return;
            }
            if (currentBandingProduct.NextNode == null) // 再次验证
            {
                throw new Exception($"板件({currentBandingProduct.Product.ToString()})," +
                                    $"当前滚筒({currentBandingProduct.CurrentRollerKey}),下节滚筒为空!");
            }

            // 下节滚筒
            var nextRolloerVo = _runningRollers.FirstOrDefault(a => a.RollerKey == currentBandingProduct.NextNode);

            if (nextRolloerVo == null)
            {
                throw new Exception($"{curRollerVo.RollerKey} 对应滚筒数据为空!");
            }
            if (nextRolloerVo.HasProduct) // 下一节滚筒有板
            {
                return;
            }
            var nextRollerViewModel = nextRolloerVo.Roller;

            if (currentBandingProduct.IsPause)
            {
                return;
            }

            lock (nextRollerViewModel)
            {
                if (nextRolloerVo.HasProduct) // 下一节滚筒有板
                {
                    return;
                }

                // 触发“离开”监听
                if (currentRollerViewModel?.OutTrigger != null)
                {
                    curRollerVo.StatusDesc = $"等待{curRollerVo.BandProduct.Id}【离开】通讯";
                    var result =
                        currentRollerViewModel.OutTrigger.GetTargetNode(currentBandingProduct.Product,
                                                                        curRollerVo.RollerKey);
                    if (result == null)
                    {
                        throw new Exception($"{curRollerVo.BandProduct.Id}【离开】通讯返回结果为空");
                    }
                    curRollerVo.StatusDesc = $"完成{curRollerVo.BandProduct.Id}【离开】通讯";

                    running2_sub(result, currentBandingProduct);
                }
                Thread.Sleep(500); // 【注意】增加一个延迟,缓解plc轮询数据过快,实际上板件在顶升下降和板件离开某个滚筒都需要一定的时间

                // 流动
                curRollerVo.BandProduct   = null;                                                              // 离开动作
                nextRolloerVo.BandProduct = currentBandingProduct;                                             // 进入动作
                RunningAccessService.SaveLog(nextRolloerVo.RollerKey, currentBandingProduct.Id, DateTime.Now); // 记录历史

                // 开始进入下节滚筒,触发“入板”监听
                if (nextRollerViewModel.InTrigger != null)
                {
                    nextRolloerVo.StatusDesc = $"等待{nextRolloerVo.BandProduct?.Id} 【进入】通讯";
                    var result =
                        nextRollerViewModel.InTrigger.GetTargetNode(currentBandingProduct.Product, nextRolloerVo.RollerKey);
                    if (result == null)
                    {
                        throw new Exception("返回值为空");
                    }
                    nextRolloerVo.StatusDesc = $"完成{nextRolloerVo.BandProduct?.Id} 【进入】通讯";

                    running2_sub(result, currentBandingProduct);
                }
            }
        }