Filtering doesn't work with local listgrid - smartgwt

I've the following problem. I add some data objecct (here Language) to a list and then to a listgrid and datasource. I want that as local data.
I can sort and group without any problems, but filter is not doing anything.
Here is my code. I've no clue and there are so many options for DataSource and ListGrid, that it seems just combinatoric guessing.
List<Language> languageCodes= new ArrayList<Language>();
final ListGrid countryGrid = new ListGrid();
countryGrid.setWidth(500);
countryGrid.setHeight(300);
countryGrid.setShowFilterEditor(true);
countryGrid.setFilterOnKeypress(true);
languageCodes.add(new Language("Russian","ru", "[^a-zA-ZÀ-ÖØ-öø-ȳЀ-ӹ-]", true));
languageCodes.add(new Language("Italian", "it","[^a-zA-ZÀ-ÖØ-öø-ȳЀ-ӹ-]", false));
languageCodes.add(new Language("English", "en", "[^a-zA-ZÀ-ÖØ-öø-ȳЀ-ӹ-]", true));
languageCodes.add(new Language("German", "de", "[^a-zA-ZÀ-ÖØ-öø-ȳЀ-ӹ-]", false));
languageCodes.add(new Language("French", "fr", "[^a-zA-ZÀ-ÖØ-öø-ȳЀ-ӹ-]", true));
languageCodes.add(new Language("Greek", "el", "[^a-zA-ZÀ-ÖØ-öø-ȳЀ-ӹ-]", true));
RecordList records= new RecordList();
for(int i=0; i< languageCodes.size(); i++) {
records.add(languageToRecord(languageCodes.get(i)));
}
DataSource ds= new DataSource();
ds.setTestData(records.toArray());
ds.setClientOnly(true);
countryGrid.setDataSource(ds);
countryGrid.setData(records);
countryGrid.setDataFetchMode(FetchMode.LOCAL);
countryGrid.setAutoFetchData(true);
countryGrid.setAutoFetchTextMatchStyle(TextMatchStyle.SUBSTRING);
ListGridField codeField= new ListGridField("code","Language Code", 50);
codeField.setCanFilter(true);
codeField.setCanEdit(true);
ListGridField nameField= new ListGridField("name","Language Name", 60);
nameField.setCanFilter(true);
nameField.setCanEdit(true);
Any help very very welcome :)

Related

Serilog WriteTo.MSSqlServer Not working Console (Not Core)

I'm having issues with WriteTo.MSSqlServer not wring to the configured database. AutitTo.MSSqlServer work fine. This is in a console app, C#. Not Core.
I've looked all over and everything I've found is a dead end. Getting a little frustrated
Code:
var sinkOptions = new SinkOptions() {
TableName = "Logs",
AutoCreateSqlTable = true,
SchemaName = "dbo"
};
//Create/Configure the logger
_logger = new LoggerConfiguration()
.WriteTo.Console()
.WriteTo.File(#"C:\Users\c.clover\source\repos\ConsoleApp3\ConsoleApp3\Log.txt")
.WriteTo.MSSqlServer(
"Server=TEST01;Database=LogDb;Trusted_Connection=True;",
sinkOptions,
null,
null,
Serilog.Events.LogEventLevel.Information
)
.AuditTo.MSSqlServer(
"Server=TEST01;Database=LogDb;Trusted_Connection=True;",
sinkOptions,
null,
null,
Serilog.Events.LogEventLevel.Information
)
.CreateLogger();
//Log something
_logger.Information("Test Log {Now}", DateTime.Now);
Log.CloseAndFlush();
}
}
I fixed the problem by bagging ILogger _logger and using Log instead
Log.Logger = new LoggerConfiguration()... etc
Log.Information.... etc.
Log.CloseAndFlush();
What I dont get is why it doesnt work with ILogger?

itextsharp generates blank PDF on server but works on dev machine in MVC

I am using itextsharp to generate PDF in MVC application and this works very well on dev machine. When i deploy this on pre-production machine, this generates blank PDF page and no exception. I tried quick debugging using logging to see if I'm getting content or not after line StringReader sr = new StringReader(sb.ToString()); and i see it has content.
After some research I found one faced similar issue and he resolved this issue just by writing document.Open() after PdfWriter.GetInstance. Source: "The document is not open" error only in production with iTextSharp
After that, I thought to use code which worked for many developers How to convert HTML to PDF using iTextSharp and I still see blank PDF on pre-production but works on dev machine.
I doubt if itextsharp has some sort of dependency on operation system or office suit (with itextsharp latest updates) because as I said it works on dev machine.
Here's the code which generates blank PDF on production machine Windows Server 2012 R2.
public ActionResult DownloadOrderReceipt(string id)
{
string companyName = "Name Here";
int orderNo = 2303;
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[5]
{
new DataColumn("ProductId", typeof(string)),
new DataColumn("Product", typeof(string)),
new DataColumn("Price", typeof(int)),
new DataColumn("Quantity", typeof(int)),
new DataColumn("Total", typeof(int))
});
dt.Rows.Add(101, "Sun Glasses", 200, 5, 1000);
dt.Rows.Add(102, "Jeans", 400, 2, 800);
dt.Rows.Add(103, "Trousers", 300, 3, 900);
dt.Rows.Add(104, "Shirts", 550, 2, 1100);
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
StringBuilder sb = new StringBuilder();
// generate invoice header
sb.Append("<table width='100%' cellspacing='0' cellpadding='2'>");
sb.Append("<tr><td align='center' style='background-color: #18B5F0' colspan = '2'><b>Order Sheet</b></td></tr>");
sb.Append("<tr><td colspan = '2'></td></tr>");
sb.Append("<tr><td><b>Order No: </b>");
sb.Append(orderNo);
sb.Append("</td><td align = 'right'><b>Date: </b>");
sb.Append(DateTime.Now);
sb.Append(" </td></tr>");
sb.Append("<tr><td colspan = '2'><b>Company Name: </b>");
sb.Append(companyName);
sb.Append("</td></tr>");
sb.Append("</table>");
sb.Append("<br />");
// generate invoice items grid
sb.Append("<table border = '1'>");
sb.Append("<tr>");
foreach (DataColumn column in dt.Columns)
{
sb.Append("<th style = 'background-color: #D20B0C;color:#ffffff'>");
sb.Append(column.ColumnName);
sb.Append("</th>");
}
sb.Append("</tr>");
foreach (DataRow row in dt.Rows)
{
sb.Append("<tr>");
foreach (DataColumn column in dt.Columns)
{
sb.Append("<td>");
sb.Append(row[column]);
sb.Append("</td>");
}
sb.Append("</tr>");
}
sb.Append("<tr><td align = 'right' colspan = '");
sb.Append(dt.Columns.Count - 1);
sb.Append("'>Total</td>");
sb.Append("<td>");
sb.Append(dt.Compute("sum(Total)", ""));
sb.Append("</td>");
sb.Append("</tr></table>");
// export html string into PDF
StringReader sr = new StringReader(sb.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Invoice_" + orderNo + ".pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(pdfDoc);
Response.End();
}
}
return new EmptyResult();
}
Any help on this is highly appreciated.
Updated 1 (still same issue)
I just updated and simplified my code according to suggestions, but I still see same issue:
public ActionResult DownloadOrderReceipt(string id)
{
var order = orderRepository.Get(id);
if (order == null)
return new EmptyResult();
using (MemoryStream stream = new MemoryStream())
{
string htmlContent = "<p>Write this on PDF Page</p>";
StringReader sr = new StringReader(htmlContent);
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, stream);
pdfDoc.Open();
XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr);
pdfDoc.Close();
return File(stream.ToArray(), "application/pdf", "Invoice_121212.pdf");
}
}
This also works on dev machine but on pre-production this generates blank PDF page.
Updated 2 (still same issue)
My attempt to fix this working on pre-production is ON. Here's the another two samples which I just tried and no help.
public ActionResult DownloadOrderReceipt(string id)
{
byte[] bytes;
using (var ms = new MemoryStream())
{
using (var doc = new Document())
{
using (var writer = PdfWriter.GetInstance(doc, ms))
{
doc.Open();
var example_html = #"<p>This <em>is </em><span class=""headline"" style=""text-decoration: underline;"">some</span> <strong>sample <em> text</em></strong><span style=""color: red;"">!</span></p>";
var example_css = #".headline{font-size:200%}";
// example 1
//using (var srHtml = new StringReader(example_html))
//{
// XMLWorkerHelper.GetInstance().ParseXHtml(writer, doc, srHtml);
//}
// example 2
using (var msCss = new MemoryStream(Encoding.UTF8.GetBytes(example_css)))
{
using (var msHtml = new MemoryStream(Encoding.UTF8.GetBytes(example_html)))
{
XMLWorkerHelper.GetInstance().ParseXHtml(writer, doc, msHtml, msCss);
}
}
doc.Close();
}
}
bytes = ms.ToArray();
}
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Invoice_1212121212.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(bytes);
Response.End();
return new EmptyResult();
}
SOLUTION
Updating this question after long time, because i noticed new comments.
In the process of code review I found that developer had wrote logic to minify HTML content dynamically that caused the bites removed from PDF too and hence empty PDF.
This works for me, MemoryStream is important:
public class PDFController : Controller
{
// GET: PDF
public ActionResult Index(string address)
{
SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf();
SelectPdf.PdfDocument doc = converter.ConvertUrl(address);
var bytes = doc.Save();
MemoryStream mstream = new MemoryStream(bytes);
doc.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=kundenvereinbarung.pdf");
Response.Buffer = true;
mstream.WriteTo(Response.OutputStream);
Response.End();
return null;
}
}

How to get a list of triggered events in espertech CEP

I have implemented espertech CEP in my project and everything works great, however I would like to show a list of all triggered events. Does espertech allow to this?
By default, CEP does not provide anything as far as I know.
But you can always do it using a HashMap<String, List<EventBean>>.
A quick example would be like:
HashMap<String, ArrayList<EventBean>> eventsNeeded = new HashMap<String, List<EventBean>>();
Configuration configuration = new Configuration();
configuration.addEventType("Event", IEvent.class);
EPServiceProvider engine = EPServiceProviderManager.getDefaultProvider(configuration);
EPRuntime runtime = engine.getEPRuntime();
EPAdministrator admin = engine.getEPAdministrator();
engine.initialize();
int limit = 30;
String query = "Select instanceId, qty from Event where netValue >" + limit;
eventsNeeded.put(query, new ArrayList<EventBean>());
admin.createEPL(query).addListener((eventBeans, eventBean1) -> {
for (EventBean eventBean : eventBeans) {
eventsNeeded.get(query).add(eventBean);
}
});
sendEvent(runtime, new Event("X", 10, 1, 100, "A"));
sendEvent(runtime, new Event("X", 20, -1, 100.0, "A"));
sendEvent(runtime, new Event("X", 15, 1, 100.0, "B"));
//You can use eventsNeeded here

Avro serialization hanging on DataFileWriter close method

I am trying to use avro serialization but when I have multiple records to serialize, the application hangs on DataFileWriter close method, however it works with a small amount of records.
final PipedOutputStream pipedOutputStream = new PipedOutputStream();
PipedInputStream pipedInputStream = new PipedInputStream(
pipedOutputStream);
DatumWriter<DW> userDatumWriter = new SpecificDatumWriter<DW>(DW.class);
DataFileWriter<DW> dataFileWriter = new DataFileWriter<DW>(
userDatumWriter);
dataFileWriter.create(payload.get(0).getSchema(), pipedOutputStream);
for (DW currentRecord : payload) {
dataFileWriter.append(currentRecord);
}
dataFileWriter.close();
return pipedInputStream;
I tried to flush after adding 10 records at a time, but then it hangs on the flush method.
Can anyone help me with this?
Solved by returning a ByteArrayOutputStream as follows:
Schema schema = ReflectData.get().getSchema(DW.class);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ReflectDatumWriter<Object> reflectDatumWriter = new ReflectDatumWriter<Object>(
schema);
DataFileWriter<Object> writer = new DataFileWriter<Object>(
reflectDatumWriter).create(schema, outputStream);
for (DW currentRecord : payload) {
writer.append(currentRecord);
}
writer.close();
return outputStream.toByteArray();

Using Microsoft Chart Control in ASP.NET MVC Returns a Blank Image

Using the answer Generating the Image from a Controller from this post, I created a controller action to return a chart image as seen below (the X and Y values are just there as test data):
public FileContentResult HistoryChart()
{
Chart chart = new Chart();
string[] currencies = { "ZAR", "USD", "GBP", "JPY" };
foreach (string currency in currencies)
{
Series series = new Series(currency);
series.ChartType = SeriesChartType.FastLine;
for (int x = 0; x <= 30; x++)
series.Points.AddXY(x, (x * 5));
chart.Series.Add(series);
}
using (MemoryStream ms = new MemoryStream())
{
chart.SaveImage(ms, ChartImageFormat.Png);
ms.Seek(0, SeekOrigin.Begin);
return File(ms.ToArray(), "image/png", "mychart.png");
}
}
The problem is, the image that the controller returns is blank (although it DOES return an image)
Im hoping its something simple that I have left out! Any input would be appreciated, thanks.
Hope this helps.....
I've had the same problem:
It's all to do with colors, I added some code to yours after having used another example from this blog and deduced the issue from that - so 'Thanks' to everyone....
public FileContentResult HistoryChart()
{
Chart chart = new Chart();
**chart.BackColor = Color.Transparent;**
string[] currencies = { "ZAR", "USD", "GBP", "JPY" };
foreach (string currency in currencies)
{
Series series = new Series(currency);
series.ChartType = SeriesChartType.FastLine;
for (int x = 0; x <= 30; x++)
series.Points.AddXY(x, (x * 5));
chart.Series.Add(series);
}
**ChartArea ca1 = new ChartArea("ca1");
ca1.BackColor = Color.Cyan;
chart.ChartAreas.Add(ca1);**
using (MemoryStream ms = new MemoryStream())
{
chart.SaveImage(ms, ChartImageFormat.Png);
ms.Seek(0, SeekOrigin.Begin);
return File(ms.ToArray(), "image/png", "mychart.png");
}
}
Also, you will need to ensure that your controller has:
using System.Drawing;
using System.Web.UI.WebControls;
Cheers to all...
JK.
Hi I had the same problem and it was because I was saving the image at a different time that had created it. When rendering the internal state loses.
Test generating the chart again before save image.
Sorry for my english.

Resources