Looking for a visual studio visualizer (natvis) for JsonCpp - jsoncpp

I'm looking for a natvis file for JsonCpp and I can't find any.
Does anyone know of such a file?

Edit: I've added this file to the visualstudio-debugger repository on GitHub.
Edit2: Two other answers to this question have linked to other github repositories (which I haven't checked out). For some reason they were deleted by admins (I have no idea why) so here they are:
#Dmitry Yastrebkov posted https://github.com/dmirys/jsoncpp.natvis
#mojmir posted https://github.com/mojmir-svoboda/json.natvis
Since nobody came through with an answer (and some people think this is off topic on stackoverflow for some reason) I wrote my own, here it is. Use at your own risk.
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<!-- Json::Value - basic support -->
<Type Name="Json::Value">
<DisplayString Condition="type_ == 0">null</DisplayString>
<DisplayString Condition="type_ == 1">{value_.int_}</DisplayString>
<DisplayString Condition="type_ == 2">{value_.uint_}</DisplayString>
<DisplayString Condition="type_ == 3">{value_.real_}</DisplayString>
<DisplayString Condition="type_ == 4">{value_.string_,s8}</DisplayString>
<DisplayString Condition="type_ == 5">{value_.bool_}</DisplayString>
<DisplayString Condition="type_ == 6">array ({value_.map_->_Mysize})</DisplayString>
<DisplayString Condition="type_ == 7">object ({value_.map_->_Mysize})</DisplayString>
<DisplayString >Unknown Value type!</DisplayString>
<StringView Condition="type_ == 4">value_.string_,s8</StringView>
<Expand>
<ExpandedItem Condition="type_ == 6">*(value_.map_)</ExpandedItem>
<ExpandedItem Condition="type_ == 7">*(value_.map_)</ExpandedItem>
</Expand>
</Type>
<!-- Key/value pairs - used as values for objects and arrays (in arrays the key is null so don't display it) -->
<Type Name="std::pair<Json::Value::CZString const ,Json::Value>">
<DisplayString Condition="first.cstr_ != nullptr">{first.cstr_,s8}: {second}</DisplayString>
<DisplayString>{second}</DisplayString>
<Expand>
<Item Name="key" Condition="first.cstr_ != nullptr">first.cstr_</Item>
<Item Name="value" Condition="first.cstr_ != nullptr">second</Item>
<ExpandedItem>second</ExpandedItem>
</Expand>
</Type>
</AutoVisualizer>

Based on the (deleted) answer of Dmitry Yastrebkov I made the following one that seems to be working nicely for me:
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="std::map<*>" IncludeView="jsoncpp">
<Expand>
<TreeItems>
<Size>_Mypair._Myval2._Myval2._Mysize</Size>
<HeadPointer>_Mypair._Myval2._Myval2._Myhead->_Parent</HeadPointer>
<LeftPointer>_Left</LeftPointer>
<RightPointer>_Right</RightPointer>
<ValueNode Condition="_Isnil == 0 && true" Name="{_Myval,view(jsonname)}">_Myval,view(jsoncpp)</ValueNode>
</TreeItems>
</Expand>
</Type>
<Type Name="std::pair<*>" IncludeView="jsonname">
<DisplayString Condition="first.cstr_ == nullptr">[{first.index_}]</DisplayString>
<DisplayString Condition="first.cstr_ != nullptr">{first.cstr_,s8}</DisplayString>
</Type>
<Type Name="std::pair<*>" IncludeView="jsoncpp">
<DisplayString Condition="second.type_ == 0 && true">null</DisplayString>
<DisplayString Condition="second.type_ == 1 && true">{second.value_.int_}</DisplayString>
<DisplayString Condition="second.type_ == 2 && true">{second.value_.uint_}</DisplayString>
<DisplayString Condition="second.type_ == 3 && true">{second.value_.real_}</DisplayString>
<DisplayString Condition="second.type_ == 4 && true">{second.value_.string_,s8}</DisplayString>
<DisplayString Condition="second.type_ == 5 && true">{second.value_.bool_}</DisplayString>
<DisplayString Condition="second.type_ == 6 && true">array({second.value_.map_->_Mypair._Myval2._Myval2._Mysize})</DisplayString>
<DisplayString Condition="second.type_ == 7 && true">object({second.value_.map_->_Mypair._Myval2._Myval2._Mysize})</DisplayString>
<StringView Condition="second.type_ == 1 && first.cstr_ != nullptr">first.cstr_,s8</StringView>
<StringView Condition="second.type_ == 2 && first.cstr_ != nullptr">first.cstr_,s8</StringView>
<StringView Condition="second.type_ == 3 && first.cstr_ != nullptr">first.cstr_,s8</StringView>
<StringView Condition="second.type_ == 4 && true">second.value_.string_,s8</StringView>
<StringView Condition="second.type_ == 5 && first.cstr_ != nullptr">first.cstr_,s8</StringView>
<StringView Condition="second.type_ == 6 && first.cstr_ != nullptr">first.cstr_,s8</StringView>
<StringView Condition="second.type_ == 7 && first.cstr_ != nullptr">first.cstr_,s8</StringView>
<Expand>
<ExpandedItem Condition="second.type_ == 6">*(second.value_.map_),view(jsoncpp)</ExpandedItem>
<ExpandedItem Condition="second.type_ == 7">*(second.value_.map_),view(jsoncpp)</ExpandedItem>
</Expand>
</Type>
<Type Name="Json::Value">
<Expand>
<ExpandedItem Condition="type_ == 6">*(value_.map_),view(jsoncpp)</ExpandedItem>
<ExpandedItem Condition="type_ == 7">*(value_.map_),view(jsoncpp)</ExpandedItem>
</Expand>
</Type>
</AutoVisualizer>

Related

How to use the same clicked.connect function for multiple buttons?

I am working on a GUI in pyqt5, that using a database (sqlite3). First, I'm uploading the entire data into a QTableWidget. Then, depending on the user filter parameters (2 comboboxes and 2 free text lineEdits which are signaled by 1 button), the filtering function is called and the data is filtered. The user may do another filter afterwards, and the table will be filtered again according to the new request.
The filter function is called upon one of three conditions:
The first combobox text changed ("comboType")
The second combobox text changed ("comboMaterial")
The button "Filter Ac/AL" clicked ("pbFilter ALAc")
The question: the filtering is always initializes when the "comboType" text is changed only (since it's the first signal). When the user wants to filter according to the second or third conditions, the function can not be called and the filtering can not be conducted. The script is stuck until the first condition will occur (call the comboType.currentTextChanged.connect).
Is there any way to "jump" to the second or third condition when clicked?
### Apply first filter when ComboBox changed###
self.uiCoresDBWin.comboType.currentTextChanged.connect(lambda: updateCoresTable())
self.uiCoresDBWin.comboMaterial.currentTextChanged.connect(lambda: updateCoresTable())
self.uiCoresDBWin.pbFilterALAc.clicked.connect(lambda: updateCoresTable())
`your text`
def updateCoresTable():
db = sqlite3.connect("ferrite_cores_db.db")
cursor = db.cursor()
typeIndex = self.uiCoresDBWin.comboType.currentIndex()+1
typeData = self.uiCoresDBWin.comboType.currentText()
materialIndex = self.uiCoresDBWin.comboMaterial.currentIndex()
materialData = self.uiCoresDBWin.comboMaterial.currentText()
typedAc = self.uiCoresDBWin.leAe.text()
typedAL = self.uiCoresDBWin.leAL.text()
if typeIndex == 0 and materialIndex == 0 and typedAc == '' and typedAL == '':
result = cursor.execute("SELECT * from ferrite_cores")
elif typeIndex == 0 and materialIndex == 0 and typedAc == '' and typedAL != '':
result = cursor.execute("SELECT * from ferrite_cores WHERE AL >=?", (typedAL,))
elif typeIndex == 0 and materialIndex == 0 and typedAc != '' and typedAL == '':
result = cursor.execute("SELECT * from ferrite_cores WHERE Aef >=?", (typedAc,))
elif typeIndex == 0 and materialIndex != 0 and typedAc != '' and typedAL != '':
result = cursor.execute("SELECT * from ferrite_cores WHERE Aef >=? and AL >=?", (typedAc, typedAL))
elif typeIndex == 0 and materialIndex != 0 and typedAc == '' and typedAL == '':
result = cursor.execute("SELECT * from ferrite_cores WHERE Material ==?", (materialData,))
elif typeIndex == 0 and materialIndex != 0 and typedAc == '' and typedAL != '':
result = cursor.execute("SELECT * from ferrite_cores WHERE Material ==? and AL >=?", (materialData, typedAL))
elif typeIndex == 0 and materialIndex != 0 and typedAc != '' and typedAL == '':
result = cursor.execute("SELECT * from ferrite_cores WHERE Material ==? and Aef >=?", (materialData, typedAc))
elif typeIndex == 0 and materialIndex != 0 and typedAc != '' and typedAL != '':
result = cursor.execute("SELECT * from ferrite_cores WHERE Material ==? and Aef >=? and AL >=?", (materialData, typedAc, typedAL))
elif typeIndex != 0 and materialIndex == 0 and typedAc == '' and typedAL == '':
result = cursor.execute("SELECT * from ferrite_cores WHERE Type == ?", (typeData,))
elif typeIndex != 0 and materialIndex == 0 and typedAc == '' and typedAL != '':
result = cursor.execute("SELECT * from ferrite_cores WHERE Type ==? and AL >=?", (typeData, typedAL))
elif typeIndex != 0 and materialIndex == 0 and typedAc != '' and typedAL == '':
result = cursor.execute("SELECT * from ferrite_cores WHERE Type ==? and Aef >=?", (typeData, typedAc))
elif typeIndex != 0 and materialIndex == 0 and typedAc != '' and typedAL != '':
result = cursor.execute("SELECT * from ferrite_cores WHERE Type ==? and AL >=? and Aef >=?", (typeData, typedAL, typedAc))
elif typeIndex != 0 and materialIndex != 0 and typedAc == '' and typedAL == '':
result = cursor.execute("SELECT * from ferrite_cores WHERE Type ==? and Material ==?", (typeData, materialData))
elif typeIndex != 0 and materialIndex != 0 and typedAc == '' and typedAL != '':
result = cursor.execute("SELECT * from ferrite_cores WHERE Type ==? and Material ==? and AL >=?", (typeData, materialData, typedAL))
elif typeIndex != 0 and materialIndex != 0 and typedAc != '' and typedAL == '':
result = cursor.execute("SELECT * from ferrite_cores WHERE Type ==? and Material ==? and Aef >=?", (typeData, materialData, typedAc))
elif typeIndex != 0 and materialIndex != 0 and typedAc != '' and typedAL != '':
result = cursor.execute("SELECT * from ferrite_cores WHERE Type ==? and Material ==? and Aef >=? and AL >=?", (typeData, materialData, typedAc, typedAL))
self.uiCoresDBWin.CoresTab.setRowCount(0)
for row_number, row_data in enumerate(result):
self.uiCoresDBWin.CoresTab.insertRow(row_number)
for column_number, data in enumerate(row_data):
self.uiCoresDBWin.CoresTab.setItem(row_number, column_number, QtWidgets.Q

ASP.NET MVC Entity Framework 5 get true,false or both result

I have a table that I am filtering on. There is a four filters status, project, department, KPI
KPI is a boolean value. This filter has three value. True, False or both.
So, when the filter is true, it should return 'true' data, when the filter is 'false', return 'false' data; and when 'all' return both true and false data.
My code attached below, how can I enhance this code ? Can I write this with out if else conditions
var result = new List<TaskMaster>();
bool kpidata;
if (request.IsKPI == 1) { kpidata = true; } else { kpidata = false; }
//For KPI Tasks
if (request.IsKPI == 1 || request.IsKPI == 0)
{
result = await _context.TaskMaster.Where(c => c.IsActive && (c.Status == request.Status || request.Status == "All") && (c.ProjectId == request.ProjectId || request.ProjectId == 0) && (c.IsKPI == kpidata) && (c.AssignedTo.DepartmentId == request.DepartmentId || request.DepartmentId == 0)).Include(y => y.TaskActionLogs)
.Include(y => y.AssignedTo)
.Include(y => y.AssignedBy)
.Include(y => y.Project)
.AsSplitQuery().ToListAsync();
//For Non-KPI Tasks
}
else {
result = await _context.TaskMaster.Where(c => c.IsActive && (c.Status == request.Status || request.Status == "All") && (c.ProjectId == request.ProjectId || request.ProjectId == 0) && (c.AssignedTo.DepartmentId == request.DepartmentId || request.DepartmentId == 0)).Include(y => y.TaskActionLogs)
.Include(y => y.AssignedTo)
.Include(y => y.AssignedBy)
.Include(y => y.Project)
.AsSplitQuery().ToListAsync();
}
Revise the code, both queries are almost identical except c.IsKPI == kpidata part.
Few ways to remove the redundant:
Write the IQueryable query and append the .Where() if the condition meets. You are fine to append/extend the query before the query is materialized (via .ToList(), .First() etc.).
var result = new List<TaskMaster>();
bool kpidata;
if (request.IsKPI == 1) { kpidata = true; } else { kpidata = false; }
IQueryable<TaskMaster> query = _context.TaskMaster
.Where(c => c.IsActive
&& (c.Status == request.Status || request.Status == "All")
&& (c.ProjectId == request.ProjectId || request.ProjectId == 0)
&& (c.AssignedTo.DepartmentId == request.DepartmentId || request.DepartmentId == 0));
//For KPI Tasks
if (request.IsKPI == 1 || request.IsKPI == 0)
{
query = query.Where(c => c.IsKPI == kpidata);
}
result = await query.Include(y => y.TaskActionLogs)
.Include(y => y.AssignedTo)
.Include(y => y.AssignedBy)
.Include(y => y.Project)
.AsSplitQuery()
.ToListAsync();
You can also migrate the if logic to the query too.
&& (!(request.IsKPI == 1 || request.IsKPI == 0) || c.IsKPI == kpidata)
If !(request.IsKPI == 1 || request.IsKPI == 0) returns true, the c.IsKPI == kpidata part will be omitted.
result = await _context.TaskMaster
.Where(c => c.IsActive
&& (c.Status == request.Status || request.Status == "All")
&& (c.ProjectId == request.ProjectId || request.ProjectId == 0)
&& (c.AssignedTo.DepartmentId == request.DepartmentId || request.DepartmentId == 0)
&& (!(request.IsKPI == 1 || request.IsKPI == 0) || c.IsKPI == kpidata))
.Include(y => y.TaskActionLogs)
.Include(y => y.AssignedTo)
.Include(y => y.AssignedBy)
.Include(y => y.Project)
.AsSplitQuery()
.ToListAsync();
This
(request.IsKPI == 1 || request.IsKPI == 0)
can also be revised to:
(new List<int> { 0, 1 }).Contains(request.IsKPI)

Expressions in a querybuildRange

Hi I am trying to do this query:
Select ProjInvoiceJour
where NOT (ProjInvoiceJour.ProjInvoiceType == ProjInvoiceType::Onaccount && ProjInvoiceJour.CountryRegionID != "ES")
But I need to do it whit querybuilder:
qbds.addRange(fieldnum(ProjInvoiceJour, ProjInvoiceType)).value(strfmt('!%1',
strfmt("((%1.%2 == %3) && (%4.%5 != '%6'))",
tablestr(ProjInvoiceJour),
fieldstr(ProjInvoiceJour, ProjInvoiceType),
any2int(ProjInvoiceType::OnAccount),
tablestr(ProjInvoiceJour),
fieldstr(ProjInvoiceJour, CountryRegionID),
queryvalue("ES"))));
But the query has some error:
SELECT * FROM ProjInvoiceJour WHERE ((NOT (ProjInvoiceType = 255)))
Thanks
The law of De Morgan comes to rescue:
select ProjInvoiceJour
where !(ProjInvoiceJour.ProjInvoiceType == ProjInvoiceType::Onaccount &&
ProjInvoiceJour.CountryRegionID != 'ES')
is equivalent to:
select ProjInvoiceJour
where ProjInvoiceJour.ProjInvoiceType != ProjInvoiceType::Onaccount ||
ProjInvoiceJour.CountryRegionID == 'ES'
Or in a query:
qbds.addRange(fieldnum(ProjInvoiceJour, ProjInvoiceType)).value(strfmt('((%1.%2 != %3) || (%4.%5 == "%6"))',
tablestr(ProjInvoiceJour),
fieldstr(ProjInvoiceJour, ProjInvoiceType),
0+ProjInvoiceType::OnAccount,
tablestr(ProjInvoiceJour),
fieldstr(ProjInvoiceJour, CountryRegionID),
'ES'));

Cant filter dynamic query

Hi i got question for the entity query. Please see my code
var list = from table in db.USER_BETTINGS
where table.UserID == UserId
&& table.UserID !="admin"
//&& table.WinningAfterRebate != 0m
&& table.BettingTransactionTime >= fromDate &&
table.BettingTransactionTime <= toDAte
//&& table.WinningAfterRebate !=0m
// orderby table.BettingTransactionNumber descending//table.BettingNumber descending//, table.BettingTransactionTime descending//
select table;
if (loteryNumber != 0)
{
list= list.Where(x => x.LotteryNumber == loteryNumber);
}
if (gameNum != 0)
{
list= list.Where(x => x.GameNumber == gameNum);
}
if (periodDate != "")
{
list= list.Where(x => x.PeriodDate == periodDate);
}
if (close.Equals("Y"))
{
list= list.Where(w => w.WinningAfterRebate != 0m);
}
else
{
list= list.Where(x => x.WinningAfterRebate == 0);
}
But the list not filtering , It return all record? Anyone got face this problem before?
You need some makeover in this code. You have unnecessarily used so many if condition, we need to get rid of that first. Change your query with the following.
var list =( from table in db.USER_BETTINGS
where table.UserID == UserId
&& table.UserID !="admin"
&& table.BettingTransactionTime >= fromDate
&& table.BettingTransactionTime <= toDAte
&& table.LotteryNumber == (loteryNumber != 0 ? loteryNumber : table.LotteryNumber)
&& table.GameNumber == (gameNum != 0 ? gameNum : table.GameNumber)
&& table.PeriodDate == (periodDate != string.Empty ? periodDate : table.PeriodDate )
&& (close.Equals("Y") ? table.WinningAfterRebate != 0 : table.WinningAfterRebate == 0)
).ToList();

Is there an overhead with tracking when using EF6.1 and if so how can I remove this?

I have some complex queries like this:
var contents = await db.Contents
.Where(q => q.ContentStatusId == contentStatusId || contentStatusId == 0)
.Where(q => q.ContentTypeId == contentTypeId || contentTypeId == 0)
.Where(q => q.CreatedBy == contentCreatedBy || contentCreatedBy == "0")
.Where(q => q.ModifiedBy == contentModifiedBy || contentModifiedBy == "0")
.Where(q => q.SubjectId == subjectId)
.ToListAsync();
I send the results back to my web API and I do not need any tracking. Does EF automatically add tracking and if so is that an overhead that I do not need. Also if it does then is there a way I can turn off the tracking ?
Yes there is an overhead. You can use AsNoTracking() on IQueryable or your DbSet.
var contents = await db.Contents
.Where(q => q.ContentStatusId == contentStatusId || contentStatusId == 0)
.Where(q => q.ContentTypeId == contentTypeId || contentTypeId == 0)
.Where(q => q.CreatedBy == contentCreatedBy || contentCreatedBy == "0")
.Where(q => q.ModifiedBy == contentModifiedBy || contentModifiedBy == "0")
.Where(q => q.SubjectId == subjectId)
.AsNoTracking()
.ToListAsync();

Resources