/// <summary> /// /// </summary> /// <param name="xe"></param> /// <returns></returns> public static HisTag LoadHisTagFromXML(this XElement xe) { HisTag hisTag = new HisTag(); hisTag.Id = int.Parse(xe.Attribute("Id").Value); hisTag.Circle = long.Parse(xe.Attribute("Circle").Value); hisTag.Type = (RecordType)(int.Parse(xe.Attribute("Type").Value)); hisTag.TagType = (TagType)(int.Parse(xe.Attribute("TagType").Value)); hisTag.CompressType = int.Parse(xe.Attribute("CompressType").Value); if (xe.Element("Parameters") != null) { Dictionary <string, double> dvals = new Dictionary <string, double>(); foreach (var vv in xe.Element("Parameters").Elements()) { string skey = vv.Attribute("Name").Value; double dval = Convert.ToDouble(vv.Attribute("Value").Value); if (!dvals.ContainsKey(skey)) { dvals.Add(skey, dval); } } hisTag.Parameters = dvals; } //hisTag.CompressParameter1 = float.Parse(xe.Attribute("CompressParameter1").Value); //hisTag.CompressParameter2 = float.Parse(xe.Attribute("CompressParameter2").Value); //hisTag.CompressParameter3 = float.Parse(xe.Attribute("CompressParameter3").Value); return(hisTag); }
/// <summary> /// /// </summary> /// <param name="tag"></param> /// <returns></returns> public static XElement SaveToXML(this HisTag tag) { XElement xe = new XElement("HisTag"); xe.SetAttributeValue("Id", tag.Id); xe.SetAttributeValue("Type", (int)tag.Type); xe.SetAttributeValue("TagType", (int)tag.TagType); xe.SetAttributeValue("Circle", tag.Circle); xe.SetAttributeValue("CompressType", tag.CompressType); if (tag.Parameters != null && tag.Parameters.Count > 0) { XElement para = new XElement("Parameters"); foreach (var vv in tag.Parameters) { var vpp = new XElement("ParameterItem"); vpp.SetAttributeValue("Name", vv.Key.ToString()); vpp.SetAttributeValue("Value", vv.Value.ToString()); para.Add(vpp); } xe.Add(para); } //xe.SetAttributeValue("CompressParameter1", tag.CompressParameter1); //xe.SetAttributeValue("CompressParameter2", tag.CompressParameter2); //xe.SetAttributeValue("CompressParameter3", tag.CompressParameter3); return(xe); }
/// <summary> /// /// </summary> /// <param name="tag"></param> public void AddHisTags(HisTag tag) { if (!HisTags.ContainsKey(tag.Id)) { HisTags.Add(tag.Id, tag); } }
/// <summary> /// /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool Equals(object obj) { HisTag target = obj as HisTag; if (target == null) { return(false); } return(target.Id == this.Id && this.Type == target.Type && this.TagType == target.TagType && this.CompressType == target.CompressType && this.Circle == target.Circle && this.MaxValueCountPerSecond == target.MaxValueCountPerSecond && Compare(this.Parameters, target.Parameters)); }
/// <summary> /// /// </summary> /// <param name="tag"></param> public void AddOrUpdate(HisTag tag) { if (!HisTags.ContainsKey(tag.Id)) { HisTags.Add(tag.Id, tag); } else { HisTags[tag.Id] = tag; } }
public TagViewModel(Cdy.Tag.Tagbase realTag, Cdy.Tag.HisTag histag) { this.mRealTagMode = realTag; this.HisTagMode = histag; CheckLinkAddress(); }
/// <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)); }
/// <summary> /// /// </summary> /// <param name="tag"></param> /// <returns></returns> public bool EqualsTo(HisTag tag) { return(tag.Id == this.Id && this.Type == tag.Type && this.TagType == tag.TagType && this.CompressType == tag.CompressType && this.Circle == tag.Circle && this.MaxValueCountPerSecond == tag.MaxValueCountPerSecond && Compare(this.Parameters, tag.Parameters)); }
/// <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)); }
/// <summary> /// /// </summary> /// <param name="tag"></param> /// <returns></returns> public static HisTag Clone(this HisTag tag) { return(tag.SaveToXML().LoadHisTagFromXML()); }
/// <summary> /// /// </summary> /// <param name="tag"></param> public static void RemoveParameters(this HisTag tag) { tag.Parameters = null; }