In my project I am trying to integrate Telerik reports. I used below code to bind data to my report:
#{
var typeReportSource = new TypeReportSource() { TypeName = typeof(Invoice).AssemblyQualifiedName };
typeReportSource.Parameters.Add("OrderNumber", Model.SelectedInvoice);
}
#(
Html.TelerikReporting().ReportViewer()
.Id("reportViewer1")
.ServiceUrl("/api/reports/")
.TemplateUrl("/ReportViewer/templates/telerikReportViewerTemplate.html")
.ReportSource(typeReportSource)
.ViewMode(ViewMode.Interactive)
.ScaleMode(ScaleMode.Specific)
.Scale(1.0)
)
Now I want to bind a static list to Report that must be generated at controller due to project structure. Is it possible bind Report to static list? I found that .ReportSource() had overload which take ReportSource as parameter but it is obsolete now. I tried to use the obsolete method as:
#{
var reportSource = new Invoice();
reportSource.DataSource = myData;
}
#(
Html.TelerikReporting().ReportViewer()
.Id("reportViewer1")
.ServiceUrl("/api/reports/")
.TemplateUrl("/ReportViewer/templates/telerikReportViewerTemplate.html")
.ReportSource(reportSource)
.ViewMode(ViewMode.Interactive)
.ScaleMode(ScaleMode.Specific)
.Scale(1.0)
)
but it is shows message No Report. Currently I am passing my data as Report Parameter but I think passing large data as report parameter may be a bad practice. Is there any better way to pass static collection to Terik Html5 Report?
Related
We are trying to load test our infrastructure of logstash/elastic. Since the actual logs are generated by a software that uses hardware, we are unable to simulate it at scale.
I am wondering if we can store the logs using file sink and later write a program that reads the log files and send data through the actual sink. Since, we are trying different setup, it would be great if we can swap different sinks for testing. Say http sink and elastic sink.
I thought of reading the json file one line at a time and then invoking Write method on the Logger. However I am not sure how to get the properties array from the json. Also, it would be great to hear if there are better alternatives in Serilog world for my needs.
Example parsing
var events= File.ReadAllLines(#"C:\20210520.json")
.Select(line => JsonConvert.DeserializeObject<dynamic>(line));
foreach (var o in objects)
{
DateTime timeStamp = o.Timestamp;
LogEventLevel level = o.Level;
string messageTemplate = o.MessageTemplate;
string exception = o.Exception;
var properties = (o.Properties as JObject);
List<object> parameters = new List<object>();
foreach (var property in properties)
{
if(messageTemplate.Contains(property.Key))
parameters.Add(property.Value.ToString());
}
logInstance.Write(level, messageTemplate, parameters.ToArray());
count++;
}
Example Json Event written to the file
{"Timestamp":"2021-05-20T13:15:49.5565372+10:00","Level":"Information","MessageTemplate":"Text dialog with {Title} and {Message} displayed, user selected {Selected}","Properties":{"Title":"Unload Device from Test","Message":"Please unload the tested device from test jig","Selected":"Methods.Option","SinkRepository":null,"SourceRepository":null,"TX":"TX2937-002 ","Host":"Host1","Session":"Host1-2021.05.20 13.12.44","Seq":87321,"ThreadId":3}}
UPDATE
Though this works for simple events,
it is not able to handle Context properties (there is a work around though using ForContext),
also it forces all the properties to be of type string and
not to mention that destucturing (#property) is not handled properly
If you can change the JSON format to Serilog.Formatting.Compact's CLEF format, then you can use Serilog.Formatting.Compact.Reader for this.
In the source app:
// dotnet add package Serilog.Formatting.Compact
Log.Logger = new LoggerConfiguration()
.WriteTo.File(new CompactJsonFormatter(), "./logs/myapp.clef")
.CreateLogger();
In the load tester:
// dotnet add package Serilog.Formatting.Compact.Reader
using (var target = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.Console()
.CreateLogger())
{
using (var file = File.OpenText("./logs/myapp.clef"))
{
var reader = new LogEventReader(file);
while (reader.TryRead(out var evt))
target.Write(evt);
}
}
Be aware though that load testing results won't be accurate for many sinks if you use repeated timestamps. You should consider re-mapping the events you read in to use current timestamps.
E.g. once you've loaded up evt:
var current = new LogEvent(DateTimeOffset.Now,
evt.Level,
evt.Exception,
evt.MessageTemplate,
evt.Properties);
target.Write(current);
I want to unit test my cshtml files to ensure they compile successfully as recently I've had some issues where at run time there were failures due to the views expecting properties that weren't present. I am trying to use RazorEngine to check this, and here is my attempt at a unit test:
public void LayoutCshtml_AnyCase_ViewCompilesSuccessfully()
{
var model = new Model();
var templateName = File.ReadAllText("PathToView/_Layout.cshtml");
var result = Engine.Razor.RunCompile(templateName, "key", typeof(Model), model);
//Assertion will go here
}
I will add the assertion later but at the moment just want the view to compile. The templateName correctly picks up the right .cshtml but the result fails because of error:
The predefined type
'System.Runtime.CompilerServices.ExtensionAttribute' is defined in
multiple assemblies in the global alias;
Is anyone familiar with using RazorEngine to test please?
I created a confluence template in which I want to insert a chart(pie) showing the status of tickets related to a specific project. I want the chart macro could retrieve the number of different tickets by their type in JIRA automatically so that each time when the user create a page based on this template, they don't need to fill in the chart data manually.
I know that in JIRA Report macro one can retrieve this kind of information easily. But how can I access this data in the report result in the chart macro? Or do I have to implement another own custom macro? If so, do I have to write some Java or Javascript code, or just using the macro template language is enough?
I am a newbie to confluence. Any ideas would be helpful.
Problem solved. The Confluence Page template is written in Storage Format and rendered by in Confluence internally before returned to client. There is a way to declare variables in the template and then feed them data by adding entries in the template context in Java or Javascript.
For instance, the JIRA chart macro is inserted in the template simple-template.xml below :
<ac:structured-macro ac:name="jira" ac:schema-version="1">
<ac:parameter ac:name="server">Your Company JIRA</ac:parameter>
<ac:parameter ac:name="jqlQuery"><at:var at:name="vJql" /></ac:parameter<name />
<ac:parameter ac:name="count">true</ac:parameter>
<ac:parameter ac:name="serverId"><at:var at:name="vServerId" /></ac:parameter>
</ac:structured-macro>
Two vars vJql and vServerId are declared using syntax <at:var at:name="varName"/>. These vars are accessible in the template context provided by a class that extends class com.atlassian.confluence.plugins.createcontent.api.contextproviders.AbstractBlueprintContextProvider. To bind the context provider with the template, one need to config the template declaration in atlassian-plugin.xml by adding the element context-provider :
<content-template key="simple-template"
template-title-key="delivery.blueprint.template.title" i18n-name-key="new.template.blueprint.name">
<resource name="template" type="download" location="/templates/simple-template.xml" />
<context-provider class="com.company.atlassian.plugins.confluence.SimpleTemplateContextProvider" />
</content-template>
Within the class, feed the vars by returning a context containing entries for the vars :
private final String VAR_PROJECT_KEY = "jira-project";
private final String VAR_VERSION = "jira-fix-version";
private final String VAR_JQL = "vJql";
private final String VAR_SERVER_ID = "vServerId";
#Override
protected BlueprintContext updateBlueprintContext(BlueprintContext context) {
try {
String projectKey = (String) context.get(VAR_PROJECT_KEY);
String version = (String) context.get(VAR_VERSION);
String jql = "project = \'" + projectKey + "\' AND fixVersion = " + version;
String serverId = ResourceBundle.getBundle("simple-template-example").getString("jira.serverid");
context.put(VAR_JQL, jql);
context.put(VAR_SERVER_ID, serverId);
return context;
} catch (Exception e) {
e.printStackTrace();
return context;
}
}
Done.
I've noticed that in the metadata there's an object entityType but also an object enumType.
We use manager.metadataStore.getEntityType() to access the metadata of an Entity.
How can we do it for a given enum ? How would I create the enum on the client side out of the metadata ?
Also, when I assign an enum value to a property, I'd like to to it by name instead of by value.
For instance, assuming that Status is of type myEnum:
myEntity.Status = myEnum.Valid;
instead of
myEntity.Status = 1;
Does breeze have any helper function to access the values of an enum ?
This issue is still open as I write. But you might want to take a look at the work-around described in the answer to this SO question.
I am assuming that you are talking about data properties that are defined as .NET enums on the server, and you want additional metadata about these properties to be made available on the Breeze client.
Unfortunately, Breeze does not yet support any metadata on enum types other than the name of the .NET type backing the enum value. This is the 'enumType' property that will appear on any dataProperty that is backed by an .NET Enum on the server. (We do need to document this better)
Please add a feature request for this to the Breeze User Voice. It's a good idea and we do take these suggestions very seriously.
Well this is not exact solution to your question but definitely can help people who are generating metadata offline.
I am using NancyFx(No EF) + Breeze + AngularJS for my web project and generating breeze metadata offline(using EF methods at development) and then using it in js file.
I also encountered similar situation where I want to get all Enum values to bind dropdowns and to display EnumName corresponding to EnumValue(Id). I searched over net but there was not much as per my scenario.
So I have written raw JS methods
1. To extract all enums and their values(Id & Name) in a JS dictionary(associated array) from metadata.
var enumDictionary = {};
JSON.parse(window.app.metadata).schema.enumType.forEach(function (enumType) {
var newEnumValues = [];
enumType.member.forEach(function (enumValue) {
var newEnumValue = { id: enumValue.value, name: enumValue.name };
newEnumValues.push(newEnumValue);
});
enumDictionary[enumType.name] = newEnumValues;
});
I created a method to get all enum values for a specific enum. This will be used for binding a dropdown.
function GetEnumDictionary(enumName) {
return enumDictionary[enumName];
}
Another method I created to get specific Enum name on basis of value.
function GetEnumDictionaryValue(enumName, enumValueId) {
var result = null;
enumDictionary[enumName].some(function (enumValue) {
if (enumValue.id == enumValueId) {
result = enumValue.name;
return;
}
});
return result;
}
When testing/debugging an ASP.NET MVC application, it's common to submit a form and then check all of the name/value pairs to make sure
All of the expected keys are present
All of the expected keys have the expected values
Debugging in Visual Studio is great for checking if a single variable (or even a simple object) contains the expected value(s), and as far as a FormCollection, it's pretty easy to check the presence of the keys. However, checking the key/value pairings in a FormCollection is a huge hassle. Is there a simple way to get Visual Studio to list the keys and their values side-by-side for a quick check?
Just a quick custom check
public void Edit(FormCollection team)
{
System.Text.StringBuilder st = new System.Text.StringBuilder();
foreach (string key in team.Keys)
{
st.AppendLine(String.Format("{0} - {1}", key, team.GetValue(key).AttemptedValue));
}
string formValues = st.ToString();
//Response.Write(st.ToString());
}
You can then place your mouse on formValues to check the key-value. Clicking the magnifier would reveal the Key-Values
Take a look at Glimpse, it is on nuGet. It exposes lots of information and is invaluable with AJAX and MVC development.
At its core Glimpse allows you to debug your web site or web service right in the browser. Glimpse allows you to "Glimpse" into what's going on in your web server. In other words what Firebug is to debugging your client side code, Glimpse is to debugging your server within the client.
Here is a method that outputs the collection to the Immediate window in a readable key/value pair format, one pair per line of output:
private void DebugWriteFormCollection(FormCollection collection)
{
foreach (string key in collection.Keys)
{
string value = collection.GetValue(key).AttemptedValue;
string output = string.Format("{0}: {1}", key, value);
System.Diagnostics.Debug.WriteLine(output);
}
}
Add that to your code and set a breakpoint. When you hit the breakpoint, call the method from the Immediate window:
DebugWriteFormCollection(collection);
Result:
Key1: Value1
Key2: Value2
Key3: Value3
etc.