public JsonResult GetLatestDocuments(RFDate?valueDate = null, bool validOnly = true) { using (var dataEditor = new RFDataEditorActivity(Context, Username)) { return(Json(dataEditor.GetDocuments(null, null, null, 0, valueDate, true) .Where(d => !validOnly || d.IsValid) .Where(d => d.KeyType != "RIFF.Framework.RFFileKey") .GroupBy(d => new Tuple <string, string, string>(d.KeyType, d.ContentType, d.Key.FriendlyString())) .Select(d => new { Key = d.Key, Latest = d.OrderByDescending(i => i.Instance?.ValueDate).First(), All = d.AsEnumerable() }) .Select(d => new { FriendlyString = d.Key.Item3, KeyReference = d.Latest.KeyReference, KeyTypeFull = d.Key.Item1, Plane = d.Latest.Key.Plane.ToString(), ContentTypeFull = d.Key.Item2, DataSize = d.Latest.DataSize, IsValid = d.Latest.IsValid, UpdateTime = d.Latest.UpdateTime, IsLatest = (d.Latest.Key.GraphInstance?.ValueDate == null || d.Latest.Key.GraphInstance.ValueDate.Value == RFDate.NullDate || d.Latest.Key.GraphInstance?.ValueDate.Value == valueDate), ValueDate = (d.Latest.Key.GraphInstance?.ValueDate == null || d.Latest.Key.GraphInstance.ValueDate.Value == RFDate.NullDate) ? null : d.Latest.Key.GraphInstance.ValueDate.Value.ToJavascript(), /*Instances = d.All.Select(i => new * { * KR = i.KeyReference, * UT = i.UpdateTime, * VD = (i.Key.GraphInstance != null && i.Key.GraphInstance.ValueDate.HasValue && i.Key.GraphInstance.ValueDate.Value != RFDate.NullDate) ? i.Key.GraphInstance.ValueDate.Value.ToJavascript() : null, * DS = i.DataSize * })*/ }))); } }
public JsonResult GetDocumentForEdit(string type, long keyReference) { using (var dataEditor = new RFDataEditorActivity(Context, Username)) { return(Json(dataEditor.GetDocumentForEdit(type, keyReference))); } }
public static List <RFCatalogKeyData> RefreshCache(IRFProcessingContext context, string username) { using (var dataEditor = new RFDataEditorActivity(context, username)) { var cache = dataEditor.GetDocuments(null, null, null, 0, null, true).Select(d => new RFCatalogKeyData { Key = JsonConvert.SerializeObject(d.Key), FriendlyString = d.Key.FriendlyString(), KeyReference = d.KeyReference, KeyType = RFReflectionHelpers.TrimType(d.KeyType), KeyTypeFull = d.KeyType, Plane = d.Key.Plane.ToString(), ContentType = RFReflectionHelpers.TrimType(d.ContentType), ContentTypeFull = d.ContentType, DataSize = d.DataSize, Metadata = JsonConvert.SerializeObject(d.Metadata), IsValid = d.IsValid, UpdateTime = d.UpdateTime, Instance = d.Key.GraphInstance != null ? d.Key.GraphInstance.Name : null, ValueDate = (d.Key.GraphInstance != null && d.Key.GraphInstance.ValueDate.HasValue && d.Key.GraphInstance.ValueDate.Value != RFDate.NullDate) ? d.Key.GraphInstance.ValueDate.Value.ToJavascript() : null }).ToList(); lock (_sync) { _cache = cache; } return(cache); } }
public ActionResult InvalidateEntry(string type, long keyReference) { using (var dataEditor = new RFDataEditorActivity(Context, Username)) { var entry = dataEditor.GetDocumentForDownload(type, keyReference); if (entry != null) { Context.Invalidate(entry.Key); } } return(RedirectToAction("DataEditor", "System", new { area = "" })); }
public FileResult DownloadEntry(string type, long keyReference) { using (var dataEditor = new RFDataEditorActivity(Context, Username)) { var entry = dataEditor.GetDocumentForDownload(type, keyReference); if (entry != null) { var shortType = System.IO.Path.GetExtension(type).TrimStart('.'); var content = entry.Content; if (content is IRFDataSet) { var namePart = entry.Key.FriendlyString(); Array.ForEach(Path.GetInvalidFileNameChars(), c => namePart = namePart.Replace(c.ToString(), String.Empty)); var date = (entry.Key.GraphInstance != null ? entry.Key.GraphInstance.ValueDate : null) ?? DateTime.Now; return(File(RIFF.Interfaces.Formats.XLSX.XLSXGenerator.ExportToXLSX(type, content as IRFDataSet), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", String.Format("{0}_{3}-{1}-{2}.xlsx", namePart, shortType, keyReference, date.ToString("yyyyMMdd")))); } else if (entry.Content is RFFile) { var file = entry.Content as RFFile; return(File(file.Data, ImplyContentType(file.ContentName), file.Attributes.FileName)); } else if (entry.Content is RFRawReport) { var report = entry.Content as RFRawReport; var csvBuilder = new StringBuilder(); foreach (var section in report.Sections) { try { csvBuilder.Append(CSVBuilder.FromDataTable(section.AsDataTable())); } catch (Exception ex) { Log.Warning(this, "Error exporting section {0} of report {1} to .csv: {2}", section.Name, report.ReportCode, ex.Message); } } return(File(Encoding.UTF8.GetBytes(csvBuilder.ToString()), "text/csv", String.Format("{0}_{1}.csv", report.ReportCode, report.ValueDate.ToString("yyyy-MM-dd")))); } else { var namePart = entry.Key.FriendlyString(); Array.ForEach(Path.GetInvalidFileNameChars(), c => namePart = namePart.Replace(c.ToString(), String.Empty)); var date = (entry.Key.GraphInstance != null ? entry.Key.GraphInstance.ValueDate : null) ?? DateTime.Now; var xml = RFXMLSerializer.PrettySerializeContract(content); return(File(Encoding.UTF8.GetBytes(xml), "text/xml", String.Format("{0}_{3}-{1}-{2}.xml", namePart, shortType, keyReference, date.ToString("yyyyMMdd")))); } } } return(null); }
public FileResult ExportEntry(string type, long keyReference) { using (var dataEditor = new RFDataEditorActivity(Context, Username)) { var entry = dataEditor.GetDocumentForDownload(type, keyReference); if (entry != null) { var shortType = System.IO.Path.GetExtension(type).TrimStart('.'); var xml = RFXMLSerializer.PrettySerializeContract(entry); return(File(Encoding.UTF8.GetBytes(xml), "text/xml", String.Format("RFDocument_{0}-{1}-{2}.xml", shortType, keyReference, DateTime.Now.ToString("yyyyMMdd_HHmmss")))); } } return(null); }
public JsonResult UpdateDocument(string type, long keyReference, string data) { if (!string.IsNullOrWhiteSpace(type) && keyReference > 0 && !string.IsNullOrWhiteSpace(data)) { try { using (var dataEditor = new RFDataEditorActivity(Context, Username)) { return(Json(dataEditor.UpdateDocument(type, keyReference, data))); } } catch (Exception ex) { return(Json(JsonError.Throw("UpdateDocument", ex))); } } return(Json(JsonError.Throw("UpdateDocument", "Internal system error."))); }
public JsonResult SaveDocument(string keyType, string contentType, string keyData, string contentData) { if (!string.IsNullOrWhiteSpace(keyType) && !string.IsNullOrWhiteSpace(keyData) && !string.IsNullOrWhiteSpace(contentType) && !string.IsNullOrWhiteSpace(contentData)) { try { using (var dataEditor = new RFDataEditorActivity(Context, Username)) { return(Json(dataEditor.SaveDocument(keyType, contentType, keyData, contentData))); } } catch (Exception ex) { return(Json(JsonError.Throw("SaveDocument", ex))); } } return(Json(JsonError.Throw("SaveDocument", "Internal system error."))); }
public JsonResult GetInstances(string keyType, long keyReference) { using (var dataEditor = new RFDataEditorActivity(Context, Username)) { var document = dataEditor.GetDocumentForDownload(keyType, keyReference); var fs = document.Key.FriendlyString(); var vd = document.Key.GraphInstance?.ValueDate; return(Json(dataEditor.GetDocuments(keyType, null, null, 0, null, false) .Where(d => d.IsValid && d.Key.FriendlyString() == fs && (!vd.HasValue || (d.Key.GraphInstance?.ValueDate == null) || d.Key.GraphInstance.ValueDate <= vd.Value)) .Select(d => new { KR = d.KeyReference, UT = d.UpdateTime, VD = (d.Key.GraphInstance != null && d.Key.GraphInstance.ValueDate.HasValue && d.Key.GraphInstance.ValueDate.Value != RFDate.NullDate) ? d.Key.GraphInstance.ValueDate.Value.ToJavascript() : null, DS = d.DataSize }))); } }