Exemplo n.º 1
0
        private void hello(RequestHandlerArgument arg)
        {
            string  executingAssemblyName = Framework.ExecutingAssembly.GetName().Name;
            JArray  services   = new JArray();
            JObject jsonResult = new JObject()
            {
                { "ROSE", "Rapid Online Service Engine" },
                { "Framework", new JObject()
                  {
                      { "AEGISFramework version", Framework.AegisVersion.ToString(3) },
                      { $"{Settings.EngineName} version", Settings.EngineVersion.ToString(3) },
                      { $"{executingAssemblyName} version", Framework.ExecutingVersion.ToString(3) }
                  } },
                { "Service Modules", services }
            };


            //  등록된 Assembly의 버전정보
            var dict = new Dictionary <string, string>();

            foreach (var item in Starter.ServiceAssemblies)
            {
                dict.Add(item.Key, item.Value.GetName().Version.ToString(3));
            }

            //  JObject 형식으로 변환
            var token = JObject.Parse(Newtonsoft.Json.JsonConvert.SerializeObject(dict));

            services.Add(token);


            arg.Response(jsonResult);
        }
Exemplo n.º 2
0
        private void delete(RequestHandlerArgument arg)
        {
            var executor = new Executer(arg.MessageBody);
            var result   = executor.Execute();

            arg.Response(result);
        }
Exemplo n.º 3
0
        private void dropCollection(RequestHandlerArgument arg)
        {
            var json       = JsonConverter.Parse(arg.MessageBody);
            var collection = Collection.GetCollection((string)json.GetProperty("collection").Value);

            collection.ParentScheme.DeleteCollection(collection.Name);
            arg.Response(null);
        }
Exemplo n.º 4
0
        private void dropScheme(RequestHandlerArgument arg)
        {
            var    json       = JsonConverter.Parse(arg.MessageBody);
            string schemeName = (string)json.GetProperty("scheme").Value;

            SchemeCatalog.DeleteScheme(schemeName);
            arg.Response(null);
        }
Exemplo n.º 5
0
        private void addIndex(RequestHandlerArgument arg)
        {
            var    json       = JsonConverter.Parse(arg.MessageBody);
            var    collection = Collection.GetCollection((string)json.GetProperty("collection").Value);
            string indexKey   = (string)json.GetProperty("indexKey").Value;

            collection.AddIndex(indexKey);
            arg.Response(null);
        }
Exemplo n.º 6
0
        private void schemeList(RequestHandlerArgument arg)
        {
            JObject json     = JObject.Parse(arg.MessageBody);
            var     response = new JArray();


            SchemeCatalog.GetSchemesInfo(ref response);
            arg.Response(response);
        }
Exemplo n.º 7
0
        private void collectionList(RequestHandlerArgument arg)
        {
            JObject json       = JObject.Parse(arg.MessageBody);
            string  schemeName = (string)json.GetProperty("scheme").Value;
            var     scheme     = SchemeCatalog.GetScheme(schemeName);
            var     response   = new JArray();


            scheme.GetCollectionsInfo(ref response);
            arg.Response(response);
        }
Exemplo n.º 8
0
        protected string ResponseString(RequestHandlerArgument arg, int resultCode, string message, JToken resultToken)
        {
            JObject result = new JObject()
            {
                { "resultCode", resultCode },
                { "message", message },
                { "processingTime", string.Format("{0:0.###}", arg.ProcessingTime.ElapsedSeconds) },
                { "result", resultToken ?? "{}" }
            };

            return(result.ToString(Newtonsoft.Json.Formatting.None));
        }
Exemplo n.º 9
0
        private void sequenceNumber(RequestHandlerArgument arg)
        {
            JToken json         = JToken.Parse(arg.MessageBody);
            var    scheme       = SchemeCatalog.GetScheme("rose");
            var    collection   = scheme.GetCollection("sequenceNumbers");
            string sequenceName = (string)json.GetProperty("name");
            long   increase     = (long)(json.GetProperty("condition/increase", false)?.Value ?? 1);
            var    result       = sequenceNumber(sequenceName, increase);


            arg.Response(result);
        }
Exemplo n.º 10
0
        private void createCollection(RequestHandlerArgument arg)
        {
            var json       = JsonConverter.Parse(arg.MessageBody);
            var collection = (string)json.GetProperty("collection").Value;

            string[] target = collection.Split('.');
            if (target.Count() != 2)
            {
                throw new AegisException(Engine.RoseResult.InvalidArgument, "Collection must be in {scheme_name}.{collection_name} format.");
            }

            bool justInCache = ((string)json.GetProperty("justInCache", false)?.Value ?? "false").ToBoolean();
            var  scheme      = SchemeCatalog.GetScheme(target[0].Trim());

            scheme.CreateCollection(target[1].Trim(), justInCache);
            arg.Response(null);
        }
Exemplo n.º 11
0
        protected override bool PreprocessRequest(HttpRequestData request)
        {
            ContentEncoding = request.ContentEncoding;

            //  Response 데이터의 크기 확인
            if (request.ContentEncoding.GetByteCount(request.MessageBody) > MaxDataSize)
            {
                var resultString = Error_TooLargeData();
                Response(request, resultString);
            }
            else
            {
                //  APIHandler에 전달할 Argument 생성
                //  APIHandler에서는 작업이 끝난 후 Response 혹은 ResponseWithResultCode를 호출해야 한다.
                RequestHandlerArgument arg = new RequestHandlerArgument();
                arg.HttpContext = request.Context;
                arg.MessageBody = request.MessageBody;
                arg.Response    = (token) =>
                {
                    var result = ResponseString(arg, RoseResult.Ok, "Ok", token);
                    Response(request, result);
                };
                arg.ResponseWithResultCode = (resultCode, message, token) =>
                {
                    var result = ResponseString(arg, resultCode, message, token);
                    Response(request, result);
                };


                //  해당 Method 호출 및 예외처리
                try
                {
                    bool handleRequest = true;
                    if (Starter.Preprocessor != null)
                    {
                        //  전처리기 호출
                        string messageBody = arg.MessageBody;
                        handleRequest = Starter.Preprocessor.BeforeRequestHandling(arg.HttpContext, ref messageBody);

                        if (handleRequest == true)
                        {
                            arg.MessageBody = messageBody;
                            _methodSelector.Invoke(arg);
                        }
                    }
                    else
                    {
                        _methodSelector.Invoke(arg);
                    }


                    if (handleRequest == true)
                    {
                        Starter.Preprocessor?.AfterRequestHandled(arg.HttpContext);
                    }
                }
                catch (System.Reflection.TargetInvocationException e) when(e.InnerException is AegisException)
                {
                    AegisException innerException = (e.InnerException as AegisException);
                    string         resultString;

                    if (innerException.ResultCodeNo == RoseResult.UnknownCommand)
                    {
                        resultString = Error_UnknownCommand(request.MessageBody);
                    }

                    else if (innerException.ResultCodeNo == RoseResult.InvalidReqest)
                    {
                        resultString = Error_InvalidRequest(request.MessageBody);
                    }

                    else
                    {
                        resultString = Error_ServerException(innerException, false);
                    }

                    Response(request, resultString);
                }
                catch (AegisException e)
                {
                    string resultString;
                    if (e.ResultCodeNo == RoseResult.UnknownCommand)
                    {
                        resultString = Error_UnknownCommand(request.MessageBody);
                    }

                    else if (e.ResultCodeNo == RoseResult.InvalidReqest)
                    {
                        resultString = Error_InvalidRequest(request.MessageBody);
                    }

                    else
                    {
                        resultString = Error_ServerException(e, false);
                    }

                    Response(request, resultString);
                }
                catch (Exception e)
                {
                    string resultString;
                    if (e.InnerException != null)
                    {
                        resultString = Error_ServerException(e.InnerException, true);
                    }
                    else
                    {
                        resultString = Error_ServerException(e, true);
                    }

                    Response(request, resultString);
                }
            }

            return(true);
        }
Exemplo n.º 12
0
 private void random(RequestHandlerArgument arg)
 {
     arg.Response(random());
 }
Exemplo n.º 13
0
 private void now(RequestHandlerArgument arg)
 {
     arg.Response(now());
 }