public HttpResponseMessage Respond(ApiController apiController, string sp, IDictionary <string, object> parameters, MediaTypeHeaderValue negotiatedMediaType, Encoding negotiatedEncoding) { HttpResponseMessage csvResponse = apiController.Request.CreateResponse(); IDictionary <string, string> queryStrings = apiController.Request.GetQueryStringDictionary(); int[] resultSetChoices = new int[] { GetQueryResultSetIndex(queryStrings, DbWebApiOptions.QueryStringContract.ResultSetParameterName) }; csvResponse.Content = new PushStreamContent((stream, httpContent, transportContext) => { StreamWriter textWriter = (negotiatedEncoding == null) ? new StreamWriter(stream) : new StreamWriter(stream, negotiatedEncoding); using (DbContext dbContext = new DbContext()) { dbContext.SetNamingConvention(queryStrings); CsvExporter csvExporter = new CsvExporter(textWriter); dbContext.ExecuteDbApi(sp, parameters, null, readHeader => { string[] headers = new string[readHeader.VisibleFieldCount]; for (int i = 0; i < headers.Length; i++) { headers[i] = dbContext.ResolvePropertyName(readHeader.GetName(i)); } csvExporter.WriteHeader(headers); }, readRow => { object[] values = new object[readRow.VisibleFieldCount]; readRow.GetColumnValues(values); csvExporter.WriteRow(values); }, null, null, resultSetChoices); textWriter.Flush(); } stream.Close(); }, negotiatedMediaType ?? _DefaultMediaType); csvResponse.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = queryStrings.GetQueryFileName(DbWebApiOptions.QueryStringContract.FileNameParameterName, FormatShortName) }; return(csvResponse); }
public HttpResponseMessage Respond(ApiController apiController, string sp, IDictionary <string, object> parameters, MediaTypeHeaderValue negotiatedMediaType, Encoding negotiatedEncoding) { HttpResponseMessage csvResponse = apiController.Request.CreateResponse(); IDictionary <string, object> queryStrings = apiController.Request.GetQueryStringDictionary(); int[] resultSetChoices = new int[] { GetQueryResultSetIndex(queryStrings, DbWebApiOptions.QueryStringContract.ResultSetParameterName) }; csvResponse.Content = new PushStreamContent((stream, httpContent, transportContext) => { StreamWriter textWriter = (negotiatedEncoding == null) ? new StreamWriter(stream) : new StreamWriter(stream, negotiatedEncoding); using (DalCenter dbContext = new DalCenter(queryStrings)) { CsvExporter csvExporter = new CsvExporter(textWriter); dbContext.ExecuteDbApi(sp, parameters, null, readHeader => { csvExporter.WriteHeader(dbContext.NameAllFields(readHeader)); }, readRow => { object[] values = new object[csvExporter.ColumnCount]; readRow.GetColumnValues(values); csvExporter.WriteRow(values); }, null, null, resultSetChoices); textWriter.Flush(); } stream.Close(); }, negotiatedMediaType ?? DefaultMediaType); csvResponse.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = queryStrings.GetQueryFileName(DbWebApiOptions.QueryStringContract.FileNameParameterName, FormatShortName) }; return(csvResponse); }
public HttpResponseMessage Respond(ApiController apiController, string sp, IDictionary<string, object> parameters, MediaTypeHeaderValue negotiatedMediaType, Encoding negotiatedEncoding) { HttpResponseMessage csvResponse = apiController.Request.CreateResponse(); IDictionary<string, string> queryStrings = apiController.Request.GetQueryStringDictionary(); int[] resultSetChoices = new int[] { GetQueryResultSetIndex(queryStrings, DbWebApiOptions.QueryStringContract.ResultSetParameterName) }; csvResponse.Content = new PushStreamContent((stream, httpContent, transportContext) => { StreamWriter textWriter = (negotiatedEncoding == null) ? new StreamWriter(stream) : new StreamWriter(stream, negotiatedEncoding); using (DalCenter dbContext = new DalCenter(queryStrings)) { CsvExporter csvExporter = new CsvExporter(textWriter); dbContext.ExecuteDbApi(sp, parameters, null, readHeader => { string[] headers = new string[readHeader.VisibleFieldCount]; for (int i = 0; i < headers.Length; i++) headers[i] = dbContext.ResolvePropertyName(readHeader.GetName(i)); csvExporter.WriteHeader(headers); }, readRow => { object[] values = new object[readRow.VisibleFieldCount]; readRow.GetColumnValues(values); csvExporter.WriteRow(values); }, null, null, resultSetChoices); textWriter.Flush(); } stream.Close(); }, negotiatedMediaType ?? _DefaultMediaType); csvResponse.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = queryStrings.GetQueryFileName(DbWebApiOptions.QueryStringContract.FileNameParameterName, FormatShortName) }; return csvResponse; }