Example #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)));
        }
Example #2
0
        private byte[] getLayerCountByType(System.Collections.Specialized.NameValueCollection boundVariables,
                                           JsonObject operationInput,
                                           string outputFormat,
                                           string requestProperties,
                                           out string responseProperties)
        {
            responseProperties = null;

            String layerType = "";

            operationInput.TryGetString("type", out layerType);

            JSONObject json = new JSONObject();

            int count = 0;

            if (layerType != null && layerType.Length > 0)
            {
                String aoType = "";
                if (layerType.Equals("all"))
                {
                    count = layerInfos.Count;
                }
                else if (layerType.Equals("feature"))
                {
                    aoType = "Feature Layer";
                }
                else if (layerType.Equals("raster"))
                {
                    aoType = "Raster Layer";
                }
                else if (layerType.Equals("dataset"))
                {
                    aoType = "Network Dataset Layer";
                }

                for (int i = 0; i < layerInfos.Count; i++)
                {
                    if (layerInfos.get_Element(i).Type.Equals(aoType))
                    {
                        count++;
                    }
                }

                json.AddLong("count", count);

                return(Encoding.UTF8.GetBytes(json.ToJSONString(null)));
            }
            else
            {
                return(createErrorObject(500, "Invalid layer type provided. Available types are: \"all\", \"feature\", \"raster\", \"dataset\".",
                                         new String[1] {
                    "No details specified."
                }));
            }
        }
        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);
        }
Example #4
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)));
        }
Example #5
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)));
        }
Example #6
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 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[] 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[] 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[] 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[] 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[] QueryByExtentHandler(NameValueCollection boundVariables,
                                            JsonObject operationInput,
                                            string outputFormat,
                                            string requestProperties,
                                            out string responseProperties)
        {
            responseProperties = null;

            if (networkDataset == null)
            {
                throw new NullReferenceException("Could not access the network dataset.");
            }

            if (!operationInput.TryGetString("Extent", out var envelopeString))
            {
                throw new ArgumentNullException("Extent is invalid.");
            }
            var coords    = envelopeString.Split(';');
            var minCoords = coords[0].Split(',');
            var maxCoords = coords[1].Split(',');

            double.TryParse(minCoords[0].Trim(), out var minX);
            double.TryParse(minCoords[1].Trim(), out var minY);
            double.TryParse(maxCoords[0].Trim(), out var maxX);
            double.TryParse(maxCoords[0].Trim(), out var maxY);

            // Find features in envelope
            IEnvelope env = new EnvelopeClass();

            env.PutCoords(minX, minY, maxX, maxY);
            ISpatialFilter spatialFilter = new SpatialFilter();

            spatialFilter.Geometry   = env;
            spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

            // Add selected features OID into LongArray
            ILongArray     oIDs    = new LongArray();
            IFeatureCursor fCursor = streetFC.Search(spatialFilter, true);
            IFeature       feature = fCursor.NextFeature();

            while (feature != null)
            {
                oIDs.Add(feature.OID);
                feature = fCursor.NextFeature();
            }

            // Get the network edges corresponding to the streets and write out information about them

            INetworkQuery    networkQuery = networkDataset as INetworkQuery;
            INetworkJunction fromJunction =
                networkQuery.CreateNetworkElement(esriNetworkElementType.esriNETJunction) as INetworkJunction;
            INetworkJunction toJunction =
                networkQuery.CreateNetworkElement(esriNetworkElementType.esriNETJunction) as INetworkJunction;

            IEnumNetworkElement networkElements = networkQuery.ElementsByOIDs[streetsSourceID, oIDs];
            INetworkElement     networkElement  = networkElements.Next();
            JSONObject          result          = new JSONObject();
            JSONArray           elementArray    = new JSONArray();
            INetworkEdge        networkEdge;

            while (networkElement != null)
            {
                JSONObject jo = new JSONObject();
                networkEdge = networkElement as INetworkEdge;
                networkEdge.QueryJunctions(fromJunction, toJunction);
                double travelTime = (double)networkEdge.AttributeValue[travelTimeAttributeID];
                jo.AddLong("EdgeID", networkEdge.EID);
                jo.AddLong("FromJunctionID", fromJunction.EID);
                jo.AddLong("ToJunctionID", toJunction.EID);
                jo.AddDoubleEx(costAttributeName, travelTime, 4);
                elementArray.AddJSONObject(jo);
                networkElement = networkElements.Next();
            }
            result.AddJSONArray("NetworkElements", elementArray);

            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)
        {
            responseProperties = null;

            String layerType = "";
            operationInput.TryGetString("type", out layerType);

            JSONObject json = new JSONObject();

            int count = 0;
            if (layerType != null && layerType.Length > 0)
            {
                String aoType = "";
                if (layerType.Equals("all"))
                {
                    count = layerInfos.Count;
                }
                else if (layerType.Equals("feature"))
                {
                    aoType = "Feature Layer";
                }
                else if (layerType.Equals("raster"))
                {
                    aoType = "Raster Layer";
                }
                else if (layerType.Equals("dataset"))
                {
                    aoType = "Network Dataset Layer";
                }

                for (int i = 0; i < layerInfos.Count; i++)
                {
                    if (layerInfos.get_Element(i).Type.Equals(aoType))
                    {
                        count++;
                    }
                }

                json.AddLong("count", count);

                return Encoding.UTF8.GetBytes(json.ToJSONString(null));
            }
            else
            {
                return createErrorObject(500, "Invalid layer type provided. Available types are: \"all\", \"feature\", \"raster\", \"dataset\".",
                    new String[1] { "No details specified." });
            }
        }