/// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            ListFunctionsResponse response = new ListFunctionsResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("Functions", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <FunctionConfiguration, FunctionConfigurationUnmarshaller>(FunctionConfigurationUnmarshaller.Instance);
                    response.Functions = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("NextMarker", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.NextMarker = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonLambdaConfig config = new AmazonLambdaConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonLambdaClient client = new AmazonLambdaClient(creds, config);

            ListFunctionsResponse resp = new ListFunctionsResponse();

            do
            {
                ListFunctionsRequest req = new ListFunctionsRequest
                {
                    Marker = resp.NextMarker
                    ,
                    MaxItems = maxItems
                };

                resp = client.ListFunctions(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.Functions)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextMarker));
        }
        /// <summary>
        /// 查询函数列表
        /// </summary>
        public static void ListFunctions(FunctionGraphClient client)
        {
            ListFunctionsRequest req = new ListFunctionsRequest
            {
                Marker   = "0",
                Maxitems = "3"
            };

            try
            {
                ListFunctionsResponse resp = client.ListFunctions(req);
                Console.WriteLine("List Function Body=" + JsonConvert.SerializeObject(resp));
                foreach (var func in resp.Functions)
                {
                    Console.WriteLine("name=" + func.FuncName);
                    Console.WriteLine("func_urn=" + func.FuncUrn);
                }
                Console.WriteLine("List Function statusCode=" + resp.HttpStatusCode);
            }
            catch (ClientRequestException e)
            {
                Console.WriteLine(e.HttpStatusCode);
                Console.WriteLine(e.ErrorCode);
                Console.WriteLine(e.ErrorMsg);
            }
            catch (ConnectionException e)
            {
                Console.WriteLine(e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Exemplo n.º 4
0
        private async Task InvalidateFunctions(uint functionIndexStart, uint functionIndexEnd)
        {
            var fbb = Debugger.BeginRequest();
            int requestDataOffset = ListFunctionsRequest.CreateListFunctionsRequest(
                fbb, Handle, functionIndexStart, functionIndexEnd);
            var response = await Debugger.CommitRequest(
                fbb, RequestData.ListFunctionsRequest, requestDataOffset);

            var responseData = new ListFunctionsResponse();

            response.GetResponseData(responseData);

            var functionEntry = new xe.debug.proto.FunctionEntry();

            for (int i = 0; i < responseData.EntryLength; ++i)
            {
                responseData.GetEntry(functionEntry, i);
                var function = new Function(Debugger, this, functionEntry);
                functions.Add(function);
            }

            functions.Sort((Function a, Function b) => {
                return((int)((long)a.AddressStart - (long)b.AddressStart));
            });
        }
        protected override async Task <bool> PerformActionAsync()
        {
            ListFunctionsRequest  request  = new ListFunctionsRequest();
            ListFunctionsResponse response = null;

            do
            {
                if (response != null)
                {
                    request.Marker = response.NextMarker;
                }

                try
                {
                    response = await this.LambdaClient.ListFunctionsAsync(request);
                }
                catch (Exception e)
                {
                    throw new LambdaToolsException("Error listing Lambda functions: " + e.Message, LambdaToolsException.LambdaErrorCode.LambdaListFunctions, e);
                }

                foreach (var function in response.Functions)
                {
                    this.Logger.WriteLine((function.FunctionName.PadRight(40) + " (" + function.Runtime + ")").PadRight(10) + "\t" + function.Description);
                }
            } while (!string.IsNullOrEmpty(response.NextMarker));

            return(true);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            ListFunctionsResponse response = new ListFunctionsResponse();

            UnmarshallResult(context, response);

            return(response);
        }
Exemplo n.º 7
0
        public void Setup()
        {
            _firstPage = new ListFunctionsResponse
            {
                NextMarker = "token-1",
                Functions  = new List <FunctionConfiguration>
                {
                    new FunctionConfiguration {
                        FunctionName = "Function-1"
                    }
                }
            };
            _secondPage = new ListFunctionsResponse
            {
                NextMarker = "token-2",
                Functions  = new List <FunctionConfiguration>
                {
                    new FunctionConfiguration {
                        FunctionName = "Function-2"
                    }
                }
            };
            _thirdPage = new ListFunctionsResponse
            {
                Functions = new List <FunctionConfiguration>
                {
                    new FunctionConfiguration {
                        FunctionName = "Function-3"
                    }
                }
            };

            var lambdaMock = new Mock <IAmazonLambda>();

            lambdaMock.Setup(s => s.ListFunctionsAsync(
                                 It.Is <ListFunctionsRequest>(r => r.Marker == null),
                                 It.IsAny <CancellationToken>()
                                 )).ReturnsAsync(_firstPage);

            lambdaMock.Setup(s => s.ListFunctionsAsync(
                                 It.Is <ListFunctionsRequest>(r => r.Marker == "token-1"),
                                 It.IsAny <CancellationToken>()
                                 )).ReturnsAsync(_secondPage);

            lambdaMock.Setup(s => s.ListFunctionsAsync(
                                 It.Is <ListFunctionsRequest>(r => r.Marker == "token-2"),
                                 It.IsAny <CancellationToken>()
                                 )).ReturnsAsync(_thirdPage);

            _lambdaSource = new LambdaSource(lambdaMock.Object);
        }
        public static async Task <List <FunctionConfiguration> > GetAllFunctions()
        {
            List <FunctionConfiguration> _functionList = new List <FunctionConfiguration>();
            ListFunctionsResponse        _response     = new ListFunctionsResponse();

            do
            {
                _response = (await _lambdaClient.ListFunctionsAsync(new ListFunctionsRequest {
                    Marker = _response.NextMarker ?? null
                }));
                _functionList.AddRange(_response.Functions);
            }while (_response.NextMarker != null);

            return(_functionList);
        }
Exemplo n.º 9
0
        public override async Task <bool> ExecuteAsync()
        {
            try
            {
                ListFunctionsRequest  request  = new ListFunctionsRequest();
                ListFunctionsResponse response = null;
                do
                {
                    if (response != null)
                    {
                        request.Marker = response.NextMarker;
                    }

                    try
                    {
                        response = await this.LambdaClient.ListFunctionsAsync(request);
                    }
                    catch (Exception e)
                    {
                        throw new LambdaToolsException("Error listing Lambda functions: " + e.Message, LambdaToolsException.ErrorCode.LambdaListFunctions, e);
                    }

                    foreach (var function in response.Functions)
                    {
                        this.Logger.WriteLine((function.FunctionName.PadRight(40) + " (" + function.Runtime + ")").PadRight(10) + "\t" + function.Description);
                    }
                } while (!string.IsNullOrEmpty(response.NextMarker));
            }
            catch (LambdaToolsException e)
            {
                this.Logger.WriteLine(e.Message);
                this.LastToolsException = e;
                return(false);
            }
            catch (Exception e)
            {
                this.Logger.WriteLine($"Unknown error listing Lambda functions: {e.Message}");
                this.Logger.WriteLine(e.StackTrace);
                return(false);
            }

            return(true);
        }
Exemplo n.º 10
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, ListFunctionsResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            while (context.Read())
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                    if (context.TestExpression("FunctionList", targetDepth))
                    {
                        var unmarshaller = FunctionListUnmarshaller.Instance;
                        response.FunctionList = unmarshaller.Unmarshall(context);
                        continue;
                    }
                }
                else if (context.IsEndElement && context.CurrentDepth < originalDepth)
                {
                    return;
                }
            }

            return;
        }