示例#1
0
        public GetAzureRmAlertRuleTests(ITestOutputHelper output)
        {
            XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
            insightsAlertRuleOperationsMock = new Mock <IAlertOperations>();
            insightsManagementClientMock    = new Mock <InsightsManagementClient>();
            commandRuntimeMock = new Mock <ICommandRuntime>();
            cmdlet             = new GetAzureRmAlertRuleCommand()
            {
                CommandRuntime           = commandRuntimeMock.Object,
                InsightsManagementClient = insightsManagementClientMock.Object
            };

            listResponse   = Utilities.InitializeRuleListResponse();
            singleResponse = Utilities.InitializeRuleGetResponse();

            insightsAlertRuleOperationsMock.Setup(f => f.ListRulesAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <RuleListResponse>(listResponse))
            .Callback((string resourceGrp, string nameOrTargetUri, CancellationToken t) =>
            {
                resourceGroup       = resourceGrp;
                ruleNameOrTargetUri = nameOrTargetUri;
            });

            insightsAlertRuleOperationsMock.Setup(f => f.GetRuleAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <RuleGetResponse>(singleResponse))
            .Callback((string resourceGrp, string nameOrTargetUri, CancellationToken t) =>
            {
                resourceGroup       = resourceGrp;
                ruleNameOrTargetUri = nameOrTargetUri;
            });

            insightsManagementClientMock.SetupGet(f => f.AlertOperations).Returns(this.insightsAlertRuleOperationsMock.Object);
        }
        public void ListRulesTest()
        {
            RuleResourceCollection expectedRuleResourceCollection = JsonExtensions.FromJson <RuleResourceCollection>(ListRulesContent);

            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(ListRulesContent)
            };

            var handler        = new RecordedDelegatingHandler(response);
            var insightsClient = GetInsightsManagementClient(handler);
            RuleListResponse actualResponse = insightsClient.AlertOperations.ListRules(resourceGroupName: " rg1", targetResourceUri: "resUri");

            AreEqual(expectedRuleResourceCollection, actualResponse.RuleResourceCollection);
        }
示例#3
0
        /// <summary>
        /// Execute the cmdlet
        /// </summary>
        protected override void ExecuteCmdletInternal()
        {
            if (string.IsNullOrWhiteSpace(this.Name))
            {
                // Retrieve all the AlertRules for a ResourceGroup
                RuleListResponse result = this.InsightsManagementClient.AlertOperations.ListRulesAsync(resourceGroupName: this.ResourceGroup, targetResourceUri: this.TargetResourceId).Result;

                var records = result.RuleResourceCollection.Value.Select(e => this.DetailedOutput.IsPresent ? (PSManagementItemDescriptor) new PSAlertRule(e) : new PSAlertRuleNoDetails(e));
                WriteObject(sendToPipeline: records.ToList());
            }
            else
            {
                // Retrieve a single AlertRule determined by the ResourceGroup and the rule name
                RuleGetResponse result      = this.InsightsManagementClient.AlertOperations.GetRuleAsync(resourceGroupName: this.ResourceGroup, ruleName: this.Name).Result;
                var             finalResult = new List <PSManagementItemDescriptor> {
                    this.DetailedOutput.IsPresent ? (PSManagementItemDescriptor) new PSAlertRule(result) : new PSAlertRuleNoDetails(result)
                };
                WriteObject(sendToPipeline: finalResult);
            }
        }
示例#4
0
        /// <summary>
        /// Execute the cmdlet
        /// </summary>
        protected override void ProcessRecordInternal()
        {
            WriteWarning("This cmdlet is being modified to enable better experience and may contain breaking changes in a future release.");

            if (string.IsNullOrWhiteSpace(this.Name))
            {
                // Retrieve all the AlertRules for a ResourceGroup
                RuleListResponse result = this.InsightsManagementClient.AlertOperations.ListRulesAsync(resourceGroupName: this.ResourceGroup, targetResourceUri: this.TargetResourceId).Result;

                var records = result.RuleResourceCollection.Value.Select(e => this.DetailedOutput.IsPresent ? (PSManagementItemDescriptor) new PSAlertRule(e) : new PSAlertRuleNoDetails(e));
                WriteObject(sendToPipeline: records.ToList());
            }
            else
            {
                // Retrieve a single AlertRule determined by the ResourceGroup and the rule name
                RuleGetResponse result = this.InsightsManagementClient.AlertOperations.GetRuleAsync(resourceGroupName: this.ResourceGroup, ruleName: this.Name).Result;

                var finalResult = new List <PSManagementItemDescriptor> {
                    this.DetailedOutput.IsPresent ? (PSManagementItemDescriptor) new PSAlertRule(result) : new PSAlertRuleNoDetails(result)
                };
                WriteObject(sendToPipeline: finalResult);
            }
        }
示例#5
0
        /// <summary>
        /// Execute the cmdlet
        /// </summary>
        public override void ExecuteCmdlet()
        {
            try
            {
                if (string.IsNullOrWhiteSpace(this.Name))
                {
                    // Retrieve all the AlertRules for a ResourceGroup
                    RuleListResponse result = this.InsightsManagementClient.AlertOperations.ListRulesAsync(resourceGroupName: this.ResourceGroup, targetResourceUri: this.TargetResourceUri).Result;

                    var records = result.RuleResourceCollection.Value.Select(e => this.DetailedOutput.IsPresent ? (PSManagementItemDescriptor) new PSAlertRule(e) : new PSAlertRuleNoDetails(e));
                    WriteObject(sendToPipeline: records, enumerateCollection: true);
                }
                else
                {
                    // Retrieve a single AlertRule determined by the ResourceGroup and the rule name
                    RuleGetResponse result = this.InsightsManagementClient.AlertOperations.GetRuleAsync(resourceGroupName: this.ResourceGroup, ruleName: this.Name).Result;
                    WriteObject(sendToPipeline: this.DetailedOutput.IsPresent ? (PSManagementItemDescriptor) new PSAlertRule(result) : new PSAlertRuleNoDetails(result));
                }
            }
            catch (AggregateException ex)
            {
                throw ex.Flatten().InnerException;
            }
        }
示例#6
0
        /// <summary>
        /// List the alert rules within a subscription.
        /// </summary>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The List Rules operation response.
        /// </returns>
        public async System.Threading.Tasks.Task <Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleListResponse> ListAsync(CancellationToken cancellationToken)
        {
            // Validate

            // Tracing
            bool   shouldTrace  = CloudContext.Configuration.Tracing.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = Tracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                Tracing.Enter(invocationId, this, "ListAsync", tracingParameters);
            }

            // Construct URL
            string url = new Uri(this.Client.BaseUri, "/").AbsoluteUri + this.Client.Credentials.SubscriptionId + "/services/monitoring/alertrules";

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

            try
            {
                httpRequest            = new HttpRequestMessage();
                httpRequest.Method     = HttpMethod.Get;
                httpRequest.RequestUri = new Uri(url);

                // Set Headers
                httpRequest.Headers.Add("Accept", "application/json");
                httpRequest.Headers.Add("x-ms-version", "2013-10-01");

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        Tracing.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        Tracing.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false), CloudExceptionType.Json);
                        if (shouldTrace)
                        {
                            Tracing.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    RuleListResponse result = null;
                    // Deserialize Response
                    cancellationToken.ThrowIfCancellationRequested();
                    string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                    result = new RuleListResponse();
                    JToken responseDoc = JToken.Parse(responseContent);

                    if (responseDoc != null && responseDoc.Type != JTokenType.Null)
                    {
                        JToken valueArray = responseDoc["Value"];
                        if (valueArray != null && valueArray.Type != JTokenType.Null)
                        {
                            foreach (JToken valueValue in (JArray)valueArray)
                            {
                                Rule ruleInstance = new Rule();
                                result.Value.Add(ruleInstance);

                                JToken idValue = valueValue["Id"];
                                if (idValue != null && idValue.Type != JTokenType.Null)
                                {
                                    string idInstance = (string)idValue;
                                    ruleInstance.Id = idInstance;
                                }

                                JToken nameValue = valueValue["Name"];
                                if (nameValue != null && nameValue.Type != JTokenType.Null)
                                {
                                    string nameInstance = (string)nameValue;
                                    ruleInstance.Name = nameInstance;
                                }

                                JToken descriptionValue = valueValue["Description"];
                                if (descriptionValue != null && descriptionValue.Type != JTokenType.Null)
                                {
                                    string descriptionInstance = (string)descriptionValue;
                                    ruleInstance.Description = descriptionInstance;
                                }

                                JToken isEnabledValue = valueValue["IsEnabled"];
                                if (isEnabledValue != null && isEnabledValue.Type != JTokenType.Null)
                                {
                                    bool isEnabledInstance = (bool)isEnabledValue;
                                    ruleInstance.IsEnabled = isEnabledInstance;
                                }

                                JToken conditionValue = valueValue["Condition"];
                                if (conditionValue != null && conditionValue.Type != JTokenType.Null)
                                {
                                    string typeName = (string)conditionValue["odata.type"];
                                    if (typeName == "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.ThresholdRuleCondition")
                                    {
                                        ThresholdRuleCondition thresholdRuleConditionInstance = new ThresholdRuleCondition();

                                        JToken dataSourceValue = conditionValue["DataSource"];
                                        if (dataSourceValue != null && dataSourceValue.Type != JTokenType.Null)
                                        {
                                            string typeName2 = (string)dataSourceValue["odata.type"];
                                            if (typeName2 == "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleMetricDataSource")
                                            {
                                                RuleMetricDataSource ruleMetricDataSourceInstance = new RuleMetricDataSource();

                                                JToken resourceIdValue = dataSourceValue["ResourceId"];
                                                if (resourceIdValue != null && resourceIdValue.Type != JTokenType.Null)
                                                {
                                                    string resourceIdInstance = (string)resourceIdValue;
                                                    ruleMetricDataSourceInstance.ResourceId = resourceIdInstance;
                                                }

                                                JToken metricNamespaceValue = dataSourceValue["MetricNamespace"];
                                                if (metricNamespaceValue != null && metricNamespaceValue.Type != JTokenType.Null)
                                                {
                                                    string metricNamespaceInstance = (string)metricNamespaceValue;
                                                    ruleMetricDataSourceInstance.MetricNamespace = metricNamespaceInstance;
                                                }

                                                JToken metricNameValue = dataSourceValue["MetricName"];
                                                if (metricNameValue != null && metricNameValue.Type != JTokenType.Null)
                                                {
                                                    string metricNameInstance = (string)metricNameValue;
                                                    ruleMetricDataSourceInstance.MetricName = metricNameInstance;
                                                }
                                                thresholdRuleConditionInstance.DataSource = ruleMetricDataSourceInstance;
                                            }
                                        }

                                        JToken operatorValue = conditionValue["Operator"];
                                        if (operatorValue != null && operatorValue.Type != JTokenType.Null)
                                        {
                                            ConditionOperator operatorInstance = (ConditionOperator)Enum.Parse(typeof(ConditionOperator), (string)operatorValue, false);
                                            thresholdRuleConditionInstance.Operator = operatorInstance;
                                        }

                                        JToken thresholdValue = conditionValue["Threshold"];
                                        if (thresholdValue != null && thresholdValue.Type != JTokenType.Null)
                                        {
                                            double thresholdInstance = (double)thresholdValue;
                                            thresholdRuleConditionInstance.Threshold = thresholdInstance;
                                        }

                                        JToken windowSizeValue = conditionValue["WindowSize"];
                                        if (windowSizeValue != null && windowSizeValue.Type != JTokenType.Null)
                                        {
                                            TimeSpan windowSizeInstance = TypeConversion.From8601TimeSpan((string)windowSizeValue);
                                            thresholdRuleConditionInstance.WindowSize = windowSizeInstance;
                                        }
                                        ruleInstance.Condition = thresholdRuleConditionInstance;
                                    }
                                }

                                JToken actionsArray = valueValue["Actions"];
                                if (actionsArray != null && actionsArray.Type != JTokenType.Null)
                                {
                                    foreach (JToken actionsValue in (JArray)actionsArray)
                                    {
                                        string typeName3 = (string)actionsValue["odata.type"];
                                        if (typeName3 == "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleEmailAction")
                                        {
                                            RuleEmailAction ruleEmailActionInstance = new RuleEmailAction();

                                            JToken sendToServiceOwnersValue = actionsValue["SendToServiceOwners"];
                                            if (sendToServiceOwnersValue != null && sendToServiceOwnersValue.Type != JTokenType.Null)
                                            {
                                                bool sendToServiceOwnersInstance = (bool)sendToServiceOwnersValue;
                                                ruleEmailActionInstance.SendToServiceOwners = sendToServiceOwnersInstance;
                                            }

                                            JToken customEmailsArray = actionsValue["CustomEmails"];
                                            if (customEmailsArray != null && customEmailsArray.Type != JTokenType.Null)
                                            {
                                                foreach (JToken customEmailsValue in (JArray)customEmailsArray)
                                                {
                                                    ruleEmailActionInstance.CustomEmails.Add((string)customEmailsValue);
                                                }
                                            }
                                            ruleInstance.Actions.Add(ruleEmailActionInstance);
                                        }
                                    }
                                }

                                JToken lastUpdatedTimeValue = valueValue["LastUpdatedTime"];
                                if (lastUpdatedTimeValue != null && lastUpdatedTimeValue.Type != JTokenType.Null)
                                {
                                    DateTime lastUpdatedTimeInstance = (DateTime)lastUpdatedTimeValue;
                                    ruleInstance.LastUpdatedTime = lastUpdatedTimeInstance;
                                }
                            }
                        }
                    }

                    result.StatusCode = statusCode;
                    if (httpResponse.Headers.Contains("x-ms-request-id"))
                    {
                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                    }

                    if (shouldTrace)
                    {
                        Tracing.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }
示例#7
0
        public void AlertRuleCrudTest()
        {
            var handler = new RecordedDelegatingHandler()
            {
            };

            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                var alertsClient = GetAlertsClient(handler);

                // provision a hosted service to consume by the test case
                string newServiceName = TestUtilities.GenerateName("cs");

                var deploymentStatus = ProvisionHostedService(newServiceName);
                var deployment       = deploymentStatus.Deployments.FirstOrDefault();
                var id = HttpMockServer.GetVariable("RuleID", Guid.NewGuid().ToString());
                Assert.NotNull(deployment);

                // now the actual test case
                Rule newRule = new Rule
                {
                    Name        = TestUtilities.GenerateName("rule"),
                    Description = "rule description",
                    Id          = id,
                    IsEnabled   = false,
                    Condition   = new ThresholdRuleCondition
                    {
                        Operator   = ConditionOperator.GreaterThanOrEqual,
                        Threshold  = 80.0,
                        WindowSize = TimeSpan.FromMinutes(5),
                        DataSource = new RuleMetricDataSource
                        {
                            MetricName = "Percentage CPU",
                            ResourceId =
                                string.Format("/hostedservices/{0}/deployments/{1}/roles/{2}", newServiceName,
                                              deployment.Name, deployment.Roles.FirstOrDefault().RoleName),
                            MetricNamespace = MetricNamespace.None
                        }
                    }
                };

                newRule.Actions.Add(new RuleEmailAction());

                // Create the rule
                AzureOperationResponse createRuleResponse =
                    alertsClient.Rules.CreateOrUpdate(new RuleCreateOrUpdateParameters {
                    Rule = newRule
                });
                Assert.Equal(HttpStatusCode.Created, createRuleResponse.StatusCode);
                Console.WriteLine("Created alert rule {0}", newRule.Name);

                // Retrieve the rule
                RuleGetResponse getRuleResponse = alertsClient.Rules.Get(newRule.Id);
                Assert.Equal(HttpStatusCode.OK, getRuleResponse.StatusCode);
                Assert.True(AreEquivalent(newRule, getRuleResponse.Rule),
                            "The retrieved rule is not equivalent to the original rule");

                // Get incidents for the rule
                IncidentListResponse incidentListResponse = alertsClient.Incidents.ListForRule(newRule.Id, true);
                Assert.Equal(HttpStatusCode.OK, incidentListResponse.StatusCode);
                Assert.False(incidentListResponse.Any(),
                             string.Format("There should be no active incident for the rule [{0}].", newRule.Name));

                // Validate rule is included by list operation
                RuleListResponse listRulesResponse = alertsClient.Rules.List();
                Assert.Equal(HttpStatusCode.OK, getRuleResponse.StatusCode);
                Assert.True(listRulesResponse.Value.Any(),
                            "The alertClient.Rules.List() call returned an empty collection of alert rules");
                Assert.True(listRulesResponse.Value.Any(rc => rc.Id.Equals(newRule.Id)),
                            "The newly created rule is not in present in the collection of rules returned by alertClient.Rules.List()");

                // Update and validate the rule
                Rule updatedRule = newRule;
                updatedRule.Description = "updated description";
                ((ThresholdRuleCondition)(updatedRule.Condition)).Threshold = 60.0;
                AzureOperationResponse updateRuleResponse =
                    alertsClient.Rules.CreateOrUpdate(new RuleCreateOrUpdateParameters {
                    Rule = updatedRule
                });
                Assert.Equal(HttpStatusCode.OK, updateRuleResponse.StatusCode);

                getRuleResponse = alertsClient.Rules.Get(newRule.Id);
                Assert.Equal(HttpStatusCode.OK, getRuleResponse.StatusCode);
                Assert.True(AreEquivalent(updatedRule, getRuleResponse.Rule),
                            "The retrieved rule is not equivalent to the updated rule");

                // Delete the rule
                AzureOperationResponse deleteResponse = alertsClient.Rules.Delete(newRule.Id);
                Assert.Equal(HttpStatusCode.OK, deleteResponse.StatusCode);

                // Validate the rule was deleted
                Assert.Throws <CloudException>(() => alertsClient.Rules.Get(newRule.Id));

                listRulesResponse = alertsClient.Rules.List();
                Assert.Equal(HttpStatusCode.OK, getRuleResponse.StatusCode);
                if (listRulesResponse.Value.Count > 0)
                {
                    var foundDeletedRule = listRulesResponse.Value.Any(rc => rc.Id.Equals(newRule.Id));
                    Assert.False(foundDeletedRule, string.Format("Rule [{0}] is found after its deletion.", newRule.Name));
                }
            }
        }
        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("----------------------------------------------");
        }