Skip to content
Lennard Fonteijn edited this page Sep 28, 2016 · 2 revisions

CopernicaNET Quickstart

Step 1

Create your own CopernicaHandler, using the following class-definition:

public class CopernicaHandler : Copernica<CopernicaHandler>, ICopernicaHandlerBase
{
    public void RegisterDataItems()
    {
    }
}

Be sure to also override the constructor if you want to pass in your Copernica Access Token by other means than the default implementation, which is using a configuration-section in your Web.config or App.config!

Step 2

Create one or more models, extending from CopernicaProfile or CopernicaSubprofile. Be sure to decorate them with attributes like CopernicaDatabase (required for profiles and subprofiles) and CopernicaCollection (required for subprofiles). You can also choose to use the Configurable-variants, or extend them and adjust the Id-retrieval to your liking.

The attribute CopernicaField is used to map your static types to Copernica Fields.

[CopernicaConfigurableDatabase]
public class Client : CopernicaProfile
{
    //Sets the Copernica field 'DatabaseId' as the identifier. Which will be used when updating.
    [CopernicaKeyField("DatabaseId", Type = CopernicaFieldTypes.IntField, Length = 50)]
    public int ID { get; set; }

    [CopernicaField("Name", Type = CopernicaFieldTypes.TextField, Length = 50)]
    public string Name { get; set; }

    [CopernicaField("Email", Type = CopernicaFieldTypes.EmailField, Length = 50)]
    public string Email { get; set; }
}

[CopernicaConfigurableDatabase]
[CopernicaConfigurableCollection]
public class Product : CopernicaSubprofile
{
    [CopernicaField("Name", Type = CopernicaFieldTypes.TextField, Length = 50)]
    public string Name { get; set; }

    [CopernicaField("Price", Type = CopernicaFieldTypes.IntField, Length = 50)]
    public int Price { get; set; }
}

Step 3

Register your models in CopernicaHandler using RegisterDataItem. This is done so CopernicaNET can run validations.

public void RegisterDataItems()
{
    RegisterDataItem(new Client());
    RegisterDataItem(new Product());
}

Step 4

To use CopernicaNET after doing all this, simply use CopernicaHandler.Instance and use the methods available to you.

var client = new Client
{
    ID = 1,
    Name = "Test",
    Email = "[email protected]"
};

CopernicaHandler.Instance.Add(client);

Appendix

Here is an example configuration-section if you wish to use that method.

<configSections>
    <section name="copernicanet" type="Arlanet.CopernicaNET.Configuration.CopernicaSettings"/>
</configSections>
<copernicanet accesstoken="replacewithaccesstoken">
    <models>
        <model name="YourAssembly.Models.Client" databaseid="1"  />
        <model name="YourAssembly.Models.Product" databaseid="1" collectionid="3" />
    </models>
</copernicanet>
Clone this wiki locally