Skip to content

Instantly share code, notes, and snippets.

@GeorgeTsiokos
Created February 21, 2019 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GeorgeTsiokos/aedb8cc94bdcfd43fabb5fe023f68b3e to your computer and use it in GitHub Desktop.
Save GeorgeTsiokos/aedb8cc94bdcfd43fabb5fe023f68b3e to your computer and use it in GitHub Desktop.
Fidessa QUERY_MORE
/// <summary>
/// Automatically requests more rows from a QUERY_IMAGE
/// </summary>
/// <param name="session">Fidessa session</param>
/// <param name="queryName">Query name</param>
/// <param name="userName">User name</param>
/// <param name="count">
/// <para>when specified, continue to request rows while the # of rows returns are less than count</para>
/// <para>when null, QUERY_MORE will be sent when MORE = 1</para>
/// </param>
public static void AutoQueryMore(this Session session, string queryName, string userName, long? count)
{
long responseCount = 0;
void OnReceivedData(object sender, SessionDataEventArgs e)
{
var data = e?.Data;
if (null == data || !data.ContainsKey("MESSAGE_TYPE") || data.String("MESSAGE_TYPE") != "QUERY_IMAGE")
return;
if (data.ContainsKey("ROW"))
responseCount += data.SdsList("ROW").Count;
if (!data.ContainsKey("MORE"))
return;
var more = data.I32("MORE") ?? -1;
switch (more)
{
case 0:
// IMAGE has completed - unsubscribe
session.ReceivedData -= OnReceivedData;
break;
case 1:
if (count.HasValue && responseCount >= count.Value)
break;
// ask for more
session.Send(
new Sds
{
{"MESSAGE_TYPE", "QUERY_MORE"},
{"QUERY_NAME", queryName},
{"USER_NAME", userName}
});
break;
}
}
session.ReceivedData += OnReceivedData;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment