/// <summary>
        ///     Handles the incoming rest requests
        /// </summary>
        /// <param name="boundVariables"> The bound variables. </param>
        /// <param name="operationInput"> The operation input. </param>
        /// <param name="outputFormat"> The output format. </param>
        /// <param name="requestProperties"> The request properties. </param>
        /// <param name="responseProperties"> The response properties. </param>
        /// <returns> </returns>
        /// <exception cref="System.ArgumentNullException"></exception>
        public static byte[] Handler(NameValueCollection boundVariables, JsonObject operationInput,
                                     string outputFormat, string requestProperties,
                                     out string responseProperties)
        {
            responseProperties = null;

            string layerName;

            object[] objectid;

            var found = operationInput.TryGetString("layerName", out layerName);

            if (!found || string.IsNullOrEmpty(layerName))
            {
                throw new ArgumentNullException("layerName");
            }

            found = operationInput.TryGetArray("objectid", out objectid);
            if (!found || objectid == null || objectid.Length < 1)
            {
                throw new ArgumentNullException("objectid");
            }

            var searchArgs = new EnvelopeArgs(layerName, objectid.Cast <int>().ToArray());

            var connector = SdeConnectorFactory.Create(layerName);

            if (connector == null)
            {
                return(Json(new
                {
                    Message = "Database does not exist for {0}".With(layerName)
                }));
            }

            var workspace = connector.Connect();

            var featureWorkSpace = workspace as IFeatureWorkspace;

            if (featureWorkSpace == null)
            {
                return(Json(new
                {
                    Message = "Error connecting to SDE."
                }));
            }

            var response = CommandExecutor.ExecuteCommand(new GetEnvelopeCommand(searchArgs, featureWorkSpace));

            if (response == null)
            {
                return(Json(new
                {
                    Message = "No features found in {0} with the Id of {1}.".With(
                        searchArgs.LayerName, string.Join(",", searchArgs.ObjectIds))
                }));
            }

            return(Json(response));
        }
 public GetEnvelopeCommand(EnvelopeArgs searchArgs, IFeatureWorkspace workspace)
 {
     SearchArgs = searchArgs;
     Workspace  = workspace;
 }