private float GetFilesystemUsedPercentage(Filesystem fs) { if (!isServiceAvailable()) { return(float.NaN); } try { FilesystemInfo fsInfo = null; Platform.GetService(delegate(IFilesystemService service) { fsInfo = service.GetFilesystemInfo(fs.FilesystemPath); }); _serviceIsOffline = false; _lastServiceAvailableTime = Platform.Time; return(100.0f - ((float)fsInfo.FreeSizeInKB) / fsInfo.SizeInKB * 100.0F); } catch (Exception) { _serviceIsOffline = true; _lastServiceAvailableTime = Platform.Time; } return(float.NaN); }
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); } }
/// <summary> /// Retrieves the <see cref="FilesystemInfo"/> for a specified path. /// </summary> /// <param name="path"></param> /// <returns></returns> public static FilesystemInfo GetFilesystemInfo(string path) { FilesystemInfo fsInfo = null; Platform.GetService(delegate(IFilesystemService service) { fsInfo = service.GetFilesystemInfo(path); }); return(fsInfo); }
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); }