Example #1
0
        private void fetch()
        {
            Response.Clear();
            SpotInfo sinfo = new SpotInfo();

            String key = Request["key"];

            sinfo.Address = key;
            Geocoder   geo    = new Geocoder();
            GeoResult  result = geo.GetGeoResult(sinfo);
            JsonObject jobj   = new JsonObject();

            if (GeoResultStatus.OK.Equals(result.Status))//@since 0.1.1
            {
                jobj.NameValuePair.Add(new JsonObject.nvpair()
                {
                    Name = "lat", Value = result.Results[0].Geometry.Location.Lat
                });
                jobj.NameValuePair.Add(new JsonObject.nvpair()
                {
                    Name = "lng", Value = result.Results[0].Geometry.Location.Lng
                });
            }
            AjaxResponse jresponse = new AjaxResponse();

            jresponse.Status  = "OK";
            jresponse.RawData = jobj;
            jresponse.Msg     = "lat, lng of " + key;
            Response.Write(jresponse.ToString());
            Response.ContentType = "application/json";
        }
Example #2
0
        public void ProcessRequest(HttpContext context)
        {
            this._context = context;
            String key = this._context.Request["key"];

            String encoding = this._context.Request["encoding"];

            if (String.IsNullOrEmpty(key))
            {
                return;
            }

            context.Response.ContentType = "application/json";
            AjaxResponse response = new AjaxResponse();

            response.Status = "OK";
            WikiArticle article = WikiArticleFactory.CreateWikiArticle(key, "zh");

            response.RawData = article.GetHtmlParagramOnlyTrimHref();//Wikipedia.filterContentFirstPara(article.GetHtmlParagramOnlyTrimHref());
            //response.RawData = "<br/><br/>Taipei City (traditional Chinese: 臺北市; simplified Chinese: 台北市; pinyin: Táiběi Shì; literally \"Northern Taiwan City\")[1] is the capital of the Republic of China (commonly known as \"Taiwan\") and the core city of the largest metropolitan area of Taiwan. Situated at the tip of the island, Taipei is located on the Danshui River, and is about 25 km southwest of Keelung, its port on the Pacific Ocean. Another coastal city, Danshui, is about 20 km northwest at the river\'s mouth on the Taiwan Strait. It lies in the two relatively narrow valleys of the Keelung (基隆河) and Xindian (新店溪) rivers, which join to form the Danshui River along the city\'s western border.[2] The city proper (Taipei City) is home to an estimated 2,606,151 people.[3] Taipei, New Taipei, and Keelung together form the Taipei metropolitan area with a population of 6,776,264.[4] However, they are administered under different local governing bodies. \"Taipei\" sometimes refers to the whole metropolitan area, while \"Taipei City\" refers to the city proper.";
            System.Text.Encoding encd = System.Text.Encoding.Default;
            if (encoding != null && encoding == "utf8")
            {
                encd = System.Text.Encoding.UTF8;
            }
            response.RawData = Citiport.Util.DataUtil.RemoveHtmlTagFromString(response.RawData.ToString());
            //response.RawData = HttpUtility.UrlEncode(Citiport.Util.DataUtil.RemoveHtmlTagFromString(response.RawData.ToString()), encd);
            context.Response.Write(response.ToString());
        }
        public void ProcessRequest(HttpContext context)
        {
            this._context = context;

            String key = this._context.Request["key"];

            String orderby = "interestingness-desc";

            if (String.IsNullOrEmpty(key))
            {
                return;
            }

            cache = CacheFactory.GetCache();

            currentCacheKey = key + orderby;

            object result = cache.get(currentCacheKey);

            if (result == null)
            {
                FlickrFetcher fetcher = new FlickrFetcher();
                fetched(fetcher.Fetch(key, orderby));
            }
            else
            {
                AjaxResponse response = new AjaxResponse();
                response.Status  = "OK";
                response.RawData = result;
                _context.Response.Write(response.ToString());
            }
            context.Response.ContentType = "application/json";
        }
Example #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            String key = Request["key"];

            String orderby = "interestingness-desc";

            if (String.IsNullOrEmpty(key))
            {
                return;
            }

            cache = CacheFactory.GetCache();

            currentCacheKey = key + orderby;

            object result = cache.get(currentCacheKey);

            if (result == null)
            {
                FlickrFetcher fetcher = new FlickrFetcher();
                fetched(fetcher.FetchGroup(key, ""));
            }
            else
            {
                AjaxResponse response = new AjaxResponse();
                response.Status  = "OK";
                response.RawData = result;
                Response.Write(response.ToString());
            }
            Response.ContentType = "application/json";
        }
        protected void fetched(List <FlickrPhoto> result)
        {
            List <JsonObject> _r       = result.Select(x => (JsonObject)x).ToList <JsonObject>();
            AjaxResponse      response = new AjaxResponse();

            response.Status  = "OK";
            response.RawData = _r;
            if (cache != null)
            {
                cache.put(_r, currentCacheKey);
            }
            _context.Response.Write(response.ToString());
        }
        protected void fetch()
        {
            String lat = Request["lat"];
            String lng = Request["lng"];

            IPlacesFetcher    fetcher  = PlacesFetcherFactory.getFetcher(this);
            List <PlaceObj>   result   = fetcher.fetch(double.Parse(lat), double.Parse(lng));
            List <JsonObject> _r       = result.Select(x => (JsonObject)x).ToList <JsonObject>();
            AjaxResponse      response = new AjaxResponse();

            response.Status  = "OK";
            response.RawData = _r;
            Response.Clear();
            Response.ContentType = "application/json";
            Response.Write(response.ToString());
        }
Example #7
0
        public void ProcessRequest(HttpContext context)
        {
            this._context = context;

            string key    = getKey();
            string method = getMethod();

            if (String.IsNullOrEmpty(key) || String.IsNullOrEmpty(method))
            {
                AjaxResponse response = new AjaxResponse();
                response.Status = "BAD";
                response.Msg    = "method and keyword are both required";
                _context.Response.Write(response.ToString());
                _context.Response.ContentType = "application/json";
                return;
            }

            if (method == "ftile")
            {
                string path = "Sandbox/FlickrTiled.aspx?key=" + key;
                _context.Server.Transfer(path);
            }
            else if (method == "wiki")
            {
                string encoding = _context.Request["encoding"];
                string path     = "CtpWikiProxy.ashx?key=" + key;
                if (!String.IsNullOrEmpty(encoding))
                {
                    path += "&encoding=" + encoding;
                }
                _context.Response.Redirect(path);
            }
            else if (method == "flickr")
            {
                string path = "CtpFlickrProxy.ashx?key=" + key;
                _context.Response.Redirect(path);
            }
            else if (method == "flickrfirst")
            {
                string path = "Sandbox/FlickrFirst.aspx?key=" + key;
                _context.Server.Transfer(path);
            }
            else if (method == "flickrgroup")
            {
                string path = "Sandbox/FlickrGroup.aspx?key=900369@N21";
                _context.Server.Transfer(path);
            }
            else if (method == "geocode")
            {
                string path = "Sandbox/geocoding.aspx?key=" + key;
                _context.Server.Transfer(path);
            }
            else if (method == "places")
            {
                string[] ss = new string[] {};
                if (key.Contains(','))
                {
                    ss = key.Split(',');
                }
                else
                {
                    if (key.ToLower() == "beijing" || key == "北京")
                    {
                        ss = new string[] { PlacesFakeData.BeijingLat + "", "0.0" }
                    }
                    ;
                    else
                    {
                        ss = new string[] { PlacesFakeData.TaipeiLat + "", "0.0" }
                    };
                }

                string path = "Sandbox/TestPlacesFetcher.aspx?lat=" + ss[0] + "&lng=" + ss[1];
                _context.Server.Transfer(path);
            }
            else
            {
                AjaxResponse response = new AjaxResponse();
                response.Status = "BAD";
                response.Msg    = "unknown method or keyword";
                _context.Response.Write(response.ToString());
                _context.Response.ContentType = "application/json";
            }
        }