Using the powerGate .NET library

Follow these steps to use the powerGate library in your C# project

With the installation of powerGate on your development machine, the required .NET library will be installed for all users.
It contains the relevant API’s to communicate with an ERP System via OData.

The powerGate .NET library requires your project to target at least .NET framework v4.7!

1. Reference the powerGate.Erp.Client assembly

In Visual Studio right-click on References and click “Add References”.
Search for the assembly “powerGate.Erp.Client” in Assemblies-tab and add it to your project.

../../_images/add_reference_to_vs.png

The assembly will be referenced from the GAC, therefore set “Copy Local” to “false” (when using Visual Studio 2017 this should be done automatically).

2. Create an ErpClient instance and connect to a service

In order to gain access to the powerGate API’s, the following namespace must be imported:

using powerGate.Erp.Client;

Root entry point is the class ErpClient:

var client = new ErpClient();

Call the ConnectErp() method in order to have access to the prefered Service:

var northwindService = client.ConnectErp(new Uri("http://services.odata.org/V4/Northwind/Northwind.svc/"));
3. Communicate with the service

If we have successfully connected to a Service (service.Available will return true), then we are able to make CRUD operations on the prefered EntitySet.

See the following example with a single get, which retrieves exactly one entry:

var categories =  client.Services["Northwind.svc"].EntitySets["Categories"];
var categoryKeys = new Dictionary<string,object> { {"CategoryID", 3} };
var category = categories.GetErpObject(categoryKeys);
Console.WriteLine("Successful retrieved category '{0}' with Id '{1}'.",
category["CategoryName"], (int)category["CategoryID"]);
4. Release the service when done

When you are done working with your ERP System, the ErpClient should be disposed, in order to disconnect from all the connected services and release all the resources.

client.Dispose();

We recommend using the “using” statement on the ErpClient, so Dispose() will be called in each situation, also when unexpected exceptions are thrown!

Install powerGate on customer machine

When shipping your projects binaries to your customer, also the customers machine requires a powerGate installation.
Therefore delivering the powerGate.Erp.Client assembly within your project should be avoided, in order to not lose the benefits from powerGates Update strategy.

See the complete example:

using System;
using System.Collections.Generic;
using powerGate.Erp.Client;

namespace HelloWorldServices
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var client = new ErpClient())
            {
                var northwindService = client.ConnectErp(new Uri("http://services.odata.org/V4/Northwind/Northwind.svc/"));
                var categories = client.Services["Northwind.svc"].EntitySets["Categories"];

                var categoryKeys = new Dictionary<string, object>{ {"CategoryID", 3} };
                var category = categories.GetErpObject(categoryKeys);

                Console.WriteLine("Successful retrieved category '{0}' with Id '{1}'.", category["CategoryName"], (int)category["CategoryID"]);
            }

            Console.ReadLine();
        }
    }
}