The ""sort"" value has to be formed as this example: ""field_ASC"" - vb.net

I'm developing an integration between a ERP and a Prestashop store, I'm now trying to use a product filter to check if a product already exists, so i can either add a new product or update an existing one.
When I try to get the filter result i got a XML response with the following error message
<![CDATA[The ""sort"" value has to be formed as this example: ""field_ASC"" or '[field_1_DESC,field_2_ASC,field_3_ASC,...]' (""field"" has to be an available field)]]>
I didn't understand what that really means, I have searched around a while and coudn't find any specific problem like this and all the examples I've found are the same.
Here is my code, it is in VB and I'm using Bukimedia Prestasharp
Dim oProdFac = New ProductFactory(oParameters.UrlAPI, oParameters.TokenAPI, oParameters.KeyAPI)
Dim objFiltro = New Dictionary(Of String, String)
Dim listFilterProducts As New List(Of Bukimedia.PrestaSharp.Entities.product)
objFiltro.Add("reference", "My_Product_Id")
listFilterProducts = oProdFac.GetByFilter(objFiltro, "null", "null")
What am I doing wrong?

Allright, the answer is SO SIMPLE that i felt ashamed.
I was sending incorrect parameters in the GetByFilter function.
I've changed this
listFilterProducts = oProdFac.GetByFilter(objFiltro, "null", "null")
to this
listFilterProducts = oProdFac.GetByFilter(objFiltro, "reference_ASC", "null")
Just like the xml message said. It solved the problem.

Related

Dynamically choose version from multiple namespaces

Select Case FIXV
Case "FIX44"
Dim _message As QuickFix.FIX44.Heartbeat = New QuickFix.FIX44.Heartbeat
_message.Header.SetField(New MsgSeqNum(_csession.NextSenderMsgSeqNum))
_message.Header.SetField(New MsgType(0))
_message.Validate()
Case "FIX43"
Dim _message As QuickFix.FIX43.Heartbeat = New QuickFix.FIX43.Heartbeat
_message.Header.SetField(New MsgSeqNum(_csession.NextSenderMsgSeqNum))
_message.Header.SetField(New MsgType(0))
_message.Validate()
Case Else
End Select
Is there a way to simplify the following code, by dynamically choosing the FIX version 4.4 or 4.3? Thanks.
OpenAI gave me this which works:
Dim _message As QuickFix.Message = Nothing
Select Case FIXV
Case "FIX44"
_message = New QuickFix.FIX44.Heartbeat()
Case "FIX43"
_message = New QuickFix.FIX43.Heartbeat()
End Select
If _message IsNot Nothing Then
_message.Header.SetField(New MsgSeqNum(_csession.NextSenderMsgSeqNum))
_message.Header.SetField(New MsgType(0))
_message.Validate()
End If
There is not a way to do this, and that's intentional. There shouldn't be, because the fields that a message contains will usually differ between FIX versions. You just happened to pick Heartbeat, the most basic and unchanging message type across all FIX versions.
But let's look at the News (35=B) message:
* News 4.0 has the Text (58) field, but not Headline (148)
* News 4.4 has Headline, but not Text
Therefore, your suggested solution won't work.
Plus, it's just not really a common use case. In practice, you're writing an engine specific to a single counterparty connection. FIX doesn't really lend itself to one-size-fits-all solutions-- it's a customizable engine, because in practice, FIX is so flexible that you NEED to customize for every counterparty.
P.S. Why are you manually creating Heartbeats? The engine handles that for you.

npgsql executescalar() allways returns nothing

I'm using npgsql as a nuget package in visual studio 2017 with visual basic.
Various commands do work very well but an ExecuteScalar allways returns 'nothing' although it should give a result.
The command looks like this:
Dim ser As Integer
Dim find = New NpgsqlCommand("SELECT serial from dbo.foreigncode WHERE code = '#code';", conn)
Dim fcode = New NpgsqlParameter("code", NpgsqlTypes.NpgsqlDbType.Varchar)
find.Parameters.Add(fcode)
find.Prepare()
fcode.Value = "XYZ"
ser = find.ExecuteScalar() ==> nothing
When the command string is copied as a value during debugging and pasted into the query tool of PGADMIN it delivers the correct result. The row is definitely there.
Different Commands executed with ExecuteNonQuery() work well, including ones performing UPDATE statements on the row in question.
When I look into the properties of the parameter fcode immediately before the ExecuteScalar it shows 'fcode.DataTypeName' caused an exception 'System.NotImplementedException'.
If I change my prepared statement to "SELECT #code" and set the value of the parameter to an arbitrary value just this value is returned. There is no access to the table taking place because the table name is not part of the SELECT in this case. If I remove the WHERE CLAUSE in the SELECT and just select one column, I would also expect that something has to be returned. But again it is nothing.
Yes there is a column named serial. It is of type bigint and can not contain NULL.
A Query shows that there is no single row that contains NULL in any column.
Latest findings:
I queried a different table where the search column and the result column happen to have the same datatype. It works, so syntax, passing of parameter, prepare etc. seems to work in principal.
The System.NotImplementedException in the DataTypeName property of the parameter occurs as well but it works anyway.
I rebuilt the index of the table in question. No change.
Still: when I copy/paste the CommandText and execute it in PGAdmin it shows the correct result.
Modifying the Command and using plain text there without parameter and without prepare still does yield nothing. The plain text CommandText was copy/pasted from PGAdmin where it was successfully executed before.
Very strange.
Reverting search column and result column also gives nothing as a result.
Please try these two alternatives and post back your results:
' Alternative 1: fetch the entire row, see what's returned
Dim dr = find.ExecuteReader()
While (dr.Read())
Console.Write("{0}\t{1} \n", dr[0], dr[1])
End While
' Alternative 2: Check if "ExecuteScalar()" returns something other than an int
Dim result = find.ExecuteScalar()
... and (I just noticed Honeyboy Wilson's response!) ...
Fix your syntax:
' Try this first: remove the single quotes around "#code"!
Dim find = New NpgsqlCommand("SELECT serial from dbo.foreigncode WHERE code = #code;", conn)
Update 1
Please try this:
Dim find = New NpgsqlCommand("SELECT * from dbo.foreigncode;", conn)
Q: Does this return anything?
Dim dr = find.ExecuteReader()
While (dr.Read())
Console.Write("{0}\t{1} \n", dr[0], dr[1])
End While
Q: Does this?
Dim result = find.ExecuteScalar()
Q: Do you happen to have a column named "serial"? What is it's data type? Is it non-null for the row(s) with 'XYZ'?
Please update your original post with this information.
Update 2
You seem to be doing ":everything right":
You've confirmed that you can connect,
You've confirmed that non-query updates to the same table work (with npgsql),
You've confirmed that the SQL queries themselves are valid (by copying/pasting the same SQL into PGAdmin and getting valid results).
As Shay Rojansky said, "System.NotImplementedException in the DataTypeName property" is a known issue stepping through the debugger. It has nothing to do with your problem: https://github.com/npgsql/npgsql/issues/2520
SUGGESTIONS (I'm grasping at straws)::
Double-check "permissions" on your database and your table.
Consider installing a different version of npgsql.
Be sure your code is detecting any/all error returns and exceptions (it sounds like you're probably already doing this, but it never hurts to ask)
... and ...
Enable verbose logging, both client- and server-side:
https://www.npgsql.org/doc/logging.html
https://www.postgresql.org/docs/9.0/runtime-config-logging.html
... Finally ...
Q: Can you make ANY query, from ANY table, using ANY query method (ExecuteReader(), ExecuteScalar(), ... ANYTHING) from your npgsql/.Net client AT ALL?
I finally found it. It's often the small things that can have a big impact.
When the value was assigned to the parameter a substring index was incorect.
Now it works perfectly.
Thanks to everybody who spent his time on this.

Nest ElasticSearch cannot convert Lambda expression

The following VB code is intended to add an alias index to a nest elastic search but the final line receives an error -
"lambda expression cannot be converted to NEST.IAliasRequest because Nest.IAliasRequest is not a delegate type"
Dim client = ConnectToSearch()
Dim Person = New Person With {.Id= Id, .Description = Description, .Tags = Tags}
client.Alias(Sub(a) a.Add(Function(add) add.Index("Person").Alias("Account1")))
client.[Alias](Function(descriptor) descriptor.Add(Function(a) a.Index("Person").[Alias]("Account1")))
UPDATE
Maybe this one will help you create alias with filter.
client.[Alias](Function([alias]) [alias].Add(Function(a) a.Index(indexName).[Alias]("alias").Filter(Of Person)(Function(f) f.Term("relationships.staffID", staffID))))
Hope this helps.

Cannot add new Workitems using TFS API

Hi I am trying to add new workitems to the TFS repository using the API, but when I validate the workitem before it is saved, it returns an error. I previously got exceptions regarding the field definitions for a bug namely, Symptom, Steps to Reproduce and Triage. (Error code TF 26027). The code snippet is shown below: Can anyone tell me what's wrong here?
switch (workItemType)
{
case "Bug":
{
workItem.Title = values["Title"].ToString();
workItem.State = values["State"].ToString();
workItem.Reason = values["Reason"].ToString();
workItem.Fields["Priority"].Value = values["Priority"].ToString();
workItem.Fields["Severity"].Value = values["Severity"].ToString();
//workItem.Fields["Triage"].Value = values["Triage"].ToString();
workItem.Fields["Assigned To"].Value = values["Assigned To"].ToString();
//workItem.Fields["Symptom"].Value = values["Symptom"].ToString();
//workItem.Fields["Steps to Reproduce"].Value = values["Steps to Reproduce"].ToString();
// Validate the Work Item fields.
ArrayList result = workItem.Validate();
// If any invalid fields are returned, report an error.
if (result.Count > 0)
MessageBox.Show("An Error occurred while adding the Bug to the repository.");
else
workItem.Save();
}
break;
To find the available field definitions, you can iterate over the collection (FieldDefinitions). The Name and ReferenceName properties are the values you can index by into the collection.
the Field "Symptom" cannot be empty
Just reading the error message it looks like you are defining a field called "somefield" in your work item. I'm thinking that you have some old code hanging around elsewhere, maybe above the code snippet you posted, where you are defining a value for workItem.Fields["somefield"]
Old question, but hopefully helps someone. The field name is "Repro Steps"
.Fields["Repro Steps"].Value

Adding related records in LINQ

Processing an XML file with LINQ to add records into a table in a SQL Server database via a data context. As we are adding records we need to assign the parents in various other tables. Most of the time we can find the existing parent and use it but sometimes we will need to create a new parent.
Thought we could do this like this:
Dim defaultPub As publication
defaultPub = New publication With {.name = e..Value}
Dim pub = _Data.publications.Where(Function(s) s.name = e..Value).DefaultIfEmpty(defaultPub).SingleOrDefault
.publication = pub
So we are trying to find a publication that matches e..Value from our XML, but if we can't find one then we use 'defaultPub'. If it does exist though we don't want to add it again. So maybe this approach is flawed anyway even if it did work...
Anyway it's not currently working, we get this error:
Unsupported overload used for query operator 'DefaultIfEmpty'.
The overload requires a publication and is getting one (I've checked the TypeNames in quickwatch), don't know what is going on here.
What we are really looking for is something like the find_or_create from activerecord for Ruby that LINQ seems to be a copied from.
Thanks in advance,
Dave.
OK, I can just do it like this:
Dim pub = _Data.publications.Where(Function(s) s.name = e.<source>.Value).SingleOrDefault
Dim newPub As publication
If Not IsNothing(pub) AndAlso pub.name <> "" Then
.publication = pub
Else
newPub = New publication With {.name = e.<source>.Value}
.publication = newPub
End If
Thanks Val!