Sage / SDataCSharpClientLib

SData .NET Client Library, written in C#, based on Microsoft Argotic
Other
33 stars 23 forks source link

Sage SData Client Libraries for .NET

This repository contains the following

For information about the client library and examples on how to use it, check out "Intro to SData CSharp Client Lib.doc" in the docs subfolder.

Also, keep an eye on the Wiki for up-to-date information.

Examples

Single Resources (Entry)

Single Resources are returned to the SData Client Libraries as an AtomEntry. Simply specify the ResourceKind and Resource Selector and call the Read method of the SDataSingleResourceRequest.

var service = new SDataService("http://localhost/sdata/slx/dynamic/-/", "admin", "");
var request = new SDataSingleResourceRequest(service)
{   
    ResourceKind = "contacts",
    ResourceSelector = "'CGHEA0000001'"
};
var entry = request.Read();
var payload = entry.GetSDataPayload();

Resource Collections (Feed)

Resource collections are returned to the SData Client Libraries as an AtomFeed. Simply specify the desired ResourceKind and call the Read method on the SDataResourceCollectionRequest object.

var service = new SDataService("http://localhost/sdata/slx/dynamic/-/", "admin", "");
var request = new SDataResourceCollectionRequest(service) 
{    
    ResourceKind = "contacts" 
}; 
var feed = request.Read(); 
foreach (var entry in feed.Entries) 
{   
    var payload = entry.GetSDataPayload(); 
}

Batch Operations

var contactIds = new[] {"CGHEA0002670", "CDEMOA00003A", "CDEMOA000037"}; 
var service = new SDataService("http://localhost/sdata/slx/dynamic/-/", "admin", ""); 
using (var batch = new SDataBatchRequest(service) {ResourceKind = "contacts"}) 
{    
    var request = new SDataSingleResourceRequest(service) {ResourceKind = "contacts"};    
    foreach (var id in contactIds)    
    {        
        request.ResourceSelector = string.Format("'{0}'", id);        
        request.Read();    
    }    
    var feed = batch.Commit();    
    foreach (var entry in feed.Entries)    
    {        
        var values = entry.GetSDataPayload().Values;        
        values.Clear(); //no need to send back unchanged values        
        values["Type"] = "Decision Maker";        
        request.Entry = entry;        
        request.Update();    
    }    feed = batch.Commit();    
    foreach (var entry in feed.Entries)    
    {       
        Debug.Assert(entry.GetSDataHttpStatus() == HttpStatusCode.OK);    
    } 
}