Documentation for the Unity C# Library
Loading...
Searching...
No Matches
ApexTypes.cs
Go to the documentation of this file.
1using Newtonsoft.Json;
2using Newtonsoft.Json.Linq;
3using System;
4using System.Collections.Generic;
5using System.ComponentModel;
6using System.Runtime.CompilerServices;
7using System.Security.Cryptography;
8using Unity.Properties;
9using UnityEngine;
10using UnityEngine.UIElements;
11
12
13namespace PixoVR.Apex
14{
15 public interface IPlatformErrorable
16 {
17 public abstract bool HasErrored();
18 }
19
20 public interface IFailure
21 {
22 // Empty so we can check all failure types against this
23 }
24
25 [Serializable]
27 {
28 public string Error;
29 public string HttpCode;
30 public string Message;
31
32 public bool HasErrored()
33 {
34 bool hasErrored = false;
35 bool hasErrorSetup = !(Error == null && Message == null && HttpCode == null);
37 if (hasErrorSetup == false)
38 {
39 if (Error != null)
40 {
41 if (Error.Equals("true", StringComparison.CurrentCultureIgnoreCase))
42 {
43 hasErrored = true;
44 }
45 else
46 {
47 hasErrored = !string.IsNullOrEmpty(Error);
48 }
49 }
50 }
51
52 return hasErrored;
53 }
54 }
55
56 [Serializable]
57 public class JoinSessionResponse : FailureResponse
58 {
59 public JObject Data;
60 public int SessionId;
61
62 public void ParseData()
63 {
64 IEnumerable<JProperty> dataPropertyEnumerator = Data.Properties();
65 foreach (JProperty property in dataPropertyEnumerator)
66 {
67 if (property.Name.Equals("SessionId", StringComparison.OrdinalIgnoreCase))
68 {
69 SessionId = JsonConvert.DeserializeObject<int>(property.Value.ToString());
70 }
71 }
72 }
73 }
75 [Serializable]
77 {
78 public string Error;
79 public string HttpCode;
80 public string Message;
81 public JObject Data;
82 public List<UserModulesData> ParsedData;
83
84 public bool HasErrored()
85 {
86 return (Error.Equals("true", StringComparison.CurrentCultureIgnoreCase));
87 }
88
89 public void ParseData()
90 {
91 ParsedData = new List<UserModulesData>();
92 IEnumerable<JProperty> dataPropertyEnumerator = Data.Properties();
93 UserModulesData currentUser;
94 foreach (JProperty currentProperty in dataPropertyEnumerator)
95 {
96 currentUser = new UserModulesData();
98 currentUser.UserId = currentProperty.Name;
99 currentUser.AvailableModules = JsonConvert.DeserializeObject<List<int>>(
100 currentProperty.Value.ToString()
101 );
103 ParsedData.Add(currentUser);
104 }
105 }
106 }
108 [Serializable]
109 public class UserModulesData
110 {
111 public string UserId;
112 public List<int> AvailableModules;
113
114 public UserModulesData()
115 {
116 AvailableModules = new List<int>();
117 }
118 }
119
120 [Serializable]
121 public class UserModulesRequestData
122 {
123 [JsonProperty(PropertyName = "userIds")]
124 public List<int> UserIds = new List<int>();
125 }
126
127 [Serializable]
128 public class LoginData
129 {
130 public string Login;
131 public string Password;
132
133 public LoginData(string username, string password)
134 {
135 Login = username;
136 Password = password;
137 }
139
140 [Serializable]
142 {
143 public int ID;
144 public int OrgId;
145 public string First;
146 public string Last;
147 public string Email;
148 public string Token;
149 public string Role;
150 public Organization Org;
152
153 public bool HasErrored()
155 return (Email == null || Token == null);
156 }
157
158 public bool IsPlatformSuperadmin()
159 {
160 var isSuperAdmin = !String.IsNullOrEmpty(Role) && Role.Equals("superadmin", StringComparison.CurrentCultureIgnoreCase);
161 var isPlatformOrg = Org != null && !String.IsNullOrEmpty(Org.Type) && Org.Type.Equals("platform", StringComparison.CurrentCultureIgnoreCase);
162 return isPlatformOrg && isSuperAdmin;
163 }
165
166 [Serializable]
168 {
170
171 public bool HasErrored()
172 {
173 return User == null;
174 }
175 }
176
177 [Serializable]
178 public class UserAccessResponseContent : IPlatformErrorable
179 {
180 public int UserId = -1;
181 public int ModuleId = -1;
182 public bool Access;
183 public int? PassingScore;
184
185 public bool HasErrored()
187 return (UserId == -1 || ModuleId == -1);
191 [Serializable]
192 public class Organization
194 public int ID;
195 public string Name;
196 public string Status;
197 public string DownloadRegion;
198 public string Type;
199 public string HubLogoLink;
200 public string PrimaryColor;
201 public string SecondaryColor;
202 }
203
204 [Serializable]
206 {
207 public int ID;
208 public string First;
209 public string Last;
210 public string Email;
211 public string Username;
212
213 public bool HasErrored()
214 {
215 return (Email == null);
216 }
218
219 [Serializable]
221 {
223
224 public bool HasErrored()
225 {
226 return (AssistedLogin == null);
227 }
228 }
229
230 public class AssistedLoginCode
231 {
232 public string AuthCode;
233 public string Expires;
236 [Serializable]
237 public class SessionData
238 {
239 public float Score;
240 public float ScaledScore;
241 public float MinimumScore;
242 public float MaximumScore;
243 public int Duration;
244 public bool Complete;
245 public bool Success;
246
247 public SessionData() { }
248
249 public SessionData(float score, float scaled, float min, float max, int duration, bool completed, bool success)
250 {
251 Score = score;
252 ScaledScore = scaled;
253 MinimumScore = min;
255 Duration = duration;
256 Complete = completed;
257 Success = success;
261#if UNITY_6000_0_OR_NEWER
262 public class OrgModule : ScriptableObject, INotifyBindablePropertyChanged
263#else
264 public class OrgModule : ScriptableObject
265#endif
266 {
267 public int ID = -1;
268 public string Name = "";
269 public string Description = "";
270 public string ShortDescription = "";
271 public string LongDescription = "";
272 public string Industry = "";
273 public string Details = "";
274 public string IconURL = "";
275 public string AvailableLanguages = "";
276 public string Distributor = "";
277 public string UserGuideLink = "";
278 public bool IsAuthenticatedLaunch = false;
279 public bool EnableDebug = false;
280
281 private Texture2D _thumbnail;
282
283 [CreateProperty]
284 public Texture2D Thumbnail
285 {
286 get { return _thumbnail; }
287 set
288 {
289 _thumbnail = value;
290#if UNITY_6000_0_OR_NEWER
291 Notify();
292#endif
293 }
295
296 public List<OrgModuleDownload> Downloads = new List<OrgModuleDownload>();
297 public int? PassingScore = null;
298 public string Categories = "";
299 public string externalId = "";
300 public PlatformPlayer player = null;
301
302#if UNITY_6000_0_OR_NEWER
303 public event EventHandler<BindablePropertyChangedEventArgs> propertyChanged;
304#endif
306 public OrgModule()
307 {
308 Downloads = new List<OrgModuleDownload>();
309 }
310
311 public OrgModule(JToken token)
312 {
313 Downloads = new List<OrgModuleDownload>();
314 Parse(token);
316
317 public void Parse(JToken token)
319 ID = token.Value<int>("ID");
320 Name = token.Value<string>("Name");
321 Description = token.Value<string>("Description");
322 ShortDescription = token.Value<string>("ShortDescription");
323 LongDescription = token.Value<string>("LongDescription");
324 Details = token.Value<string>("Details");
325 IconURL = token.Value<string>("IconURL");
326 PassingScore = token.Value<int?>("PassingScore");
327 Categories = token.Value<string>("Categories");
328 externalId = token.Value<string>("externalId");
329 UserGuideLink = token.Value<string>("UserGuideLink");
330
331 var PlayerToken = token.Value<JObject>("player");
332
333 if (PlayerToken != null)
334 {
335 player = new PlatformPlayer(PlayerToken);
336 }
337
338 var DownloadTokens = token.Value<JArray>("Downloads");
339
340 if (DownloadTokens != null)
341 {
342 foreach (JToken DownloadToken in DownloadTokens)
343 {
344 var downloadData = ScriptableObject.CreateInstance<OrgModuleDownload>();
345 downloadData.Parse(DownloadToken);
346 Downloads.Add(downloadData);
350 var availableLanguages = GetValue<JArray>(token, "availableLanguages");
352 if (availableLanguages != null)
354 var availableLanguagesList = new List<string>();
356 foreach (JToken languageToken in availableLanguages)
358 string displayName = GetValue<string>(languageToken, "displayName");
359 if (!string.IsNullOrEmpty(displayName))
360 {
361 availableLanguagesList.Add(displayName);
363 }
364
365 AvailableLanguages = string.Join(", ", availableLanguagesList);
366 }
367
368 var industry = GetValue<string>(token, "Industry");
369 if (!string.IsNullOrEmpty(industry) && industry.Length > 0)
370 {
371 Industry = char.ToUpper(industry[0]) + (industry.Length > 1 ? industry[1..] : string.Empty);
372 }
373
374 var distributor = GetValue<JToken>(token, "distributor");
375 if (distributor != null)
377 Distributor = GetValue<string>(distributor, "name");
379
380 EnableDebug = token.Value<bool>("enableDebug");
381 IsAuthenticatedLaunch = token.Value<bool>("isAuthenticatedLaunch");
382 }
383
384 private T GetValue<T>(JToken token, string propertyName, T defaultValue = default)
385 {
386 return token[propertyName] != null ? token.Value<T>(propertyName) : defaultValue;
387 }
388
389#if UNITY_6000_0_OR_NEWER
390 void Notify([CallerMemberName] string property = "")
391 {
392 propertyChanged?.Invoke(this, new BindablePropertyChangedEventArgs(property));
393 }
394#endif
396
397 [Serializable]
399 {
400 public int ID;
401 public int VersionID;
402 public string FileLocation;
403 public string Version;
404 public string Platform;
405 public long DownloadSize;
406 public string ApkName;
407 public string URL;
408 public string Status;
409 public string externalId;
410
411 public OrgModuleDownload(JToken token)
412 {
413 Parse(token);
414 }
415
416 public void Parse(JToken token)
417 {
418 ID = token.Value<int>("ID");
419 VersionID = token.Value<int>("VersionID");
420 DownloadSize = token.Value<long>("DownloadSize");
421 externalId = token.Value<string>("externalId");
422 FileLocation = token.Value<string>("FileLocation");
423 Version = token.Value<string>("Version");
424 Platform = token.Value<string>("Platform");
425 ApkName = token.Value<string>("ApkName");
426 URL = token.Value<string>("URL");
427 Status = token.Value<string>("Status");
428 }
429 }
430
431#region Platform Models
432 [Serializable]
433 public class PlatformPlayer
434 {
435 public int id;
436 public string name;
437 public string description;
438 public int distributorId;
439 public string launchProtocol;
440 public List<PlatformPlayerDownload> versions = new List<PlatformPlayerDownload>();
441
442 public PlatformPlayer(JObject tokenObject)
443 {
444 id = tokenObject.Value<int>("id");
445 distributorId = tokenObject.Value<int>("distributorId");
446 name = tokenObject.Value<string>("name");
447 description = tokenObject.Value<string>("description");
448 launchProtocol = tokenObject.Value<string>("launchProtocol");
449
450 var versionTokens = tokenObject.Value<JArray>("versions");
451 if (versionTokens == null)
452 {
453 versionTokens = new JArray();
454 }
455
456 foreach (JToken Version in versionTokens)
457 {
458 versions.Add(new PlatformPlayerDownload(Version));
459 }
460 }
461 }
463 [Serializable]
464 public class PlatformPlayerDownload
465 {
466 public int id;
467 public string version;
468 public int modulePlayerId;
469 public string status;
470 public string URL;
471 public string ApkName;
472 public string platform;
473
474 public PlatformPlayerDownload(JToken token)
475 {
476 id = token.Value<int>("id");
477 modulePlayerId = token.Value<int>("modulePlayerId");
478 version = token.Value<string>("version");
479 status = token.Value<string>("status");
480 URL = token.Value<string>("URL");
481 ApkName = token.Value<string>("ApkName");
482 platform = token.Value<string>("platform");
483 }
487 [Serializable]
490 public string Token { get; set; }
491 public string Msg { get; set; }
492 public User User { get; set; }
494 public bool HasErrored()
496 return (User == null || string.IsNullOrEmpty(Token));
497 }
498 }
499
500 [Serializable]
501 public class User
502 {
503 public int Id { get; set; }
504 public string CreatedBy { get; set; }
505 public string UpdatedBy { get; set; }
506 public DateTime CreatedAt { get; set; }
507 public DateTime UpdatedAt { get; set; }
508 public string Role { get; set; }
509 public string[] Permissions { get; set; }
510 public string FirstName { get; set; }
511 public string LastName { get; set; }
512 public string Username { get; set; }
513 public string Email { get; set; }
514 public string Phone { get; set; }
515 public string Status { get; set; }
516 public string ExternalId { get; set; }
517 public DateTime PasswordExpDate { get; set; }
518 public Organization Org { get; set; }
519 public int OrgId { get; set; }
520 public DateTime? DeletedAt { get; set; }
521 public string AuthToken { get; set; }
525 [Serializable]
529 public List<QuickIDUser> QuickIDUsers;
530
531 public bool HasErrored()
532 {
533 return QuickIDUsers == null || OrgProperties == null;
534 }
535 }
536
537 public class OrgProperties
538 {
539 public string PrimaryColor;
540 public string SecondaryColor;
541 public string HubLogoURL;
542 public string OrgName;
543
544 public OrgProperties() { }
545 public OrgProperties(string primaryColor, string secondaryColor, string hubLogoURL, string orgName)
546 {
547 PrimaryColor = primaryColor;
548 SecondaryColor = secondaryColor;
549 HubLogoURL = hubLogoURL;
550 OrgName = orgName;
551 }
552 }
553
554 public class QuickIDUser
555 {
556 public string FirstName;
557 public string LastName;
558 public string Username;
559 public string Email;
561 public QuickIDUser() { }
563 public QuickIDUser(string firstName, string lastName, string username, string email)
565 FirstName = firstName;
566 LastName = lastName;
567 Username = username;
568 Email = email;
569 }
570 }
571
572 [Serializable]
573 public class QuickIDLoginData
574 {
575 public string Username;
576 public string SerialNumber;
577
578 public QuickIDLoginData( string serialNumber, string username)
579 {
580 SerialNumber = serialNumber;
581 Username = username;
582 }
583 }
584
585 [Serializable]
586 public class UserMetricsResponse : IFailure, IPlatformErrorable
587 {
588 public List<UserMetric> result;
589 public PageInfo pageInfo;
591 public bool HasErrored()
593 return (result == null || result.Count <= 0);
595 }
597
598 [Serializable]
599 public class PageInfo
600 {
601 public int totalCount;
602 public int page;
603 public int offset;
604 public int pageSize;
605 public int? previousPage;
606 public int? nextPage;
607
608 public int? GetLastPageNumber()
610 var lastPage = 1;
611 if (pageSize > 0)
613 lastPage = (int)Math.Ceiling((double)totalCount / pageSize);
615 return lastPage;
619 public enum UserRoles
621 [Description("superadmin")]
623 [Description("admin")]
624 Admin = 1,
625 [Description("manager")]
627 [Description("developer")]
629 [Description("user")]
630 User = 4,
631 [Description("student")]
632 Student = 5,
633 [Description("trial")]
634 Trial = 6
635 }
636
637 [Serializable]
638 public class UserMetric
639 {
640 public int id;
641 public string firstName;
642 public string lastName;
643 public string username;
644 public string email;
645 public string role;
646 public DateTime createdAt;
647 public int? orgUnitId;
649 public int? lastModuleId;
650 public Module lastModule;
651 public int sessionCount;
652 public DateTime? lastActiveAt;
653 public bool isInModule;
654 public string passcode;
655
656 [SerializeField]
657 public string DisplayName
659 get { return $"{firstName} {lastName}"; }
660 }
662 [SerializeField]
663 public string UsernameEmail
664 {
665 get
666 {
667 var display = username;
668 if (!String.IsNullOrWhiteSpace(email))
669 {
670 display = $"{username} ({email})";
672 return display ;
676 [SerializeField]
677 public string LastActiveDisplay
679 get
681 var dateFormat = "hh:mm tt";
682 return $"{lastActiveAt?.ToString(dateFormat)}";
683 }
684 }
685
686 [SerializeField]
687 public string LastSessionDisplay
688 {
689 get
690 {
691 var dateFormat = "MM/dd/yyyy hh:mm tt";
692 if (lastActiveAt?.Date == DateTime.Now.Date)
693 {
694 dateFormat = "hh:mm tt";
695 }
697 if (isInModule)
699 // TODO: Determine how we want to handle when no module exists but it says they are in a module.
700 if (lastModule == null)
702 //Debug.Log("No module found for this user.");
703 return "In module...";
704 }
705
707 {
708 return "In Hub App";
709 }
710
711 return $"In module {lastModule.description} ({lastModule.abbreviation}) - {lastActiveAt?.ToString(dateFormat)}";
712 }
713
714 if (lastActiveAt != null)
716 return $"Session Completed - {lastActiveAt?.ToString(dateFormat)}";
719
720 return "No session";
721 }
722 }
723 }
724
725 [Serializable]
726 public class OrgUnit
727 {
728 public int id;
729 public string name;
730 public string externalId;
731 }
732
733 [Serializable]
734 public class Module
735 {
736 public int id;
737 public string abbreviation;
738 public string description;
741 #endregion
List< UserModulesData > ParsedData
Definition ApexTypes.cs:100
[Serializable]
Definition ApexTypes.cs:165
LoginData(string username, string password)
Definition ApexTypes.cs:169
[Serializable]
Definition ApexTypes.cs:915
void Parse(JToken token)
Definition ApexTypes.cs:500
OrgModuleDownload(JToken token)
Definition ApexTypes.cs:495
void Parse(JToken token)
Definition ApexTypes.cs:395
PlatformPlayer player
Definition ApexTypes.cs:378
List< OrgModuleDownload > Downloads
Definition ApexTypes.cs:374
OrgModule(JToken token)
Definition ApexTypes.cs:389
T GetValue< T >(JToken token, string propertyName, T defaultValue=default)
Definition ApexTypes.cs:462
OrgProperties(string primaryColor, string secondaryColor, string hubLogoURL, string orgName)
Definition ApexTypes.cs:662
[Serializable]
Definition ApexTypes.cs:901
[Serializable]
Definition ApexTypes.cs:738
List< PlatformPlayerDownload > versions
Definition ApexTypes.cs:527
PlatformPlayer(JObject tokenObject)
Definition ApexTypes.cs:529
QuickIDLoginData(string serialNumber, string username)
Definition ApexTypes.cs:701
QuickIDUser(string firstName, string lastName, string username, string email)
Definition ApexTypes.cs:680
SessionData(float score, float scaled, float min, float max, int duration, bool completed, bool success)
Definition ApexTypes.cs:327
[Serializable]
Definition ApexTypes.cs:610
DateTime CreatedAt
Definition ApexTypes.cs:614
Organization Org
Definition ApexTypes.cs:626
string[] Permissions
Definition ApexTypes.cs:617
DateTime? DeletedAt
Definition ApexTypes.cs:628
DateTime UpdatedAt
Definition ApexTypes.cs:615
DateTime PasswordExpDate
Definition ApexTypes.cs:625
string DisplayName
[SerializeField]
Definition ApexTypes.cs:808
string?? LastSessionDisplay
[SerializeField]
Definition ApexTypes.cs:856
string UsernameEmail
[SerializeField]
Definition ApexTypes.cs:820
string? LastActiveDisplay
[SerializeField]
Definition ApexTypes.cs:840
List< UserMetric > result
Definition ApexTypes.cs:717