Пример #1
0
        public async Task <InfoData.Response> LoadInfo(LambdaInfoArg data, ILambdaContext ctx)
        {
            var resp = new InfoData.Response()
            {
                status = InfoError.E_CHAOS.ToString()
            };

            try{
                using (var s3Client = new AmazonS3Client(Amazon.RegionEndpoint.APNortheast1))
                {
                    var s3Req = new GetObjectRequest
                    {
                        BucketName = data.s3Bucket,
                        Key        = data.s3InfoObject
                    };
                    var s3Resp = await s3Client.GetObjectAsync(s3Req);

                    using (var s3Stream = new StreamReader(s3Resp.ResponseStream)){
                        var json = s3Stream.ReadToEnd();
                        resp.apiInfo = JsonSerializer.Deserialize <InfoData.ApiInfo>(json);
                        resp.status  = InfoError.E_OK.ToString();
                    }
                }
            }
            catch (Exception ex) {
                ctx.Log(ex.Message);
                resp.status = InfoError.E_CRITICAL.ToString();
            }

            return(resp);
        }
Пример #2
0
        public override async Task Invoke()
        {
            m_infoClient = new InfoClient(currentSetting.apiUrl);
            //await Task.Run(() => {   });
            var ret = await m_infoClient.LoadInfo();

            Debug.Log("InfoClient Ret : " + ret.status.ToString());
            m_infoResp = ret;
        }
Пример #3
0
        async Task <InfoData.Response> ClientJob(LambdaInfoArg data, ILambdaContext ctx)
        {
            InfoData.Response ret = null;

            var infoClient = new InfoClient("");

            if (data.mode == "load")
            {
                ret = await infoClient.LoadInfo();
            }
            else
            {
                ret = await Task.Run(() => { return(new InfoData.Response()
                    {
                        status = InfoError.E_INVALID_ARGS.ToString()
                    }); });
            }

            return(ret);
        }
Пример #4
0
        public async Task <InfoData.Response> LoadInfo()
        {
            var resp = new InfoData.Response()
            {
                status = InfoError.E_CHAOS.ToString()
            };

            using (var client = new HttpClient()){
                try {
                    var response = await client.PostAsync
                                   (
                        m_apiUrl
                        , new StringContent
                        (
                            JsonSerializer.ToJsonString(new InfoData.Request()
                    {
                        mode = "load"
                    })
                            , new UTF8Encoding()
                            , "application/json"
                        )
                                   );

                    var responseContent = await response.Content.ReadAsStringAsync();

                    if (!String.IsNullOrEmpty(responseContent))
                    {
                        resp = JsonSerializer.Deserialize <InfoData.Response>(responseContent);
                    }
                    else
                    {
                        resp.status = InfoError.E_CRITICAL.ToString();
                    }
                }
                catch (Exception e) {
                    //Log("Exception : " + e.ToString());
                    resp.status = InfoError.E_CRITICAL.ToString();
                }
            }
            return(resp);
        }
Пример #5
0
        async Task <InfoData.Response> ServerJob(LambdaInfoArg data, ILambdaContext ctx)
        {
            InfoData.Response ret = null;

            var infoServer = new InfoServer();

            // 環境変数に依存する処理
            var env     = System.Environment.GetEnvironmentVariable("LAMBDA_ENV");
            var service = System.Environment.GetEnvironmentVariable("LAMBDA_SERVICE");

            data.s3Bucket = System.Environment.GetEnvironmentVariable("S3_BUCKET");

            if (env != null)
            {
                ctx.Log("Environment [env] : " + env);
                data.s3InfoObject = "InfoData/ApiInfo-" + env + ".json";
            }
            else
            {
                ctx.Log("Environment [env] : null");
                data.s3InfoObject = "InfoData/ApiInfo-dev.json";
            }

            if (data.mode == "load")
            {
                ret = await infoServer.LoadInfo(data, ctx);
            }
            else
            {
                ret = await Task.Run(() => { return(new InfoData.Response()
                    {
                        status = InfoError.E_INVALID_ARGS.ToString()
                    }); });
            }

            return(ret);
        }
Пример #6
0
        public override string Handler(LambdaInfoArg data, ILambdaContext context)
        {
            m_ctx  = context;
            m_data = data;

            m_data.sw.Start();

            m_ctx.Log(String.Format("{0:D8} : Start Process", m_data.sw.ElapsedMilliseconds));

            string resp;

            if (data.role == "client")
            {
                Task <InfoData.Response> result = ClientJob(data, context);
                m_ctx.Log(String.Format("{0:D8} : Wait Async Method", m_data.sw.ElapsedMilliseconds));
                resp = JsonSerializer.ToJsonString(result.Result);
            }
            else if (data.role == "server")
            {
                Task <InfoData.Response> result = ServerJob(data, context);
                m_ctx.Log(String.Format("{0:D8} : Wait Async Method", m_data.sw.ElapsedMilliseconds));
                resp = JsonSerializer.ToJsonString(result.Result);
            }
            else
            {
                var dummyResp = new InfoData.Response()
                {
                    status = InfoError.E_CHAOS.ToString()
                };
                resp = JsonSerializer.ToJsonString(dummyResp);
            }

            m_ctx.Log(String.Format("{0:D8} : Complete Process", m_data.sw.ElapsedMilliseconds));

            return(resp);
        }