public static async Task <IActionResult> GetSecrets(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "secrets")] HttpRequest req,
            ILogger log)
        {
            IActionResult result;

            try
            {
                result = await Factory.Create <IGetSecretsFunction, ILogger>(log)
                         .InvokeAsync <HttpRequest, IActionResult>(req)
                         .ConfigureAwait(false);
            }
            catch (KeyVaultErrorException ex)
            {
                var statusCode = (int)ex.Response.StatusCode;
                var value      = new ErrorModel(statusCode, ex.Body?.Error?.Message);
                result = new ObjectResult(value)
                {
                    StatusCode = statusCode
                };
            }
            catch (Exception ex)
            {
                var statusCode = (int)HttpStatusCode.InternalServerError;
                var value      = new ErrorModel(statusCode, ex.Message);
                result = new ObjectResult(value)
                {
                    StatusCode = statusCode
                };
            }

            return(result);
        }
        public static async Task <HttpResponseMessage> GetDummies(
            [HttpTrigger(AuthorizationLevel.Function, "GET", Route = "dummies")] HttpRequestMessage req,
            ILogger log)
        {
            var result = await Factory.Create <IGetDummiesFunction, ILogger>(log)
                         .InvokeAsync <HttpRequestMessage, HttpResponseMessage>(req)
                         .ConfigureAwait(false);

            return(result);
        }
示例#3
0
        public static async Task <HttpResponseMessage> GetSample(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "samples")] HttpRequestMessage req,
            ILogger log)
        {
            var result = await Factory.Create <ISampleHttpFunction, ILogger>(log)
                         .InvokeAsync <HttpRequestMessage, HttpResponseMessage>(req)
                         .ConfigureAwait(false);

            return(result);
        }
        public static async Task <IActionResult> RenderSwagger(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "swagger.{extension}")] HttpRequest req,
            string extension,
            ILogger log)
        {
            IActionResult result;

            try
            {
                var options = new RenderSwaggerFunctionOptions()
                {
                    Extension = extension
                };

                result = await Factory.Create <IRenderSwaggerFunction, ILogger>(log)
                         .InvokeAsync <HttpRequest, IActionResult>(req, options)
                         .ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                var statusCode = (int)HttpStatusCode.InternalServerError;
                var value      = new ErrorModel(statusCode, ex.Message);
                result = new ObjectResult(value)
                {
                    StatusCode = statusCode
                };
            }

            return(result);
        }
        public static Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "graphql")] HttpRequest req, ILogger log)
        {
            log.LogInformation("GraphQLFunctionHttpTrigger processed a request.");

            return(Factory.Create <IGraphQLFunction>(log)
                   .InvokeAsync <HttpRequest, IActionResult>(req));
        }
        public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = "core/repositories")] HttpRequest req, TraceWriter log)
        {
            var options = GetOptions(req);

            var result = await Factory.Create <IGitHubRepositoriesFunction>(log).InvokeAsync <HttpRequest, object>(req, options).ConfigureAwait(false);

            return(new OkObjectResult(result));
        }
示例#7
0
        public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log)
        {
            var result = await Factory.Create <ISampleHttpFunction, ILogger>(log)
                         .InvokeAsync <HttpRequest, IActionResult>(req)
                         .ConfigureAwait(false);

            return(result);
        }
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = "v1/repositories")] HttpRequestMessage req, TraceWriter log)
        {
            var options = GetOptions(req);

            var result = await Factory.Create <IGitHubRepositoriesFunction>(log).InvokeAsync <HttpRequestMessage, object>(req, options).ConfigureAwait(false);

            return(req.CreateResponse(HttpStatusCode.OK, result));
        }
        public static async Task Run([TimerTrigger("0/5 * * * * *")] TimerInfo myTimer, [Queue("output")] IAsyncCollector <string> collector, ILogger log)
        {
            var options = new SampleTimerFunctionOptions()
            {
                Collector = collector
            };

            var result = await Factory.Create <ISampleTimerFunction, ILogger>(log).InvokeAsync <TimerInfo, bool>(myTimer, options).ConfigureAwait(false);

            Factory.ResultInvoked = result;
        }
示例#10
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log
            )
        {
            var options = new GetSecretFunctionOptions("Sample");


            var result = await Factory.Create <IGetOneCustomer, ILogger>(log)
                         .InvokeAsync <HttpRequest, IActionResult>(req, options)
                         .ConfigureAwait(false);

            return(new OkObjectResult(result));
        }
        public ICode Transform(ICode code, TryTransformInstructionDelegate transformInstructionDelegate,
                               Func <ICodeInMemoryLayout> codeInLayoutFactoryDelegate = null)
        {
            var newInstructionsList        = new List <IAssemblyInstructionForTransformation>();
            var newFunctionsList           = new List <IFunction>();
            var instructionListIterator    = code.AssemblyInstructions.GetEnumerator();
            var lastInstructionInLastBlock = code.Functions.Last().BasicBlocks.Last().AssemblyInstructions.Last();
            IAssemblyInstructionForTransformation previousInstruction = null;
            bool afterInstructionOfLastBlock = false;

            //move to the first instruction
            instructionListIterator.MoveNext();

            //iterate through all functions
            foreach (var function in code.Functions)
            {
                var basicBlockList = new List <IBasicBlock>();
                //iterate through all basic block
                foreach (var basicBlock in function.BasicBlocks)
                {
                    var instructionsListOfBlock = new List <IAssemblyInstructionForTransformation>();
                    foreach (var instructionInBasicBlock in basicBlock.AssemblyInstructions)
                    {
                        bool isInstructionInBasicBlock;
                        bool done = false;

                        //transform instructions from instruction list.
                        //this loop transform:
                        //1. instructions before the basic block which are left to process
                        //2. instructions inside a basic block
                        //3. instructions after the last basic block
                        while (!done)
                        {
                            isInstructionInBasicBlock = instructionListIterator.Current == instructionInBasicBlock;
                            IAssemblyInstructionForTransformation instructionToTransform =
                                instructionListIterator.Current;

                            //perfom the transformation of the instruction
                            List <IAssemblyInstructionForTransformation> transformedInstructionList;
                            var wasTransformed = transformInstructionDelegate(instructionToTransform,
                                                                              isInstructionInBasicBlock ? basicBlock : null,
                                                                              isInstructionInBasicBlock ? function : null,
                                                                              out transformedInstructionList);

                            if (wasTransformed)
                            {
                                if (transformedInstructionList.Count == 0)
                                {
                                    throw new ApplicationException("transformation should return at least one instruction");
                                }

                                if (isInstructionInBasicBlock)
                                {
                                    instructionsListOfBlock.AddRange(transformedInstructionList);
                                }
                                newInstructionsList.AddRange(transformedInstructionList);

                                if (previousInstruction != null)
                                {
                                    transformedInstructionList[0].PreviousInstruction = previousInstruction;
                                    previousInstruction.NextInstruction = transformedInstructionList[0];
                                }

                                if (transformedInstructionList.Count > 1)
                                {
                                    for (int i = 1; i < transformedInstructionList.Count; i++)
                                    {
                                        transformedInstructionList[i].PreviousInstruction = transformedInstructionList[i - 1];
                                        transformedInstructionList[i - 1].NextInstruction = transformedInstructionList[i];
                                    }
                                }

                                previousInstruction = transformedInstructionList.Last();
                            }
                            else
                            {
                                if (isInstructionInBasicBlock)
                                {
                                    instructionsListOfBlock.Add(instructionToTransform);
                                }
                                newInstructionsList.Add(instructionToTransform);
                                if (previousInstruction != null)
                                {
                                    instructionToTransform.PreviousInstruction = previousInstruction;
                                    previousInstruction.NextInstruction        = instructionToTransform;
                                }
                                previousInstruction = instructionToTransform;
                            }

                            //check weather this is the last instruction in the last basic block
                            if (isInstructionInBasicBlock && !afterInstructionOfLastBlock)
                            {
                                //The transformed instruction is now in the end of program
                                //after the last basic block instruction
                                afterInstructionOfLastBlock = (instructionToTransform == lastInstructionInLastBlock);
                            }

                            instructionListIterator.MoveNext();

                            //stop transforming intructions in loop when all instruction in scope are processed
                            done = (isInstructionInBasicBlock ||
                                    instructionListIterator.Current == null);

                            //keep transforming after the last basic block instruction to the end of the program
                            if (afterInstructionOfLastBlock && instructionListIterator.Current != null)
                            {
                                done = false;
                            }
                        }
                    }

                    IBasicBlock newBasicBlock = m_basicBlockFactory.Create(instructionsListOfBlock);
                    basicBlockList.Add(newBasicBlock);
                }

                var newFunction = m_functionFactory.Create(basicBlockList.First().AssemblyInstructions.First(),
                                                           basicBlockList.Last().AssemblyInstructions.Last(),
                                                           basicBlockList);
                newFunctionsList.Add(newFunction);
            }


            //if there is a factory to create a new code in memory layout structure than use it, otherwise use
            //the original code layout in memrory instance
            ICodeInMemoryLayout codeInMemoryLayout = codeInLayoutFactoryDelegate == null ? code.CodeInMemoryLayout:codeInLayoutFactoryDelegate();

            //return m_codeFactory.Create(newInstructionsList, newFunctionsList,codeInMemoryLayout);
            var newcode = m_codeFactory.Create(newInstructionsList, newFunctionsList, codeInMemoryLayout);

            ValidateNewCode(newcode);
            return(newcode);
        }