// This method validates that a key exists in the cache.
 public bool Exist(SearchRequest key)
 {
     using (cacheLock.ReadLock())
         return(cacheStore.ContainsKey(key));
 }
예제 #2
0
        private void ProcessRequest(IAsyncResult result)
        {
            HttpListener        listener = (HttpListener)result.AsyncState;
            HttpListenerContext context  = listener.EndGetContext(result);

            string method = context.Request.HttpMethod;
            string path   = context.Request.Url.LocalPath;

            switch (method)
            {
            case "POST":
                #region [ === POST === ]
                try
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    dbMsg           m         = formatter.Deserialize(context.Request.InputStream) as dbMsg;
                    if (m != null)
                    {
                        switch (m.Action)
                        {
                        case dbAction.DB_SELECT:
                            SearchRequest sr = (SearchRequest)m.Data;
                            var           rs = SearchGetIDs(sr);
                            formatter.Serialize(context.Response.OutputStream, rs);
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    //Serializer.NonGeneric.Serialize(context.Response.OutputStream, 500);
                    //context.Response.Close();
                }

                context.Response.Close();
                //context.Response.Abort();

                break;

                #endregion
            case "GET":
                #region [ === GET === ]

                switch (path)
                {
                case "/favicon.ico":
                    context.Response.Close();
                    return;

                case "/ping":
                    byte[] buffer = Encoding.UTF8.GetBytes("OK");
                    context.Response.ContentLength64 = buffer.Length;
                    Stream output = context.Response.OutputStream;
                    output.Write(buffer, 0, buffer.Length);
                    output.Close();
                    break;
                }

                break;
                #endregion
            }

            listener.BeginGetContext(ProcessRequest, listener);
        }