Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="val"></param>
        public static TagViewModel LoadFromCSVString(string val)
        {
            string[]        stmp    = val.Split(new char[] { ',' });
            Cdy.Tag.TagType tp      = (Cdy.Tag.TagType)Enum.Parse(typeof(Cdy.Tag.TagType), stmp[4]);
            var             realtag = TagTypeExtends.GetTag(tp);

            realtag.Id            = int.Parse(stmp[0]);
            realtag.Name          = stmp[1];
            realtag.Desc          = stmp[2];
            realtag.Group         = stmp[3];
            realtag.LinkAddress   = stmp[5];
            realtag.ReadWriteType = (ReadWriteMode)(int.Parse(stmp[6]));
            if (stmp[7] != null)
            {
                realtag.Conveter = stmp[7].DeSeriseToValueConvert();
            }

            if (realtag is NumberTagBase)
            {
                (realtag as NumberTagBase).MaxValue = double.Parse(stmp[8], System.Globalization.NumberStyles.Any);
                (realtag as NumberTagBase).MinValue = double.Parse(stmp[9], System.Globalization.NumberStyles.Any);
            }

            if (realtag is FloatingTagBase)
            {
                (realtag as FloatingTagBase).Precision = byte.Parse(stmp[10]);
            }
            if (stmp.Length > 11)
            {
                Cdy.Tag.HisTag histag = new HisTag();
                histag.Type = (Cdy.Tag.RecordType)Enum.Parse(typeof(Cdy.Tag.RecordType), stmp[11]);

                histag.Circle                 = int.Parse(stmp[12]);
                histag.CompressType           = int.Parse(stmp[13]);
                histag.Parameters             = new Dictionary <string, double>();
                histag.TagType                = realtag.Type;
                histag.Id                     = realtag.Id;
                histag.MaxValueCountPerSecond = short.Parse(stmp[14]);

                for (int i = 15; i < stmp.Length; i++)
                {
                    string skey = stmp[i];
                    if (string.IsNullOrEmpty(skey))
                    {
                        break;
                    }
                    double dval = double.Parse(stmp[i + 1]);

                    if (!histag.Parameters.ContainsKey(skey))
                    {
                        histag.Parameters.Add(skey, dval);
                    }

                    i++;
                }
                return(new TagViewModel(realtag, histag));
            }

            return(new TagViewModel(realtag, null));
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tag"></param>
        /// <param name="parameterName"></param>
        /// <param name="value"></param>
        private static void UpdateHisTagParameter(HisTag tag, string parameterName, string value)
        {
            switch (parameterName)
            {
            case "type":
                tag.Type = (RecordType)(int.Parse(value));
                break;

            case "circle":
                tag.Circle = long.Parse(value);
                break;

            case "compresstype":
                tag.CompressType = int.Parse(value);
                break;

            case "parameters":
                var vals = value.Split(new char[';']);
                foreach (var vv in vals)
                {
                    string[] sval = vv.Split(new char['=']);
                    tag.Parameters.Add(sval[0], double.Parse(sval[1]));
                }
                break;
            }
        }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="mRealTagMode"></param>
        /// <param name="mHisTagMode"></param>
        /// <returns></returns>
        public static string SaveToCSVString(Tagbase mRealTagMode, HisTag mHisTagMode)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(mRealTagMode.Id + ",");
            sb.Append(mRealTagMode.Name + ",");
            sb.Append(mRealTagMode.Desc + ",");
            sb.Append(mRealTagMode.Group + ",");
            sb.Append(mRealTagMode.Type + ",");
            sb.Append(mRealTagMode.LinkAddress + ",");
            if (mHisTagMode != null)
            {
                sb.Append(mHisTagMode.Type + ",");
                sb.Append(mHisTagMode.Circle + ",");
                sb.Append(mHisTagMode.CompressType + ",");
                if (mHisTagMode.Parameters != null)
                {
                    foreach (var vv in mHisTagMode.Parameters)
                    {
                        sb.Append(vv.Key + ",");
                        sb.Append(vv.Value + ",");
                    }
                }
            }
            sb.Length = sb.Length > 0 ? sb.Length - 1 : sb.Length;
            return(sb.ToString());
        }
Exemple #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="val"></param>
        public static Tuple <Tagbase, HisTag> LoadFromCSVString(string val)
        {
            string[]        stmp    = val.Split(new char[] { ',' });
            Cdy.Tag.TagType tp      = (Cdy.Tag.TagType)Enum.Parse(typeof(Cdy.Tag.TagType), stmp[4]);
            var             realtag = TagTypeExtends.GetTag(tp);

            realtag.Id          = int.Parse(stmp[0]);
            realtag.Name        = stmp[1];
            realtag.Desc        = stmp[2];
            realtag.Group       = stmp[3];
            realtag.LinkAddress = stmp[5];

            if (stmp.Length > 6)
            {
                Cdy.Tag.HisTag histag = new HisTag();
                histag.Type = (Cdy.Tag.RecordType)Enum.Parse(typeof(Cdy.Tag.RecordType), stmp[6]);

                histag.Circle       = long.Parse(stmp[7]);
                histag.CompressType = int.Parse(stmp[8]);
                histag.Parameters   = new Dictionary <string, double>();
                histag.TagType      = realtag.Type;
                histag.Id           = realtag.Id;

                for (int i = 9; i < stmp.Length; i++)
                {
                    string skey = stmp[i];
                    if (string.IsNullOrEmpty(skey))
                    {
                        break;
                    }
                    double dval = double.Parse(stmp[i + 1]);

                    if (!histag.Parameters.ContainsKey(skey))
                    {
                        histag.Parameters.Add(skey, dval);
                    }

                    i++;
                }
                return(new Tuple <Tagbase, HisTag>(realtag, histag));
            }

            return(new Tuple <Tagbase, HisTag>(realtag, null));
        }
Exemple #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="database"></param>
        /// <param name="tag"></param>
        /// <param name="parameterName"></param>
        /// <param name="value"></param>
        private static void UpdateHisTag(Database database, string tag, string parameterName, string value)
        {
            var vv = database.RealDatabase.GetTagByName(tag);

            if (vv != null)
            {
                if (database.HisDatabase.HisTags.ContainsKey(vv.Id))
                {
                    UpdateHisTagParameter(database.HisDatabase.HisTags[vv.Id], parameterName, value);
                }
                else
                {
                    HisTag vtag = new HisTag()
                    {
                        Id = vv.Id, TagType = vv.Type
                    };
                    database.HisDatabase.AddHisTags(vtag);
                    UpdateHisTagParameter(vtag, parameterName, value);
                }
            }
        }