/// <summary>
        /// Makes sure that buffering is disabled and correct header values are set
        /// before streaming file data to the client. This method is invoked deferred
        /// when returning the resource in order to overcome some issues with OpenRasta.
        /// See the implementation in the handlers and the <see cref="FileDataResource"/>.
        /// </summary>
        /// <param name="token"></param>
        protected void SetResponseHeader(TransferToken token)
        {
            if (HttpContext.Current == null)
            {
                return;
            }

            //we need to disable buffering and set headers before streaming
            var resp = HttpContext.Current.Response;

            resp.BufferOutput = false;
            resp.AppendHeader("Content-Type", token.ContentType);
            resp.AppendHeader("Content-Disposition", "inline; filename=" + token.ResourceName);
            resp.AppendHeader("Content-Length", token.ResourceLength.ToString());
        }
Example #2
0
        public IHttpActionResult GetTransferToken()
        {
            var identity = ActionContext.ActionArguments["identity"] as JwtToken;

            try
            {
                var transferToken = new TransferToken(base.AccountCode, identity.name, base.ClientId);
                transferTokenApp.Save(transferToken);

                return(Ok(new { transfer_token = transferToken.Code }));
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Example #3
0
        public void Save(TransferToken token)
        {
            using (var transaction = Connection.BeginTransaction())
            {
                try
                {
                    if (token.Validate())
                    {
                        var _transferToken = transferTokenRepository.GetByOwner(token.OwnerCode.Value);

                        if (!_transferToken.IsNull())
                        {
                            if (!_transferToken.Validate())
                            {
                                transferTokenRepository.Delete(_transferToken);
                            }
                            else
                            {
                                throw new ArgumentException("Tranfer token válido existente.");
                            }
                        }

                        transferTokenRepository.Add(token);
                    }
                    else
                    {
                        throw new ArgumentException("Token inválido.");
                    }

                    transaction.Commit();
                }
                catch
                {
                    transaction.Rollback();
                    throw;
                }
            }
        }
Example #4
0
 public FileDataResource(TransferToken token, Func <Stream> openStreamFunc)
 {
     Token          = token;
     OpenStreamFunc = openStreamFunc;
 }