public void HandleCheckFileInfoRequest(WopiRequest requestData) { lock (this) { // userId(user@polihub) will be passed from the policyHub application if (!_authorization.ValidateToken(requestData.AccessToken, ConfigurationManager.AppSettings["userId"], requestData.Id)) { _errorHandler.ReturnInvalidToken(_response); _response.Close(); return; } if (!File.Exists(requestData.FullPath)) { _errorHandler.ReturnFileUnknown(_response); _response.Close(); return; } try { FileInfo fileInfo = new FileInfo(requestData.FullPath); ResponseGenerator generator = new ResponseGenerator(fileInfo); if (!fileInfo.Exists) { _errorHandler.ReturnFileUnknown(_response); return; } var memoryStream = new MemoryStream(); var json = new DataContractJsonSerializer(typeof(WopiCheckFileInfo)); json.WriteObject(memoryStream, generator.GetFileInfoResponse()); memoryStream.Flush(); memoryStream.Position = 0; StreamReader streamReader = new StreamReader(memoryStream); var jsonResponse = Encoding.UTF8.GetBytes(streamReader.ReadToEnd()); _response.ContentType = ConfigurationManager.AppSettings["appJson"]; _response.ContentLength64 = jsonResponse.Length; _response.OutputStream.Write(jsonResponse, 0, jsonResponse.Length); _errorHandler.ReturnSuccess(_response); } catch (UnauthorizedAccessException) { _errorHandler.ReturnFileUnknown(_response); } _response.Close(); } }
public void HandleCheckFileInfoRequest(WopiRequest requestData) { lock (this) { if (!_authorization.ValidateAccess(requestData, writeAccessRequired: false)) { _errorHandler.ReturnInvalidToken(_response); _response.Close(); return; } if (!File.Exists(requestData.FullPath)) { _errorHandler.ReturnFileUnknown(_response); _response.Close(); return; } try { FileInfo fileInfo = new FileInfo(requestData.FullPath); ResponseGenerator generator = new ResponseGenerator(fileInfo); if (!fileInfo.Exists) { _errorHandler.ReturnFileUnknown(_response); return; } var memoryStream = new MemoryStream(); var json = new DataContractJsonSerializer(typeof(WopiCheckFileInfo)); json.WriteObject(memoryStream, generator.GetFileInfoResponse()); memoryStream.Flush(); memoryStream.Position = 0; StreamReader streamReader = new StreamReader(memoryStream); var jsonResponse = Encoding.UTF8.GetBytes(streamReader.ReadToEnd()); _response.ContentType = @"application/json"; _response.ContentLength64 = jsonResponse.Length; _response.OutputStream.Write(jsonResponse, 0, jsonResponse.Length); _errorHandler.ReturnSuccess(_response); } catch (UnauthorizedAccessException) { _errorHandler.ReturnFileUnknown(_response); } _response.Close(); } }