Why is this code added to MetadataTypesHandler.ProcessRequest - ormlite-servicestack

Why is this code added to MetadataTypesHandler.ProcessRequest() in ORMLite for ServiceStack?
httpRes.ContentType = "application/x-ssz-metatypes";
var encJson = CryptUtils.Encrypt(EndpointHostConfig.PublicKey, json, RsaKeyLengths.Bit2048);
httpRes.Write(encJson);
Looks like it's signing the page but the content type is non-standard.

That code lives in ServiceStack project itself, it doesn't have nothing to do with OrmLite. That code is essentially the beginning part of this future feature to provide enough metadata suitable for being able to code-gen DTOs locally as a substitute for sharing dlls. Because it involves code-gen from a remote source it's encrypted to give us better security/control on how and what gets code-gen'ed.

Related

view nlog's output as a web page with asp.net

In an ASP.NET application, is there a way to get the nlog output to go in a buffer in memory?
I'd like to make a circular buffer that would display the log's content on a web page.
What about writing to the memory target?
Then you could read them as follow:
var target = LogManager.Configuration.FindTargetByName<MemoryTarget>("target1");
var logs = target.Logs;
You can specify custom targets with NLog: https://github.com/nlog/NLog/wiki/Targets
It does not look like one exists that does exactly what you need, but you can write your own!
https://github.com/NLog/NLog/wiki/Extending-NLog
Why don't you read tail n-lines from the actual log file and display it? Or send to a database and display the table? Seems that this will added more overhead and memory constants to the ASP.Net site.

Get AST from .Net assembly without source code (IL code)

I'd like to analyze .Net assemblies to be language independent from C#, VB.NET or whatever.
I know Roslyn and NRefactory but they only seem to work on C# source code level?
There is also the "Common Compiler Infrastructure: Code Model and AST API" project on CodePlex which claims to "supports a hierarchical object model that represents code blocks in a language-independent structured form" which sound exactly for what I looking for.
However I'am unable to find any useful documentation or code that is actual doing this.
Any advice how to archive this?
Can Mono.Cecil maybe doing something?
You can do this and there is also one (although tiny) example of this in the source of ILSpy.
var assembly = AssemblyDefinition.ReadAssembly("path/to/assembly.dll");
var astBuilder = new AstBuilder(new DecompilerContext(assembly.MainModule));
decompiler.AddAssembly(assembly);
astBuilder.SyntaxTree...
The CCI Code Model is somewhere between a IL disassembler and full C# decompiler: it gives your code some structure (e.g. if statements and expressions), but it also contains some low level stack operations like push and pop.
CCI contains a sample that shows this: PeToText.
For example, to get Code Model for the first method of the Program type (in the global namespace), you could use code like this:
string fileName = "whatever.exe";
using (var host = new PeReader.DefaultHost())
{
var module = (IModule)host.LoadUnitFrom(fileName);
var type = (ITypeDefinition)module.UnitNamespaceRoot.Members
.Single(m => m.Name.Value == "Program");
var method = (IMethodDefinition)type.Members.First();
var methodBody = new SourceMethodBody(method.Body, host, null, null);
}
To demonstrate, if you decompile the above code and show it using PeToText, you're going to get:
Microsoft.Cci.ITypeDefinition local_3;
Microsoft.Cci.ILToCodeModel.SourceMethodBody local_5;
string local_0 = "C:\\code\\tmp\\nuget tmp 2015\\bin\\Debug\\nuget tmp 2015.exe";
Microsoft.Cci.PeReader.DefaultHost local_1 = new Microsoft.Cci.PeReader.DefaultHost();
try
{
push (Microsoft.Cci.IModule)local_1.LoadUnitFrom(local_0).UnitNamespaceRoot.Members;
push Program.<>c.<>9__0_0;
if (dup == default(System.Func<Microsoft.Cci.INamespaceMember, bool>))
{
pop;
push Program.<>c.<>9.<Main0>b__0_0;
Program.<>c.<>9__0_0 = dup;
}
local_3 = (Microsoft.Cci.ITypeDefinition)System.Linq.Enumerable.Single<Microsoft.Cci.INamespaceMember>(pop, pop);
local_5 = new Microsoft.Cci.ILToCodeModel.SourceMethodBody((Microsoft.Cci.IMethodDefinition)System.Linq.Enumerable.First<Microsoft.Cci.ITypeDefinitionMember>(local_3.Members).Body, local_1, (Microsoft.Cci.ISourceLocationProvider)null, (Microsoft.Cci.ILocalScopeProvider)null, 0);
}
finally
{
if (local_1 != default(Microsoft.Cci.PeReader.DefaultHost))
{
local_1.Dispose();
}
}
Of note are all those push, pop and dup statements and the lambda caching condition.
As far as I know, it's not possible to build AST from binary (without sources) since AST itself generated by parser as part of compilation process from sources.
Mono.Cecil won't help because you can only modify opcodes/metadata with them, not analyze assembly.
But since it's .NET you can dump IL code from dll with help of ildasm. Then you can pass generated sources to any parser with CIL dictionary hooked up and get AST from parser. The problem is that as far as I know there is only one publically available CIL grammar for parser, so you don't really have a choice. And ECMA-355 is big enough so it's bad idea to write your own grammar.
So I can suggest you only one solution:
Pass assembly to ildasm.exe to get CIL.
Then pass CIL to ANTLR v3 parser with this CIL grammar wired up (note it's a little bit outdated - grammar created at 2004 and latest CIL specification is 2006, but CIL doesn't really change to much)
After that you can freely access AST generated by ANTLR
Note that you will need ANTLR v3 not v4, since grammar written for 3rd version, and it's hardly possible to port it to v4 without good knowledge of ANTLR syntax.
Also you can try to look into new Microsoft ryujit compiler sources at github (part of CoreCLR) - I don't sure that it's helps, but in theory it must contains CIL grammar and parser implementations since it works with CIL code. But it's written in CPP, have enormous code base and lacks of documentation since it's in active development stage, so it's may be easier to stuck with ANTLR.
If you treat the .net binary file as a stream of bytes, you ought to be able to "parse" it just fine.
You simply write a grammar whose tokens are essentially bytes. You can certainly build a classical lexer/parser with almost any set of lexer/parser tools by defining the lexer to read single bytes as tokens.
You can then build the AST using standard AST-building machinery for the parsing engine (on your own for YACC, automatically with ANTLR4).
What you will discover, of course, is that "parsing" isn't enough; you'll still need to build symbol tables, and carry out control and data flow analyses if you are going to do serious analysis of the corresponding code. See my essay on LifeAfterParsing.
You will also likely have to take into account "distinguished" functions that provide key runtime facilities to the particular programming languages that actually generated the CIL code. And these will make your analyzers language-dependent. Yes, you still get to share the part of the analysis that works on generic CIL.

How to use ReportingCloud in asp.net web site?

Recently I have started to work with SSRS and found ReportingCloud. It says
ReportingCloud provides an open source quality implementation
as an extension of the RDL specification
I haven't found any tutorial/documentation on how to use it in sourceforge or via google search.
Can anyone give an walk-through/example on How to use ReportingCloud?
There is one partial example available at http://sourceforge.net/projects/reportingcloud/forums/forum/1116661/topic/4571059.
The example takes an existing RDL file, parses and executes it and then places the HTML output into an asp.net Literal Control for display in the browser.
That code snippet is repeated here:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("C:\MyFolder\MyReport.rdl");
RDLParser rdlp = new RDLParser(xmlDoc.OuterXml);
rdlp.Parse();
MemoryStreamGen ms = new MemoryStreamGen();
ProcessReport pr = new ProcessReport(rdlp.Report, ms);
pr.Run(null, OutputPresentationType.ASPHTML);
// Dump memory stream (HTML Text) to an out-of-box ASPX Literal control
this.LiteralReportHtml.Text = ms.GetText();
To do this you'll need a reference to ReportingCloud.Engine.
I'm not sure exactly what your bigger goals are but I'd like to draw your attention to another open source project on GitHub called My-FyiReporting https://github.com/majorsilence/My-FyiReporting
Just like ReportingCloud, My-FyiReporting is a fork of FyiReporting (which has gone dormant).
The big difference as far as you are concerned is that My-FyiReporting has ASP.NET samples and an ASP.NET user control link. This might be the fast way to get to what you need.
File ORIGINALPROJECT.TXT from ReportingCloud says:
The ReportingCloud is a fork from the original project fyiReporting
4.1 (http://www.fyireporting.com).
File readme.md from My-FyiReporting says:
My-FyiReporting is a fork of fyiReporting. I cannot stress this
enough. This is a FORK. The main purpose is to make sure that I have a
copy of fyiReporting since that project seems to be dead.

push external multimedia file in to package at tridion publish time

When we publish some page/dynamic component from tridion is it possible to add some external multimedia file/content(ex:jpg image) in to current executing/rendering package at publish time.So that final transportation package has this binary file present along with original published content?
Is this achivable using customization of tridion renderer/resolver?If yes please provide some inputs.
*Note:*The binary content that needs to be pushed in to package at publish time is not present as multimedia component in tridion, it is located at other file location outside tridion CMS.Instead we have some stub multimedia component being used inside published component/page which has some dummy image. we plan to replace the stub image with original image at publish(rendering/resolving) time.
Since we have huge bulk of binary content stored in DAM tool we dont want that data to be recreated as multimedia component in tridion, insted we want to use that data by querying DAM tool and attach it in to tridion package with some logical referencesplanning to maintain one to one mapping between stub multimedia comp tcmid to original content in some mapping DB for reference).
Please let us know if any solution is there to attach external binary content to package at publish time.
The best - and easiest way - is to use the mechanism provided by Tridion out-of-the-box for this. Create a new multimedia component, select "External" in the resource type drop-down, and type the URL to the object. As long as you can address it with a URL, it will work exactly as you want (item will be added to package and sent to delivery server).
If this is not good enough for you, then yes, you can add it to the package yourself. I've done this in the past with code somewhat like this:
FileInfo file = // Weird logic to get a FileInfo object from external system
Item item = package.GetItem("My original Item");
item.SetAsStream(file.OpenRead());
This replaced the content of my original component with the actual file I wanted. This will work for you IF the original component is also a multimedia component. If it's not, just create a new item with your own name, etc. If possible, do use the out-of-the-box process instead.
PS: FileInfo Class.
As Nuno suggested the best way is to use multimedia component with 'External' resource type. You may not need to create these manually, you can automate using core services or API programs.
Another way I used before to create zip file at run time and add same to package with following code. Hope it may help.
using (MemoryStream ms = new MemoryStream())
{
zip.Save(ms);
downloadAllInOneURL = String.Format("ZipAsset{0}.zip", uniqueZipID);
downloadAllInOneURL = m_Engine.PublishingContext.RenderedItem.AddBinary(ms, downloadAllInOneURL, "", "application/zip").Url;
downloadAllInOneSize = getSize(ms.Length);
}

Flash/Flex Error #1063 When Retrieving SharedObject

I have a parts application that is built on Flex 3 and I having a problem with the parts list. The parts list uses two objects:
Part
ArrayOfPart
I cache the parts list locally in a SharedObject. This has been working fine for a couple months. I added a new Boolean property to the Part class and re-imported web services (which shouldn't have affected anything) and now, I can save the ArrayOfPart SharedObject fine, but when I try to retrieve the SharedObject, I get "ArgumentError: Error #1063: Argument count mismatch on ArrayOfPart. Expected 1, got 0. AND then it DELETES my SOL file completely.
(I used RegisterClass on Part and ArrayOfPart, so they both are serializable to SharedObjects)
Here's the steps I followed to get the error:
Save the shared object:
so = SharedObject.getLocal("PartsList");
so.data.AllParts = AllParts;
so.flush();
Verify the SharedObject:
The SharedObject PartsList.sol exists where it should
I opened the SharedObject file and the ArrayOfPart data looks valid
Restart the application and it retrieves the parts list from the SharedObject. This is the line that throws the Error #1063 and causes the sol file to be deleted:
so = SharedObject.getLocal("PartsList");
It looks like the data may not be well-formed when it's saved in the SharedObject? Is this possible?
I solved my own problem.
The ArrayOfPart had a constructor with a parameter. When I removed the constructor, the error went away.
By the way, this was Flash 9.
This looks like a tough one.
I don't think it is a formation or serialization issue. Maybe something else in your code is writing to the shared object?
Is there any way you can share your source? This would help as I personally don't have enough info to diagnose what is going on w/o seeing the rest of the code :(
Also....
Is there anything else that is writing to or changing this shared object?
Are all my objects created in AS3 or are some in MXML (I have noticed that the Flex compiler does not always do a good job figuring out MXML).
What version of Flash do I have?
If its Flash 10 does the same problem occur in Flash 9?
Does this happen in all browsers and on all platforms?
Just a hunch, but, since I installed Flash Player 10, I am seeing lots of errors with Shared Objects when browsing. Could it be related to newly introduced sandbox/security restrictions?

Resources