Added Query.OnResult callback

This commit is contained in:
Garry Newman 2016-12-01 11:07:47 +00:00
parent 9f3ecfd66e
commit 15bfd887bd
2 changed files with 47 additions and 2 deletions

View File

@ -243,6 +243,41 @@ public void QueryFile()
}
}
[TestMethod]
public void QueryCallback()
{
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
{
Assert.IsTrue( client.IsValid );
using ( var Query = client.Workshop.CreateQuery() )
{
var gotCallback = false;
Query.OnResult = ( q ) =>
{
Assert.AreEqual( q.Items.Length, 1 );
Console.WriteLine( "Query.TotalResults: {0}", q.TotalResults );
Console.WriteLine( "Query.Items.Length: {0}", q.Items.Length );
gotCallback = true;
};
Query.FileId.Add( 751993251 );
Query.Run();
Assert.IsTrue( Query.IsRunning );
client.UpdateWhile( () => gotCallback == false );
Assert.IsFalse( Query.IsRunning );
Assert.AreEqual( Query.TotalResults, 1 );
Assert.AreEqual<ulong>( Query.Items[0].Id, 751993251 );
}
}
}
[TestMethod]
public void QueryFiles()
{

View File

@ -37,6 +37,11 @@ public class Query : IDisposable
public UserQueryType UserQueryType { get; set; } = UserQueryType.Published;
/// <summary>
/// Called when the query finishes
/// </summary>
public Action<Query> OnResult;
/// <summary>
/// Page starts at 1 !!
/// </summary>
@ -106,10 +111,10 @@ unsafe void RunInternal()
foreach ( var tag in ExcludeTags )
workshop.ugc.AddExcludedTag( Handle, tag );
Callback = workshop.ugc.SendQueryUGCRequest( Handle, OnResult );
Callback = workshop.ugc.SendQueryUGCRequest( Handle, ResultCallback );
}
void OnResult( SteamNative.SteamUGCQueryCompleted_t data, bool bFailed )
void ResultCallback( SteamNative.SteamUGCQueryCompleted_t data, bool bFailed )
{
if ( bFailed )
throw new System.Exception( "bFailed!" );
@ -166,6 +171,11 @@ void OnResult( SteamNative.SteamUGCQueryCompleted_t data, bool bFailed )
else
{
Items = _results.ToArray();
if ( OnResult != null )
{
OnResult( this );
}
}
}