/// <summary>
        /// 根据当前的变量名称情况,更新和完善 NextVariableID 属性。
        /// </summary>
        /// <returns>NextVariableID 是否发生变化?</returns>
        public bool PurifyNextVariableID()
        {
            int oldNextVariableID = this.NextVariableID;

            int maxVariableID = 0, varID;

            foreach (ViNamedObject obj in this.Children)
            {
                ViGlobalVariable variable = obj as ViGlobalVariable;
                if (variable == null)
                {
                    continue;
                }

                if (variable.Name.StartsWith(VariablePrefix, StringComparison.OrdinalIgnoreCase))
                {
                    if (int.TryParse(variable.Name.Substring(VariablePrefix.Length), out varID))
                    {
                        if (maxVariableID < varID)
                        {
                            maxVariableID = varID;
                        }
                    }
                }
            }
            //
            this.NextVariableID = maxVariableID + 1;

            return(oldNextVariableID != this.NextVariableID);
        }
Esempio n. 2
0
        /// <summary>
        /// 删除指定的全局变量。
        /// </summary>
        public virtual bool RemoveGlobalVariable(ViGlobalVariable var)
        {
            if (var == null)
            {
                return(false);
            }

            return(this.Children.Remove(var));
        }
Esempio n. 3
0
 /// <summary>
 /// 保存变量信息。
 /// </summary>
 /// <param name="writer">文本对象</param>
 protected virtual void SaveVariables(TextWriter writer)
 {
     foreach (ViNamedObject obj in this.Children)
     {
         ViGlobalVariable connType = obj as ViGlobalVariable;
         if (connType != null)
         {
             writer.WriteLine(ViTextFile.Indent + connType.ToString(true));
         }
     }
 }
Esempio n. 4
0
        /// <summary>
        /// 将文本行描述的变量定义,解析为变量对象。
        /// </summary>
        /// <param name="decl">变量的文本行描述</param>
        /// <param name="typeCreation">自动创建变量数据类型的方式</param>
        /// <returns>变量对象,null 表示解析失败</returns>
        public static new ViGlobalVariable Parse(string decl, ViTypeCreation typeCreation)
        {
            ViGlobalVariable variable = Parse(decl, typeCreation, (name, dataType) => new ViGlobalVariable(name, dataType)) as ViGlobalVariable;

            if (variable == null)
            {
                return(null);
            }

            StringConfig config = new StringConfig(variable.Comment);

            variable.Comment = config["_C"];
            variable.UUID    = config["UUID"];
            //
            return(variable);
        }
Esempio n. 5
0
        /// <summary>
        /// 读取一行变量描述信息。
        /// </summary>
        /// <param name="line">变量文本行描述信息</param>
        /// <returns>成功/失败?</returns>
        protected virtual bool OnVariableLine(string line)
        {
            if (line.StartsWith(ViTextFile.CommentBegin))
            {
                return(true);
            }

            ViGlobalVariable connType = ViGlobalVariable.Parse(line, ViTypeCreation.Create);

            if (connType == null || connType.Type == null)
            {
                return(false);
            }

            this.AddChild(connType);
            return(true);
        }
Esempio n. 6
0
        public ViGlobalVariable GetGlobalVariable(string uuid)
        {
            if (string.IsNullOrEmpty(uuid))
            {
                return(null);
            }
            if (!ViGlobalVariable.CheckUUID(uuid))
            {
                return(null);
            }

            if (this.Children.Count > 0)
            {
                return(this.Children.Where((o) => ((ViGlobalVariable)o).UUID == uuid).FirstOrDefault() as ViGlobalVariable);
            }

            return(null);
        }
 /// <summary>
 /// 删除指定的全局变量。
 /// </summary>
 public override bool RemoveGlobalVariable(ViGlobalVariable var)
 {
     return(this.DeleteChild(var));
 }