/// <summary> /// Generates a diffgram object graph corresponding /// to the provided business object graph. /// </summary> /// <param name="root">Root of the business object graph /// to be exported into the diffgram.</param> /// <returns> /// A DataItem representing the root of the diffgram object graph. /// </returns> public DataItem GenerateGraph(IExportData root) { if (root != null && root.IsParticipating) { _lastKey++; root.Key = _lastKey; DataItem result = new DataItem { Key = root.Key }; var track = root as Csla.Core.ITrackStatus; if (track != null) { result.IsNew = track.IsNew; result.IsDeleted = track.IsDeleted; } root.ExportTo(result); foreach (var item in root.GetChildren()) { var ci = GenerateGraph(item); if (ci != null) result.Children.Add(ci); } return result; } else return null; }
/// <summary> /// Generates a diffgram object graph corresponding /// to the provided business object graph. /// </summary> /// <param name="root">Root of the business object graph /// to be exported into the diffgram.</param> /// <returns> /// A DataItem representing the root of the diffgram object graph. /// </returns> public DataItem GenerateGraph(IExportData root) { if (root != null && root.IsParticipating) { _lastKey++; root.Key = _lastKey; DataItem result = new DataItem { Key = root.Key }; var track = root as Csla.Core.ITrackStatus; if (track != null) { result.IsNew = track.IsNew; result.IsDeleted = track.IsDeleted; } root.ExportTo(result); foreach (var item in root.GetChildren()) { var ci = GenerateGraph(item); if (ci != null) { result.Children.Add(ci); } } return(result); } else { return(null); } }
/// <summary> /// Integrates a diffgram object graph into an /// existing business object graph. /// </summary> /// <param name="root">Root of the business object graph.</param> /// <param name="dtoGraph">Root of the diffgram object /// graph containing the data used to update the business /// object graph.</param> public void IntegrateGraph(IExportData root, DataItem dtoGraph) { if (root != null && root.IsParticipating) { if (root.Key == dtoGraph.Key) { foreach (var child in root.GetChildren().Where(c => c.IsParticipating)) { var dto = (from d in dtoGraph.Children where d.Key == child.Key select d).SingleOrDefault(); if (dto != null) { IntegrateGraph(child, dto); } else { throw new Exception("Child key not in DTO graph"); } } root.ImportFrom(dtoGraph); } else { throw new Exception("Root object keys don't match"); } } }
/// <summary> /// Integrates a diffgram object graph into an /// existing business object graph. /// </summary> /// <param name="root">Root of the business object graph.</param> /// <param name="dtoGraph">Root of the diffgram object /// graph containing the data used to update the business /// object graph.</param> public void IntegrateGraph(IExportData root, DataItem dtoGraph) { if (root != null && root.IsParticipating) { if (root.Key == dtoGraph.Key) { foreach (var child in root.GetChildren().Where(c => c.IsParticipating)) { var dto = (from d in dtoGraph.Children where d.Key == child.Key select d).SingleOrDefault(); if (dto != null) IntegrateGraph(child, dto); else throw new Exception("Child key not in DTO graph"); } root.ImportFrom(dtoGraph); } else throw new Exception("Root object keys don't match"); } }
public override void ExportContent(out IExportData data) { data = new ExportNodes(nodes); }
public FileController(IExportData exportToFile) { _exportData = exportToFile; }
private void ExportEmployees(IExportData export) { export.Export(); }
public virtual void ExportContent(out IExportData data) { data = null; }
public override void ExportContent(out IExportData data) { throw new NotImplementedException(); }
public async Task <bool> HandleSuccessfulReqeustAsync(HttpContext context, object body, IExportData exportData) { var contentType = ""; var fileStr = !exportData.FileName.IsNullOrWhiteSpace() ? exportData.FileName + "_" : ""; string filename = fileStr + DateTime.Now.ToString("yyyyMMddHHmmss"); byte[] result = null; switch (context.Request.Headers["exportType"]) { case ExportType.Excel: filename += ".xlsx"; var dt = ToDataTable(body?.ToString()); contentType = HttpContentMediaType.XLSXHttpContentMediaType; var exporter = new ExcelExporter(); result = await exporter.ExportAsByteArray(dt, exportData.Type); break; case ExportType.PDF: filename += ".pdf"; contentType = HttpContentMediaType.PDFHttpContentMediaType; IExportFileByTemplate pdfexporter = new PdfExporter(); var tpl = File.ReadAllText(exportData.TemplatePath); var obj = JsonConvert.DeserializeObject(body.ToString(), exportData.Type); result = await pdfexporter.ExportBytesByTemplate(obj, tpl, exportData.Type); break; case ExportType.Word: filename += ".docx"; contentType = HttpContentMediaType.DOCXHttpContentMediaType; IExportFileByTemplate docxexporter = new WordExporter(); result = await docxexporter.ExportBytesByTemplate(JsonConvert.DeserializeObject(body.ToString(), exportData.Type), File.ReadAllText(exportData.TemplatePath), exportData.Type); break; } if (contentType != "") { //必须清空原有响应返回内容,否则会抛异常 System.InvalidOperationException: Response Content-Length mismatch: too few bytes written context.Response.Clear(); context.Response.Headers.Add("Content-Disposition", $"attachment;filename={HttpUtility.UrlEncode(filename)}"); context.Response.ContentType = contentType; if (result != null) { await context.Response.Body.WriteAsync(result, 0, result.Length); } } else { return(false); } return(true); }
public CustomerController(ICustomerSearch customerSearch,IExportData exportData) { _customerSearch = customerSearch; _exportData = exportData; }