public System.Web.Mvc.ActionResult UploadFiles(FormCollection form)
        {
            var fileClient = SvcBldr.FileTransferV2();
            var ieClient = SvcBldr.ImportExport();
            var uploadFileName = Functions.NewSeq().ToString() + ".zip";
            foreach (string item in Context.Request.Files)
            {
                var file = Context.Request.Files.Get(item);

                byte[] fs = new byte[file.InputStream.Length];
                file.InputStream.Read(fs, 0, fs.Length);
                RemoteFileHandler.UploadFile(uploadFileName, fs, fileClient);

                break;
            }
            var pkg = new ImportEntitiesPackage
            {
                ZipFile = uploadFileName,
                OverwriteExisting = form["overwrite"] == "on",
                MachineId = Functions.GetMachineId(), // this will be the webServer's machineId; not some client machine
                MachineName = String.Empty       // Let's leave this empty to distinguish EntityExchange jobs from client-initiated jobs
            };
            var sr = ieClient.ImportEntities(pkg);
            // Progress Monitoring done in javascript via CheckImportStatus
            return View("ImportFrame", sr);
        }
Beispiel #2
0
        public mvc.ActionResult ProcessDownloadRequestResult()
        {
            Guid id         = new Guid(Request.QueryString["id"]);
            Guid instanceId = new Guid(Request.QueryString["instanceId"]);
            var  password   = Request.QueryString["password"];
            var  fileId     = Request.QueryString["fileId"];
            SR <ProxyAuthRequestResult> sr = null;

            try
            {
                var client = SvcBldr.SecurityV2();
                sr = client.GetProxyRequest(new GetProxyRequestArgs {
                    Id = id, InstanceId = instanceId, Password = password
                });
                ExceptionsML.Check(sr.Error);

                BaseToken = sr.Result.Token;

                var ip       = GetIP();
                var server   = GetServerURI();
                var sb       = new ServiceBuilder(server, BaseToken, ip);
                var fileName = Path.GetFileName(fileId);
                var mimeType = fileId.GetMIMEType();
                var ftSvc    = sb.FileTransferV2();
                var bytes    = RemoteFileHandler.DownloadFile(fileId, ftSvc);
                return(File(bytes, mimeType, fileName));
            }
            catch (LoginRequiredException lex)
            {
                if (lex.Reason == LoginRequiredReason.ProxyMoveInProgress)
                {
                    var proxyUrl = Functions.GetAuthenticationProxyUrl();
                    var domain   = Functions.GetProxyCookieDomain();
                    var url      = Functions.CombineUri(proxyUrl, "Guest");
                    url += String.Format("?RequestId={0}&InstanceId={1}&auto={2}", id, instanceId, String.IsNullOrEmpty(password));
                    return(View("../Home/Oops", new ExceptionsML {
                        Message = url, Type = LoginRequiredReason.ProxyMoveInProgress.ToString()
                    }));
                }
                return(View("../Home/Oops", ExceptionsML.GetExceptionML(lex)));
            }
            catch (RecordNotFoundException rex)
            {
                return(View("../Home/Oops", new ExceptionsML {
                    Message = Constants.i18n("invalidGuestDownloadRequest"), Type = rex.GetType().ToString()
                }));
            }
            catch (Exception ex) { return(View("../Home/Oops", ExceptionsML.GetExceptionML(ex))); }
        }
Beispiel #3
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));
            }
        }