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
10
11namespace PixoVR.Apex
12{
13 public interface IPlatformErrorable
14 {
15 public abstract bool HasErrored();
16 }
17
18 public interface IFailure
19 {
20 // Empty so we can check all failure types against this
21 }
22
23 [Serializable]
25 {
26 public string Error;
27 public string HttpCode;
28 public string Message;
29
30 public bool HasErrored()
31 {
32 bool hasErrored = false;
33 bool hasErrorSetup = !(Error == null && Message == null && HttpCode == null);
35 if (hasErrorSetup == false)
36 {
37 if (Error != null)
38 {
39 if (Error.Equals("true", StringComparison.CurrentCultureIgnoreCase))
40 {
41 hasErrored = true;
42 }
43 else
44 {
45 hasErrored = !string.IsNullOrEmpty(Error);
46 }
47 }
48 }
49
50 return hasErrored;
51 }
52 }
53
54 [Serializable]
55 public class JoinSessionResponse : FailureResponse
56 {
57 public JObject Data;
58 public int SessionId;
59
60 public void ParseData()
61 {
62 IEnumerable<JProperty> dataPropertyEnumerator = Data.Properties();
63 foreach (JProperty property in dataPropertyEnumerator)
64 {
65 if (property.Name.Equals("SessionId", StringComparison.OrdinalIgnoreCase))
66 {
67 SessionId = JsonConvert.DeserializeObject<int>(property.Value.ToString());
68 }
69 }
70 }
71 }
73 [Serializable]
75 {
76 public string Error;
77 public string HttpCode;
78 public string Message;
79 public JObject Data;
80 public List<UserModulesData> ParsedData;
81
82 public bool HasErrored()
83 {
84 return (Error.Equals("true", StringComparison.CurrentCultureIgnoreCase));
85 }
86
87 public void ParseData()
88 {
89 ParsedData = new List<UserModulesData>();
90 IEnumerable<JProperty> dataPropertyEnumerator = Data.Properties();
91 UserModulesData currentUser;
92 foreach (JProperty currentProperty in dataPropertyEnumerator)
93 {
94 currentUser = new UserModulesData();
96 currentUser.UserId = currentProperty.Name;
97 currentUser.AvailableModules = JsonConvert.DeserializeObject<List<int>>(
98 currentProperty.Value.ToString()
99 );
101 ParsedData.Add(currentUser);
102 }
103 }
104 }
106 [Serializable]
107 public class UserModulesData
108 {
109 public string UserId;
110 public List<int> AvailableModules;
111
112 public UserModulesData()
113 {
114 AvailableModules = new List<int>();
115 }
116 }
117
118 [Serializable]
119 public class UserModulesRequestData
120 {
121 [JsonProperty(PropertyName = "userIds")]
122 public List<int> UserIds = new List<int>();
123 }
124
125 [Serializable]
126 public class LoginData
127 {
128 public string Login;
129 public string Password;
130
131 public LoginData(string username, string password)
132 {
133 Login = username;
134 Password = password;
135 }
137
138 [Serializable]
140 {
141 public int ID;
142 public int OrgId;
143 public string First;
144 public string Last;
145 public string Email;
146 public string Token;
147 public string Role;
148 public Organization Org;
150
151 public bool HasErrored()
153 return (Email == null || Token == null);
154 }
155
156 public bool IsPlatformSuperadmin()
157 {
158 var isSuperAdmin = !String.IsNullOrEmpty(Role) && Role.Equals("superadmin", StringComparison.CurrentCultureIgnoreCase);
159 var isPlatformOrg = Org != null && !String.IsNullOrEmpty(Org.Type) && Org.Type.Equals("platform", StringComparison.CurrentCultureIgnoreCase);
160 return isPlatformOrg && isSuperAdmin;
161 }
163
164 [Serializable]
166 {
168
169 public bool HasErrored()
170 {
171 return User == null;
172 }
173 }
174
175 [Serializable]
176 public class UserAccessResponseContent : IPlatformErrorable
177 {
178 public int UserId = -1;
179 public int ModuleId = -1;
180 public bool Access;
181 public int? PassingScore;
182
183 public bool HasErrored()
185 return (UserId == -1 || ModuleId == -1);
189 [Serializable]
190 public class Organization
192 public int ID;
193 public string Name;
194 public string Status;
195 public string DownloadRegion;
196 public string Type;
197 public string HubLogoLink;
198 public string PrimaryColor;
199 public string SecondaryColor;
200 }
201
202 [Serializable]
204 {
205 public int ID;
206 public string First;
207 public string Last;
208 public string Email;
209 public string Username;
210
211 public bool HasErrored()
212 {
213 return (Email == null);
214 }
216
217 [Serializable]
219 {
221
222 public bool HasErrored()
223 {
224 return (AssistedLogin == null);
225 }
226 }
227
228 public class AssistedLoginCode
229 {
230 public string AuthCode;
231 public string Expires;
234 [Serializable]
235 public class SessionData
236 {
237 public float Score;
238 public float ScaledScore;
239 public float MinimumScore;
240 public float MaximumScore;
241 public int Duration;
242 public bool Complete;
243 public bool Success;
244
245 public SessionData() { }
246
247 public SessionData(float score, float scaled, float min, float max, int duration, bool completed, bool success)
248 {
249 Score = score;
250 ScaledScore = scaled;
251 MinimumScore = min;
253 Duration = duration;
254 Complete = completed;
255 Success = success;
259#if UNITY_6000_0_OR_NEWER
260 public class OrgModule : ScriptableObject, INotifyBindablePropertyChanged
261#else
262 public class OrgModule : ScriptableObject
263#endif
264 {
265 public int ID = -1;
266 public string Name = "";
267 public string Description = "";
268 public string ShortDescription = "";
269 public string LongDescription = "";
270 public string Industry = "";
271 public string Details = "";
272 public string IconURL = "";
273 public string AvailableLanguages = "";
274 public string Distributor = "";
275 public string UserGuideLink = "";
276 public bool IsAuthenticatedLaunch = false;
277 public bool EnableDebug = false;
278
279 private Texture2D _thumbnail;
280
281 [CreateProperty]
282 public Texture2D Thumbnail
283 {
284 get { return _thumbnail; }
285 set
286 {
287 _thumbnail = value;
288#if UNITY_6000_0_OR_NEWER
289 Notify();
290#endif
291 }
293
294 public List<OrgModuleDownload> Downloads = new List<OrgModuleDownload>();
295 public int? PassingScore = null;
296 public string Categories = "";
297 public string externalId = "";
298 public PlatformPlayer player = null;
299
300#if UNITY_6000_0_OR_NEWER
301 public event EventHandler<BindablePropertyChangedEventArgs> propertyChanged;
302#endif
304 public OrgModule()
305 {
306 Downloads = new List<OrgModuleDownload>();
307 }
308
309 public OrgModule(JToken token)
310 {
311 Downloads = new List<OrgModuleDownload>();
312 Parse(token);
314
315 public void Parse(JToken token)
317 ID = token.Value<int>("ID");
318 Name = token.Value<string>("Name");
319 Description = token.Value<string>("Description");
320 ShortDescription = token.Value<string>("ShortDescription");
321 LongDescription = token.Value<string>("LongDescription");
322 Details = token.Value<string>("Details");
323 IconURL = token.Value<string>("IconURL");
324 PassingScore = token.Value<int?>("PassingScore");
325 Categories = token.Value<string>("Categories");
326 externalId = token.Value<string>("externalId");
327 UserGuideLink = token.Value<string>("UserGuideLink");
328
329 var PlayerToken = token.Value<JObject>("player");
330
331 if (PlayerToken != null)
332 {
333 player = new PlatformPlayer(PlayerToken);
334 }
335
336 var DownloadTokens = token.Value<JArray>("Downloads");
337
338 if (DownloadTokens != null)
339 {
340 foreach (JToken DownloadToken in DownloadTokens)
341 {
342 var downloadData = ScriptableObject.CreateInstance<OrgModuleDownload>();
343 downloadData.Parse(DownloadToken);
344 Downloads.Add(downloadData);
348 var availableLanguages = GetValue<JArray>(token, "availableLanguages");
350 if (availableLanguages != null)
352 var availableLanguagesList = new List<string>();
354 foreach (JToken languageToken in availableLanguages)
356 string displayName = GetValue<string>(languageToken, "displayName");
357 if (!string.IsNullOrEmpty(displayName))
358 {
359 availableLanguagesList.Add(displayName);
361 }
362
363 AvailableLanguages = string.Join(", ", availableLanguagesList);
364 }
365
366 var industry = GetValue<string>(token, "Industry");
367 if (!string.IsNullOrEmpty(industry) && industry.Length > 0)
368 {
369 Industry = char.ToUpper(industry[0]) + (industry.Length > 1 ? industry[1..] : string.Empty);
370 }
371
372 var distributor = GetValue<JToken>(token, "distributor");
373 if (distributor != null)
375 Distributor = GetValue<string>(distributor, "name");
377
378 EnableDebug = token.Value<bool>("enableDebug");
379 IsAuthenticatedLaunch = token.Value<bool>("isAuthenticatedLaunch");
380 }
381
382 private T GetValue<T>(JToken token, string propertyName, T defaultValue = default)
383 {
384 return token[propertyName] != null ? token.Value<T>(propertyName) : defaultValue;
385 }
386
387#if UNITY_6000_0_OR_NEWER
388 void Notify([CallerMemberName] string property = "")
389 {
390 propertyChanged?.Invoke(this, new BindablePropertyChangedEventArgs(property));
391 }
392#endif
394
395 [Serializable]
397 {
398 public int ID;
399 public int VersionID;
400 public string FileLocation;
401 public string Version;
402 public string Platform;
403 public long DownloadSize;
404 public string ApkName;
405 public string URL;
406 public string Status;
407 public string externalId;
408
409 public OrgModuleDownload(JToken token)
410 {
411 Parse(token);
412 }
413
414 public void Parse(JToken token)
415 {
416 ID = token.Value<int>("ID");
417 VersionID = token.Value<int>("VersionID");
418 DownloadSize = token.Value<long>("DownloadSize");
419 externalId = token.Value<string>("externalId");
420 FileLocation = token.Value<string>("FileLocation");
421 Version = token.Value<string>("Version");
422 Platform = token.Value<string>("Platform");
423 ApkName = token.Value<string>("ApkName");
424 URL = token.Value<string>("URL");
425 Status = token.Value<string>("Status");
426 }
427 }
428
429#region Platform Models
430 [Serializable]
431 public class PlatformPlayer
432 {
433 public int id;
434 public string name;
435 public string description;
436 public int distributorId;
437 public string launchProtocol;
438 public List<PlatformPlayerDownload> versions = new List<PlatformPlayerDownload>();
439
440 public PlatformPlayer(JObject tokenObject)
441 {
442 id = tokenObject.Value<int>("id");
443 distributorId = tokenObject.Value<int>("distributorId");
444 name = tokenObject.Value<string>("name");
445 description = tokenObject.Value<string>("description");
446 launchProtocol = tokenObject.Value<string>("launchProtocol");
447
448 var versionTokens = tokenObject.Value<JArray>("versions");
449 if (versionTokens == null)
450 {
451 versionTokens = new JArray();
452 }
453
454 foreach (JToken Version in versionTokens)
455 {
456 versions.Add(new PlatformPlayerDownload(Version));
457 }
458 }
459 }
461 [Serializable]
462 public class PlatformPlayerDownload
463 {
464 public int id;
465 public string version;
466 public int modulePlayerId;
467 public string status;
468 public string URL;
469 public string ApkName;
470 public string platform;
471
472 public PlatformPlayerDownload(JToken token)
473 {
474 id = token.Value<int>("id");
475 modulePlayerId = token.Value<int>("modulePlayerId");
476 version = token.Value<string>("version");
477 status = token.Value<string>("status");
478 URL = token.Value<string>("URL");
479 ApkName = token.Value<string>("ApkName");
480 platform = token.Value<string>("platform");
481 }
485 [Serializable]
488 public string Token { get; set; }
489 public string Msg { get; set; }
490 public User User { get; set; }
492 public bool HasErrored()
494 return (User == null || string.IsNullOrEmpty(Token));
495 }
496 }
497
498 [Serializable]
499 public class User
500 {
501 public int Id { get; set; }
502 public string CreatedBy { get; set; }
503 public string UpdatedBy { get; set; }
504 public DateTime CreatedAt { get; set; }
505 public DateTime UpdatedAt { get; set; }
506 public string Role { get; set; }
507 public string[] Permissions { get; set; }
508 public string FirstName { get; set; }
509 public string LastName { get; set; }
510 public string Username { get; set; }
511 public string Email { get; set; }
512 public string Phone { get; set; }
513 public string Status { get; set; }
514 public string ExternalId { get; set; }
515 public DateTime PasswordExpDate { get; set; }
516 public Organization Org { get; set; }
517 public int OrgId { get; set; }
518 public DateTime? DeletedAt { get; set; }
519 public string AuthToken { get; set; }
523 [Serializable]
527 public List<QuickIDUser> QuickIDUsers;
528
529 public bool HasErrored()
530 {
531 return QuickIDUsers == null || OrgProperties == null;
532 }
533 }
534
535 public class OrgProperties
536 {
537 public string PrimaryColor;
538 public string SecondaryColor;
539 public string HubLogoURL;
540 public string OrgName;
541
542 public OrgProperties() { }
543 public OrgProperties(string primaryColor, string secondaryColor, string hubLogoURL, string orgName)
544 {
545 PrimaryColor = primaryColor;
546 SecondaryColor = secondaryColor;
547 HubLogoURL = hubLogoURL;
548 OrgName = orgName;
549 }
550 }
551
552 public class QuickIDUser
553 {
554 public string FirstName;
555 public string LastName;
556 public string Username;
557 public string Email;
559 public QuickIDUser() { }
561 public QuickIDUser(string firstName, string lastName, string username, string email)
563 FirstName = firstName;
564 LastName = lastName;
565 Username = username;
566 Email = email;
567 }
568 }
569
570 [Serializable]
571 public class QuickIDLoginData
572 {
573 public string Username;
574 public string SerialNumber;
575
576 public QuickIDLoginData( string serialNumber, string username)
577 {
578 SerialNumber = serialNumber;
579 Username = username;
580 }
581 }
582
583#endregion
584
585}
List< UserModulesData > ParsedData
Definition ApexTypes.cs:98
[Serializable]
Definition ApexTypes.cs:163
LoginData(string username, string password)
Definition ApexTypes.cs:167
void Parse(JToken token)
Definition ApexTypes.cs:498
OrgModuleDownload(JToken token)
Definition ApexTypes.cs:493
void Parse(JToken token)
Definition ApexTypes.cs:393
PlatformPlayer player
Definition ApexTypes.cs:376
List< OrgModuleDownload > Downloads
Definition ApexTypes.cs:372
OrgModule(JToken token)
Definition ApexTypes.cs:387
T GetValue< T >(JToken token, string propertyName, T defaultValue=default)
Definition ApexTypes.cs:460
OrgProperties(string primaryColor, string secondaryColor, string hubLogoURL, string orgName)
Definition ApexTypes.cs:660
List< PlatformPlayerDownload > versions
Definition ApexTypes.cs:525
PlatformPlayer(JObject tokenObject)
Definition ApexTypes.cs:527
QuickIDLoginData(string serialNumber, string username)
Definition ApexTypes.cs:699
QuickIDUser(string firstName, string lastName, string username, string email)
Definition ApexTypes.cs:678
SessionData(float score, float scaled, float min, float max, int duration, bool completed, bool success)
Definition ApexTypes.cs:325
[Serializable]
Definition ApexTypes.cs:608
DateTime CreatedAt
Definition ApexTypes.cs:612
Organization Org
Definition ApexTypes.cs:624
string[] Permissions
Definition ApexTypes.cs:615
DateTime? DeletedAt
Definition ApexTypes.cs:626
DateTime UpdatedAt
Definition ApexTypes.cs:613
DateTime PasswordExpDate
Definition ApexTypes.cs:623