public bool EditTagPosition(Position position)
        {
            TagPosition tagPos = TagPositions.FindByCode(position.Tag);//判断是否存在实时数据

            if (tagPos == null)
            {
                TagPosition tagPosition = new TagPosition(position);
                if (TagPositions.Add(tagPosition))//添加新的实时数据
                {
                    return(true);
                }
                else
                {
                    ErrorMessage = Position.ErrorMessage;
                    return(false);
                }
            }
            else
            {
                tagPos.Edit(position);
                if (TagPositions.Edit(tagPos))//修改实时数据
                {
                    return(true);
                }
                else
                {
                    ErrorMessage = Position.ErrorMessage;
                    return(false);
                }
            }
        }
        private List <TagPosition> EditTagPositionList(List <Position> positions)
        {
            //1.获取列表
            List <TagPosition> tagPosList        = TagPositions.ToList();
            List <TagPosition> changedTagPosList = new List <TagPosition>();

            //2.修改数据
            for (int i = 0; i < positions.Count; i++)
            {
                Position position = positions[i];
                if (position == null)
                {
                    continue;                  //位置信息可能有null
                }
                TagPosition tagPos = tagPosList.Find(item => item.Tag == position.Tag);
                if (tagPos == null)
                {
                    continue;
                }
                tagPos.Edit(position);
                if (!changedTagPosList.Contains(tagPos))
                {
                    changedTagPosList.Add(tagPos);
                }
            }
            return(changedTagPosList);
        }
        public bool AddPositions(List <Position> positions)
        {
            Position.IsAutoSave     = false;
            TagPositions.IsAutoSave = false;

            bool r = true;

            foreach (Position position in positions)
            {
                if (AddPosition(position) == false)
                {
                    r = false;
                    break;
                }
            }

            Position.Save();
            TagPositions.Save();

            Position.IsAutoSave     = true;
            TagPositions.IsAutoSave = true;
            return(r);
        }
        public void AddTagPositionsByTags(List <Tag> tags)
        {
            List <TagPosition> tagPosList = TagPositions.ToList();//事先取出全部到内存中,比每次都到数据库中查询快很多。 100个从6.4s->1.8s,1.8s中主要是第一次查询的一些初始工作
            List <TagPosition> newPosList = new List <TagPosition>();

            foreach (Tag tag in tags)
            {
                //TagPosition tagPos = TagPositions.FindByCode(tag.Code);//100个要2s
                TagPosition tagPos = tagPosList.Find(i => i.Tag == tag.Code);//判断是否存在实时数据
                if (tagPos == null)
                {
                    TagPosition tagPosition = new TagPosition(tag.Code);
                    newPosList.Add(tagPosition);
                }
            }

            //TagPositions.Db.BulkInsert(newPosList);//插件Z.EntityFramework.Extensions功能
            //TagPositions.Db.BulkSaveChanges();

            foreach (TagPosition tp in newPosList)
            {
                TagPositions.Add(tp);
            }
        }
Beispiel #5
0
        private void InitTagPositions()
        {
            Log.InfoStart("InitTagPositions");
            Tag tag1 = new Tag()
            {
                Name = "标签1", Code = "0002"
            };
            Tag tag2 = new Tag()
            {
                Name = "标签2", Code = "0003"
            };
            Tag tag3 = new Tag()
            {
                Name = "标签3", Code = "0004"
            };
            Tag tag4 = new Tag()
            {
                Name = "标签4", Code = "0005"
            };
            Tag tag5 = new Tag()
            {
                Name = "标签5", Code = "0006"
            };
            Tag tag6 = new Tag()
            {
                Name = "标签6", Code = "0007"
            };
            Tag tag7 = new Tag()
            {
                Name = "标签7", Code = "0008"
            };
            Tag tag8 = new Tag()
            {
                Name = "标签8", Code = "0009"
            };
            List <Tag> tags = new List <Tag>()
            {
                tag1, tag2, tag3, tag4, tag5, tag6, tag7, tag8
            };

            Tags.AddRange(tags);


            //TagPosition tagposition1 = new TagPosition() { Tag = "0002", X = -50, Y = -50, Z = -50, Time = 1527754678, Power = 0, Number = 0, Flag = "0:0:0:0:0" };
            //TagPosition tagposition2 = new TagPosition() { Tag = "0003", X = -50, Y = -50, Z = -50, Time = 1527754678, Power = 0, Number = 0, Flag = "0:0:0:0:0" };
            TagPosition tagposition1 = new TagPosition()
            {
                Tag = "0002", X = 2293.5, Y = 2, Z = 1715.5F, Time = 1527754678, Power = 0, Number = 0, Flag = "0:0:0:0:0"
            };
            TagPosition tagposition2 = new TagPosition()
            {
                Tag = "0003", X = 2294.5, Y = 2, Z = 1715.5f, Time = 1527754678, Power = 0, Number = 0, Flag = "0:0:0:0:0"
            };
            TagPosition tagposition3 = new TagPosition()
            {
                Tag = "0004", X = 2295.5, Y = 2, Z = 1715.5F, Time = 1527754678, Power = 0, Number = 0, Flag = "0:0:0:0:0"
            };
            TagPosition tagposition4 = new TagPosition()
            {
                Tag = "0005", X = 2296.5, Y = 2, Z = 1715.5f, Time = 1527754678, Power = 0, Number = 0, Flag = "0:0:0:0:0"
            };
            TagPosition tagposition5 = new TagPosition()
            {
                Tag = "0006", X = 2297.5, Y = 2, Z = 1715.5F, Time = 1527754678, Power = 0, Number = 0, Flag = "0:0:0:0:0"
            };
            TagPosition tagposition6 = new TagPosition()
            {
                Tag = "0007", X = 2298.5, Y = 2, Z = 1715.5F, Time = 1527754678, Power = 0, Number = 0, Flag = "0:0:0:0:0"
            };
            TagPosition tagposition7 = new TagPosition()
            {
                Tag = "0008", X = 2299.5, Y = 2, Z = 1715.5f, Time = 1527754678, Power = 0, Number = 0, Flag = "0:0:0:0:0"
            };
            TagPosition tagposition8 = new TagPosition()
            {
                Tag = "0009", X = 2300.5, Y = 2, Z = 1715.5F, Time = 1527754678, Power = 0, Number = 0, Flag = "0:0:0:0:0"
            };

            List <TagPosition> tagpositions = new List <TagPosition>()
            {
                tagposition1, tagposition2, tagposition3, tagposition4, tagposition5, tagposition6, tagposition7, tagposition8
            };

            TagPositions.AddRange(tagpositions);

            Position position1 = new Position()
            {
                Tag = "002", X = -50, Y = -50, Z = -50, Time = 1527754678, Power = 0, Number = 0, Flag = "0:0:0:0:0"
            };
            Position position2 = new Position()
            {
                Tag = "002", X = 0, Y = 0, Z = 0, Time = 1527756478, Power = 0, Number = 0, Flag = "0:0:0:0:0"
            };
            Position position3 = new Position()
            {
                Tag = "002", X = 50, Y = 50, Z = 50, Time = 1527758278, Power = 0, Number = 0, Flag = "0:0:0:0:0"
            };
            Position position4 = new Position()
            {
                Tag = "002", X = 100, Y = 100, Z = 100, Time = 1527760078, Power = 0, Number = 0, Flag = "0:0:0:0:1"
            };
            Position position5 = new Position()
            {
                Tag = "002", X = 150, Y = 150, Z = 150, Time = 1527761878, Power = 0, Number = 0, Flag = "0:0:0:0:0"
            };
            Position position6 = new Position()
            {
                Tag = "002", X = 200, Y = 200, Z = 200, Time = 1527763678, Power = 0, Number = 0, Flag = "0:0:0:0:0"
            };
            Position position7 = new Position()
            {
                Tag = "002", X = 250, Y = 250, Z = 250, Time = 1527765478, Power = 0, Number = 0, Flag = "0:0:0:0:0"
            };
            Position position8 = new Position()
            {
                Tag = "002", X = 300, Y = 300, Z = 300, Time = 1527767278, Power = 0, Number = 0, Flag = "0:0:0:0:1"
            };
            Position position9 = new Position()
            {
                Tag = "002", X = 350, Y = 350, Z = 350, Time = 1527769078, Power = 0, Number = 0, Flag = "0:0:0:0:0"
            };
            Position position10 = new Position()
            {
                Tag = "002", X = 400, Y = 400, Z = 400, Time = 1527770878, Power = 0, Number = 0, Flag = "0:0:0:0:0"
            };
            Position position11 = new Position()
            {
                Tag = "002", X = 500, Y = 500, Z = 450, Time = 1527772678, Power = 0, Number = 0, Flag = "0:0:0:0:1"
            };
            Position position12 = new Position()
            {
                Tag = "002", X = 600, Y = 600, Z = 500, Time = 1527774478, Power = 0, Number = 0, Flag = "0:0:0:0:0"
            };
            Position position13 = new Position()
            {
                Tag = "002", X = 700, Y = 700, Z = 550, Time = 1527776278, Power = 0, Number = 0, Flag = "0:0:0:0:0"
            };
            Position position14 = new Position()
            {
                Tag = "002", X = 800, Y = 800, Z = 600, Time = 1527778078, Power = 0, Number = 0, Flag = "0:0:0:0:0"
            };
            Position position15 = new Position()
            {
                Tag = "002", X = 900, Y = 900, Z = 650, Time = 1527779878, Power = 0, Number = 0, Flag = "0:0:0:0:1"
            };
            Position position16 = new Position()
            {
                Tag = "002", X = 1100, Y = 1100, Z = 700, Time = 1527781678, Power = 0, Number = 0, Flag = "0:0:0:0:0"
            };
            Position position17 = new Position()
            {
                Tag = "002", X = 1200, Y = 1200, Z = 750, Time = 1527783478, Power = 0, Number = 0, Flag = "0:0:0:0:0"
            };
            Position position18 = new Position()
            {
                Tag = "002", X = 1300, Y = 1300, Z = 800, Time = 1527785278, Power = 0, Number = 0, Flag = "0:0:0:0:0"
            };
            Position position19 = new Position()
            {
                Tag = "002", X = 1400, Y = 1400, Z = 850, Time = 1527787078, Power = 0, Number = 0, Flag = "0:0:0:0:0"
            };
            Position position20 = new Position()
            {
                Tag = "002", X = 1500, Y = 1500, Z = 900, Time = 1527788878, Power = 0, Number = 0, Flag = "0:0:0:0:0"
            };
            List <Position> positions = new List <Position>()
            {
                position1, position2, position3, position4, position5, position6, position7, position8, position9, position10, position11, position12, position13, position14, position15, position16, position17, position18, position19, position20
            };

            Position.AddRange(positions);
            Log.InfoEnd("InitTagPositions");
        }