protected override bool OnServerSideEvaluate()
        {
            String path = GetControlValidationValue(ControlToValidate);

            if (String.IsNullOrEmpty(path))
            {
                ErrorMessage = ValidationErrors.FilesystemPathCannotBeEmpty;
                return(false);
            }

            try
            {
                FilesystemInfo fsInfo = ServerUtility.GetFilesystemInfo(path);

                return(fsInfo != null && fsInfo.Exists);
            }
            catch (EndpointNotFoundException e)
            {
                ErrorMessage = e.Message;
                return(true);
            }
            catch (IndexOutOfRangeException)
            {
                ErrorMessage = String.Format(ValidationErrors.FilesystemPathInvalidOrUnreachable, path);
                return(false);
            }
            catch (Exception e)
            {
                ErrorMessage = e.Message;
                return(false);
            }
        }
Exemplo n.º 2
0
        public FilesystemInfo GetFilesystemInfo(string path)
        {
            Platform.CheckForEmptyString(path, "requested path is empty or null");

            if (Context.Request.UserLanguages != null && Context.Request.UserLanguages.Length > 0)
            {
                CultureInfo culture = new CultureInfo(Context.Request.UserLanguages[0]);
                Thread.CurrentThread.CurrentCulture   = culture;
                Thread.CurrentThread.CurrentUICulture = culture;
            }
            return(ServerUtility.GetFilesystemInfo(path.Trim()));
        }
Exemplo n.º 3
0
        public ValidationResult ValidateFilesystemPath(string path)
        {
            // This web service in turns call a WCF service which resides on the same or different systems.

            ValidationResult result = new ValidationResult();

            if (String.IsNullOrEmpty(path))
            {
                result.Success   = false;
                result.ErrorCode = -1;
                result.ErrorText = ValidationErrors.FilesystemPathCannotBeEmpty;
                return(result);
            }

            FilesystemInfo fsInfo = null;

            result.Success = false;
            try
            {
                fsInfo = ServerUtility.GetFilesystemInfo(path);
                if (fsInfo != null && fsInfo.Exists)
                {
                    result.Success = true;
                }
                else
                {
                    result.Success   = false;
                    result.ErrorText = String.Format(ValidationErrors.FilesystemPathInvalidOrUnreachable, path);
                }
                return(result);
            }
            catch (Exception e)
            {
                result.Success   = false;
                result.ErrorCode = 100;
                result.ErrorText = String.Format(ValidationErrors.UnableToValidatePath, path, e.Message);
            }

            return(result);
        }
        public FilesystemInfo GetFilesystemInfo(string path)
        {
            Platform.CheckForEmptyString(path, "requested path is empty or null");

            return(ServerUtility.GetFilesystemInfo(path.Trim()));
        }