/// <summary>
        /// 将文本行描述的变量定义,解析为变量对象。
        /// </summary>
        /// <param name="line">变量的文本行描述</param>
        /// <param name="typeCreation">自动创建变量数据类型的方式</param>
        /// <returns>变量对象,null 表示解析失败</returns>
        public static new ExternalConnection Parse(string line, ViTypeCreation typeCreation)
        {
            ExternalConnection variable = ParseExternalConnection(line);

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

            int targetPathStart      = line.IndexOf(sTargetPathIdentifier);
            int sourcePathStart      = line.IndexOf(sSourcePathIdentifier);
            int targetTaskStart      = line.IndexOf(sTargetTaskTypeIdentifier);
            int sourceTaskStart      = line.IndexOf(sSourceTaskTypeIdentifier);
            int targetBlockModeStart = line.IndexOf(sTargetBlockModeIdentifier);
            int sourceBlockModeStart = line.IndexOf(sSourceBlockModeIdentifier);
            int uuidStart            = line.IndexOf(sUuidIdentifier);
            int endIndex             = line.IndexOf("*)");

            //targetPath
            if (sourcePathStart > targetPathStart + sTargetPathIdentifier.Length)
            {
                variable.TargetPath = line.Substring(targetPathStart + sTargetPathIdentifier.Length, sourcePathStart - targetPathStart - sTargetPathIdentifier.Length).Trim();
            }
            //sourcePath
            if (targetTaskStart > sourcePathStart + sSourcePathIdentifier.Length)
            {
                variable.SourcePath = line.Substring(sourcePathStart + sSourcePathIdentifier.Length, targetTaskStart - sourcePathStart - sSourcePathIdentifier.Length).Trim();
            }
            //targetTask
            if (sourceTaskStart > targetTaskStart + sTargetTaskTypeIdentifier.Length)
            {
                variable.TargetTaskType = line.Substring(targetTaskStart + sTargetTaskTypeIdentifier.Length, sourceTaskStart - targetTaskStart - sTargetTaskTypeIdentifier.Length).Trim();
            }
            //sourceTask
            if (targetBlockModeStart > sourceTaskStart + sSourceTaskTypeIdentifier.Length)
            {
                variable.SourceTaskType = line.Substring(sourceTaskStart + sSourceTaskTypeIdentifier.Length, targetBlockModeStart - sourceTaskStart - sSourceTaskTypeIdentifier.Length).Trim();
            }
            //targetBlockMode
            if (sourceBlockModeStart > targetBlockModeStart + sTargetBlockModeIdentifier.Length)
            {
                variable.TargetBlockModes = line.Substring(targetBlockModeStart + sTargetBlockModeIdentifier.Length, sourceBlockModeStart - targetBlockModeStart - sTargetBlockModeIdentifier.Length).Trim();
            }
            //sourceBlockMode
            if (uuidStart > sourceBlockModeStart + sSourceBlockModeIdentifier.Length)
            {
                variable.SourceBlockModes = line.Substring(sourceBlockModeStart + sSourceBlockModeIdentifier.Length, uuidStart - sourceBlockModeStart - sSourceBlockModeIdentifier.Length).Trim();
            }
            //UUID
            if (endIndex > uuidStart + sUuidIdentifier.Length)
            {
                variable.UUID = line.Substring(uuidStart + sUuidIdentifier.Length, endIndex - uuidStart - sUuidIdentifier.Length).Trim();
            }

            return(variable);
        }
Example #2
0
        /// <summary>
        /// 将文本行描述的变量定义,解析为管脚类型对象。
        /// </summary>
        /// <param name="decl">管脚的文本行描述</param>
        /// <param name="typeCreation">自动创建管脚数据类型的方式</param>
        /// <param name="creator">ViConnType 的创建函数</param>
        /// <returns>管脚类型对象,null 表示解析失败</returns>
        public static ViConnType Parse(string decl, ViTypeCreation typeCreation, Func <string, ViDataType, ViConnType> creator)
        {
            string name = null, type = null, comment = null; string[] addiInfo = null;

            if (!SeperateNameType(decl.Trim(), ref name, ref type, ref addiInfo, ref comment))
            {
                return(null);
            }

            ViDataType dataType = null;

            if (!string.IsNullOrEmpty(type))
            {
                dataType = ViDataType.GetDataType(type, typeCreation);
                if (dataType == null)
                {
                    return(null);
                }
            }

            ViConnType connType = creator(name, dataType);

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

            // 备注
            connType.Comment = comment;

            if (addiInfo != null)
            {
                // 特性
                foreach (string info in addiInfo)
                {
                    if (info.Equals("F_EDGE", StringComparison.OrdinalIgnoreCase))
                    {
                        connType.Attributes |= ViConnAttributes.F_EDGE;
                    }
                    else if (info.Equals("R_EDGE", StringComparison.OrdinalIgnoreCase))
                    {
                        connType.Attributes |= ViConnAttributes.R_EDGE;
                    }
                }

                // 缺省值
                if (addiInfo.Count() >= 2 && addiInfo[addiInfo.Count() - 2] == ":=")
                {
                    connType.DefaultValue = addiInfo[addiInfo.Count() - 1];
                }
            }

            return(connType);
        }
        /// <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);
        }
Example #4
0
        /// <summary>
        /// 得到指定名称的数据类型对象。如果该名称的数据类型不存在,则会按照指定的创建方式进行创建。
        /// </summary>
        /// <param name="name">类型名称</param>
        /// <param name="creation">自动创建数据类型的方式</param>
        /// <returns>数据类型对象</returns>
        public static ViDataType GetDataType(string name, ViTypeCreation creation)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }

            // 确保数据被加载了
            ViObservableCollection <ViDataType> allDataTypes = AllDataTypes;

            // 便于使用,去掉括号后面的注释信息
            int pos = name.IndexOf('(');

            if (pos > 0)
            {
                name = name.Substring(0, pos);
            }

            // 关键字都是大写
            string key = name.ToUpper().Trim();

            // 从字典中取得指定名称的对象
            if (mapAllDTypes.ContainsKey(key))
            {
                return(mapAllDTypes[key]);
            }

            // 自动创建?
            if (creation != ViTypeCreation.None &&
                ViIECStandard.IsValidName(name))
            {
                ViDataType dataType = new ViDataType(name, string.Empty);
                dataType.AutoCreated = true;
                if (creation == ViTypeCreation.CreateGlobal)
                {
                    allDataTypes.Add(dataType);
                    mapAllDTypes[key] = dataType;
                }
                //
                return(dataType);
            }

            // 没有找到
            return(null);
        }
Example #5
0
 /// <summary>
 /// 将文本行描述的变量定义,解析为管脚类型对象。
 /// </summary>
 /// <param name="decl">管脚的文本行描述</param>
 /// <param name="typeCreation">自动创建管脚数据类型的方式</param>
 /// <returns>管脚类型对象,null 表示解析失败</returns>
 public static ViConnType Parse(string decl, ViTypeCreation typeCreation)
 {
     return(Parse(decl, typeCreation, (name, dataType) => new ViConnType(name, dataType)));
 }