public byte[] Generate(Guid docId, string fileName, IStringParams prms) { using (var stream = new MemoryStream()) { using (var documentBuilder = new DocumentBuilder(fileName, stream, "\\windows\\fonts\\times.ttf")) { using (var dynaDoc = new DynaDoc(docId, UserId, Provider)) FillDoc(documentBuilder, "", dynaDoc); FillDoc(documentBuilder, prms); } return(stream.GetBuffer()); } }
/* * * public ExcelTemplateRepository(IDataContext dataContext, Guid userId) * { * if (dataContext == null) * { * DataContext = new DataContext(); * _ownDataContext = true; * } * else * DataContext = dataContext; * UserId = userId; * } * * public ExcelTemplateRepository(Guid userId) : this(null, userId) {} */ public Stream Generate(Doc document, string fileName) { using (var temp = new FileStream(fileName, FileMode.Open)) { using (var wb = new HSSFWorkbook(temp)) { using (var dynaDoc = new DynaDoc(document, UserId, Provider)) FillDoc(wb, "", dynaDoc); var stream = new MemoryStream(); wb.Write(stream); return(stream); } } }
public Stream Generate(Doc document, string fileName, IStringParams prms) { var stream = new MemoryStream(); try { using (var documentBuilder = new DocumentBuilder(fileName, stream, "\\windows\\fonts\\times.ttf")) { if (document != null) { using (var dynaDoc = new DynaDoc(document, UserId, Provider)) FillDoc(documentBuilder, "", dynaDoc); } FillDoc(documentBuilder, prms); } return(stream); } catch { stream.Dispose(); throw; } }
private void FillDoc(DocumentBuilder builder, string prefix, DynaDoc doc) { var pref = String.IsNullOrEmpty(prefix) ? "" : prefix + "."; //foreach (var attr in doc.Doc.Attributes) //{ // var fn = Logger.GetLogFileName("ReportManagerError"); // Logger.OutputLog(fn, "ERROR BLOB: " + attr.AttrDef.Name + " ----- " + attr.GetType() + " ----- " + attr.ObjectValue.ToString().Length + " ----- " + (attr is BlobAttribute)); //} foreach (var attr in doc.Doc.Attributes) { var value = attr.ObjectValue; try { if (attr is BlobAttribute) { //var fn = Logger.GetLogFileName("ReportManagerError"); //Logger.OutputLog(fn, "ERROR BLOB: " + attr.AttrDef.Name + " ----- " + attr.GetType()); IDocRepository _docRepo = Provider.Get <IDocRepository>(); BlobData img = _docRepo.GetBlobAttrData(doc.Doc.Id, attr.AttrDef); //Logger.OutputLog(fn, "ERROR BLOB: " + img.FileName); // We assume only Image types blobs are used in reports builder.SetBlobField(pref + attr.AttrDef.Name, img.Data); continue; } } catch (Exception e) { var fn = Logger.GetLogFileName("ReportManagerError"); Logger.OutputLog(fn, e, e.Message); } if (value == null) { continue; } if (attr is DocAttribute) { var attrDoc = doc.GetAttrDoc((DocAttribute)attr); if (attrDoc != null) { using (var dynaDoc = new DynaDoc(attrDoc, UserId, Provider)) FillDoc(builder, pref + attr.AttrDef.Name, dynaDoc); } } else if (attr is DocListAttribute) { var index = 0; foreach (var docItem in doc.GetAttrDocList((DocListAttribute)attr)) { using (var dynaDoc = new DynaDoc(docItem, UserId, Provider)) FillDoc(builder, string.Format("{0}{1}.{2}", pref, attr.AttrDef.Name, index), dynaDoc); index++; } } else if (attr is EnumAttribute) { var enumValue = doc.GetAttrEnum((EnumAttribute)attr); if (enumValue != null) { builder.SetField(pref + attr.AttrDef.Name, enumValue.Value); } } else if (attr is DateTimeAttribute) { builder.SetField(pref + attr.AttrDef.Name, String.Format("{0:d}", value)); } else if (attr is CurrencyAttribute || attr is FloatAttribute) { builder.SetField(pref + attr.AttrDef.Name, String.Format("{0:F2}", value)); } else { builder.SetField(pref + attr.AttrDef.Name, value); } } }
public void Save(DynaDoc doc) { _docRepo.Save(doc.Doc); }