Exemple #1
0
        private byte[] createErrorObject(int codeNumber, String errorMessageSummary, String[] errorMessageDetails)
        {
            if (errorMessageSummary.Length == 0 || errorMessageSummary == null)
            {
                throw new Exception("Invalid error message specified.");
            }

            JSONObject errorJSON = new JSONObject();

            errorJSON.AddLong("code", codeNumber);
            errorJSON.AddString("message", errorMessageSummary);

            if (errorMessageDetails == null)
            {
                errorJSON.AddString("details", "No error details specified.");
            }
            else
            {
                String errorMessages = "";
                for (int i = 0; i < errorMessageDetails.Length; i++)
                {
                    errorMessages = errorMessages + errorMessageDetails[i] + "\n";
                }

                errorJSON.AddString("details", errorMessages);
            }

            JSONObject error = new JSONObject();

            errorJSON.AddJSONObject("error", errorJSON);

            return(Encoding.UTF8.GetBytes(errorJSON.ToJSONString(null)));
        }
Exemple #2
0
        private byte[] RootResHandler(NameValueCollection boundVariables, string outputFormat, string requestProperties, out string responseProperties)
        {
            responseProperties = null;

            JSONObject result = new JSONObject();

            result.AddString("name", ".Net Simple REST SOE With properties");
            result.AddString("description", "Simple REST SOE with 1 sub-resource called \"layers\" and 1 property called layerType.");
            result.AddString("usage", "The \"layers\" subresource returns all layers of a certain type in the map service.\n"
                             + "The layerType property defines the type of layers are returned by the \"layers\" subresource.");

            return(Encoding.UTF8.GetBytes(result.ToJSONString(null)));
        }
Exemple #3
0
        /**
         * Returns basic Utility Network properties on the root resource
         */
        private byte[] RootResHandler(NameValueCollection boundVariables, string outputFormat, string requestProperties, out string responseProperties)
        {
            responseProperties = null;

            if (unDataset == null)
            {
                throw new RestErrorException("No Utility Network found");
            }

            JSONObject result = new JSONObject();

            try
            {
                result.AddString("description",
                                 "UN Tracing is a REST SOE with 2 operations called \"getMVTransformerAssetIds\" and  \"getCustomers\".");
                result.AddString(
                    "usage",
                    "The \"getMVTransformerAssetIds\" operation returns a list of medium voltage transformer asset IDs.\n"
                    + "These asset IDs can be then used as input in the \"getCustomers\" operation.\n"
                    + "The \"getCustomers\" operation runs a network trace starting at a specified medium voltage transformer\n"
                    + " and returns the list of service points and associated customer information.");
                result.AddString("note",
                                 "Make sure that the network topology is enabled. If it is the case, then \"hasValidNetworkTopology\" property should be 'true'.");

                result.AddString("networkName", unLayerInfo.Name);

                // Get UN properties
                IPropertySet unProps = GetUNProperties();

                object[] nameArray  = new object[1];
                object[] valueArray = new object[1];
                unProps.GetAllProperties(out nameArray[0], out valueArray[0]);
                object[]   names     = (object[])nameArray[0];
                object[]   values    = (object[])valueArray[0];
                JSONObject joUNProps = new JSONObject();

                for (int i = 0; i < unProps.Count; i++)
                {
                    joUNProps.Add((String)names[i], values[i]);
                }
                result.AddJSONObject("networkProperties", joUNProps);
            }
            catch (Exception e)
            {
                logger.LogMessage(ServerLogger.msgType.debug, soe_name + " root resource", 500, "Exception " + e.GetType().Name + " " + e.Message + " " + e.StackTrace);
                JSONObject error = soeUtil.CreateErrorJSON(500, "Unable to complete operation", e.HResult, e.Message);
                return(Encoding.UTF8.GetBytes(error.ToJSONString(null)));
            }

            return(Encoding.UTF8.GetBytes(result.ToJSONString(null)));
        }
Exemple #4
0
        private byte[] RootResHandler(System.Collections.Specialized.NameValueCollection boundVariables,
                                      string outputFormat,
                                      string requestProperties,
                                      out string responseProperties)
        {
            responseProperties = null;

            JSONObject json = new JSONObject();

            json.AddString("name", ".Net Simple REST SOE");
            json.AddString("description", "Simple REST SOE with 1 sub-resource called \"layers\" and 1 operation called \"getLayerCountByType\".");
            json.AddString("usage", "The \"layers\" subresource returns all layers in the map service.\n"
                           + "The \"getLayerCountByType\" operation returns a count of layer of specified type. It accepts one of the following values as input: \"feature\", \"raster\", "
                           + "\"dataset\", and \"all\".");
            return(Encoding.UTF8.GetBytes(json.ToJSONString(null)));
        }
        private JSONArray getLayerInfo()
        {
            JSONArray layersArray = new JSONArray();

            for (int i = 0; i < this.layerInfos.Count; i++)
            {
                IMapLayerInfo layerInfo = layerInfos.get_Element(i);
                JSONObject    jo        = new JSONObject();
                jo.AddString("name", layerInfo.Name);
                jo.AddLong("id", layerInfo.ID);
                jo.AddString("description", layerInfo.Description);
                layersArray.AddJSONObject(jo);
            }

            return(layersArray);
        }
        private byte[] SrvcPropResHandler(NameValueCollection boundVariables, string outputFormat, string requestProperties, out string responseProperties)
        {
            responseProperties = "{\"Content-Type\" : \"application/json\"}";

            IPropertySet pPropSet = SOIBase.QueryConfigurationProperties(this.soHelper.ServerObject.ConfigurationName, this.soHelper.ServerObject.TypeName);

            JSONObject jo = new JSONObject();

            jo.AddString("MaxRecordCount", pPropSet.GetProperty("MaxRecordCount").ToString());
            jo.AddString("MaxImageHeight", pPropSet.GetProperty("MaxImageHeight").ToString());
            jo.AddString("MaxImageWidth", pPropSet.GetProperty("MaxImageWidth").ToString());
            jo.AddString("PhysicalOutputDirectory", pPropSet.GetProperty("outputDir").ToString());
            jo.AddString("PhysicalCacheDirectory", pPropSet.GetProperty("cacheDir").ToString());

            JSONObject result = new JSONObject();

            result.AddJSONObject("serviceproperties", jo);
            return(Encoding.UTF8.GetBytes(result.ToJSONString(null)));
        }
Exemple #7
0
        private byte[] LayersResHandler(NameValueCollection boundVariables, string outputFormat, string requestProperties, out string responseProperties)
        {
            responseProperties = "{\"Content-Type\" : \"application/json\"}";
            String aoLayerType = "";

            if (this.layerType.Equals("feature"))
            {
                aoLayerType = "Feature Layer";
            }
            else if (this.layerType.Equals("raster"))
            {
                aoLayerType = "Raster Layer";
            }
            else if (this.layerType.Equals("dataset"))
            {
                aoLayerType = "Network Dataset Layer";
            }
            else
            {
                throw new Exception("Propety layerType has invalid value. Acceptable values are \"feature\", \"raster\", and \"dataset\".");
            }

            JSONArray layersArray = new JSONArray();

            for (int i = 0; i < this.layerInfos.Count; i++)
            {
                IMapLayerInfo layerInfo = layerInfos.get_Element(i);
                String        lType     = layerInfo.Type;
                if (lType.Equals(aoLayerType))
                {
                    JSONObject jo = new JSONObject();
                    jo.AddString("name", layerInfo.Name);
                    jo.AddLong("id", layerInfo.ID);
                    jo.AddString("description", layerInfo.Description);
                    layersArray.AddJSONObject(jo);
                }
            }

            JSONObject result = new JSONObject();

            result.AddJSONArray("Layers", layersArray);
            return(Encoding.UTF8.GetBytes(result.ToJSONString(null)));
        }
        private byte[] RootResHandler(NameValueCollection boundVariables, string outputFormat, string requestProperties, out string responseProperties)
        {
            responseProperties = null;

            JSONObject json = new JSONObject();

            json.AddString("name", ".NET Simple REST SOE With Capabilities");
            json.AddJSONArray("layerInfo", getLayerInfo());

            return(Encoding.UTF8.GetBytes(json.ToJSONString(null)));
        }
Exemple #9
0
        private byte[] LayersResHandler(NameValueCollection boundVariables, string outputFormat, string requestProperties, out string responseProperties)
        {
            responseProperties = "{\"Content-Type\" : \"application/json\"}";

            JSONArray layersArray = new JSONArray();

            for (int i = 0; i < this.layerInfos.Count; i++)
            {
                IMapLayerInfo layerInfo = layerInfos.get_Element(i);
                JSONObject    jo        = new JSONObject();
                jo.AddString("name", layerInfo.Name);
                jo.AddLong("id", layerInfo.ID);
                jo.AddString("type", layerInfo.Type);
                jo.AddString("description", layerInfo.Description);

                layersArray.AddJSONObject(jo);
            }

            JSONObject result = new JSONObject();

            result.AddJSONArray("layers", layersArray);
            return(Encoding.UTF8.GetBytes(result.ToJSONString(null)));
        }
Exemple #10
0
        /*
         * This method returns made-up anonymized customer details (mimics querying a customer service database for customer information)
         */
        private JSONObject GetCustomerInfoJSON()
        {
            JSONObject customerInfo = new JSONObject();

            customerInfo.AddString("customerID", "XXXXXXXXXX");
            customerInfo.AddString("firstName", "XXXXXXXXXX");
            customerInfo.AddString("lastName", "XXXXXXXXXX");
            customerInfo.AddString("phoneNumber", "XXX-XXX-XXXX");
            customerInfo.AddString("address", "XXXXXXXXXX");
            customerInfo.AddString("city", "XXXXXXXXXX");
            customerInfo.AddString("zipCode", "XXXXX");
            return(customerInfo);
        }
Exemple #11
0
        /**
         * Returns a list of customers serviced by the specified transformer
         */
        private byte[] GetCustomersOperHandler(NameValueCollection boundVariables,
                                               JsonObject operationInput,
                                               string outputFormat,
                                               string requestProperties,
                                               out string responseProperties)
        {
            responseProperties = null;

            if (unDataset == null)
            {
                throw new RestErrorException("No Utility Network found");
            }

            JSONObject result = new JSONObject();

            try
            {
                string xfrAssetID = "";
                operationInput.TryGetString("transformerAssetId", out xfrAssetID);
                if (string.IsNullOrEmpty(xfrAssetID))
                {
                    long?assetNumber = null;
                    operationInput.TryGetAsLong("transformerAssetId", out assetNumber);
                    if (assetNumber == null)
                    {
                        throw new ArgumentNullException("transformerAssetId");
                    }
                    else
                    {
                        xfrAssetID = assetNumber.ToString();
                    }
                }

                // Get the transformer feature global ID from the asset ID
                string       xfrWhereClause = "ASSETGROUP=" + MV_XFR_ASSETGROUP.ToString() + " AND ASSETID=" + xfrAssetID;
                IStringArray xfrOutFields   = new StrArrayClass();
                xfrOutFields.Add("GLOBALID");
                xfrOutFields.Add("ASSETTYPE");
                xfrOutFields.Add("SHAPE");
                IPropertySetArray xfrQryResults = QueryDevices(xfrWhereClause, xfrOutFields);

                if (xfrQryResults == null || xfrQryResults.Count == 0)
                {
                    throw new RestErrorException("No medium voltage transformer found for asset id: " + xfrAssetID);
                }

                string xfrGlobalID  = (string)xfrQryResults.Element[0].GetProperty("GLOBALID");
                short  xfrAssetType = (short)xfrQryResults.Element[0].GetProperty("ASSETTYPE");

                // Execute a downstream trace to find all customer low voltage service points
                IStringArray lvsGlobalIDs = FindLVServicePoints(xfrGlobalID);

                // Prepare response JSON
                JSONObject xfrInfo = new JSONObject();
                xfrInfo.AddString("ASSETID", xfrAssetID);
                xfrInfo.AddString("GLOBALID", xfrGlobalID);
                xfrInfo.AddLong("ASSETGROUP", MV_XFR_ASSETGROUP);
                xfrInfo.AddLong("ASSETTYPE", xfrAssetType);

                IJSONObject            xfrPointJson  = new JSONObject();
                IGeometry              xfrPoint      = (IGeometry)xfrQryResults.Element[0].GetProperty("SHAPE");
                IJSONConverterGeometry geoSerializer = new JSONConverterGeometryClass();
                geoSerializer.QueryJSONGeometry(xfrPoint, false, xfrPointJson);
                xfrInfo.AddJSONObject("geometry", xfrPointJson);
                result.AddJSONObject("transformer", xfrInfo);

                IJSONArray servicePoints = new JSONArrayClass();

                // Get additional service point info if any returned from trace
                if (lvsGlobalIDs != null && lvsGlobalIDs.Count > 0)
                {
                    // Query devices to get more details about service points
                    string lvsGlobalIDList = "";

                    for (int i = 0; i < lvsGlobalIDs.Count; i++)
                    {
                        lvsGlobalIDList += (i == 0) ? "" : ",";
                        lvsGlobalIDList += "'" + lvsGlobalIDs.Element[i] + "'";
                    }

                    string       lvsWhereClause = "GLOBALID IN (" + lvsGlobalIDList + ")";
                    IStringArray lvsOutFields   = new StrArrayClass();
                    lvsOutFields.Add("GLOBALID");
                    lvsOutFields.Add("ASSETTYPE");
                    lvsOutFields.Add("ASSETGROUP");
                    lvsOutFields.Add("ASSETID");
                    lvsOutFields.Add("SHAPE");
                    IPropertySetArray lvsQryResults = QueryDevices(lvsWhereClause, lvsOutFields);

                    // Get customer details
                    if (lvsQryResults != null && lvsQryResults.Count > 0)
                    {
                        for (int i = 0; i < lvsQryResults.Count; i++)
                        {
                            IPropertySet lvs          = lvsQryResults.Element[i];
                            JSONObject   servicePoint = new JSONObject();
                            servicePoint.AddString("GLOBALID", (string)lvs.GetProperty("GLOBALID"));
                            servicePoint.AddString("ASSETID", (string)lvs.GetProperty("ASSETID"));
                            servicePoint.AddLong("ASSETGROUP", (int)lvs.GetProperty("ASSETGROUP"));
                            servicePoint.AddLong("ASSETTYPE", (short)lvs.GetProperty("ASSETTYPE"));

                            IGeometry   lvsPoint     = (IGeometry)lvs.GetProperty("SHAPE");
                            IJSONObject lvsPointJson = new JSONObject();
                            geoSerializer.QueryJSONGeometry(lvsPoint, false, lvsPointJson);
                            servicePoint.AddJSONObject("geometry", lvsPointJson);

                            JSONObject customerInfo = GetCustomerInfoJSON();
                            servicePoint.AddJSONObject("customerInfo", customerInfo);
                            servicePoints.AddJSONObject(servicePoint);
                        }
                    }
                }
                result.AddJSONArray("servicePoints", servicePoints);
            }
            catch (Exception e)
            {
                logger.LogMessage(ServerLogger.msgType.debug, soe_name + " getCustomers", 500, "Exception " + e.GetType().Name + " " + e.Message + " " + e.StackTrace);
                JSONObject error = soeUtil.CreateErrorJSON(500, "Unable to complete operation", e.HResult, e.Message);
                return(Encoding.UTF8.GetBytes(error.ToJSONString(null)));
            }

            return(Encoding.UTF8.GetBytes(result.ToJSONString(null)));
        }
        private byte[] RootResHandler(System.Collections.Specialized.NameValueCollection boundVariables,
            string outputFormat,
            string requestProperties,
            out string responseProperties)
        {
            responseProperties = null; 
    
            JSONObject json = new JSONObject();
	        json.AddString("name", ".Net Simple REST SOE");
	        json.AddString("description", "Simple REST SOE with 1 sub-resource called \"layers\" and 1 operation called \"getLayerCountByType\".");
	        json.AddString("usage", "The \"layers\" subresource returns all layers in the map service.\n"
			    + "The \"getLayerCountByType\" operation returns a count of layer of specified type. It accepts one of the following values as input: \"feature\", \"raster\", "
			    + "\"dataset\", and \"all\".");
	        return Encoding.UTF8.GetBytes(json.ToJSONString(null));
        }
        private byte[] LayersResHandler(NameValueCollection boundVariables, string outputFormat, string requestProperties, out string responseProperties)
        {
            responseProperties = "{\"Content-Type\" : \"application/json\"}";

            JSONArray layersArray = new JSONArray();
            for (int i = 0; i < this.layerInfos.Count; i++)
            {
                IMapLayerInfo layerInfo = layerInfos.get_Element(i);
                JSONObject jo = new JSONObject();
                jo.AddString("name", layerInfo.Name);
                jo.AddLong("id", layerInfo.ID);
                jo.AddBoolean("addlayer", false);
                jo.AddString("description", layerInfo.Description);
              
                layersArray.AddJSONObject(jo);
            }

            JSONObject result = new JSONObject();
            result.AddJSONArray("layers", layersArray);
            return Encoding.UTF8.GetBytes(result.ToJSONString(null));
        }
        private byte[] getLayerCountByType(System.Collections.Specialized.NameValueCollection boundVariables,
            ESRI.ArcGIS.SOESupport.JsonObject operationInput,
            string outputFormat,
            string requestProperties,
            out string responseProperties) 
        {
            IMapImage mapImage = null;

            bool? shouldAdd = null;
            operationInput.TryGetAsBoolean("addlayer", out shouldAdd);

            if (shouldAdd.HasValue)
            {
                if ((bool)shouldAdd)
                {
                    if (((IMapServerInfo4)mapServerInfo).SupportsDynamicLayers)
                    {
                        IRgbColor color = new RgbColor(){ Blue = 255};

                        ISimpleLineSymbol outline = new SimpleLineSymbol(){ 
                            Color = color, 
                            Width = 1, 
                            Style = esriSimpleLineStyle.esriSLSSolid
                        };

                        ISimpleFillSymbol sfs = new SimpleFillSymbol(){ 
                            Color = color, 
                            Outline = outline, 
                            Style = esriSimpleFillStyle.esriSFSSolid
                        };
                        
                        ISimpleRenderer sr = new SimpleRenderer(){ Symbol = (ISymbol)sfs };

                        IFeatureLayerDrawingDescription featureLayerDrawingDesc = new FeatureLayerDrawingDescription(){
                            FeatureRenderer = (IFeatureRenderer)sr
                        };

                        IMapServerSourceDescription mapServerSourceDesc = new TableDataSourceDescriptionClass();
                        ((IDataSourceDescription)mapServerSourceDesc).WorkspaceID = "MyFGDB";
                        ((ITableDataSourceDescription)mapServerSourceDesc).TableName = "B";

                        IDynamicLayerDescription dynamicLayerDesc = new LayerDescriptionClass(){
                            ID = 3,
                            Visible = true,
                            DrawingDescription = (ILayerDrawingDescription)featureLayerDrawingDesc,
                            Source = mapServerSourceDesc
                        };

                        mapDesc.HonorLayerReordering = true;
                        mapDesc.LayerDescriptions.Insert(0, (ILayerDescription)dynamicLayerDesc);

                        mapImage = exportMap();
                    }    
                }
                else
                {
                    mapImage = exportMap();
                }
            }
            responseProperties = null; 
  
        	JSONObject json = new JSONObject();
            json.AddString("URL", mapImage.URL);
            return Encoding.UTF8.GetBytes(json.ToJSONString(null));
        }
        private JSONArray getLayerInfo()
        {
            JSONArray layersArray = new JSONArray();
            for (int i = 0; i < this.layerInfos.Count; i++)
            {
                IMapLayerInfo layerInfo = layerInfos.get_Element(i);
                JSONObject jo = new JSONObject();
                jo.AddString("name", layerInfo.Name);
                jo.AddLong("id", layerInfo.ID);
                jo.AddString("description", layerInfo.Description);
                layersArray.AddJSONObject(jo);
            }

            return layersArray;
        }
        private byte[] RootResHandler(NameValueCollection boundVariables, string outputFormat, string requestProperties, out string responseProperties)
        {
            responseProperties = null;

            JSONObject json = new JSONObject();
            json.AddString("name", ".NET Simple REST SOE With Capabilities");
            json.AddJSONArray("layerInfo", getLayerInfo());

            return Encoding.UTF8.GetBytes(json.ToJSONString(null));
        }
        private byte[] createErrorObject(int codeNumber, String errorMessageSummary, String[] errorMessageDetails)
        {
            if (errorMessageSummary.Length == 0 || errorMessageSummary == null)
            {
                throw new Exception("Invalid error message specified.");
            }

            JSONObject errorJSON = new JSONObject();
            errorJSON.AddLong("code", codeNumber);
            errorJSON.AddString("message", errorMessageSummary);

            if (errorMessageDetails == null)
            {
                errorJSON.AddString("details", "No error details specified.");
            }
            else
            {
                String errorMessages = "";
                for (int i = 0; i < errorMessageDetails.Length; i++)
                {
                    errorMessages = errorMessages + errorMessageDetails[i] + "\n";
                }

                errorJSON.AddString("details", errorMessages);
            }

            JSONObject error = new JSONObject();
            error.AddJSONObject("error", errorJSON);

            return Encoding.UTF8.GetBytes(error.ToJSONString(null));
        }
        private byte[] ProcessEditAreas(IServerObject serverObject, string versionName)
        {
            try
            {
                // Open utility network
                IDataset   unDataset = _soiUtil.GetUNDataset(serverObject, versionName);
                IWorkspace workspace = (IWorkspace)unDataset.Workspace;

                // Get all the dirty areas in the given validation area
                IBaseNetwork baseNetwork    = (IBaseNetwork)unDataset;
                ITable       dirtyAreaTable = baseNetwork.DirtyAreaTable;

                string shapeFieldName    = ((IFeatureClass)dirtyAreaTable).ShapeFieldName;
                int    areaFieldIndex    = dirtyAreaTable.FindField(shapeFieldName);
                int    creatorFieldIndex = dirtyAreaTable.FindField("CREATOR");

                // Get UN schema version
                IDatasetComponent dsComponent   = (IDatasetComponent)unDataset;
                IDEBaseNetwork    deBaseNetwork = (IDEBaseNetwork)dsComponent.DataElement;
                int unVersion = deBaseNetwork.SchemaGeneration;

                // Get inserts made to dirty areas table in the current version
                // For UN > V4, Errors are discarded (ERROCODE>0) to only retain true dirty areas
                // Note that changes made in the last edit session must be saved for this to work
                // as it is not possible to get the modifications until they have been saved.

                IVersionedTable versionedTable = (IVersionedTable)dirtyAreaTable;
                QueryFilter     qryFilter      = null;
                if (unVersion >= 4)
                {
                    qryFilter             = new QueryFilter();
                    qryFilter.WhereClause = _errorCodeFName + "=0";
                }

                IDifferenceCursor diffCursor = versionedTable.Differences(dirtyAreaTable, esriDifferenceType.esriDifferenceTypeInsert, qryFilter);

                // Loop through added rows to construct the modified zone extent
                int       editCount = 0;
                int       OID;
                IRow      diffRow;
                IEnvelope editZone = null;
                string    creator  = "";

                diffCursor.Next(out OID, out diffRow);

                // Return an error if no dirty areas found as it may be because the last edits were not saved
                if (diffRow == null)
                {
                    JSONObject responseJSON = new JSONObject();
                    responseJSON.AddBoolean("success", false);
                    JSONObject errorJSON = new JSONObject();
                    errorJSON.AddLong("extendedCode", (int)fdoError.FDO_E_DIRTY_AREA_BUILD_EXTENT_DO_NOT_INTERSECT);
                    errorJSON.AddString("message", "A dirty area is not present within the validate network topology input extent. A validate network topology process did not occur.");
                    JSONArray detailsJSON = new JSONArray();
                    detailsJSON.AddString("Make sure to save edits before validating.");
                    errorJSON.AddJSONArray("details", detailsJSON);
                    responseJSON.AddJSONObject("error", errorJSON);

                    return(Encoding.UTF8.GetBytes(responseJSON.ToJSONString(null)));
                }

                while (diffRow != null)
                {
                    editCount += 1;
                    creator    = diffRow.Value[creatorFieldIndex].ToString();
                    IGeometry rowShape = (IGeometry)diffRow.Value[areaFieldIndex];
                    IEnvelope rowArea  = rowShape.Envelope;
                    if (editZone != null)
                    {
                        editZone.Union(rowArea);
                    }
                    else
                    {
                        editZone = rowArea.Envelope;
                    }

                    diffCursor.Next(out OID, out diffRow);
                }
                diffCursor     = null;
                versionedTable = null;
                workspace      = null;

                // Add new or modify existing edit zone
                if (editZone != null)
                {
                    AddEditArea(serverObject, creator, versionName, editCount, editZone);
                }
            }
            catch (Exception e)
            {
                _serverLog.LogMessage(ServerLogger.msgType.infoStandard, _soiName + ".AddEditArea()",
                                      200, "Error while adding edit are: " + e.ToString());
            }

            return(null);
        }
        private byte[] getLayerCountByType(System.Collections.Specialized.NameValueCollection boundVariables,
                                           ESRI.ArcGIS.SOESupport.JsonObject operationInput,
                                           string outputFormat,
                                           string requestProperties,
                                           out string responseProperties)
        {
            IMapImage mapImage = null;

            bool?shouldAdd = null;

            operationInput.TryGetAsBoolean("addlayer", out shouldAdd);

            if (shouldAdd.HasValue)
            {
                if ((bool)shouldAdd)
                {
                    if (((IMapServerInfo4)mapServerInfo).SupportsDynamicLayers)
                    {
                        IRgbColor color = new RgbColor()
                        {
                            Blue = 255
                        };

                        ISimpleLineSymbol outline = new SimpleLineSymbol()
                        {
                            Color = color,
                            Width = 1,
                            Style = esriSimpleLineStyle.esriSLSSolid
                        };

                        ISimpleFillSymbol sfs = new SimpleFillSymbol()
                        {
                            Color   = color,
                            Outline = outline,
                            Style   = esriSimpleFillStyle.esriSFSSolid
                        };

                        ISimpleRenderer sr = new SimpleRenderer()
                        {
                            Symbol = (ISymbol)sfs
                        };

                        IFeatureLayerDrawingDescription featureLayerDrawingDesc = new FeatureLayerDrawingDescription()
                        {
                            FeatureRenderer = (IFeatureRenderer)sr
                        };

                        IMapServerSourceDescription mapServerSourceDesc = new TableDataSourceDescriptionClass();
                        ((IDataSourceDescription)mapServerSourceDesc).WorkspaceID    = "MyFGDB";
                        ((ITableDataSourceDescription)mapServerSourceDesc).TableName = "B";

                        IDynamicLayerDescription dynamicLayerDesc = new LayerDescriptionClass()
                        {
                            ID                 = 3,
                            Visible            = true,
                            DrawingDescription = (ILayerDrawingDescription)featureLayerDrawingDesc,
                            Source             = mapServerSourceDesc
                        };

                        mapDesc.HonorLayerReordering = true;
                        mapDesc.LayerDescriptions.Insert(0, (ILayerDescription)dynamicLayerDesc);

                        mapImage = exportMap();
                    }
                }
                else
                {
                    mapImage = exportMap();
                }
            }
            responseProperties = null;

            JSONObject json = new JSONObject();

            json.AddString("URL", mapImage.URL);
            return(Encoding.UTF8.GetBytes(json.ToJSONString(null)));
        }
        private byte[] RootResHandler(NameValueCollection boundVariables, string outputFormat, string requestProperties, out string responseProperties)
        {
            responseProperties = null;

            JSONObject result = new JSONObject();
            result.AddString("name", ".Net Simple REST SOE With properties");
            result.AddString("description", "Simple REST SOE with 1 sub-resource called \"layers\" and 1 property called layerType.");
            result.AddString("usage", "The \"layers\" subresource returns all layers of a certain type in the map service.\n"
                + "The layerType property defines the type of layers are returned by the \"layers\" subresource."); 

            return Encoding.UTF8.GetBytes(result.ToJSONString(null));
        }
        private byte[] LayersResHandler(NameValueCollection boundVariables, string outputFormat, string requestProperties, out string responseProperties)
        {
            responseProperties = "{\"Content-Type\" : \"application/json\"}";
            String aoLayerType = "";
            if (this.layerType.Equals("feature"))
            {
                aoLayerType = "Feature Layer";
            }
            else if (this.layerType.Equals("raster"))
            {
                aoLayerType = "Raster Layer";
            }
            else if (this.layerType.Equals("dataset"))
            {
                aoLayerType = "Network Dataset Layer";
            }
            else
            {
                throw new Exception("Propety layerType has invalid value. Acceptable values are \"feature\", \"raster\", and \"dataset\".");
            }

            JSONArray layersArray = new JSONArray();
            for (int i = 0; i < this.layerInfos.Count; i++)
            {
                IMapLayerInfo layerInfo = layerInfos.get_Element(i);
                String lType = layerInfo.Type;
                if (lType.Equals(aoLayerType))
                {
                    JSONObject jo = new JSONObject();
                    jo.AddString("name", layerInfo.Name);
                    jo.AddLong("id", layerInfo.ID);
                    jo.AddString("description", layerInfo.Description);
                    layersArray.AddJSONObject(jo);
                }
            }

            JSONObject result = new JSONObject();
            result.AddJSONArray("Layers", layersArray);
            return Encoding.UTF8.GetBytes(result.ToJSONString(null));
        }