예제 #1
0
        protected bool AddExistingItem(String file, String type)
        {
            if (!File.Exists(file))
            {
                MessageBox.Show(String.Format("File {0} is not exist!", file), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            // 如果当前文件夹不存在,进行文件复制的时候就会出问题;
            if (!Directory.Exists(this.FolderPath))
            {
                Directory.CreateDirectory(this.FolderPath);
            }

            if (String.IsNullOrEmpty(type))
            {
                PcsFileInfo fileInfo = PcsFileInfo.GetPcsFileInfo(file);
                type = fileInfo == null ? String.Empty : fileInfo.type;
            }

            // 如果新旧文件为同一个文件,并且目标文件已经存在,则退出;
            String fileName = Path.GetFileName(file);
            String newFile  = Path.Combine(this.FolderPath, fileName);

            // 如果项目中不存在该文件名
            if (!this.FileNameCanUsed(newFile, type, false))
            {
                // 文件名冲突;
                MessageBox.Show(String.Format("FileName {0} is existing in project!", fileName), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            if (file.Equals(newFile, StringComparison.OrdinalIgnoreCase))
            {
                // 目标文件与newFile为同一个文件,则直接导入;
                return(this.AddExistingItem(FileCreateFactory.CreateFile(newFile, type)));
            }
            else if (File.Exists(newFile))
            {
                // 目标文件与的newFile不为同一个文件,单newFile已经存在;
                MessageBox.Show(String.Format("File {0} is existing in {1}!", newFile, this.FolderPath), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            // 复制文件
            if (FileName.CopyFile(file, newFile))
            {
                return(this.AddExistingItem(FileCreateFactory.CreateFile(newFile, String.Empty)));
            }

            return(false);
        }
예제 #2
0
 public override ViFileInfo CreateFile(string fileType, string filePath, String fileName)
 {
     return(FileCreateFactory.CreateFile(fileName, fileType));
 }
예제 #3
0
 static FileCreateFactory()
 {
     // register filetype
     FileCreateFactory.RegisterFileType(PcsFileInfo.FileType.CFCProgram, typeof(ViCFCFile));
     FileCreateFactory.RegisterFileType(PcsFileInfo.FileType.CPU, typeof(ViCPUInfo));
 }
예제 #4
0
 public virtual ViFileInfo CreateFile(String fileType, String filePath, String fileName)
 {
     return(FileCreateFactory.CreateFile(filePath, fileType));
 }