Last active
December 19, 2015 10:49
-
-
Save stoolrossa/5943541 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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