Exemple #1
0
        public void HandleGetFileRequest(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);

                    var content = generator.GetFileContent();
                    _response.ContentType     = ConfigurationManager.AppSettings["appXbinary"];
                    _response.ContentLength64 = content.Length;
                    _response.OutputStream.Write(content, 0, content.Length);
                    _errorHandler.ReturnSuccess(_response);
                }
                catch (UnauthorizedAccessException)
                {
                    _errorHandler.ReturnFileUnknown(_response);
                }
                catch (FileNotFoundException)
                {
                    _errorHandler.ReturnFileUnknown(_response);
                }
            }
        }
Exemple #2
0
        public void HandleGetFileRequest(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);
                var content = generator.GetFileContent();
                _response.ContentType = @"application/x-binary";
                _response.ContentLength64 = content.Length;
                _response.OutputStream.Write(content, 0, content.Length);
                _errorHandler.ReturnSuccess(_response);
                
            }
            catch (UnauthorizedAccessException)
            {
                _errorHandler.ReturnFileUnknown(_response);
                
            }
            catch (FileNotFoundException)
            {
                _errorHandler.ReturnFileUnknown(_response);
            }
        }