1- using System . Collections . Generic ;
1+ using System ;
2+ using System . Collections . Generic ;
23using System . Threading . Tasks ;
34using Dev . Dres . ClientApi . Api ;
45using Dev . Dres . ClientApi . Client ;
@@ -14,39 +15,92 @@ namespace Dres.Unityclient
1415 /// </summary>
1516 internal static class DresWrapper
1617 {
17-
18+ internal static readonly EvaluationClientApi EvaluationClientApi = new ( DresConfigManager . Instance . ApiConfiguration ) ;
19+
1820 /// <summary>
1921 /// The deliberately single Logging Api instance of DRES. Used to send logs to DRES
2022 /// </summary>
21- internal static readonly LogApi LogApi = new LogApi ( DresConfigManager . Instance . ApiConfiguration ) ;
23+ internal static readonly LogApi LogApi = new ( DresConfigManager . Instance . ApiConfiguration ) ;
24+
2225 /// <summary>
2326 /// The deliberately single Status Api instance of DRES. Used to get the status of DRES
2427 /// </summary>
25- internal static readonly StatusApi StatusApi = new StatusApi ( DresConfigManager . Instance . ApiConfiguration ) ;
28+ internal static readonly StatusApi StatusApi = new ( DresConfigManager . Instance . ApiConfiguration ) ;
29+
2630 /// <summary>
2731 /// The deliberately single Submission Api instance of DRES. Used to submit media items during competitions to DRES:
2832 /// </summary>
29- internal static readonly SubmissionApi SubmissionApi = new SubmissionApi ( DresConfigManager . Instance . ApiConfiguration ) ;
33+ internal static readonly SubmissionApi SubmissionApi = new ( DresConfigManager . Instance . ApiConfiguration ) ;
34+
3035 /// <summary>
3136 /// The deliberately single User Api instance of DRES. Used to log into DRES and retrieve the session id of the user.
3237 /// </summary>
33- internal static readonly UserApi UserApi = new UserApi ( DresConfigManager . Instance . ApiConfiguration ) ;
38+ internal static readonly UserApi UserApi = new ( DresConfigManager . Instance . ApiConfiguration ) ;
3439
3540 /// <summary>
3641 /// Login to DRES with given username and password.
37- /// The login state (i.e. the <see cref="Dev.Dres.ClientApi.Model.UserDetails "/>) are not kept
42+ /// The login state (i.e. the <see cref="Dev.Dres.ClientApi.Model.ApiUser "/>) are not kept
3843 /// and have to be managed by the caller.
3944 /// </summary>
4045 /// <param name="user">The DRES username</param>
4146 /// <param name="password">The DRES password</param>
4247 /// <returns>The login state on success.</returns>
4348 /// <exception cref="ApiException">If the config has no credentials set and no credentials file exists</exception>
44- internal static async Task < UserDetails > Login ( string user , string password )
49+ internal static Task < ApiUser > Login ( string user , string password )
4550 {
4651 var loginRequest = new LoginRequest ( user , password ) ;
47- return await UserApi . PostApiV1LoginAsync ( loginRequest ) ;
52+ return UserApi . PostApiV2LoginAsync ( loginRequest ) ;
53+ }
54+
55+ internal static Task < List < ApiClientEvaluationInfo > > ListClientEvaluations ( string session )
56+ {
57+ return EvaluationClientApi . GetApiV2ClientEvaluationListAsync ( session ) ;
58+ }
59+
60+ internal static Task < ApiTaskTemplateInfo > GetTaskInfo ( string evaluationId , string session )
61+ {
62+ return EvaluationClientApi . GetApiV2ClientEvaluationCurrentTaskByEvaluationIdAsync ( evaluationId , session ) ;
4863 }
4964
65+ /// <summary>
66+ /// Submits an item to the DRES endpoint using the DRES API v2.
67+ /// </summary>
68+ /// <param name="session">The session ID to which this submission belongs</param>
69+ /// <param name="evaluationId">The evaluation ID to which this submission belongs</param>
70+ /// <param name="item">The name of the item (or identifier) to submit</param>
71+ /// <param name="start">The optional start (in milliseconds) of the submitted item</param>
72+ /// <param name="end">The optional end (in milliseconds) of the submitted item</param>
73+ /// <returns>The submission state on success / failure.</returns>
74+ internal static Task < SuccessfulSubmissionsStatus > SubmitV2 ( string session , string evaluationId , string item , long ? start = null ,
75+ long ? end = null )
76+ {
77+ var answerSets = new List < ApiClientAnswerSet >
78+ {
79+ new ( answers : new List < ApiClientAnswer >
80+ {
81+ new ( mediaItemName : item , start : start . GetValueOrDefault ( ) , end : end . GetValueOrDefault ( ) )
82+ } )
83+ } ;
84+ var apiClientSubmission = new ApiClientSubmission ( answerSets ) ;
85+ return SubmissionApi . PostApiV2SubmitByEvaluationIdAsync ( evaluationId , apiClientSubmission , session ) ;
86+ }
87+
88+ /// <summary>
89+ /// Submits text to the DRES endpoint using the DRES API v2.
90+ /// </summary>
91+ /// <param name="session">The session ID to which this submission belongs</param>
92+ /// <param name="evaluationId">The evaluation ID to which this submission belongs</param>
93+ /// <param name="text">The text to submit</param>
94+ /// <returns>The submission state on success / failure.</returns>
95+ internal static Task < SuccessfulSubmissionsStatus > SubmitTextV2 ( string session , string evaluationId , string text )
96+ {
97+ var answerSets = new List < ApiClientAnswerSet > { new ( answers : new List < ApiClientAnswer > { new ( text : text ) } ) } ;
98+ var apiClientSubmission = new ApiClientSubmission ( answerSets ) ;
99+ return SubmissionApi . PostApiV2SubmitByEvaluationIdAsync ( evaluationId , apiClientSubmission , session ) ;
100+ }
101+
102+ // TODO: Once the functionality of the new API is confirmed, implement bulk submission
103+
50104 /// <summary>
51105 /// Submits an item to the DRES endpoint.
52106 /// Submissions are only allowed during active competitions (inferred from the given sesssion id)
@@ -57,11 +111,12 @@ internal static async Task<UserDetails> Login(string user, string password)
57111 /// If no notion of frames exist for the item, this can likely be omitted.</param>
58112 /// <returns>The submission state on success / failure.</returns>
59113 /// <exception cref="ApiException">A 404 if there is no ongoing competition for this session, a 403 if there is no such user</exception>
60- internal static async Task < SuccessfulSubmissionsStatus > Submit ( string item , string session , int ? frame = null )
114+ [ Obsolete ( "Obsolete" ) ]
115+ internal static Task < SuccessfulSubmissionsStatus > Submit ( string item , string session , int ? frame = null )
61116 {
62- return await SubmissionApi . GetApiV1SubmitAsync ( item : item , frame : frame , session : session ) ;
117+ return SubmissionApi . GetApiV1SubmitAsync ( item : item , frame : frame , session : session ) ;
63118 }
64-
119+
65120 /// <summary>
66121 /// Submits given TEXT to the DRES endpoint.
67122 /// Submissions are only allowed during active competitions (inferred from the given sesssion id)
@@ -70,9 +125,10 @@ internal static async Task<SuccessfulSubmissionsStatus> Submit(string item, stri
70125 /// <param name="session">The session id to which this submission belongs</param>
71126 /// <returns>The submission state on success / failure.</returns>
72127 /// <exception cref="ApiException">A 404 if there is no ongoing competition for this session, a 403 if there is no such user</exception>
73- internal static async Task < SuccessfulSubmissionsStatus > SubmitText ( string text , string session )
128+ [ Obsolete ( "Obsolete" ) ]
129+ internal static Task < SuccessfulSubmissionsStatus > SubmitText ( string text , string session )
74130 {
75- return await SubmissionApi . GetApiV1SubmitAsync ( text : text , session : session ) ;
131+ return SubmissionApi . GetApiV1SubmitAsync ( text : text , session : session ) ;
76132 }
77133
78134
@@ -89,11 +145,11 @@ internal static async Task<SuccessfulSubmissionsStatus> SubmitText(string text,
89145 /// <param name="session">The session id to which this log belongs</param>
90146 /// <returns>The state of success / failure of the log sending.</returns>
91147 /// <exception cref="ApiException">A 404 if there is no ongoing competition for this session, a 403 if there is no such user</exception>
92- internal static async Task < SuccessStatus > LogResults ( long timestamp , string sortType , string resultSetAvailability ,
148+ internal static Task < SuccessStatus > LogResults ( long timestamp , string sortType , string resultSetAvailability ,
93149 List < QueryResult > results , List < QueryEvent > events , string session )
94150 {
95151 var resultLog = new QueryResultLog ( timestamp , sortType , resultSetAvailability , results , events ) ;
96- return await LogApi . PostApiV1LogResultAsync ( session , resultLog ) ;
152+ return LogApi . PostApiV2LogResultAsync ( session , resultLog ) ;
97153 }
98154
99155 /// <summary>
@@ -106,10 +162,10 @@ internal static async Task<SuccessStatus> LogResults(long timestamp, string sort
106162 /// <param name="session">The session id to which this log belongs</param>
107163 /// <returns>The state of success / failure of the log sending.</returns>
108164 /// <exception cref="ApiException">A 404 if there is no ongoing competition for this session, a 403 if there is no such user</exception>
109- internal static async Task < SuccessStatus > LogQueryEvents ( long timestamp , List < QueryEvent > events , string session )
165+ internal static Task < SuccessStatus > LogQueryEvents ( long timestamp , List < QueryEvent > events , string session )
110166 {
111167 var queryEventLog = new QueryEventLog ( timestamp , events ) ;
112- return await LogApi . PostApiV1LogQueryAsync ( session , queryEventLog ) ;
168+ return LogApi . PostApiV2LogQueryAsync ( session , queryEventLog ) ;
113169 }
114170 }
115171}
0 commit comments