This topic describes how to use SDK for C# to create an event rule.

Sample code:

using System;
using System.Collections.Generic;

using Tea;

namespace Alibabacloud.Sample
{
    public class Client
    {

        /**
         * Uses the CreateClient() function to initialize common request parameters.
         */
        public static AlibabaCloud.SDK.EventBridge.EventBridgeClient CreateClient()
        {
            AlibabaCloud.SDK.EventBridge.Models.Config config = new AlibabaCloud.SDK.EventBridge.Models.Config();
            // Your AccessKey ID.
            config.AccessKeyId = "<accessKeyId>";
            // Your AccessKey secret.
            config.AccessKeySecret = "<accessKeySecret>";
            // Your endpoint.
            config.Endpoint = "<endpoint>";
            return new AlibabaCloud.SDK.EventBridge.EventBridgeClient(config);
        }

        public static void CreateEventRuleSample(AlibabaCloud.SDK.EventBridge.EventBridgeClient client)
        {
            try
            {
                AlibabaCloud.SDK.EventBridge.Models.CreateRuleRequest createEventRuleRequest = new AlibabaCloud.SDK.EventBridge.Models.CreateRuleRequest();
                AlibabaCloud.SDK.EventBridge.Models.TargetEntry targetEntry = new AlibabaCloud.SDK.EventBridge.Models.TargetEntry();
                targetEntry.Id = "1234";
                targetEntry.Endpoint = "http://www.baidu.com";
                //targetEntry.Type = "{"resourceKey":"url","form":"JSONPAHT","value":"http://www.baidu.com"}";
                List<AlibabaCloud.SDK.EventBridge.Models.TargetEntry> targetEntryList = new List<AlibabaCloud.SDK.EventBridge.Models.TargetEntry>
                {
                    targetEntry
                };
                //targetEntryList[0] =targetEntry;
                createEventRuleRequest.RuleName = "myRule";
                createEventRuleRequest.EventBusName = "demo-bus";
                createEventRuleRequest.FilterPattern = "{\"source\":[\"acs.aliyuncvc\"],\"type\":[\"aliyuncvc:MeetingEvent:MeetingStateEvent\"]}";
                createEventRuleRequest.Status = "enable";
                createEventRuleRequest.Targets = targetEntryList;
                AlibabaCloud.SDK.EventBridge.Models.CreateRuleResponse response = client.CreateRule(createEventRuleRequest);
                Console.WriteLine("--------------------create rule success--------------------");
                Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(response.ToMap()));
            }
            catch (TeaException error)
            {
                Console.WriteLine(error.Message);
            }
            catch (Exception _error)
            {
                TeaException error = new TeaException(new Dictionary<string, object>
                { { "message", _error.Message }
                });
                Console.WriteLine(error.Message);
            }
        }

        static void Main(string[] args)
        {
            AlibabaCloud.SDK.EventBridge.EventBridgeClient client = Client.CreateClient();
            Client.CreateEventRuleSample(client);
            Console.ReadKey();
        }

    }
}