Ejemplo n.º 1
0
        private void filePathValidate(string value)
        {
            IsFilePathCorrect = true;
            if (string.IsNullOrEmpty(value))
            {
                IsFilePathCorrect = false;
                // 位置不能为空
                FilePathValidatedWrongTip = ResxIF.GetString("PathCannotBeEmpty");
            }
            else
            {
                if (!Directory.Exists(value))
                {
                    IsFilePathCorrect = false;
                    // 指定的位置不存在
                    FilePathValidatedWrongTip = ResxIF.GetString("ThePathDoesNotExist");
                }
            }

            //判断是否是在项目目录中的子目录里
            if (!value.IsSubPathOf(ProjectPath))
            {
                IsFilePathCorrect = false;
                // 指定的位置必须是项目所在目录或其子目录中
                FilePathValidatedWrongTip = ResxIF.GetString("NotInSubDirectory");
            }

            CreateFileCommand.RaiseCanExecuteChanged();
        }
Ejemplo n.º 2
0
        private void filePathValidate(string value)
        {
            IsFilePathCorrect = true;
            if (string.IsNullOrEmpty(value))
            {
                IsFilePathCorrect         = false;
                FilePathValidatedWrongTip = "位置不能为空";
            }
            else
            {
                if (!Directory.Exists(value))
                {
                    IsFilePathCorrect         = false;
                    FilePathValidatedWrongTip = "指定的位置不存在";
                }
            }

            //判断是否是在项目目录中的子目录里
            if (!value.IsSubPathOf(ProjectPath))
            {
                IsFilePathCorrect         = false;
                FilePathValidatedWrongTip = "指定的位置必须是项目所在目录或其子目录中";
            }

            CreateFileCommand.RaiseCanExecuteChanged();
        }
Ejemplo n.º 3
0
        private void fileNameValidate(string value)
        {
            IsFileNameCorrect = true;

            if (string.IsNullOrEmpty(value))
            {
                IsFileNameCorrect = false;
                // 名称不能为空
                FileNameValidatedWrongTip = ResxIF.GetString("NameIsRequired");
            }
            else
            {
                if (value.Contains(@"\") || value.Contains(@"/"))
                {
                    IsFileNameCorrect = false;
                    // 名称不能有非法字符
                    FileNameValidatedWrongTip = ResxIF.GetString("NameHasIlligalCharacter");
                }
                else
                {
                    System.IO.FileInfo fi = null;
                    try
                    {
                        fi = new System.IO.FileInfo(value);
                    }
                    catch (ArgumentException) { }
                    catch (System.IO.PathTooLongException) { }
                    catch (NotSupportedException) { }
                    if (ReferenceEquals(fi, null))
                    {
                        // file name is not valid
                        IsFileNameCorrect         = false;
                        FileNameValidatedWrongTip = ResxIF.GetString("NameHasIlligalCharacter");
                    }
                    else
                    {
                        // file name is valid... May check for existence by calling fi.Exists.
                    }
                }
            }

            if (File.Exists(FilePath + @"\" + FileName + @".xaml"))
            {
                IsFileNameCorrect = false;
                // 指定的文件已存在
                FileNameValidatedWrongTip = ResxIF.GetString("TheFileAlreadyExists");
            }

            CreateFileCommand.RaiseCanExecuteChanged();
        }