Skip to content

Instantly share code, notes, and snippets.

@stoolrossa
Last active December 19, 2015 10:49
Show Gist options
  • Save stoolrossa/5943541 to your computer and use it in GitHub Desktop.
Save stoolrossa/5943541 to your computer and use it in GitHub Desktop.
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections.Specialized;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.SOESupport;
using Blog.SoeExample.Repository;
namespace Blog.SoeExample.Service
{
public class ExampleService : IExampleService
{
private IExampleRepository repository;
// constructor - injects repository dependency
public ExampleService(IExampleRepository repository)
{
this.repository = repository;
}
// workspace dependency - set direct on repository dependency
public IWorkspace Workspace
{
get
{
return repository.Workspace;
}
set
{
repository.Workspace = value;
}
}
// service operation
public byte[] GetLandUseSelection(NameValueCollection boundVariables,
JsonObject operationInput,
string outputFormat,
string requestProperties,
out string responseProperties)
{
// set response header
responseProperties = "{\"Content-Type\" : \"application/json\"}";
// get the landUse parameter
string landUse;
if (!operationInput.TryGetString("landUse", out landUse))
{
throw new ArgumentException("No landUse supplied in json");
}
// execute the repository method
var parcels = this.repository.SelectParcelsWithLandUse(landUse);
// package up the parcel models as a json array
var parcelsJson = new List<JsonObject>();
foreach(var parcel in parcels)
{
parcelsJson.Add(parcel.Serialise());
}
var result = new JsonObject();
result.AddArray("parcels", parcelsJson.ToArray());
return Encoding.UTF8.GetBytes(result.ToJson());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment