Question

I have a object, better, a class. It is like a win form, with the parts:

class.cs, class.Designer.cs and the last class.Resx

It is an XtraReport, so what I'm doing is to get this object and serialize it into a xml file that holds enough information about its controls. The xml generated is used on another project, that uses just the xml. The problem is that it is not enough, despite the xml having all information, it still needs the origin object to resolve the controls properly. Basically:

Saving the Xml - First Solution(C# solution):

var originalReport = new MyCompleteReportDrawInDesignerMode();
original.SaveLayoutToXml(@"c:\FileToBeSerializedAndUsedInAnotherProject");

Consuming the Xml - Another solution(C# Solution)

var genericClass = new GenericClass();
genericClass.LoadLayoutFromXml(@"C:\FileGeneratedByDeserializedXML");

Both classes are child from XtraReports:

public class MyCompleteReportDrawInDesignerMode : XtraReport

public class GenericClass : XtraReport

this doest not work, since the Another Solution does not have a clue about MyCompleteReportDrawInDesignerMode. So i thought, why not teletransport the whole object and make it happen

//Build the object
var generator = GetObjectFromText(text);
//Resolve the dependecy check
var objectGenerated = generator.ResolveAssembly();

But I have no clue how to do it or if it is viable. Any thoughts ?

Update:

I wanna store the class implementation in the database and rebuild it from another application, since the xml transformation is causing information loss.

Let me introduce a little more deeper context. We are building a reporting server application. The process is basically:

1 - Desginer the XtraReport in designer mode, set the fields databindings, set the xrsubreports reportsource if any 2 - Make a xml file from it and save in local C:\ hard driver. 3 - In another application, the user uploads this file and serialize it into varbinary. 4 - The client side receives this serialized xml and restore it, then it trys to load into a generic XtraReport class.

So I would have to create and bound this assemblys at runtime, since we cannot relase a new version of our product every new report we built.

Was it helpful?

Solution 2

the solution found was to create a class library visual studio solution, then we design the report, the subreports, and compile the all thing, and serialize the dll into a varbinary column in sql server. The dll is small, about 100 kbytes, so no problem.

After serialized into the database, the other application can consume the dll. In the same table, we put the namespace and class name from the main report, so you can create a instance at runtime, fill the datasource and print. I found that the xml serialization only works on the most recent devexpress versions, like: 13.1.10.

Here is the code:

Assembly local = 
     Assembly.LoadFile(@"C:\TempReports\5a788bc0-3e70-4f8b-8fa9-f180d23c4f03.dll");

Type t = _local.GetType("Relatórios_Teste.Reports.FluxoCaixa");

object test = Activator.CreateInstance(t);

var report = (XtraReport) test;

var controls = report.AllControls<XRSubreport>();
foreach (var control in controls)
{
    if (control.Name.Equals("sub_detail"))
    {
        control.ReportSource.DataSource = GetSource();
        control.ReportSource.DataMember = @"sp_test";
    }
}
report.ShowPreview();

OTHER TIPS

You need to make the MyCompleteReportDrawInDesignerMode class known by both solutions.

Make a separate class library assembly (separate project) that defines MyCompleteReportDrawInDesignerMode. This assembly (DLL) can then be referenced by both applications; the one that writes the report to an XML file and the one that reads this file and recreates the report.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top