示例#1
0
    public IHttpActionResult GetDownload(string id)
    {
        IHttpActionResult result  = null;
        ProfileCommon     profile = APIhelper.GetProfileCommon(Request);

        if (!string.IsNullOrEmpty(id))
        {
            web_Document doc = GetWebDocument(id);

            if (doc != null)
            {
                string file = Path.Combine(Util.GetAppSettings("DocRoot") + doc.Path);

                var fileinfo = new FileInfo(file);
                try
                {
                    if (!fileinfo.Exists)
                    {
                        throw new FileNotFoundException(fileinfo.Name);
                    }

                    result = new FileActionResult(file);
                }
                catch (Exception ex)
                {
                    result = ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.NotFound, "File not found"));
                }
            }
        }

        return(result);
    }
示例#2
0
 public IHttpActionResult DownloadSummaryDiscountProductReport([FromUri] OrderAdminSearchCriteria searchCriteria)
 {
     try
     {
         var    path = System.Web.Hosting.HostingEnvironment.MapPath(_appSettings.SummaryDiscountProductTemplate);
         byte[] content;
         var    isWarehouse = _workContext.User.IsInRole(UserRole.Warehouse);
         using (FileStream file = File.Open(path, FileMode.Open))
         {
             content = _orderReportService.GetSummaryDiscountProductReport(
                 _workContext.User,
                 file,
                 searchCriteria);
         }
         var stream = new MemoryStream(content);
         var result = new FileActionResult(stream,
                                           $"SummaryDiscountProduct_{searchCriteria.OrderStatus}_{DateTime.Now.ToString("dd-MM-yyyy")}.xlsx");
         return(result);
     }
     catch (StaffingPurchaseException ex)
     {
         return(new StaffPurchaseExceptionActionResult(ex.Message));
     }
     catch (Exception ex)
     {
         _logger.Error("Failed to download Summary Discount Product Report", ex);
         return(new StaffPurchaseExceptionActionResult(_resourceManager.GetString("OrderReport.FailedToReport")));
     }
 }
        public virtual async Task <IHttpActionResult> Download(Guid sourceId)
        {
            var fileSource = context.GetDataSource <FileDataSource>(sourceId);

            if (fileSource == null)
            {
                return(NotFound());
            }
            var memoryStream = await streamManager.RetrieveData(sourceId, fileSource.CurrentFileName);

            var contentLength = memoryStream.Length;

            MediaTypeHeaderValue mediaType;

            MediaTypeHeaderValue.TryParse(fileSource.MediaType, out mediaType);
            var contentDisposition = new ContentDispositionHeaderValue("attachment")
            {
                FileName = fileSource.OriginalFileName,
                Size     = contentLength
            };
            var result = new FileActionResult(
                Request,
                memoryStream,
                mediaType,
                memoryStream.Length,
                contentDisposition);

            return(result);
        }
 public CallMethodResultInfo(MethodCallbackInfo callbackInfo, IStreamInfo streamInfo, List <HttpKeyAttribute> httpKeyAttributees, Type serviceType, MethodInfo method, object serviceInstance, FileActionResult fileActionResult, T context, object result)
 {
     CallbackInfo       = callbackInfo;
     StreamInfo         = streamInfo;
     HttpKeyAttributees = httpKeyAttributees;
     ServiceType        = serviceType;
     Method             = method;
     ServiceInstance    = serviceInstance;
     FileActionResult   = fileActionResult;
     Context            = context;
     Result             = result;
 }
示例#5
0
 protected void FailEventOrFinish(FileActionResult fileActionResult, FsmEvent notFoundEvent, FsmEvent accessErrorEvent)
 {
     if (fileActionResult == FileActionResult.NotFound && notFoundEvent != null)
     {
         Fsm.Event(notFoundEvent);
         return;
     }
     else if (fileActionResult == FileActionResult.AccessError && accessErrorEvent != null)
     {
         Fsm.Event(accessErrorEvent);
         return;
     }
     else
     {
         Finish();
     }
 }
示例#6
0
 public FileAction(FileActionResult action, string file)
 {
     Action = action;
     File   = file;
 }