예제 #1
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="tag"></param>
        public bool Add(Tagbase tag)
        {
            if (!Tags.ContainsKey(tag.Id))
            {
                Tags.Add(tag.Id, tag);
                CheckAndAddGroup(tag.Group)?.Tags.Add(tag);
                MaxId = Math.Max(MaxId, tag.Id);

                if (!NamedTags.ContainsKey(tag.Name))
                {
                    NamedTags.Add(tag.Name, tag);
                }
                else
                {
                    NamedTags[tag.Name] = tag;
                }

                return(true);
            }
            else
            {
                Tags[tag.Id] = tag;

                if (!NamedTags.ContainsKey(tag.Name))
                {
                    NamedTags.Add(tag.Name, tag);
                }
                else
                {
                    NamedTags[tag.Name] = tag;
                }
            }
            return(false);
        }
예제 #2
0
        /// <summary>
        /// 添加或更新
        /// </summary>
        /// <param name="id"></param>
        public void AddOrUpdate(Tagbase tag)
        {
            if (!Tags.ContainsKey(tag.Id))
            {
                Tags.Add(tag.Id, tag);
                CheckAndAddGroup(tag.Group)?.Tags.Add(tag);

                if (!NamedTags.ContainsKey(tag.Name))
                {
                    NamedTags.Add(tag.Name, tag);
                }
                else
                {
                    NamedTags[tag.Name] = tag;
                }
            }
            else
            {
                Tags[tag.Id] = tag;

                if (!NamedTags.ContainsKey(tag.Name))
                {
                    NamedTags.Add(tag.Name, tag);
                }
                else
                {
                    NamedTags[tag.Name] = tag;
                }
            }
            MaxId = Math.Max(MaxId, tag.Id);
        }
예제 #3
0
        public static XElement SaveToXML(this Tagbase tag)
        {
            XElement xe = new XElement("Tag");

            xe.SetAttributeValue("Id", tag.Id);
            xe.SetAttributeValue("Name", tag.Name);
            xe.SetAttributeValue("Type", (int)tag.Type);
            xe.SetAttributeValue("Group", tag.Group);
            xe.SetAttributeValue("Desc", tag.Desc);
            xe.SetAttributeValue("LinkAddress", tag.LinkAddress);
            xe.SetAttributeValue("ReadWriteType", (int)tag.ReadWriteType);
            if (tag.Conveter != null)
            {
                xe.SetAttributeValue("Conveter", tag.Conveter.Name + ":" + tag.Conveter.SaveToString());
            }
            if (tag is NumberTagBase)
            {
                xe.SetAttributeValue("MaxValue", (tag as NumberTagBase).MaxValue);
                xe.SetAttributeValue("MinValue", (tag as NumberTagBase).MinValue);
            }
            if (tag is FloatingTagBase)
            {
                xe.SetAttributeValue("Precision", (tag as FloatingTagBase).Precision);
            }
            return(xe);
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool RemoveWithoutGroupProcess(Tagbase tag)
        {
            Tags.Remove(tag.Id);
            NamedTags.Remove(tag.FullName);
            IsDirty = true;

            MinId = Tags.Keys.Count > 0 ? Tags.Keys.Min() : 0;

            return(true);
        }
예제 #5
0
 /// <summary>
 /// 添加或更新
 /// </summary>
 /// <param name="id"></param>
 public void AddOrUpdate(Tagbase tag)
 {
     if (!NamedTags.ContainsKey(tag.FullName))
     {
         Append(tag);
     }
     else
     {
         Update(tag.FullName, tag);
     }
 }
예제 #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="tag"></param>
 /// <returns></returns>
 public bool SupportTag(Tagbase tag)
 {
     if (tag is NumberTagBase)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #7
0
파일: Tagbase.cs 프로젝트: fangxunqing/mars
        public static XElement SaveToXML(this Tagbase tag)
        {
            XElement xe = new XElement("Tag");

            xe.SetAttributeValue("Id", tag.Id);
            xe.SetAttributeValue("Name", tag.Name);
            xe.SetAttributeValue("Type", (int)tag.Type);
            xe.SetAttributeValue("Group", tag.Group);
            xe.SetAttributeValue("Desc", tag.Desc);
            xe.SetAttributeValue("LinkAddress", tag.LinkAddress);
            return(xe);
        }
예제 #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sname"></param>
 /// <param name="tag"></param>
 public void Update(string sname, Tagbase tag)
 {
     if (NamedTags.ContainsKey(sname))
     {
         var vtag = NamedTags[sname];
         var vid  = vtag.Id;
         tag.Id           = vid;
         NamedTags[sname] = tag;
         Tags[vid]        = tag;
         IsDirty          = true;
     }
 }
예제 #9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="id"></param>
 /// <param name="tag"></param>
 public void UpdateById(int id, Tagbase tag)
 {
     if (Tags.ContainsKey(id))
     {
         string sname = Tags[id].FullName;
         if (sname != tag.FullName)
         {
             NamedTags.Remove(sname);
             NamedTags.Add(tag.FullName, tag);
         }
         Tags[id] = tag;
         IsDirty  = true;
     }
 }
예제 #10
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="tag"></param>
        public bool Add(Tagbase tag)
        {
            if (!Tags.ContainsKey(tag.Id))
            {
                Tags.Add(tag.Id, tag);
                CheckAndAddGroup(tag.Group)?.Tags.Add(tag);
                MaxId = Math.Max(MaxId, tag.Id);

                tag.UpdateFullName();

                if (!NamedTags.ContainsKey(tag.FullName))
                {
                    NamedTags.Add(tag.FullName, tag);
                }
                else
                {
                    NamedTags[tag.FullName] = tag;
                }
                IsDirty = true;
                return(true);
            }
            else
            {
                var vtag = Tags[tag.Id];

                if (NamedTags.ContainsKey(vtag.FullName))
                {
                    NamedTags.Remove(vtag.FullName);
                }

                Tags[tag.Id] = tag;

                if (!NamedTags.ContainsKey(tag.FullName))
                {
                    NamedTags.Add(tag.FullName, tag);
                }
                else
                {
                    NamedTags[tag.FullName] = tag;
                }
            }
            IsDirty = true;

            MinId = Math.Min(MinId, tag.Id);
            return(false);
        }
예제 #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tag"></param>
        /// <returns>变量在表中的编号</returns>
        public int AddTag(Tagbase tag)
        {
            var vp = mTagCount * TagSize;

            WriteInt(vp, tag.Id);
            WriteString(vp + 4, tag.Name, Encoding.UTF8);
            WriteString(vp + 36, tag.Name, Encoding.UTF8);
            // WriteString(tag.Group, 64);
            WriteByte(vp + 100, (byte)tag.Type);
            WriteByte(vp + 101, (byte)tag.ReadWriteType);
            WriteString(vp + 102, tag.LinkAddress, Encoding.UTF8);
            WriteString(vp + 166, tag.Conveter != null? tag.Conveter.Name:"", Encoding.UTF8);
            if (tag is NumberTagBase)
            {
                WriteDouble(vp + 198, (tag as NumberTagBase).MaxValue);
            }
            else
            {
                WriteDouble(vp + 198, 0);
            }
            if (tag is NumberTagBase)
            {
                WriteDouble(vp + 206, (tag as NumberTagBase).MinValue);
            }
            else
            {
                WriteDouble(vp + 206, 0);
            }

            if (tag is FloatingTagBase)
            {
                WriteByte(vp + 214, (tag as FloatingTagBase).Precision);
            }
            else
            {
                WriteByte(vp + 214, 0);
            }
            WriteString(vp + 215, tag.Conveter != null ? tag.Conveter.Name : "", Encoding.UTF8);

            var re = mTagCount;

            mTagCount++;
            //WriteString(tag.Desc, 128);
            return(re);
        }
예제 #12
0
 /// <summary>
 /// 更改变量所在的组
 /// </summary>
 /// <param name="tag"></param>
 /// <param name="group"></param>
 public void ChangedTagGroup(Tagbase tag, string group)
 {
     if (string.IsNullOrEmpty(tag.Group))
     {
         tag.Group = group;
         CheckAndAddGroup(tag.Group)?.Tags.Add(tag);
     }
     else
     {
         if (Groups.ContainsKey(tag.Group))
         {
             var vv = Groups[tag.Group].Tags;
             if (vv.Contains(tag))
             {
                 vv.Remove(tag);
             }
         }
     }
 }
예제 #13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tag"></param>
        public void Update(Tagbase tag)
        {
            if (Tags.ContainsKey(tag.Id))
            {
                var oldname = Tags[tag.Id].FullName;
                if (oldname != tag.FullName)
                {
                    if (NamedTags.ContainsKey(oldname))
                    {
                        NamedTags.Remove(oldname);
                    }

                    NamedTags.Add(tag.FullName, tag);
                }
                else
                {
                    NamedTags[tag.FullName] = tag;
                }
                Tags[tag.Id] = tag;
                IsDirty      = true;
            }
        }
예제 #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tagType"></param>
        private void ChangeTagType(Cdy.Tag.TagType tagType)
        {
            Cdy.Tag.Tagbase ntag = null;
            switch (tagType)
            {
            case Cdy.Tag.TagType.Bool:
                ntag = new Cdy.Tag.BoolTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                if (mHisTagMode != null)
                {
                    mHisTagMode.TagType = Cdy.Tag.TagType.Bool;
                }
                break;

            case Cdy.Tag.TagType.Byte:
                ntag = new Cdy.Tag.ByteTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                if (mHisTagMode != null)
                {
                    mHisTagMode.TagType = Cdy.Tag.TagType.Byte;
                }
                break;

            case Cdy.Tag.TagType.DateTime:
                ntag = new Cdy.Tag.DateTimeTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                if (mHisTagMode != null)
                {
                    mHisTagMode.TagType = Cdy.Tag.TagType.DateTime;
                }
                break;

            case Cdy.Tag.TagType.Double:
                ntag = new Cdy.Tag.DoubleTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                if (mHisTagMode != null)
                {
                    mHisTagMode.TagType = Cdy.Tag.TagType.Double;
                }
                break;

            case Cdy.Tag.TagType.Float:
                ntag = new Cdy.Tag.FloatTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                if (mHisTagMode != null)
                {
                    mHisTagMode.TagType = Cdy.Tag.TagType.Float;
                }
                break;

            case Cdy.Tag.TagType.Int:
                ntag = new Cdy.Tag.IntTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                if (mHisTagMode != null)
                {
                    mHisTagMode.TagType = Cdy.Tag.TagType.Int;
                }
                break;

            case Cdy.Tag.TagType.Long:
                ntag = new Cdy.Tag.LongTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                if (mHisTagMode != null)
                {
                    mHisTagMode.TagType = Cdy.Tag.TagType.Long;
                }
                break;

            case Cdy.Tag.TagType.Short:
                ntag = new Cdy.Tag.ShortTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                if (mHisTagMode != null)
                {
                    mHisTagMode.TagType = Cdy.Tag.TagType.Short;
                }
                break;

            case Cdy.Tag.TagType.String:
                ntag = new Cdy.Tag.StringTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                if (mHisTagMode != null)
                {
                    mHisTagMode.TagType = Cdy.Tag.TagType.String;
                }
                break;

            case Cdy.Tag.TagType.UInt:
                ntag = new Cdy.Tag.UIntTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                if (mHisTagMode != null)
                {
                    mHisTagMode.TagType = Cdy.Tag.TagType.UInt;
                }
                break;

            case Cdy.Tag.TagType.ULong:
                ntag = new Cdy.Tag.ULongTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                if (mHisTagMode != null)
                {
                    mHisTagMode.TagType = Cdy.Tag.TagType.ULong;
                }
                break;

            case Cdy.Tag.TagType.UShort:
                ntag = new Cdy.Tag.UShortTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                if (mHisTagMode != null)
                {
                    mHisTagMode.TagType = Cdy.Tag.TagType.UShort;
                }
                break;

            case Cdy.Tag.TagType.IntPoint:
                ntag = new Cdy.Tag.IntPointTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                if (mHisTagMode != null)
                {
                    mHisTagMode.TagType = Cdy.Tag.TagType.IntPoint;
                }
                break;

            case Cdy.Tag.TagType.IntPoint3:
                ntag = new Cdy.Tag.IntPoint3Tag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                if (mHisTagMode != null)
                {
                    mHisTagMode.TagType = Cdy.Tag.TagType.IntPoint3;
                }
                break;

            case Cdy.Tag.TagType.UIntPoint:
                ntag = new Cdy.Tag.UIntPointTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                if (mHisTagMode != null)
                {
                    mHisTagMode.TagType = Cdy.Tag.TagType.UIntPoint;
                }
                break;

            case Cdy.Tag.TagType.UIntPoint3:
                ntag = new Cdy.Tag.UIntPoint3Tag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                if (mHisTagMode != null)
                {
                    mHisTagMode.TagType = Cdy.Tag.TagType.UIntPoint3;
                }
                break;

            case Cdy.Tag.TagType.LongPoint:
                ntag = new Cdy.Tag.LongPointTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                if (mHisTagMode != null)
                {
                    mHisTagMode.TagType = Cdy.Tag.TagType.LongPoint;
                }
                break;

            case Cdy.Tag.TagType.LongPoint3:
                ntag = new Cdy.Tag.LongPoint3Tag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                if (mHisTagMode != null)
                {
                    mHisTagMode.TagType = Cdy.Tag.TagType.LongPoint3;
                }
                break;

            case Cdy.Tag.TagType.ULongPoint:
                ntag = new Cdy.Tag.ULongPointTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                if (mHisTagMode != null)
                {
                    mHisTagMode.TagType = Cdy.Tag.TagType.ULongPoint;
                }
                break;

            case Cdy.Tag.TagType.ULongPoint3:
                ntag = new Cdy.Tag.ULongPoint3Tag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                if (mHisTagMode != null)
                {
                    mHisTagMode.TagType = Cdy.Tag.TagType.ULongPoint3;
                }
                break;

            default:
                break;
            }
            if (ntag != null)
            {
                RealTagMode = ntag;
            }
            IsChanged = true;
        }
예제 #15
0
 public TagViewModel(Cdy.Tag.Tagbase realTag, Cdy.Tag.HisTag histag)
 {
     this.mRealTagMode = realTag;
     this.HisTagMode   = histag;
     CheckLinkAddress();
 }
예제 #16
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public TagViewModel Clone()
        {
            Cdy.Tag.Tagbase ntag = null;
            Cdy.Tag.HisTag  htag = null;
            if (mHisTagMode != null)
            {
                htag = new Cdy.Tag.HisTag()
                {
                    Id = mHisTagMode.Id, Circle = mHisTagMode.Circle, MaxValueCountPerSecond = mHisTagMode.MaxValueCountPerSecond, CompressType = mHisTagMode.CompressType, TagType = mHisTagMode.TagType, Type = mHisTagMode.Type
                };

                if (this.mHisTagMode.Parameters != null)
                {
                    htag.Parameters = new Dictionary <string, double>();
                    foreach (var vv in mHisTagMode.Parameters)
                    {
                        htag.Parameters.Add(vv.Key, vv.Value);
                    }
                }
            }

            switch (this.mRealTagMode.Type)
            {
            case Cdy.Tag.TagType.Bool:
                ntag = new Cdy.Tag.BoolTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group, Conveter = mRealTagMode.Conveter != null?mRealTagMode.Conveter.Clone() : null
                };
                break;

            case Cdy.Tag.TagType.Byte:
                ntag = new Cdy.Tag.ByteTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group, Conveter = mRealTagMode.Conveter != null?mRealTagMode.Conveter.Clone() : null
                };

                break;

            case Cdy.Tag.TagType.DateTime:
                ntag = new Cdy.Tag.DateTimeTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group, Conveter = mRealTagMode.Conveter != null?mRealTagMode.Conveter.Clone() : null
                };

                break;

            case Cdy.Tag.TagType.Double:
                ntag = new Cdy.Tag.DoubleTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group, Conveter = mRealTagMode.Conveter != null?mRealTagMode.Conveter.Clone() : null
                };

                break;

            case Cdy.Tag.TagType.Float:
                ntag = new Cdy.Tag.FloatTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group, Conveter = mRealTagMode.Conveter != null?mRealTagMode.Conveter.Clone() : null
                };

                break;

            case Cdy.Tag.TagType.Int:
                ntag = new Cdy.Tag.IntTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group, Conveter = mRealTagMode.Conveter != null?mRealTagMode.Conveter.Clone() : null
                };

                break;

            case Cdy.Tag.TagType.Long:
                ntag = new Cdy.Tag.LongTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group, Conveter = mRealTagMode.Conveter != null?mRealTagMode.Conveter.Clone() : null
                };

                break;

            case Cdy.Tag.TagType.Short:
                ntag = new Cdy.Tag.ShortTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group, Conveter = mRealTagMode.Conveter != null?mRealTagMode.Conveter.Clone() : null
                };

                break;

            case Cdy.Tag.TagType.String:
                ntag = new Cdy.Tag.StringTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group, Conveter = mRealTagMode.Conveter != null?mRealTagMode.Conveter.Clone() : null
                };

                break;

            case Cdy.Tag.TagType.UInt:
                ntag = new Cdy.Tag.UIntTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group, Conveter = mRealTagMode.Conveter != null?mRealTagMode.Conveter.Clone() : null
                };

                break;

            case Cdy.Tag.TagType.ULong:
                ntag = new Cdy.Tag.ULongTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group, Conveter = mRealTagMode.Conveter != null?mRealTagMode.Conveter.Clone() : null
                };

                break;

            case Cdy.Tag.TagType.UShort:
                ntag = new Cdy.Tag.UShortTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group, Conveter = mRealTagMode.Conveter != null?mRealTagMode.Conveter.Clone() : null
                };

                break;

            case Cdy.Tag.TagType.IntPoint:
                ntag = new Cdy.Tag.IntPointTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                if (mHisTagMode != null)
                {
                    mHisTagMode.TagType = Cdy.Tag.TagType.IntPoint;
                }
                break;

            case Cdy.Tag.TagType.IntPoint3:
                ntag = new Cdy.Tag.IntPoint3Tag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                if (mHisTagMode != null)
                {
                    mHisTagMode.TagType = Cdy.Tag.TagType.IntPoint3;
                }
                break;

            case Cdy.Tag.TagType.UIntPoint:
                ntag = new Cdy.Tag.UIntPointTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                if (mHisTagMode != null)
                {
                    mHisTagMode.TagType = Cdy.Tag.TagType.UIntPoint;
                }
                break;

            case Cdy.Tag.TagType.UIntPoint3:
                ntag = new Cdy.Tag.UIntPoint3Tag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                if (mHisTagMode != null)
                {
                    mHisTagMode.TagType = Cdy.Tag.TagType.UIntPoint3;
                }
                break;

            case Cdy.Tag.TagType.LongPoint:
                ntag = new Cdy.Tag.LongPointTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                if (mHisTagMode != null)
                {
                    mHisTagMode.TagType = Cdy.Tag.TagType.LongPoint;
                }
                break;

            case Cdy.Tag.TagType.LongPoint3:
                ntag = new Cdy.Tag.LongPoint3Tag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                if (mHisTagMode != null)
                {
                    mHisTagMode.TagType = Cdy.Tag.TagType.LongPoint3;
                }
                break;

            case Cdy.Tag.TagType.ULongPoint:
                ntag = new Cdy.Tag.ULongPointTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                if (mHisTagMode != null)
                {
                    mHisTagMode.TagType = Cdy.Tag.TagType.ULongPoint;
                }
                break;

            case Cdy.Tag.TagType.ULongPoint3:
                ntag = new Cdy.Tag.ULongPoint3Tag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                if (mHisTagMode != null)
                {
                    mHisTagMode.TagType = Cdy.Tag.TagType.ULongPoint3;
                }
                break;

            default:
                break;
            }

            if (IsNumberTag)
            {
                (ntag as NumberTagBase).MaxValue = (mRealTagMode as NumberTagBase).MaxValue;
                (ntag as NumberTagBase).MinValue = (mRealTagMode as NumberTagBase).MinValue;
            }

            if (IsFloatingTag)
            {
                (ntag as FloatingTagBase).Precision = (mRealTagMode as FloatingTagBase).Precision;
            }

            return(new TagViewModel(ntag, htag));
        }
예제 #17
0
파일: Tagbase.cs 프로젝트: fangxunqing/mars
        public static Tagbase LoadTagFromXML(this XElement xe)
        {
            TagType tp = (TagType)int.Parse(xe.Attribute("Type").Value);
            Tagbase re = null;

            switch (tp)
            {
            case TagType.Bool:
                re = new BoolTag();
                break;

            case TagType.Byte:
                re = new ByteTag();
                break;

            case TagType.Short:
                re = new ShortTag();
                break;

            case TagType.UShort:
                re = new UShortTag();
                break;

            case TagType.Int:
                re = new IntTag();
                break;

            case TagType.UInt:
                re = new UIntTag();
                break;

            case TagType.Long:
                re = new LongTag();
                break;

            case TagType.ULong:
                re = new ULongTag();
                break;

            case TagType.Float:
                re = new FloatTag();
                break;

            case TagType.Double:
                re = new DoubleTag();
                break;

            case TagType.String:
                re = new StringTag();
                break;

            case TagType.DateTime:
                re = new DateTimeTag();
                break;
            }
            re.Id    = int.Parse(xe.Attribute("Id").Value);
            re.Name  = xe.Attribute("Name").Value;
            re.Group = xe.Attribute("Group") != null?xe.Attribute("Group").Value : "";

            re.Desc = xe.Attribute("Desc") != null?xe.Attribute("Desc").Value : "";

            re.LinkAddress = xe.Attribute("LinkAddress") != null?xe.Attribute("LinkAddress").Value : "";

            return(re);
        }
예제 #18
0
파일: Database.cs 프로젝트: cdy816/mars
        public Tagbase ConvertToTagbase()
        {
            Cdy.Tag.Tagbase re = null;
            switch (this.Type)
            {
            case (int)(Cdy.Tag.TagType.Bool):
                re = new Cdy.Tag.BoolTag();
                break;

            case (int)(Cdy.Tag.TagType.Byte):
                re = new Cdy.Tag.ByteTag();
                break;

            case (int)(Cdy.Tag.TagType.DateTime):
                re = new Cdy.Tag.DateTimeTag();
                break;

            case (int)(Cdy.Tag.TagType.Double):
                re = new Cdy.Tag.DoubleTag();
                break;

            case (int)(Cdy.Tag.TagType.Float):
                re = new Cdy.Tag.FloatTag();
                break;

            case (int)(Cdy.Tag.TagType.Int):
                re = new Cdy.Tag.IntTag();
                break;

            case (int)(Cdy.Tag.TagType.UInt):
                re = new Cdy.Tag.UIntTag();
                break;

            case (int)(Cdy.Tag.TagType.ULong):
                re = new Cdy.Tag.ULongTag();
                break;

            case (int)(Cdy.Tag.TagType.UShort):
                re = new Cdy.Tag.UShortTag();
                break;

            case (int)(Cdy.Tag.TagType.Long):
                re = new Cdy.Tag.LongTag();
                break;

            case (int)(Cdy.Tag.TagType.Short):
                re = new Cdy.Tag.ShortTag();
                break;

            case (int)(Cdy.Tag.TagType.String):
                re = new Cdy.Tag.StringTag();
                break;
            }
            if (re != null)
            {
                re.Name          = this.Name;
                re.LinkAddress   = this.LinkAddress;
                re.Group         = this.Group;
                re.Desc          = this.Desc;
                re.Id            = (int)this.Id;
                re.ReadWriteType = (Cdy.Tag.ReadWriteMode) this.ReadWriteType;
                if (!string.IsNullOrEmpty(this.Convert))
                {
                    re.Conveter = this.Convert.DeSeriseToValueConvert();
                }
                if (re is Cdy.Tag.NumberTagBase)
                {
                    (re as Cdy.Tag.NumberTagBase).MaxValue = this.MaxValue;
                    (re as Cdy.Tag.NumberTagBase).MinValue = this.MinValue;
                }

                if (re is Cdy.Tag.FloatingTagBase)
                {
                    (re as Cdy.Tag.FloatingTagBase).Precision = (byte)this.Precision;
                }
            }

            return(re);
        }
예제 #19
0
 /// <summary>
 /// 追加新的变量
 /// </summary>
 /// <param name="tag"></param>
 /// <returns></returns>
 public bool Append(Tagbase tag)
 {
     tag.Id = ++MaxId;
     MinId  = Math.Min(MinId, tag.Id);
     return(Add(tag));
 }
예제 #20
0
 public static Tagbase Clone(this Tagbase tag)
 {
     return(tag.SaveToXML().LoadTagFromXML());
 }
예제 #21
0
        public static Tagbase LoadTagFromXML(this XElement xe)
        {
            TagType tp = (TagType)int.Parse(xe.Attribute("Type").Value);
            Tagbase re = null;

            switch (tp)
            {
            case TagType.Bool:
                re = new BoolTag();
                break;

            case TagType.Byte:
                re = new ByteTag();
                break;

            case TagType.Short:
                re = new ShortTag();
                break;

            case TagType.UShort:
                re = new UShortTag();
                break;

            case TagType.Int:
                re = new IntTag();
                break;

            case TagType.UInt:
                re = new UIntTag();
                break;

            case TagType.Long:
                re = new LongTag();
                break;

            case TagType.ULong:
                re = new ULongTag();
                break;

            case TagType.Float:
                re = new FloatTag();
                break;

            case TagType.Double:
                re = new DoubleTag();
                break;

            case TagType.String:
                re = new StringTag();
                break;

            case TagType.DateTime:
                re = new DateTimeTag();
                break;

            case TagType.IntPoint:
                re = new IntPointTag();
                break;

            case TagType.UIntPoint:
                re = new UIntPointTag();
                break;

            case TagType.LongPoint:
                re = new LongPointTag();
                break;

            case TagType.ULongPoint:
                re = new ULongPointTag();
                break;

            case TagType.IntPoint3:
                re = new IntPoint3Tag();
                break;

            case TagType.UIntPoint3:
                re = new UIntPoint3Tag();
                break;

            case TagType.LongPoint3:
                re = new LongPoint3Tag();
                break;

            case TagType.ULongPoint3:
                re = new ULongPoint3Tag();
                break;
            }
            re.Id    = int.Parse(xe.Attribute("Id").Value);
            re.Name  = xe.Attribute("Name").Value;
            re.Group = xe.Attribute("Group") != null?xe.Attribute("Group").Value : "";

            re.Desc = xe.Attribute("Desc") != null?xe.Attribute("Desc").Value : "";

            re.LinkAddress = xe.Attribute("LinkAddress") != null?xe.Attribute("LinkAddress").Value : "";


            if (xe.Attribute("Conveter") != null)
            {
                var      vres = xe.Attribute("Conveter").Value;
                string[] sval = vres.Split(new char[] { ':' });
                var      vtmp = ValueConvertManager.manager.GetConvert(sval[0]);
                if (vtmp != null)
                {
                    re.Conveter = vtmp.LoadFromString(vres.Replace(sval[0] + ":", ""));
                }
            }

            if (xe.Attribute("ReadWriteType") != null)
            {
                re.ReadWriteType = (ReadWriteMode)int.Parse(xe.Attribute("ReadWriteType").Value);
            }

            if (re is NumberTagBase)
            {
                if (xe.Attribute("MaxValue") != null)
                {
                    (re as NumberTagBase).MaxValue = double.Parse(xe.Attribute("MaxValue").Value);
                }
                if (xe.Attribute("MinValue") != null)
                {
                    (re as NumberTagBase).MinValue = double.Parse(xe.Attribute("MinValue").Value);
                }
            }
            if (re is FloatingTagBase)
            {
                if (xe.Attribute("Precision") != null)
                {
                    (re as FloatingTagBase).Precision = byte.Parse(xe.Attribute("Precision").Value);
                }
            }
            return(re);
        }
예제 #22
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public TagViewModel Clone()
        {
            Cdy.Tag.Tagbase ntag = null;
            Cdy.Tag.HisTag  htag = null;
            if (mHisTagMode != null)
            {
                htag = new Cdy.Tag.HisTag()
                {
                    Id = mHisTagMode.Id, Circle = mHisTagMode.Circle, CompressType = mHisTagMode.CompressType, TagType = mHisTagMode.TagType, Type = mHisTagMode.Type
                };

                if (this.mHisTagMode.Parameters != null)
                {
                    htag.Parameters = new Dictionary <string, double>();
                    foreach (var vv in mHisTagMode.Parameters)
                    {
                        htag.Parameters.Add(vv.Key, vv.Value);
                    }
                }
            }

            switch (this.mRealTagMode.Type)
            {
            case Cdy.Tag.TagType.Bool:
                ntag = new Cdy.Tag.BoolTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };
                break;

            case Cdy.Tag.TagType.Byte:
                ntag = new Cdy.Tag.ByteTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };

                break;

            case Cdy.Tag.TagType.DateTime:
                ntag = new Cdy.Tag.DateTimeTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };

                break;

            case Cdy.Tag.TagType.Double:
                ntag = new Cdy.Tag.DoubleTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };

                break;

            case Cdy.Tag.TagType.Float:
                ntag = new Cdy.Tag.FloatTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };

                break;

            case Cdy.Tag.TagType.Int:
                ntag = new Cdy.Tag.IntTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };

                break;

            case Cdy.Tag.TagType.Long:
                ntag = new Cdy.Tag.LongTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };

                break;

            case Cdy.Tag.TagType.Short:
                ntag = new Cdy.Tag.ShortTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };

                break;

            case Cdy.Tag.TagType.String:
                ntag = new Cdy.Tag.StringTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };

                break;

            case Cdy.Tag.TagType.UInt:
                ntag = new Cdy.Tag.UIntTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };

                break;

            case Cdy.Tag.TagType.ULong:
                ntag = new Cdy.Tag.ULongTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };

                break;

            case Cdy.Tag.TagType.UShort:
                ntag = new Cdy.Tag.UShortTag()
                {
                    Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group
                };

                break;

            default:
                break;
            }
            return(new TagViewModel(ntag, htag));
        }
예제 #23
0
 /// <summary>
 /// 追加新的变量
 /// </summary>
 /// <param name="tag"></param>
 /// <returns></returns>
 public bool Append(Tagbase tag)
 {
     tag.Id = ++MaxId;
     return(Add(tag));
 }