Ejemplo n.º 1
0
        /// <summary>
        /// 构建对象。自动加载工程文件信息。
        /// </summary>
        /// <param name="varFileName">工程文件名称。</param>
        //public ViGETVarFile(string varFileName)
        //    : base(varFileName)
        //{
        //    this.LoadInfo(varFileName);
        //}

        /// <summary>
        /// 得到组合之后的全路径名称。原始文件名称中可能没有目录信息,可能没有扩展名信息。
        /// </summary>
        public static string GetFullFileName(string fileName, string basePath, string extName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return(null);
            }

            if (string.IsNullOrEmpty(Path.GetExtension(fileName)))
            {
                fileName += extName;
            }

            return(FileName.GetAbsoluteFileName(basePath, fileName));
        }
Ejemplo n.º 2
0
        private static string GetPouSrcFileName(ViHardwareType hardwareType, string sourceFile)
        {
            if (FileName.GetFilePathType(sourceFile) != FileName.FilePathType.Absolute)
            {
                string newFile = FileName.GetAbsoluteFileName(hardwareType.DetailPathName, sourceFile);
                if (!File.Exists(newFile))
                {
                    newFile = FileName.GetAbsoluteFileName(ProjODKPath + @"System\", sourceFile);
                }
                //
                sourceFile = newFile;
            }
            if (!File.Exists(sourceFile))
            {
                return(null);
            }

            return(sourceFile);
        }
Ejemplo n.º 3
0
        protected override bool LoadDocument(XmlDocument doc)
        {
            XmlElement root = doc.DocumentElement;

            if (root == null || !Constants.TAG.Soluton.Equals(root.Name))
            {
                return(false);
            }

            this.Type = root.GetAttribute(Constants.Attribute.Type);
            String version = root.GetAttribute(Constants.Attribute.Version);
            Dictionary <String, String> dProjectFile = new Dictionary <string, string>();

            foreach (XmlElement group in root.ChildNodes)
            {
                if (Constants.TAG.Projects.Equals(group.Name))
                {
                    // ProjectGroup
                    foreach (XmlElement itemElement in group.ChildNodes)
                    {
                        // 根据项目相关信息,创建项目实例;
                        if (Constants.TAG.Project.Equals(itemElement.Name))
                        {
                            String         include  = itemElement.GetAttribute(Constants.Attribute.FilePath);
                            String         projFile = FileName.GetAbsoluteFileName(this.DirectoryPath, include);
                            ProjectManager project  = new ProjectManager(projFile);
                            if (project.Load())
                            {
                                this.AddChild(project);
                            }
                        }
                    }
                }
                else if (Constants.TAG.Global.Equals(group.Name))
                {
                    // Global
                }
            }

            this.UpdateActiveCpu();

            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 得到功能块路径中包含的硬件类型名称。
        /// </summary>
        public static string GetPathHardwareName(string projectPath, string fbFileName)
        {
            fbFileName = FileName.GetAbsoluteFileName(projectPath, fbFileName);
            string userFBsPath = GetUserFBsPath(projectPath);

            if (!fbFileName.StartsWith(userFBsPath))
            {
                return(null);
            }

            fbFileName = fbFileName.Substring(userFBsPath.Length);

            int pos = fbFileName.IndexOf('\\');

            if (pos <= 0)
            {
                return(null);
            }

            return(fbFileName.Substring(0, pos));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 更新功能块数组列表。
        /// </summary>
        public override void UpdatePOUs()
        {
            // 当CPU为null的时候,有可能当前类还未初始化完毕;
            if (this.CPU == null)
            {
                return;
            }

            this.DeleteAll();

            IniFile iniFile     = new IniFile(this.SourceFile);
            string  projectPath = FileName.GetFilePath(this.SourceFile);

            int sectionType = 0;    // 0 不关心;2 POE;9 LIBRARY

            iniFile.LoopSections((section) =>
            {
                if (section.EndsWith("_FUNCTIONBLOCK", StringComparison.OrdinalIgnoreCase) ||
                    section.EndsWith("_FUNCTION", StringComparison.OrdinalIgnoreCase))
                {
                    sectionType = 2;
                    return(true);
                }
                if (string.Equals(section, "LIBRARY", StringComparison.OrdinalIgnoreCase))
                {
                    sectionType = 9;
                    return(true);
                }

                sectionType = 0;
                return(false);
            }, (key, value) =>
            {
                if (!string.IsNullOrEmpty(value) && key.IsPrefixIndex("FILE"))
                {
                    string file, hardwareType;
                    switch (sectionType)
                    {
                    case 2:
                        // 工程本身的功能块
                        {
                            file         = FileName.GetAbsoluteFileName(projectPath, value);
                            file         = FileName.GetNewExtFileName(file, ".POE");
                            hardwareType = ViGlobal.GetPathHardwareName(projectPath, file);
                            // 没有硬件类型名称,或者硬件类型名称匹配的情况下,才将功能块加入
                            if (string.IsNullOrEmpty(hardwareType) ||
                                string.Equals(hardwareType, this.CPU.HardwareType, StringComparison.OrdinalIgnoreCase))
                            {
                                ViPOEBlockType blockType = ViIECPOEFile.GetBlockType(file);
                                if (blockType != null)
                                {
                                    blockType.PouSource = this;
                                    this.AddChild(blockType);
                                }
                            }
                        }
                        break;

                    case 9:
                        // 工程使用的 ViGET 库工程的功能块
                        {
                            file = FileName.GetAbsoluteFileName(ViGlobal.ProjODKPath, value);
                            file = FileName.GetNewExtFileName(file, ".VAR");

                            // 不能讲把自身作为一个库文件来使用,否则会造成死循环;
                            if (this.CPU.ProjectFile != null && !this.CPU.ProjectFile.Equals(file, StringComparison.OrdinalIgnoreCase))
                            {
                                ViPouSourceCPU cpu = new ViPouSourceCPU()
                                {
                                    ProjectFile  = file,
                                    HardwareType = this.CPU.HardwareType,
                                };

                                ViCPUPouSource cpuSource = new ViCPUPouSource(cpu, ViPouAttributes.ProjectLibrary | (this.PouAttributes & ViPouAttributes.Public));
                                if (cpuSource != null)
                                {
                                    this.AddChild(cpuSource);
                                }
                            }
                        }
                        break;
                    }
                }
                return(true);
            });

            // CPU 安装的硬件库的功能块
            if (!string.IsNullOrEmpty(this.CPU.CPUName))
            {
                string globProt = ViGlobal.GetCPUENVPath(projectPath, this.CPU.CPUName) + "GLOBPROT.INC";
                string infoFile = ViGlobal.GetCPUENVPath(projectPath, this.CPU.CPUName) + this.CPU.HardwareType + ".ini";
                this.AddChild(new ViIncPouSource(globProt, infoFile, ViPouAttributes.CPULibrary | (this.PouAttributes & ViPouAttributes.Public)));
            }

            // ViGET 全局的功能块。对于安装的库工程,就不要这些信息了,否则就重复了
            if (!string.IsNullOrEmpty(this.CPU.CPUName))
            {
                ArrayList alPouSources = ViGlobal.GetPouSources(this.CPU.HardwareType);
                if (alPouSources != null)
                {
                    foreach (ViPouSource source in alPouSources)
                    {
                        this.AddChild(source);
                    }
                }
            }
        }