├── fc.png ├── .gitignore ├── samples ├── ReadMe.md ├── fc-csharp-sdk-samples │ ├── fc-csharp-sdk-samples.csproj │ └── Program.cs ├── fc-code-samples │ ├── Events │ │ ├── TimerEvent.cs │ │ ├── MNSTopicEvent.cs │ │ ├── LogEvent.cs │ │ └── OSSEvent.cs │ ├── fc-code-samples.csproj │ ├── TableSoreEventHandler.cs │ ├── OSSEventHandler.cs │ └── SimpleHandler.cs ├── fc-exec-samples │ ├── fc-exec-samples.csproj │ └── Program.cs └── samples.sln ├── Libraries ├── src │ ├── Aliyun.FunctionCompute.SDK.Unittests │ │ ├── hello.zip │ │ ├── Aliyun.FunctionCompute.SDK.Unittests.csproj │ │ ├── ReservedCapacityTest.cs │ │ ├── TestConfig.cs │ │ └── TagTest.cs │ └── Aliyun.FunctionCompute.SDK │ │ ├── Response │ │ ├── Service │ │ │ ├── GetServiceResponse.cs │ │ │ ├── CreateServiceResponse.cs │ │ │ ├── UpdateServiceResponse.cs │ │ │ ├── DeleteServiceResponse.cs │ │ │ ├── ServerResponseBase.cs │ │ │ └── ListServicesResponse.cs │ │ ├── Alias │ │ │ ├── GetAliasResponse.cs │ │ │ ├── DeleteAliasResponse.cs │ │ │ ├── CreateAliasResponse.cs │ │ │ ├── UpdateAliasResponse.cs │ │ │ ├── AliasResponseBase.cs │ │ │ └── ListAliasesResponse.cs │ │ ├── Tag │ │ │ ├── TagResourceResponse.cs │ │ │ ├── UntagResourceResponse.cs │ │ │ ├── TagResponseBase.cs │ │ │ └── GetResourceTagsResponse.cs │ │ ├── Trigger │ │ │ ├── GetTriggerResponse.cs │ │ │ ├── CreateTriggerResponse.cs │ │ │ ├── UpdateTriggerResponse.cs │ │ │ ├── DeleteTriggerResponse.cs │ │ │ ├── TriggerResponseBase.cs │ │ │ └── ListTriggersResponse.cs │ │ ├── Function │ │ │ ├── GetFunctionResponse.cs │ │ │ ├── UpdateFunctionResponse.cs │ │ │ ├── CreateFunctionResponse.cs │ │ │ ├── HttpInvokeFunctionResponse.cs │ │ │ ├── DeleteFunctionResponse.cs │ │ │ ├── FunctionResponseBase.cs │ │ │ ├── GetFunctionCodeResponse.cs │ │ │ ├── InvokeFunctionResponse.cs │ │ │ └── ListFunctionsResponse.cs │ │ ├── Version │ │ │ ├── PublishVersionResponse.cs │ │ │ ├── DeleteVersionResponse.cs │ │ │ ├── VersionReaponseBase.cs │ │ │ └── ListVersionsResponse.cs │ │ ├── CustomDomain │ │ │ ├── DeleteCustomDomainResponse.cs │ │ │ ├── GetCustomDomainResponse.cs │ │ │ ├── CreateCustomDomainResponse.cs │ │ │ ├── UpdateCustomDomainResponse.cs │ │ │ ├── CustomDomainResponseBase.cs │ │ │ └── ListCustomDomainsResponse.cs │ │ ├── AsyncConfig │ │ │ ├── DeleteFunctionAsyncConfig.cs │ │ │ ├── GetFunctionAsyncConfigResponse.cs │ │ │ ├── PutFunctionAsyncConfigResponse.cs │ │ │ └── ListFunctionAsyncConfigResponse.cs │ │ ├── IResponseBase.cs │ │ ├── DeleteResponseBase.cs │ │ ├── Provision │ │ │ ├── PutProvisionConfigResponse.cs │ │ │ ├── GetProvisionConfigResponse.cs │ │ │ └── ListProvisionConfigsResponse.cs │ │ ├── Instance │ │ │ ├── ListInstancesResponse.cs │ │ │ └── InstanceExecResponse.cs │ │ └── ReservedCapacity │ │ │ └── ListReservedCapacitiesResponse.cs │ │ ├── Request │ │ ├── IRequestBase.cs │ │ ├── Function │ │ │ ├── GetFunctionCodeRequest.cs │ │ │ ├── DeleteFunctionRequest.cs │ │ │ ├── GetFunctionRequest.cs │ │ │ ├── InvokeFunctionRequest.cs │ │ │ ├── UpdateFunctionRequest.cs │ │ │ ├── CreateFunctionRequest.cs │ │ │ ├── ListFunctionsRequest.cs │ │ │ └── HttpInvokeFunctionRequest.cs │ │ ├── CustomDomain │ │ │ ├── GetCustomDomainRequest.cs │ │ │ ├── DeleteCustomDomainRequest.cs │ │ │ ├── CreateCustomDomainRequest.cs │ │ │ ├── UpdateCustomDomainRequest.cs │ │ │ └── ListCustomDomainsRequest.cs │ │ ├── Tag │ │ │ ├── TagResourceRequest.cs │ │ │ ├── GetResourceTagsRequest.cs │ │ │ └── UntagResourceRequest.cs │ │ ├── Service │ │ │ ├── DeleteServiceRequest.cs │ │ │ ├── CreateServiceRequest.cs │ │ │ ├── GetServiceRequest.cs │ │ │ ├── UpdateServiceRequest.cs │ │ │ └── ListServicesRequest.cs │ │ ├── Alias │ │ │ ├── GetAliasRequest.cs │ │ │ ├── DeleteAliasRequest.cs │ │ │ ├── CreateAliasRequest.cs │ │ │ ├── UpdateAliasRequest.cs │ │ │ └── ListAliasesRequest.cs │ │ ├── Version │ │ │ ├── DeleteVersionRequest.cs │ │ │ ├── PublishVersionRequest.cs │ │ │ └── ListVersionsRequest.cs │ │ ├── ReservedCapacity │ │ │ └── ListReservedCapacitiesRequest.cs │ │ ├── RequestBase.cs │ │ ├── Provision │ │ │ ├── GetProvisionConfigRequest.cs │ │ │ ├── PutProvisionConfigRequest.cs │ │ │ └── ListProvisionConfigsRequest.cs │ │ ├── Trigger │ │ │ ├── GetTriggerRequest.cs │ │ │ ├── DeleteTriggerRequest.cs │ │ │ ├── UpdateTriggerRequest.cs │ │ │ ├── CreateTriggerRequest.cs │ │ │ └── ListTriggersRequest.cs │ │ ├── AsyncConfig │ │ │ ├── DeleteAsyncConfigRequest.cs │ │ │ ├── PutFunctionAsyncConfigRequest.cs │ │ │ ├── GetFunctionAsyncConfigRequest.cs │ │ │ └── ListFunctionAsyncConfigRequest.cs │ │ └── Instance │ │ │ └── ListInstancesRequest.cs │ │ ├── Constants │ │ ├── HeaderKeys.cs │ │ └── Const.cs │ │ ├── model │ │ ├── InstanceMeta.cs │ │ ├── VersionMeta.cs │ │ ├── ReservedCapacityMeta.cs │ │ ├── ProvisionMeta.cs │ │ ├── TagMeta.cs │ │ ├── AliasMeta.cs │ │ ├── FunctionAsyncConfigMeta.cs │ │ ├── TriggerMeta.cs │ │ └── CustomDomainMeta.cs │ │ ├── Utils │ │ └── Helper.cs │ │ ├── Aliyun.FunctionCompute.SDK.nuspec │ │ ├── Aliyun.FunctionCompute.SDK.csproj │ │ └── Config │ │ └── Config.cs └── Aliyun.FunctionCompute.sln ├── .travis.yml ├── LICENSE └── ReadMe.md /fc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aliyun/fc-csharp-sdk/HEAD/fc.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.suo 3 | *.user 4 | Backup* 5 | *.vs 6 | .vscode 7 | 8 | bin 9 | obj 10 | -------------------------------------------------------------------------------- /samples/ReadMe.md: -------------------------------------------------------------------------------- 1 | ## fc-code-samples 2 | 3 | C# 编写的函数示例 4 | 5 | 6 | ## fc-csharp-sdk-samples 7 | 8 | 函数计算 C# 版本 sdk 使用示例 -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK.Unittests/hello.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aliyun/fc-csharp-sdk/HEAD/Libraries/src/Aliyun.FunctionCompute.SDK.Unittests/hello.zip -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Service/GetServiceResponse.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Aliyun.FunctionCompute.SDK.Response 3 | { 4 | public class GetServiceResponse : ServiceResponseBase 5 | { 6 | 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Alias/GetAliasResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Aliyun.FunctionCompute.SDK.Response 3 | { 4 | public class GetAliasResponse: AliasResponseBase 5 | { 6 | 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Service/CreateServiceResponse.cs: -------------------------------------------------------------------------------- 1 | namespace Aliyun.FunctionCompute.SDK.Response 2 | { 3 | public class CreateServiceResponse : ServiceResponseBase 4 | { 5 | 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Tag/TagResourceResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Aliyun.FunctionCompute.SDK.Response 3 | { 4 | public class TagResourceResponse : TagResponseBase 5 | { 6 | 7 | } 8 | } -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Alias/DeleteAliasResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Aliyun.FunctionCompute.SDK.Response 3 | { 4 | public class DeleteAliasResponse : DeleteResponseBase 5 | { 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Service/UpdateServiceResponse.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Aliyun.FunctionCompute.SDK.Response 3 | { 4 | public class UpdateServiceResponse : ServiceResponseBase 5 | { 6 | 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Tag/UntagResourceResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Aliyun.FunctionCompute.SDK.Response 3 | { 4 | public class UntagResourceResponse : TagResponseBase 5 | { 6 | 7 | } 8 | } -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Alias/CreateAliasResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Aliyun.FunctionCompute.SDK.Response 3 | { 4 | public class CreateAliasResponse : AliasResponseBase 5 | { 6 | 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Alias/UpdateAliasResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Aliyun.FunctionCompute.SDK.Response 3 | { 4 | public class UpdateAliasResponse : AliasResponseBase 5 | { 6 | 7 | } 8 | } -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Trigger/GetTriggerResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Aliyun.FunctionCompute.SDK.Response 3 | { 4 | public class GetTriggerResponse: TriggerResponseBase 5 | { 6 | 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Function/GetFunctionResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Aliyun.FunctionCompute.SDK.Response 3 | { 4 | public class GetFunctionResponse: FunctionResponseBase 5 | { 6 | 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Version/PublishVersionResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Aliyun.FunctionCompute.SDK.Response 3 | { 4 | public class PublishVersionResponse : VersionResponseBase 5 | { 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/CustomDomain/DeleteCustomDomainResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Aliyun.FunctionCompute.SDK.Response 3 | { 4 | public class DeleteCustomDomainResponse : DeleteResponseBase 5 | { 6 | } 7 | } -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Function/UpdateFunctionResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Aliyun.FunctionCompute.SDK.Response 3 | { 4 | public class UpdateFunctionResponse : FunctionResponseBase 5 | { 6 | 7 | } 8 | } -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Trigger/CreateTriggerResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Aliyun.FunctionCompute.SDK.Response 3 | { 4 | public class CreateTriggerResponse : TriggerResponseBase 5 | { 6 | 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Trigger/UpdateTriggerResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Aliyun.FunctionCompute.SDK.Response 3 | { 4 | public class UpdateTriggerResponse : TriggerResponseBase 5 | { 6 | 7 | } 8 | } -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Function/CreateFunctionResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Aliyun.FunctionCompute.SDK.Response 3 | { 4 | public class CreateFunctionResponse : FunctionResponseBase 5 | { 6 | 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/CustomDomain/GetCustomDomainResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Aliyun.FunctionCompute.SDK.Response 3 | { 4 | public class GetCustomDomainResponse : CustomDomainResponseBase 5 | { 6 | 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Function/HttpInvokeFunctionResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Aliyun.FunctionCompute.SDK.Response 3 | { 4 | public class HttpInvokeFunctionResponse : InvokeFunctionResponse 5 | { 6 | 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/CustomDomain/CreateCustomDomainResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Aliyun.FunctionCompute.SDK.Response 3 | { 4 | public class CreateCustomDomainResponse : CustomDomainResponseBase 5 | { 6 | 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/CustomDomain/UpdateCustomDomainResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Aliyun.FunctionCompute.SDK.Response 3 | { 4 | public class UpdateCustomDomainResponse : CustomDomainResponseBase 5 | { 6 | 7 | } 8 | } -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Function/DeleteFunctionResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Aliyun.FunctionCompute.SDK.Response 5 | { 6 | public class DeleteFunctionResponse : DeleteResponseBase 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Service/DeleteServiceResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Aliyun.FunctionCompute.SDK.Response 5 | { 6 | public class DeleteServiceResponse : DeleteResponseBase 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Trigger/DeleteTriggerResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Aliyun.FunctionCompute.SDK.Response 5 | { 6 | public class DeleteTriggerResponse : DeleteResponseBase 7 | { 8 | 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Version/DeleteVersionResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Aliyun.FunctionCompute.SDK.Response 5 | { 6 | public class DeleteVersionResponse : DeleteResponseBase 7 | { 8 | 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/AsyncConfig/DeleteFunctionAsyncConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Aliyun.FunctionCompute.SDK.Response 5 | { 6 | public class DeleteFunctionAsyncConfigResponse : DeleteResponseBase 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: csharp 2 | solution: Libraries/Aliyun.FunctionCompute.sln 3 | 4 | dotnet: 2.1 5 | 6 | script: 7 | - dotnet restore Libraries/Aliyun.FunctionCompute.sln 8 | - cd Libraries/src/Aliyun.FunctionCompute.SDK.Unittests 9 | - mkdir -p bin/Debug/netcoreapp2.1 10 | - cp hello.zip bin/Debug/netcoreapp2.1/hello.zip 11 | - dotnet test -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/IRequestBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Aliyun.FunctionCompute.SDK.Config; 3 | using RestSharp; 4 | 5 | namespace Aliyun.FunctionCompute.SDK.Request 6 | { 7 | public interface IRequestBase 8 | { 9 | string GetPath(); 10 | RestRequest GenHttpRequest(FCConfig cfg); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/IResponseBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Aliyun.FunctionCompute.SDK.Response 5 | { 6 | public interface IResponseBase 7 | { 8 | void SetStatusContent(string content, int status, byte[] rawBytes); 9 | void SetHeaders(Dictionary headers); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /samples/fc-csharp-sdk-samples/fc-csharp-sdk-samples.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.1 6 | fc_csharp_sdk_samples 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /samples/fc-code-samples/Events/TimerEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Newtonsoft.Json; 3 | 4 | namespace fc_code_samples.Events 5 | { 6 | public class TimerEvent 7 | { 8 | [JsonProperty("triggerTime")] 9 | public string TriggerTime { get; set; } 10 | 11 | [JsonProperty("triggerName")] 12 | public string TriggerName { get; set; } 13 | 14 | [JsonProperty("payload")] 15 | public string Payload { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Constants/HeaderKeys.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Aliyun.FunctionCompute.SDK.Constants 3 | { 4 | public static class HeaderKeys 5 | { 6 | public static readonly string REQUEST_ID = "X-Fc-Request-Id"; 7 | public static readonly string INVOCATION_TYPE = "X-Fc-Invocation-Type"; 8 | public static readonly string INVOCATION_LOG_TYPE = "X-Fc-Log-Type"; 9 | public static readonly string INVOCATION_LOG_RESULT = "X-Fc-Log-Result"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/model/InstanceMeta.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Newtonsoft.Json; 5 | 6 | namespace Aliyun.FunctionCompute.SDK.model 7 | { 8 | public class InstanceMeta 9 | { 10 | [JsonProperty("instanceId")] 11 | public string InstanceId { get; set; } 12 | 13 | [JsonProperty("versionId")] 14 | public string VersionId { get; set; } 15 | 16 | public InstanceMeta() { } 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/model/VersionMeta.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Newtonsoft.Json; 3 | 4 | namespace Aliyun.FunctionCompute.SDK.model 5 | { 6 | public class VersionMeta 7 | { 8 | [JsonProperty("versionId")] 9 | public string VersionId { get; set; } 10 | 11 | [JsonProperty("description")] 12 | public string Description { get; set; } 13 | 14 | 15 | [JsonProperty("createdTime")] 16 | public string CreatedTime { get; set; } 17 | 18 | [JsonProperty("lastModifiedTime")] 19 | public string LastModifiedTime { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /samples/fc-exec-samples/fc-exec-samples.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net6.0 6 | fc_exec_samples 7 | enable 8 | enable 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Utils/Helper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Aliyun.FunctionCompute.SDK.Utils 5 | { 6 | public static class Helper 7 | { 8 | 9 | public static Dictionary MergeDictionary(Dictionary first, Dictionary second) 10 | { 11 | if (first == null) first = new Dictionary(); 12 | if (second == null) return first; 13 | 14 | foreach (string key in second.Keys) 15 | { 16 | if (!first.ContainsKey(key)) 17 | first.Add(key, second[key]); 18 | } 19 | return first; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /samples/fc-code-samples/Events/MNSTopicEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace fc_code_samples.Events 3 | { 4 | // notifyContentFormat 为 JSON 5 | public class MNSTopicEvent 6 | { 7 | public string Context { get; set; } 8 | 9 | public string TopicOwner { get; set; } 10 | 11 | public string Message { get; set; } 12 | 13 | public string Subscriber { get; set; } 14 | 15 | public int PublishTime { get; set; } 16 | 17 | public string SubscriptionName { get; set; } 18 | 19 | public string MessageMD5 { get; set; } 20 | 21 | public string TopicName { get; set; } 22 | 23 | public string MessageId { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK.Unittests/Aliyun.FunctionCompute.SDK.Unittests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.1 5 | 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /samples/fc-code-samples/fc-code-samples.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.1 6 | fc_code_samples 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/model/ReservedCapacityMeta.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Newtonsoft.Json; 3 | 4 | namespace Aliyun.FunctionCompute.SDK.model 5 | { 6 | 7 | public class ReservedCapacityMeta 8 | { 9 | [JsonProperty("instanceId")] 10 | public string InstanceId { get; set; } 11 | 12 | [JsonProperty("cu")] 13 | public int CU { get; set; } 14 | 15 | [JsonProperty("deadline")] 16 | public string Deadline { get; set; } 17 | 18 | [JsonProperty("createdTime")] 19 | public string CreatedTime { get; set; } 20 | 21 | [JsonProperty("lastModifiedTime")] 22 | public string LastModifiedTime { get; set; } 23 | 24 | [JsonProperty("isRefunded")] 25 | public string IsRefunded { get; set; } 26 | 27 | public ReservedCapacityMeta() 28 | { 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/model/ProvisionMeta.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Newtonsoft.Json; 3 | 4 | namespace Aliyun.FunctionCompute.SDK.model 5 | { 6 | public class ProvisionMeta 7 | { 8 | [JsonProperty("target")] 9 | public int Target { get; set; } 10 | 11 | [JsonProperty("resource")] 12 | public string Resource { get; set; } 13 | 14 | public ProvisionMeta(){} 15 | } 16 | 17 | public class GetProvisionMeta : ProvisionMeta 18 | { 19 | [JsonProperty("current")] 20 | public string Current { get; set; } 21 | 22 | public GetProvisionMeta(){ } 23 | } 24 | 25 | public class ListProvisionMeta 26 | { 27 | [JsonProperty("nextToken")] 28 | public string NextToken { get; set; } 29 | 30 | [JsonProperty("provisionConfigs")] 31 | public GetProvisionMeta[] ProvisionConfigs { get; set; } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/model/TagMeta.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Newtonsoft.Json; 4 | 5 | namespace Aliyun.FunctionCompute.SDK.model 6 | { 7 | public class TagMeta 8 | { 9 | [JsonProperty("resourceArn")] 10 | public string ResourceArn { get; set; } 11 | 12 | [JsonProperty("tags")] 13 | public Dictionary Tags { get; set; } 14 | 15 | public TagMeta() { } 16 | 17 | public TagMeta(string resourceArn, Dictionary tags) 18 | { 19 | this.ResourceArn = resourceArn; 20 | this.Tags = tags; 21 | } 22 | } 23 | 24 | public class GetTagMeta : TagMeta 25 | { 26 | 27 | public GetTagMeta() 28 | { 29 | } 30 | 31 | public GetTagMeta(string resourceArn, Dictionary tags) : 32 | base(resourceArn,tags) 33 | { 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /samples/fc-code-samples/TableSoreEventHandler.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Text; 3 | using Aliyun.Serverless.Core; 4 | using Microsoft.Extensions.Logging; 5 | using PeterO.Cbor; 6 | 7 | // If I meet some problems, you use. Please use the Dahomey Cbor, refer: https://yq.aliyun.com/articles/739452?type=2 8 | namespace fc_code_samples { 9 | public class TableSoreEventHandler { 10 | public Stream Handler (Stream input, IFcContext context) { 11 | ILogger logger = context.Logger; 12 | logger.LogDebug (string.Format ("Handle request {0}", context.RequestId)); 13 | var cbor = CBORObject.Read (input); 14 | 15 | // do your things with cbor 16 | 17 | byte[] hello = Encoding.UTF8.GetBytes ("hello world"); 18 | MemoryStream output = new MemoryStream (); 19 | output.Write (hello, 0, hello.Length); 20 | output.Seek (0, SeekOrigin.Begin); 21 | return output; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/DeleteResponseBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Aliyun.FunctionCompute.SDK.Response 5 | { 6 | public class DeleteResponseBase : IResponseBase 7 | { 8 | public Dictionary Headers { get; set; } 9 | public string Content { get; set; } 10 | public int StatusCode { get; set; } 11 | 12 | public DeleteResponseBase() 13 | { 14 | this.Headers = new Dictionary { }; 15 | } 16 | 17 | public void SetStatusContent(string content, int status, byte[] rawBytes) 18 | { 19 | this.StatusCode = status; 20 | this.Content = content; 21 | } 22 | 23 | public void SetHeaders(Dictionary headers) 24 | { 25 | this.Headers = headers; 26 | } 27 | 28 | public string GetRequestID() 29 | { 30 | return this.Headers[Constants.HeaderKeys.REQUEST_ID].ToString(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Tag/TagResponseBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.model; 4 | using Newtonsoft.Json; 5 | 6 | namespace Aliyun.FunctionCompute.SDK.Response 7 | { 8 | public class TagResponseBase : IResponseBase 9 | { 10 | public string Content { get; set; } 11 | public int StatusCode { get; set; } 12 | public Dictionary Headers { get; set; } 13 | 14 | 15 | public TagResponseBase() 16 | { 17 | this.Headers = new Dictionary { }; 18 | } 19 | public void SetStatusContent(string content, int status, byte[] rawBytes) 20 | { 21 | this.StatusCode = status; 22 | this.Content = content; 23 | } 24 | 25 | public void SetHeaders(Dictionary headers) 26 | { 27 | this.Headers = headers; 28 | } 29 | 30 | public string GetRequestID() 31 | { 32 | return this.Headers[Constants.HeaderKeys.REQUEST_ID].ToString(); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Alibaba Cloud 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /samples/fc-code-samples/Events/LogEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Newtonsoft.Json; 3 | 4 | namespace fc_code_samples.Events 5 | { 6 | public class Source 7 | { 8 | [JsonProperty("endpoint")] 9 | public string Endpoint { get; set; } 10 | 11 | [JsonProperty("projectName")] 12 | public string ProjectName { get; set; } 13 | 14 | [JsonProperty("logstoreName")] 15 | public string LogstoreName { get; set; } 16 | 17 | [JsonProperty("shardId")] 18 | public int ShardId { get; set; } 19 | 20 | [JsonProperty("beginCursor")] 21 | public string BeginCursor { get; set; } 22 | 23 | [JsonProperty("endCursor")] 24 | public string EndCursor { get; set; } 25 | } 26 | 27 | public class LogEvent 28 | { 29 | 30 | [JsonProperty("parameter")] 31 | public object Parameter { get; set; } 32 | 33 | [JsonProperty("source")] 34 | public Source Source { get; set; } 35 | 36 | [JsonProperty("jsonName")] 37 | public string JobName { get; set; } 38 | 39 | [JsonProperty("taskId")] 40 | public string TaskId { get; set; } 41 | 42 | [JsonProperty("cursorTime ")] 43 | public int CursorTime { get; set; } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Aliyun.FunctionCompute.SDK.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Aliyun.FC.SDK.NetCore 5 | 1.1.4 6 | Aliyun Function Compute csharp sdk 7 | Aliyun FC team 8 | Aliyun FC team 9 | 10 | LICENSE 11 | https://github.com/aliyun/fc-csharp-sdk 12 | https://github.com/aliyun/fc-csharp-sdk/blob/master/fc.png 13 | false 14 | Aliyun Function Compute csharp sdk 15 | Aliyun Function Compute csharp sdk v1 version 16 | Copyright 2019 17 | FC serverless 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Function/GetFunctionCodeRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Constants; 5 | 6 | namespace Aliyun.FunctionCompute.SDK.Request 7 | { 8 | public class GetFunctionCodeRequest : GetFunctionRequest 9 | { 10 | public GetFunctionCodeRequest(string serviceName, string functionName, string qualifier = null, 11 | Dictionary customHeaders = null) : base(serviceName, functionName, qualifier, customHeaders) 12 | { 13 | Contract.Requires(string.IsNullOrEmpty(functionName) == false); 14 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 15 | 16 | } 17 | 18 | public override string GetPath() 19 | { 20 | if (string.IsNullOrEmpty(this.Qualifier)) 21 | { 22 | return string.Format(Const.FUNCTION_CODE_PATH, Const.API_VERSION, this.ServiceName, this.FunctionName); 23 | } 24 | else 25 | { 26 | return string.Format(Const.FUNCTION_CODE_WITH_QUALIFIER_PATH, Const.API_VERSION, this.ServiceName, this.Qualifier, this.FunctionName); 27 | } 28 | } 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Alias/AliasResponseBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.model; 4 | using Newtonsoft.Json; 5 | 6 | namespace Aliyun.FunctionCompute.SDK.Response 7 | { 8 | public class AliasResponseBase : IResponseBase 9 | { 10 | public string Content { get; set; } 11 | public int StatusCode { get; set; } 12 | public Dictionary Headers { get; set; } 13 | 14 | public AliasMeta Data { get; set; } 15 | 16 | public AliasResponseBase() 17 | { 18 | this.Data = new AliasMeta(); 19 | this.Headers = new Dictionary { }; 20 | } 21 | 22 | public void SetStatusContent(string content, int status, byte[] rawBytes) 23 | { 24 | this.StatusCode = status; 25 | this.Content = content; 26 | if (status < 300) 27 | this.Data = JsonConvert.DeserializeObject(this.Content); 28 | } 29 | 30 | public void SetHeaders(Dictionary headers) 31 | { 32 | this.Headers = headers; 33 | } 34 | 35 | public string GetRequestID() 36 | { 37 | return this.Headers[Constants.HeaderKeys.REQUEST_ID].ToString(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Service/ServerResponseBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.model; 4 | using Newtonsoft.Json; 5 | 6 | namespace Aliyun.FunctionCompute.SDK.Response 7 | { 8 | public class ServiceResponseBase : IResponseBase 9 | { 10 | public string Content { get; set; } 11 | public int StatusCode { get; set; } 12 | public Dictionary Headers { get; set; } 13 | public ServiceMeta Data { get; set; } 14 | 15 | public ServiceResponseBase() 16 | { 17 | this.Data = new ServiceMeta(); 18 | this.Headers = new Dictionary { }; 19 | } 20 | 21 | public void SetStatusContent(string content, int status, byte[] rawBytes) 22 | { 23 | this.StatusCode = status; 24 | this.Content = content; 25 | if(status < 300) 26 | this.Data = JsonConvert.DeserializeObject(this.Content); 27 | } 28 | 29 | public void SetHeaders(Dictionary headers) 30 | { 31 | this.Headers = headers; 32 | } 33 | 34 | public string GetRequestID() 35 | { 36 | return this.Headers[Constants.HeaderKeys.REQUEST_ID].ToString(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Trigger/TriggerResponseBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.model; 4 | using Newtonsoft.Json; 5 | 6 | namespace Aliyun.FunctionCompute.SDK.Response 7 | { 8 | public class TriggerResponseBase : IResponseBase 9 | { 10 | public string Content { get; set; } 11 | public int StatusCode { get; set; } 12 | public Dictionary Headers { get; set; } 13 | 14 | public TriggerMeta Data { get; set; } 15 | 16 | public TriggerResponseBase() 17 | { 18 | this.Data = new TriggerMeta(); 19 | this.Headers = new Dictionary { }; 20 | } 21 | 22 | public void SetStatusContent(string content, int status, byte[] rawBytes) 23 | { 24 | this.StatusCode = status; 25 | this.Content = content; 26 | if (status < 300) 27 | this.Data = JsonConvert.DeserializeObject(this.Content); 28 | } 29 | 30 | public void SetHeaders(Dictionary headers) 31 | { 32 | this.Headers = headers; 33 | } 34 | 35 | public string GetRequestID() 36 | { 37 | return this.Headers[Constants.HeaderKeys.REQUEST_ID].ToString(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Version/VersionReaponseBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.model; 4 | using Newtonsoft.Json; 5 | 6 | namespace Aliyun.FunctionCompute.SDK.Response 7 | { 8 | public class VersionResponseBase : IResponseBase 9 | { 10 | public string Content { get; set; } 11 | public int StatusCode { get; set; } 12 | public Dictionary Headers { get; set; } 13 | 14 | public VersionMeta Data { get; set; } 15 | 16 | public VersionResponseBase() 17 | { 18 | this.Data = new VersionMeta(); 19 | this.Headers = new Dictionary { }; 20 | } 21 | 22 | public void SetStatusContent(string content, int status, byte[] rawBytes) 23 | { 24 | this.StatusCode = status; 25 | this.Content = content; 26 | if (status < 300) 27 | this.Data = JsonConvert.DeserializeObject(this.Content); 28 | } 29 | 30 | public void SetHeaders(Dictionary headers) 31 | { 32 | this.Headers = headers; 33 | } 34 | 35 | public string GetRequestID() 36 | { 37 | return this.Headers[Constants.HeaderKeys.REQUEST_ID].ToString(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Function/FunctionResponseBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.model; 4 | using Newtonsoft.Json; 5 | 6 | namespace Aliyun.FunctionCompute.SDK.Response 7 | { 8 | public class FunctionResponseBase : IResponseBase 9 | { 10 | public string Content { get; set; } 11 | public int StatusCode { get; set; } 12 | public Dictionary Headers { get; set; } 13 | 14 | public FunctionMeta Data { get; set; } 15 | 16 | public FunctionResponseBase() 17 | { 18 | this.Data = new FunctionMeta(); 19 | this.Headers = new Dictionary { }; 20 | } 21 | 22 | public void SetStatusContent(string content, int status, byte[] rawBytes) 23 | { 24 | this.StatusCode = status; 25 | this.Content = content; 26 | if (status < 300) 27 | this.Data = JsonConvert.DeserializeObject(this.Content); 28 | } 29 | 30 | public void SetHeaders(Dictionary headers) 31 | { 32 | this.Headers = headers; 33 | } 34 | 35 | public string GetRequestID() 36 | { 37 | return this.Headers[Constants.HeaderKeys.REQUEST_ID].ToString(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Tag/GetResourceTagsResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.model; 4 | using Newtonsoft.Json; 5 | 6 | namespace Aliyun.FunctionCompute.SDK.Response 7 | { 8 | public class GetResourceTagsResponse : IResponseBase 9 | { 10 | public string Content { get; set; } 11 | public int StatusCode { get; set; } 12 | public Dictionary Headers { get; set; } 13 | public GetTagMeta Data { get; set; } 14 | 15 | public GetResourceTagsResponse() 16 | { 17 | this.Data = new GetTagMeta(); 18 | this.Headers = new Dictionary { }; 19 | } 20 | 21 | virtual public void SetStatusContent(string content, int status, byte[] rawBytes) 22 | { 23 | this.StatusCode = status; 24 | this.Content = content; 25 | if (status < 300) 26 | this.Data = JsonConvert.DeserializeObject(this.Content); 27 | } 28 | 29 | public void SetHeaders(Dictionary headers) 30 | { 31 | this.Headers = headers; 32 | } 33 | 34 | public string GetRequestID() 35 | { 36 | return this.Headers[Constants.HeaderKeys.REQUEST_ID].ToString(); 37 | } 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Provision/PutProvisionConfigResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.model; 4 | using Newtonsoft.Json; 5 | 6 | namespace Aliyun.FunctionCompute.SDK.Response 7 | { 8 | 9 | public class PutProvisionConfigResponse : IResponseBase 10 | { 11 | public string Content { get; set; } 12 | public int StatusCode { get; set; } 13 | public Dictionary Headers { get; set; } 14 | 15 | public ProvisionMeta Data { get; set; } 16 | 17 | public PutProvisionConfigResponse() 18 | { 19 | this.Data = new ProvisionMeta(); 20 | this.Headers = new Dictionary { }; 21 | } 22 | public void SetStatusContent(string content, int status, byte[] rawBytes) 23 | { 24 | this.StatusCode = status; 25 | this.Content = content; 26 | if (status < 300) 27 | this.Data = JsonConvert.DeserializeObject(this.Content); 28 | } 29 | 30 | public void SetHeaders(Dictionary headers) 31 | { 32 | this.Headers = headers; 33 | } 34 | 35 | public string GetRequestID() 36 | { 37 | return this.Headers[Constants.HeaderKeys.REQUEST_ID].ToString(); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/CustomDomain/CustomDomainResponseBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.model; 4 | using Newtonsoft.Json; 5 | 6 | namespace Aliyun.FunctionCompute.SDK.Response 7 | { 8 | public class CustomDomainResponseBase : IResponseBase 9 | { 10 | public string Content { get; set; } 11 | public int StatusCode { get; set; } 12 | public Dictionary Headers { get; set; } 13 | 14 | public CustomDomainMeta Data { get; set; } 15 | 16 | public CustomDomainResponseBase() 17 | { 18 | this.Data = new CustomDomainMeta(); 19 | this.Headers = new Dictionary { }; 20 | } 21 | 22 | public void SetStatusContent(string content, int status, byte[] rawBytes) 23 | { 24 | this.StatusCode = status; 25 | this.Content = content; 26 | if (status < 300) 27 | this.Data = JsonConvert.DeserializeObject(this.Content); 28 | } 29 | 30 | public void SetHeaders(Dictionary headers) 31 | { 32 | this.Headers = headers; 33 | } 34 | 35 | public string GetRequestID() 36 | { 37 | return this.Headers[Constants.HeaderKeys.REQUEST_ID].ToString(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Provision/GetProvisionConfigResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.model; 4 | using Newtonsoft.Json; 5 | 6 | namespace Aliyun.FunctionCompute.SDK.Response 7 | { 8 | 9 | public class GetProvisionConfigResponse : IResponseBase 10 | { 11 | public string Content { get; set; } 12 | public int StatusCode { get; set; } 13 | public Dictionary Headers { get; set; } 14 | 15 | public GetProvisionMeta Data { get; set; } 16 | 17 | public GetProvisionConfigResponse() 18 | { 19 | this.Data = new GetProvisionMeta(); 20 | this.Headers = new Dictionary { }; 21 | } 22 | public void SetStatusContent(string content, int status, byte[] rawBytes) 23 | { 24 | this.StatusCode = status; 25 | this.Content = content; 26 | if (status < 300) 27 | this.Data = JsonConvert.DeserializeObject(this.Content); 28 | } 29 | 30 | public void SetHeaders(Dictionary headers) 31 | { 32 | this.Headers = headers; 33 | } 34 | 35 | public string GetRequestID() 36 | { 37 | return this.Headers[Constants.HeaderKeys.REQUEST_ID].ToString(); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Provision/ListProvisionConfigsResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.model; 4 | using Newtonsoft.Json; 5 | 6 | namespace Aliyun.FunctionCompute.SDK.Response 7 | { 8 | 9 | public class ListProvisionConfigsResponse : IResponseBase 10 | { 11 | public string Content { get; set; } 12 | public int StatusCode { get; set; } 13 | public Dictionary Headers { get; set; } 14 | 15 | public ListProvisionMeta Data { get; set; } 16 | 17 | public ListProvisionConfigsResponse() 18 | { 19 | this.Data = new ListProvisionMeta(); 20 | this.Headers = new Dictionary { }; 21 | } 22 | public void SetStatusContent(string content, int status, byte[] rawBytes) 23 | { 24 | this.StatusCode = status; 25 | this.Content = content; 26 | if (status < 300) 27 | this.Data = JsonConvert.DeserializeObject(this.Content); 28 | } 29 | 30 | public void SetHeaders(Dictionary headers) 31 | { 32 | this.Headers = headers; 33 | } 34 | 35 | public string GetRequestID() 36 | { 37 | return this.Headers[Constants.HeaderKeys.REQUEST_ID].ToString(); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/AsyncConfig/GetFunctionAsyncConfigResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.model; 4 | using Newtonsoft.Json; 5 | 6 | namespace Aliyun.FunctionCompute.SDK.Response 7 | { 8 | 9 | public class GetFunctionAsyncConfigResponse : IResponseBase 10 | { 11 | public string Content { get; set; } 12 | public int StatusCode { get; set; } 13 | public Dictionary Headers { get; set; } 14 | 15 | public FunctionAsyncConfigMeta Data { get; set; } 16 | 17 | public GetFunctionAsyncConfigResponse() 18 | { 19 | this.Data = new FunctionAsyncConfigMeta(); 20 | this.Headers = new Dictionary { }; 21 | } 22 | public void SetStatusContent(string content, int status, byte[] rawBytes) 23 | { 24 | this.StatusCode = status; 25 | this.Content = content; 26 | if (status < 300) 27 | this.Data = JsonConvert.DeserializeObject(this.Content); 28 | } 29 | 30 | public void SetHeaders(Dictionary headers) 31 | { 32 | this.Headers = headers; 33 | } 34 | 35 | public string GetRequestID() 36 | { 37 | return this.Headers[Constants.HeaderKeys.REQUEST_ID].ToString(); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/AsyncConfig/PutFunctionAsyncConfigResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.model; 4 | using Newtonsoft.Json; 5 | 6 | namespace Aliyun.FunctionCompute.SDK.Response 7 | { 8 | 9 | public class PutFunctionAsyncConfigResponse : IResponseBase 10 | { 11 | public string Content { get; set; } 12 | public int StatusCode { get; set; } 13 | public Dictionary Headers { get; set; } 14 | 15 | public FunctionAsyncConfigMeta Data { get; set; } 16 | 17 | public PutFunctionAsyncConfigResponse() 18 | { 19 | this.Data = new FunctionAsyncConfigMeta(); 20 | this.Headers = new Dictionary { }; 21 | } 22 | public void SetStatusContent(string content, int status, byte[] rawBytes) 23 | { 24 | this.StatusCode = status; 25 | this.Content = content; 26 | if (status < 300) 27 | this.Data = JsonConvert.DeserializeObject(this.Content); 28 | } 29 | 30 | public void SetHeaders(Dictionary headers) 31 | { 32 | this.Headers = headers; 33 | } 34 | 35 | public string GetRequestID() 36 | { 37 | return this.Headers[Constants.HeaderKeys.REQUEST_ID].ToString(); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/AsyncConfig/ListFunctionAsyncConfigResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.model; 4 | using Newtonsoft.Json; 5 | 6 | namespace Aliyun.FunctionCompute.SDK.Response 7 | { 8 | 9 | public class ListFunctionAsyncConfigsResponse : IResponseBase 10 | { 11 | public string Content { get; set; } 12 | public int StatusCode { get; set; } 13 | public Dictionary Headers { get; set; } 14 | 15 | public ListFunctionAsyncConfigsMeta Data { get; set; } 16 | 17 | public ListFunctionAsyncConfigsResponse() 18 | { 19 | this.Data = new ListFunctionAsyncConfigsMeta(); 20 | this.Headers = new Dictionary { }; 21 | } 22 | public void SetStatusContent(string content, int status, byte[] rawBytes) 23 | { 24 | this.StatusCode = status; 25 | this.Content = content; 26 | if (status < 300) 27 | this.Data = JsonConvert.DeserializeObject(this.Content); 28 | } 29 | 30 | public void SetHeaders(Dictionary headers) 31 | { 32 | this.Headers = headers; 33 | } 34 | 35 | public string GetRequestID() 36 | { 37 | return this.Headers[Constants.HeaderKeys.REQUEST_ID].ToString(); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /samples/fc-code-samples/OSSEventHandler.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using Aliyun.Serverless.Core; 3 | using Microsoft.Extensions.Logging; 4 | using Newtonsoft.Json; 5 | using fc_code_samples.Events; 6 | 7 | namespace fc_code_samples 8 | { 9 | public class OssEventHandler 10 | { 11 | public Stream Handler(Stream input, IFcContext context) 12 | { 13 | ILogger logger = context.Logger; 14 | logger.LogDebug(string.Format("Handle request {0}", context.RequestId)); 15 | string data = new StreamReader(input).ReadToEnd(); 16 | OSSEvent ossEvent = JsonConvert.DeserializeObject(data); 17 | return HandlePoco(ossEvent, context); 18 | } 19 | 20 | public Stream HandlePoco(OSSEvent ossEvent, IFcContext context) 21 | { 22 | MemoryStream output = new MemoryStream(); 23 | StreamWriter writer = new StreamWriter(output); 24 | foreach (OSSEvent.Event evnt in ossEvent.events) 25 | { 26 | writer.Write(string.Format("received {0} from {1} @ {2}", evnt.eventName, evnt.eventSource, evnt.region)); 27 | writer.Write(string.Format("received bucket {0}", evnt.oss.bucket.arn)); 28 | writer.Write(string.Format("received object {0} and it's size is {1}", evnt.oss.obj.key, evnt.oss.obj.size)); 29 | } 30 | writer.Flush(); 31 | 32 | return output; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK.Unittests/ReservedCapacityTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.Request; 4 | using Aliyun.FunctionCompute.SDK.Response; 5 | using Xunit; 6 | 7 | namespace Aliyun.FunctionCompute.SDK.Unittests 8 | { 9 | [Collection("fcDotnet.Unittests")] 10 | public class ReservedCapacityUnitTests : IDisposable 11 | { 12 | readonly TestConfig tf = new TestConfig(); 13 | 14 | public void Dispose() 15 | { 16 | Console.WriteLine("ReservedCapacityUnitTests TearDownBase ....."); 17 | } 18 | 19 | [Fact] 20 | public void TestListReservedCapacities() 21 | { 22 | var response = tf.Client.ListReservedCapacities(new ListReservedCapacitiesRequest(5)); 23 | Assert.True(response.Data.ReservedCapacities.GetLength(0)<=5); 24 | 25 | for (int i = 0; i < response.Data.ReservedCapacities.GetLength(0); i++) 26 | { 27 | Assert.Equal(22, response.Data.ReservedCapacities[i].InstanceId.Length); 28 | Assert.True(response.Data.ReservedCapacities[i].CU > 0); 29 | Assert.NotNull(response.Data.ReservedCapacities[i].LastModifiedTime); 30 | Assert.NotNull(response.Data.ReservedCapacities[i].IsRefunded); 31 | Assert.True(response.Data.ReservedCapacities[i].Deadline.CompareTo(response.Data.ReservedCapacities[i].CreatedTime) > 0); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/CustomDomain/GetCustomDomainRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Config; 5 | using Aliyun.FunctionCompute.SDK.Constants; 6 | using RestSharp; 7 | 8 | namespace Aliyun.FunctionCompute.SDK.Request 9 | { 10 | public class GetCustomDomainRequest : RequestBase, IRequestBase 11 | { 12 | 13 | public object DomainName { get; set; } 14 | public Dictionary Headers { get; set; } 15 | 16 | public GetCustomDomainRequest(string domainName, Dictionary customHeaders = null) 17 | { 18 | Contract.Requires(string.IsNullOrEmpty(domainName) == false); 19 | this.DomainName = domainName; 20 | this.Headers = customHeaders; 21 | } 22 | 23 | public virtual string GetPath() 24 | { 25 | return string.Format(Const.SINGLE_CUSTOM_DOMAIN_PATH, Const.API_VERSION, this.DomainName); 26 | } 27 | 28 | public RestRequest GenHttpRequest(FCConfig cfg) 29 | { 30 | this.Config = cfg; 31 | this.Headers = this.BuildCommonHeaders("GET", this.GetPath(), this.Headers); 32 | var request = new RestRequest(this.GetPath(), Method.GET); 33 | 34 | foreach (var item in this.Headers) 35 | request.AddHeader(item.Key, item.Value); 36 | 37 | return request; 38 | 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Tag/TagResourceRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.Config; 4 | using Aliyun.FunctionCompute.SDK.Constants; 5 | using Newtonsoft.Json; 6 | using RestSharp; 7 | using Aliyun.FunctionCompute.SDK.model; 8 | 9 | namespace Aliyun.FunctionCompute.SDK.Request 10 | { 11 | public class TagResourceRequest : RequestBase, IRequestBase 12 | { 13 | public Dictionary Headers { get; set; } 14 | public TagMeta TagMeta { get; set; } 15 | 16 | public TagResourceRequest(string resourceArn, Dictionary tags, Dictionary customHeaders = null) 17 | { 18 | this.Headers = customHeaders; 19 | this.TagMeta = new TagMeta(resourceArn, tags); 20 | } 21 | 22 | public string GetPath() 23 | { 24 | return string.Format(Const.TAG_PATH, Const.API_VERSION); 25 | } 26 | 27 | public RestRequest GenHttpRequest(FCConfig cfg) 28 | { 29 | this.Config = cfg; 30 | this.Headers = this.BuildCommonHeaders("POST", this.GetPath(), this.Headers); 31 | var request = new RestRequest(this.GetPath(), Method.POST); 32 | 33 | foreach (var item in this.Headers) 34 | request.AddHeader(item.Key, item.Value); 35 | 36 | request.AddJsonBody(JsonConvert.SerializeObject(this.TagMeta)); 37 | 38 | return request; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Service/DeleteServiceRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Auth; 5 | using Aliyun.FunctionCompute.SDK.Config; 6 | using Aliyun.FunctionCompute.SDK.Constants; 7 | using RestSharp; 8 | 9 | namespace Aliyun.FunctionCompute.SDK.Request 10 | { 11 | public class DeleteServiceRequest : RequestBase, IRequestBase 12 | { 13 | public string ServiceName { get; set; } 14 | public Dictionary Headers { get; set; } 15 | 16 | public DeleteServiceRequest(string serviceName, Dictionary customHeaders = null) 17 | { 18 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 19 | this.ServiceName = serviceName; 20 | this.Headers = customHeaders; 21 | } 22 | 23 | public string GetPath() 24 | { 25 | return string.Format(Const.SINGLE_SERVICE_PATH, Const.API_VERSION, this.ServiceName); 26 | } 27 | 28 | public RestRequest GenHttpRequest(FCConfig cfg) 29 | { 30 | this.Config = cfg; 31 | this.Headers = this.BuildCommonHeaders("DELETE", this.GetPath(), this.Headers); 32 | var request = new RestRequest(this.GetPath(), Method.DELETE); 33 | 34 | foreach (var item in this.Headers) 35 | request.AddHeader(item.Key, item.Value); 36 | 37 | return request; 38 | 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/CustomDomain/DeleteCustomDomainRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Auth; 5 | using Aliyun.FunctionCompute.SDK.Config; 6 | using Aliyun.FunctionCompute.SDK.Constants; 7 | using RestSharp; 8 | 9 | namespace Aliyun.FunctionCompute.SDK.Request 10 | { 11 | public class DeleteCustomDomainRequest : RequestBase, IRequestBase 12 | { 13 | public Dictionary Headers { get; set; } 14 | public object DomainName { get; set; } 15 | 16 | public DeleteCustomDomainRequest(string domainName, Dictionary customHeaders = null) 17 | { 18 | Contract.Requires(string.IsNullOrEmpty(domainName) == false); 19 | this.DomainName = domainName; 20 | this.Headers = customHeaders; 21 | } 22 | 23 | public string GetPath() 24 | { 25 | return string.Format(Const.SINGLE_CUSTOM_DOMAIN_PATH, Const.API_VERSION, this.DomainName); 26 | } 27 | 28 | public RestRequest GenHttpRequest(FCConfig cfg) 29 | { 30 | this.Config = cfg; 31 | this.Headers = this.BuildCommonHeaders("DELETE", this.GetPath(), this.Headers); 32 | var request = new RestRequest(this.GetPath(), Method.DELETE); 33 | 34 | foreach (var item in this.Headers) 35 | request.AddHeader(item.Key, item.Value); 36 | 37 | return request; 38 | 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Function/GetFunctionCodeResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Newtonsoft.Json; 4 | 5 | namespace Aliyun.FunctionCompute.SDK.Response 6 | { 7 | public class FunctionCodeMeta 8 | { 9 | [JsonProperty("url")] 10 | public string Url { get; set; } 11 | 12 | [JsonProperty("checksum")] 13 | public string Checksum { get; set; } 14 | } 15 | 16 | public class GetFunctionCodeResponse : IResponseBase 17 | { 18 | public string Content { get; set; } 19 | public Dictionary Headers { get; set; } 20 | public int StatusCode { get; set; } 21 | 22 | public FunctionCodeMeta Data { get; set; } 23 | 24 | public GetFunctionCodeResponse() 25 | { 26 | this.Data = new FunctionCodeMeta(); 27 | this.Headers = new Dictionary { }; 28 | } 29 | 30 | public void SetStatusContent(string content, int status, byte[] rawBytes) 31 | { 32 | this.StatusCode = status; 33 | this.Content = content; 34 | this.Content.Replace(@"\u0026", "&"); 35 | if (status < 300) 36 | this.Data = JsonConvert.DeserializeObject(this.Content); 37 | } 38 | 39 | public void SetHeaders(Dictionary headers) 40 | { 41 | this.Headers = headers; 42 | } 43 | 44 | public string GetRequestID() 45 | { 46 | return this.Headers[Constants.HeaderKeys.REQUEST_ID].ToString(); 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Tag/GetResourceTagsRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Config; 5 | using Aliyun.FunctionCompute.SDK.Constants; 6 | using RestSharp; 7 | 8 | namespace Aliyun.FunctionCompute.SDK.Request 9 | { 10 | public class GetResourceTagsRequest : RequestBase, IRequestBase 11 | { 12 | 13 | public string ResourceArn { get; set; } 14 | public Dictionary Headers { get; set; } 15 | 16 | public GetResourceTagsRequest(string resourceArn, Dictionary customHeaders = null) 17 | { 18 | if (string.IsNullOrWhiteSpace(resourceArn)) 19 | { 20 | throw new ArgumentException("message", nameof(resourceArn)); 21 | } 22 | 23 | this.ResourceArn = resourceArn; 24 | this.Headers = customHeaders; 25 | } 26 | 27 | public string GetPath() 28 | { 29 | return string.Format(Const.TAG_PATH, Const.API_VERSION); 30 | } 31 | 32 | public RestRequest GenHttpRequest(FCConfig cfg) 33 | { 34 | this.Config = cfg; 35 | this.Headers = this.BuildCommonHeaders("GET", this.GetPath(), this.Headers); 36 | var request = new RestRequest(this.GetPath(), Method.GET); 37 | 38 | request.AddQueryParameter("resourceArn", this.ResourceArn); 39 | foreach (var item in this.Headers) 40 | request.AddHeader(item.Key, item.Value); 41 | 42 | return request; 43 | 44 | } 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Trigger/ListTriggersResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.model; 4 | using Newtonsoft.Json; 5 | 6 | namespace Aliyun.FunctionCompute.SDK.Response 7 | { 8 | 9 | public class TriggersResponseData 10 | { 11 | public TriggersResponseData() 12 | { 13 | this.Triggers = new TriggerMeta[] { }; 14 | this.NextToken = null; 15 | } 16 | 17 | [JsonProperty("triggers")] 18 | public TriggerMeta[] Triggers { get; set; } 19 | 20 | [JsonProperty("nextToken")] 21 | public string NextToken { get; set; } 22 | } 23 | 24 | public class ListTriggersResponse : IResponseBase 25 | { 26 | public string Content { get; set; } 27 | public Dictionary Headers { get; set; } 28 | public int StatusCode { get; set; } 29 | 30 | public TriggersResponseData Data { get; set; } 31 | 32 | public ListTriggersResponse() 33 | { 34 | this.Data = new TriggersResponseData(); 35 | this.Headers = new Dictionary { }; 36 | } 37 | 38 | public void SetStatusContent(string content, int status, byte[] rawBytes) 39 | { 40 | this.StatusCode = status; 41 | this.Content = content; 42 | if(status < 300) 43 | this.Data = JsonConvert.DeserializeObject(this.Content); 44 | } 45 | 46 | public void SetHeaders(Dictionary headers) 47 | { 48 | this.Headers = headers; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Alias/GetAliasRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Config; 5 | using Aliyun.FunctionCompute.SDK.Constants; 6 | using RestSharp; 7 | 8 | namespace Aliyun.FunctionCompute.SDK.Request 9 | { 10 | public class GetAliasRequest : RequestBase, IRequestBase 11 | { 12 | 13 | public string ServiceName { get; set; } 14 | public string AliasName { get; set; } 15 | public Dictionary Headers { get; set; } 16 | 17 | public GetAliasRequest(string serviceName, string aliasName,Dictionary customHeaders = null) 18 | { 19 | Contract.Requires(string.IsNullOrEmpty(aliasName) == false); 20 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 21 | this.ServiceName = serviceName; 22 | this.AliasName = aliasName; 23 | this.Headers = customHeaders; 24 | } 25 | 26 | public virtual string GetPath() 27 | { 28 | return string.Format(Const.SINGLE_ALIAS_PATH, Const.API_VERSION, this.ServiceName, this.AliasName); 29 | } 30 | 31 | public RestRequest GenHttpRequest(FCConfig cfg) 32 | { 33 | this.Config = cfg; 34 | this.Headers = this.BuildCommonHeaders("GET", this.GetPath(), this.Headers); 35 | var request = new RestRequest(this.GetPath(), Method.GET); 36 | 37 | foreach (var item in this.Headers) 38 | request.AddHeader(item.Key, item.Value); 39 | 40 | return request; 41 | 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Instance/ListInstancesResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.model; 4 | using Newtonsoft.Json; 5 | 6 | namespace Aliyun.FunctionCompute.SDK.Response 7 | { 8 | 9 | public class InstancesResponseData 10 | { 11 | public InstancesResponseData() 12 | { 13 | this.Instances = new InstanceMeta[] { }; 14 | } 15 | 16 | [JsonProperty("instances")] 17 | public InstanceMeta[] Instances { get; set; } 18 | 19 | } 20 | 21 | public class ListInstancesResponse : IResponseBase 22 | { 23 | public string Content { get; set; } 24 | public Dictionary Headers { get; set; } 25 | public int StatusCode { get; set; } 26 | 27 | public InstancesResponseData Data { get; set; } 28 | 29 | public ListInstancesResponse() 30 | { 31 | this.Data = new InstancesResponseData(); 32 | this.Headers = new Dictionary { }; 33 | } 34 | 35 | public void SetStatusContent(string content, int status, byte[] rawBytes) 36 | { 37 | this.StatusCode = status; 38 | this.Content = content; 39 | if (status < 300) 40 | this.Data = JsonConvert.DeserializeObject(this.Content); 41 | } 42 | 43 | public void SetHeaders(Dictionary headers) 44 | { 45 | this.Headers = headers; 46 | } 47 | 48 | public string GetRequestID() 49 | { 50 | return this.Headers[Constants.HeaderKeys.REQUEST_ID].ToString(); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Alias/DeleteAliasRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Auth; 5 | using Aliyun.FunctionCompute.SDK.Config; 6 | using Aliyun.FunctionCompute.SDK.Constants; 7 | using RestSharp; 8 | 9 | namespace Aliyun.FunctionCompute.SDK.Request 10 | { 11 | public class DeleteAliasRequest : RequestBase, IRequestBase 12 | { 13 | public string ServiceName { get; set; } 14 | public string AliasName { get; set; } 15 | public Dictionary Headers { get; set; } 16 | 17 | public DeleteAliasRequest(string serviceName, string aliasName, Dictionary customHeaders = null) 18 | { 19 | Contract.Requires(string.IsNullOrEmpty(aliasName) == false); 20 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 21 | this.ServiceName = serviceName; 22 | this.AliasName = aliasName; 23 | this.Headers = customHeaders; 24 | } 25 | 26 | public string GetPath() 27 | { 28 | return string.Format(Const.SINGLE_ALIAS_PATH, Const.API_VERSION, this.ServiceName, this.AliasName); 29 | } 30 | 31 | public RestRequest GenHttpRequest(FCConfig cfg) 32 | { 33 | this.Config = cfg; 34 | this.Headers = this.BuildCommonHeaders("DELETE", this.GetPath(), this.Headers); 35 | var request = new RestRequest(this.GetPath(), Method.DELETE); 36 | 37 | foreach (var item in this.Headers) 38 | request.AddHeader(item.Key, item.Value); 39 | 40 | return request; 41 | 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Function/DeleteFunctionRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Auth; 5 | using Aliyun.FunctionCompute.SDK.Config; 6 | using Aliyun.FunctionCompute.SDK.Constants; 7 | using RestSharp; 8 | 9 | namespace Aliyun.FunctionCompute.SDK.Request 10 | { 11 | public class DeleteFunctionRequest : RequestBase 12 | { 13 | public string ServiceName { get; set; } 14 | public string FunctionName { get; set; } 15 | public Dictionary Headers { get; set; } 16 | 17 | public DeleteFunctionRequest(string serviceName, string functionName, Dictionary customHeaders = null) 18 | { 19 | Contract.Requires(string.IsNullOrEmpty(functionName) == false); 20 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 21 | this.ServiceName = serviceName; 22 | this.FunctionName = functionName; 23 | this.Headers = customHeaders; 24 | } 25 | 26 | public string GetPath() 27 | { 28 | return string.Format(Const.SINGLE_FUNCTION_PATH, Const.API_VERSION, this.ServiceName, this.FunctionName); 29 | } 30 | 31 | public RestRequest GenHttpRequest(FCConfig cfg) 32 | { 33 | this.Config = cfg; 34 | this.Headers = this.BuildCommonHeaders("DELETE", this.GetPath(), this.Headers); 35 | var request = new RestRequest(this.GetPath(), Method.DELETE); 36 | 37 | foreach (var item in this.Headers) 38 | request.AddHeader(item.Key, item.Value); 39 | 40 | return request; 41 | 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Version/DeleteVersionRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Auth; 5 | using Aliyun.FunctionCompute.SDK.Config; 6 | using Aliyun.FunctionCompute.SDK.Constants; 7 | using RestSharp; 8 | 9 | namespace Aliyun.FunctionCompute.SDK.Request 10 | { 11 | public class DeleteVersionRequest : RequestBase, IRequestBase 12 | { 13 | public string ServiceName { get; set; } 14 | public string VersionID { get; set; } 15 | 16 | public Dictionary Headers { get; set; } 17 | 18 | 19 | public DeleteVersionRequest(string serviceName, string versionID, Dictionary customHeaders = null) 20 | { 21 | Contract.Requires(string.IsNullOrEmpty(versionID) == false); 22 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 23 | this.ServiceName = serviceName; 24 | this.VersionID = versionID; 25 | this.Headers = customHeaders; 26 | } 27 | 28 | public string GetPath() 29 | { 30 | return string.Format(Const.SINGLE_VERSION_PATH, Const.API_VERSION, this.ServiceName, this.VersionID); 31 | } 32 | 33 | public RestRequest GenHttpRequest(FCConfig cfg) 34 | { 35 | this.Config = cfg; 36 | this.Headers = this.BuildCommonHeaders("DELETE", this.GetPath(), this.Headers); 37 | var request = new RestRequest(this.GetPath(), Method.DELETE); 38 | 39 | foreach (var item in this.Headers) 40 | request.AddHeader(item.Key, item.Value); 41 | 42 | return request; 43 | 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/ReservedCapacity/ListReservedCapacitiesRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Config; 5 | using Aliyun.FunctionCompute.SDK.Constants; 6 | using RestSharp; 7 | 8 | namespace Aliyun.FunctionCompute.SDK.Request 9 | { 10 | public class ListReservedCapacitiesRequest : RequestBase, IRequestBase 11 | { 12 | public string NextToken { get; set; } 13 | public int Limit { get; set; } 14 | 15 | public Dictionary Headers { get; set; } 16 | 17 | public ListReservedCapacitiesRequest(int limit = 0, string nextToken = null, Dictionary reservedCapacityHeaders = null) 18 | { 19 | this.Limit = limit; 20 | this.NextToken = nextToken; 21 | this.Headers = reservedCapacityHeaders; 22 | } 23 | 24 | public string GetPath() 25 | { 26 | return string.Format(Const.RESERVED_CAPACITY_PATH, Const.API_VERSION); 27 | } 28 | 29 | public RestRequest GenHttpRequest(FCConfig cfg) 30 | { 31 | this.Config = cfg; 32 | this.Headers = this.BuildCommonHeaders("GET", this.GetPath(), this.Headers); 33 | var request = new RestRequest(this.GetPath(), Method.GET); 34 | 35 | foreach (var item in this.Headers) 36 | request.AddHeader(item.Key, item.Value); 37 | 38 | if (this.Limit > 0) request.AddQueryParameter("limit", this.Limit.ToString()); 39 | if (!string.IsNullOrEmpty(this.NextToken)) request.AddQueryParameter("nextToken", this.NextToken); 40 | 41 | return request; 42 | } 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/RequestBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.Auth; 4 | using Aliyun.FunctionCompute.SDK.Config; 5 | using Aliyun.FunctionCompute.SDK.Utils; 6 | using RestSharp; 7 | 8 | namespace Aliyun.FunctionCompute.SDK.Request 9 | { 10 | public class RequestBase 11 | { 12 | public static Authentication Auth { get; set; } 13 | 14 | private FCConfig config; 15 | 16 | public FCConfig Config 17 | { 18 | get { return config; } 19 | set 20 | { 21 | if (value != config) Auth = new Authentication(value); 22 | config = value; 23 | } 24 | } 25 | 26 | protected Dictionary BuildCommonHeaders(string method, string path, Dictionary customHeaders = null, Dictionary unescapedQueries = null) 27 | { 28 | Dictionary headers = new Dictionary { 29 | { "host", this.Config.Host}, 30 | { "date", DateTime.Now.ToUniversalTime().ToString("r")}, 31 | { "content-type", "application/json"}, 32 | { "content-length", "0"}, 33 | { "user-agent", this.Config.UserAgent}, 34 | }; 35 | 36 | if (this.Config.SecurityToken != "") 37 | headers.Add("x-fc-security-token", this.Config.SecurityToken); 38 | 39 | if (customHeaders != null) 40 | headers = Helper.MergeDictionary(headers, customHeaders); 41 | 42 | headers.Add("authorization", Auth.SignRequest(method, path, headers, unescapedQueries)); 43 | 44 | return headers; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Provision/GetProvisionConfigRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.Config; 4 | using Aliyun.FunctionCompute.SDK.Constants; 5 | using Newtonsoft.Json; 6 | using RestSharp; 7 | using Aliyun.FunctionCompute.SDK.model; 8 | 9 | namespace Aliyun.FunctionCompute.SDK.Request 10 | { 11 | public class GetProvisionConfigRequest : RequestBase, IRequestBase 12 | { 13 | public Dictionary Headers { get; set; } 14 | public string ServiceName { get; set; } 15 | public string Qualifier { get; set; } 16 | public string FunctionName { get; set; } 17 | 18 | 19 | 20 | public GetProvisionConfigRequest(string serviceName, string qualifier, string functionName, Dictionary customHeaders = null) 21 | { 22 | this.ServiceName = serviceName; 23 | this.Qualifier = qualifier; 24 | this.FunctionName = functionName; 25 | this.Headers = customHeaders; 26 | } 27 | 28 | public string GetPath() 29 | { 30 | return string.Format(Const.SINGLE_PROVISION_CONFIG_PATH, Const.API_VERSION, 31 | this.ServiceName, this.Qualifier, this.FunctionName); 32 | } 33 | 34 | public RestRequest GenHttpRequest(FCConfig cfg) 35 | { 36 | this.Config = cfg; 37 | this.Headers = this.BuildCommonHeaders("GET", this.GetPath(), this.Headers); 38 | var request = new RestRequest(this.GetPath(), Method.GET); 39 | 40 | foreach (var item in this.Headers) 41 | request.AddHeader(item.Key, item.Value); 42 | 43 | 44 | return request; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Function/InvokeFunctionResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.model; 4 | using Newtonsoft.Json; 5 | 6 | namespace Aliyun.FunctionCompute.SDK.Response 7 | { 8 | public class InvokeFunctionResponse : IResponseBase 9 | { 10 | /// 11 | /// Gets or sets the content. 12 | /// Invoke function string result 13 | /// 14 | /// The content. 15 | public string Content { get; set; } 16 | public int StatusCode { get; set; } 17 | public Dictionary Headers { get; set; } 18 | 19 | /// 20 | /// Gets or sets the data. 21 | /// Invoke function byte[] result 22 | /// 23 | /// The data. 24 | public byte[] Data { get; set; } 25 | 26 | public InvokeFunctionResponse() 27 | { 28 | this.Data = new byte[] { }; 29 | this.Headers = new Dictionary { }; 30 | } 31 | 32 | public void SetStatusContent(string content, int status, byte[] rawBytes) 33 | { 34 | this.StatusCode = status; 35 | this.Content = content; 36 | this.Data = rawBytes; 37 | } 38 | 39 | public void SetHeaders(Dictionary headers) 40 | { 41 | this.Headers = headers; 42 | } 43 | 44 | public string GetRequestID() 45 | { 46 | if (!this.Headers.ContainsKey(Constants.HeaderKeys.REQUEST_ID)) 47 | { 48 | return ""; 49 | } 50 | return this.Headers[Constants.HeaderKeys.REQUEST_ID].ToString(); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/model/AliasMeta.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Newtonsoft.Json; 4 | 5 | namespace Aliyun.FunctionCompute.SDK.model 6 | { 7 | public class UpdateAliasMeta 8 | { 9 | [JsonProperty("versionId")] 10 | public string VersionId { get; set; } 11 | 12 | [JsonProperty("description")] 13 | public string Description { get; set; } 14 | 15 | [JsonProperty("additionalVersionWeight")] 16 | public Dictionary AdditionalVersionWeight { get; set; } 17 | 18 | 19 | public UpdateAliasMeta(string versionId, string description = null, Dictionary additionalVersionWeight = null) 20 | { 21 | this.VersionId = versionId; 22 | this.Description = description; 23 | this.AdditionalVersionWeight = additionalVersionWeight; 24 | } 25 | 26 | public UpdateAliasMeta() { } 27 | } 28 | 29 | public class CreateAliasMeta : UpdateAliasMeta 30 | { 31 | 32 | [JsonProperty("aliasName")] 33 | public string AliasName { get; set; } 34 | 35 | public CreateAliasMeta(string aliasName, string versionId, string description=null, Dictionary additionalVersionWeight=null) 36 | : base(versionId, description, additionalVersionWeight) 37 | { 38 | this.AliasName = aliasName; 39 | } 40 | 41 | public CreateAliasMeta() { } 42 | } 43 | 44 | public class AliasMeta: CreateAliasMeta 45 | { 46 | [JsonProperty("createdTime")] 47 | public string CreatedTime { get; set; } 48 | 49 | [JsonProperty("lastModifiedTime")] 50 | public string LastModifiedTime { get; set; } 51 | 52 | public AliasMeta() { } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Alias/ListAliasesResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.model; 4 | using Newtonsoft.Json; 5 | 6 | namespace Aliyun.FunctionCompute.SDK.Response 7 | { 8 | 9 | public class AliasesResponseData 10 | { 11 | public AliasesResponseData() 12 | { 13 | this.Aliases = new AliasMeta[] { }; 14 | this.NextToken = null; 15 | } 16 | 17 | [JsonProperty("aliases")] 18 | public AliasMeta[] Aliases { get; set; } 19 | 20 | [JsonProperty("nextToken")] 21 | public string NextToken { get; set; } 22 | } 23 | 24 | public class ListAliasesResponse : IResponseBase 25 | { 26 | public string Content { get; set; } 27 | public Dictionary Headers { get; set; } 28 | public int StatusCode { get; set; } 29 | 30 | public AliasesResponseData Data { get; set; } 31 | 32 | public ListAliasesResponse() 33 | { 34 | this.Data = new AliasesResponseData(); 35 | this.Headers = new Dictionary { }; 36 | } 37 | 38 | public void SetStatusContent(string content, int status, byte[] rawBytes) 39 | { 40 | this.StatusCode = status; 41 | this.Content = content; 42 | if(status < 300) 43 | this.Data = JsonConvert.DeserializeObject(this.Content); 44 | } 45 | 46 | public void SetHeaders(Dictionary headers) 47 | { 48 | this.Headers = headers; 49 | } 50 | 51 | public string GetRequestID() 52 | { 53 | return this.Headers[Constants.HeaderKeys.REQUEST_ID].ToString(); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Service/ListServicesResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.model; 4 | using Newtonsoft.Json; 5 | 6 | namespace Aliyun.FunctionCompute.SDK.Response 7 | { 8 | 9 | public class ServicesResponseData 10 | { 11 | public ServicesResponseData() 12 | { 13 | this.Services = new ServiceMeta[] { }; 14 | this.NextToken = null; 15 | } 16 | 17 | [JsonProperty("services")] 18 | public ServiceMeta[] Services { get; set; } 19 | 20 | [JsonProperty("nextToken")] 21 | public string NextToken { get; set; } 22 | } 23 | 24 | public class ListServicesResponse : IResponseBase 25 | { 26 | public string Content { get; set; } 27 | public int StatusCode { get; set; } 28 | public Dictionary Headers { get; set; } 29 | public ServicesResponseData Data { get; set; } 30 | 31 | public ListServicesResponse() 32 | { 33 | this.Data = new ServicesResponseData(); 34 | this.Headers = new Dictionary { }; 35 | } 36 | 37 | public void SetStatusContent(string content, int status, byte[] rawBytes) 38 | { 39 | this.StatusCode = status; 40 | this.Content = content; 41 | if(status < 300) 42 | this.Data = JsonConvert.DeserializeObject(this.Content); 43 | } 44 | 45 | public void SetHeaders(Dictionary headers) 46 | { 47 | this.Headers = headers; 48 | } 49 | 50 | public string GetRequestID() 51 | { 52 | return this.Headers[Constants.HeaderKeys.REQUEST_ID].ToString(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Aliyun.FunctionCompute.SDK.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Aliyun.FC.SDK.NetCore 5 | 1.1.4 6 | netstandard2.0 7 | 1.1.4 8 | false 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Version/PublishVersionRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Config; 5 | using Aliyun.FunctionCompute.SDK.Constants; 6 | using RestSharp; 7 | 8 | namespace Aliyun.FunctionCompute.SDK.Request 9 | { 10 | public class PublishVersionRequest : RequestBase, IRequestBase 11 | { 12 | public string ServiceName { get; private set; } 13 | public string Description { get; private set; } 14 | public Dictionary Headers { get; set; } 15 | 16 | public PublishVersionRequest(string serviceName, string description = null, Dictionary customHeaders = null) 17 | { 18 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 19 | this.ServiceName = serviceName; 20 | this.Description = description; 21 | this.Headers = customHeaders; 22 | } 23 | 24 | public string GetPath() 25 | { 26 | return string.Format(Const.SERVICE_VERSION_PATH, Const.API_VERSION, this.ServiceName); 27 | } 28 | 29 | public RestRequest GenHttpRequest(FCConfig cfg) 30 | { 31 | this.Config = cfg; 32 | this.Headers = this.BuildCommonHeaders("POST", this.GetPath(), this.Headers); 33 | var request = new RestRequest(this.GetPath(), Method.POST); 34 | 35 | foreach (var item in this.Headers) 36 | request.AddHeader(item.Key, item.Value); 37 | 38 | 39 | var payLoad = new Dictionary{ 40 | {"description" , this.Description} 41 | }; 42 | 43 | request.AddJsonBody(payLoad); 44 | 45 | return request; 46 | 47 | } 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Function/ListFunctionsResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.model; 4 | using Newtonsoft.Json; 5 | 6 | namespace Aliyun.FunctionCompute.SDK.Response 7 | { 8 | 9 | public class FunctionsResponseData 10 | { 11 | public FunctionsResponseData() 12 | { 13 | this.Functions = new FunctionMeta[] { }; 14 | this.NextToken = null; 15 | } 16 | 17 | [JsonProperty("functions")] 18 | public FunctionMeta[] Functions { get; set; } 19 | 20 | [JsonProperty("nextToken")] 21 | public string NextToken { get; set; } 22 | } 23 | 24 | public class ListFunctionsResponse : IResponseBase 25 | { 26 | public string Content { get; set; } 27 | public Dictionary Headers { get; set; } 28 | public int StatusCode { get; set; } 29 | 30 | public FunctionsResponseData Data { get; set; } 31 | 32 | public ListFunctionsResponse() 33 | { 34 | this.Data = new FunctionsResponseData(); 35 | this.Headers = new Dictionary { }; 36 | } 37 | 38 | public void SetStatusContent(string content, int status, byte[] rawBytes) 39 | { 40 | this.StatusCode = status; 41 | this.Content = content; 42 | if(status < 300) 43 | this.Data = JsonConvert.DeserializeObject(this.Content); 44 | } 45 | 46 | public void SetHeaders(Dictionary headers) 47 | { 48 | this.Headers = headers; 49 | } 50 | 51 | public string GetRequestID() 52 | { 53 | return this.Headers[Constants.HeaderKeys.REQUEST_ID].ToString(); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/CustomDomain/CreateCustomDomainRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Config; 5 | using Aliyun.FunctionCompute.SDK.Constants; 6 | using Aliyun.FunctionCompute.SDK.model; 7 | using Newtonsoft.Json; 8 | using RestSharp; 9 | 10 | namespace Aliyun.FunctionCompute.SDK.Request 11 | { 12 | 13 | public class CreateCustomDomainRequest : RequestBase, IRequestBase 14 | { 15 | public CreateCustomDomainMeta CreateCustomDomainMeta { get; set; } 16 | public Dictionary Headers { get; set; } 17 | 18 | public CreateCustomDomainRequest(string domainName, string protocal = null, string apiVersion = null, RouteConfig routeConfig = null, Dictionary customHeaders = null, CertConfig certConfig = null) 19 | { 20 | Contract.Requires(string.IsNullOrEmpty(domainName) == false); 21 | 22 | this.CreateCustomDomainMeta = new CreateCustomDomainMeta(domainName, protocal, apiVersion, routeConfig, certConfig); 23 | this.Headers = customHeaders; 24 | } 25 | 26 | public string GetPath() 27 | { 28 | return string.Format(Const.CUSTOM_DOMAIN_PATH, Const.API_VERSION); 29 | } 30 | 31 | public RestRequest GenHttpRequest(FCConfig cfg) 32 | { 33 | this.Config = cfg; 34 | this.Headers = this.BuildCommonHeaders("POST", this.GetPath(), this.Headers); 35 | var request = new RestRequest(this.GetPath(), Method.POST); 36 | 37 | foreach (var item in this.Headers) 38 | request.AddHeader(item.Key, item.Value); 39 | 40 | request.AddJsonBody(JsonConvert.SerializeObject(this.CreateCustomDomainMeta)); 41 | 42 | return request; 43 | 44 | } 45 | 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/CustomDomain/ListCustomDomainsResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.model; 4 | using Newtonsoft.Json; 5 | 6 | namespace Aliyun.FunctionCompute.SDK.Response 7 | { 8 | 9 | public class CustomDomainsResponseData 10 | { 11 | public CustomDomainsResponseData() 12 | { 13 | this.CustomDomains = new CustomDomainMeta[] { }; 14 | this.NextToken = null; 15 | } 16 | 17 | [JsonProperty("customDomains")] 18 | public CustomDomainMeta[] CustomDomains { get; set; } 19 | 20 | [JsonProperty("nextToken")] 21 | public string NextToken { get; set; } 22 | } 23 | 24 | public class ListCustomDomainsResponse : IResponseBase 25 | { 26 | public string Content { get; set; } 27 | public Dictionary Headers { get; set; } 28 | public int StatusCode { get; set; } 29 | 30 | public CustomDomainsResponseData Data { get; set; } 31 | 32 | public ListCustomDomainsResponse() 33 | { 34 | this.Data = new CustomDomainsResponseData(); 35 | this.Headers = new Dictionary { }; 36 | } 37 | 38 | public void SetStatusContent(string content, int status, byte[] rawBytes) 39 | { 40 | this.StatusCode = status; 41 | this.Content = content; 42 | if(status < 300) 43 | this.Data = JsonConvert.DeserializeObject(this.Content); 44 | } 45 | 46 | public void SetHeaders(Dictionary headers) 47 | { 48 | this.Headers = headers; 49 | } 50 | 51 | public string GetRequestID() 52 | { 53 | return this.Headers[Constants.HeaderKeys.REQUEST_ID].ToString(); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Version/ListVersionsResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.model; 4 | using Newtonsoft.Json; 5 | 6 | namespace Aliyun.FunctionCompute.SDK.Response 7 | { 8 | 9 | public class VersionsResponseData 10 | { 11 | public VersionsResponseData() 12 | { 13 | this.Versions = new VersionMeta[] { }; 14 | this.NextToken = null; 15 | } 16 | 17 | [JsonProperty("versions")] 18 | public VersionMeta[] Versions { get; set; } 19 | 20 | [JsonProperty("nextToken")] 21 | public string NextToken { get; set; } 22 | 23 | [JsonProperty("direction")] 24 | public string Direction { get; set; } 25 | } 26 | 27 | public class ListVersionsResponse : IResponseBase 28 | { 29 | public string Content { get; set; } 30 | public int StatusCode { get; set; } 31 | public Dictionary Headers { get; set; } 32 | public VersionsResponseData Data { get; set; } 33 | 34 | public ListVersionsResponse() 35 | { 36 | this.Data = new VersionsResponseData(); 37 | this.Headers = new Dictionary { }; 38 | } 39 | 40 | public void SetStatusContent(string content, int status, byte[] rawBytes) 41 | { 42 | this.StatusCode = status; 43 | this.Content = content; 44 | if (status < 300) 45 | this.Data = JsonConvert.DeserializeObject(this.Content); 46 | } 47 | 48 | public void SetHeaders(Dictionary headers) 49 | { 50 | this.Headers = headers; 51 | } 52 | 53 | public string GetRequestID() 54 | { 55 | return this.Headers[Constants.HeaderKeys.REQUEST_ID].ToString(); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Trigger/GetTriggerRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Config; 5 | using Aliyun.FunctionCompute.SDK.Constants; 6 | using RestSharp; 7 | 8 | namespace Aliyun.FunctionCompute.SDK.Request 9 | { 10 | public class GetTriggerRequest : RequestBase, IRequestBase 11 | { 12 | 13 | public string ServiceName { get; set; } 14 | public string FunctionName { get; set; } 15 | public string TriggerName { get; set; } 16 | public Dictionary Headers { get; set; } 17 | 18 | public GetTriggerRequest(string serviceName, string functionName, string triggerName, Dictionary customHeaders = null) 19 | { 20 | Contract.Requires(string.IsNullOrEmpty(triggerName) == false); 21 | Contract.Requires(string.IsNullOrEmpty(functionName) == false); 22 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 23 | this.ServiceName = serviceName; 24 | this.FunctionName = functionName; 25 | this.TriggerName = triggerName; 26 | this.Headers = customHeaders; 27 | } 28 | 29 | public virtual string GetPath() 30 | { 31 | return string.Format(Const.SINGLE_TRIGGER_PATH, Const.API_VERSION, this.ServiceName, this.FunctionName, this.TriggerName); 32 | } 33 | 34 | public RestRequest GenHttpRequest(FCConfig cfg) 35 | { 36 | this.Config = cfg; 37 | this.Headers = this.BuildCommonHeaders("GET", this.GetPath(), this.Headers); 38 | var request = new RestRequest(this.GetPath(), Method.GET); 39 | 40 | foreach (var item in this.Headers) 41 | request.AddHeader(item.Key, item.Value); 42 | 43 | return request; 44 | 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Service/CreateServiceRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Config; 5 | using Aliyun.FunctionCompute.SDK.Constants; 6 | using Aliyun.FunctionCompute.SDK.model; 7 | using Newtonsoft.Json; 8 | using RestSharp; 9 | 10 | namespace Aliyun.FunctionCompute.SDK.Request 11 | { 12 | public class CreateServiceRequest : RequestBase, IRequestBase 13 | { 14 | public CreateServiceMeta CreateServiceMeta { get; set; } 15 | 16 | public Dictionary Headers { get; set; } 17 | 18 | public CreateServiceRequest(string serviceName, string description = "", string role = null, LogConfig logConfig =null, 19 | bool internetAccess=true, VpcConfig vpcConfig=null, NasConfig nasConfig=null, Dictionary customHeaders = null) 20 | { 21 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 22 | this.CreateServiceMeta = new CreateServiceMeta(serviceName, description, role, logConfig, internetAccess, vpcConfig, nasConfig); 23 | 24 | this.Headers = customHeaders; 25 | } 26 | 27 | 28 | public string GetPath() 29 | { 30 | return string.Format(Const.SERVICE_PATH, Const.API_VERSION); 31 | } 32 | 33 | public RestRequest GenHttpRequest(FCConfig cfg) 34 | { 35 | this.Config = cfg; 36 | this.Headers = this.BuildCommonHeaders("POST", this.GetPath(), this.Headers); 37 | var request = new RestRequest(this.GetPath(), Method.POST); 38 | 39 | foreach (var item in this.Headers) 40 | request.AddHeader(item.Key, item.Value); 41 | 42 | request.AddJsonBody(JsonConvert.SerializeObject(this.CreateServiceMeta)); 43 | 44 | return request; 45 | 46 | } 47 | 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Service/GetServiceRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Auth; 5 | using Aliyun.FunctionCompute.SDK.Config; 6 | using Aliyun.FunctionCompute.SDK.Constants; 7 | using RestSharp; 8 | 9 | namespace Aliyun.FunctionCompute.SDK.Request 10 | { 11 | public class GetServiceRequest: RequestBase, IRequestBase 12 | { 13 | public string ServiceName { get; set; } 14 | public string Qualifier { get; set; } 15 | public Dictionary Headers { get ; set; } 16 | 17 | public GetServiceRequest(string serviceName, string qualifier = null, Dictionary customHeaders = null) 18 | { 19 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 20 | this.ServiceName = serviceName; 21 | this.Qualifier = qualifier; 22 | this.Headers = customHeaders; 23 | } 24 | 25 | public string GetPath() 26 | { 27 | if (string.IsNullOrEmpty(this.Qualifier)) 28 | { 29 | return string.Format(Const.SINGLE_SERVICE_PATH, Const.API_VERSION, this.ServiceName); 30 | } 31 | else 32 | { 33 | return string.Format(Const.SINGLE_SERVICE_WITH_QUALIFIER_PATH, Const.API_VERSION, this.ServiceName, this.Qualifier); 34 | } 35 | } 36 | 37 | public RestRequest GenHttpRequest(FCConfig cfg) 38 | { 39 | this.Config = cfg; 40 | this.Headers = this.BuildCommonHeaders("GET", this.GetPath(), this.Headers); 41 | var request = new RestRequest(this.GetPath(), Method.GET); 42 | 43 | foreach (var item in this.Headers) 44 | request.AddHeader(item.Key, item.Value); 45 | 46 | return request; 47 | 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/model/FunctionAsyncConfigMeta.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Newtonsoft.Json; 3 | 4 | namespace Aliyun.FunctionCompute.SDK.model 5 | { 6 | public class DestinationMeta 7 | { 8 | [JsonProperty("destination")] 9 | public string Destination { get; set; } 10 | 11 | public DestinationMeta() { } 12 | } 13 | 14 | public class DestinationConfigMeta 15 | { 16 | [JsonProperty("onSuccess")] 17 | public DestinationMeta OnSuccess { get; set; } 18 | 19 | [JsonProperty("onFailure")] 20 | public DestinationMeta OnFailure { get; set; } 21 | 22 | public DestinationConfigMeta() { } 23 | } 24 | 25 | public class FunctionAsyncConfigMeta 26 | { 27 | [JsonProperty("service")] 28 | public string Service { get; set; } 29 | 30 | [JsonProperty("function")] 31 | public string Function { get; set; } 32 | 33 | [JsonProperty("qualifier")] 34 | public string Qualifier { get; set; } 35 | 36 | [JsonProperty("lastModifiedTime")] 37 | public string LastModifiedTime { get; set; } 38 | 39 | [JsonProperty("createdTime")] 40 | public string CreatedTime { get; set; } 41 | 42 | [JsonProperty("destinationConfig")] 43 | public DestinationConfigMeta DestinationConfig { get; set; } 44 | 45 | [JsonProperty("maxAsyncEventAgeInSeconds")] 46 | public int MaxAsyncEventAgeInSeconds { get; set; } 47 | 48 | [JsonProperty("maxAsyncRetryAttempts")] 49 | public int MaxAsyncRetryAttempts { get; set; } 50 | 51 | public FunctionAsyncConfigMeta(){} 52 | } 53 | 54 | 55 | public class ListFunctionAsyncConfigsMeta 56 | { 57 | [JsonProperty("nextToken")] 58 | public string NextToken { get; set; } 59 | 60 | [JsonProperty("configs")] 61 | public FunctionAsyncConfigMeta[] AsyncConfigs { get; set; } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/ReservedCapacity/ListReservedCapacitiesResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.model; 4 | using Newtonsoft.Json; 5 | 6 | namespace Aliyun.FunctionCompute.SDK.Response 7 | { 8 | 9 | public class ReservedCapacitiesResponseData 10 | { 11 | public ReservedCapacitiesResponseData() 12 | { 13 | this.ReservedCapacities = new ReservedCapacityMeta[] { }; 14 | this.NextToken = null; 15 | } 16 | 17 | [JsonProperty("reservedCapacities")] 18 | public ReservedCapacityMeta[] ReservedCapacities { get; set; } 19 | 20 | [JsonProperty("nextToken")] 21 | public string NextToken { get; set; } 22 | } 23 | 24 | public class ListReservedCapacitiesResponse : IResponseBase 25 | { 26 | public string Content { get; set; } 27 | public Dictionary Headers { get; set; } 28 | public int StatusCode { get; set; } 29 | 30 | public ReservedCapacitiesResponseData Data { get; set; } 31 | 32 | public ListReservedCapacitiesResponse() 33 | { 34 | this.Data = new ReservedCapacitiesResponseData(); 35 | this.Headers = new Dictionary { }; 36 | } 37 | 38 | public void SetStatusContent(string content, int status, byte[] rawBytes) 39 | { 40 | this.StatusCode = status; 41 | this.Content = content; 42 | if(status < 300) 43 | this.Data = JsonConvert.DeserializeObject(this.Content); 44 | } 45 | 46 | public void SetHeaders(Dictionary headers) 47 | { 48 | this.Headers = headers; 49 | } 50 | 51 | public string GetRequestID() 52 | { 53 | return this.Headers[Constants.HeaderKeys.REQUEST_ID].ToString(); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Trigger/DeleteTriggerRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Auth; 5 | using Aliyun.FunctionCompute.SDK.Config; 6 | using Aliyun.FunctionCompute.SDK.Constants; 7 | using RestSharp; 8 | 9 | namespace Aliyun.FunctionCompute.SDK.Request 10 | { 11 | public class DeleteTriggerRequest : RequestBase, IRequestBase 12 | { 13 | public string ServiceName { get; set; } 14 | public string FunctionName { get; set; } 15 | public string TriggerName { get; set; } 16 | public Dictionary Headers { get; set; } 17 | 18 | public DeleteTriggerRequest(string serviceName, string functionName, string triggerName, Dictionary customHeaders = null) 19 | { 20 | Contract.Requires(string.IsNullOrEmpty(triggerName) == false); 21 | Contract.Requires(string.IsNullOrEmpty(functionName) == false); 22 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 23 | this.ServiceName = serviceName; 24 | this.FunctionName = functionName; 25 | this.TriggerName = triggerName; 26 | this.Headers = customHeaders; 27 | } 28 | 29 | public string GetPath() 30 | { 31 | return string.Format(Const.SINGLE_TRIGGER_PATH, Const.API_VERSION, this.ServiceName, this.FunctionName, this.TriggerName); 32 | } 33 | 34 | public RestRequest GenHttpRequest(FCConfig cfg) 35 | { 36 | this.Config = cfg; 37 | this.Headers = this.BuildCommonHeaders("DELETE", this.GetPath(), this.Headers); 38 | var request = new RestRequest(this.GetPath(), Method.DELETE); 39 | 40 | foreach (var item in this.Headers) 41 | request.AddHeader(item.Key, item.Value); 42 | 43 | return request; 44 | 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/CustomDomain/UpdateCustomDomainRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Config; 5 | using Aliyun.FunctionCompute.SDK.Constants; 6 | using Aliyun.FunctionCompute.SDK.model; 7 | using Newtonsoft.Json; 8 | using RestSharp; 9 | 10 | namespace Aliyun.FunctionCompute.SDK.Request 11 | { 12 | 13 | public class UpdateCustomDomainRequest : RequestBase, IRequestBase 14 | { 15 | public UpdateCustomDomainMeta UpdateCustomDomainMeta { get; set; } 16 | public Dictionary Headers { get; set; } 17 | public object DomainName { get; private set; } 18 | 19 | public UpdateCustomDomainRequest(string domainName, string protocal = null, string apiVersion = null, RouteConfig routeConfig = null, Dictionary customHeaders = null, CertConfig certConfig = null) 20 | { 21 | Contract.Requires(string.IsNullOrEmpty(domainName) == false); 22 | this.DomainName = domainName; 23 | this.UpdateCustomDomainMeta = new UpdateCustomDomainMeta(protocal, apiVersion, routeConfig, certConfig); 24 | this.Headers = customHeaders; 25 | } 26 | 27 | public string GetPath() 28 | { 29 | return string.Format(Const.SINGLE_CUSTOM_DOMAIN_PATH, Const.API_VERSION, this.DomainName); 30 | } 31 | 32 | public RestRequest GenHttpRequest(FCConfig cfg) 33 | { 34 | this.Config = cfg; 35 | this.Headers = this.BuildCommonHeaders("PUT", this.GetPath(), this.Headers); 36 | var request = new RestRequest(this.GetPath(), Method.PUT); 37 | 38 | foreach (var item in this.Headers) 39 | request.AddHeader(item.Key, item.Value); 40 | 41 | request.AddJsonBody(JsonConvert.SerializeObject(this.UpdateCustomDomainMeta)); 42 | 43 | return request; 44 | 45 | } 46 | 47 | 48 | } 49 | } 50 | 51 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Service/UpdateServiceRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Config; 5 | using Aliyun.FunctionCompute.SDK.Constants; 6 | using Aliyun.FunctionCompute.SDK.model; 7 | using Newtonsoft.Json; 8 | using RestSharp; 9 | 10 | namespace Aliyun.FunctionCompute.SDK.Request 11 | { 12 | public class UpdateServiceRequest : RequestBase, IRequestBase 13 | { 14 | public UpdateServiceMeta UpdateServiceMeta { get; set; } 15 | 16 | public Dictionary Headers { get; set; } 17 | public string ServiceName { get; private set; } 18 | 19 | public UpdateServiceRequest(string serviceName, string description = "", string role = null, LogConfig logConfig = null, 20 | bool internetAccess = true, VpcConfig vpcConfig = null, NasConfig nasConfig = null, Dictionary customHeaders = null) 21 | { 22 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 23 | this.ServiceName = serviceName; 24 | this.UpdateServiceMeta = new UpdateServiceMeta(description, role, logConfig, internetAccess, vpcConfig, nasConfig); 25 | 26 | this.Headers = customHeaders; 27 | } 28 | 29 | 30 | public string GetPath() 31 | { 32 | return string.Format(Const.SINGLE_SERVICE_PATH, Const.API_VERSION, this.ServiceName); 33 | } 34 | 35 | public RestRequest GenHttpRequest(FCConfig cfg) 36 | { 37 | this.Config = cfg; 38 | this.Headers = this.BuildCommonHeaders("PUT", this.GetPath(), this.Headers); 39 | var request = new RestRequest(this.GetPath(), Method.PUT); 40 | 41 | foreach (var item in this.Headers) 42 | request.AddHeader(item.Key, item.Value); 43 | 44 | request.AddJsonBody(JsonConvert.SerializeObject(this.UpdateServiceMeta)); 45 | 46 | return request; 47 | 48 | } 49 | 50 | 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Tag/UntagResourceRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.Config; 4 | using Aliyun.FunctionCompute.SDK.Constants; 5 | using Newtonsoft.Json; 6 | using RestSharp; 7 | using Aliyun.FunctionCompute.SDK.model; 8 | 9 | namespace Aliyun.FunctionCompute.SDK.Request 10 | { 11 | public class UnTagInput 12 | { 13 | [JsonProperty("resourceArn")] 14 | public string ResourceArn { get; set; } 15 | 16 | [JsonProperty("tagKeys")] 17 | public string[] TagKeys { get; set; } 18 | 19 | [JsonProperty("all")] 20 | public bool All { get; set; } 21 | 22 | public UnTagInput(string resourceArn, string[] keys, bool all) 23 | { 24 | this.ResourceArn = resourceArn; 25 | this.TagKeys = keys; 26 | this.All = all; 27 | } 28 | } 29 | 30 | public class UntagResourceRequest : RequestBase, IRequestBase 31 | { 32 | public Dictionary Headers { get; set; } 33 | public UnTagInput UnTagInput { get; set; } 34 | 35 | public UntagResourceRequest(string resourceArn, string[] keys, bool all, Dictionary customHeaders = null) 36 | { 37 | this.Headers = customHeaders; 38 | this.UnTagInput = new UnTagInput(resourceArn, keys, all); 39 | } 40 | 41 | public string GetPath() 42 | { 43 | return string.Format(Const.TAG_PATH, Const.API_VERSION); 44 | } 45 | 46 | public RestRequest GenHttpRequest(FCConfig cfg) 47 | { 48 | this.Config = cfg; 49 | this.Headers = this.BuildCommonHeaders("DELETE", this.GetPath(), this.Headers); 50 | var request = new RestRequest(this.GetPath(), Method.DELETE); 51 | 52 | foreach (var item in this.Headers) 53 | request.AddHeader(item.Key, item.Value); 54 | 55 | request.AddJsonBody(JsonConvert.SerializeObject(this.UnTagInput)); 56 | 57 | return request; 58 | } 59 | } 60 | } 61 | 62 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/AsyncConfig/DeleteAsyncConfigRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Auth; 5 | using Aliyun.FunctionCompute.SDK.Config; 6 | using Aliyun.FunctionCompute.SDK.Constants; 7 | using RestSharp; 8 | 9 | namespace Aliyun.FunctionCompute.SDK.Request 10 | { 11 | public class DeleteFunctionAsyncConfigRequest : RequestBase, IRequestBase 12 | { 13 | public string ServiceName { get; set; } 14 | public string Qualifier { get; set; } 15 | public string FunctionName { get; set; } 16 | public Dictionary Headers { get; set; } 17 | 18 | public DeleteFunctionAsyncConfigRequest(string serviceName, string qualifier, string functionName, Dictionary customHeaders = null) 19 | { 20 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 21 | Contract.Requires(string.IsNullOrEmpty(functionName) == false); 22 | this.ServiceName = serviceName; 23 | this.FunctionName = functionName; 24 | this.Qualifier = qualifier; 25 | this.Headers = customHeaders; 26 | } 27 | 28 | public string GetPath() 29 | { 30 | if (string.IsNullOrEmpty(this.Qualifier)) { 31 | return string.Format(Const.ASYNC_CONFIG_PATH, Const.API_VERSION, this.ServiceName, this.FunctionName); 32 | 33 | } 34 | return string.Format(Const.ASYNC_CONFIG_WITH_QUALIFIER_PATH, Const.API_VERSION, this.ServiceName, this.Qualifier, this.FunctionName); 35 | } 36 | 37 | public RestRequest GenHttpRequest(FCConfig cfg) 38 | { 39 | this.Config = cfg; 40 | this.Headers = this.BuildCommonHeaders("DELETE", this.GetPath(), this.Headers); 41 | var request = new RestRequest(this.GetPath(), Method.DELETE); 42 | 43 | foreach (var item in this.Headers) 44 | request.AddHeader(item.Key, item.Value); 45 | 46 | return request; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/AsyncConfig/PutFunctionAsyncConfigRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.Config; 4 | using Aliyun.FunctionCompute.SDK.Constants; 5 | using Newtonsoft.Json; 6 | using RestSharp; 7 | using Aliyun.FunctionCompute.SDK.model; 8 | 9 | namespace Aliyun.FunctionCompute.SDK.Request 10 | { 11 | 12 | public class PutFunctionAsyncConfigRequest : RequestBase, IRequestBase 13 | { 14 | public Dictionary Headers { get; set; } 15 | public string ServiceName { get; set; } 16 | public string Qualifier { get; set; } 17 | public string FunctionName { get; set; } 18 | 19 | public FunctionAsyncConfigMeta AsyncConfig { get; set; } 20 | 21 | public PutFunctionAsyncConfigRequest(string serviceName, string qualifier, string functionName, Dictionary customHeaders = null) 22 | { 23 | this.ServiceName = serviceName; 24 | this.Qualifier = qualifier; 25 | this.FunctionName = functionName; 26 | this.Headers = customHeaders; 27 | } 28 | 29 | public string GetPath() 30 | { 31 | if (string.IsNullOrEmpty(this.Qualifier)) 32 | { 33 | return string.Format(Const.ASYNC_CONFIG_PATH, Const.API_VERSION, this.ServiceName, this.FunctionName); 34 | } 35 | return string.Format(Const.ASYNC_CONFIG_WITH_QUALIFIER_PATH, Const.API_VERSION, this.ServiceName, this.Qualifier, this.FunctionName); 36 | } 37 | 38 | public RestRequest GenHttpRequest(FCConfig cfg) 39 | { 40 | this.Config = cfg; 41 | this.Headers = this.BuildCommonHeaders("PUT", this.GetPath(), this.Headers); 42 | var request = new RestRequest(this.GetPath(), Method.PUT); 43 | 44 | foreach (var item in this.Headers) 45 | request.AddHeader(item.Key, item.Value); 46 | 47 | request.AddJsonBody(JsonConvert.SerializeObject(this.AsyncConfig)); 48 | 49 | return request; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Config/Config.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.Contracts; 3 | using Aliyun.FunctionCompute.SDK.Constants; 4 | 5 | namespace Aliyun.FunctionCompute.SDK.Config 6 | { 7 | public class FCConfig 8 | { 9 | /// 10 | /// Initializes a new instance of the class. 11 | /// 12 | /// Region. 13 | /// Account identifier. 14 | /// Access key identifier. 15 | /// Access key secret. 16 | /// Security token. 17 | /// If set to true is https. 18 | public FCConfig(string region, string accountId, string accessKeyID, string accessKeySecret, string securityToken, bool isHttps) 19 | { 20 | Contract.Requires(string.IsNullOrEmpty(accessKeyID) == false); 21 | Contract.Requires(string.IsNullOrEmpty(accessKeySecret) == false); 22 | Contract.Requires(string.IsNullOrEmpty(region) == false); 23 | Contract.Requires(string.IsNullOrEmpty(accountId) == false); 24 | 25 | string protocol = isHttps ? "https" : "http"; 26 | this.Host = string.Format(Const.ENDPOINT_FMT, accountId, region); 27 | this.Endpoint = protocol + "://" + this.Host; 28 | this.AccountId = accountId; 29 | this.AccessKeyID = accessKeyID; 30 | this.AccessKeySecret = accessKeySecret; 31 | this.SecurityToken = securityToken; 32 | 33 | this.UserAgent = "fc-dotnet-sdk-1.0.0"; 34 | } 35 | 36 | public string AccessKeySecret { get ; set ; } 37 | public string AccessKeyID { get; set; } 38 | public string SecurityToken { get; set; } 39 | public string AccountId { get; set; } 40 | public string Endpoint { get; set; } 41 | public string Host { get; set; } 42 | public string UserAgent { get; set; } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Alias/CreateAliasRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Config; 5 | using Aliyun.FunctionCompute.SDK.Constants; 6 | using Aliyun.FunctionCompute.SDK.model; 7 | using Newtonsoft.Json; 8 | using RestSharp; 9 | 10 | namespace Aliyun.FunctionCompute.SDK.Request 11 | { 12 | 13 | public class CreateAliasRequest : RequestBase, IRequestBase 14 | { 15 | public string ServiceName { get; private set; } 16 | 17 | public CreateAliasMeta CreateAliasMeta { get; set; } 18 | public Dictionary Headers { get; set; } 19 | 20 | public CreateAliasRequest(string serviceName, string aliasName, string versionId, string description = null, 21 | Dictionary additionalVersionWeight = null, Dictionary customHeaders = null) 22 | { 23 | Contract.Requires(string.IsNullOrEmpty(versionId) == false); 24 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 25 | Contract.Requires(string.IsNullOrEmpty(aliasName) == false); 26 | this.ServiceName = serviceName; 27 | this.CreateAliasMeta = new CreateAliasMeta(aliasName, versionId, description, additionalVersionWeight); 28 | this.Headers = customHeaders; 29 | } 30 | 31 | 32 | public string GetPath() 33 | { 34 | return string.Format(Const.ALIAS_PATH, Const.API_VERSION, this.ServiceName); 35 | } 36 | 37 | public RestRequest GenHttpRequest(FCConfig cfg) 38 | { 39 | this.Config = cfg; 40 | this.Headers = this.BuildCommonHeaders("POST", this.GetPath(), this.Headers); 41 | var request = new RestRequest(this.GetPath(), Method.POST); 42 | 43 | foreach (var item in this.Headers) 44 | request.AddHeader(item.Key, item.Value); 45 | 46 | request.AddJsonBody(JsonConvert.SerializeObject(this.CreateAliasMeta)); 47 | 48 | return request; 49 | 50 | } 51 | 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/AsyncConfig/GetFunctionAsyncConfigRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.Config; 4 | using System.Diagnostics.Contracts; 5 | using Aliyun.FunctionCompute.SDK.Constants; 6 | using Newtonsoft.Json; 7 | using RestSharp; 8 | using Aliyun.FunctionCompute.SDK.model; 9 | 10 | namespace Aliyun.FunctionCompute.SDK.Request 11 | { 12 | public class GetFunctionAsyncConfigRequest : RequestBase, IRequestBase 13 | { 14 | public Dictionary Headers { get; set; } 15 | public string ServiceName { get; set; } 16 | public string Qualifier { get; set; } 17 | public string FunctionName { get; set; } 18 | 19 | 20 | public GetFunctionAsyncConfigRequest(string serviceName, string qualifier, string functionName, Dictionary customHeaders = null) 21 | { 22 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 23 | Contract.Requires(string.IsNullOrEmpty(functionName) == false); 24 | this.ServiceName = serviceName; 25 | this.Qualifier = qualifier; 26 | this.FunctionName = functionName; 27 | this.Headers = customHeaders; 28 | } 29 | 30 | public string GetPath() 31 | { 32 | if (string.IsNullOrEmpty(this.Qualifier)) 33 | { 34 | return string.Format(Const.ASYNC_CONFIG_PATH, Const.API_VERSION, this.ServiceName, this.FunctionName); 35 | } 36 | return string.Format(Const.ASYNC_CONFIG_WITH_QUALIFIER_PATH, Const.API_VERSION, this.ServiceName, this.Qualifier, this.FunctionName); 37 | } 38 | 39 | public RestRequest GenHttpRequest(FCConfig cfg) 40 | { 41 | this.Config = cfg; 42 | this.Headers = this.BuildCommonHeaders("GET", this.GetPath(), this.Headers); 43 | var request = new RestRequest(this.GetPath(), Method.GET); 44 | foreach (var item in this.Headers) 45 | request.AddHeader(item.Key, item.Value); 46 | return request; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/CustomDomain/ListCustomDomainsRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Config; 5 | using Aliyun.FunctionCompute.SDK.Constants; 6 | using RestSharp; 7 | 8 | namespace Aliyun.FunctionCompute.SDK.Request 9 | { 10 | public class ListCustomDomainsRequest : RequestBase, IRequestBase 11 | { 12 | public string Prefix { get; set; } 13 | public string StartKey { get; set; } 14 | public string NextToken { get; set; } 15 | public int Limit { get; set; } 16 | 17 | public Dictionary Headers { get; set; } 18 | 19 | public ListCustomDomainsRequest(int limit = 0, string prefix = null, string startKey = null, string nextToken = null, Dictionary customHeaders = null) 20 | { 21 | this.Limit = limit; 22 | this.Prefix = prefix; 23 | this.StartKey = startKey; 24 | this.NextToken = nextToken; 25 | this.Headers = customHeaders; 26 | } 27 | 28 | public string GetPath() 29 | { 30 | return string.Format(Const.CUSTOM_DOMAIN_PATH, Const.API_VERSION); 31 | } 32 | 33 | public RestRequest GenHttpRequest(FCConfig cfg) 34 | { 35 | this.Config = cfg; 36 | this.Headers = this.BuildCommonHeaders("GET", this.GetPath(), this.Headers); 37 | var request = new RestRequest(this.GetPath(), Method.GET); 38 | 39 | foreach (var item in this.Headers) 40 | request.AddHeader(item.Key, item.Value); 41 | 42 | if (this.Limit > 0) request.AddQueryParameter("limit", this.Limit.ToString()); 43 | if (!string.IsNullOrEmpty(this.Prefix)) request.AddQueryParameter("prefix", this.Prefix); 44 | if (!string.IsNullOrEmpty(this.StartKey)) request.AddQueryParameter("startKey", this.StartKey); 45 | if (!string.IsNullOrEmpty(this.NextToken)) request.AddQueryParameter("nextToken", this.NextToken); 46 | 47 | return request; 48 | } 49 | 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Function/GetFunctionRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Config; 5 | using Aliyun.FunctionCompute.SDK.Constants; 6 | using RestSharp; 7 | 8 | namespace Aliyun.FunctionCompute.SDK.Request 9 | { 10 | public class GetFunctionRequest : RequestBase 11 | { 12 | 13 | public string ServiceName { get; set; } 14 | public string FunctionName { get; set; } 15 | public string Qualifier { get; set; } 16 | public Dictionary Headers { get; set; } 17 | 18 | public GetFunctionRequest(string serviceName, string functionName, string qualifier = null, Dictionary customHeaders = null) 19 | { 20 | Contract.Requires(string.IsNullOrEmpty(functionName) == false); 21 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 22 | this.ServiceName = serviceName; 23 | this.FunctionName = functionName; 24 | this.Qualifier = qualifier; 25 | this.Headers = customHeaders; 26 | } 27 | 28 | public virtual string GetPath() 29 | { 30 | if (string.IsNullOrEmpty(this.Qualifier)) 31 | { 32 | return string.Format(Const.SINGLE_FUNCTION_PATH, Const.API_VERSION, this.ServiceName, this.FunctionName); 33 | } 34 | else 35 | { 36 | return string.Format(Const.SINGLE_FUNCTION_WITH_QUALIFIER_PATH, Const.API_VERSION, 37 | this.ServiceName, this.Qualifier, this.FunctionName); 38 | } 39 | } 40 | 41 | public RestRequest GenHttpRequest(FCConfig cfg) 42 | { 43 | this.Config = cfg; 44 | this.Headers = this.BuildCommonHeaders("GET", this.GetPath(), this.Headers); 45 | var request = new RestRequest(this.GetPath(), Method.GET); 46 | 47 | foreach (var item in this.Headers) 48 | request.AddHeader(item.Key, item.Value); 49 | 50 | return request; 51 | 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Alias/UpdateAliasRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Config; 5 | using Aliyun.FunctionCompute.SDK.Constants; 6 | using Aliyun.FunctionCompute.SDK.model; 7 | using Newtonsoft.Json; 8 | using RestSharp; 9 | 10 | namespace Aliyun.FunctionCompute.SDK.Request 11 | { 12 | 13 | public class UpdateAliasRequest : RequestBase, IRequestBase 14 | { 15 | public string ServiceName { get; set; } 16 | public string AliasName { get; set; } 17 | 18 | public UpdateAliasMeta UpdateAliasMeta { get; set; } 19 | 20 | public Dictionary Headers { get; set; } 21 | 22 | public UpdateAliasRequest(string serviceName, string aliasName, string versionId, string description = null, 23 | Dictionary additionalVersionWeight = null, Dictionary customHeaders = null) 24 | { 25 | Contract.Requires(string.IsNullOrEmpty(versionId) == false); 26 | Contract.Requires(string.IsNullOrEmpty(aliasName) == false); 27 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 28 | this.ServiceName = serviceName; 29 | this.AliasName = aliasName; 30 | this.UpdateAliasMeta = new UpdateAliasMeta(versionId, description, additionalVersionWeight); 31 | this.Headers = customHeaders; 32 | } 33 | 34 | public string GetPath() 35 | { 36 | return string.Format(Const.SINGLE_ALIAS_PATH, Const.API_VERSION, this.ServiceName, this.AliasName); 37 | } 38 | 39 | public RestRequest GenHttpRequest(FCConfig cfg) 40 | { 41 | this.Config = cfg; 42 | this.Headers = this.BuildCommonHeaders("PUT", this.GetPath(), this.Headers); 43 | var request = new RestRequest(this.GetPath(), Method.PUT); 44 | 45 | foreach (var item in this.Headers) 46 | request.AddHeader(item.Key, item.Value); 47 | 48 | request.AddJsonBody(JsonConvert.SerializeObject(this.UpdateAliasMeta)); 49 | 50 | return request; 51 | 52 | } 53 | 54 | 55 | } 56 | } 57 | 58 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/AsyncConfig/ListFunctionAsyncConfigRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Config; 5 | using Aliyun.FunctionCompute.SDK.Constants; 6 | using Newtonsoft.Json; 7 | using RestSharp; 8 | using Aliyun.FunctionCompute.SDK.model; 9 | 10 | namespace Aliyun.FunctionCompute.SDK.Request 11 | { 12 | 13 | public class ListFunctionAsyncConfigsRequest : RequestBase, IRequestBase 14 | { 15 | public Dictionary Headers { get; set; } 16 | public string ServiceName { get; set; } 17 | public string FunctionName { get; set; } 18 | public string NextToken { get; set; } 19 | public int Limit { get; set; } 20 | 21 | 22 | public ListFunctionAsyncConfigsRequest(string serviceName, string functionName, int limit= 0, string nextToken=null, Dictionary customHeaders = null) 23 | { 24 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 25 | Contract.Requires(string.IsNullOrEmpty(functionName) == false); 26 | this.ServiceName = serviceName; 27 | this.FunctionName = functionName; 28 | this.Limit = limit; 29 | this.NextToken = nextToken; 30 | this.Headers = customHeaders; 31 | } 32 | 33 | public string GetPath() 34 | { 35 | return string.Format(Const.LIST_ASYNC_CONFIGS_PATH, Const.API_VERSION, this.ServiceName, this.FunctionName); 36 | } 37 | 38 | public RestRequest GenHttpRequest(FCConfig cfg) 39 | { 40 | this.Config = cfg; 41 | this.Headers = this.BuildCommonHeaders("GET", this.GetPath(), this.Headers); 42 | var request = new RestRequest(this.GetPath(), Method.GET); 43 | 44 | foreach (var item in this.Headers) 45 | request.AddHeader(item.Key, item.Value); 46 | 47 | if (this.Limit > 0) request.AddQueryParameter("limit", this.Limit.ToString()); 48 | if (!string.IsNullOrEmpty(this.NextToken)) request.AddQueryParameter("nextToken", this.NextToken); 49 | 50 | 51 | return request; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Provision/PutProvisionConfigRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.Config; 4 | using Aliyun.FunctionCompute.SDK.Constants; 5 | using Newtonsoft.Json; 6 | using RestSharp; 7 | using Aliyun.FunctionCompute.SDK.model; 8 | 9 | namespace Aliyun.FunctionCompute.SDK.Request 10 | { 11 | public class PutProvisionConfigInput 12 | { 13 | [JsonProperty("target")] 14 | public int Target { get; set; } 15 | 16 | 17 | public PutProvisionConfigInput() { } 18 | 19 | public PutProvisionConfigInput(int t) 20 | { 21 | this.Target = t; 22 | } 23 | } 24 | 25 | public class PutProvisionConfigRequest : RequestBase, IRequestBase 26 | { 27 | public Dictionary Headers { get; set; } 28 | public string ServiceName { get; set; } 29 | public string Qualifier { get; set; } 30 | public string FunctionName { get; set; } 31 | 32 | public PutProvisionConfigInput Input { get; set; } 33 | 34 | public PutProvisionConfigRequest(string serviceName, string qualifier, string functionName, int target, Dictionary customHeaders = null) 35 | { 36 | this.ServiceName = serviceName; 37 | this.Qualifier = qualifier; 38 | this.FunctionName = functionName; 39 | this.Input = new PutProvisionConfigInput(target); 40 | this.Headers = customHeaders; 41 | } 42 | 43 | public string GetPath() 44 | { 45 | return string.Format(Const.SINGLE_PROVISION_CONFIG_PATH, Const.API_VERSION, 46 | this.ServiceName, this.Qualifier, this.FunctionName); 47 | } 48 | 49 | public RestRequest GenHttpRequest(FCConfig cfg) 50 | { 51 | this.Config = cfg; 52 | this.Headers = this.BuildCommonHeaders("PUT", this.GetPath(), this.Headers); 53 | var request = new RestRequest(this.GetPath(), Method.PUT); 54 | 55 | foreach (var item in this.Headers) 56 | request.AddHeader(item.Key, item.Value); 57 | 58 | request.AddJsonBody(JsonConvert.SerializeObject(this.Input)); 59 | 60 | return request; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Alias/ListAliasesRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Config; 5 | using Aliyun.FunctionCompute.SDK.Constants; 6 | using RestSharp; 7 | 8 | namespace Aliyun.FunctionCompute.SDK.Request 9 | { 10 | public class ListAliasesRequest : RequestBase, IRequestBase 11 | { 12 | public string ServiceName { get; set; } 13 | public string Prefix { get; set; } 14 | public string StartKey { get; set; } 15 | public string NextToken { get; set; } 16 | public int Limit { get; set; } 17 | 18 | public Dictionary Headers { get; set; } 19 | 20 | public ListAliasesRequest(string serviceName, int limit = 0, string prefix = null, string startKey = null, string nextToken = null, Dictionary customHeaders = null) 21 | { 22 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 23 | this.ServiceName = serviceName; 24 | this.Limit = limit; 25 | this.Prefix = prefix; 26 | this.StartKey = startKey; 27 | this.NextToken = nextToken; 28 | this.Headers = customHeaders; 29 | } 30 | 31 | public string GetPath() 32 | { 33 | return string.Format(Const.ALIAS_PATH, Const.API_VERSION, this.ServiceName); 34 | } 35 | 36 | public RestRequest GenHttpRequest(FCConfig cfg) 37 | { 38 | this.Config = cfg; 39 | this.Headers = this.BuildCommonHeaders("GET", this.GetPath(), this.Headers); 40 | var request = new RestRequest(this.GetPath(), Method.GET); 41 | 42 | foreach (var item in this.Headers) 43 | request.AddHeader(item.Key, item.Value); 44 | 45 | if (this.Limit > 0) request.AddQueryParameter("limit", this.Limit.ToString()); 46 | if (!string.IsNullOrEmpty(this.Prefix)) request.AddQueryParameter("prefix", this.Prefix); 47 | if (!string.IsNullOrEmpty(this.StartKey)) request.AddQueryParameter("startKey", this.StartKey); 48 | if (!string.IsNullOrEmpty(this.NextToken)) request.AddQueryParameter("nextToken", this.NextToken); 49 | 50 | return request; 51 | } 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Function/InvokeFunctionRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Config; 5 | using Aliyun.FunctionCompute.SDK.Constants; 6 | using RestSharp; 7 | 8 | namespace Aliyun.FunctionCompute.SDK.Request 9 | { 10 | public class InvokeFunctionRequest : RequestBase 11 | { 12 | 13 | public string ServiceName { get; set; } 14 | public string FunctionName { get; set; } 15 | public string Qualifier { get; set; } 16 | public Dictionary Headers { get; set; } 17 | public byte[] Payload { get; set; } 18 | 19 | public InvokeFunctionRequest(string serviceName, string functionName, string qualifier = null, byte[] payload = null, Dictionary customHeaders = null) 20 | { 21 | Contract.Requires(string.IsNullOrEmpty(functionName) == false); 22 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 23 | this.ServiceName = serviceName; 24 | this.FunctionName = functionName; 25 | this.Qualifier = qualifier; 26 | this.Payload = payload; 27 | this.Headers = customHeaders; 28 | } 29 | 30 | public string GetPath() 31 | { 32 | if (string.IsNullOrEmpty(this.Qualifier)) 33 | { 34 | return string.Format(Const.INVOKE_FUNCTION_PATH, Const.API_VERSION, this.ServiceName, this.FunctionName); 35 | } 36 | else 37 | { 38 | return string.Format(Const.INVOKE_FUNCTION_WITH_QUALIFIER_PATH, Const.API_VERSION, this.ServiceName, this.Qualifier, this.FunctionName); 39 | } 40 | } 41 | 42 | public RestRequest GenHttpRequest(FCConfig cfg) 43 | { 44 | this.Config = cfg; 45 | this.Headers = this.BuildCommonHeaders("POST", this.GetPath(), this.Headers); 46 | var request = new RestRequest(this.GetPath(), Method.POST); 47 | 48 | foreach (var item in this.Headers) 49 | request.AddHeader(item.Key, item.Value); 50 | 51 | request.AddParameter("application/octet-stream", this.Payload, ParameterType.RequestBody); 52 | 53 | return request; 54 | 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Provision/ListProvisionConfigsRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.Config; 4 | using Aliyun.FunctionCompute.SDK.Constants; 5 | using Newtonsoft.Json; 6 | using RestSharp; 7 | using Aliyun.FunctionCompute.SDK.model; 8 | 9 | namespace Aliyun.FunctionCompute.SDK.Request 10 | { 11 | 12 | public class ListProvisionConfigsRequest : RequestBase, IRequestBase 13 | { 14 | public Dictionary Headers { get; set; } 15 | public string ServiceName { get; set; } 16 | public string Qualifier { get; set; } 17 | public string NextToken { get; set; } 18 | public int Limit { get; set; } 19 | 20 | 21 | public ListProvisionConfigsRequest(string serviceName, string qualifier, int limit= 0, string nextToken=null, Dictionary customHeaders = null) 22 | { 23 | if (string.IsNullOrEmpty(serviceName) && !string.IsNullOrEmpty(qualifier)) 24 | { 25 | throw new ArgumentException("serviceName is required when qualifier is not empty", nameof(serviceName)); 26 | } 27 | 28 | this.ServiceName = serviceName; 29 | this.Qualifier = qualifier; 30 | this.Limit = limit; 31 | this.NextToken = nextToken; 32 | this.Headers = customHeaders; 33 | } 34 | 35 | public string GetPath() 36 | { 37 | return string.Format(Const.PROVISION_CONFIGS_PATH, Const.API_VERSION); 38 | } 39 | 40 | public RestRequest GenHttpRequest(FCConfig cfg) 41 | { 42 | this.Config = cfg; 43 | this.Headers = this.BuildCommonHeaders("GET", this.GetPath(), this.Headers); 44 | var request = new RestRequest(this.GetPath(), Method.GET); 45 | 46 | foreach (var item in this.Headers) 47 | request.AddHeader(item.Key, item.Value); 48 | 49 | request.AddQueryParameter("serviceName", this.ServiceName); 50 | request.AddQueryParameter("qualifier", this.Qualifier); 51 | 52 | if (this.Limit > 0) request.AddQueryParameter("limit", this.Limit.ToString()); 53 | if (!string.IsNullOrEmpty(this.NextToken)) request.AddQueryParameter("nextToken", this.NextToken); 54 | 55 | 56 | return request; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Trigger/UpdateTriggerRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Config; 5 | using Aliyun.FunctionCompute.SDK.Constants; 6 | using Aliyun.FunctionCompute.SDK.model; 7 | using Newtonsoft.Json; 8 | using RestSharp; 9 | 10 | namespace Aliyun.FunctionCompute.SDK.Request 11 | { 12 | 13 | public class UpdateTriggerRequest : RequestBase, IRequestBase 14 | { 15 | public string ServiceName { get; set; } 16 | public string FunctionName { get; set; } 17 | public string TriggerName { get; set; } 18 | 19 | public UpdateTriggerMeta UpdateTriggerMeta { get; set; } 20 | 21 | public Dictionary Headers { get; set; } 22 | 23 | public UpdateTriggerRequest(string serviceName, string functionName, string triggerName, 24 | object triggerConfig=null, string invocationRole=null, string description = null, string qualifier = null, Dictionary customHeaders = null) 25 | { 26 | Contract.Requires(string.IsNullOrEmpty(triggerName) == false); 27 | Contract.Requires(string.IsNullOrEmpty(functionName) == false); 28 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 29 | this.ServiceName = serviceName; 30 | this.FunctionName = functionName; 31 | this.TriggerName = triggerName; 32 | this.UpdateTriggerMeta = new UpdateTriggerMeta(invocationRole, triggerConfig, description, qualifier); 33 | this.Headers = customHeaders; 34 | } 35 | 36 | public string GetPath() 37 | { 38 | return string.Format(Const.SINGLE_TRIGGER_PATH, Const.API_VERSION, this.ServiceName,this.FunctionName, this.TriggerName); 39 | } 40 | 41 | public RestRequest GenHttpRequest(FCConfig cfg) 42 | { 43 | this.Config = cfg; 44 | this.Headers = this.BuildCommonHeaders("PUT", this.GetPath(), this.Headers); 45 | var request = new RestRequest(this.GetPath(), Method.PUT); 46 | 47 | foreach (var item in this.Headers) 48 | request.AddHeader(item.Key, item.Value); 49 | 50 | request.AddJsonBody(JsonConvert.SerializeObject(this.UpdateTriggerMeta)); 51 | 52 | return request; 53 | 54 | } 55 | 56 | 57 | } 58 | } 59 | 60 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Function/UpdateFunctionRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Config; 5 | using Aliyun.FunctionCompute.SDK.Constants; 6 | using Aliyun.FunctionCompute.SDK.model; 7 | using Newtonsoft.Json; 8 | using RestSharp; 9 | 10 | namespace Aliyun.FunctionCompute.SDK.Request 11 | { 12 | 13 | public class UpdateFunctionRequest : RequestBase 14 | { 15 | public string ServiceName { get; set; } 16 | public string FunctionName { get; set; } 17 | 18 | public UpdateFunctionMeta UpdateFunctionMeta { get; set; } 19 | 20 | public Dictionary Headers { get; set; } 21 | 22 | public UpdateFunctionRequest(string serviceName, string functionName, string runtime, 23 | string handler, Code code, string desc = null, 24 | int memorySize=256, int timeout = 60, 25 | Dictionary env = null, 26 | string initializer = null, int initializationTimeout=30, 27 | Dictionary customHeaders = null, string instanceType = null) 28 | { 29 | Contract.Requires(string.IsNullOrEmpty(functionName) == false); 30 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 31 | this.ServiceName = serviceName; 32 | this.FunctionName = functionName; 33 | this.UpdateFunctionMeta = new UpdateFunctionMeta(runtime, handler, code, desc, memorySize, timeout, env, initializer, initializationTimeout, instanceType); 34 | this.Headers = customHeaders; 35 | } 36 | 37 | 38 | public string GetPath() 39 | { 40 | return string.Format(Const.SINGLE_FUNCTION_PATH, Const.API_VERSION, this.ServiceName,this.FunctionName); 41 | } 42 | 43 | public RestRequest GenHttpRequest(FCConfig cfg) 44 | { 45 | this.Config = cfg; 46 | this.Headers = this.BuildCommonHeaders("PUT", this.GetPath(), this.Headers); 47 | var request = new RestRequest(this.GetPath(), Method.PUT); 48 | 49 | foreach (var item in this.Headers) 50 | request.AddHeader(item.Key, item.Value); 51 | 52 | request.AddJsonBody(JsonConvert.SerializeObject(this.UpdateFunctionMeta)); 53 | 54 | return request; 55 | 56 | } 57 | 58 | 59 | } 60 | } 61 | 62 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Trigger/CreateTriggerRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Config; 5 | using Aliyun.FunctionCompute.SDK.Constants; 6 | using Aliyun.FunctionCompute.SDK.model; 7 | using Newtonsoft.Json; 8 | using RestSharp; 9 | 10 | namespace Aliyun.FunctionCompute.SDK.Request 11 | { 12 | 13 | public class CreateTriggerRequest : RequestBase, IRequestBase 14 | { 15 | public string ServiceName { get; private set; } 16 | public string FunctionName { get; private set; } 17 | 18 | public CreateTriggerMeta CreateTriggerMeta { get; set; } 19 | public Dictionary Headers { get; set; } 20 | 21 | public CreateTriggerRequest(string serviceName, string functionName, string triggerName, string triggerType, 22 | string sourceArn, string invocationRole, object triggerConfig, string description =null, string qualifier = null, Dictionary customHeaders = null) 23 | { 24 | Contract.Requires(string.IsNullOrEmpty(triggerType) == false); 25 | Contract.Requires(string.IsNullOrEmpty(triggerName) == false); 26 | Contract.Requires(string.IsNullOrEmpty(functionName) == false); 27 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 28 | this.ServiceName = serviceName; 29 | this.FunctionName = functionName; 30 | this.CreateTriggerMeta = new CreateTriggerMeta(triggerName, triggerType, sourceArn, invocationRole, triggerConfig, description, qualifier); 31 | this.Headers = customHeaders; 32 | } 33 | 34 | 35 | public string GetPath() 36 | { 37 | return string.Format(Const.TRIGGER_PATH, Const.API_VERSION, this.ServiceName, this.FunctionName); 38 | } 39 | 40 | public RestRequest GenHttpRequest(FCConfig cfg) 41 | { 42 | this.Config = cfg; 43 | this.Headers = this.BuildCommonHeaders("POST", this.GetPath(), this.Headers); 44 | var request = new RestRequest(this.GetPath(), Method.POST); 45 | 46 | foreach (var item in this.Headers) 47 | request.AddHeader(item.Key, item.Value); 48 | 49 | request.AddJsonBody(JsonConvert.SerializeObject(this.CreateTriggerMeta)); 50 | 51 | return request; 52 | 53 | } 54 | 55 | } 56 | } 57 | 58 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Function/CreateFunctionRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Config; 5 | using Aliyun.FunctionCompute.SDK.Constants; 6 | using Aliyun.FunctionCompute.SDK.model; 7 | using Newtonsoft.Json; 8 | using RestSharp; 9 | 10 | namespace Aliyun.FunctionCompute.SDK.Request 11 | { 12 | 13 | public class CreateFunctionRequest : RequestBase 14 | { 15 | public string ServiceName { get; set; } 16 | 17 | public CreateFunctionMeta CreateFunctionMeta { get; set; } 18 | public Dictionary Headers { get; set; } 19 | 20 | public CreateFunctionRequest(string serviceName, string functionName, string runtime, 21 | string handler, Code code, string desc = null, 22 | int memorySize=256, int timeout = 60, 23 | Dictionary env = null, 24 | string initializer = null, int initializationTimeout=30, 25 | Dictionary customHeaders = null) 26 | { 27 | Contract.Requires(code != null); 28 | Contract.Requires(string.IsNullOrEmpty(handler) == false); 29 | Contract.Requires(string.IsNullOrEmpty(runtime) == false); 30 | Contract.Requires(string.IsNullOrEmpty(functionName) == false); 31 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 32 | this.ServiceName = serviceName; 33 | this.CreateFunctionMeta = new CreateFunctionMeta(functionName, runtime, handler, code, desc, memorySize, timeout, env, initializer, initializationTimeout); 34 | this.Headers = customHeaders; 35 | } 36 | 37 | 38 | public string GetPath() 39 | { 40 | return string.Format(Const.FUNCTION_PATH, Const.API_VERSION, this.ServiceName); 41 | } 42 | 43 | public RestRequest GenHttpRequest(FCConfig cfg) 44 | { 45 | this.Config = cfg; 46 | this.Headers = this.BuildCommonHeaders("POST", this.GetPath(), this.Headers); 47 | var request = new RestRequest(this.GetPath(), Method.POST); 48 | 49 | foreach (var item in this.Headers) 50 | request.AddHeader(item.Key, item.Value); 51 | 52 | request.AddJsonBody(JsonConvert.SerializeObject(this.CreateFunctionMeta)); 53 | 54 | return request; 55 | 56 | } 57 | 58 | 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Service/ListServicesRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Aliyun.FunctionCompute.SDK.Config; 4 | using Aliyun.FunctionCompute.SDK.Constants; 5 | using RestSharp; 6 | 7 | namespace Aliyun.FunctionCompute.SDK.Request 8 | { 9 | public class ListServicesRequest : RequestBase, IRequestBase 10 | { 11 | public string Prefix { get; set; } 12 | public string StartKey { get; set; } 13 | public string NextToken { get; set; } 14 | public int Limit { get; set; } 15 | public Dictionary Tags { get; set; } 16 | 17 | public Dictionary Headers { get; set; } 18 | 19 | public ListServicesRequest(int limit=0, string prefix=null, string startKey=null, string nextToken=null, Dictionary customHeaders = null, Dictionary tags = null) 20 | { 21 | this.Limit = limit; 22 | this.Prefix = prefix; 23 | this.StartKey = startKey; 24 | this.NextToken = nextToken; 25 | this.Headers = customHeaders; 26 | this.Tags = tags; 27 | } 28 | 29 | public string GetPath() 30 | { 31 | return string.Format(Const.SERVICE_PATH, Const.API_VERSION); 32 | } 33 | 34 | public RestRequest GenHttpRequest(FCConfig cfg) 35 | { 36 | this.Config = cfg; 37 | this.Headers = this.BuildCommonHeaders("GET", this.GetPath(), this.Headers); 38 | var request = new RestRequest(this.GetPath(), Method.GET); 39 | 40 | foreach (var item in this.Headers) 41 | request.AddHeader(item.Key, item.Value); 42 | 43 | if (this.Limit > 0) request.AddQueryParameter("limit", this.Limit.ToString()); 44 | if (!string.IsNullOrEmpty(this.Prefix)) request.AddQueryParameter("prefix", this.Prefix); 45 | if (!string.IsNullOrEmpty(this.StartKey)) request.AddQueryParameter("startKey", this.StartKey); 46 | if (!string.IsNullOrEmpty(this.NextToken)) request.AddQueryParameter("nextToken", this.NextToken); 47 | 48 | if (this.Tags!= null && this.Tags.Count > 0) 49 | { 50 | foreach (var item in this.Tags) 51 | { 52 | request.AddQueryParameter("tag_" + item.Key, item.Value); 53 | } 54 | } 55 | 56 | return request; 57 | } 58 | 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Version/ListVersionsRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Config; 5 | using Aliyun.FunctionCompute.SDK.Constants; 6 | using RestSharp; 7 | 8 | namespace Aliyun.FunctionCompute.SDK.Request 9 | { 10 | public class ListVersionsRequest : RequestBase, IRequestBase 11 | { 12 | public string ServiceName { get; set; } 13 | public string Direction { get; set; } 14 | public string StartKey { get; set; } 15 | public string NextToken { get; set; } 16 | public int Limit { get; set; } 17 | 18 | public Dictionary Headers { get; set; } 19 | 20 | public const string LIST_DIRECTION_BACKWARD = "BACKWARD"; 21 | public const string LIST_DIRECTION_FORWARD = "FORWARD"; 22 | 23 | public ListVersionsRequest(string serviceName, int limit = 0, string startKey = null, string nextToken = null, string direction = LIST_DIRECTION_BACKWARD, Dictionary customHeaders = null) 24 | { 25 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 26 | this.ServiceName = serviceName; 27 | this.Limit = limit; 28 | this.Direction = direction; 29 | this.StartKey = startKey; 30 | this.NextToken = nextToken; 31 | this.Headers = customHeaders; 32 | } 33 | 34 | public string GetPath() 35 | { 36 | return string.Format(Const.SERVICE_VERSION_PATH, Const.API_VERSION, this.ServiceName); 37 | } 38 | 39 | public RestRequest GenHttpRequest(FCConfig cfg) 40 | { 41 | this.Config = cfg; 42 | this.Headers = this.BuildCommonHeaders("GET", this.GetPath(), this.Headers); 43 | var request = new RestRequest(this.GetPath(), Method.GET); 44 | 45 | foreach (var item in this.Headers) 46 | request.AddHeader(item.Key, item.Value); 47 | 48 | if (this.Limit > 0) request.AddQueryParameter("limit", this.Limit.ToString()); 49 | if (!string.IsNullOrEmpty(this.Direction)) request.AddQueryParameter("direction", this.Direction); 50 | if (!string.IsNullOrEmpty(this.StartKey)) request.AddQueryParameter("startKey", this.StartKey); 51 | if (!string.IsNullOrEmpty(this.NextToken)) request.AddQueryParameter("nextToken", this.NextToken); 52 | 53 | return request; 54 | } 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/model/TriggerMeta.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Newtonsoft.Json; 3 | 4 | namespace Aliyun.FunctionCompute.SDK.model 5 | { 6 | public class UpdateTriggerMeta 7 | { 8 | [JsonProperty("invocationRole")] 9 | public string InvocationRole { get; set; } 10 | 11 | [JsonProperty("triggerConfig")] 12 | public object TriggerConfig { get; set; } 13 | 14 | [JsonProperty("qualifier")] 15 | public string Qualifier { get; set; } 16 | 17 | [JsonProperty("description")] 18 | public string Description { get; set; } 19 | 20 | public UpdateTriggerMeta() { } 21 | 22 | public UpdateTriggerMeta(string invocationRole, object triggerConfig, string description = null, string qualifier = null) 23 | { 24 | this.InvocationRole = invocationRole; 25 | this.TriggerConfig = triggerConfig; 26 | this.Description = description; 27 | this.Qualifier = qualifier; 28 | } 29 | } 30 | 31 | public class CreateTriggerMeta: UpdateTriggerMeta 32 | { 33 | [JsonProperty("triggerName")] 34 | public string TriggerName { get; set; } 35 | 36 | [JsonProperty("sourceArn")] 37 | public string SourceArn { get; set; } 38 | 39 | [JsonProperty("triggerType")] 40 | public string TriggerType { get; set; } 41 | 42 | public CreateTriggerMeta() { } 43 | 44 | public CreateTriggerMeta(string triggerName, string triggerType, 45 | string sourceArn, string invocationRole, object triggerConfig, string description = null, string qualifier = null) 46 | :base(invocationRole, triggerConfig, description, qualifier) 47 | { 48 | this.TriggerName = triggerName; 49 | this.TriggerType = triggerType; 50 | this.SourceArn = sourceArn; 51 | } 52 | } 53 | 54 | 55 | public class TriggerMeta: CreateTriggerMeta 56 | { 57 | [JsonProperty("createdTime")] 58 | public string CreatedTime { get; set; } 59 | 60 | [JsonProperty("lastModifiedTime")] 61 | public string LastModifiedTime { get; set; } 62 | 63 | public TriggerMeta() { } 64 | public TriggerMeta(string triggerName, string triggerType, string sourceArn, string invocationRole, object triggerConfig, string description = null, string qualifier = null) : base(triggerName, triggerType, sourceArn, invocationRole, triggerConfig, description, qualifier) 65 | { 66 | } 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Trigger/ListTriggersRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Config; 5 | using Aliyun.FunctionCompute.SDK.Constants; 6 | using RestSharp; 7 | 8 | namespace Aliyun.FunctionCompute.SDK.Request 9 | { 10 | public class ListTriggersRequest : RequestBase, IRequestBase 11 | { 12 | public string ServiceName { get; set; } 13 | public string FunctionName { get; set; } 14 | public string Prefix { get; set; } 15 | public string StartKey { get; set; } 16 | public string NextToken { get; set; } 17 | public int Limit { get; set; } 18 | 19 | public Dictionary Headers { get; set; } 20 | 21 | public ListTriggersRequest(string serviceName, string functionName, int limit = 0, string prefix = null, string startKey = null, string nextToken = null, Dictionary customHeaders = null) 22 | { 23 | Contract.Requires(string.IsNullOrEmpty(functionName) == false); 24 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 25 | this.ServiceName = serviceName; 26 | this.FunctionName = functionName; 27 | this.Limit = limit; 28 | this.Prefix = prefix; 29 | this.StartKey = startKey; 30 | this.NextToken = nextToken; 31 | this.Headers = customHeaders; 32 | } 33 | 34 | public string GetPath() 35 | { 36 | return string.Format(Const.TRIGGER_PATH, Const.API_VERSION, this.ServiceName, this.FunctionName); 37 | } 38 | 39 | public RestRequest GenHttpRequest(FCConfig cfg) 40 | { 41 | this.Config = cfg; 42 | this.Headers = this.BuildCommonHeaders("GET", this.GetPath(), this.Headers); 43 | var request = new RestRequest(this.GetPath(), Method.GET); 44 | 45 | foreach (var item in this.Headers) 46 | request.AddHeader(item.Key, item.Value); 47 | 48 | if (this.Limit > 0) request.AddQueryParameter("limit", this.Limit.ToString()); 49 | if (!string.IsNullOrEmpty(this.Prefix)) request.AddQueryParameter("prefix", this.Prefix); 50 | if (!string.IsNullOrEmpty(this.StartKey)) request.AddQueryParameter("startKey", this.StartKey); 51 | if (!string.IsNullOrEmpty(this.NextToken)) request.AddQueryParameter("nextToken", this.NextToken); 52 | 53 | return request; 54 | } 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Instance/ListInstancesRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Config; 5 | using Aliyun.FunctionCompute.SDK.Constants; 6 | using Newtonsoft.Json; 7 | using RestSharp; 8 | 9 | namespace Aliyun.FunctionCompute.SDK.Request 10 | { 11 | public class ListInstancesRequest : RequestBase 12 | { 13 | public string ServiceName { get; set; } 14 | public string Qualifier { get; set; } 15 | public string FunctionName { get; set; } 16 | 17 | public int Limit { get; set; } 18 | public string[] InstanceIds { get; set; } 19 | 20 | public Dictionary Headers { get; set; } 21 | 22 | public ListInstancesRequest(string serviceName, string functionName, string qualifier = null, int limit = 0, string[] instanceIds = null, Dictionary customHeaders = null) 23 | { 24 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 25 | this.ServiceName = serviceName; 26 | this.FunctionName = functionName; 27 | this.Qualifier = qualifier; 28 | this.Limit = limit; 29 | this.InstanceIds = instanceIds; 30 | this.Headers = customHeaders; 31 | } 32 | 33 | public string GetPath() 34 | { 35 | if (string.IsNullOrEmpty(this.Qualifier)) 36 | { 37 | return string.Format(Const.SINGLE_INSTANCE_PATH, Const.API_VERSION, this.ServiceName, this.FunctionName); 38 | } 39 | else 40 | { 41 | return string.Format(Const.SINGLE_INSTANCE_WITH_QUALIFIER_PATH, Const.API_VERSION, this.ServiceName, this.Qualifier, this.FunctionName); 42 | } 43 | } 44 | 45 | public RestRequest GenHttpRequest(FCConfig cfg) 46 | { 47 | this.Config = cfg; 48 | this.Headers = this.BuildCommonHeaders("GET", this.GetPath(), this.Headers); 49 | var request = new RestRequest(this.GetPath(), Method.GET); 50 | 51 | foreach (var item in this.Headers) 52 | request.AddHeader(item.Key, item.Value); 53 | 54 | if (this.Limit > 0) request.AddQueryParameter("limit", this.Limit.ToString()); 55 | if (this.InstanceIds != null && this.InstanceIds.Length > 0) 56 | request.AddQueryParameter("instanceIds", JsonConvert.SerializeObject(this.InstanceIds)); 57 | 58 | return request; 59 | } 60 | 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Function/ListFunctionsRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using Aliyun.FunctionCompute.SDK.Config; 5 | using Aliyun.FunctionCompute.SDK.Constants; 6 | using RestSharp; 7 | 8 | namespace Aliyun.FunctionCompute.SDK.Request 9 | { 10 | public class ListFunctionsRequest : RequestBase 11 | { 12 | public string ServiceName { get; set; } 13 | public string Qualifier { get; set; } 14 | public string Prefix { get; set; } 15 | public string StartKey { get; set; } 16 | public string NextToken { get; set; } 17 | public int Limit { get; set; } 18 | 19 | public Dictionary Headers { get; set; } 20 | 21 | public ListFunctionsRequest(string serviceName, string qualifier = null, int limit = 0, string prefix = null, string startKey = null, string nextToken = null, Dictionary customHeaders = null) 22 | { 23 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 24 | this.ServiceName = serviceName; 25 | this.Qualifier = qualifier; 26 | this.Limit = limit; 27 | this.Prefix = prefix; 28 | this.StartKey = startKey; 29 | this.NextToken = nextToken; 30 | this.Headers = customHeaders; 31 | } 32 | 33 | public string GetPath() 34 | { 35 | if (string.IsNullOrEmpty(this.Qualifier)) 36 | { 37 | return string.Format(Const.FUNCTION_PATH, Const.API_VERSION, this.ServiceName); 38 | } 39 | else 40 | { 41 | return string.Format(Const.FUNCTION_WITH_QUALIFIER_PATH, Const.API_VERSION, this.ServiceName, this.Qualifier); 42 | } 43 | } 44 | 45 | public RestRequest GenHttpRequest(FCConfig cfg) 46 | { 47 | this.Config = cfg; 48 | this.Headers = this.BuildCommonHeaders("GET", this.GetPath(), this.Headers); 49 | var request = new RestRequest(this.GetPath(), Method.GET); 50 | 51 | foreach (var item in this.Headers) 52 | request.AddHeader(item.Key, item.Value); 53 | 54 | if (this.Limit > 0) request.AddQueryParameter("limit", this.Limit.ToString()); 55 | if (!string.IsNullOrEmpty(this.Prefix)) request.AddQueryParameter("prefix", this.Prefix); 56 | if (!string.IsNullOrEmpty(this.StartKey)) request.AddQueryParameter("startKey", this.StartKey); 57 | if (!string.IsNullOrEmpty(this.NextToken)) request.AddQueryParameter("nextToken", this.NextToken); 58 | 59 | return request; 60 | } 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /samples/fc-csharp-sdk-samples/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Aliyun.FunctionCompute.SDK.Client; 3 | using Aliyun.FunctionCompute.SDK.Request; 4 | using Aliyun.FunctionCompute.SDK.model; 5 | using System.IO; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | 9 | // more sample code can refrence 10 | // https://github.com/aliyun/fc-csharp-sdk/tree/master/Libraries/src/Aliyun.FunctionCompute.SDK.Unittests 11 | 12 | namespace fc_csharp_sdk_samples 13 | { 14 | class Program 15 | { 16 | 17 | static void Main(string[] args) 18 | { 19 | var fcClient = new FCClient("cn-shanghai", "", "", ""); 20 | var response1 = fcClient.CreateService(new CreateServiceRequest("csharp-service", "create by c# sdk")); 21 | Console.WriteLine(response1.Content); 22 | Console.WriteLine(response1.Data.ServiceName + "---" + response1.Data.Description); 23 | 24 | byte[] contents = File.ReadAllBytes(@"/Users/songluo/gitpro/fc-dotnet-sdk/Libraries/samples/hello2.zip"); 25 | var code = new Code(Convert.ToBase64String(contents)); 26 | var response2 = fcClient.CreateFunction(new CreateFunctionRequest("csharp-service", "csharp-function", "python3", "index.handler", code)); 27 | Console.WriteLine(response2.Content); 28 | 29 | byte[] payload = Encoding.UTF8.GetBytes("hello csharp world"); 30 | var response3 = fcClient.InvokeFunction(new InvokeFunctionRequest("csharp-service", "csharp-function", null, payload)); 31 | Console.WriteLine(response3.Content); 32 | 33 | var customHeaders = new Dictionary { 34 | {"x-fc-invocation-type", "Async"} 35 | }; 36 | var response4 = fcClient.InvokeFunction(new InvokeFunctionRequest("csharp-service", "csharp-function", null, payload, customHeaders)); 37 | Console.WriteLine(response4.StatusCode); 38 | 39 | var response5 = fcClient.CreateTrigger(new CreateTriggerRequest("csharp-service", "csharp-function", "my-http-trigger", "http", "dummy_arn", "", 40 | new HttpTriggerConfig(HttpAuthType.ANONYMOUS, new HttpMethod[] { HttpMethod.GET, HttpMethod.POST }))); 41 | Console.WriteLine(response5.Content); 42 | 43 | var response6 = fcClient.DeleteTrigger(new DeleteTriggerRequest("csharp-service", "csharp-function", "my-http-trigger")); 44 | Console.WriteLine(response6.StatusCode); 45 | 46 | var response7 = fcClient.DeleteFunction(new DeleteFunctionRequest("test", "fff2")); 47 | Console.WriteLine(response7.StatusCode); 48 | 49 | var response8 = fcClient.DeleteService(new DeleteServiceRequest("csharp")); 50 | Console.WriteLine(response8.StatusCode); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/model/CustomDomainMeta.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Newtonsoft.Json; 3 | 4 | namespace Aliyun.FunctionCompute.SDK.model 5 | { 6 | public class PathConfig 7 | { 8 | [JsonProperty("path")] 9 | public string Path { get; set; } 10 | 11 | [JsonProperty("serviceName")] 12 | public string ServiceName { get; set; } 13 | 14 | [JsonProperty("functionName")] 15 | public string FunctionName { get; set; } 16 | 17 | [JsonProperty("qualifier")] 18 | public string Qualifier { get; set; } 19 | } 20 | 21 | public class RouteConfig 22 | { 23 | [JsonProperty("routes")] 24 | public PathConfig[] Routes { get; set; } 25 | } 26 | 27 | public class CertConfig 28 | { 29 | [JsonProperty("certName")] 30 | public string CertName { get; set; } 31 | 32 | [JsonProperty("privateKey")] 33 | public string PrivateKey { get; set; } 34 | 35 | [JsonProperty("certificate")] 36 | public string Certificate { get; set; } 37 | 38 | } 39 | 40 | public class UpdateCustomDomainMeta 41 | { 42 | [JsonProperty("protocol")] 43 | public string Protocol { get; set; } 44 | 45 | [JsonProperty("apiVersion")] 46 | public string ApiVersion { get; set; } 47 | 48 | [JsonProperty("routeConfig")] 49 | public RouteConfig RouteConfig { get; set; } 50 | 51 | [JsonProperty("certConfig")] 52 | public CertConfig CertConfig { get; set; } 53 | 54 | public UpdateCustomDomainMeta() 55 | { 56 | } 57 | 58 | public UpdateCustomDomainMeta(string protocal=null, string apiVersion=null, RouteConfig routeConfig =null, CertConfig certConfig = null) 59 | { 60 | this.Protocol = protocal; 61 | this.ApiVersion = apiVersion; 62 | this.RouteConfig = routeConfig; 63 | this.CertConfig = certConfig; 64 | } 65 | } 66 | 67 | public class CreateCustomDomainMeta : UpdateCustomDomainMeta 68 | { 69 | [JsonProperty("domainName")] 70 | public string DomainName { get; set; } 71 | 72 | 73 | public CreateCustomDomainMeta() 74 | { 75 | } 76 | 77 | public CreateCustomDomainMeta(string domainName, string protocal = null, string apiVersion = null, RouteConfig routeConfig = null, CertConfig certConfig = null) : 78 | base(protocal,apiVersion ,routeConfig, certConfig) 79 | { 80 | this.DomainName = domainName; 81 | } 82 | } 83 | 84 | 85 | public class CustomDomainMeta: CreateCustomDomainMeta 86 | { 87 | [JsonProperty("createdTime")] 88 | public string CreatedTime { get; set; } 89 | 90 | [JsonProperty("lastModifiedTime")] 91 | public string LastModifiedTime { get; set; } 92 | 93 | public CustomDomainMeta() 94 | { 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /samples/samples.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26124.0 5 | MinimumVisualStudioVersion = 15.0.26124.0 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "fc-csharp-sdk-samples", "fc-csharp-sdk-samples\fc-csharp-sdk-samples.csproj", "{C5BB7FE7-11C5-41ED-B584-38A80C5F6E40}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "fc-code-samples", "fc-code-samples\fc-code-samples.csproj", "{36D54CBD-E04C-4A5C-BAB8-E53C39451694}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|x64 = Debug|x64 14 | Debug|x86 = Debug|x86 15 | Release|Any CPU = Release|Any CPU 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 23 | {C5BB7FE7-11C5-41ED-B584-38A80C5F6E40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 24 | {C5BB7FE7-11C5-41ED-B584-38A80C5F6E40}.Debug|Any CPU.Build.0 = Debug|Any CPU 25 | {C5BB7FE7-11C5-41ED-B584-38A80C5F6E40}.Debug|x64.ActiveCfg = Debug|Any CPU 26 | {C5BB7FE7-11C5-41ED-B584-38A80C5F6E40}.Debug|x64.Build.0 = Debug|Any CPU 27 | {C5BB7FE7-11C5-41ED-B584-38A80C5F6E40}.Debug|x86.ActiveCfg = Debug|Any CPU 28 | {C5BB7FE7-11C5-41ED-B584-38A80C5F6E40}.Debug|x86.Build.0 = Debug|Any CPU 29 | {C5BB7FE7-11C5-41ED-B584-38A80C5F6E40}.Release|Any CPU.ActiveCfg = Release|Any CPU 30 | {C5BB7FE7-11C5-41ED-B584-38A80C5F6E40}.Release|Any CPU.Build.0 = Release|Any CPU 31 | {C5BB7FE7-11C5-41ED-B584-38A80C5F6E40}.Release|x64.ActiveCfg = Release|Any CPU 32 | {C5BB7FE7-11C5-41ED-B584-38A80C5F6E40}.Release|x64.Build.0 = Release|Any CPU 33 | {C5BB7FE7-11C5-41ED-B584-38A80C5F6E40}.Release|x86.ActiveCfg = Release|Any CPU 34 | {C5BB7FE7-11C5-41ED-B584-38A80C5F6E40}.Release|x86.Build.0 = Release|Any CPU 35 | {36D54CBD-E04C-4A5C-BAB8-E53C39451694}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 36 | {36D54CBD-E04C-4A5C-BAB8-E53C39451694}.Debug|Any CPU.Build.0 = Debug|Any CPU 37 | {36D54CBD-E04C-4A5C-BAB8-E53C39451694}.Debug|x64.ActiveCfg = Debug|Any CPU 38 | {36D54CBD-E04C-4A5C-BAB8-E53C39451694}.Debug|x64.Build.0 = Debug|Any CPU 39 | {36D54CBD-E04C-4A5C-BAB8-E53C39451694}.Debug|x86.ActiveCfg = Debug|Any CPU 40 | {36D54CBD-E04C-4A5C-BAB8-E53C39451694}.Debug|x86.Build.0 = Debug|Any CPU 41 | {36D54CBD-E04C-4A5C-BAB8-E53C39451694}.Release|Any CPU.ActiveCfg = Release|Any CPU 42 | {36D54CBD-E04C-4A5C-BAB8-E53C39451694}.Release|Any CPU.Build.0 = Release|Any CPU 43 | {36D54CBD-E04C-4A5C-BAB8-E53C39451694}.Release|x64.ActiveCfg = Release|Any CPU 44 | {36D54CBD-E04C-4A5C-BAB8-E53C39451694}.Release|x64.Build.0 = Release|Any CPU 45 | {36D54CBD-E04C-4A5C-BAB8-E53C39451694}.Release|x86.ActiveCfg = Release|Any CPU 46 | {36D54CBD-E04C-4A5C-BAB8-E53C39451694}.Release|x86.Build.0 = Release|Any CPU 47 | EndGlobalSection 48 | EndGlobal 49 | -------------------------------------------------------------------------------- /Libraries/Aliyun.FunctionCompute.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26124.0 5 | MinimumVisualStudioVersion = 15.0.26124.0 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aliyun.FunctionCompute.SDK", "src\Aliyun.FunctionCompute.SDK\Aliyun.FunctionCompute.SDK.csproj", "{D35783B3-C5C6-4B7D-834B-825642FD98FF}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aliyun.FunctionCompute.SDK.Unittests", "src\Aliyun.FunctionCompute.SDK.Unittests\Aliyun.FunctionCompute.SDK.Unittests.csproj", "{52DF4CD2-7BBA-42E5-B702-F8559290477C}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|x64 = Debug|x64 14 | Debug|x86 = Debug|x86 15 | Release|Any CPU = Release|Any CPU 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 23 | {D35783B3-C5C6-4B7D-834B-825642FD98FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 24 | {D35783B3-C5C6-4B7D-834B-825642FD98FF}.Debug|Any CPU.Build.0 = Debug|Any CPU 25 | {D35783B3-C5C6-4B7D-834B-825642FD98FF}.Debug|x64.ActiveCfg = Debug|Any CPU 26 | {D35783B3-C5C6-4B7D-834B-825642FD98FF}.Debug|x64.Build.0 = Debug|Any CPU 27 | {D35783B3-C5C6-4B7D-834B-825642FD98FF}.Debug|x86.ActiveCfg = Debug|Any CPU 28 | {D35783B3-C5C6-4B7D-834B-825642FD98FF}.Debug|x86.Build.0 = Debug|Any CPU 29 | {D35783B3-C5C6-4B7D-834B-825642FD98FF}.Release|Any CPU.ActiveCfg = Release|Any CPU 30 | {D35783B3-C5C6-4B7D-834B-825642FD98FF}.Release|Any CPU.Build.0 = Release|Any CPU 31 | {D35783B3-C5C6-4B7D-834B-825642FD98FF}.Release|x64.ActiveCfg = Release|Any CPU 32 | {D35783B3-C5C6-4B7D-834B-825642FD98FF}.Release|x64.Build.0 = Release|Any CPU 33 | {D35783B3-C5C6-4B7D-834B-825642FD98FF}.Release|x86.ActiveCfg = Release|Any CPU 34 | {D35783B3-C5C6-4B7D-834B-825642FD98FF}.Release|x86.Build.0 = Release|Any CPU 35 | {52DF4CD2-7BBA-42E5-B702-F8559290477C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 36 | {52DF4CD2-7BBA-42E5-B702-F8559290477C}.Debug|Any CPU.Build.0 = Debug|Any CPU 37 | {52DF4CD2-7BBA-42E5-B702-F8559290477C}.Debug|x64.ActiveCfg = Debug|Any CPU 38 | {52DF4CD2-7BBA-42E5-B702-F8559290477C}.Debug|x64.Build.0 = Debug|Any CPU 39 | {52DF4CD2-7BBA-42E5-B702-F8559290477C}.Debug|x86.ActiveCfg = Debug|Any CPU 40 | {52DF4CD2-7BBA-42E5-B702-F8559290477C}.Debug|x86.Build.0 = Debug|Any CPU 41 | {52DF4CD2-7BBA-42E5-B702-F8559290477C}.Release|Any CPU.ActiveCfg = Release|Any CPU 42 | {52DF4CD2-7BBA-42E5-B702-F8559290477C}.Release|Any CPU.Build.0 = Release|Any CPU 43 | {52DF4CD2-7BBA-42E5-B702-F8559290477C}.Release|x64.ActiveCfg = Release|Any CPU 44 | {52DF4CD2-7BBA-42E5-B702-F8559290477C}.Release|x64.Build.0 = Release|Any CPU 45 | {52DF4CD2-7BBA-42E5-B702-F8559290477C}.Release|x86.ActiveCfg = Release|Any CPU 46 | {52DF4CD2-7BBA-42E5-B702-F8559290477C}.Release|x86.Build.0 = Release|Any CPU 47 | EndGlobalSection 48 | EndGlobal 49 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Request/Function/HttpInvokeFunctionRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using System.Text.RegularExpressions; 5 | using Aliyun.FunctionCompute.SDK.Config; 6 | using Aliyun.FunctionCompute.SDK.Constants; 7 | using RestSharp; 8 | 9 | namespace Aliyun.FunctionCompute.SDK.Request 10 | { 11 | public class HttpInvokeFunctionRequest : RequestBase 12 | { 13 | 14 | public string ServiceName { get; set; } 15 | public string FunctionName { get; set; } 16 | public string Qualifier { get; set; } 17 | public string RequestMethod { get; set; } 18 | private string path; 19 | public Dictionary Headers { get; set; } 20 | public byte[] Payload { get; set; } 21 | public Dictionary UnescapedQueries { get; set; } 22 | public string Path { get => path ?? "/"; set => path = value; } 23 | 24 | public HttpInvokeFunctionRequest(string serviceName, string functionName, string method, string path = null, string qualifier = null, byte[] payload = null, 25 | Dictionary unescapedQueries =null , Dictionary customHeaders = null) 26 | { 27 | Contract.Requires(string.IsNullOrEmpty(method) == false); 28 | Contract.Requires(string.IsNullOrEmpty(functionName) == false); 29 | Contract.Requires(string.IsNullOrEmpty(serviceName) == false); 30 | this.ServiceName = serviceName; 31 | this.FunctionName = functionName; 32 | this.Qualifier = qualifier; 33 | this.RequestMethod = method; 34 | this.Path = path; 35 | this.Payload = payload; 36 | this.UnescapedQueries = unescapedQueries; 37 | this.Headers = customHeaders; 38 | } 39 | 40 | public string GetPath() 41 | { 42 | string _path = this.Path; 43 | if (this.Path.StartsWith("/", StringComparison.Ordinal)) 44 | { 45 | _path = this.Path.Substring(1); 46 | } 47 | if (string.IsNullOrEmpty(this.Qualifier)) 48 | { 49 | return string.Format(Const.HTTP_INVOKE_FUNCTION_PATH, Const.API_VERSION, this.ServiceName, 50 | this.FunctionName, _path); 51 | } 52 | else 53 | { 54 | return string.Format(Const.HTTP_INVOKE_FUNCTION_WITH_QUALIFIER_PATH, Const.API_VERSION, 55 | this,ServiceName, this.Qualifier, this.FunctionName, _path); 56 | } 57 | } 58 | 59 | public RestRequest GenHttpRequest(FCConfig cfg) 60 | { 61 | this.Config = cfg; 62 | this.Headers = this.BuildCommonHeaders(this.RequestMethod, Regex.Unescape(this.GetPath()), this.Headers, UnescapedQueries); 63 | var request = new RestRequest(this.GetPath(), (Method)Enum.Parse(typeof(Method), this.RequestMethod)); 64 | 65 | foreach (var item in this.Headers) 66 | request.AddHeader(item.Key, item.Value); 67 | 68 | if (this.UnescapedQueries != null) 69 | { 70 | foreach (var item in this.UnescapedQueries) 71 | foreach (var query in item.Value) 72 | request.AddQueryParameter(item.Key, query); 73 | } 74 | 75 | request.AddParameter("application/octet-stream", this.Payload, ParameterType.RequestBody); 76 | 77 | return request; 78 | } 79 | } 80 | } 81 | 82 | -------------------------------------------------------------------------------- /samples/fc-exec-samples/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Aliyun.FunctionCompute.SDK.Client; 3 | using Aliyun.FunctionCompute.SDK.Request; 4 | using Aliyun.FunctionCompute.SDK.Response; 5 | using Aliyun.FunctionCompute.SDK.model; 6 | using Aliyun.FunctionCompute.SDK.Constants; 7 | using System.IO; 8 | using System.Collections.Generic; 9 | using System.Text; 10 | 11 | // more sample code can refrence 12 | // https://github.com/aliyun/fc-csharp-sdk/tree/master/Libraries/src/Aliyun.FunctionCompute.SDK.Unittests 13 | 14 | 15 | namespace fc_csharp_sdk_samples 16 | { 17 | class Program 18 | { 19 | public static readonly string ACCOUNT_ID = Environment.GetEnvironmentVariable("ACCOUNT_ID"); 20 | public static readonly string ACCESS_KEY_ID = Environment.GetEnvironmentVariable("ACCESS_KEY_ID"); 21 | public static readonly string ACCESS_KEY_SECRET = Environment.GetEnvironmentVariable("ACCESS_KEY_SECRET"); 22 | public static readonly string REGION = Environment.GetEnvironmentVariable("REGION"); 23 | public static readonly string FC_ENDPOINT = Environment.GetEnvironmentVariable("FC_ENDPOINT"); 24 | public static readonly string serviceName = Environment.GetEnvironmentVariable("serviceName"); 25 | public static readonly string functionName = Environment.GetEnvironmentVariable("functionName"); 26 | public static readonly string qualifier = Environment.GetEnvironmentVariable("qualifier"); 27 | 28 | static void Main(string[] args) 29 | { 30 | Console.WriteLine(ACCOUNT_ID); 31 | Console.WriteLine(REGION); 32 | var fcClient = new FCClient(REGION, ACCOUNT_ID, ACCESS_KEY_ID, ACCESS_KEY_SECRET); 33 | fcClient.SetEndpoint("http://1011863232026330.dev-cluster-1.test.fc.aliyun-inc.com"); 34 | 35 | var resp = fcClient.ListInstances(new ListInstancesRequest(serviceName, functionName, qualifier)); 36 | Console.WriteLine(resp.Data); 37 | 38 | var insid = ""; 39 | if (resp.Data != null && resp.Data.Instances != null) 40 | { 41 | foreach (var instance in resp.Data.Instances) 42 | { 43 | Console.WriteLine(instance.InstanceId, instance.VersionId); 44 | insid = instance.InstanceId; 45 | } 46 | 47 | if (insid != "") 48 | { 49 | var execResp = fcClient.InstanceExec(new InstanceExecRequest(serviceName, functionName, insid, new string[] { "/bin/bash" }), new Callback()); 50 | 51 | execResp.Start(); 52 | } 53 | 54 | } 55 | } 56 | } 57 | 58 | class Callback : ExecCallback 59 | { 60 | public void OnOpen(ExecWebSocket ws) 61 | { 62 | ws.Send(Encoding.UTF8.GetBytes("ls\r")); 63 | Thread.Sleep(1000); 64 | ws.Send(Encoding.UTF8.GetBytes("exit\r")); 65 | Thread.Sleep(1000); 66 | } 67 | public void OnStdout(ExecWebSocket ws, byte[] msg) 68 | { 69 | Console.WriteLine("stdout({0}): {1}", msg.Length, Encoding.UTF8.GetString(msg)); 70 | } 71 | public void OnStderr(ExecWebSocket ws, byte[] msg) 72 | { 73 | Console.WriteLine("stderr({0}): {1}", msg.Length, Encoding.UTF8.GetString(msg)); 74 | } 75 | public void OnServerErr(ExecWebSocket ws, byte[] msg) 76 | { 77 | Console.WriteLine("server error({0}): {1}", msg.Length, Encoding.UTF8.GetString(msg)); 78 | } 79 | public void OnClose(ExecWebSocket ws) 80 | { 81 | Console.WriteLine("Close"); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK.Unittests/TestConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using Aliyun.FunctionCompute.SDK.Client; 4 | using Aliyun.FunctionCompute.SDK.model; 5 | 6 | namespace Aliyun.FunctionCompute.SDK.Unittests 7 | { 8 | public class TestConfig 9 | { 10 | public TestConfig() 11 | { 12 | this.VpcId = Environment.GetEnvironmentVariable("VPC_ID"); 13 | this.VSwitchIds = Environment.GetEnvironmentVariable("VSWITCH_IDS"); 14 | this.SecurityGroupId = Environment.GetEnvironmentVariable("SECURITY_GROUP_ID"); 15 | this.VpcRole = Environment.GetEnvironmentVariable("VPC_ROLE"); 16 | this.UserId = Environment.GetEnvironmentVariable("USER_ID"); 17 | this.GroupId = Environment.GetEnvironmentVariable("GROUP_ID"); 18 | this.NasServerAddr = Environment.GetEnvironmentVariable("NAS_SERVER_ADDR"); 19 | this.NasMountDir = Environment.GetEnvironmentVariable("NAS_MOUNT_DIR"); 20 | this.ServiceRole = Environment.GetEnvironmentVariable("SERVICE_ROLE"); 21 | this.LogProject = Environment.GetEnvironmentVariable("LOG_PROJECT"); 22 | this.LogStore = Environment.GetEnvironmentVariable("LOG_STORE"); 23 | this.AccountID = Environment.GetEnvironmentVariable("ACCOUNT_ID"); 24 | this.DomainName = "pythonSDK.cn-hongkong.1221968287646227.cname-test.fc.aliyun-inc.com"; 25 | this.InvocationRole = Environment.GetEnvironmentVariable("INVOCATION_ROLE"); 26 | this.Region = Environment.GetEnvironmentVariable("REGION"); 27 | this.CodeBucket = Environment.GetEnvironmentVariable("CODE_BUCKET"); 28 | this.RdsInstanceId = "rm-j6c2938h95da19vmi"; 29 | 30 | this.Client = new FCClient( 31 | Environment.GetEnvironmentVariable("REGION"), 32 | this.AccountID, 33 | Environment.GetEnvironmentVariable("ACCESS_KEY_ID"), 34 | Environment.GetEnvironmentVariable("ACCESS_KEY_SECRET") 35 | ); 36 | 37 | this.NasConfig = new NasConfig 38 | { 39 | UserId = int.Parse(this.UserId), 40 | GroupId = int.Parse(this.GroupId), 41 | MountPoints = new MountPointsItem[] { 42 | new MountPointsItem { ServerAddr= this.NasServerAddr, MountDir=this.NasMountDir } 43 | } 44 | }; 45 | 46 | this.LogConfig = new LogConfig 47 | { 48 | Project = this.LogProject, 49 | Logstore = this.LogStore 50 | }; 51 | 52 | this.VpcConfig = new VpcConfig 53 | { 54 | VpcId = this.VpcId, 55 | VSwitchIds = new string[] { this.VSwitchIds }, 56 | SecurityGroupId= this.SecurityGroupId 57 | }; 58 | 59 | } 60 | 61 | private static Random myRandom = new Random(); 62 | public static string RandomString(int length) 63 | { 64 | const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; 65 | return new string(Enumerable.Repeat(chars, length) 66 | .Select(s => s[myRandom.Next(s.Length)]).ToArray()); 67 | } 68 | 69 | public string VpcId { get; } 70 | public string VSwitchIds { get; } 71 | public string SecurityGroupId { get;} 72 | public string VpcRole { get; } 73 | public string UserId { get; } 74 | public string GroupId { get;} 75 | public string NasServerAddr { get;} 76 | public string NasMountDir { get; } 77 | public string ServiceRole { get; } 78 | public string LogProject { get; } 79 | public string LogStore { get; } 80 | public string AccountID { get; } 81 | public string DomainName { get; } 82 | public string InvocationRole { get; } 83 | public string Region { get; } 84 | public string CodeBucket { get; } 85 | public string RdsInstanceId { get; } 86 | public FCClient Client { get; private set; } 87 | public NasConfig NasConfig { get; } 88 | public LogConfig LogConfig { get; } 89 | public VpcConfig VpcConfig { get; } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /samples/fc-code-samples/SimpleHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | using Aliyun.Serverless.Core; 6 | using Microsoft.Extensions.Logging; 7 | using Aliyun.OSS; 8 | 9 | namespace fc_code_samples 10 | { 11 | class Program 12 | { 13 | static void Main(string[] args) 14 | { 15 | Console.WriteLine("Hello World!"); 16 | } 17 | } 18 | 19 | public class Product 20 | { 21 | public int Id { get; set; } 22 | public string Description { get; set; } 23 | } 24 | 25 | 26 | public class OssFileHandlerRequest 27 | { 28 | public string Bucket; 29 | public string Key; 30 | public string Endpoint; 31 | } 32 | 33 | public class TestHandler 34 | { 35 | public async Task AsyncEchoEvent(Stream input, IFcContext context) 36 | { 37 | context.Logger.LogInformation("Handle request: {0}", context.RequestId); 38 | MemoryStream copy = new MemoryStream(); 39 | await input.CopyToAsync(copy); 40 | copy.Seek(0, SeekOrigin.Begin); 41 | return copy; 42 | } 43 | 44 | public async Task AsyncEchoEventNoContext(Stream input) 45 | { 46 | MemoryStream copy = new MemoryStream(); 47 | await input.CopyToAsync(copy); 48 | copy.Seek(0, SeekOrigin.Begin); 49 | return copy; 50 | } 51 | 52 | public Stream TestLogger(Stream input, IFcContext context) 53 | { 54 | context.Logger.EnabledLogLevel = LogLevel.Error; 55 | context.Logger.LogError("console error 1"); 56 | context.Logger.LogInformation("console info 1"); 57 | context.Logger.LogWarning("console warn 1"); 58 | context.Logger.LogDebug("console debug 1"); 59 | 60 | context.Logger.EnabledLogLevel = LogLevel.Warning; 61 | 62 | context.Logger.LogError("console error 2"); 63 | context.Logger.LogInformation("console info 2"); 64 | context.Logger.LogWarning("console warn 2"); 65 | context.Logger.LogDebug("console debug 2"); 66 | 67 | context.Logger.EnabledLogLevel = LogLevel.Information; 68 | context.Logger.LogInformation("Handle request: {0}", context.RequestId); 69 | 70 | byte[] hello = Encoding.UTF8.GetBytes("hello world"); 71 | MemoryStream output = new MemoryStream(); 72 | output.Write(hello, 0, hello.Length); 73 | output.Seek(0, SeekOrigin.Begin); 74 | return output; 75 | } 76 | 77 | public Stream EchoEventNoContext(Stream input) 78 | { 79 | byte[] hello = Encoding.UTF8.GetBytes("hello world"); 80 | MemoryStream output = new MemoryStream(); 81 | output.Write(hello, 0, hello.Length); 82 | output.Seek(0, SeekOrigin.Begin); 83 | return output; 84 | } 85 | 86 | // optional serializer class, if it’s not specified, the default serializer (based on JSON.Net) will be used. 87 | // [FcSerializer(typeof(MySerialization))] 88 | public Product EchoPoco(Product product, IFcContext context) 89 | { 90 | int Id = product.Id; 91 | string Description = product.Description; 92 | context.Logger.LogInformation("Id {0}, Description {1}", Id, Description); 93 | return product; 94 | } 95 | 96 | public Stream GetOssFile(OssFileHandlerRequest req, IFcContext context) 97 | { 98 | if (req == null) 99 | { 100 | throw new ArgumentNullException(nameof(req)); 101 | } 102 | if (context == null || context.Credentials == null) 103 | { 104 | throw new ArgumentNullException(nameof(context)); 105 | } 106 | OssClient ossClient = new OssClient(req.Endpoint, context.Credentials.AccessKeyId, context.Credentials.AccessKeySecret, context.Credentials.SecurityToken); 107 | OssObject obj = ossClient.GetObject(req.Bucket, req.Key); 108 | return obj.Content; 109 | } 110 | } 111 | } 112 | 113 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Constants/Const.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace Aliyun.FunctionCompute.SDK.Constants 3 | { 4 | public static class Const 5 | { 6 | public static readonly string ENDPOINT_FMT = "{0}.{1}.fc.aliyuncs.com"; 7 | 8 | public static readonly string ACCOUNT_SETTING_PATH = "/{0}/account-settings"; 9 | 10 | public static readonly string SERVICE_PATH = "/{0}/services"; 11 | public static readonly string PROVISION_CONFIGS_PATH = "/{0}/provision-configs"; 12 | 13 | public static readonly string SINGLE_SERVICE_PATH = SERVICE_PATH + "/{1}"; 14 | public static readonly string FUNCTION_PATH = SINGLE_SERVICE_PATH + "/functions"; 15 | public static readonly string SINGLE_FUNCTION_PATH = FUNCTION_PATH + "/{2}"; 16 | public static readonly string SINGLE_INSTANCE_PATH = SINGLE_FUNCTION_PATH + "/instances"; 17 | public static readonly string INSTACE_PATH = SINGLE_INSTANCE_PATH + "/{3}"; 18 | public static readonly string SINGLE_INSTANCE_EXEC_PATH = INSTACE_PATH + "/exec"; 19 | 20 | public static readonly string CUSTOM_DOMAIN_PATH = "/{0}/custom-domains"; 21 | public static readonly string SINGLE_CUSTOM_DOMAIN_PATH = CUSTOM_DOMAIN_PATH + "/{1}"; 22 | public static readonly string SERVICE_VERSION_PATH = SINGLE_SERVICE_PATH + "/versions"; 23 | public static readonly string SINGLE_VERSION_PATH = SERVICE_VERSION_PATH + "/{2}"; 24 | public static readonly string ALIAS_PATH = SINGLE_SERVICE_PATH + "/aliases"; 25 | public static readonly string SINGLE_ALIAS_PATH = ALIAS_PATH + "/{2}"; 26 | public static readonly string TAG_PATH = "/{0}/tag"; 27 | public static readonly string RESERVED_CAPACITY_PATH = "/{0}/reservedCapacities"; 28 | 29 | public static readonly string FUNCTION_CODE_PATH = SINGLE_FUNCTION_PATH + "/code"; 30 | public static readonly string TRIGGER_PATH = SINGLE_FUNCTION_PATH + "/triggers"; 31 | public static readonly string SINGLE_TRIGGER_PATH = TRIGGER_PATH + "/{3}"; 32 | public static readonly string INVOKE_FUNCTION_PATH = SINGLE_FUNCTION_PATH + "/invocations"; 33 | public static readonly string HTTP_INVOKE_FUNCTION_PATH = "/{0}/proxy/{1}/{2}/{3}"; 34 | public static readonly string HTTP_INVOKE_FUNCTION_WITH_QUALIFIER_PATH = "/{0}/proxy/{1}.{2}/{3}/{4}"; 35 | 36 | public static readonly string SINGLE_SERVICE_WITH_QUALIFIER_PATH = SERVICE_PATH + "/{1}.{2}"; 37 | public static readonly string FUNCTION_WITH_QUALIFIER_PATH = SINGLE_SERVICE_WITH_QUALIFIER_PATH + "/functions"; 38 | public static readonly string SINGLE_FUNCTION_WITH_QUALIFIER_PATH = FUNCTION_WITH_QUALIFIER_PATH + "/{3}"; 39 | public static readonly string SINGLE_INSTANCE_WITH_QUALIFIER_PATH = SINGLE_FUNCTION_WITH_QUALIFIER_PATH + "/instances"; 40 | public static readonly string INSTACE_WITH_QUALIFIER_PATH = SINGLE_FUNCTION_WITH_QUALIFIER_PATH + "/{4}"; 41 | public static readonly string SINGLE_INSTANCE_EXEC_WITH_QUALIFIER_PATH = INSTACE_WITH_QUALIFIER_PATH + "/exec"; 42 | 43 | public static readonly string FUNCTION_CODE_WITH_QUALIFIER_PATH = SINGLE_FUNCTION_WITH_QUALIFIER_PATH + "/code"; 44 | public static readonly string INVOKE_FUNCTION_WITH_QUALIFIER_PATH = SINGLE_FUNCTION_WITH_QUALIFIER_PATH + "/invocations"; 45 | 46 | public static readonly string SINGLE_PROVISION_CONFIG_PATH = SINGLE_FUNCTION_WITH_QUALIFIER_PATH + "/provision-config"; 47 | 48 | public static readonly string ASYNC_CONFIG_PATH = SINGLE_FUNCTION_PATH + "/async-invoke-config"; 49 | public static readonly string ASYNC_CONFIG_WITH_QUALIFIER_PATH = SINGLE_FUNCTION_WITH_QUALIFIER_PATH + "/async-invoke-config"; 50 | public static readonly string LIST_ASYNC_CONFIGS_PATH = SINGLE_FUNCTION_PATH + "/async-invoke-configs"; 51 | 52 | /* 53 | * 3 seconds 54 | * 55 | * Used for http request connect timeout 56 | */ 57 | public static readonly int CONNECT_TIMEOUT = 60 * 1000; 58 | 59 | /* 60 | * 10 minutes 3 seconds 61 | * 62 | * Used for http request read timeout 63 | */ 64 | public static readonly int READ_TIMEOUT = 10 * 60 * 1000 + 3000; 65 | 66 | public static readonly string API_VERSION = "2016-08-15"; 67 | public static readonly string INVOCATION_TYPE_ASYNC = "Async"; 68 | public static readonly string INVOCATION_TYPE_HTTP = "http"; 69 | public static readonly string IF_MATCH_HEADER = "If-Match"; 70 | 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK/Response/Instance/InstanceExecResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net.WebSockets; 4 | using System.IO; 5 | using System.Threading; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using Aliyun.FunctionCompute.SDK.Request; 9 | using Newtonsoft.Json; 10 | 11 | namespace Aliyun.FunctionCompute.SDK.Response 12 | { 13 | public class InstanceExecResponse : ExecWebSocket 14 | { 15 | const byte STDIN = 0; 16 | const byte STDOUT = 1; 17 | const byte STDERR = 2; 18 | const byte SYSERR = 3; 19 | 20 | public string Content { get; set; } 21 | public Dictionary Headers { get; set; } 22 | public int StatusCode { get; set; } 23 | 24 | public InstancesResponseData Data { get; set; } 25 | 26 | private Uri uri { get; set; } 27 | private ClientWebSocket websocket { get; } 28 | private ExecCallback callback { get; } 29 | 30 | public InstanceExecResponse(ClientWebSocket websocket, string uri, ExecCallback callback) 31 | { 32 | this.Data = new InstancesResponseData(); 33 | this.Headers = new Dictionary { }; 34 | 35 | this.websocket = websocket; 36 | this.callback = callback; 37 | this.uri = new Uri(uri); 38 | } 39 | 40 | public void Start() 41 | { 42 | this.websocket.ConnectAsync(this.uri, CancellationToken.None).Wait(); 43 | 44 | var task = new Task(() => 45 | { 46 | this.callback.OnOpen(this); 47 | }); 48 | task.Start(); 49 | 50 | using (var ms = new MemoryStream()) 51 | { 52 | while (this.websocket.State == WebSocketState.Open) 53 | { 54 | WebSocketReceiveResult result; 55 | do 56 | { 57 | var messageBuffer = WebSocket.CreateClientBuffer(16, 16); 58 | var recv = this.websocket.ReceiveAsync(messageBuffer, CancellationToken.None); 59 | recv.Wait(); 60 | result = recv.Result; 61 | ms.Write(messageBuffer.Array, messageBuffer.Offset, result.Count); 62 | } 63 | while (!result.EndOfMessage); 64 | 65 | var data = ms.ToArray(); 66 | if (data.Length > 0) 67 | { 68 | var messageType = data[0]; 69 | var msg = new byte[data.Length - 1]; 70 | for (var i = 1; i < data.Length; i++) 71 | msg[i - 1] = data[i]; 72 | 73 | Array.Copy(data, 1, msg, 0, data.Length - 1); 74 | switch (messageType) 75 | { 76 | case STDOUT: 77 | this.callback.OnStdout(this, msg); 78 | break; 79 | case STDERR: 80 | this.callback.OnStderr(this, msg); 81 | break; 82 | case SYSERR: 83 | this.callback.OnServerErr(this, msg); 84 | break; 85 | } 86 | } 87 | 88 | ms.Seek(0, SeekOrigin.Begin); 89 | ms.Position = 0; 90 | ms.SetLength(0); 91 | } 92 | this.callback.OnClose(this); 93 | } 94 | } 95 | 96 | public void Send(byte[] msg) 97 | { 98 | byte[] buf = new byte[msg.Length + 1]; 99 | buf[0] = STDIN; 100 | msg.CopyTo(buf, 1); 101 | this.websocket.SendAsync(new ArraySegment(buf), WebSocketMessageType.Text, true, System.Threading.CancellationToken.None).Wait(); 102 | } 103 | 104 | public void Close() 105 | { 106 | this.websocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None).Wait(); 107 | } 108 | 109 | public void SetStatusContent(string content, int status, byte[] rawBytes) 110 | { 111 | this.StatusCode = status; 112 | this.Content = content; 113 | if (status < 300) 114 | this.Data = JsonConvert.DeserializeObject(this.Content); 115 | } 116 | 117 | public void SetHeaders(Dictionary headers) 118 | { 119 | this.Headers = headers; 120 | } 121 | 122 | public string GetRequestID() 123 | { 124 | return this.Headers[Constants.HeaderKeys.REQUEST_ID].ToString(); 125 | } 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /ReadMe.md: -------------------------------------------------------------------------------- 1 | Aliyun FunctionCompute C# SDK 2 | ================================= 3 | 4 | [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE) 5 | [![GitHub version](https://badge.fury.io/gh/aliyun%2Ffc-csharp-sdk.svg)](https://badge.fury.io/gh/aliyun%2Ffc-csharp-sdk) 6 | [![Build Status](https://travis-ci.org/aliyun/fc-csharp-sdk.svg?branch=master)](https://travis-ci.org/aliyun/fc-csharp-sdk) 7 | 8 | Overview 9 | -------- 10 | 11 | The SDK of this version is dependent on the third-party library [Json.NET](https://www.newtonsoft.com/json) and [RestSharp](https://www.nuget.org/packages/RestSharp/). 12 | 13 | Running environment 14 | ------------------- 15 | 16 | Applicable to .net core 2.1 or above 17 | 18 | 19 | Installation 20 | ------------------- 21 | 22 | #### Install the SDK through NuGet 23 | - If NuGet hasn't been installed for Visual Studio, install [NuGet](http://docs.nuget.org/docs/start-here/installing-nuget) first. 24 | 25 | - After NuGet is installed, access Visual Studio to create a project or open an existing project, and then select `TOOLS` > `NuGet Package Manager` > `Manage NuGet Packages for Solution`. 26 | 27 | - Type `aliyun.fc.sdk` in the search box and click *Search*, find `Aliyun.FC.SDK` or `Aliyun.FC.SDK.NetCore` in the search results, select the latest version, and click *Install*. After installation, the SDK is added to the project. 28 | 29 | Getting started 30 | ------------------- 31 | 32 | ```csharp 33 | using System; 34 | using Aliyun.FunctionCompute.SDK.Client; 35 | using Aliyun.FunctionCompute.SDK.Request; 36 | using Aliyun.FunctionCompute.SDK.model; 37 | using System.IO; 38 | using System.Collections.Generic; 39 | using Newtonsoft.Json; 40 | using System.Text; 41 | 42 | namespace samples 43 | { 44 | class Program 45 | { 46 | 47 | static void Main(string[] args) 48 | { 49 | var fcClient = new FCClient("cn-shanghai", "", "", ""); 50 | var response1 = fcClient.CreateService(new CreateServiceRequest("csharp-service", "create by c# sdk") ); 51 | Console.WriteLine(response1.Content); 52 | Console.WriteLine(response1.Data.ServiceName + "---" + response1.Data.Description); 53 | 54 | byte[] contents = File.ReadAllBytes(@"/Users/songluo/gitpro/fc-dotnet-sdk/Libraries/samples/hello2.zip"); 55 | var code = new Code(Convert.ToBase64String(contents)); 56 | var response2 = fcClient.CreateFunction(new CreateFunctionRequest("csharp-service", "csharp-function", "python3", "index.handler", code)); 57 | Console.WriteLine(response2.Content); 58 | 59 | byte[] payload = Encoding.UTF8.GetBytes("hello csharp world"); 60 | var response3 = fcClient.InvokeFunction(new InvokeFunctionRequest("csharp-service", "csharp-function", null, payload)); 61 | Console.WriteLine(response3.Content); 62 | 63 | var customHeaders = new Dictionary { 64 | {"x-fc-invocation-type", "Async"} 65 | }; 66 | var response4 = fcClient.InvokeFunction(new InvokeFunctionRequest("csharp-service", "csharp-function", null, payload, customHeaders)); 67 | Console.WriteLine(response4.StatusCode); 68 | 69 | var response5 = fcClient.CreateTrigger(new CreateTriggerRequest("csharp-service", "csharp-function", "my-http-trigger", "http", "dummy_arn", "", 70 | new HttpTriggerConfig(HttpAuthType.ANONYMOUS, new HttpMethod[] { HttpMethod.GET, HttpMethod.POST }))); 71 | Console.WriteLine(response5.Content); 72 | 73 | var response6 = fcClient.DeleteTrigger(new DeleteTriggerRequest("csharp-service", "csharp-function", "my-http-trigger")); 74 | Console.WriteLine(response6.StatusCode); 75 | 76 | var response7 = fcClient.DeleteFunction(new DeleteFunctionRequest("test", "fff2")); 77 | Console.WriteLine(response7.StatusCode); 78 | 79 | var response8 = fcClient.DeleteService(new DeleteServiceRequest("csharp")); 80 | Console.WriteLine(response8.StatusCode); 81 | } 82 | } 83 | } 84 | 85 | ``` 86 | 87 | 88 | Testing 89 | ------- 90 | 91 | To run the tests, please set the access key id/secret, endpoint as environment variables. 92 | Take the Linux system for example: 93 | 94 | $ export ENDPOINT= 95 | $ export ACCESS_KEY_ID= 96 | $ export ACCESS_KEY_SECRET= 97 | 98 | 99 | Install [xunit](https://www.nuget.org/packages/xunit/), then run the test in the following method: 100 | 101 | $ cd Libraries/src/Aliyun.FunctionCompute.SDK.Unittests 102 | $ dotnet test 103 | 104 | 105 | More resources 106 | -------------- 107 | - [Aliyun FunctionCompute docs](https://help.aliyun.com/product/50980.html) 108 | 109 | Contacting us 110 | ------------- 111 | - [Links](https://help.aliyun.com/document_detail/53087.html) 112 | -------------------------------------------------------------------------------- /Libraries/src/Aliyun.FunctionCompute.SDK.Unittests/TagTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using Aliyun.FunctionCompute.SDK.model; 7 | using Aliyun.FunctionCompute.SDK.Request; 8 | using Aliyun.FunctionCompute.SDK.Response; 9 | using Xunit; 10 | 11 | namespace Aliyun.FunctionCompute.SDK.Unittests 12 | { 13 | [Collection("fcDotnet.Unittests")] 14 | public class TagUnitTests : IDisposable 15 | { 16 | readonly TestConfig tf; 17 | 18 | public List Services = new List(); 19 | 20 | public TagUnitTests() 21 | { 22 | Console.WriteLine("TagUnitTests Setup ....."); 23 | 24 | tf = new TestConfig(); 25 | for(int i =0; i < 3; i++) 26 | { 27 | string SvrName = "test-csharp-" + TestConfig.RandomString(8); 28 | var resp = tf.Client.CreateService(new CreateServiceRequest(SvrName)); 29 | Assert.Equal(200, resp.StatusCode); 30 | Services.Add(SvrName); 31 | } 32 | } 33 | 34 | public void Dispose() 35 | { 36 | Console.WriteLine("TagUnitTests TearDownBase ....."); 37 | try 38 | { 39 | foreach (var s in Services) 40 | { 41 | string[] keys = { }; 42 | string resArn = String.Format("services/{0}", s); 43 | tf.Client.UnTagResource(new UntagResourceRequest(resArn, keys, true)); 44 | tf.Client.DeleteService(new DeleteServiceRequest(s)); 45 | } 46 | 47 | } 48 | catch (Exception) 49 | { 50 | // 51 | } 52 | } 53 | 54 | [Fact] 55 | public void TestTagOperation() 56 | { 57 | int i = 0; 58 | foreach (var s in Services) 59 | { 60 | string resArn = String.Format("services/{0}", s); 61 | string fullArn = String.Format("acs:fc:{0}:{1}:services/{2}", tf.Region, tf.AccountID, s); 62 | Dictionary tags = new Dictionary { 63 | {"k3","v3"}, 64 | }; 65 | if (i % 2 == 0) 66 | { 67 | tags["k1"] = "v1"; 68 | } 69 | else 70 | { 71 | tags["k2"] = "v2"; 72 | } 73 | var resp = tf.Client.TagResource(new TagResourceRequest(resArn, tags)); 74 | Assert.Equal(200, resp.StatusCode); 75 | Assert.NotNull(resp.GetRequestID()); 76 | 77 | var gResp = tf.Client.GetResourceTags(new GetResourceTagsRequest(resArn)); 78 | Assert.Equal(200, gResp.StatusCode); 79 | Assert.NotNull(gResp.GetRequestID()); 80 | Assert.Equal(fullArn, gResp.Data.ResourceArn); 81 | Assert.Equal("v3", gResp.Data.Tags["k3"]); 82 | if (i % 2 == 0) 83 | { 84 | Assert.Equal("v1", gResp.Data.Tags["k1"]); 85 | Assert.False(gResp.Data.Tags.ContainsKey("k2")); 86 | } 87 | else 88 | { 89 | Assert.Equal("v2", gResp.Data.Tags["k2"]); 90 | Assert.False(gResp.Data.Tags.ContainsKey("k1")); 91 | } 92 | 93 | string[] keys = { "k3" }; 94 | var uresp = tf.Client.UnTagResource(new UntagResourceRequest(resArn, keys, false)); 95 | Assert.Equal(200, uresp.StatusCode); 96 | Assert.NotNull(uresp.GetRequestID()); 97 | 98 | gResp = tf.Client.GetResourceTags(new GetResourceTagsRequest(resArn)); 99 | Assert.Equal(200, gResp.StatusCode); 100 | Assert.NotNull(gResp.GetRequestID()); 101 | Assert.Equal(fullArn, gResp.Data.ResourceArn); 102 | Assert.False(gResp.Data.Tags.ContainsKey("k3")); 103 | 104 | string[] emptyKeys = { }; 105 | uresp = tf.Client.UnTagResource(new UntagResourceRequest(resArn, emptyKeys, true)); 106 | Assert.Equal(200, uresp.StatusCode); 107 | Assert.NotNull(uresp.GetRequestID()); 108 | 109 | gResp = tf.Client.GetResourceTags(new GetResourceTagsRequest(resArn)); 110 | Assert.Equal(200, gResp.StatusCode); 111 | Assert.NotNull(gResp.GetRequestID()); 112 | Assert.Equal(fullArn, gResp.Data.ResourceArn); 113 | Assert.False(gResp.Data.Tags.ContainsKey("k1")); 114 | Assert.False(gResp.Data.Tags.ContainsKey("k2")); 115 | Assert.False(gResp.Data.Tags.ContainsKey("k3")); 116 | 117 | i++; 118 | } 119 | } 120 | } 121 | } 122 | 123 | -------------------------------------------------------------------------------- /samples/fc-code-samples/Events/OSSEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Newtonsoft.Json; 3 | 4 | namespace fc_code_samples.Events 5 | { 6 | public class OSSEvent 7 | { 8 | public class Bucket 9 | { 10 | 11 | public readonly string arn; 12 | public readonly string name; 13 | public readonly string ownerIdentity; 14 | public readonly string virtualBucket; 15 | 16 | [JsonConstructor] 17 | public Bucket(string arn, 18 | string name, 19 | string ownerIdentity, 20 | string virtualBucket) 21 | { 22 | this.arn = arn; 23 | this.name = name; 24 | this.ownerIdentity = ownerIdentity; 25 | this.virtualBucket = virtualBucket; 26 | } 27 | } 28 | 29 | public class Object 30 | { 31 | public readonly long deltaSize; 32 | public readonly string eTag; 33 | public readonly string key; 34 | public readonly long size; 35 | 36 | [JsonConstructor] 37 | public Object(long deltaSize, 38 | string eTag, 39 | string key, 40 | long size) 41 | { 42 | this.deltaSize = deltaSize; 43 | this.eTag = eTag; 44 | this.key = key; 45 | this.size = size; 46 | } 47 | } 48 | 49 | public class RequestParameters 50 | { 51 | 52 | public readonly string sourceIPAddress; 53 | 54 | [JsonConstructor] 55 | public RequestParameters(string sourceIPAddress) 56 | { 57 | this.sourceIPAddress = sourceIPAddress; 58 | } 59 | } 60 | 61 | public class ResponseElements 62 | { 63 | public readonly string requestId; 64 | 65 | [JsonConstructor] 66 | public ResponseElements(string requestId) 67 | { 68 | this.requestId = requestId; 69 | } 70 | } 71 | 72 | public class UserIdentity 73 | { 74 | 75 | public readonly string principalId; 76 | 77 | [JsonConstructor] 78 | public UserIdentity(string principalId) 79 | { 80 | this.principalId = principalId; 81 | } 82 | } 83 | 84 | public class Oss 85 | { 86 | public readonly Bucket bucket; 87 | 88 | [JsonProperty("object")] 89 | public readonly Object obj; 90 | public readonly string ossSchemaVersion; 91 | public readonly string ruleId; 92 | 93 | [JsonConstructor] 94 | public Oss(Bucket bucket, 95 | Object obj, 96 | string ossSchemaVersion, 97 | string ruleId) 98 | { 99 | this.bucket = bucket; 100 | this.obj = obj; 101 | this.ossSchemaVersion = ossSchemaVersion; 102 | this.ruleId = ruleId; 103 | } 104 | } 105 | 106 | public class Event 107 | { 108 | public readonly string eventName; 109 | public readonly string eventSource; 110 | public readonly string eventTime; 111 | public readonly string eventVersion; 112 | public readonly Oss oss; 113 | public readonly string region; 114 | public readonly RequestParameters requestParameters; 115 | public readonly ResponseElements responseElements; 116 | public readonly UserIdentity userIdentity; 117 | 118 | [JsonConstructor] 119 | public Event(string eventName, 120 | string eventSource, 121 | string eventTime, 122 | string eventVersion, 123 | Oss oss, 124 | string region, 125 | RequestParameters requestParameters, 126 | ResponseElements responseElements, 127 | UserIdentity userIdentity) 128 | { 129 | this.eventName = eventName; 130 | this.eventSource = eventSource; 131 | this.eventTime = eventTime; 132 | this.eventVersion = eventVersion; 133 | this.oss = oss; 134 | this.region = region; 135 | this.requestParameters = requestParameters; 136 | this.responseElements = responseElements; 137 | this.userIdentity = userIdentity; 138 | } 139 | } 140 | 141 | public readonly Event[] events; 142 | 143 | [JsonConstructor] 144 | public OSSEvent(Event[] events) 145 | { 146 | this.events = events; 147 | } 148 | } 149 | } 150 | --------------------------------------------------------------------------------