예제 #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
        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);
        }