示例#1
0
        public ActionResult SubmitFiles(
            RFDate?valueDate = null,
            string returnUrl = null,
            string instance  = null
            )
        {
            try
            {
                if (Request.Files == null || Request.Files.Count == 0)
                {
                    throw new RFSystemException(this, "No files submitted.");
                }

                var processKey  = String.Format("{0}_web", DateTime.Now.ToString("yyyyMMdd_HHmmss"));
                var submittable = new List <RFCatalogEntryDTO>();
                int uqIdx       = 1;

                foreach (var knownFileEnum in RIFF.Web.Core.App_Start.RIFFStart.Config.GetInputFileKeys())
                {
                    // match up by string (or could have registered an enum type...)
                    foreach (string inputFileKey in Request.Files.Keys)
                    {
                        if (knownFileEnum.ToString() == inputFileKey)
                        {
                            var inputFile = Request.Files[inputFileKey] as HttpPostedFileBase;
                            if (inputFile != null && inputFile.ContentLength > 0)
                            {
                                var uniqueKey = String.Format("{0}_web_{1}", DateTime.Now.ToString("yyyyMMdd_HHmmss"), uqIdx++);

                                var doc = RFDocument.Create(
                                    RFFileKey.Create(
                                        EngineConfig.KeyDomain,
                                        knownFileEnum,
                                        uniqueKey),
                                    new RFFile
                                {
                                    Attributes = new RFFileTrackedAttributes
                                    {
                                        FileName     = inputFile.FileName,
                                        FullPath     = inputFile.FileName,
                                        FileSize     = inputFile.ContentLength,
                                        ModifiedDate = DateTime.Now
                                    },
                                    Data      = RFStreamHelpers.ReadBytes(inputFile.InputStream),
                                    FileKey   = knownFileEnum,
                                    ValueDate = valueDate,
                                    UniqueKey = uniqueKey
                                });

                                if (instance.NotBlank() && valueDate.HasValue)
                                {
                                    doc.Key.GraphInstance = new RFGraphInstance {
                                        Name = instance, ValueDate = valueDate.Value
                                    };
                                }

                                submittable.Add(new RFCatalogEntryDTO(doc));
                            }
                        }
                    }
                }

                using (var rfService = new RFServiceClient())
                {
                    RFProcessingTrackerHandle trackerKey = null;
                    trackerKey = rfService.RFService.SubmitAndProcess(submittable, new RFUserLogEntry
                    {
                        Action       = "Upload Files",
                        Description  = String.Format("Uploaded {0} files for processing", submittable.Count),
                        IsUserAction = true,
                        IsWarning    = false,
                        Processor    = null,
                        ValueDate    = valueDate.HasValue ? valueDate.Value : RFDate.NullDate,
                        Username     = Username
                    });
                    //lock (sSync)
                    {
                        AddModelToCache(processKey, new ProcessingModel
                        {
                            Tracker       = trackerKey,
                            ProcessingKey = processKey,
                            ReturnUrl     = returnUrl
                        });
                    }
                    return(RedirectToAction("ProcessingStatus", new { processKey = processKey }));
                }
            }
            catch (Exception ex)
            {
                Log.Exception(this, "SubmitFiles", ex);
                return(Error("InputFiles", "System", null, "Error submitting files: {0}", ex.Message));
            }
        }
示例#2
0
        public ActionResult SubmitFile(
            string fileKey,
            HttpPostedFileBase fileData,
            RFDate?valueDate,
            string returnUrl = null,
            string instance  = null)
        {
            try
            {
                if (fileData == null && Request.Files != null && Request.Files.Count > 0)
                {
                    fileData = Request.Files[0];
                }
                var uniqueKey = String.Format("{0}_web", DateTime.Now.ToString("yyyyMMdd_HHmmss"));
                if (fileData == null || fileData.FileName == null || fileData.InputStream == null)
                {
                    throw new RFSystemException(this, "No file submitted.");
                }

                var fileName = Path.GetFileName(fileData.FileName);

                var newFileEntry = RFDocument.Create(
                    RFFileKey.Create(
                        EngineConfig.KeyDomain,
                        RFEnum.FromString(fileKey),
                        uniqueKey),
                    new RFFile
                {
                    Attributes = new RFFileTrackedAttributes
                    {
                        FileName     = fileName,
                        FullPath     = fileData.FileName,
                        FileSize     = fileData.ContentLength,
                        ModifiedDate = DateTime.Now
                    },
                    Data      = RFStreamHelpers.ReadBytes(fileData.InputStream),
                    FileKey   = RFEnum.FromString(fileKey),
                    ValueDate = valueDate,
                    UniqueKey = uniqueKey
                });

                // the file will have graph instance attached
                if (instance.NotBlank() && valueDate.HasValue)
                {
                    newFileEntry.Key.GraphInstance = new RFGraphInstance
                    {
                        Name      = instance,
                        ValueDate = valueDate.Value
                    };
                }

                using (var rfService = new RFServiceClient())
                {
                    RFProcessingTrackerHandle trackerKey = null;
                    trackerKey = rfService.RFService.SubmitAndProcess(new List <RFCatalogEntryDTO> {
                        new RFCatalogEntryDTO(newFileEntry)
                    }, new RFUserLogEntry
                    {
                        Action       = "Upload File",
                        Description  = String.Format("Uploaded file {0} for processing", fileName),
                        IsUserAction = true,
                        IsWarning    = false,
                        Processor    = null,
                        ValueDate    = valueDate.HasValue ? valueDate.Value : RFDate.NullDate,
                        Username     = Username
                    });
                    //lock (sSync)
                    {
                        AddModelToCache(uniqueKey, new ProcessingModel
                        {
                            Tracker       = trackerKey,
                            ProcessingKey = uniqueKey,
                            FileKey       = fileKey,
                            FileName      = fileName,
                            FileSize      = fileData.ContentLength,
                            ReturnUrl     = returnUrl
                        });
                    }
                    return(RedirectToAction("ProcessingStatus", new { processKey = uniqueKey }));
                }
            }
            catch (Exception ex)
            {
                Log.Exception(this, "SubmitFile", ex);
                return(Error("InputFiles", "System", null, "Error submitting file: {0}", ex.Message));
            }
        }