.NET APIs for Distributed Mode

To take advantage of distributed mode, you must include the necessary Genero Report Writer APIs in your report application.

Provide the remote connection details

In the .cs source code, include the following:
RemoteConnection remoteConnection = new RemoteConnection(report);  
remoteConnection.host = "GRE_server_name";   
remoteConnection.port = "port";
  • GRE_server_name is the name of the server where the GRE is running.
  • port is the port number where the GRE is listening.

Simple code sample

The code sample below updates the simple .NET example to include the remote connection details for a GRE on a server named "huascar", listening on port 1974.
using FourJs.Report.Runtime;
using System;
using System.Collections.Generic;
using System.Xml.Serialization;

namespace Sales
{

    //The XmlRoot annotation causes an global element declaration to be produced in the schema.
    [Serializable]
    [XmlRoot]
    public class Sales
    {
        //The XmlElement annotation maps a property to an XML element.

        //The Genero Engine does not support optional variables so setting "IsNullable = true" is mandatory.
        //If a variable needs to be optional then set the variable to null whenthere is no value.
        //If a primitive type needs to be optional then use the c# nullable type 
        //instead (e.g "int?" for "int").

        [XmlElementAttribute(IsNullable = true)]
        public String shopName;
        public int zipCode;
        public DateTime day;


        //This and any other public collection will be serialized in the order they are declared descending //recursively into the classes contained in the collections.
        [XmlElementAttribute(IsNullable = true)]
        public List<SalesItem> items;

        public Sales(String shopName, int zipCode, DateTime day)
        {
            this.items = new List<SalesItem>();
            this.shopName = shopName;
            this.zipCode = zipCode;
            this.day = day;
            int i = 0;
            items.Add(new SalesItem("Tablelamp", SalesItem.Category.Furniture, 23.00, null));
            items.Add(new SalesItem("Tablelamp", SalesItem.Category.Furniture, 267.00, items[i++]));
            items.Add(new SalesItem("Officechair", SalesItem.Category.Furniture, 155.00, items[i++]));
            items.Add(new SalesItem("Grandfather clock", SalesItem.Category.Furniture, 329.00, items[i++]));
            items.Add(new SalesItem("Scissors", SalesItem.Category.Supplies, 19.00, items[i++]));
            items.Add(new SalesItem("Measuring tape", SalesItem.Category.Supplies, 23.00, items[i++]));
            items.Add(new SalesItem("Sunglasses", SalesItem.Category.Travelling, 15.95, items[i++]));
            items.Add(new SalesItem("Penknife", SalesItem.Category.Travelling, 6.25, items[i++]));
            items.Add(new SalesItem("Ornateangel", SalesItem.Category.Art, 1.95, items[i++]));
        }

        /** Default Constructor that is required for deserialization.
            In this program this is never used.
        
         */
        public Sales()
        {

        }

        /**
            Runs the report using the design file specified in args[0] or "SalesList.4rp" otherwise.
            The program creates the file "SalesList.pdf" and opens it using
            System.Diagnostics.Process.Start which will typically
            invoke the Acrobat Reader.
        */
        static void Main(string[] args)
        {

            String designFile;
            String outputFilename = "SalesList.pdf";

            if (args.Length == 0)
            {
                designFile = "..\\SalesList.4rp";
            }
            else
            {
                designFile = args[0];
            }

            FormatHandler handler = new FormatWriter(outputFilename);
            PDFRenderer renderer = new PDFRenderer(handler);
            FourRpLayouter report = new FourRpLayouter(designFile, renderer);

            RemoteConnection remoteConnection = new RemoteConnection(report);  
            remoteConnection.host = "huascar";   
            remoteConnection.port = "1974";

            report.debugLevel = 9;
            Sales data = new Sales("Columbus Arts", 75038, new DateTime());

            remoteConnection.runFromSerializable(data);

            // open the file
            System.Diagnostics.Process.Start(outputFilename);

        }

    }

    public class SalesItem
    {
        public enum Category { Furniture, Art, Supplies, Travelling };

        [XmlElementAttribute(IsNullable = true)]
        public String articleName;
        public Category category;
        public double price;
        public double runningTotal;

        //The previous item is passed to allow computing the running total.
        public SalesItem(String articleName, Category category, double price, SalesItem previousItem)
        {
            this.articleName = articleName;
            this.category = category;
            this.price = price;

            this.runningTotal = previousItem == null ? price : previousItem.runningTotal + price;
        }

        /** Default Constructor that is required for deserialization.
            In this program this is never used.
        */
        public SalesItem() { }

    }
}