/// <summary>
        /// 添加新项;
        /// </summary>
        protected void AddNewItem()
        {
            if (this.TheFactory == null || this.TheFactory.TempWizard == null)
            {
                return;
            }
            if (!Directory.Exists(this.FolderPath))
            {
                Directory.CreateDirectory(this.FolderPath);
            }

            this.TheFactory.TempWizard.RunCreateFileWizard(this.FolderPath, this.Type, (filePath, name, type) =>
            {
                ViFileInfo child = this.CreateFile(type, filePath, name);
                this.AddChild(child);
                // 如果child为一个目录,则需要创建对应的本地文件夹
                if (child is ViFolderInfo)
                {
                    ViFolderInfo folder = child as ViFolderInfo;
                    if (!Directory.Exists(folder.FolderPath))
                    {
                        Directory.CreateDirectory(folder.FolderPath);
                    }
                }
            }, (fileName, type) => {
                return(this.CurrProject.FileNameCanUsed(fileName, type));
            });
        }
        public void ModeFileInfo(ViFileInfo file)
        {
            if (file == null)
            {
                return;
            }
            // 如果文件所属项目为空,则文件处于游离状态,暂时不做处理
            if (this.CurrProject == null || file.CurrProject == null)
            {
                return;
            }

            if (this.CurrProject == file.CurrProject)
            {
                // 同一个项目下的文件
                // 如果目标文件已经打开,则需要关闭已打开的文件;
                //IViDocManager docManager = file.TheFactory.DocManager;
                //if (docManager != null && docManager.IsFileOpened(file.FullName))
                //{
                //    if (!docManager.CloseDocument(file.FullName))
                //        return;
                //}
                if (this.AddExistingItem(file.FullName, file.Type))
                {
                    file.DoDelete(false);
                }
            }
            else
            {
                // 不同项目下的文件,执行复制操作;
                this.AddExistingItem(file.FullName, file.Type);
            }
        }
        public override bool RemoveChild(ViFileNode child)
        {
            ViFileInfo item = child as ViFileInfo;

            item.Linked = false;
            this.TaskManager.UnlinkTask(item.FullName);

            return(base.RemoveChild(child));
        }
        /// <summary>
        /// 判断给定的文件是否是当前文件夹所支持的文件;
        /// </summary>
        /// <param name="file">目标文件</param>
        /// <returns>支持与否</returns>
        public virtual bool IsSupportedFile(ViFileInfo file)
        {
            if (file is ViCFCFile)
            {
                return(true);
            }

            return(false);
        }
        public override ViFileInfo CreateFile(string fileType, string filePath, string fileName)
        {
            ViFileInfo child = base.CreateFile(fileType, filePath, fileName);

            if (child != null)
            {
                child.Linked = true;
            }

            return(child);
        }
        private bool AddExistingItem(ViFileInfo file)
        {
            if (file == null)
            {
                return(false);
            }

            this.AddChild(file);
            file.Linked     = true;
            file.IsSelected = true;
            return(true);
        }
        /// <summary>
        /// 添加新项;
        /// </summary>
        protected void AddNewItem()
        {
            if (this.TheFactory == null || this.TheFactory.TempWizard == null)
            {
                return;
            }

            this.TheFactory.TempWizard.RunCreateFileWizard(this.FullPath, this.Type, (file, type) =>
            {
                ViFileInfo child = ViFileInfo.CreateFile(type, file);
                this.AddChild(child);
            });
        }
        public override void ExecutedCommand(object sender, System.Windows.Input.ExecutedRoutedEventArgs e)
        {
            if (e.Command == ViCommands.AddNewItem)
            {
                this.TheFactory.TempWizard.RunCreateFileWizard(this.DirectoryPath, this.Type, (file, type) =>
                {
                    this.AddChild(ViFileInfo.CreateFile(type, file));
                });
            }
            else if (e.Command == ViCommands.AddExistingItem)
            {
            }

            base.ExecutedCommand(sender, e);
        }
        public override void AddChild(ViFileNode child)
        {
            if (child == null)
            {
                return;
            }

            base.AddChild(child);

            // Link File
            ViFileInfo item = child as ViFileInfo;

            if (item.Linked)
            {
                this.TaskManager.LinkTask(item.FullName);
            }
        }
Exemple #10
0
        public static ViFileInfo CreateFile(String file, String fileType)
        {
            if (String.IsNullOrEmpty(file))
            {
                return(null);
            }
            if (String.IsNullOrEmpty(fileType))
            {
                PcsFileInfo fileInfo = PcsFileInfo.GetPcsFileInfo(file);
                if (fileInfo == null)
                {
                    return(null);
                }

                fileType = fileInfo.type;
            }
            if (String.IsNullOrEmpty(fileType))
            {
                return(null);
            }

            try
            {
                fileType = fileType.ToUpper();
                if (!DFileTypes.ContainsKey(fileType))
                {
                    return(null);
                }

                Type       type = FileCreateFactory.DFileTypes[fileType];
                ViFileInfo info = Activator.CreateInstance(type, file) as ViFileInfo;
                if (info != null)
                {
                    info.Type = fileType;
                }

                return(info);
            }
            catch (Exception ee)
            {
                Trace.WriteLine("### [" + ee.Source + "] Exception: " + ee.Message);
                Trace.WriteLine("### " + ee.StackTrace);
                return(null);
            }
        }
        /// <summary>
        /// 根据绝对路径查找目标文件;
        /// </summary>
        /// <param name="fullPath">目标文件绝对路径;</param>
        /// <returns></returns>
        public override ViFileInfo GetFileInfoByFullPath(string fullPath)
        {
            if (String.IsNullOrEmpty(fullPath))
            {
                return(null);
            }
            if (fullPath.TrimEnd('\\', '/').Equals(this.FolderPath.TrimEnd('\\', '/'), StringComparison.OrdinalIgnoreCase))
            {
                return(this);
            }

            foreach (ViFileInfo item in this.Children)
            {
                ViFileInfo target = item.GetFileInfoByFullPath(fullPath);
                if (target != null)
                {
                    return(target);
                }
            }

            return(null);
        }
Exemple #12
0
        /// <summary>
        /// 查找制定名称文件;
        /// </summary>
        /// <param name="name">需要查找的目标文件名称</param>
        /// <returns></returns>
        public virtual ViFileInfo GetFileInfo(String name, ViFileInfo exept = null)
        {
            if (String.IsNullOrEmpty(name) || exept == this)
            {
                return(null);
            }

            if (Path.GetFileNameWithoutExtension(name).Equals(Path.GetFileNameWithoutExtension(this.Name), StringComparison.OrdinalIgnoreCase))
            {
                return(this);
            }

            foreach (var item in this.Children)
            {
                var target = item is ViFileInfo ? (item as ViFileInfo).GetFileInfo(name) : null;
                if (target != null)
                {
                    return(target);
                }
            }

            return(null);
        }
Exemple #13
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);
        }