Exemple #1
0
        public void PostQuery(Action <DBCommand> actionOnRead, Action <Exception> actionOnCompletion)
        {
            Exception exception = null;

            _isAsync = true;
            SpinWorker.Work(() =>
            {
                try
                {
                    Query();
                    actionOnRead?.Invoke(this);

                    _isAsync = false;
                    Dispose();
                }
                catch (Exception e)
                {
                    exception = e;
                    _isAsync  = false;
                    Dispose();
                    throw;  //  상위 Exception Handler가 처리하도록 예외를 던진다.
                }
            },
                            () => { actionOnCompletion?.Invoke(exception); });
        }
Exemple #2
0
        public void PostQuery(Action actionOnRead, Action <Exception> actionOnCompletion)
        {
            Exception exception = null;

            _isAsync = true;
            SpinWorker.Work(() =>
            {
                try
                {
                    Query();
                    if (actionOnRead != null)
                    {
                        actionOnRead();
                    }

                    _isAsync = false;
                    Dispose();
                }
                catch (Exception e)
                {
                    exception = e;
                    _isAsync  = false;
                    Dispose();
                    throw;  //  상위 Exception Handler가 처리하도록 예외를 던진다.
                }
            },
                            () => { actionOnCompletion(exception); });
        }
Exemple #3
0
 private void PostToSpinWorker(Action action)
 {
     if (DispatchWithWorkerThread == true)
     {
         SpinWorker.Work(action);
     }
     else
     {
         SpinWorker.Dispatch(action);
     }
 }
Exemple #4
0
        public void PostQueryNoReader()
        {
            _isAsync = true;
            SpinWorker.Work(() =>
            {
                try
                {
                    QueryNoReader();

                    _isAsync = false;
                    Dispose();
                }
                catch (Exception)
                {
                    _isAsync = false;
                    Dispose();
                    throw;  //  상위 Exception Handler가 처리하도록 예외를 던진다.
                }
            });
        }
Exemple #5
0
        public void PostQueryNoReader(Action <Exception> actionOnCompletion)
        {
            Exception exception = null;

            _isAsync = true;
            SpinWorker.Work(() =>
            {
                try
                {
                    QueryNoReader();

                    _isAsync = false;
                    Dispose();
                }
                catch (Exception e)
                {
                    exception = e;
                    _isAsync  = false;
                    Dispose();
                }
            },
                            () => { actionOnCompletion?.Invoke(exception); });
        }
        private void ProcessContext(HttpListenerContext context)
        {
            String path, rawUrl = context.Request.RawUrl;

            if (rawUrl == "")
            {
                return;
            }


            String[]      splitUrl = rawUrl.Split('?');
            String        rawMessage;
            WebAPIRequest request = null;


            //  Path 가져오기
            path = splitUrl[0].ToLower();
            if (path.Length == 0)
            {
                return;
            }

            if (path.Length > 1 && path[path.Length - 1] == '/')
            {
                path = path.Remove(path.Length - 1);
            }


            //  Query / Message Body 가져오기
            if (context.Request.HttpMethod == "GET")
            {
                if (splitUrl.Length > 1)
                {
                    rawMessage = splitUrl[1];
                    request    = new WebAPIRequest(WebMethodType.Get, rawUrl, path, rawMessage);
                }
                else
                {
                    request = new WebAPIRequest(WebMethodType.Get, rawUrl, path, "");
                }
            }
            if (context.Request.HttpMethod == "POST")
            {
                using (var reader = new StreamReader(context.Request.InputStream, context.Request.ContentEncoding))
                {
                    rawMessage = reader.ReadToEnd();
                    request    = new WebAPIRequest(WebMethodType.Post, rawUrl, path, rawMessage);
                }
            }


            //  Routing
            RequestHandler handler;

            if (request == null)
            {
                return;
            }


            using (_lock.ReaderLock)
            {
                if (_routes.TryGetValue(path, out handler) == false)
                {
                    return;
                }
            }


            SpinWorker.Work(() =>
            {
                handler(request, context.Response);
            });
        }