예제 #1
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));
        }
예제 #2
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;
        }
예제 #3
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);
        }
예제 #4
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);
        }
예제 #5
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);
        }
예제 #6
0
파일: Program.cs 프로젝트: fangxunqing/mars
 /// <summary>
 ///
 /// </summary>
 /// <param name="database"></param>
 /// <param name="type"></param>
 /// <param name="tag"></param>
 /// <param name="link"></param>
 /// <param name="repeat"></param>
 private static void AddTag(Database database, string type, string tag, string link, int repeat)
 {
     if (type == "double")
     {
         if (repeat == 1)
         {
             var vtag = new Cdy.Tag.DoubleTag()
             {
                 Name = tag, LinkAddress = link
             };
             database.RealDatabase.Append(vtag);
             database.HisDatabase.AddHisTags(new Cdy.Tag.HisTag()
             {
                 Id = vtag.Id, TagType = TagType.Double, Type = RecordType.Timer, Circle = 1000, CompressType = 0
             });
         }
         else
         {
             for (int j = 0; j < repeat; j++)
             {
                 var vtag = new Cdy.Tag.DoubleTag()
                 {
                     Name = tag + j, LinkAddress = link
                 };
                 database.RealDatabase.Append(vtag);
                 database.HisDatabase.AddHisTags(new Cdy.Tag.HisTag()
                 {
                     Id = vtag.Id, TagType = TagType.Double, Type = RecordType.Timer, Circle = 1000, CompressType = 0
                 });
             }
         }
     }
     else if (type == "float")
     {
         if (repeat == 1)
         {
             var vtag = new Cdy.Tag.FloatTag()
             {
                 Name = tag, LinkAddress = link
             };
             database.RealDatabase.Append(vtag);
             database.HisDatabase.AddHisTags(new Cdy.Tag.HisTag()
             {
                 Id = vtag.Id, TagType = TagType.Float, Type = RecordType.Timer, Circle = 1000, CompressType = 0
             });
         }
         else
         {
             for (int j = 0; j < repeat; j++)
             {
                 var vtag = new Cdy.Tag.FloatTag()
                 {
                     Name = tag + j, LinkAddress = link
                 };
                 database.RealDatabase.Append(vtag);
                 database.HisDatabase.AddHisTags(new Cdy.Tag.HisTag()
                 {
                     Id = vtag.Id, TagType = TagType.Float, Type = RecordType.Timer, Circle = 1000, CompressType = 0
                 });
             }
         }
     }
     else if (type == "int")
     {
         if (repeat == 1)
         {
             var vtag = new Cdy.Tag.IntTag()
             {
                 Name = tag, LinkAddress = link
             };
             database.RealDatabase.Append(vtag);
             database.HisDatabase.AddHisTags(new Cdy.Tag.HisTag()
             {
                 Id = vtag.Id, TagType = TagType.Int, Type = RecordType.Timer, Circle = 1000, CompressType = 0
             });
         }
         else
         {
             for (int j = 0; j < repeat; j++)
             {
                 var vtag = new Cdy.Tag.IntTag()
                 {
                     Name = tag + j, LinkAddress = link
                 };
                 database.RealDatabase.Append(vtag);
                 database.HisDatabase.AddHisTags(new Cdy.Tag.HisTag()
                 {
                     Id = vtag.Id, TagType = TagType.Int, Type = RecordType.Timer, Circle = 1000, CompressType = 0
                 });
             }
         }
     }
     else if (type == "uint")
     {
         if (repeat == 1)
         {
             var vtag = new Cdy.Tag.UIntTag()
             {
                 Name = tag, LinkAddress = link
             };
             database.RealDatabase.Append(vtag);
             database.HisDatabase.AddHisTags(new Cdy.Tag.HisTag()
             {
                 Id = vtag.Id, TagType = TagType.UInt, Type = RecordType.Timer, Circle = 1000, CompressType = 0
             });
         }
         else
         {
             for (int j = 0; j < repeat; j++)
             {
                 var vtag = new Cdy.Tag.UIntTag()
                 {
                     Name = tag + j, LinkAddress = link
                 };
                 database.RealDatabase.Append(vtag);
                 database.HisDatabase.AddHisTags(new Cdy.Tag.HisTag()
                 {
                     Id = vtag.Id, TagType = TagType.UInt, Type = RecordType.Timer, Circle = 1000, CompressType = 0
                 });
             }
         }
     }
     else if (type == "long")
     {
         if (repeat == 1)
         {
             var vtag = new Cdy.Tag.LongTag()
             {
                 Name = tag, LinkAddress = link
             };
             database.RealDatabase.Append(vtag);
             database.HisDatabase.AddHisTags(new Cdy.Tag.HisTag()
             {
                 Id = vtag.Id, TagType = TagType.Long, Type = RecordType.Timer, Circle = 1000, CompressType = 0
             });
         }
         else
         {
             for (int j = 0; j < repeat; j++)
             {
                 var vtag = new Cdy.Tag.LongTag()
                 {
                     Name = tag + j, LinkAddress = link
                 };
                 database.RealDatabase.Append(vtag);
                 database.HisDatabase.AddHisTags(new Cdy.Tag.HisTag()
                 {
                     Id = vtag.Id, TagType = TagType.Long, Type = RecordType.Timer, Circle = 1000, CompressType = 0
                 });
             }
         }
     }
     else if (type == "ulong")
     {
         if (repeat == 1)
         {
             var vtag = new Cdy.Tag.ULongTag()
             {
                 Name = tag, LinkAddress = link
             };
             database.RealDatabase.Append(vtag);
             database.HisDatabase.AddHisTags(new Cdy.Tag.HisTag()
             {
                 Id = vtag.Id, TagType = TagType.ULong, Type = RecordType.Timer, Circle = 1000, CompressType = 0
             });
         }
         else
         {
             for (int j = 0; j < repeat; j++)
             {
                 var vtag = new Cdy.Tag.ULongTag()
                 {
                     Name = tag + j, LinkAddress = link
                 };
                 database.RealDatabase.Append(vtag);
                 database.HisDatabase.AddHisTags(new Cdy.Tag.HisTag()
                 {
                     Id = vtag.Id, TagType = TagType.ULong, Type = RecordType.Timer, Circle = 1000, CompressType = 0
                 });
             }
         }
     }
     else if (type == "short")
     {
         if (repeat == 1)
         {
             var vtag = new Cdy.Tag.ShortTag()
             {
                 Name = tag, LinkAddress = link
             };
             database.RealDatabase.Append(vtag);
             database.HisDatabase.AddHisTags(new Cdy.Tag.HisTag()
             {
                 Id = vtag.Id, TagType = TagType.Short, Type = RecordType.Timer, Circle = 1000, CompressType = 0
             });
         }
         else
         {
             for (int j = 0; j < repeat; j++)
             {
                 var vtag = new Cdy.Tag.ShortTag()
                 {
                     Name = tag + j, LinkAddress = link
                 };
                 database.RealDatabase.Append(vtag);
                 database.HisDatabase.AddHisTags(new Cdy.Tag.HisTag()
                 {
                     Id = vtag.Id, TagType = TagType.Short, Type = RecordType.Timer, Circle = 1000, CompressType = 0
                 });
             }
         }
     }
     else if (type == "ushort")
     {
         if (repeat == 1)
         {
             var vtag = new Cdy.Tag.UShortTag()
             {
                 Name = tag, LinkAddress = link
             };
             database.RealDatabase.Append(vtag);
             database.HisDatabase.AddHisTags(new Cdy.Tag.HisTag()
             {
                 Id = vtag.Id, TagType = TagType.UShort, Type = RecordType.Timer, Circle = 1000, CompressType = 0
             });
         }
         else
         {
             for (int j = 0; j < repeat; j++)
             {
                 var vtag = new Cdy.Tag.UShortTag()
                 {
                     Name = tag + j, LinkAddress = link
                 };
                 database.RealDatabase.Append(vtag);
                 database.HisDatabase.AddHisTags(new Cdy.Tag.HisTag()
                 {
                     Id = vtag.Id, TagType = TagType.UShort, Type = RecordType.Timer, Circle = 1000, CompressType = 0
                 });
             }
         }
     }
     else if (type == "bool")
     {
         if (repeat == 1)
         {
             var vtag = new Cdy.Tag.BoolTag()
             {
                 Name = tag, LinkAddress = link
             };
             database.RealDatabase.Append(vtag);
             database.HisDatabase.AddHisTags(new Cdy.Tag.HisTag()
             {
                 Id = vtag.Id, TagType = TagType.Bool, Type = RecordType.Timer, Circle = 1000, CompressType = 0
             });
         }
         else
         {
             for (int j = 0; j < repeat; j++)
             {
                 var vtag = new Cdy.Tag.BoolTag()
                 {
                     Name = tag + j, LinkAddress = link
                 };
                 database.RealDatabase.Append(vtag);
                 database.HisDatabase.AddHisTags(new Cdy.Tag.HisTag()
                 {
                     Id = vtag.Id, TagType = TagType.Bool, Type = RecordType.Timer, Circle = 1000, CompressType = 0
                 });
             }
         }
     }
     else if (type == "string")
     {
         if (repeat == 1)
         {
             var vtag = new Cdy.Tag.StringTag()
             {
                 Name = tag, LinkAddress = link
             };
             database.RealDatabase.Append(vtag);
             database.HisDatabase.AddHisTags(new Cdy.Tag.HisTag()
             {
                 Id = vtag.Id, TagType = TagType.String, Type = RecordType.Timer, Circle = 1000, CompressType = 0
             });
         }
         else
         {
             for (int j = 0; j < repeat; j++)
             {
                 var vtag = new Cdy.Tag.StringTag()
                 {
                     Name = tag + j, LinkAddress = link
                 };
                 database.RealDatabase.Append(vtag);
                 database.HisDatabase.AddHisTags(new Cdy.Tag.HisTag()
                 {
                     Id = vtag.Id, TagType = TagType.String, Type = RecordType.Timer, Circle = 1000, CompressType = 0
                 });
             }
         }
     }
     else if (type == "datetime")
     {
         if (repeat == 1)
         {
             var vtag = new Cdy.Tag.DateTimeTag()
             {
                 Name = tag, LinkAddress = link
             };
             database.RealDatabase.Append(vtag);
             database.HisDatabase.AddHisTags(new Cdy.Tag.HisTag()
             {
                 Id = vtag.Id, TagType = TagType.String, Type = RecordType.Timer, Circle = 1000, CompressType = 0
             });
         }
         else
         {
             for (int j = 0; j < repeat; j++)
             {
                 var vtag = new Cdy.Tag.DateTimeTag()
                 {
                     Name = tag + j, LinkAddress = link
                 };
                 database.RealDatabase.Append(vtag);
                 database.HisDatabase.AddHisTags(new Cdy.Tag.HisTag()
                 {
                     Id = vtag.Id, TagType = TagType.String, Type = RecordType.Timer, Circle = 1000, CompressType = 0
                 });
             }
         }
     }
 }
예제 #7
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));
        }