Home Php C# Sql C C++ Javascript Python Java Go Android Git Linux Asp.net Django .net Node.js Ios Xcode Cocoa Iphone Mysql Tomcat Mongodb Bash Objective-c Scala Visual-studio Apache Elasticsearch Jar Eclipse Jquery Ruby-on-rails Ruby Rubygems Android-studio Spring Lua Sqlite Emacs Ubuntu Perl Docker Swift Amazon-web-services Svn Html Ajax Xml Java-ee Maven Intellij-idea Rvm Macos Unix Css Ipad Postgresql Css3 Json Windows-server Vue.js Typescript Oracle Hibernate Internet-explorer Github Tensorflow Laravel Symfony Redis Html5 Google-app-engine Nginx Firefox Sqlalchemy Lucene Erlang Flask Vim Solr Webview Facebook Zend-framework Virtualenv Nosql Ide Twitter Safari Flutter Bundle Phonegap Centos Sphinx Actionscript Tornado Register | Login | Edit Tags | New Questions | 繁体 | 简体


10 questions online user: 8

13
votes
answers
46 views
+10

从lambda返回变体

我有这个简单的lambda:

  std :: variant< int,char> myLambda = [](){//没有合适的用户定义的从“type”到“std :: variant< int,char>”的转换 存在std :: variant< int,char> 水库; if(true){res = 1; } else {res ='c'; } return res; };   

但是它没有编译,产生错误没有合适的用户定义的转换,从“type”到“std :: variant< int,char>” 存在我做错了什么?

沙发
+60
+50

lambda表达式类型错误。您正在尝试绑定到 std :: variant< int,char> Lambda表达式类型是 ClosureType 使用 auto

  auto processProjectFile = [](){std :: variant< int,char> 水库; if(true){res = 1; } else {res ='c'; } return res; };   

或者,你可以将 ClosureType 强制转换为 std :: function ,用 std替换 auto :: function< std :: variant< int,char>(void)>

但是如果你打算调用lambda,只需替换}; 最后由

是的,这是我错过的。谢谢。我遇到过的愚蠢错误。BTW std :: function部分很方便!谢谢! - Nurbol Alpysbayev 8月30日12:32

不确定ClosureType是什么意思。一个lambda类型的名称是impl-defined - Lightness Races in Orbit 8月30日13:27

+70

要么是指

  std :: variant< int,char> v = [](){std :: variant< int,char> 水库; if(true){res = 1; } else {res ='c'; } return res; }(); ^^^   

或者你的意思是

  auto myLambda = [](){std :: variant< int,char> 水库; if(true){res = 1; } else {res ='c'; } return res; };   

Lambda表达式具有唯一类型。

0
votes
answers
50 views
+10

使用.NET核心在aws lambda中讀取excel文件

2

我有一個在AWS Lambda中運行的.NET Core應用程序。我現在有一個需求來閱讀並對Excel文件進??行一些計算。我發現對於Excel在.NET的核心解析兩個庫,但每次似乎並不能夠在lambda運行不同的原因:使用.NET核心在aws lambda中讀取excel文件

我有任何除了選擇:

  1. 等待拉姆達支持.NET核2.0
  2. 不使用lambda

謝謝。

+2

此鏈接可能有所幫助:https://stackoverflow.com/questions/33436525/how-to-parse-excel-rows-back-to-types-using-epplus/37746915#37746915 –

沙发
0
2

如果您正在尋找替代選項,則可以使用Google表格和API代替使用Excel。

可以從Lamda調用Google Sheets API,如果存在複雜的讀寫操作,還可以在Google Sheet中編寫應用程序腳本,並從Lambda調用它。

我們處於類似的情況,並將Excel導入到Google表格,並能夠進行計算工作。

0
votes
answers
37 views
+10

通過表達式檢索嵌套的PropertyInfo

1

我試圖創建一個函數,我可以在表達式中傳遞我感興趣的屬性。我讓它爲頂級屬性工作,但不適用於嵌套屬性。通過表達式檢索嵌套的PropertyInfo

例模型

public class Foo { 
    public string Name { get; set; } 
    public List<Foo> List { get; set; } 
} 

我有什麼到目前爲止

private PropertyInfo GetPropertyInfo<TModel>(Expression<Func<TModel, object>> selector) 
    { 
     if (selector.NodeType != ExpressionType.Lambda) 
     { 
      throw new ArgumentException("Selector must be lambda expression", nameof(selector)); 
     } 

     var lambda = (LambdaExpression)selector; 

     var memberExpression = ExtractMemberExpression(lambda.Body); 
     if (memberExpression == null) 
      throw new ArgumentException("Selector must be member access expression", nameof(selector)); 

     if (memberExpression.Member.DeclaringType == null) 
     { 
      throw new InvalidOperationException("Property does not have declaring type"); 
     } 

     return memberExpression.Member.DeclaringType.GetProperty(memberExpression.Member.Name); 
    } 

    private static MemberExpression ExtractMemberExpression(Expression expression) 
    { 
     if (expression.NodeType == ExpressionType.MemberAccess) 
     { 
      return ((MemberExpression)expression); 
     } 

     if (expression.NodeType == ExpressionType.Convert) 
     { 
      var operand = ((UnaryExpression)expression).Operand; 
      return ExtractMemberExpression(operand); 
     } 

     return null; 
    } 

所以:

GetPropertyInfo<Foo>(x => x.Name); // works 
GetPropertyInfo<Foo>(x => x.List.Select(y => y.Name); <-- how do I get this? 

我正在尋找一種方法可以選擇任何財產從一個複雜的對象。

沙发
0
2

您需要擴展ExtractMemberExpression只是有點接受Select調用表達式:

private MemberExpression ExtractMemberExpression(Expression expression) { 
    if (expression.NodeType == ExpressionType.MemberAccess) { 
     return ((MemberExpression) expression); 
    } 

    if (expression.NodeType == ExpressionType.Convert) { 
     var operand = ((UnaryExpression) expression).Operand; 
     return ExtractMemberExpression(operand); 
    } 
    if (expression.NodeType == ExpressionType.Lambda) {    
     return ExtractMemberExpression(((LambdaExpression) expression).Body); 
    } 

    if (expression.NodeType == ExpressionType.Call) { 
     var call = (MethodCallExpression) expression; 
     // any method named Select with 2 parameters will do 
     if (call.Method.Name == "Select" && call.Arguments.Count == 2) { 
      return ExtractMemberExpression(call.Arguments[1]); 
     } 
    } 

    return null; 
} 
+0

真棒,謝謝 – Magpie

0
votes
answers
65 views
+10

如何爲Zapier編寫回調函數

0

我在Lambda中有一個可以正常工作的nodejs函數。但是,當我嘗試將其與Zapier整合時。該函數不會將值返回給Zapier。他們是一種特定的方式來回調您的lambda函數,以便Zapier可以接收返回的值?如何爲Zapier編寫回調函數

+0

你不應該需要任何特定的東西。您是否閱讀了https://zapier.com/help/aws-lambda?如果是這樣,你能否在這裏提供你的函數的簡化版本,以便我們看到並測試? – xavdid

+0

@xavdid該函數工作正常我的回調看起來像這樣'callback(null,{「statusCode」:200,「headers」:{「Content-Type」:「application/json」},「body」:labels}); '標籤是一個字符串。正如我所說的功能正常工作,標籤中有內容,但是沒有任何內容返回給Zapier –

沙发
0
0

那麼,你可以顯示爲一些代碼來獲得一個想法。我的猜測是你將一個對象返回給Zapier,而Zapier總是期望得到一組數據。如果我是正確的,請嘗試在發送之前將對象包裝在數組中。

0
votes
answers
60 views
+10

VPC中的Lambda函數無法訪問Internet

0

我的Lambda函數可以訪問VPC中的其他資源,但一旦它嘗試向Internet發出請求,它就會超時。我有以下幾點:VPC中的Lambda函數無法訪問Internet

  • 兩個專用子網
  • 路由表的路由0.0.0.0/0互聯網網關。
  • 一對夫婦的ACL規則和LAMBDA安全組

任何幫助將是有益的。這裏是我的CF模板:

AWSTemplateFormatVersion: 2010-09-09 
Description: VPC Stack 
Resources: 
    VPC: 
    Type: 'AWS::EC2::VPC' 
    Properties: 
     CidrBlock: 10.0.0.0/16 
     EnableDnsHostnames: true 
     Tags: 
     - Key: Application 
      Value: !Ref 'AWS::StackId' 
    Subnet1: 
    Type: 'AWS::EC2::Subnet' 
    Properties: 
     VpcId: !Ref VPC 
     CidrBlock: 10.0.3.0/24 
     AvailabilityZone: 'us-east-1b' 
     Tags: 
     - Key: Application 
      Value: !Ref 'AWS::StackId' 
    Subnet2: 
    Type: 'AWS::EC2::Subnet' 
    Properties: 
     VpcId: !Ref VPC 
     CidrBlock: 10.0.4.0/24 
     AvailabilityZone: 'us-east-1e' 
     Tags: 
     - Key: Application 
      Value: !Ref 'AWS::StackId' 
    InternetGateway: 
    Type: 'AWS::EC2::InternetGateway' 
    Properties: 
     Tags: 
     - Key: Application 
      Value: !Ref 'AWS::StackId' 
    AttachGateway: 
    Type: 'AWS::EC2::VPCGatewayAttachment' 
    Properties: 
     VpcId: !Ref VPC 
     InternetGatewayId: !Ref InternetGateway 
    RouteTable: 
    Type: 'AWS::EC2::RouteTable' 
    Properties: 
     VpcId: !Ref VPC 
     Tags: 
     - Key: Application 
      Value: !Ref 'AWS::StackId' 
    Route: 
    Type: 'AWS::EC2::Route' 
    DependsOn: AttachGateway 
    Properties: 
     RouteTableId: !Ref RouteTable 
     DestinationCidrBlock: 0.0.0.0/0 
     GatewayId: !Ref InternetGateway 
    SubnetRouteTableAssociation1: 
    Type: 'AWS::EC2::SubnetRouteTableAssociation' 
    Properties: 
     SubnetId: !Ref Subnet1 
     RouteTableId: !Ref RouteTable 
    SubnetRouteTableAssociation2: 
    Type: 'AWS::EC2::SubnetRouteTableAssociation' 
    Properties: 
     SubnetId: !Ref Subnet2 
     RouteTableId: !Ref RouteTable 
    NetworkAcl: 
    Type: 'AWS::EC2::NetworkAcl' 
    Properties: 
     VpcId: !Ref VPC 
     Tags: 
     - Key: Application 
      Value: !Ref 'AWS::StackId' 
    InboundHTTPNetworkAclEntry: 
    Type: 'AWS::EC2::NetworkAclEntry' 
    Properties: 
     NetworkAclId: !Ref NetworkAcl 
     RuleNumber: '100' 
     Protocol: '6' 
     RuleAction: allowAWSTemplateFormatVersion: 2010-09-09 
Description: VPC Stack 
Resources: 
    VPC: 
    Type: 'AWS::EC2::VPC' 
    Properties: 
     CidrBlock: 10.0.0.0/16 
     EnableDnsHostnames: true 
     Tags: 
     - Key: Application 
      Value: !Ref 'AWS::StackId' 
    Subnet1: 
    Type: 'AWS::EC2::Subnet' 
    Properties: 
     VpcId: !Ref VPC 
     CidrBlock: 10.0.3.0/24 
     AvailabilityZone: 'us-east-1b' 
     Tags: 
     - Key: Application 
      Value: !Ref 'AWS::StackId' 
    Subnet2: 
    Type: 'AWS::EC2::Subnet' 
    Properties: 
     VpcId: !Ref VPC 
     CidrBlock: 10.0.4.0/24 
     AvailabilityZone: 'us-east-1e' 
     Tags: 
     - Key: Application 
      Value: !Ref 'AWS::StackId' 
    InternetGateway: 
    Type: 'AWS::EC2::InternetGateway' 
    Properties: 
     Tags: 
     - Key: Application 
      Value: !Ref 'AWS::StackId' 
    AttachGateway: 
    Type: 'AWS::EC2::VPCGatewayAttachment' 
    Properties: 
     VpcId: !Ref VPC 
     InternetGatewayId: !Ref InternetGateway 
    RouteTable: 
    Type: 'AWS::EC2::RouteTable' 
    Properties: 
     VpcId: !Ref VPC 
     Tags: 
     - Key: Application 
      Value: !Ref 'AWS::StackId' 
    Route: 
    Type: 'AWS::EC2::Route' 
    DependsOn: AttachGateway 
    Properties: 
     RouteTableId: !Ref RouteTable 
     DestinationCidrBlock: 0.0.0.0/0 
     GatewayId: !Ref InternetGateway 
    SubnetRouteTableAssociation1: 
    Type: 'AWS::EC2::SubnetRouteTableAssociation' 
    Properties: 
     SubnetId: !Ref Subnet1 
     RouteTableId: !Ref RouteTable 
    SubnetRouteTableAssociation2: 
    Type: 'AWS::EC2::SubnetRouteTableAssociation' 
    Properties: 
     SubnetId: !Ref Subnet2 
     RouteTableId: !Ref RouteTable 
    NetworkAcl: 
    Type: 'AWS::EC2::NetworkAcl' 
    Properties: 
     VpcId: !Ref VPC 
     Tags: 
     - Key: Application 
      Value: !Ref 'AWS::StackId' 
    InboundHTTPNetworkAclEntry: 
    Type: 'AWS::EC2::NetworkAclEntry' 
    Properties: 
     NetworkAclId: !Ref NetworkAcl 
     RuleNumber: '100' 
     Protocol: '6' 
     RuleAction: allow 
     Egress: 'false' 
     CidrBlock: 0.0.0.0/0 
     PortRange: 
     From: '80' 
     To: '80' 
    InboundSSHNetworkAclEntry: 
    Type: 'AWS::EC2::NetworkAclEntry' 
    Properties: 
     NetworkAclId: !Ref NetworkAcl 
     RuleNumber: '101' 
     Protocol: '6' 
     RuleAction: allow 
     Egress: 'false' 
     CidrBlock: 0.0.0.0/0 
     PortRange: 
     From: '22' 
     To: '22' 
    InboundResponsePortsNetworkAclEntry: 
    Type: 'AWS::EC2::NetworkAclEntry' 
    Properties: 
     NetworkAclId: !Ref NetworkAcl 
     RuleNumber: '102' 
     Protocol: '6' 
     RuleAction: allow 
     Egress: 'false' 
     CidrBlock: 0.0.0.0/0 
     PortRange: 
     From: '1024' 
     To: '65535' 
    OutBoundNetworkAclEntry: 
    Type: 'AWS::EC2::NetworkAclEntry' 
    Properties: 
     NetworkAclId: !Ref NetworkAcl 
     RuleNumber: '103' 
     Protocol: '6' 
     RuleAction: allow 
     Egress: 'true' 
     CidrBlock: 0.0.0.0/0 
     PortRange: 
     From: '0' 
     To: '65535' 
    SubnetNetworkAclAssociation1: 
    Type: 'AWS::EC2::SubnetNetworkAclAssociation' 
    Properties: 
     SubnetId: !Ref Subnet1 
     NetworkAclId: !Ref NetworkAcl 
    SubnetNetworkAclAssociation2: 
    Type: 'AWS::EC2::SubnetNetworkAclAssociation' 
    Properties: 
     SubnetId: !Ref Subnet2 
     NetworkAclId: !Ref NetworkAcl 
    LambdaSecurityGroup: 
     Type: AWS::EC2::SecurityGroup 
     Properties: 
      VpcId: !Ref VPC 
      GroupDescription: Access to Lambda functions 
      SecurityGroupIngress: 
      - CidrIp: 0.0.0.0/0 
       IpProtocol: -1 
     SecurityGroupEgress: 
      - CidrIp: 0.0.0.0/0 
       IpProtocol: -1 
Outputs: 
    VpcId: 
    Description: VPC ID 
    Value: !Ref VPC 
    Export: 
     Name: !Sub "Portal-VpcId" 
    Subnet1: 
    Description: Subnet ID 1 
    Value: !Ref Subnet1 
    Export: 
     Name: !Sub "Portal-SubnetID1" 
    Subnet2: 
    Description: Subnet ID 2 
    Value: !Ref Subnet2 
    Export: 
     Name: !Sub "Portal-SubnetID2"  
    LambdaSecurityGroup: 
    Description: Access to Lambda functions 
    Value: !Ref LambdaSecurityGroup 
    Export: 
     Name: !Sub "LambdaSecurityGroup"  
     Egress: 'false' 
     CidrBlock: 0.0.0.0/0 
     PortRange: 
     From: '80' 
     To: '80' 
    InboundResponsePortsNetworkAclEntry: 
    Type: 'AWS::EC2::NetworkAclEntry' 
    Properties: 
     NetworkAclId: !Ref NetworkAcl 
     RuleNumber: '102' 
     Protocol: '6' 
     RuleAction: allow 
     Egress: 'false' 
     CidrBlock: 0.0.0.0/0 
     PortRange: 
     From: '1024' 
     To: '65535' 
    OutBoundNetworkAclEntry: 
    Type: 'AWS::EC2::NetworkAclEntry' 
    Properties: 
     NetworkAclId: !Ref NetworkAcl 
     RuleNumber: '103' 
     Protocol: '6' 
     RuleAction: allow 
     Egress: 'true' 
     CidrBlock: 0.0.0.0/0 
     PortRange: 
     From: '0' 
     To: '65535' 
    SubnetNetworkAclAssociation1: 
    Type: 'AWS::EC2::SubnetNetworkAclAssociation' 
    Properties: 
     SubnetId: !Ref Subnet1 
     NetworkAclId: !Ref NetworkAcl 
    SubnetNetworkAclAssociation2: 
    Type: 'AWS::EC2::SubnetNetworkAclAssociation' 
    Properties: 
     SubnetId: !Ref Subnet2 
     NetworkAclId: !Ref NetworkAcl 
    LambdaSecurityGroup: 
     Type: AWS::EC2::SecurityGroup 
     Properties: 
      VpcId: !Ref VPC 
      GroupDescription: Access to Lambda functions 
      SecurityGroupIngress: 
      - CidrIp: 0.0.0.0/0 
       IpProtocol: -1 
      SecurityGroupEgress: 
      - CidrIp: 0.0.0.0/0 
       IpProtocol: -1 
Outputs: 
    VpcId: 
    Description: VPC ID 
    Value: !Ref VPC 
    Export: 
     Name: !Sub "Portal-VpcId" 
    Subnet1: 
    Description: Subnet ID 1 
    Value: !Ref Subnet1 
    Export: 
     Name: !Sub "Portal-SubnetID1" 
    Subnet2: 
    Description: Subnet ID 2 
    Value: !Ref Subnet2 
    Export: 
     Name: !Sub "Portal-SubnetID2"  
    LambdaSecurityGroup: 
    Description: Access to Lambda functions 
    Value: !Ref LambdaSecurityGroup 
    Export: 
     Name: !Sub "LambdaSecurityGroup"  

CF模板2:

??
+1

看到的是https將所有向外的連接://aws.amazon .com/premiumsupport/knowledge-center/internet-access-lambda-function/ – jarmod

沙发
0
2

在VPC內部執行Lambda函數時,Lambda函數將只接收私有IP地址。它不會收到公共IP地址。

爲了任何AWS服務器通過互聯網網關來訪問公共互聯網,它必須:

  1. 有一個公網IP地址,並
  2. 在一個公共子網(即一個子網。直接訪問互聯網網關)

由於您的Lambda函數沒有該公共IP地址,因此它無法訪問互聯網,即使它位於公有子網中。

要解決此問題,您必須在專用子網中執行Lambda函數。這是一個子網:

  1. 沒有到Internet網關的直接訪問,並
  2. 通過NAT實例或NAT網關
板凳
0
2

您通過NAT實例需要途徑,如果你想拉姆達與Internet進行通信。

向您現有的VPC子網添加兩個子網和一個NAT網關。然後,在新的子網中設置路由表,通過NAT路由Internet。

+1

@DominickPiganell - 澄清爲什麼* Chris *說你還需要兩個子網:當子網路由到Internet網關時,它是一個_public_子網。專用子網不通過IGW路由,但可能通過NAT網關(與NAT實例不同)路由。 – kdgregory

0
votes
answers
45 views
+10

Javac不能推斷類型,除非lambda表達式被內聯

0

我有以下的使用Vavr的Java代碼片段。類型檢查失敗,除非我內聯一個參數。Javac不能推斷類型,除非lambda表達式被內聯

爲什麼下面的代碼不能被編譯器接受?

import io.vavr.Function1; 
import io.vavr.Tuple; 
import io.vavr.Tuple2; 
import io.vavr.collection.List; 
import io.vavr.Option; 

import static io.vavr.collection.List.unfoldRight; 

class A {} 
class B {} 
class Main { 
    Function1<A, Option<Tuple2<B, A>>> f = (a) -> Option.of(Tuple.of(new B(), new A())); 
    List<B> L0 = unfoldRight(new A(), f); // * 
    List<B> L1 = unfoldRight(new A(), (a) -> Option.of(Tuple.of(new B(), new A())); 

    Option<Tuple2<B, A>> g(A a) { return Option.of(Tuple.of(new B(), new A())); } 
    List<B> L2 = unfoldRight(new A(), (a) -> g(a)); // ** 
} 


// * Compilation fails with: "Incompatible equality constraint: ? extends T and A" 

// ** Compilation fails with: "Incompatible equality constraint: ? extends A and A" 

下面是來自Vavr庫unfoldRight方法簽名:

static <T, U> List<U> unfoldRight(T seed, Function<? super T, Option<Tuple2<? extends U, ? extends T>>> f) 

,這裏是在Github上的文檔的鏈接相同:

https://github.com/vavr-io/vavr/blob/master/vavr/src/main/java/io/vavr/collection/List.java#L644-L671

沙发
0
1

的關鍵是, Option<Tuple<A, B>>不是Option<Tuple<? extends A, ? extends B>>的一個實例(雖然它是Option<? extends Tuple<? extends A, ? extends B>>)。

考慮一個List<Map<A, B>>List<Map<? extends A, ? extends B>>(從類型安全角度與您的代碼相同)的情況。如果你可以寫:

List<Map<A, B>> list = new ArrayList<>(); 

// Compiler error! Pretend it's OK, though. 
List<Map<? extends A, ? extends B>> list2 = list; 

Map<SubclassOfA, SubclassOfB> map = new HashMap<>(); 
list2.add(map); 

list.get(0).put(new A(), new B()); 

現在這是一個問題,因爲map包含一個鍵/值對類型A,B,不SubclassOfA,SubclassOfB的。因此,如果您試圖從map獲取東西,則會得到ClassCastException

// ClassCastException! 
SubclassOfA soa = map.keySet().iterator().next(); 

Ideone demo

因此,它是由編譯器不允許的。

如果list2被宣佈爲List<? extends Map<? extends A, ? extends B>>,則不能撥打list2.add(map),因此您無法獲得相同的問題。因此,該分配將被允許。

添加通配符上界到你的類型:

Function1<A, Option<Tuple2<? extends B, ? extends A>>> f = ... 
Option<Tuple2<? extends B, ? extends A>> g(A a) { ... } 
+0

哦,對了,這是'''不兼容的不等式約束:(?延伸A,A)'''不'''不兼容的不等式約束:( ?擴展A,?擴展A)'''。非常感謝! – Zaaier

0
votes
answers
67 views
+10

Claudia.Js - 添加發布標籤

0

任何人都有一種巧妙的方式,在部署時使用Claudi.Js將Github發佈標籤添加到NodeJs風格的AWS Lambda中?我們最初使用Terraform設置我們的Lambdas,然後使用Claudia從Travis部署它們。我想用每個發佈標籤標記它們。Claudia.Js - 添加發布標籤

技術: Terraform 的Git 特拉維斯 克勞迪婭 節點6(AWS的限制) AWS CLI 猛砸

沙发
0
0

添加釋放標籤Github上是推動Git標籤的問題。如果你想從CI做到這一點,你的CI需要有權推動你的回購。 添加標籤很簡單,您應該可以按照本教程進行操作:https://www.barrykooij.com/create-github-releases-via-command-line/

0
votes
answers
48 views
+10

無法在命令行上啓動Amazon Lambda(HelloWorld示例)

1

我遵循Amazon的教程,在悉尼地區創建HelloWorld lambda函數。它在AWS控制檯上工作。無法在命令行上啓動Amazon Lambda(HelloWorld示例)

enter image description here

然後我試圖做到這一點的命令行:

aws lambda invoke --invocation-type RequestResponse --function-name HelloWorld --region Sydney --payload '{"key1":"value1", "key2":"value2", "key3":"value3"}' outputfile.txt

錯誤:

Could not connect to the endpoint URL: " https://lambda.Sydney.amazonaws.com/2015-03-31/functions/HelloWorld/invocations "

我覺得我的安全密鑰是工作,因爲上市的以下命令我的S3桶工作:

aws s3api list-buckets # Worked, so the security keys should work

沙发
0
2

根據您發出的用於調用Lambda函數的CLI命令,似乎問題在於region參數。

取而代之的是區域參數值「悉尼」,以「AP-東南-2」,這是亞太(悉尼)地區代碼替換它。

0
votes
answers
52 views
+10

C#Lambda表達式到VB.Net

0

我想轉換C#Lambda表達式到VB.Net

cfind.OnResponseReceived = (DicomCFindRequest rq, DicomCFindResponse rp) => { 
    Console.WriteLine("Study UID: {0}", rp.Dataset.Get<string>(DicomTag.StudyInstanceUID)); 
}; 

到VB.Net

但是, 既不

AddHandler cfind.OnResponseReceived, AddressOf onResponse 

也不

AddHandler cfind.OnResponseReceived, Sub(rq, rp) 
     onCFindResponse(rq, rp) 
End Sub 

事作品.. 我該如何轉換它?

+0

的作用,並不等同 - 你重構原始的C#Console.WriteLine行動統一到一個單獨的'Sub'? – StuartLC

+0

這是一項任務,而不是事件訂閱。注意=,沒有+ =。因此使用AddHander是不正確的。賦值在VB.NET中的作用相同,您可以使用=。使用Sub,而不是Function。 –

沙发
0
2

這應該是對應的VB.NET:要執行

cfind.OnResponseReceived = Sub(rq As DicomCFindRequest, rp As DicomCFindResponse) 
    Console.WriteLine("Study UID: {0}", rp.Dataset.[Get](Of String)(DicomTag.StudyInstanceUID)) 

End Sub 
+0

由於該方法不返回任何東西,它應該是一個'Sub',而不是'Function'。 –

+0

@visualvincent你是對的,謝謝。更新了答案。 – CodingYoshi

0
votes
answers
40 views
+10

過濾但屬性和子實體屬性

1

我爲構建搜索邏輯的動態表達式樹遇到了一個小問題。爲實體自己的屬性創建一個表達式樹工作正常,但我不知道如何添加一個表達式,它將按照子實體屬性進行過濾。過濾但屬性和子實體屬性

這是我的任務實體:

public class Task: Entity 
{ 
    public TaskType Type { get; set; } 
    public TaskPriority Priority { get; set; } 
    public int ProjectId { get; set; } 
    public Project Project { get; set; } 
} 

這裏是項目實體:

public class Project: Entity 
{   
    public int CustomerId { get; set; } 
    public Customer Customer { get; set; } 
} 

和邏輯構建動態表達:

public Func<TaskItem, bool> Build(IList<Filter> filters) 
{ 
    ParameterExpression param = Expression.Parameter(typeof(TaskItem), "task"); 
    List<Filter> priorityFilter = FilterFilters(filters, "Priority"); 
    List<Filter> typeFilter = FilterFilters(filters, "Type"); 
    List<Filter> customerFilter = FilterFilters(filters, "CustomerId"); 

    Expression expression = null; 

    // BuildExpression is a method which simply creates expression which is using Tasks properties (like Type or Priority) 
    expression = BuildExpression(param, priorityFilter, expression); 
    expression = BuildExpression(param, typeFilter, expression); 

    // This part need's to be reworked 
    ParameterExpression projectParam = Expression.Parameter(typeof(Project), "project"); 
    Expression projectCustomerExpression = Expression.Equal(Expression.PropertyOrField(projectParam, "CustomerId"), Expression.Constant(customerFilter[0].Value)); 
    Expression customerExpression = Expression.Equal(Expression.PropertyOrField(param, "Project"), projectCustomerExpression); 
    Expression finall = expression != null ? Expression.AndAlso(expression, projectCustomerExpression) : projectCustomerExpression;   
    // End of filtering by CutomerId 

    return Expression.Lambda<Func<TaskItem, bool>>(finall, param).Compile(); 
} 

我不知道怎麼樣通過CustomerId進行過濾。上面代碼標記爲This part need's to be reworked的部分可能是錯誤的,或者至少是其最後部分。這個想法是擴展現有的表達式(這個由BuildExpression方法構建的表達式)和一個將由CustomerId過濾的表達式。

我已經在這方面失去了一些時間,嘗試自己尋找答案,但沒有結果。

任何幫助?

沙发
0
2

由於您提供了最少的代碼,因此如何創建實際表達式是未知的。所以,我會嘗試爲這種情況提供一個通用配方。

如果你想過濾的Task列表,那麼你仍然需要使用Task類型相同??,就像你已經這樣做:

ParameterExpression param = Expression.Parameter(typeof(TaskItem), "task"); 

沒有必要創建Project類型的其他??即使您想過濾Project的屬性。相反,你只需要重用前者??。需要注意的是,如果我們建立一個靜態謂詞像下面,這也是我們也不使用不同的參數表達的情況:

queryableTask.Where(t => t.Priority == TaskPriority.High && t.Project.CustomerId == 123); 

我們動態地建立在導航(子)屬性篩選,關鍵是以正確形成左表達式(即導航屬性的表達式)。

可以說我們的導航屬性是用點符號表示的:Project.CustomerId。然後,我們可以做這樣的事情,以創建左表達財產:

// We already have the following commented properties 
// prop = "Project.CustomerId"; 
// ParameterExpression param = Expression.Parameter(typeof(TaskItem), "task"); 
var leftExpr = prop.Split('.') 
        .Aggregate<string, MemberExpression>(null, 
         (acc, p) => acc == null 
          ? Expression.Property(param, p) 
          : Expression.Property(acc, p)); 

然後你就可以做其他像一個正常的特性,例如創建正確表達,並將其與另一種表達結合定義運算符(等於,不等於等)。

希望這會有所幫助。

+0

謝謝 - 你救了我的一天!但是當我像這樣調用ToList()時,我得到「對象引用未設置爲對象的實例」:'Context.Tasks.Where(searchCondition).ToList()'(搜索條件包含表達它是'IQueryable ')。堆棧跟蹤:在System.Linq.Enumerable的System.Linq.Enumerable.WhereEnumerableIterator1.ToList()處的lambda_method(Closure,Task)處。ToList [TSource](IEnumerable1 source)'。 任何想法? –

+1

@DawidRutkowski很可能'Project'是'null'。如果你想填充'IQueryable ',你最好改變方法簽名來返回'Expression >'並移除'Compile()'調用。目前,即使您的源代碼是'IQueryable ',編譯器也會調用'IEnumerable '上的Where'方法。 –

+1

@DawidRutkowski雖然我不確定,但是可能的原因會像@IvanStoev指出的那樣。如果你在'searchCondition'上使用'.Compile',那麼你不必這樣做,除非你想避免延遲加載。相反,您可以直接將'searchCondition'應用於'IQueryable'數據,然後'ToList'來枚舉。如果這不起作用,那麼可以嘗試包括導航屬性路徑(不包括路徑中的最後一個屬性;即簡單類型的實際屬性)以強制連接。 –