Parsing Configuration File To Excel-Like View - c#

I have a firewall configuration file that goes like this:
{
"javaClass": "some text",
"rules": {
"javaClass": "java.util.LinkedList",
"list": [
{
"block": true,
"conditions": {
"javaClass": "java.util.LinkedList",
"list": [
{
"conditionType": "DST_PORT",
"invert": false,
"javaClass": "some text",
"value": "21"
}
]
},
"description": "Block and flag all traffic destined to port 21",
"enabled": false,
"flag": true,
"javaClass": "some text",
"ruleId": 100018
},
{
"block": true,
"conditions": {
"javaClass": "java.util.LinkedList",
"list": [
{
"conditionType": "SRC_ADDR",
"invert": false,
"javaClass": "some text",
"value": "1.2.3.4/255.255.255.0"
}
]
},
"description": "Block and flag all TCP traffic from 1.2.3.0 netmask 255.255.255.0",
"enabled": false,
"flag": true,
"javaClass": "some text",
"ruleId": 100019
},
{
"block": true,
"conditions": {
"javaClass": "java.util.LinkedList",
"list": [
{
"conditionType": "DST_ADDR",
"invert": false,
"javaClass": "some text",
"value": "1.2.3.4/255.255.255.0"
},
{
"conditionType": "DST_PORT",
"invert": false,
"javaClass": "some text",
"value": "1000-5000"
}
]
},
"description": "Accept and flag all traffic to the range 1.2.3.1 - 1.2.3.10 to ports 1000-5000",
"enabled": false,
"flag": true,
"javaClass": "some text",
"ruleId": 100020
}
]
},
"version": 1
}
I'm trying to extract the list part, then, extract parts of it for storing the data.
Now, I'm able to load the whole file using myConfigDetails.Text = File.ReadAllLines("firewall.settings_9.js");, but I'm unable to extract the data I want .. The rule can have no conditions, single conditions or multiple conditions ...
I created the class below to store the data in temporarily for further usage:
public class fwDATA
{
public string ruleID;
public bool ruleBlock;
public string ruleValue;
public string ruleDesc;
public bool ruleEnabled;
public bool ruleFlag;
}
Can someone guide me to the correct way to extract the list parts (both the rule and conditions)
Parts I need:
"block"
"conditionType"
"value"
"description"
"enabled"
"flag"
"ruleId"

Related

Multi-tab in message extension like shown in the microsoft documentation

How can I add multiple tab in message extension in Bot Framework using C# like as shown in this image here ?
enter image description here
You can add it by adding multiple search commands in the manifest file. Sharing part of JSON below.
"composeExtensions": [
{
"botId": "448ec85c-4395-4f80-b5a1-cd3bdefd1f5b",
"canUpdateConfiguration": true,
"commands": [
{
"id": "searchQuery",
"context": [
"compose",
"commandBox"
],
"description": "Test command to run query",
"title": "Search",
"type": "query",
"initialRun": true,
"parameters": [
{
"name": "searchQuery",
"title": "Search Query",
"description": "Your search query",
"inputType": "text"
}
]
},
{
"id": "searchQuery2",
"context": [
"compose",
"commandBox"
],
"description": "Test command to run query2",
"title": "Search2",
"type": "query",
"initialRun": true,
"parameters": [
{
"name": "searchQuery2",
"title": "Search Query2",
"description": "Your search query2",
"inputType": "text"
}
]
},
{
"id": "searchQuery3",
"context": [
"compose",
"commandBox"
],
"description": "Test command to run query",
"title": "Search3",
"type": "query",
"initialRun": true,
"parameters": [
{
"name": "searchQuery3",
"title": "Search Query3",
"description": "Your search query3",
"inputType": "text"
}
]
}
]
Here is the sample - https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/csharp_dotnetcore/50.teams-messaging-extensions-search

Convert HTTPResponse Message (Json)

I am trying to convert the content of a response message to a list of items contained within the response message and keep running into issues, the returned json looks like this:
Jason output
Here is the whole returned response content:
{
"Version": 1,
"Result": "Success",
"Data": {
"Tasks": [
{
"Oid": "f70b1a46-690f-4637-886b-f90f035a11e8",
"CreatedOn": "2022-07-15T00:07:41.553Z",
"ChangedOn": "2022-07-15T03:39:58.373Z",
"Subject": "233817 3693 Range Rd",
"Description": "",
"Comment": "",
"IsStarted": true,
"IsFinished": true,
"IsFinalAppointment": false,
"ScheduledOn": "2022-07-15T09:37:41.553",
"ProductionDeadline": "0001-01-01T00:00:00",
"ScheduledStart": "2022-07-15T09:45:00",
"ScheduledEnd": "2022-07-15T09:50:00",
"RealStart": "2022-07-15T09:45:00",
"RealEnd": "2022-07-15T09:50:00",
"CalculatedSeconds": 300.0000,
"IdleSeconds": 0,
"ScheduledDuration": "PT5M",
"RealDuration": "PT5M",
"Status": 2,
"PercentComplete": 100,
"HasFinishedItems": true,
"IsCustomTask": false,
"AppointmentType": "OrderSpecificAppointment",
"OrderItemCount": 31,
"OrderItemPartsCount": 56,
"MaterialUsageTotal": 58.3280000000,
"MaterialUsageTotalConverted": 58.328,
"MaterialUsageNet": 46.9659000000,
"MaterialUsageNetConverted": 46.9659,
"MaterialUsageScrap": 11.3621000000,
"MaterialUsageScrapConverted": 11.3621,
"MaterialUsageTotalWeight": 263.4676,
"MaterialUsageTotalWeightConverted": 263.4676,
"MaterialUsageNetWeight": 212.1449000000,
"MaterialUsageNetWeightConverted": 212.14490,
"MaterialUsageScrapWeight": 51.3227000000,
"MaterialUsageScrapWeightConverted": 51.32270,
"Station": {
"_Value": "Centurio",
"oid": "f7f3c5fe-49f0-4a9a-b366-29c4ab990fc7"
},
"Materials": [
{
"_Value": "STEALTH MATTE .55 (MONUMENT†)",
"oid": "4889a4f2-75c6-4fb2-b57d-d393ff495ef1",
"externalID": "161539"
}
],
"MaterialCoils": [],
"MaterialDimensions": [],
"PreviousDependencies": [],
"NextDependencies": [
{
"_Value": "",
"oid": "4699df81-4d5c-456c-904d-389a08f60a82",
"start": "2022-07-17T03:37:00",
"station": "Unallocated Folding Station"
}
]
},
{
"Oid": "4699df81-4d5c-456c-904d-389a08f60a82",
"CreatedOn": "2022-07-15T00:07:41.567Z",
"ChangedOn": "2022-07-15T08:27:19.297Z",
"Subject": "233817 3693 Range Rd",
"Description": "",
"Comment": "",
"IsStarted": true,
"IsFinished": true,
"IsFinalAppointment": true,
"ScheduledOn": "2022-07-15T09:37:41.567",
"ProductionDeadline": "0001-01-01T00:00:00",
"ScheduledStart": "2022-07-17T03:37:00",
"ScheduledEnd": "2022-07-17T06:33:00",
"RealStart": "2022-07-17T03:37:00",
"RealEnd": "2022-07-17T06:33:00",
"CalculatedSeconds": 10560.0000,
"IdleSeconds": 0,
"ScheduledDuration": "PT2H56M",
"RealDuration": "PT2H56M",
"Status": 2,
"PercentComplete": 100,
"HasFinishedItems": true,
"IsCustomTask": false,
"AppointmentType": "OrderSpecificAppointment",
"OrderItemCount": 31,
"OrderItemPartsCount": 56,
"MaterialUsageTotal": 46.9659000000,
"MaterialUsageTotalConverted": 46.9659,
"MaterialUsageNet": 46.9659000000,
"MaterialUsageNetConverted": 46.9659,
"MaterialUsageScrap": 0.0000000000,
"MaterialUsageScrapConverted": 0.0,
"MaterialUsageTotalWeight": 212.1449,
"MaterialUsageTotalWeightConverted": 212.1449,
"MaterialUsageNetWeight": 212.1449000000,
"MaterialUsageNetWeightConverted": 212.14490,
"MaterialUsageScrapWeight": 0.0000000000,
"MaterialUsageScrapWeightConverted": 0.00000,
"Station": {
"_Value": "Unallocated Folding Station",
"oid": "7ce5334a-b05c-4511-be7b-1a83d2bf8d4c"
},
"Materials": [
{
"_Value": "STEALTH MATTE .55 (MONUMENT†)",
"oid": "4889a4f2-75c6-4fb2-b57d-d393ff495ef1",
"externalID": "161539"
}
],
"PreviousDependencies": [
{
"_Value": "",
"oid": "f70b1a46-690f-4637-886b-f90f035a11e8",
"start": "2022-07-15T09:45:00",
"station": "Centurio"
}
],
"NextDependencies": []
}
]
},
"Details": ""
}
I wish to extract each task from the "Tasks" element into a list (I have created a class to hold each Task element). So far my code looks like this:
public async void AppointmentsAsync(int taskScheduleID)
{
HttpResponseMessage taskList;
using (RevSchedDataContext context = new RevSchedDataContext())
{
string TimePrint = ConfigurationManager.AppSettings["TimePrint"];
schedule = (from s in context.TaskSchedules.Where(x => x.TaskScheduleID == taskScheduleID) select s).FirstOrDefault();
client.BaseAddress = new Uri("http://bendex.revroof.com.au/microsea/BendexRevBend/import/1.0/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
taskList = await client.GetAsync($"{client.BaseAddress}GetOrderScheduledTasksListJson?did=233817");
var products = await taskList.Content.ReadAsStringAsync();
var mtLists = JsonConvert.DeserializeObject<BendexTaskList>(products);
}
}
When putting a breakpoint on mtLists line and stepping mtLists never get populated.
Regards
Peter
I have found a solution to my problem thanks to the following site: https://json2csharp.com/
This enabled me to create the correct required classes to deserialize the json output in the format required to process.
New calling code:
Root scheduledTaskList = JsonConvert.DeserializeObject<Root>(products);
foreach(var tsk in scheduledTaskList.Data.Tasks)
{
//ToDo: pull required data and update table
}
Regards
Peter

Trying to setup diagnostic settings for activity logs in ARM template

I've been trying to create a template for a logger function app in Azure, the basic idea is that it'll forward all activity log category info along with all audit log info using event hubs as triggers, I've gotten down most of the template, but I keep hitting the following error when it comes to the diagnostic settings part:
The resource type '/' does not support diagnostic settings.
Is there something I'm doing wrong? I've only started working with azure for a short while, and am afraid I'm misunderstanding how diagnostic settings are created in an ARM template. I can't seem to find any template or documentation online about this, and am at a loss...
Here's an excerpt:
...
"variables": {
"eventHubNamespaceName": "azure-logger",
"auditEventHubName": "[concat(variables('eventHubNamespaceName'), '/', 'audit-logs')]",
"activityEventHubName": "[concat(variables('eventHubNamespaceName'), '/', 'activity-logs')]",
"authRuleResourceId": "[resourceId('Microsoft.Eventhub/namespaces/authorizationRules', variables('eventHubNamespaceName'), 'RootManageSharedAccessKey')]",
"auditAuthorizationRuleId": "[resourceId('Microsoft.EventHub/namespaces/eventhubs/authorizationRules', variables('eventHubNamespaceName') , 'audit-logs', 'default')]",
"activityAuthorizationRuleId": "[resourceId('Microsoft.EventHub/namespaces/eventhubs/authorizationRules', variables('eventHubNamespaceName') , 'activity-logs', 'default')]"
},
"resources": [
{
"name": "[variables('eventHubNamespaceName')]",
"type": "Microsoft.EventHub/namespaces",
"apiVersion": "2021-06-01-preview",
"location": "[parameters('location')]",
"sku": {
"name": "Standard"
},
"identity": {
"type": "SystemAssigned"
},
"properties": {
"status": "Active"
},
"resources": [
{
"type": "Microsoft.EventHub/namespaces/eventhubs",
"apiVersion": "2021-06-01-preview",
"name": "[concat(variables('eventHubNamespaceName'), '/', 'audit-logs')]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.EventHub/namespaces', variables('eventHubNamespaceName'))]"
],
"properties": {
"messageRetentionInDays": 1,
"partitionCount": 1
},
"resources": [
{
"type": "Microsoft.EventHub/namespaces/eventhubs/authorizationRules",
"apiVersion": "2021-06-01-preview",
"name": "[concat(variables('eventHubNamespaceName'), '/', 'audit-logs','/','default')]",
"properties": {
"rights": [ "Manage", "Listen", "Send" ]
},
"dependsOn": [
"[resourceId('Microsoft.EventHub/namespaces/eventhubs', variables('eventHubNamespaceName'), 'audit-logs')]"
]
}
]
},
{
"type": "Microsoft.EventHub/namespaces/eventhubs",
"apiVersion": "2021-06-01-preview",
"name": "[concat(variables('eventHubNamespaceName'), '/', 'activity-logs')]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.EventHub/namespaces', variables('eventHubNamespaceName'))]"
],
"properties": {
"messageRetentionInDays": 1,
"partitionCount": 1
},
"resources": [
{
"type": "Microsoft.EventHub/namespaces/eventhubs/authorizationRules",
"apiVersion": "2021-06-01-preview",
"name": "[concat(variables('eventHubNamespaceName'), '/', 'activity-logs','/','default')]",
"properties": {
"rights": [ "Manage", "Listen", "Send" ]
},
"dependsOn": [
"[resourceId('Microsoft.EventHub/namespaces/eventhubs', variables('eventHubNamespaceName'), 'activity-logs')]"
]
}
]
}
]
},
{
"type": "Microsoft.Insights/diagnosticSettings",
"apiVersion": "2017-05-01-preview",
"name": "[concat(variables('eventHubNamespaceName'),'activity-logs')]",
"properties": {
"eventHubName": "activity-logs",
"eventHubAuthorizationRuleId": "[variables('activityAuthorizationRuleId')]",
"logs": [
{
"category": "Administrative",
"enabled": true
},
{
"category": "Security",
"enabled": true
},
{
"category": "ServiceHealth",
"enabled": true
},
{
"category": "Alert",
"enabled": true
},
{
"category": "Recommendation",
"enabled": true
},
{
"category": "Policy",
"enabled": true
},
{
"category": "Autoscale",
"enabled": true
},
{
"category": "ResourceHealth",
"enabled": true
}
]
}
}
]
...```
Diagnostic settings for Activity logs are created for a subscription, not for a resource group like settings for Azure resources. Therefore, when you check the Diagnostic setting for Activity log in this document, you will find that you can deploy Azure Resource Manager templates using any valid method including PowerShell and CLI. Diagnostic settings for Activity log must deploy to a subscription using az deployment create for CLI or New-AzDeployment for PowerShell.
And the template should look like as following :
{
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"settingName": {
"type": "String"
},
"workspaceId": {
"type": "String"
},
"storageAccountId": {
"type": "String"
},
"eventHubAuthorizationRuleId": {
"type": "String"
},
"eventHubName": {
"type": "String"
}
},
"resources": [
{
"type": "Microsoft.Insights/diagnosticSettings",
"apiVersion": "2017-05-01-preview",
"name": "[parameters('settingName')]",
"properties": {
"workspaceId": "[parameters('workspaceId')]",
"storageAccountId": "[parameters('storageAccountId')]",
"eventHubAuthorizationRuleId": "[parameters('eventHubAuthorizationRuleId')]",
"eventHubName": "[parameters('eventHubName')]",
"logs": [
{
"category": "Administrative",
"enabled": true
},
{
"category": "Security",
"enabled": true
},
{
"category": "ServiceHealth",
"enabled": true
},
{
"category": "Alert",
"enabled": true
},
{
"category": "Recommendation",
"enabled": true
},
{
"category": "Policy",
"enabled": true
},
{
"category": "Autoscale",
"enabled": true
},
{
"category": "ResourceHealth",
"enabled": true
}
]
}
}
]
}
You should have a Parameter file if you follow the above template.
Also note that when virtual networks are enabled Diagnostic Settings can't access Event Hubs resources. You have to enable the Allow trusted Microsoft services to bypass this firewall setting in Event Hub, so that Diagnostic Settings (Azure Monitor Services) is granted access to your Event Hubs resources.

Jquery datatable search text

How can I catch search text with a parameter in server side. It's always null when I debug the program. I saw this Request.Form.GetValues("search[value]")[0] but I want to take it as a parameter. Is it possible ?
$('#datatableClients').DataTable({
"processing": true,
"serverSide": true,
"filter": true,
"orderMulti": false,
"ajax": {
"url": "/Custom/Data/GetRows",
"type": "POST",
"datatype": "json"
},
"columns": [
{ "data": "FirstName", "name": "First Name", "autoWidth": true },
{ "data": "LastName", "name": "Last Name", "autoWidth": true }
]
});
public JsonResult GetRows(int draw, int start, int length, string search)
{
// search parameter is null
}

C# Get Json sub values

I have a API response has a structure like shown below. How can I get the values from this Json string?
[
{
"id": xxx,
"profileId": xxx,
"recipientId": xxx,
"creationTime": "xxxx",
"modificationTime": "xxxx",
"active": true,
"eligible": true,
"balances": [
{
"balanceType": "AVAILABLE",
"currency": "EUR",
"amount": {
"value": 55555,
"currency": "EUR"
},
"reservedAmount": {
"value": 0,
"currency": "EUR"
},
"bankDetails": {
"id": xxx,
"currency": "EUR",
"bankCode": "code",
"accountNumber": "account number",
"swift": "swift",
"iban": "iban",
"bankName": "bankName",
"accountHolderName": "accountHolderName",
"bankAddress": {
"addressFirstLine": "bankAddress",
"postCode": "xxxxx",
"city": "xxxxx",
"country": "xxxxx",
"stateCode": null
}
}
}
]
}
]
I am using The below extension method to get data for some other API's I have integrated in my system. This works fine for the other API's I have integrated.
public static string GetJsonField(RestSharp.IRestResponse value, string res)
{
Newtonsoft.Json.Linq.JObject json = Newtonsoft.Json.Linq.JObject.Parse(value.Content);
res = json.GetValue(res).ToString();
return res;
}
Thanks in advance
Copy that Json in json2csharp.com, it will give you the classes that you will need to convert the Json in a c# object.
Then just use var myJson = JsonConverter.deserialize(Json) ;
And you can access to the Json properties as you do with any other class

Categories

Resources