Esempio n. 1
0
        private byte[] SampleOperationHandler(NameValueCollection boundVariables,
                                              JsonObject operationInput,
                                              string outputFormat,
                                              string requestProperties,
                                              out string responseProperties)
        {
            var result = new OperationResult();

            responseProperties = null;

            JsonObject jsonObj;
            bool       found = operationInput.TryGetJsonObject(typeof(GpsData).Name, out jsonObj);

            if (!found)
            {
                throw new ArgumentNullException(typeof(GpsData).Name);
            }
            var gpsData = JsonableObject.FromJson <GpsData>(jsonObj.ToJson());

            IMapLayerInfo layer = _serverObjectHelper.ServerObject.FindLayer(gpsData.LayerName);

            if (layer == null)
            {
                result.Success = false;
                return(Encoding.UTF8.GetBytes(result.ToJson()));
            }

            try
            {
                // TODO : add some ArcObjects code here to do whatever needed
                result.ExtraData = string.Format("Layer '{0}' has feature class '{1}'", layer.Name,
                                                 _serverObjectHelper.ServerObject.GetFeatureClassFromLayer(layer).AliasName);
                result.Success = true;
            }
            catch (COMException comExc)
            {
                // Handle any errors that might occur.
                _logger.LogMessage(ServerLogger.msgType.error, "SampleOperationHandler", 666, comExc.Message);
                result.Success = false;
            }
            finally
            {
                // TODO : release any COM handles here, flush buffers etc.
            }

            return(Encoding.UTF8.GetBytes(result.ToJson()));
        }
Esempio n. 2
0
        public T SubmitRequest <T>(Dictionary <string, string> parameters) where T : JsonableObject, new()
        {
            if (string.IsNullOrEmpty(_url))
            {
                throw new NullReferenceException("You must specify a url.");
            }

            if (parameters == null)
            {
                parameters = new Dictionary <string, string>();
            }
            parameters.Add("f", "json");

            string queryString = GetUrlEncodedQueryString(parameters);

            var httpWebRequest = (HttpWebRequest)WebRequest.Create(ProxyEncodeUrlAsString());

            httpWebRequest.Method        = "POST";
            httpWebRequest.ContentType   = "application/x-www-form-urlencoded";
            httpWebRequest.ContentLength = (long)(queryString.Length + 2);
            bool tmpExpect100Continue = httpWebRequest.ServicePoint.Expect100Continue;

            httpWebRequest.ServicePoint.Expect100Continue = false;
            httpWebRequest.AutomaticDecompression         = DecompressionMethods.GZip;

            var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream());

            streamWriter.WriteLine(queryString);
            streamWriter.Flush();
            var httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;

            httpWebRequest.ServicePoint.Expect100Continue = tmpExpect100Continue;
            if (httpWebResponse != null && httpWebResponse.StatusCode == HttpStatusCode.OK)
            {
                string streamReader = new StreamReader(httpWebResponse.GetResponseStream()).ReadToEnd();
                return(JsonableObject.FromJson <T>(streamReader));
            }

            throw new ApplicationException(httpWebResponse.StatusDescription);
        }