private ViTaskInfo GetDefaultCyclicTask()
        {
            ViTaskInfo task = this.CyclicTasks.FirstOrDefault();

            if (task != null)
            {
                return(task);
            }

            task = ViTaskInfo.CreateTaskInfo(CyclicTaskInfo.TASK_TYPE, "T1", 1);
            this.Tasks.SortedAdd(task);
            return(task);
        }
        public void LinkTask(String fileName)
        {
            // 1、县查找下当前文件是否已经存在;
            if (this.HasLinked(fileName))
            {
                return;
            }

            ViTaskInfo task = this.GetDefaultCyclicTask();

            task.AddTaskFile(fileName);
            task.UpdatePriority();
        }
        public ViTaskInfo CreateTaskInfo(String type, String name, int priority)
        {
            if (String.IsNullOrEmpty(name) || String.IsNullOrEmpty(type))
            {
                return(null);
            }

            ViTaskInfo task = this.GetTaskInfo(name);

            if (task != null)
            {
                return(task);
            }

            task = ViTaskInfo.CreateTaskInfo(type, name, priority);
            if (task == null)
            {
                return(null);
            }

            this.Tasks.SortedAdd(task);
            return(task);
        }
Exemple #4
0
        public override bool LoadElement(XmlElement element)
        {
            if (element == null || !Constants.TAG.CPU.Equals(element.Name, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            bool bValue;
            int  iValue;

            this.Name = element.GetAttribute(Constants.Attribute.Name);
            String sActive = element.GetAttribute(Constants.Attribute.IsActive);

            this.IsActive = Boolean.TryParse(sActive, out bValue) && bValue;

            foreach (XmlNode groupElement in element.ChildNodes)
            {
                // Settings
                if (Constants.TAG.Settings.Equals(groupElement.Name, StringComparison.OrdinalIgnoreCase))
                {
                    this.Type = (groupElement as XmlElement).GetAttribute(Constants.Attribute.HwType);
                    String hasShm = (groupElement as XmlElement).GetAttribute(Constants.Attribute.HasShmVars);
                    if (Boolean.TryParse(hasShm, out bValue))
                    {
                        this.HasShmVars = bValue;
                    }
                    foreach (XmlNode itemElement in groupElement.ChildNodes)
                    {
                        // connection
                        if (Constants.TAG.Connection.Equals(itemElement.Name))
                        {
                            this.TcpPort = (itemElement as XmlElement).GetAttribute(Constants.Attribute.TcpPort);
                            this.TcpIp   = (itemElement as XmlElement).GetAttribute(Constants.Attribute.TcpIp);
                        }
                    }
                } // Tasks
                else if (Constants.TAG.Tasks.Equals(groupElement.Name, StringComparison.OrdinalIgnoreCase))
                {
                    foreach (XmlNode itemElement in groupElement.ChildNodes)
                    {
                        // Task
                        if (Constants.TAG.Task.Equals(itemElement.Name))
                        {
                            String     name     = (itemElement as XmlElement).GetAttribute(Constants.Attribute.Name);
                            String     type     = (itemElement as XmlElement).GetAttribute(Constants.Attribute.Type);
                            String     priority = (itemElement as XmlElement).GetAttribute(Constants.Attribute.Priority);
                            ViTaskInfo task     = this.TaskManager.CreateTaskInfo(type, name, Int32.TryParse(priority, out iValue) ? iValue : 0);

                            if (task != null)
                            {
                                task.LoadElement(itemElement as XmlElement);
                            }
                        }
                    }
                } // Files
                else if (Constants.TAG.Files.Equals(groupElement.Name, StringComparison.OrdinalIgnoreCase))
                {
                    foreach (XmlNode fileElement in groupElement.ChildNodes)
                    {
                        var fileType   = (fileElement as XmlElement).GetAttribute(Constants.Attribute.FileType);
                        var filePath   = (fileElement as XmlElement).GetAttribute(Constants.Attribute.FilePath);
                        var fileLinked = (fileElement as XmlElement).GetAttribute(Constants.Attribute.Linked);

                        // filePath是相对路径,需要转换为绝对路径
                        filePath = this.CurrProject.GetFullPath(filePath);
                        ViFileInfo fileInfo = this.CreateFile(fileType, filePath, String.Empty);
                        if (fileInfo != null)
                        {
                            if (Boolean.TryParse(fileLinked, out bValue))
                            {
                                fileInfo.Linked = bValue;
                            }
                            this.AddChild(fileInfo);
                        }
                    }
                }
            }

            return(true);
        }