Documentation for the Unity C# Library
Loading...
Searching...
No Matches
ApexTypes.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Runtime.CompilerServices;
4using Newtonsoft.Json;
5using Newtonsoft.Json.Linq;
6using Unity.Properties;
7using UnityEngine;
8using UnityEngine.UIElements;
9
10namespace PixoVR.Apex
11{
12 public interface IPlatformErrorable
13 {
14 public abstract bool HasErrored();
15 }
16
17 public interface IFailure
18 {
19 // Empty so we can check all failure types against this
20 }
21
22 [Serializable]
24 {
25 public string Error;
26 public string HttpCode;
27 public string Message;
28
29 public bool HasErrored()
30 {
31 bool hasErrored = false;
32 bool hasErrorSetup = !(Error == null && Message == null && HttpCode == null);
34 if (hasErrorSetup == false)
35 {
36 if (Error != null)
37 {
38 if (Error.Equals("true", StringComparison.CurrentCultureIgnoreCase))
39 {
40 hasErrored = true;
41 }
42 else
43 {
44 hasErrored = !string.IsNullOrEmpty(Error);
45 }
46 }
47 }
48
49 return hasErrored;
50 }
51 }
52
53 [Serializable]
54 public class JoinSessionResponse : FailureResponse
55 {
56 public JObject Data;
57 public int SessionId;
58
59 public void ParseData()
60 {
61 IEnumerable<JProperty> dataPropertyEnumerator = Data.Properties();
62 foreach (JProperty property in dataPropertyEnumerator)
63 {
64 if (property.Name.Equals("SessionId", StringComparison.OrdinalIgnoreCase))
65 {
66 SessionId = JsonConvert.DeserializeObject<int>(property.Value.ToString());
67 }
68 }
69 }
70 }
72 [Serializable]
74 {
75 public string Error;
76 public string HttpCode;
77 public string Message;
78 public JObject Data;
79 public List<UserModulesData> ParsedData;
80
81 public bool HasErrored()
82 {
83 return (Error.Equals("true", StringComparison.CurrentCultureIgnoreCase));
84 }
85
86 public void ParseData()
87 {
88 ParsedData = new List<UserModulesData>();
89 IEnumerable<JProperty> dataPropertyEnumerator = Data.Properties();
90 UserModulesData currentUser;
91 foreach (JProperty currentProperty in dataPropertyEnumerator)
92 {
93 currentUser = new UserModulesData();
95 currentUser.UserId = currentProperty.Name;
96 currentUser.AvailableModules = JsonConvert.DeserializeObject<List<int>>(
97 currentProperty.Value.ToString()
98 );
100 ParsedData.Add(currentUser);
101 }
102 }
103 }
105 [Serializable]
106 public class UserModulesData
107 {
108 public string UserId;
109 public List<int> AvailableModules;
110
111 public UserModulesData()
112 {
113 AvailableModules = new List<int>();
114 }
115 }
116
117 [Serializable]
118 public class UserModulesRequestData
119 {
120 [JsonProperty(PropertyName = "userIds")]
121 public List<int> UserIds = new List<int>();
122 }
123
124 [Serializable]
125 public class LoginData
126 {
127 public string Login;
128 public string Password;
129
130 public LoginData(string username, string password)
131 {
132 Login = username;
133 Password = password;
134 }
136
137 [Serializable]
139 {
140 public int ID;
141 public int OrgId;
142 public string First;
143 public string Last;
144 public string Email;
145 public string Token;
146 public string Role;
147 public Organization Org;
149
150 public bool HasErrored()
152 return (Email == null || Token == null);
153 }
154
155 public bool IsPlatformSuperadmin()
156 {
157 var isSuperAdmin = !String.IsNullOrEmpty(Role) && Role.Equals("superadmin", StringComparison.CurrentCultureIgnoreCase);
158 var isPlatformOrg = Org != null && !String.IsNullOrEmpty(Org.Type) && Org.Type.Equals("platform", StringComparison.CurrentCultureIgnoreCase);
159 return isPlatformOrg && isSuperAdmin;
160 }
162
163 [Serializable]
165 {
167
168 public bool HasErrored()
169 {
170 return User == null;
171 }
172 }
173
174 [Serializable]
175 public class UserAccessResponseContent : IPlatformErrorable
176 {
177 public int UserId = -1;
178 public int ModuleId = -1;
179 public bool Access;
180 public int? PassingScore;
181
182 public bool HasErrored()
184 return (UserId == -1 || ModuleId == -1);
188 [Serializable]
189 public class Organization
191 public int ID;
192 public string Name;
193 public string Status;
194 public string DownloadRegion;
195 public string Type;
196 public string HubLogoLink;
197 public string PrimaryColor;
198 public string SecondaryColor;
199 }
200
201 [Serializable]
203 {
204 public int ID;
205 public string First;
206 public string Last;
207 public string Email;
208 public string Username;
209
210 public bool HasErrored()
211 {
212 return (Email == null);
213 }
215
216 [Serializable]
218 {
220
221 public bool HasErrored()
222 {
223 return (AssistedLogin == null);
224 }
225 }
226
227 public class AssistedLoginCode
228 {
229 public string AuthCode;
230 public string Expires;
233 [Serializable]
234 public class SessionData
235 {
236 public float Score;
237 public float ScaledScore;
238 public float MinimumScore;
239 public float MaximumScore;
240 public int Duration;
241 public bool Complete;
242 public bool Success;
243
244 public SessionData() { }
245
246 public SessionData(float score, float scaled, float min, float max, int duration, bool completed, bool success)
247 {
248 Score = score;
249 ScaledScore = scaled;
250 MinimumScore = min;
252 Duration = duration;
253 Complete = completed;
254 Success = success;
258#if UNITY_6000_0_OR_NEWER
259 public class OrgModule : ScriptableObject, INotifyBindablePropertyChanged
260#else
261 public class OrgModule : ScriptableObject
262#endif
263 {
264 public int ID = -1;
265 public string Name = "";
266 public string Description = "";
267 public string ShortDescription = "";
268 public string LongDescription = "";
269 public string Industry = "";
270 public string Details = "";
271 public string IconURL = "";
272 public string AvailableLanguages = "";
273 public string Distributor = "";
274 public string UserGuideLink = "";
275 public bool IsAuthenticatedLaunch = false;
276 public bool EnableDebug = false;
277
278 private Texture2D _thumbnail;
279
280 [CreateProperty]
281 public Texture2D Thumbnail
282 {
283 get { return _thumbnail; }
284 set
285 {
286 _thumbnail = value;
287#if UNITY_6000_0_OR_NEWER
288 Notify();
289#endif
290 }
292
293 public List<OrgModuleDownload> Downloads = new List<OrgModuleDownload>();
294 public int? PassingScore = null;
295 public string Categories = "";
296 public string externalId = "";
297 public PlatformPlayer player = null;
298
299#if UNITY_6000_0_OR_NEWER
300 public event EventHandler<BindablePropertyChangedEventArgs> propertyChanged;
301#endif
303 public OrgModule()
304 {
305 Downloads = new List<OrgModuleDownload>();
306 }
307
308 public OrgModule(JToken token)
309 {
310 Downloads = new List<OrgModuleDownload>();
311 Parse(token);
313
314 public void Parse(JToken token)
316 ID = token.Value<int>("ID");
317 Name = token.Value<string>("Name");
318 Description = token.Value<string>("Description");
319 ShortDescription = token.Value<string>("ShortDescription");
320 LongDescription = token.Value<string>("LongDescription");
321 Details = token.Value<string>("Details");
322 IconURL = token.Value<string>("IconURL");
323 PassingScore = token.Value<int?>("PassingScore");
324 Categories = token.Value<string>("Categories");
325 externalId = token.Value<string>("externalId");
326 UserGuideLink = token.Value<string>("UserGuideLink");
327
328 var PlayerToken = token.Value<JObject>("player");
329
330 if (PlayerToken != null)
331 {
332 player = new PlatformPlayer(PlayerToken);
333 }
334
335 var DownloadTokens = token.Value<JArray>("Downloads");
336
337 if (DownloadTokens != null)
338 {
339 foreach (JToken DownloadToken in DownloadTokens)
340 {
341 var downloadData = ScriptableObject.CreateInstance<OrgModuleDownload>();
342 downloadData.Parse(DownloadToken);
343 Downloads.Add(downloadData);
347 var availableLanguages = GetValue<JArray>(token, "availableLanguages");
349 if (availableLanguages != null)
351 var availableLanguagesList = new List<string>();
353 foreach (JToken languageToken in availableLanguages)
355 string displayName = GetValue<string>(languageToken, "displayName");
356 if (!string.IsNullOrEmpty(displayName))
357 {
358 availableLanguagesList.Add(displayName);
360 }
361
362 AvailableLanguages = string.Join(", ", availableLanguagesList);
363 }
364
365 var industry = GetValue<string>(token, "Industry");
366 if (!string.IsNullOrEmpty(industry) && industry.Length > 0)
367 {
368 Industry = char.ToUpper(industry[0]) + (industry.Length > 1 ? industry[1..] : string.Empty);
369 }
370
371 var distributor = GetValue<JToken>(token, "distributor");
372 if (distributor != null)
374 Distributor = GetValue<string>(distributor, "name");
376
377 EnableDebug = token.Value<bool>("enableDebug");
378 IsAuthenticatedLaunch = token.Value<bool>("isAuthenticatedLaunch");
379 }
380
381 private T GetValue<T>(JToken token, string propertyName, T defaultValue = default)
382 {
383 return token[propertyName] != null ? token.Value<T>(propertyName) : defaultValue;
384 }
385
386#if UNITY_6000_0_OR_NEWER
387 void Notify([CallerMemberName] string property = "")
388 {
389 propertyChanged?.Invoke(this, new BindablePropertyChangedEventArgs(property));
390 }
391#endif
393
394 [Serializable]
396 {
397 public int ID;
398 public int VersionID;
399 public string FileLocation;
400 public string Version;
401 public string Platform;
402 public long DownloadSize;
403 public string ApkName;
404 public string URL;
405 public string Status;
406 public string externalId;
407
408 public OrgModuleDownload(JToken token)
409 {
410 Parse(token);
411 }
412
413 public void Parse(JToken token)
414 {
415 ID = token.Value<int>("ID");
416 VersionID = token.Value<int>("VersionID");
417 DownloadSize = token.Value<long>("DownloadSize");
418 externalId = token.Value<string>("externalId");
419 FileLocation = token.Value<string>("FileLocation");
420 Version = token.Value<string>("Version");
421 Platform = token.Value<string>("Platform");
422 ApkName = token.Value<string>("ApkName");
423 URL = token.Value<string>("URL");
424 Status = token.Value<string>("Status");
425 }
426 }
427
428 [Serializable]
429 public class PlatformPlayer
430 {
431 public int id;
432 public string name;
433 public string description;
434 public int distributorId;
435 public string launchProtocol;
436 public List<PlatformPlayerDownload> versions = new List<PlatformPlayerDownload>();
437
438 public PlatformPlayer(JObject tokenObject)
439 {
440 id = tokenObject.Value<int>("id");
441 distributorId = tokenObject.Value<int>("distributorId");
442 name = tokenObject.Value<string>("name");
443 description = tokenObject.Value<string>("description");
444 launchProtocol = tokenObject.Value<string>("launchProtocol");
445
446 var versionTokens = tokenObject.Value<JArray>("versions");
447 if (versionTokens == null)
448 {
449 versionTokens = new JArray();
450 }
451
452 foreach (JToken Version in versionTokens)
453 {
454 versions.Add(new PlatformPlayerDownload(Version));
455 }
456 }
457 }
458
459 [Serializable]
460 public class PlatformPlayerDownload
461 {
462 public int id;
463 public string version;
464 public int modulePlayerId;
465 public string status;
466 public string URL;
467 public string ApkName;
468 public string platform;
469
470 public PlatformPlayerDownload(JToken token)
471 {
472 id = token.Value<int>("id");
473 modulePlayerId = token.Value<int>("modulePlayerId");
474 version = token.Value<string>("version");
475 status = token.Value<string>("status");
476 URL = token.Value<string>("URL");
477 ApkName = token.Value<string>("ApkName");
478 platform = token.Value<string>("platform");
480 }
List< UserModulesData > ParsedData
Definition ApexTypes.cs:97
[Serializable]
Definition ApexTypes.cs:162
LoginData(string username, string password)
Definition ApexTypes.cs:166
void Parse(JToken token)
Definition ApexTypes.cs:497
OrgModuleDownload(JToken token)
Definition ApexTypes.cs:492
void Parse(JToken token)
Definition ApexTypes.cs:392
PlatformPlayer player
Definition ApexTypes.cs:375
List< OrgModuleDownload > Downloads
Definition ApexTypes.cs:371
OrgModule(JToken token)
Definition ApexTypes.cs:386
T GetValue< T >(JToken token, string propertyName, T defaultValue=default)
Definition ApexTypes.cs:459
List< PlatformPlayerDownload > versions
Definition ApexTypes.cs:526
PlatformPlayer(JObject tokenObject)
Definition ApexTypes.cs:528
SessionData(float score, float scaled, float min, float max, int duration, bool completed, bool success)
Definition ApexTypes.cs:324