Dynamically choose version from multiple namespaces - vb.net

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.

Related

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.

Exception while accessing Repository.GetElementSet in Enterprise Architect

I tried to automate the traceability between the elements in Enterprise Architect using VBA scripting. If the traceability already existed between the elements I need to skip those elements.
I wrote using one simple query where the Object ids are present in the EAP.
set useCaseCollection = Repository.GetElementSet("select Start_Object_ID from t_connector where (Start_Object_ID = -1222814411 and End_Object_ID = 505879126 and Connector_Type = 'Realisation')",2)
If Err.Number <> 0 Then
Session.Output( useCaseCollection.Count)
End if
On Error Goto 0
Now the problem is I am getting one exception as Item not found in the collection if the traceability exists between the elements. If traceability is not there then it's printing the value as zero. Anything is wrong in the above approach or any other solution is there for this problem?
I guess the answer is simple. GetElementSet only works on t_object (Elements) not on t_connector. Use SQLQuery instead. Or use a JOIN to actually return the connected element, rather than the object ID.
Something along those lines:
dim useCaseCollection as EA.Collection
set useCaseCollection = Repository.GetElementSet("select * from t_object WHERE object_ID in (SELECT start_object_id FROM t_connector)",2)
Session.Output( useCaseCollection.Count)
I think it might be enough to change the alias of the field Start_Object_ID in your query to read Object_ID
set useCaseCollection = Repository.GetElementSet("select Start_Object_ID as Object_ID from t_connector where (Start_Object_ID = -1222814411 and End_Object_ID = 505879126 and Connector_Type = 'Realisation')",2)
Assuming of course the rest of the query is OK; I've never seen negative object ID's.

The ""sort"" value has to be formed as this example: ""field_ASC""

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.

Nhibernate.Search, Lucene, and the Criteria API: types mismatch

Update
I've been looking around the NHibernate.Search.Tests project to find out how the Criteria API is used (i find it immensely useful to look around the test code to have working examples) and i noticed that the way to use the Fulltext search is radically different. Here are two tests, one with the criteria API, one with the classic query schema:
[Test]
public void ResultSize()
{
IFullTextSession s = Search.CreateFullTextSession(OpenSession());
ITransaction tx = s.BeginTransaction();
// snipped the objects creation
QueryParser parser = new QueryParser("title", new StopAnalyzer());
Lucene.Net.Search.Query query = parser.Parse("Summary:noword");
IFullTextQuery hibQuery = s.CreateFullTextQuery(query, typeof(Clock), typeof(Book));
Assert.AreEqual(0, hibQuery.ResultSize);
// snipped the end of the test
}
[Test]
public void UsingCriteriaApi()
{
IFullTextSession s = Search.CreateFullTextSession(OpenSession());
ITransaction tx = s.BeginTransaction();
// snipped creation
IList list = s.CreateCriteria(typeof(Clock))
.Add(SearchRestrictions.Query("Brand:seiko"))
.List();
Assert.AreEqual(1, list.Count, "should get result back from query");
// snipped deletion
}
The second solution works under vb.net, at the cost of the useful Lucene query (which embarks it's own total of the corresponding rows) and at the cost of the Lucene ordering (or i couldn't find it)
Hello everyone,
yet again, i'm stumped on the path, but this time, i suspect something a bit more sinister than my usual erratic errors (cue ominous music)
I'm trying to combine FullText search using Lucene.net with paging and the Criteria API.
So far paging and the Fulltext search have been working flawlessly. Recently though, we had to use the criteria API to add specific filters to the query. So what i did was the following:
Create the Nhibernate.Search query object using the following
Private Function GetQuery(ByVal QueryString As String, ByVal Orders() As String) As IFullTextQuery
Dim ifts As IFullTextSession = Search.CreateFullTextSession(UnitOfWork.CurrentSession)
Dim analyzer As New SimpleAnalyzer
Dim parser As New MultiFieldQueryParser(SearchPropertyNames, analyzer)
Dim queryObj As Lucene.Net.Search.Query = parser.Parse(QueryString)
Dim nhsQuery As IFullTextQuery = ifts.CreateFullTextQuery(queryObj, New System.Type() {GetType(T)})
For i As Integer = 0 To Orders.Count - 1
Orders(i) = Orders(i) & "FS"
Next
nhsQuery.SetSort(New Sort(Orders))
then add my Criteria to the query:
Dim crit As ICriteria = ifts.CreateCriteria(GetType(T))
Dim criterion As ICriterion
If criteria IsNot Nothing Then
For Each criterion In criteria
If (Not criterion Is Nothing) Then
crit.Add(criterion)
End If
Next
End If
nhsQuery.SetCriteriaQuery(crit)
but when i list the resulting query, i receive the following exception
Criteria query entity should match query entity
A quick glance in the FullTextQueryImpl source file (method GetLoader) shows that there is a comparison between the type name given to the NHibernate.Search query object and the EntityOrClassName property for the Criteria object. That's where my problems appear because the FullTextQueryImpl uses the Name, and the Criteria uses the Fullname. Here's a constructor code for the CriteriaImpl class
Public Sub New(ByVal persistentClass As Type, ByVal session As ISessionImplementor)
Me.New(persistentClass.FullName, CriteriaSpecification.RootAlias, session)
Me.persistentClass = persistentClass
End Sub
and here's the comparison:
Dim entityOrClassName As String = DirectCast(Me.criteria, CriteriaImpl).EntityOrClassName
If ((Me.classes.GetLength(0) = 1) AndAlso (Me.classes(0).Name <> entityOrClassName)) Then
Throw New SearchException("Criteria query entity should match query entity")
End If
As a result, the comparison fails and the exception is thrown. I tried playing around with the aliases to no avail since the comparison is not using the aliases.
Am i missing something huge in my mix of the Fulltext search and the Criteria API, or is it something else? Does it work as expected in C#, because i'm having a weird feeling that it could be vb.net related?
Thank you for reading,
Samy
Looks like this has been resolved with revision 1611 of NHibernate.Search :
Revision: 1611
Message: Fixed a bug where a full class name was being compared against a partial one. This was causing LuceneQueryTest.UsingCriteriaApi to fail.
Modified : /trunk/src/NHibernate.Search/src/NHibernate.Search/Query/FullTextQueryImpl.cs
svn : https://nhcontrib.svn.sourceforge.net/svnroot/nhcontrib/trunk/src/NHibernate.Search/

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!