Exemplo n.º 1
0
        public static String GetPdfWithPrintDialog(GetFileParameters parameters)
        {
            var displayName = string.IsNullOrEmpty(parameters.DisplayName) ?
                              Path.GetFileName(parameters.Path) : Uri.EscapeDataString(parameters.DisplayName);

            var pdfFileOptions = new PdfFileOptions
            {
                // AddPrintAction = parameters.IsPrintable,
                Transformations = Transformation.Rotate | Transformation.Reorder,
                Watermark       = GetWatermark(parameters),
            };

            if (parameters.IsPrintable)
            {
                pdfFileOptions.Transformations |= Transformation.AddPrintAction;
            }

            var response = _htmlHandler.GetPdfFile(parameters.Path, pdfFileOptions);

            string contentDispositionString = new ContentDisposition {
                FileName = displayName, Inline = true
            }.ToString();

            HttpContext.Current.Response.AddHeader("Content-Disposition", contentDispositionString);

            return("");
        }
Exemplo n.º 2
0
        public ActionResult GetPdfWithPrintDialog(GetFileParameters parameters)
        {
            var displayName = string.IsNullOrEmpty(parameters.DisplayName)
                ? Path.GetFileName(parameters.Path)
                : Uri.EscapeDataString(parameters.DisplayName);

            var options = new PdfFileOptions
            {
                Guid      = parameters.Path,
                Watermark = Utils.GetWatermark(parameters.WatermarkText, parameters.WatermarkColor, parameters.WatermarkPosition, parameters.WatermarkWidth)
            };

            if (parameters.IsPrintable)
            {
                options.AddPrintAction = true;
            }

            if (parameters.SupportPageRotation)
            {
                options.Transformations |= Transformation.Rotate;
            }

            options.Transformations |= Transformation.Reorder;


            var response = _htmlHandler.GetPdfFile(options);

            var contentDispositionString = new ContentDisposition {
                FileName = displayName, Inline = true
            }.ToString();

            Response.AddHeader("Content-Disposition", contentDispositionString);

            return(File(((MemoryStream)response.Stream).ToArray(), "application/pdf"));
        }
        public HttpResponseMessage GetFile([FromUri] GetFileParameters parameters)
        {
            byte[] bytes;
            string fileDisplayName;
            bool   isSuccessful = _coreHandler.GetFile(parameters,
                                                       out bytes, out fileDisplayName);

            if (!isSuccessful)
            {
                return(new HttpResponseMessage(HttpStatusCode.NoContent));
            }

            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK);

            if (bytes == null)
            {
                response.Content = new StringContent("File not found", Encoding.UTF8);
                return(response);
            }

            response.Content = new ByteArrayContent(bytes);
            response.Content.Headers.ContentType        = new MediaTypeHeaderValue("application/octet-stream");
            response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attacment")
            {
                FileName = fileDisplayName
            };
            return(response);
        }
Exemplo n.º 4
0
        public async Task <string> GetFileFromUri(string uri, CancellationToken cancellationToken)
        {
            using var handler = new HttpClientHandler
                  {
                      ClientCertificateOptions = ClientCertificateOption.Manual,
                      SslProtocols             = SslProtocols.Tls12
                  };

            try
            {
                var certificate = CertificateHelper.GetCertificate(_storeName, _storeLocation, _thumbprint);
                handler.ClientCertificates.Add(certificate);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Fant ikke sertifikat med thumbprint {_thumbprint} StoreName: {_options.Value.StoreName} StoreLocation: {_options.Value.StoreLocation}");
                return(null);
            }

            using var httpClient = new HttpClient(handler)
                  {
                      BaseAddress = new Uri(_baseAddress),
                  };

            using var client = new WebDavClient(httpClient);
            var getFileParameters = new GetFileParameters {
                CancellationToken = cancellationToken
            };
            var response = await client.GetRawFile(uri, getFileParameters);

            var reader = new StreamReader(response.Stream);
            var fil    = await reader.ReadToEndAsync();

            return(fil);
        }
        public HttpResponseMessage GetPdfWithPrintDialog([FromUri] GetFileParameters parameters)
        {
            if (!_helper.IsRequestHandlingEnabled(Constants.GroupdocsPrintRequestHandlingIsEnabled))
            {
                return(new HttpResponseMessage(HttpStatusCode.NoContent));
            }

            byte[] bytes;
            string fileDisplayName;
            bool   isSuccessful = _coreHandler.GetFile(parameters,
                                                       out bytes, out fileDisplayName);

            if (!isSuccessful)
            {
                return(new HttpResponseMessage(HttpStatusCode.NoContent));
            }

            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK);

            if (bytes == null)
            {
                response.Content = new StringContent("File not found", Encoding.UTF8);
                return(response);
            }

            response.Content = new ByteArrayContent(bytes);
            response.Content.Headers.ContentType        = new MediaTypeHeaderValue("application/pdf");
            response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("inline");
            return(response);
        }
        public ActionResult GetFile(GetFileParameters parameters)
        {
            try
            {
                var displayName = string.IsNullOrEmpty(parameters.DisplayName)
              ? Path.GetFileName(parameters.Path)
              : Uri.EscapeDataString(parameters.DisplayName);

                Stream fileStream;
                if (parameters.GetPdf)
                {
                    displayName = Path.ChangeExtension(displayName, "pdf");

                    var options = new PdfFileOptions
                    {
                        Watermark = Utils.GetWatermark(parameters.WatermarkText, parameters.WatermarkColor, parameters.WatermarkPosition, parameters.WatermarkWidth, parameters.WatermarkOpacity),
                    };

                    if (parameters.IsPrintable)
                    {
                        options.Transformations |= Transformation.AddPrintAction;
                    }

                    if (parameters.SupportPageRotation)
                    {
                        options.Transformations |= Transformation.Rotate;
                    }

                    options.Transformations |= Transformation.Reorder;

                    var pdfFileResponse = _htmlHandler.GetPdfFile(parameters.Path, options);
                    fileStream = pdfFileResponse.Stream;
                }
                else
                {
                    var fileResponse = _htmlHandler.GetFile(parameters.Path);
                    fileStream = fileResponse.Stream;
                }

                //jquery.fileDownload uses this cookie to determine that a file download has completed successfully
                Response.SetCookie(new HttpCookie("jqueryFileDownloadJSForGD", "true")
                {
                    Path = "/"
                });

                fileStream.Position = 0;
                using (var ms = new MemoryStream())
                {
                    fileStream.CopyTo(ms);
                    return(File(ms.ToArray(), "application/octet-stream", displayName));
                }
            }
            catch (Exception e)
            {
                return(this.JsonOrJsonP(new FailedResponse {
                    Reason = e.Message
                }, null));
            }
        }
        private  Watermark GetWatermark(GetFileParameters request)
        {
            if (string.IsNullOrWhiteSpace(request.WatermarkText))
                return null;

            return new Watermark(request.WatermarkText)
            {
                Color = request.WatermarkColor.HasValue
                    ? Color.FromArgb(request.WatermarkColor.Value)
                    : Color.Blue,
                Position = ToWatermarkPosition(request.WatermarkPosition),
                Width = request.WatermarkWidth
            };
        }
        public ActionResult GetFile(GetFileParameters parameters)
        {
            string displayName = string.IsNullOrEmpty(parameters.DisplayName) ?
                                 Path.GetFileName(parameters.Path) : Uri.EscapeDataString(parameters.DisplayName);

            Stream fileStream = annotator.GetFile(parameters.Path).Stream;

            //jquery.fileDownload uses this cookie to determine that a file download has completed successfully
            Response.SetCookie(new HttpCookie("jqueryFileDownloadJSForGD", "true")
            {
                Path = "/"
            });

            return(File(GetBytes(fileStream), "application/octet-stream", displayName));
        }
Exemplo n.º 9
0
        public static Stream GetFile(GetFileParameters parameters)
        {
            string displayName = string.IsNullOrEmpty(parameters.DisplayName) ?
                                 Path.GetFileName(parameters.Path) : Uri.EscapeDataString(parameters.DisplayName);

            Stream fileStream = annotator.GetFile(parameters.Path).Stream;

            //jquery.fileDownload uses this cookie to determine that a file download has completed successfully
            HttpContext.Current.Response.SetCookie(new HttpCookie("jqueryFileDownloadJSForGD", "true")
            {
                Path = "/"
            });

            return(fileStream);
        }
        private Watermark GetWatermark(GetFileParameters request)
        {
            if (string.IsNullOrWhiteSpace(request.WatermarkText))
            {
                return(null);
            }

            return(new Watermark(request.WatermarkText)
            {
                Color = request.WatermarkColor.HasValue
                        ? Color.FromArgb(request.WatermarkColor.Value)
                        : (Color?)Color.Red,
                Position = ToWatermarkPosition(request.WatermarkPosition),
                Width = request.WatermarkWidth
            });
        }
Exemplo n.º 11
0
        async private Task DownloadFileFromLastPosition(FileInfo fileinfo, int fileInDirNo, int filesinDirCount, WebDavResource fileResource)
        {
            long starPos            = (fileinfo.Length / BLOCK_SIZE) * BLOCK_SIZE;
            var  downloadParameters = new GetFileParameters {
                Headers = new List <KeyValuePair <string, string> > {
                    new KeyValuePair <string, string>("Range", "bytes=" + starPos.ToString() + "-" + fileResource.ContentLength)
                }.AsReadOnly()
            };

            using (var response = await Client.GetRawFile(fileResource.Uri, downloadParameters)) {
                using (var fileStream = fileinfo.OpenWrite()) {
                    fileStream.Position = starPos;
                    long downloadSize = (fileResource.ContentLength ?? 0) - starPos;
                    await WriteWebDavToFile(downloadSize, response.Stream, fileinfo, fileInDirNo, filesinDirCount, fileStream);
                }
            }
        }
        public override void ProcessRequest(HttpContext context)
        {
            try
            {
                GetFileParameters   parameters        = new GetFileParameters();
                NameValueCollection requestParameters = context.Request.Params;
                parameters.Path                  = GetParameter <string>(requestParameters, "path");
                parameters.DisplayName           = GetParameter <string>(requestParameters, "displayName");
                parameters.GetPdf                = GetParameter <bool>(requestParameters, "getPdf");
                parameters.WatermarkText         = GetParameter <string>(requestParameters, "watermarkText");
                parameters.WatermarkColor        = GetParameter <int?>(requestParameters, "watermarkColor");
                parameters.WatermarkPosition     = GetParameter <WatermarkPosition>(requestParameters, "watermarkPosition");
                parameters.WatermarkWidth        = GetParameter <float>(requestParameters, "watermarkWidth");
                parameters.IgnoreDocumentAbsence = GetParameter <bool>(requestParameters, "ignoreDocumentAbsence");
                parameters.UseHtmlBasedEngine    = GetParameter <bool>(requestParameters, "useHtmlBasedEngine");
                parameters.SupportPageRotation   = GetParameter <bool>(requestParameters, "supportPageRotation");
                parameters.InstanceIdToken       = GetParameter <string>(requestParameters, Constants.InstanceIdRequestKey);

                context.Response.ContentType = "application/octet-stream";
                byte[] bytes;
                string fileDisplayName;
                bool   isSuccessful = GetFile(parameters, out bytes, out fileDisplayName);
                if (!isSuccessful || bytes == null)
                {
                    return;
                }

                context.Response.AddHeader("Content-Disposition",
                                           String.Format("attachment;filename=\"{0}\"", fileDisplayName));

                HttpCookie jqueryFileDownloadCookie = new HttpCookie(Constants.JqueryFileDownloadCookieName);
                jqueryFileDownloadCookie.Path  = "/";
                jqueryFileDownloadCookie.Value = "true";
                context.Response.Cookies.Add(jqueryFileDownloadCookie);
                context.Response.BinaryWrite(bytes);
            }
            catch (Exception exception)
            {
                OnException(exception, context);
            }
        }
Exemplo n.º 13
0
        public override void ProcessRequest(HttpContext context)
        {
            try
            {
                if (!_helper.IsRequestHandlingEnabled(Constants.GroupdocsPrintRequestHandlingIsEnabled))
                {
                    return;
                }

                GetFileParameters   parameters        = new GetFileParameters();
                NameValueCollection requestParameters = context.Request.Params;
                parameters.Path                  = GetParameter <string>(requestParameters, "path");
                parameters.GetPdf                = true;
                parameters.IsPrintable           = true;
                parameters.WatermarkText         = GetParameter <string>(requestParameters, "watermarkText");
                parameters.WatermarkColor        = GetParameter <int?>(requestParameters, "watermarkColor");
                parameters.WatermarkPosition     = GetParameter <WatermarkPosition>(requestParameters, "watermarkPosition");
                parameters.WatermarkWidth        = GetParameter <float>(requestParameters, "watermarkWidth");
                parameters.IgnoreDocumentAbsence = false;
                parameters.UseHtmlBasedEngine    = GetParameter <bool>(requestParameters, "useHtmlBasedEngine");
                parameters.SupportPageRotation   = GetParameter <bool>(requestParameters, "supportPageRotation");
                parameters.InstanceIdToken       = GetParameter <string>(requestParameters, Constants.InstanceIdRequestKey);

                byte[] bytes;
                string fileDisplayName;
                bool   isSuccessful = GetFile(parameters,
                                              out bytes, out fileDisplayName);
                if (!isSuccessful || bytes == null)
                {
                    return;
                }

                context.Response.ContentType = "application/pdf";
                context.Response.BinaryWrite(bytes);
            }
            catch (Exception exception)
            {
                OnException(exception, context);
            }
        }
        public ActionResult GetPdfWithPrintDialog(GetFileParameters parameters)
        {
            var displayName = string.IsNullOrEmpty(parameters.DisplayName) ?
                              Path.GetFileName(parameters.Path) : Uri.EscapeDataString(parameters.DisplayName);

            var pdfFileOptions = new PdfFileOptions
            {
                Guid            = parameters.Path,
                AddPrintAction  = parameters.IsPrintable,
                Transformations = Transformation.Rotate | Transformation.Reorder,
                Watermark       = GetWatermark(parameters),
            };
            var response = _htmlHandler.GetPdfFile(pdfFileOptions);

            string contentDispositionString = new ContentDisposition {
                FileName = displayName, Inline = true
            }.ToString();

            Response.AddHeader("Content-Disposition", contentDispositionString);

            return(File(((MemoryStream)response.Stream).ToArray(), "application/pdf"));
        }
        public ActionResult GetPdfWithPrintDialog(GetFileParameters parameters)
        {
            if (!_helper.IsRequestHandlingEnabled(Constants.GroupdocsPrintRequestHandlingIsEnabled))
            {
                return(new EmptyResult());
            }

            byte[] bytes;
            string fileDisplayName;
            bool   isSuccessful = _coreHandler.GetFile(parameters,
                                                       out bytes, out fileDisplayName);

            if (!isSuccessful)
            {
                return(new EmptyResult());
            }
            string contentDispositionString = new ContentDisposition {
                FileName = fileDisplayName, Inline = true
            }.ToString();

            Response.AddHeader("Content-Disposition", contentDispositionString);
            return(File(bytes, "application/pdf"));
        }
        public ActionResult GetFile(GetFileParameters parameters)
        {
            byte[] bytes;
            string fileDisplayName;
            bool   isSuccessful = _coreHandler.GetFile(parameters,
                                                       out bytes, out fileDisplayName);

            if (!isSuccessful)
            {
                return(new EmptyResult());
            }
            if (bytes == null)
            {
                if (Request != null)
                {
                    if (Request.Cookies[Constants.JqueryFileDownloadCookieName] != null)
                    {
                        var httpCookie = Response.Cookies[Constants.JqueryFileDownloadCookieName];
                        if (httpCookie != null)
                        {
                            httpCookie.Expires = DateTime.Now.AddYears(-1);
                        }
                    }
                }
                return(Content("File not found"));
            }

            if (Response != null)
            {
                //jquery.fileDownload uses this cookie to determine that a file download has completed successfully
                Response.SetCookie(new HttpCookie(Constants.JqueryFileDownloadCookieName, "true")
                {
                    Path = "/"
                });
            }
            return(File(bytes, "application/octet-stream", fileDisplayName));
        }
        public ActionResult GetFile(GetFileParameters parameters)
        {
            var displayName = string.IsNullOrEmpty(parameters.DisplayName) ?
                              Path.GetFileName(parameters.Path) : Uri.EscapeDataString(parameters.DisplayName);

            Stream fileStream;

            if (parameters.GetPdf)
            {
                displayName = Path.ChangeExtension(displayName, "pdf");

                var getPdfFileRequest = new PdfFileOptions
                {
                    Guid            = parameters.Path,
                    AddPrintAction  = parameters.IsPrintable,
                    Transformations = Transformation.Rotate | Transformation.Reorder,
                    Watermark       = GetWatermark(parameters),
                };

                var pdfFileResponse = _htmlHandler.GetPdfFile(getPdfFileRequest);
                fileStream = pdfFileResponse.Stream;
            }
            else
            {
                var fileResponse = _htmlHandler.GetFile(parameters.Path);
                fileStream = fileResponse.Stream;
            }

            //jquery.fileDownload uses this cookie to determine that a file download has completed successfully
            Response.SetCookie(new HttpCookie("jqueryFileDownloadJSForGD", "true")
            {
                Path = "/"
            });

            return(File(GetBytes(fileStream), "application/octet-stream", displayName));
        }
        public override void ProcessRequest(HttpContext context)
        {
            try
            {
                if (!_helper.IsRequestHandlingEnabled(Constants.GroupdocsPrintRequestHandlingIsEnabled))
                    return;

                GetFileParameters parameters = new GetFileParameters();
                NameValueCollection requestParameters = context.Request.Params;
                parameters.Path = GetParameter<string>(requestParameters, "path");
                parameters.GetPdf = true;
                parameters.IsPrintable = true;
                parameters.WatermarkText = GetParameter<string>(requestParameters, "watermarkText");
                parameters.WatermarkColor = GetParameter<int?>(requestParameters, "watermarkColor");
                parameters.WatermarkPosition = GetParameter<WatermarkPosition>(requestParameters, "watermarkPosition");
                parameters.WatermarkWidth = GetParameter<float>(requestParameters, "watermarkWidth");
                parameters.IgnoreDocumentAbsence = false;
                parameters.UseHtmlBasedEngine = GetParameter<bool>(requestParameters, "useHtmlBasedEngine");
                parameters.SupportPageRotation = GetParameter<bool>(requestParameters, "supportPageRotation");
                parameters.InstanceIdToken = GetParameter<string>(requestParameters, Constants.InstanceIdRequestKey);

                byte[] bytes;
                string fileDisplayName;
                bool isSuccessful = GetFile(parameters,
                                         out bytes, out fileDisplayName);
                if (!isSuccessful || bytes == null)
                    return;

                context.Response.ContentType = "application/pdf";
                context.Response.BinaryWrite(bytes);
            }
            catch (Exception exception)
            {
                OnException(exception, context);
            }
        }
Exemplo n.º 19
0
        public byte[] GetFile(string filename1, ProgressCallback progressCallback)
        {
            var webDav = GetWebDavClient();
            var yaFile = new YandexDiscFile(filename1, Location, webDav);

            var props = new GetFileParameters();

            props.OperationProgress = args =>
            {
                progressCallback?.Invoke(args.Progress);
            };

            using (var response = webDav.GetFile(yaFile.Uri, false, props))
            {
                if (!response.IsSuccessful)
                {
                    throw new ApplicationException($"Unable read file: --> {response.StatusCode} {response.Description}");
                }

                var data = new byte[response.Stream.Length];
                response.Stream.Read(data, 0, data.Length);
                return(data);
            }
        }
Exemplo n.º 20
0
 public static void GetFile(GetFileParameters parameters)
 {
     HttpContext.Current.Session["fileparams"] = parameters;
 }
        public ActionResult GetPdfWithPrintDialog(GetFileParameters parameters)
        {
            if (!_helper.IsRequestHandlingEnabled(Constants.GroupdocsPrintRequestHandlingIsEnabled))
                return new EmptyResult();

            byte[] bytes;
            string fileDisplayName;
            bool isSuccessful = _coreHandler.GetFile(parameters,
                                    out bytes, out fileDisplayName);
            if (!isSuccessful)
                return new EmptyResult();
            string contentDispositionString = new ContentDisposition { FileName = fileDisplayName, Inline = true }.ToString();
            Response.AddHeader("Content-Disposition", contentDispositionString);
            return File(bytes, "application/pdf");
        }
        public ActionResult GetFile(GetFileParameters parameters)
        {
            byte[] bytes;
            string fileDisplayName;
            bool isSuccessful = _coreHandler.GetFile(parameters,
                                                    out bytes, out fileDisplayName);
            if (!isSuccessful)
            {
                return new EmptyResult();
            }
            if (bytes == null)
            {
                if (Request != null)
                {
                    if (Request.Cookies[Constants.JqueryFileDownloadCookieName] != null)
                    {
                        var httpCookie = Response.Cookies[Constants.JqueryFileDownloadCookieName];
                        if (httpCookie != null)
                            httpCookie.Expires = DateTime.Now.AddYears(-1);
                    }
                }
                return Content("File not found");
            }

            if (Response != null)
            {
                //jquery.fileDownload uses this cookie to determine that a file download has completed successfully
                Response.SetCookie(new HttpCookie(Constants.JqueryFileDownloadCookieName, "true") { Path = "/" });
            }
            return File(bytes, "application/octet-stream", fileDisplayName);
        }