public IDnsDocument ExportResponse(IDnsResponseContext context, IDnsResponseAggregationMode aggregationMode, IDnsResponseExportFormat format) { throw new NotImplementedException(); }
public IDnsDocument ExportResponse(IDnsResponseContext context, IDnsResponseAggregationMode aggregationMode, IDnsResponseExportFormat format, string args) { using (StringWriter sw = new StringWriter()) { string filename = EXPORT_BASENAME + "_" + context.Request.Model.Name + "_" + context.Request.RequestID.ToString() + "." + format.ID; var DMDocs = new SortedDictionary <string, List <Document> >(); var lDocs = (from r in context.DataMartResponses from doc in r.Documents orderby r.DataMart.ID select new { Doc = doc, Name = doc.Name, ID = doc.ID, DataMartName = r.DataMart.Name, RevisionVersion = doc.RevisionVersion }); var docs = from r in lDocs group r by r.DataMartName into grp select new KeyValuePair <string, Document> ( grp.FirstOrDefault().DataMartName, grp.OrderByDescending(p => p.RevisionVersion).FirstOrDefault().Doc ); ZipHelper.DownloadZipToBrowser(HttpContext.Current, docs, filename); return(Dns.Document( name: filename, mimeType: FileHelper.GetMimeType(filename), isViewable: false, kind: DocumentKind.User, Data: Encoding.UTF8.GetBytes(sw.ToString()) )); } }
public IDnsDocument ExportResponse(IDnsResponseContext context, IDnsResponseAggregationMode aggregationMode, IDnsResponseExportFormat format, string args) { using (StringWriter sw = new StringWriter()) { DataSet ds = GetResponseDataSet(context, aggregationMode); string filename = EXPORT_BASENAME + "_" + context.Request.Model.Name + "_" + context.Request.RequestID.ToString() + "." + format.ID; switch (format.ID) { case "xlsx": ExcelHelper.ToExcel(ds, filename, HttpContext.Current.Response); break; case "csv": ExcelHelper.ToCSV(ds, sw); break; } return(Dns.Document( name: filename, mimeType: GetMimeType(filename), isViewable: false, kind: DocumentKind.User, Data: Encoding.UTF8.GetBytes(sw.ToString()) )); } }
public IDnsDocument ExportResponse(IDnsResponseContext context, IDnsResponseAggregationMode aggregationMode, IDnsResponseExportFormat format, string args) { return(null); }
public IDnsDocument ExportResponse(IDnsResponseContext context, IDnsResponseAggregationMode aggregationMode, IDnsResponseExportFormat format, string args) { using (StringWriter sw = new StringWriter()) { string filename = EXPORT_BASENAME + "_" + context.Request.Model.Name + "_" + context.Request.RequestID.ToString() + "." + format.ID; SortedDictionary <string, List <Document> > DMDocs = new SortedDictionary <string, List <Document> >(); #region "TO BE MOVED TO QUERYBUILDER UI" //#region "Generate a List of Documents Keyed on DataMarts for Aggregation" ////IEnumerable<IDnsPersistentDocument> docs = null; //var docs = from r in context.DataMartResponses // from doc in r.Documents // orderby r.DataMart.Id // select new { Id = r.DataMart.Id, Document = doc }; //foreach (var item in docs) //{ // if (!DMDocs.ContainsKey(item.Id.ToString())) DMDocs.Add(item.Id.ToString(), new List<IDnsPersistentDocument>()); // DMDocs[item.Id.ToString()].Add(item.Document); //} //#endregion ////Aggregate and Download //Workbook AggregatedWorkBook = null; //try //{ // AggregatedWorkBook = AggregateDocuments(DMDocs); // if (AggregatedWorkBook != null) // { // //present for download. // string DownloadFileName = filename; // //string DownloadPath = System.Web.Configuration.WebConfigurationManager.AppSettings["DownloadFolder"]+ @"\" + DownloadFileName; // AggregatedWorkBook.Save(HttpContext.Current.Response, DownloadFileName, ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003)); // HttpContext.Current.Response.Flush(); // HttpContext.Current.Response.End(); // } //} //catch (Exception ex) //{ // sw.WriteLine("Error Encountered During Aggregation Process."); // sw.WriteLine(ex.Message); // sw.WriteLine(ex.StackTrace); //} #endregion //IEnumerable<IDnsPersistentDocument> docs = null; var docs = from r in context.DataMartResponses from doc in r.Documents orderby r.DataMart.ID select new KeyValuePair <string, Document>(r.DataMart.Name, doc); DownloadZipToBrowser(docs); return(Dns.Document( name: filename, mimeType: GetMimeType(filename), isViewable: false, kind: DocumentKind.User, Data: Encoding.UTF8.GetBytes(sw.ToString()) )); } }
public IDnsDocument ExportResponse(IDnsResponseContext context, IDnsResponseAggregationMode aggregationMode, IDnsResponseExportFormat format, string args) { using (StringWriter sw = new StringWriter()) { DataSet ds = GetResponseDataSet(context); switch (format.ID) { case "xls": using (HtmlTextWriter htw = new HtmlTextWriter(sw)) { DataGrid dg = new DataGrid(); dg.DataSource = ds.Tables[0]; dg.DataBind(); dg.RenderControl(htw); } break; case "csv": DataTable dt = ds.Tables[0]; int iColCount = dt.Columns.Count; for (int i = 0; i < iColCount; i++) { sw.Write(dt.Columns[i]); if (i < iColCount - 1) { sw.Write(","); } } sw.Write(sw.NewLine); // Now write all the rows. foreach (DataRow dr in dt.Rows) { for (int i = 0; i < iColCount; i++) { if (!Convert.IsDBNull(dr[i])) { sw.Write(dr[i].ToString()); } if (i < iColCount - 1) { sw.Write(","); } } sw.Write(sw.NewLine); } break; } string filename = EXPORT_BASENAME + "_" + context.Request.Model.Name + "_" + context.Request.RequestID.ToString() + "." + format.ID; return(Dns.Document( name: filename, mimeType: GetMimeType(filename), isViewable: false, kind: DocumentKind.User, Data: Encoding.UTF8.GetBytes(sw.ToString()) )); } }
public IDnsDocument ExportResponse(IDnsResponseContext context, IDnsResponseAggregationMode aggregationMode, IDnsResponseExportFormat format, string args) { using (var db = new DataContext()) { string reqDoc = FixDocumentContent(System.Text.UTF8Encoding.UTF8.GetString(context.Request.Documents.Where(d => d.Name == REQUEST_ARGS_FILENAME).FirstOrDefault().GetData(db))); using (StringWriter sw = new StringWriter()) { DataSet ds = GetResponseDataSet(context, reqDoc, aggregationMode); string filename = EXPORT_BASENAME + "_" + context.Request.Model.Name + "_" + context.Request.RequestID.ToString() + "." + format.ID; switch (format.ID) { case "xlsx": ExcelHelper.ToExcel(ds, filename, HttpContext.Current.Response); break; case "csv": ExcelHelper.ToCSV(ds, sw); break; } return(Dns.Document( name: filename, mimeType: GetMimeType(filename), isViewable: false, kind: DocumentKind.User, Data: Encoding.UTF8.GetBytes(sw.ToString()) )); } } }
public IDnsDocument ExportResponse(IDnsResponseContext context, IDnsResponseAggregationMode aggregationMode, IDnsResponseExportFormat format, string args) { using (StringWriter sw = new StringWriter()) { string filename = EXPORT_BASENAME + "_" + context.Request.Model.Name + "_" + context.Request.RequestID.ToString() + "." + format.ID; var DMDocs = new SortedDictionary <string, List <Document> >(); #region "Generate a List of Documents Keyed on DataMarts for Aggregation" //IEnumerable<IDnsPersistentDocument> docs = null; var docs = from r in context.DataMartResponses from doc in r.Documents orderby r.DataMart.ID select new { Id = r.DataMart.ID, Document = doc }; foreach (var item in docs) { if (!DMDocs.ContainsKey(item.Id.ToString())) { DMDocs.Add(item.Id.ToString(), new List <Document>()); } DMDocs[item.Id.ToString()].Add(item.Document); } #endregion //Aggregate and Download Workbook AggregatedWorkBook = null; try { AggregatedWorkBook = AggregateDocuments(DMDocs); if (AggregatedWorkBook != null) { //present for download. string DownloadFileName = filename; //string DownloadPath = System.Web.Configuration.WebConfigurationManager.AppSettings["DownloadFolder"]+ @"\" + DownloadFileName; AggregatedWorkBook.Save(HttpContext.Current.Response, DownloadFileName, ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003)); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); } } catch (Exception ex) { sw.WriteLine("Error Encountered During Aggregation Process."); sw.WriteLine(ex.Message); sw.WriteLine(ex.StackTrace); } return(null); } }