本文整理汇总了C#中JsonObject.TryGetAsBoolean方法的典型用法代码示例。如果您正苦于以下问题:C# JsonObject.TryGetAsBoolean方法的具体用法?C# JsonObject.TryGetAsBoolean怎么用?C# JsonObject.TryGetAsBoolean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonObject
的用法示例。
在下文中一共展示了JsonObject.TryGetAsBoolean方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExtractByPolygonHandler
private byte[] ExtractByPolygonHandler(NameValueCollection boundVariables,
JsonObject operationInput,
string outputFormat,
string requestProperties,
out string responseProperties)
{
string search_id;
bool found = operationInput.TryGetString("search_id", out search_id);
if (!found || string.IsNullOrEmpty(search_id))
{
throw new ArgumentNullException("search_id");
}
// input polygon - REQUIRED - the polygon to summarise data within
JsonObject jsonPolygon;
found = operationInput.TryGetJsonObject("polygon", out jsonPolygon);
if (!found)
{
throw new ArgumentNullException("polygon");
}
IPolygon extractionPolygon = Conversion.ToGeometry(jsonPolygon, esriGeometryType.esriGeometryPolygon) as IPolygon;
long? jsonWkid;
found = operationInput.TryGetAsLong("input_wkid", out jsonWkid);
if (!found)
{
throw new ArgumentNullException("input_wkid", "WKID numeric value for spatial reference of input point must be provided");
}
if (jsonWkid.HasValue)
{
int wkid = (int)jsonWkid.Value;
ISpatialReferenceFactory2 tInSRFac = new SpatialReferenceEnvironment() as ISpatialReferenceFactory2;
ISpatialReference tInSR = tInSRFac.CreateSpatialReference(wkid);
extractionPolygon.SpatialReference = tInSR;
}
else
{
// we won't get here
extractionPolygon.SpatialReference = new UnknownCoordinateSystemClass();
}
bool? reqReturnAsAttributes;
bool returnAsAttributes = false;
found = operationInput.TryGetAsBoolean("extractToPolygonAttributes", out reqReturnAsAttributes);
if (found && reqReturnAsAttributes.HasValue)
{
returnAsAttributes = (bool)reqReturnAsAttributes;
}
List<ExtractionLayerConfig> extractionRequests = new List<ExtractionLayerConfig>();
foreach (ExtractionLayerConfig tExtLayerInfo in m_ExtractableParams)
{
string jsonParam = tExtLayerInfo.ParamName;
bool? wasRequested;
found = operationInput.TryGetAsBoolean(jsonParam, out wasRequested);
if (found && wasRequested.HasValue && (bool)wasRequested)
{
extractionRequests.Add(tExtLayerInfo);
}
}
logger.LogMessage(ServerLogger.msgType.debug, "ExtractByPolygonHandler", 99,
"Processed inputs, attempting " + extractionRequests.Count.ToString() + " extractions");
// now need to convert the IPolygon to a geodataset, (a polygon one) for feature
// extractions.
IWorkspace inMemWksp = CreateInMemoryWorkspace() as IWorkspace;
IFeatureWorkspace inMemFeatWksp = inMemWksp as IFeatureWorkspace;
IFeatureClass tPolyAsFC = CreateFeatureClassFromGeometry(extractionPolygon, inMemFeatWksp, extractionPolygon.SpatialReference.FactoryCode);
IArea tArea = extractionPolygon as IArea;
if (AddAField(tPolyAsFC,"Total_Area",esriFieldType.esriFieldTypeDouble))
{
IFeatureCursor tFCursor = tPolyAsFC.Search(null,false);
IFeature tPolyAsFeature = tFCursor.NextFeature();
tPolyAsFeature.set_Value(tPolyAsFC.FindField("Total_Area"),tArea.Area);
tPolyAsFeature.Store();
}
IGeoDataset tPolygonGDS = tPolyAsFC as IGeoDataset;
// now do the extractions from it
ExtractionResultCollection tExtractionResults =
ProcessExtractions(search_id,tPolygonGDS, null, extractionRequests);
// Warning! Don't go assuming that the suggestively-named responseProperties can be set to anything
// helpful to describe, say, response properties. Try setting it to anything other than null
// (that I have tried) and you get "500 Unexpected Error" message and lose the best part of an
// afternoon working out why!
//responseProperties = "Extractions processed successfully";
responseProperties = null;
logger.LogMessage(ServerLogger.msgType.debug, "ExtractByPolygonHandler", 99,
"Extractions complete, returning feature");
if (returnAsAttributes)
{
IRecordSetInit returnRecSet = new RecordSetClass();
IGeoDataset tFinalGDS = tExtractionResults.ResultsAsAttributedGeodataset;
returnRecSet.SetSourceTable(tFinalGDS as ITable, null);
IRecordSet recset = returnRecSet as IRecordSet;
byte[] jsonFeature = Conversion.ToJson(recset);
return jsonFeature;
}
else
{
JsonObject tResultsAsJson = tExtractionResults.ResultsAsJson;
byte[] jsonFeatures = System.Text.Encoding.UTF8.GetBytes(tResultsAsJson.ToJson());
return jsonFeatures;
}
}
示例2: ExportCsvHandler
private byte[] ExportCsvHandler(NameValueCollection boundVariables,
JsonObject operationInput,
string outputFormat,
string requestProperties,
out string responseProperties)
{
string retval = "";
StringBuilder sb = new StringBuilder();
string s = "";
bool applyQuery = true;
bool? applyHeader = true;
//bool? applyGeoms = true;
bool addHeader = false;
//bool addGeoms = false;
responseProperties = "{\"Content-Type\" : \"text/csv\"}";
string whereClause = "";
bool found = operationInput.TryGetString("query", out whereClause);
if (!found || string.IsNullOrEmpty(whereClause))
{
//then no definition query
applyQuery = false;
}
long? layerOrdinal;
found = operationInput.TryGetAsLong("layer", out layerOrdinal); //.TryGetString("layer", out parm2Value);
if (!found)
{
throw new ArgumentNullException("layer");
}
bool useHeader = operationInput.TryGetAsBoolean("headers", out applyHeader);
if (useHeader)
{
if ((bool)applyHeader)
{
addHeader = true;
}
}
//bool useGeoms = operationInput.TryGetAsBoolean("addgeoms", out applyGeoms);
//if (useGeoms)
//{
// if ((bool)applyGeoms)
// {
// addGeoms = true;
// }
//}
ESRI.ArcGIS.Carto.IMapServer mapServer = (ESRI.ArcGIS.Carto.IMapServer)serverObjectHelper.ServerObject;
ESRI.ArcGIS.Carto.IMapServerDataAccess mapServerObjects = (ESRI.ArcGIS.Carto.IMapServerDataAccess)mapServer;
var lyr = mapServerObjects.GetDataSource(mapServer.DefaultMapName, Convert.ToInt32(layerOrdinal));
if (lyr is IFeatureClass)
{
IFeatureClass fclass = (IFeatureClass)lyr;
IQueryFilter filter = new QueryFilterClass();
filter.set_OutputSpatialReference(fclass.ShapeFieldName, getWGS84());
if (applyQuery)
{
filter.WhereClause = whereClause;
}
IFeatureCursor curs = fclass.Search(filter, false);
try
{
//();
s = curs.ToCSV(addHeader);
Marshal.ReleaseComObject(curs);
}
catch (Exception ex)
{
s = ex.GetBaseException().ToString(); //.StackTrace;
}
retval = s;
sb.Append(retval);
}
else
{
throw new Exception("Layer " + layerOrdinal.ToString() + " is not a feature layer.");
}
return Encoding.UTF8.GetBytes(sb.ToString());
}
示例3: CreateWatershedHandler
private byte[] CreateWatershedHandler(NameValueCollection boundVariables,
JsonObject operationInput,
string outputFormat,
string requestProperties,
out string responseProperties)
{
responseProperties = null;
#region Process the REST arguments
// hydroshed_id - REQUIRED - to identify the overall result
string search_id;
bool found = operationInput.TryGetString("search_id", out search_id);
if (!found || string.IsNullOrEmpty(search_id))
{
throw new ArgumentNullException("search_id");
}
// input point - REQUIRED - the search location
JsonObject jsonPoint;
found = operationInput.TryGetJsonObject("location", out jsonPoint);
if (!found)
{
throw new ArgumentNullException("location");
}
IPoint locationpoint = Conversion.ToGeometry(jsonPoint, esriGeometryType.esriGeometryPoint) as IPoint;
long? jsonWkid;
found = operationInput.TryGetAsLong("input_wkid", out jsonWkid);
if (!found)
{
throw new ArgumentNullException("input_wkid", "WKID numeric value for spatial reference of input point must be provided");
}
if (jsonWkid.HasValue)
{
int wkid = (int)jsonWkid.Value;
ISpatialReferenceFactory2 tInSRFac = new SpatialReferenceEnvironment() as ISpatialReferenceFactory2;
ISpatialReference tInSR = tInSRFac.CreateSpatialReference(wkid);
locationpoint.SpatialReference = tInSR;
}
// extent - OPTIONAL - we will use full extent if not provided but this is slow!!
// TODO maybe preferable to have the extent looked up in the SOE rather than expecting it as a parameter
JsonObject jsonExtent;
found = operationInput.TryGetJsonObject("extent", out jsonExtent);
IGeometry tAnalysisEnvelope;
if (found && jsonExtent != null)
{
logger.LogMessage(ServerLogger.msgType.debug, "process input params", 8000, "Found input extent json object ");
tAnalysisEnvelope = convertAnyJsonGeometry(jsonExtent);
logger.LogMessage(ServerLogger.msgType.debug, "process input params", 8000, "Input extent processed ok ");
try
{
logger.LogMessage(ServerLogger.msgType.debug, "process input params", 8000, "Input extent height*width are: " + tAnalysisEnvelope.Envelope.Height.ToString() + " * " + tAnalysisEnvelope.Envelope.Width.ToString());
}
catch (NullReferenceException nre)
{
logger.LogMessage(ServerLogger.msgType.debug, "Processing parameters", 8000, "Problem reading input extent, exception was " + nre.Message + " at " + nre.StackTrace);
}
}
else
{
tAnalysisEnvelope = null;
logger.LogMessage(ServerLogger.msgType.debug, "process input params", 8000, "No input extent parameter requested ");
}
List<ExtractionLayerConfig> extractionRequests = new List<ExtractionLayerConfig>();
foreach (ExtractionLayerConfig tExtLayerInfo in m_ExtractableParams)
{
string jsonParam = tExtLayerInfo.ParamName;
bool? wasRequested;
found = operationInput.TryGetAsBoolean(jsonParam, out wasRequested);
if (found && wasRequested.HasValue && (bool)wasRequested)
{
extractionRequests.Add(tExtLayerInfo);
}
}
// check whether to return as json structured object or all flattened onto attributes of the
// polygon
bool returnAsPolygonAttributes=false;
if (extractionRequests.Count > 0)
{
bool? nullableBool;
found = operationInput.TryGetAsBoolean("extractToPolygonAttributes", out nullableBool);
if (found && nullableBool.HasValue)
{
returnAsPolygonAttributes = (bool)nullableBool;
}
}
#endregion
#region Do the actual watershed extraction
// Modified the computeWatershed method to return both the raster and converted polygon versions of the
// watershed. Because the polygon version, if made by unioning separate polygons, is multipart, and
// although this is what we want to return to the user, the raster extraction operations can't handle
// that so we run them with a raster mask input instead. Returning both here saves the extraction methods
// from converting back to a raster.
IGeoDataset tWatershedPolyGDS;
IGeoDataset tWatershedRasterGDS;
if (tAnalysisEnvelope != null)
{
KeyValuePair<IGeoDataset, IGeoDataset> tPair = computeWatershed(locationpoint, tAnalysisEnvelope.Envelope);
tWatershedPolyGDS = tPair.Value;
tWatershedRasterGDS = tPair.Key;
}
//.........这里部分代码省略.........
示例4: GetWISiteSynonyms
private byte[] GetWISiteSynonyms(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties)
{
responseProperties = null;
JsonObject data;
Boolean? excludeWISiteCodes;
bool found = operationInput.TryGetJsonObject("data", out data);
if (!found || (data == null)) throw new ArgumentNullException("data");
found = operationInput.TryGetAsBoolean("excludeWISiteCodes", out excludeWISiteCodes);
if (!found || (data == null)) throw new ArgumentNullException("excludeWISiteCodes");
object[] records;
data.TryGetArray("records", out records);
JsonObject result = null;
if (records.Length > 0) result = GetWISynonyms(records, excludeWISiteCodes);
return Encoding.UTF8.GetBytes(result.ToJson());
}
开发者ID:andrewcottam,项目名称:IWC-ArcGIS-ServerObjectExtensions,代码行数:15,代码来源:InternationalWaterbirdCensusExtensions.cs