Example #1
0
        private mvc.ActionResult DownloadFiles(ProxyAuthRequestResult request, string connectionId)
        {
            try
            {
                BaseToken = request.Token;

                var ip     = GetIP();
                var server = GetServerURI();
                var sb     = new ServiceBuilder(server, request.Token, ip);
                sb.Options = ServiceRequestOptions.OverrideErrors;
                var         docClient   = sb.DocumentV2();
                var         documentIds = new List <Guid>();
                SendOptions sendOptions = new SendOptions
                {
                    ActionType         = ActionType.Downloaded,
                    ExportType         = ExportDocumentType.Native,
                    IncludeAnnotations = true,
                    IncludeRedactions  = true,
                    PageSelection      = null,
                    Password           = null
                };
                var parameters = new ProxySendOptions {
                    DocumentIds = null, SendOptions = null
                };
                if (request.Arguments.StartsWith("{"))
                {
                    parameters = JsonConvert.DeserializeObject <ProxySendOptions>(request.Arguments);
                }
                else if (request.Arguments.StartsWith("<?xml version=\"1.0\" encoding=\"utf-16\"?><ProxySendOptions"))
                {
                    parameters = (ProxySendOptions)parameters.DeserializeObject(request.Arguments);
                }
                else
                {
                    documentIds = (List <Guid>)documentIds.DeserializeObject(request.Arguments);
                }
                documentIds = parameters.DocumentIds ?? documentIds;
                sendOptions = parameters.SendOptions ?? sendOptions;
                sendOptions.ConnectionId = connectionId;
                sendOptions.ActionType   = ActionType.Downloaded; //Downloading here so the action type is always download.

                var sr = docClient.PrepForSend(new Framework.DataContracts.V2.PrepForSendPackage {
                    DocumentIds = documentIds.ToArray(), SendOptions = sendOptions
                });
                if (sr.Error != null)
                {
                    return(View("../Home/Oops", sr.Error));
                }

                if (sr.Result == Constants.GONE_OOP)
                {
                    return(new mvc.EmptyResult());
                }
                else
                {
                    var fileName = Path.GetFileName(sr.Result);
                    var mimeType = sr.Result.GetMIMEType();
                    var ftSvc    = sb.FileTransferV2();
                    var bytes    = RemoteFileHandler.DownloadFile(sr.Result, ftSvc);
                    return(File(bytes, mimeType, fileName));
                }
            }
            catch (Exception ex)
            {
                return(Result(null, ExceptionsML.GetExceptionML(ex), mvc.JsonRequestBehavior.AllowGet));
            }
        }