本文介绍如何使用C# SDK更新一个事件规则的配置。

示例代码如下:

using System;
using System.Collections.Generic;

using Tea;

namespace Alibabacloud.Sample
{
    public class Client
    {

        /**
         * Create client初始化公共请求参数。
         */
        public static AlibabaCloud.SDK.EventBridge.EventBridgeClient CreateClient()
        {
            AlibabaCloud.SDK.EventBridge.Models.Config config = new AlibabaCloud.SDK.EventBridge.Models.Config();
            // 您的AccessKey ID。
            config.AccessKeyId = "<accessKeyId>";
            // 您的AccessKey Secret。
            config.AccessKeySecret = "<accessKeySecret>";
            // 您的接入点。
            config.Endpoint = "<endpoint>";
            return new AlibabaCloud.SDK.EventBridge.EventBridgeClient(config);
        }

        public static void UpdateEventRuleSample(AlibabaCloud.SDK.EventBridge.EventBridgeClient client)
        {
            try
            {
                AlibabaCloud.SDK.EventBridge.Models.UpdateRuleRequest updateEventRuleRequest = new AlibabaCloud.SDK.EventBridge.Models.UpdateRuleRequest();
                updateEventRuleRequest.EventBusName = "demo-bus";
                updateEventRuleRequest.RuleName = "myRule";
                updateEventRuleRequest.FilterPattern = "{\"source\":[\"acs.oss\"],\"type\":[\"oss:BucketQueried:GetBucketStat\"]}";
                client.UpdateRule(updateEventRuleRequest);
                Console.WriteLine("--------------------update rule success--------------------");
            }
            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.UpdateEventRuleSample(client);
            Console.ReadKey();
        }

    }
}