Beispiel #1
0
        public BuilderRequest GetBuilderRequest(string json)
        {
            BuilderRequest builderRequest = new BuilderRequest();

            try
            {
                builderRequest = JsonConvert.DeserializeObject <BuilderRequest>(json);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error : Unable to intersept request json " + ex.Message + ex.StackTrace);
            }

            return(builderRequest);
        }
        private object Specializev2()
        {
            Console.WriteLine("Call Reached at  /v2/specialize");

            try
            {
                var errors   = new List <string>();
                var oinfo    = new List <string>();
                var _request = Request;
                var _body    = Request.Body;
                // Request.Body.Position = 0; use it only if requst has already been read before that
                var _requestBodystring = RequestStream.FromStream(Request.Body).AsString();
                Console.WriteLine($"Request received by endpoint from builder : {_requestBodystring}");
                BuilderRequest builderRequest = EnvironmentHelper.Instance.GetBuilderRequest(_requestBodystring);
                if (builderRequest == null)
                {
                    Console.WriteLine("Error : Unbale to parse builder request!!");
                    throw new Exception("Error : Unbale to parse builder request!!");
                }

                string functionPath = string.Empty;
                // functionPath = Path.Combine(builderRequest.filepath, $"{builderRequest.functionName}.cs");

                PackagePath = builderRequest.filepath;
                //following will enable us to skip --entrypoint flag during function creation
                if (!string.IsNullOrWhiteSpace(builderRequest.functionName))
                {
                    functionPath = Path.Combine(builderRequest.filepath, $"{builderRequest.functionName}.cs");
                }
                else
                {
                    functionPath = Path.Combine(builderRequest.filepath, EnvironmentHelper.Instance.environmentSettings.functionBodyFileName);
                }

                Console.WriteLine($"Going to read function body from path : {functionPath}");

                if (File.Exists(functionPath))
                {
                    var code = File.ReadAllText(functionPath);
                    try
                    {
                        FissionCompiler fissionCompiler = new FissionCompiler(builderRequest.filepath);
                        _userFunc = fissionCompiler.Compilev2(code, out errors, out oinfo);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Error getting _userFunc :{ex.Message} , Trace : {ex.StackTrace}");
                    }
                    if (_userFunc == null)
                    {
                        var errstr = string.Join(Environment.NewLine, errors);
                        _logger.WriteError(errstr);
                        Console.WriteLine($"Error  _userFunc is null :{errstr}");
                        var response = (Response)errstr;
                        response.StatusCode = HttpStatusCode.InternalServerError;
                        return(response);
                    }
                    else
                    {
                        //try to retrun few details
                        var infostr = string.Join(Environment.NewLine, oinfo);
                        _logger.WriteInfo(infostr);
                        var response = (Response)infostr;
                        response.StatusCode = HttpStatusCode.OK;
                        return(response);
                    }
                }
                else
                {
                    var errstr = $"Unable to locate code at '{functionPath}'";
                    _logger.WriteError(errstr);
                    var response = (Response)errstr;
                    response.StatusCode = HttpStatusCode.InternalServerError;
                    return(response);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Exception occured {ex.Message} | {ex.StackTrace}");
                var errstr = $"Exception occured {ex.Message} | {ex.StackTrace}";
                _logger.WriteError(errstr);
                var response = (Response)errstr;
                response.StatusCode = HttpStatusCode.InternalServerError;
                return(response);
            }
        }