/// <summary> /// Creates a new rule. /// /// </summary> /// <param name="request">The request object containing the details to send. Required.</param> /// <param name="retryConfiguration">The retry configuration that will be used by to send this request. Optional.</param> /// <param name="cancellationToken">The cancellation token to cancel this operation. Optional.</param> /// <returns>A response object containing details about the completed operation</returns> /// <example>Click <a href="https://docs.cloud.oracle.com/en-us/iaas/tools/dot-net-examples/latest/events/CreateRule.cs.html">here</a> to see an example of how to use CreateRule API.</example> public async Task <CreateRuleResponse> CreateRule(CreateRuleRequest request, RetryConfiguration retryConfiguration = null, CancellationToken cancellationToken = default) { logger.Trace("Called createRule"); Uri uri = new Uri(this.restClient.GetEndpoint(), System.IO.Path.Combine(basePathWithoutHost, "/rules".Trim('/'))); HttpMethod method = new HttpMethod("POST"); HttpRequestMessage requestMessage = Converter.ToHttpRequestMessage(uri, method, request); requestMessage.Headers.Add("Accept", "application/json"); GenericRetrier retryingClient = Retrier.GetPreferredRetrier(retryConfiguration, this.retryConfiguration); HttpResponseMessage responseMessage; try { if (retryingClient != null) { responseMessage = await retryingClient.MakeRetryingCall(this.restClient.HttpSend, requestMessage, cancellationToken).ConfigureAwait(false); } else { responseMessage = await this.restClient.HttpSend(requestMessage).ConfigureAwait(false); } this.restClient.CheckHttpResponseMessage(requestMessage, responseMessage); return(Converter.FromHttpResponseMessage <CreateRuleResponse>(responseMessage)); } catch (Exception e) { logger.Error($"CreateRule failed with error: {e.Message}"); throw; } }
//创建一个完整的规则,订阅的Topic是自定义类型(自己创建的) public void TestCreateRuleAboutUserTopic() { DefaultAcsClient acsClient = Demo.IotClient.GetClient(); CreateRuleRequest request = new CreateRuleRequest(); //Topic名称不能同名 request.Name = "Rule_User_Topic_0826"; request.ProductKey = "<productKey>"; request.ShortTopic = "firstDevice/user/update"; //自定义Topic request.TopicType = 1; request.Select = "*"; request._Where = " 1=1 "; request.DataType = "JSON"; request.RuleDesc = "This is a test."; CreateRuleResponse response = acsClient.GetAcsResponse(request); Console.WriteLine("Create Rule: " + response.Success); if (!(bool)response.Success) { Console.WriteLine(response.Code + ", " + response.ErrorMessage); return; } Console.WriteLine("Rule: " + response.RuleId); }
//创建一个完整的规则,订阅的Topic是系统类型(平台内置的) public void TestCreateRuleAboutSystemTopic() { DefaultAcsClient acsClient = Demo.IotClient.GetClient(); CreateRuleRequest request = new CreateRuleRequest(); //Topic名称不能同名 request.Name = "Rule_Property_Topic_0826"; request.ProductKey = "<productKey>"; //使用通配符,订阅全部设备的 request.ShortTopic = "+/thing/event/property/post"; //自定义Topic request.TopicType = 0; request.Select = "*"; request._Where = " 1=1 "; request.DataType = "JSON"; request.RuleDesc = "This is a test."; CreateRuleResponse response = acsClient.GetAcsResponse(request); Console.WriteLine("Create Rule: " + response.Success); if (!(bool)response.Success) { Console.WriteLine(response.Code + ", " + response.ErrorMessage); return; } Console.WriteLine("Rule: " + response.RuleId); }
/// <summary> /// Creates a Recycle Bin retention rule. For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/recycle-bin-working-with-rules.html#recycle-bin-create-rule"> /// Create Recycle Bin retention rules</a> in the <i>Amazon Elastic Compute Cloud User /// Guide</i>. /// </summary> /// <param name="request">Container for the necessary parameters to execute the CreateRule service method.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// /// <returns>The response from the CreateRule service method, as returned by RecycleBin.</returns> /// <exception cref="Amazon.RecycleBin.Model.InternalServerException"> /// The service could not respond to the request due to an internal problem. /// </exception> /// <exception cref="Amazon.RecycleBin.Model.ServiceQuotaExceededException"> /// The request would cause a service quota for the number of tags per resource to be /// exceeded. /// </exception> /// <exception cref="Amazon.RecycleBin.Model.ValidationException"> /// One or more of the parameters in the request is not valid. /// </exception> /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/rbin-2021-06-15/CreateRule">REST API Reference for CreateRule Operation</seealso> public virtual Task <CreateRuleResponse> CreateRuleAsync(CreateRuleRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var options = new InvokeOptions(); options.RequestMarshaller = CreateRuleRequestMarshaller.Instance; options.ResponseUnmarshaller = CreateRuleResponseUnmarshaller.Instance; return(InvokeAsync <CreateRuleResponse>(request, options, cancellationToken)); }
/// <summary> /// Creates a Recycle Bin retention rule. For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/recycle-bin-working-with-rules.html#recycle-bin-create-rule"> /// Create Recycle Bin retention rules</a> in the <i>Amazon Elastic Compute Cloud User /// Guide</i>. /// </summary> /// <param name="request">Container for the necessary parameters to execute the CreateRule service method.</param> /// /// <returns>The response from the CreateRule service method, as returned by RecycleBin.</returns> /// <exception cref="Amazon.RecycleBin.Model.InternalServerException"> /// The service could not respond to the request due to an internal problem. /// </exception> /// <exception cref="Amazon.RecycleBin.Model.ServiceQuotaExceededException"> /// The request would cause a service quota for the number of tags per resource to be /// exceeded. /// </exception> /// <exception cref="Amazon.RecycleBin.Model.ValidationException"> /// One or more of the parameters in the request is not valid. /// </exception> /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/rbin-2021-06-15/CreateRule">REST API Reference for CreateRule Operation</seealso> public virtual CreateRuleResponse CreateRule(CreateRuleRequest request) { var options = new InvokeOptions(); options.RequestMarshaller = CreateRuleRequestMarshaller.Instance; options.ResponseUnmarshaller = CreateRuleResponseUnmarshaller.Instance; return(Invoke <CreateRuleResponse>(request, options)); }
/// <summary> /// Initiates the asynchronous execution of the CreateRule operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the CreateRule operation on AmazonRecycleBinClient.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> /// /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndCreateRule /// operation.</returns> /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/rbin-2021-06-15/CreateRule">REST API Reference for CreateRule Operation</seealso> public virtual IAsyncResult BeginCreateRule(CreateRuleRequest request, AsyncCallback callback, object state) { var options = new InvokeOptions(); options.RequestMarshaller = CreateRuleRequestMarshaller.Instance; options.ResponseUnmarshaller = CreateRuleResponseUnmarshaller.Instance; return(BeginInvoke(request, options, callback, state)); }
/// <summary> /// 创建规则 /// </summary> public async Task <CreateRuleResponse> CreateRuleAsync(CreateRuleRequest createRuleRequest) { Dictionary <string, string> urlParam = new Dictionary <string, string>(); string urlPath = HttpUtils.AddUrlPath("/v5/iot/{project_id}/rules", urlParam); SdkRequest request = HttpUtils.InitSdkRequest(urlPath, "application/json", createRuleRequest); HttpResponseMessage response = await DoHttpRequestAsync("POST", request); return(JsonUtils.DeSerialize <CreateRuleResponse>(response)); }
/// <summary> /// This endpoint allows you to create a Rule. Note that in the examples, ":domain_id" can be one of your private domains. /// </summary> /// <param name="request">CreateRuleRequest object.</param> /// <returns></returns> public async Task <CreateRuleResponse> CreateRuleAsync(CreateRuleRequest request) { var requestObject = httpClient.GetRequest(endpointUrl + "/{domain_id}/rules", Method.POST); requestObject.AddUrlSegment("domain_id", request.DomainId); requestObject.JsonSerializer = new DynamicJsonSerializer(); requestObject.AddJsonBody(request.Rule); var response = await httpClient.ExecuteAsync <CreateRuleResponse>(requestObject); return(response); }
/// <summary> /// 创建规则 /// </summary> /// <param name="req"><see cref="CreateRuleRequest"/></param> /// <returns><see cref="CreateRuleResponse"/></returns> public CreateRuleResponse CreateRuleSync(CreateRuleRequest req) { JsonResponseModel <CreateRuleResponse> rsp = null; try { var strResp = this.InternalRequestSync(req, "CreateRule"); rsp = JsonConvert.DeserializeObject <JsonResponseModel <CreateRuleResponse> >(strResp); } catch (JsonSerializationException e) { throw new TencentCloudSDKException(e.Message); } return(rsp.Response); }
//创建一个简单的规则,不设置处理规则(不指定规则订阅的topic) public void TestCreateSimpleRule() { DefaultAcsClient acsClient = Demo.IotClient.GetClient(); CreateRuleRequest request = new CreateRuleRequest(); request.Name = "Rule_JSON_0826"; request.DataType = "JSON"; request.RuleDesc = "This is a test."; CreateRuleResponse response = acsClient.GetAcsResponse(request); Console.WriteLine("Create Rule: " + response.Success); if (!(bool)response.Success) { Console.WriteLine(response.Code + ", " + response.ErrorMessage); return; } Console.WriteLine("Rule: " + response.RuleId); }
public async Task CreateRuleAsync() { RuleToCreate rule = new RuleToCreate() { Name = "RuleName", Priority = 15, Description = "Description", Conditions = new List <Condition>() { new Condition() { Operation = OperationType.PREFIX, ConditionData = new ConditionData() { Field = "to", Value = "raul" } } }, Enabled = true, Match = MatchType.ANY, Actions = new List <ActionRule>() { new ActionRule() { Action = ActionType.WEBHOOK, ActionData = new ActionData() { Url = "https://google.com" } } } }; var request = new CreateRuleRequest() { DomainId = Domain.Id, Rule = rule }; var response = await mailinatorClient.RulesClient.CreateRuleAsync(request); Assert.IsTrue(response != null); }
public static int CreateRule(int variantID, string ruleName) { try { using (_certonaService = new CertonaServiceClient()) { try { UserDTO user = FormsAuthenticationWrapper.User; var request = new CreateRuleRequest() { User = user, ApplicationID = null, Description = string.Empty, Enabled = true, Name = ruleName, VariantID = variantID }; var response = _certonaService.CreateRule(request); return(response.RuleID); } catch (TimeoutException exception) { _certonaService.Abort(); throw; } catch (CommunicationException exception) { _certonaService.Abort(); throw; } } } catch (Exception ex) { throw; } }
protected override void ProcessRecord() { base.ProcessRecord(); CreateRuleRequest request; try { request = new CreateRuleRequest { CreateRuleDetails = CreateRuleDetails, OpcRetryToken = OpcRetryToken, OpcRequestId = OpcRequestId }; response = client.CreateRule(request).GetAwaiter().GetResult(); WriteOutput(response, response.Rule); FinishProcessing(response); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }
public async Task <Guid> CreatAsync(Guid groupId, int index, string pattern, SourceTypeEnum sourceType, DestinationTypeEnum destinationType = DestinationTypeEnum.Any) { CreateRuleRequest request = new CreateRuleRequest { Index = index, Pattern = pattern, SourceType = sourceType, DestinationType = destinationType, GroupId = groupId }; HttpResponseMessage response = await client.PostAsJsonAsync( controllerPath, request); if (response.IsSuccessStatusCode) { CreateRuleResponse rule = await response.Content.ReadAsAsync <CreateRuleResponse>(); return(rule.Id); } else { throw new UnauthorizedAccessException($"Unauthorized rule creation at index '{index}' for group '{groupId}'"); } }
static void Main(string[] args) { //Initialize Samart API using clientcode and password. string Client_code = ""; //YOUR CLIENT CODE string Password = ""; //YOUR PASSWORD string api_key = ""; string JWTToken = ""; // optional string RefreshToken = ""; // optional SmartApi connect = new SmartApi(api_key, JWTToken, RefreshToken); OutputBaseClass obj = new OutputBaseClass(); //Login by client code and password obj = connect.GenerateSession(Client_code, Password); AngelToken agr = obj.TokenResponse; Console.WriteLine("------GenerateSession call output-------------"); Console.WriteLine(JsonConvert.SerializeObject(agr)); Console.WriteLine("----------------------------------------------"); //Get Token obj = connect.GenerateToken(); agr = obj.TokenResponse; Console.WriteLine("------GenerateToken call output-------------"); Console.WriteLine(JsonConvert.SerializeObject(agr)); Console.WriteLine("----------------------------------------------"); //Get Profile obj = connect.GetProfile(); GetProfileResponse gp = obj.GetProfileResponse; Console.WriteLine("------GetProfile call output-------------"); Console.WriteLine(JsonConvert.SerializeObject(gp)); Console.WriteLine("----------------------------------------------"); //Place Order OrderInfo ord = new OrderInfo(); ord.variety = Constants.VARIETY_NORMAL; ord.tradingsymbol = "SBIN-EQ"; ord.symboltoken = "3045"; ord.transactiontype = Constants.TRANSACTION_TYPE_BUY; ord.exchange = Constants.EXCHANGE_NSE; ord.ordertype = Constants.ORDER_TYPE_LIMIT; ord.producttype = Constants.PRODUCT_TYPE_INTRADAY; ord.duration = Constants.VALIDITY_DAY.ToString(); ord.price = "350.00"; ord.squareoff = "0"; ord.stoploss = "0"; ord.quantity = "10"; ord.triggerprice = "0"; //OPTIONAL PARAMETER //ord.triggerprice = "350"; //OPTIONAL PARAMETER obj = connect.placeOrder(ord); OrderResponse Ores = obj.PlaceOrderResponse; Console.WriteLine("------placeOrder call output-------------"); Console.WriteLine(JsonConvert.SerializeObject(Ores)); Console.WriteLine("----------------------------------------------"); //Modify Order OrderInfo mord = new OrderInfo(); mord.orderid = "211029001245777"; mord.variety = Constants.VARIETY_NORMAL; mord.tradingsymbol = "SBIN-EQ"; mord.symboltoken = "3045"; mord.transactiontype = Constants.TRANSACTION_TYPE_BUY; mord.exchange = Constants.EXCHANGE_NSE; mord.ordertype = Constants.ORDER_TYPE_LIMIT; mord.producttype = Constants.PRODUCT_TYPE_DELIVERY; mord.duration = Constants.VALIDITY_DAY.ToString(); mord.price = "340.00"; mord.squareoff = "0"; mord.stoploss = "0"; mord.quantity = "20"; mord.triggerprice = "0"; //OPTIONAL PARAMETER //mord.triggerprice = "357"; //OPTIONAL PARAMETER obj = connect.modifyOrder(mord); OrderResponse mOres = obj.ModifyOrderResponse; Console.WriteLine("------modifyOrder call output-------------"); Console.WriteLine(JsonConvert.SerializeObject(mOres)); Console.WriteLine("----------------------------------------------"); //cancel Order OrderInfo ord2 = new OrderInfo(); ord2.orderid = "211029001245777"; ord2.variety = Constants.VARIETY_NORMAL; obj = connect.cancelOrder(ord2); OrderResponse cOrs = obj.CancelOrderResponse; Console.WriteLine("------cancelOrder call output-------------"); Console.WriteLine(JsonConvert.SerializeObject(cOrs)); Console.WriteLine("----------------------------------------------"); //get Order Book obj = connect.getOrderBook(); GetOrderBookResponse book = obj.GetOrderBookResponse; Console.WriteLine("------getOrderBook call output-------------"); Console.WriteLine(JsonConvert.SerializeObject(book)); Console.WriteLine("----------------------------------------------"); //get Trade Book obj = connect.getTradeBook(); GetTradeBookResponse trade = obj.GetTradeBookResponse; Console.WriteLine("------getTradeBook call output-------------"); Console.WriteLine(JsonConvert.SerializeObject(trade)); Console.WriteLine("----------------------------------------------"); // Get Get LTP Data LTPDataRequest lreq = new LTPDataRequest(); lreq.exchange = Constants.EXCHANGE_NSE; lreq.symboltoken = "3045"; lreq.tradingsymbol = "SBIN-EQ"; obj = connect.GetLTPData(lreq); GetLTPDataResponse ltp = obj.GetLTPDataResponse; Console.WriteLine("------GetLTPData call output-------------"); Console.WriteLine(JsonConvert.SerializeObject(ltp)); Console.WriteLine("----------------------------------------------"); //get Holding obj = connect.getHolding(); GetHoldingResponse holding = obj.GetHoldingResponse; Console.WriteLine("------getHolding call output-------------"); Console.WriteLine(JsonConvert.SerializeObject(holding)); Console.WriteLine("----------------------------------------------"); //get Position obj = connect.getPosition(); GetPositionResponse position = obj.GetPositionResponse; Console.WriteLine("------getPosition call output-------------"); Console.WriteLine(JsonConvert.SerializeObject(position)); Console.WriteLine("----------------------------------------------"); //Convert Position ConvertPositionRequest req = new ConvertPositionRequest(); req.exchange = Constants.EXCHANGE_NSE.ToString(); req.oldproducttype = Constants.PRODUCT_TYPE_DELIVERY; req.newproducttype = Constants.PRODUCT_TYPE_MARGIN; req.tradingsymbol = "SBIN-EQ"; req.transactiontype = Constants.TRANSACTION_TYPE_BUY; req.quantity = 1; req.type = Constants.VALIDITY_DAY; obj = connect.convertPosition(req); PositionConversionResponse cc = obj.PositionConversionResponse; Console.WriteLine("------convertPosition call output-------------"); Console.WriteLine(JsonConvert.SerializeObject(cc)); Console.WriteLine("----------------------------------------------"); //get RMS obj = connect.getRMS(); GetRMSLimitResponse gmres = obj.GetRMSLimitResponse; Console.WriteLine("------getRMS call output-------------"); Console.WriteLine(JsonConvert.SerializeObject(gmres)); Console.WriteLine("----------------------------------------------"); //Create Rule CreateRuleRequest crreq = new CreateRuleRequest(); //crreq.id = 0; crreq.tradingsymbol = "SBIN-EQ"; crreq.symboltoken = "3045"; crreq.exchange = Constants.EXCHANGE_NSE; crreq.transactiontype = Constants.TRANSACTION_TYPE_BUY; crreq.producttype = Constants.PRODUCT_TYPE_MARGIN; crreq.price = "350"; crreq.qty = "10"; crreq.triggerprice = "370"; crreq.disclosedqty = "10"; crreq.timeperiod = "20"; obj = connect.CreateRule(crreq); RuleResponse rr = obj.CreateRuleResponse; Console.WriteLine("------CreateRule call output-------------"); Console.WriteLine(JsonConvert.SerializeObject(rr)); Console.WriteLine("----------------------------------------------"); //Rule Details string RuleID = "1000118"; obj = connect.ruleDetails(RuleID); RuleDetailsResponse rd = obj.RuleDetailsResponse; Console.WriteLine("------ruleDetails call output-------------"); Console.WriteLine(JsonConvert.SerializeObject(rd)); Console.WriteLine("----------------------------------------------"); //Modify Rule CreateRuleRequest crreq2 = new CreateRuleRequest(); crreq2.id = "1000118"; crreq2.tradingsymbol = "SBIN-EQ"; crreq2.symboltoken = "3045"; crreq2.exchange = Constants.EXCHANGE_NSE; crreq2.transactiontype = Constants.TRANSACTION_TYPE_BUY; crreq2.producttype = Constants.PRODUCT_TYPE_MARGIN; crreq2.price = "350"; crreq2.qty = "10"; crreq2.triggerprice = "360"; crreq2.disclosedqty = "10"; crreq2.timeperiod = "20"; obj = connect.modifyRule(crreq2); RuleResponse rm = obj.ModifyRuleResponse; Console.WriteLine("------modifyRule call output-------------"); Console.WriteLine(JsonConvert.SerializeObject(rm)); Console.WriteLine("----------------------------------------------"); //Cancel Rule CancelRuleRequest creq = new CancelRuleRequest(); creq.id = "1000117"; creq.symboltoken = "3045"; creq.exchange = Constants.EXCHANGE_NSE; obj = connect.cancelRule(creq); RuleResponse rc = obj.CancelRuleResponse; Console.WriteLine("------cancelRule call output-------------"); Console.WriteLine(JsonConvert.SerializeObject(rc)); Console.WriteLine("----------------------------------------------"); //Rule List RuleListRequest rreq = new RuleListRequest(); rreq.status = new List <string>(); rreq.status.Add("NEW"); rreq.status.Add("CANCELLED"); rreq.page = 1; rreq.count = 10; obj = connect.ruleList(rreq); RuleListResponse rl = obj.RuleListResponse; Console.WriteLine("------ruleList call output-------------"); Console.WriteLine(JsonConvert.SerializeObject(rl)); Console.WriteLine("----------------------------------------------"); //Get Candle Data CandleRequest cdreq = new CandleRequest(); cdreq.exchange = Constants.EXCHANGE_NSE; cdreq.symboltoken = "3045"; cdreq.interval = Constants.INTERVAL_MINUTE; cdreq.fromdate = "2021-02-08 09:00"; cdreq.todate = "2021-02-08 09:15"; obj = connect.GetCandleData(cdreq); CandleDataResponse cd = obj.GetCandleDataResponse; Console.WriteLine("------GetCandleData call output-------------"); Console.WriteLine(JsonConvert.SerializeObject(cd)); Console.WriteLine("----------------------------------------------"); //LogOut obj = connect.LogOut(Client_code); LogOutResponse lg = obj.LogOutResponse; Console.WriteLine("------LogOut call output-------------"); Console.WriteLine(JsonConvert.SerializeObject(lg)); Console.WriteLine("----------------------------------------------"); }
private static void createRule(IoTDAClient client) { CreateRuleRequest req = new CreateRuleRequest { Body = new Rule() { Actions = new List <RuleAction>() { new RuleAction() { Type = "IoTA_FORWARDING", Addition = new List <string>() { "88cce89f943646cfbda057aed55c4841" }, IotaForwarding = new ActionIoTAForwarding() { ProjectId = "88cce89f943646cfbda057aed55c4841", RegionName = "cn-north-7" } } }, ConditionGroup = new ConditionGroup() { Conditions = new List <RuleCondition>() { new RuleCondition() { DevicePropertyCondition = new DeviceDataCondition() { Filters = new List <PropertyFilter>() { new PropertyFilter() { Operator = ">", Path = "Meter/signalStrength", Value = "0" } } }, Type = "DEVICE_DATA" } }, TimeRange = new TimeRange() { EndTime = "12:02", StartTime = "12:00" } }, Name = "test_createRule_Success", RuleType = "DATA_FORWARDING", Status = "inactive" } }; try { var resp = client.CreateRule(req); Console.WriteLine(resp); } catch (RequestTimeoutException requestTimeoutException) { Console.WriteLine(requestTimeoutException.ErrorMessage); } catch (ServiceResponseException clientRequestException) { Console.WriteLine(clientRequestException.HttpStatusCode); Console.WriteLine(clientRequestException.ErrorCode); Console.WriteLine(clientRequestException.ErrorMsg); } catch (ConnectionException connectionException) { Console.WriteLine(connectionException.ErrorMessage); } }