Tanoda
NetworkManager.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.IO;
5using System.IO.Compression;
6using System.Linq;
7using System.Net.Mail;
8#if UNITY_EDITOR
9using System.Runtime.InteropServices;
10#endif
11using System.Text;
12using GILES;
13using NaughtyAttributes;
14using UnityEngine;
15using UnityEngine.Networking;
16
17public class NetworkManager : pb_MonoBehaviourSingleton<NetworkManager>
18{
19 public string url;
20 public string demoUrl;
21 public bool forceDemo = false;
23
24 [SerializeField]
25 private WSCourses cachedCourses;
26 private bool working;
27 private bool downloadFailed;
28 private byte failCounter = 0;
29#if UNITY_EDITOR
30 [SerializeField]
31#endif
32 private bool dontUploadDEV =
33#if UNITY_EDITOR
34 true;
35#else
36 false;
37#endif
38 [SerializeField] private string currentToken = "";
39
40 protected override void Awake()
41 {
42 DontDestroyOnLoad(gameObject);
43 base.Awake();
44 DontDestroyOnLoad(this);
45 Debug.Log(Application.absoluteURL);
46 Debug.Log(System.Reflection.Assembly.GetExecutingAssembly().Location);
47 if (Application.absoluteURL.ToLower().Contains("demo") || forceDemo
48#if !UNITY_WEBGL
49 || System.Reflection.Assembly.GetExecutingAssembly().Location.ToLower().Contains("demo")
50#endif
51 )
52 {
53 url = demoUrl;
54 Debug.Log("Using Demo URL");
55 }
56 }
57
58 public void SetAdminToken()
59 {
60 currentToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEsImlhdCI6MTYyMTMxOTI3NCwiZXhwIjoxNjUyODU1Mjc0fQ.TfN9HNCWHisjIOMURPf3VowoXOyNxbE5t6-65jJu-LE";
61 }
62
63 //public IEnumerator GetRequest(string url, Action<UnityWebRequest> callback)
64 //{
65 // using (UnityWebRequest request = UnityWebRequest.Get(url))
66 // {
67 // // Send the request and wait for a response
68 // yield return request.SendWebRequest();
69 // callback(request);
70 // }
71 //}
72
73 //private void Upload(byte[] content, string name)
74 //{
75 //}
76 //
77 //private void Download(string file)
78 //{
79 // WebClient client = new WebClient();
80 // client.DownloadFileCompleted += Client_DownloadFileCompleted;
81 //}
82 //
83 //private void Client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
84 //{
85 // if (e.Error == null)
86 // {
87 // working = false;
88 // }
89 // else
90 // {
91 // downloadFailed = true;
92 // }
93 //}
94
95 //public IEnumerable Sync() //TODO: check modified date
96 //{
97 // LoadingManager.instance.SetSyncing();
98 // LoadingManager.instance.ShowWindow();
99 // var serverFiles = GetFiles();
100 // GetLocalFiles(Application.streamingAssetsPath, out var localFiles);
101 // var downloadQueue = new Queue<string>();
102 //
103 // foreach (var localFile in localFiles)
104 // {
105 // var filename = localFile.Remove(0, localFile.LastIndexOf("\\") + 1);
106 // if (!serverFiles.Contains(filename))
107 // {
108 // downloadQueue.Enqueue(filename);
109 // }
110 // }
111 //
112 // while (downloadQueue.Count > 0)
113 // {
114 // var file = downloadQueue.Dequeue();
115 // Download(file);
116 // working = true;
117 // while (working)
118 // {
119 // yield return new WaitForEndOfFrame();
120 // }
121 //
122 // if (downloadFailed)
123 // {
124 // if (failCounter >= 5)
125 // {
126 // LoadingManager.instance.HideWindow();
127 // PopupManager.instance.ShowPopup("Syncing failed!", "Downloading files from the server failed multiple times!");
128 // yield break;
129 // }
130 // downloadQueue.Enqueue(file);
131 // failCounter++;
132 // }
133 // }
134 // LoadingManager.instance.HideWindow();
135 // yield return null;
136 //}
137
138 //private void GetLocalFiles(string folder, out List<string> files)
139 //{
140 // files = new List<string>();
141 // files.AddRange(Directory.GetFiles(folder, "*.zip"));
142 //
143 // var dirs = Directory.GetDirectories(folder);
144 // foreach (var dir in dirs)
145 // {
146 // GetLocalFiles(dir, out var temp);
147 // files.AddRange(temp);
148 // }
149 //}
150
151 public void SaveToken(string token)
152 {
153 currentToken = token.Replace("Bearer%20", "").Replace("Bearer ", "");
154 }
155
156 public IEnumerator Login(string user, string pw, Action<UserManager.WSLogin> success, Action<string> fail)
157 {
158 WWWForm form = new WWWForm();
159 form.AddField("email", user);
160 form.AddField("password", pw);
161 using (UnityWebRequest www = UnityWebRequest.Post(url + "users/login", form))
162 {
163 yield return www.SendWebRequest();
164
165 if (www.isNetworkError || www.isHttpError)
166 {
167 Debug.LogError(www.error);
168 var errortext = www.error;
169
170 try
171 {
172 errortext = JsonUtility.FromJson<ReturnError>(www.downloadHandler.text).message;
173 }
174 catch (Exception e)
175 {
176 Debug.LogError(e);
177 // ignored
178 }
179
180 fail(errortext);
181 }
182 else
183 {
184 var login = JsonUtility.FromJson<UserManager.WSLogin>(www.downloadHandler.text);
185 currentToken = login.accessToken;
186
187 var token = HttpCookie.GetCookie("token");
188 if (string.IsNullOrEmpty(token))
189 {
190 HttpCookie.SetCookie("token", "Bearer%20" + currentToken);
191 HttpCookie.SetCookie("userId", login.user.id.ToString());
192 }
193 success(login);
194 }
195 }
196 }
197
198 public IEnumerator LoginWithQR(string qr, Action<UserManager.WSLogin> success, Action<string> fail)
199 {
200 WWWForm form = new WWWForm();
201 form.AddField("qrcode", qr);
202 using (UnityWebRequest www = UnityWebRequest.Post(url + "users/login-with-qr", form))
203 {
204 yield return www.SendWebRequest();
205
206 if (www.isNetworkError || www.isHttpError)
207 {
208 Debug.LogError(www.error);
209 fail(www.error);
210 }
211 else
212 {
213 var login = JsonUtility.FromJson<UserManager.WSLogin>(www.downloadHandler.text);
214 currentToken = login.accessToken;
215
216 var token = HttpCookie.GetCookie("token");
217 if (string.IsNullOrEmpty(token))
218 {
219 HttpCookie.SetCookie("token", "Bearer%20" + currentToken);
220 HttpCookie.SetCookie("userId", login.user.id.ToString());
221 }
222 success(login);
223 }
224 }
225 }
226
227 public void AuthWebRequest(ref UnityWebRequest req)
228 {
229 req.SetRequestHeader("Authorization", "Bearer " + currentToken);
230 }
231
232 public IEnumerator CreateCurse(string name, string description, Action<WSCourse> success)
233 {
234 if (dontUploadDEV)
235 {
236 success(selectedLevel);
237 yield break;
238 }
239 WWWForm form = new WWWForm();
240 form.AddField("name", @name);
241 if (description == "")
242 {
243 description = " ";
244 }
245 form.AddField("description", description);
246 using (UnityWebRequest www = UnityWebRequest.Post(url + "course/create-course", form))
247 {
248 www.SetRequestHeader("Authorization", "Bearer " + currentToken);
249 yield return www.SendWebRequest();
250
251 if (www.isNetworkError || www.isHttpError)
252 {
253 Debug.LogError(www.error);
254 }
255 else
256 {
257 selectedLevel = JsonUtility.FromJson<WSReturnCourse>(www.downloadHandler.text).course;
259 success(selectedLevel);
260 }
261 }
262 }
263 public IEnumerator CreateQualityCurse(string name, string description, Action<WSCourse> success)
264 {
265 if (dontUploadDEV)
266 {
267 success(selectedLevel);
268 yield break;
269 }
270 WWWForm form = new WWWForm();
271 form.AddField("name", @name);
272 if (description == "")
273 {
274 description = " ";
275 }
276 form.AddField("description", description);
277 using (UnityWebRequest www = UnityWebRequest.Post(url + "course/create-quality-course", form))
278 {
279 www.SetRequestHeader("Authorization", "Bearer " + currentToken);
280 yield return www.SendWebRequest();
281
282 if (www.isNetworkError || www.isHttpError)
283 {
284 Debug.LogError(www.error);
285 }
286 else
287 {
288 selectedLevel = JsonUtility.FromJson<WSReturnCourse>(www.downloadHandler.text).course;
290 success(selectedLevel);
291 }
292 }
293 }
294
295 public IEnumerator CreateDobotCurse(string name, string description, Action<WSCourse> success)
296 {
297 if (dontUploadDEV)
298 {
299 success(selectedLevel);
300 yield break;
301 }
302 WWWForm form = new WWWForm();
303 form.AddField("name", @name);
304 if (description == "")
305 {
306 description = " ";
307 }
308 form.AddField("description", description);
309 using (UnityWebRequest www = UnityWebRequest.Post(url + "course/create-digital-twin-course", form))
310 {
311 www.SetRequestHeader("Authorization", "Bearer " + currentToken);
312 yield return www.SendWebRequest();
313
314 if (www.isNetworkError || www.isHttpError)
315 {
316 Debug.LogError(www.error);
317 }
318 else
319 {
320 selectedLevel = JsonUtility.FromJson<WSReturnCourse>(www.downloadHandler.text).course;
322 success(selectedLevel);
323 }
324 }
325 }
326
327 public string Compress(string uncompressedString)
328 {
329 byte[] compressedBytes;
330
331 using (var uncompressedStream = new MemoryStream(Encoding.UTF8.GetBytes(uncompressedString)))
332 {
333 using (var compressedStream = new MemoryStream())
334 {
335 using (var compressorStream = new GZipStream(compressedStream, System.IO.Compression.CompressionLevel.Fastest))
336 {
337 uncompressedStream.CopyTo(compressorStream);
338 }
339 compressedBytes = compressedStream.ToArray();
340 }
341 }
342
343 return Convert.ToBase64String(compressedBytes);
344 }
345
346 public string Decompress(string compressedString)
347 {
348 try
349 {
350 var compressedStream = new MemoryStream(Convert.FromBase64String(compressedString));
351
352 byte[] decompressedBytes;
353 using (var decompressorStream = new GZipStream(compressedStream, CompressionMode.Decompress))
354 {
355 using (var decompressedStream = new MemoryStream())
356 {
357 decompressorStream.CopyTo(decompressedStream);
358
359 decompressedBytes = decompressedStream.ToArray();
360 }
361 }
362
363 return Encoding.UTF8.GetString(decompressedBytes);
364 }
365 catch (Exception)
366 {
367 //ignored
368 }
369
370 return compressedString;
371 }
372
373 public IEnumerator SaveCourse(int id, string data, Action<WSCourse> success)
374 {
375 if (Application.internetReachability == NetworkReachability.NotReachable)
376 {
377 PopupManager.instance.ShowPopup("NO_NETWORK", "NO_NETWORK_MESSAGE");
378 LoadingManager.instance.HideWindow();
379 yield break;
380 }
381
382 if (dontUploadDEV)
383 {
384 success(selectedLevel);
385 yield break;
386 }
387 WWWForm form = new WWWForm();
388 form.AddField("courseId", id);
389 form.AddField("data", Compress(data));
390 using (UnityWebRequest www = UnityWebRequest.Post(url + "course/save-course", form))
391 {
392 www.SetRequestHeader("Authorization", "Bearer " + currentToken);
393 yield return www.SendWebRequest();
394
395 if (www.isNetworkError || www.isHttpError)
396 {
397 Debug.LogError(www.error);
398 }
399 else
400 {
401 selectedLevel = JsonUtility.FromJson<WSReturnCourse>(www.downloadHandler.text).course;
403 success(selectedLevel);
404 }
405 }
406 }
407
408 private IEnumerator SaveCourse2(int id, string data, Action<WSCourse> success)
409 {
410 if (dontUploadDEV)
411 {
412 success(selectedLevel);
413 yield break;
414 }
415 WWWForm form = new WWWForm();
416 form.AddField("courseId", id);
417 form.AddField("data", data);
418 using (UnityWebRequest www = UnityWebRequest.Post(url + "course/save-course", form))
419 {
420 www.SetRequestHeader("Authorization", "Bearer " + currentToken);
421 yield return www.SendWebRequest();
422
423 if (www.isNetworkError || www.isHttpError)
424 {
425 Debug.Log(www.error);
426 }
427 else
428 {
429 selectedLevel = JsonUtility.FromJson<WSReturnCourse>(www.downloadHandler.text).course;
431 success(selectedLevel);
432 }
433 }
434 }
435
436 public IEnumerator AddUsersToCourse(int[] userIds, int courseId, Action success)
437 {
438 WWWForm form = new WWWForm();
439 form.AddField("courseId", courseId);
440 var userIdData = userIds.Aggregate("[", (current, userId) => current + (userId + ","));
441 userIdData += "]";
442 form.AddField("userIds", userIdData);
443
444 using (UnityWebRequest www = UnityWebRequest.Post(url + "course/add-users-to-course", form))
445 {
446 www.SetRequestHeader("Authorization", "Bearer " + currentToken);
447 yield return www.SendWebRequest();
448
449 if (www.isNetworkError || www.isHttpError)
450 {
451 Debug.Log(www.error);
452 }
453 else
454 {
455 success();
456 }
457 }
458 }
459
460 public IEnumerator GetMyCurses(Action<WSCourses> success)
461 {
462 using (UnityWebRequest www = UnityWebRequest.Get(url + "course/all-by-user"))
463 {
464 www.SetRequestHeader("Authorization", "Bearer " + currentToken);
465 yield return www.SendWebRequest();
466
467 if (www.isNetworkError || www.isHttpError)
468 {
469 Debug.LogError(www.error);
470 }
471 else
472 {
473 cachedCourses = JsonUtility.FromJson<WSCourses>(www.downloadHandler.text);
474 success(cachedCourses);
475 }
476 }
477 }
478
479 public IEnumerator GetQualityMyCurses(Action<WSCourses> success)
480 {
481 using (UnityWebRequest www = UnityWebRequest.Get(url + "course/quality-all-by-user"))
482 {
483 www.SetRequestHeader("Authorization", "Bearer " + currentToken);
484 yield return www.SendWebRequest();
485
486 if (www.isNetworkError || www.isHttpError)
487 {
488 Debug.LogError(www.error);
489 }
490 else
491 {
492 cachedCourses = JsonUtility.FromJson<WSCourses>(www.downloadHandler.text);
493 success(cachedCourses);
494 }
495 }
496 }
497
498 public IEnumerator GetDobotMyCurses(Action<WSCourses> success)
499 {
500 using (UnityWebRequest www = UnityWebRequest.Get(url + "course/digital-twin-all-by-user"))
501 {
502 www.SetRequestHeader("Authorization", "Bearer " + currentToken);
503 yield return www.SendWebRequest();
504
505 if (www.isNetworkError || www.isHttpError)
506 {
507 Debug.LogError(www.error);
508 }
509 else
510 {
511 cachedCourses = JsonUtility.FromJson<WSCourses>(www.downloadHandler.text);
512 success(cachedCourses);
513 }
514 }
515 }
516
517 public IEnumerator GetGlobalFiles(Action<WSFiles> success)
518 {
519 using (UnityWebRequest www = UnityWebRequest.Get(url + "files"))
520 {
521 www.SetRequestHeader("Authorization", "Bearer " + currentToken);
522 yield return www.SendWebRequest();
523
524 if (www.isNetworkError || www.isHttpError)
525 {
526 Debug.LogError(www.error);
527 }
528 else
529 {
530 var files = JsonUtility.FromJson<WSFiles>("{\"files\": " + www.downloadHandler.text + "}");
531 success(files);
532 }
533 }
534 }
535
536 public string GetDataFromCourseNameInCache(string name)
537 {
538 foreach (var course in cachedCourses.courses)
539 {
540 if (name == course.name)
541 {
542 selectedLevel = course;
544 return selectedLevel.data;
545 }
546 }
547 return "";
548 }
549
550 public string GetDataFromIdInCache(string id)
551 {
552 foreach (var course in cachedCourses.courses)
553 {
554 if (Convert.ToInt32(id) == course.id)
555 {
556 selectedLevel = course;
558 return selectedLevel.data;
559 }
560 }
561 return "";
562 }
563
565 {
566 foreach (var course in cachedCourses.courses)
567 {
568 if (Convert.ToInt32(id) == course.id)
569 {
570 selectedLevel = course;
572 return selectedLevel;
573 }
574 }
575 return default;
576 }
577
578 public IEnumerator GetCurseByID(int id, Action<WSCourse> success)
579 {
580 using (UnityWebRequest www = UnityWebRequest.Get(url + "course/all-by-user/" + id))
581 {
582 www.SetRequestHeader("Authorization", "Bearer " + currentToken);
583 yield return www.SendWebRequest();
584
585 if (www.isNetworkError || www.isHttpError)
586 {
587 Debug.LogError(www.error);
588 }
589 else
590 {
591 //selectedLevel = az ott lenn
592 var course = JsonUtility.FromJson<WSCourse>(www.downloadHandler.text);
593 course.data = Decompress(course.data);
594 success(course);
595 }
596 }
597 }
598
599 public IEnumerator DeleteCurseByID(int id, Action success)
600 {
601 using (UnityWebRequest www = UnityWebRequest.Delete(url + "course/delete-course-by-id/" + id))
602 {
603 www.SetRequestHeader("Authorization", "Bearer " + currentToken);
604 yield return www.SendWebRequest();
605
606 if (www.isNetworkError || www.isHttpError)
607 {
608 Debug.LogError(www.error);
609 }
610 else
611 {
612 //UnityWebRequest.Delete does NOT returns anything (www.downloadHandler is null)
613 success();
614 }
615 }
616 }
617
618 //DEPRECATED
619 public IEnumerator DeleteFileByName(string fileName, Action success)
620 {
621 WWWForm form = new WWWForm();
622 form.AddField("courseId", selectedLevel.id);
623 form.AddField("fileName", fileName);
624
625 byte[] data = (byte[])null;
626 data = form.data;
627 if (data.Length == 0)
628 data = (byte[])null;
629
630 using (UnityWebRequest www = UnityWebRequest.Delete(url + "files/delete-file"))
631 {
632 www.uploadHandler = (UploadHandler)new UploadHandlerRaw(data);
633
634 www.SetRequestHeader("Authorization", "Bearer " + currentToken);
635
636 foreach (KeyValuePair<string, string> header in form.headers)
637 www.SetRequestHeader(header.Key, header.Value);
638
639 yield return www.SendWebRequest();
640
641 if (www.isNetworkError || www.isHttpError)
642 {
643 Debug.Log(www.error);
644 }
645 else
646 {
647 success();
648 }
649 }
650 }
651
652 public IEnumerator DeleteFileById(int fileId, Action success)
653 {
654 if (dontUploadDEV || fileId == -1)
655 {
656 Debug.Log("Invalid fileId!");
657 success();
658 yield break;
659 }
660
661 WWWForm form = new WWWForm();
662 form.AddField("courseId", selectedLevel.id);
663 form.AddField("fileId", fileId);
664
665 byte[] data = (byte[])null;
666 data = form.data;
667 if (data.Length == 0)
668 data = (byte[])null;
669
670 using (UnityWebRequest www = UnityWebRequest.Delete($"{(forceDemo ? demoUrl : url)}files/delete-file-by-id/{fileId}/{selectedLevel.id}"))
671 {
672 www.uploadHandler = (UploadHandler)new UploadHandlerRaw(data);
673
674 www.SetRequestHeader("Authorization", "Bearer " + currentToken);
675
676 foreach (KeyValuePair<string, string> header in form.headers)
677 www.SetRequestHeader(header.Key, header.Value);
678
679 yield return www.SendWebRequest();
680
681 if (www.isNetworkError || www.isHttpError)
682 {
683 Debug.LogError($"Failed to delete file id: {fileId}");
684 Debug.LogError(www.error);
685 }
686 else
687 {
688 success();
689 }
690 }
691 }
692 public IEnumerator DeleteGlobalFileById(int fileId, Action success)
693 {
694 if (dontUploadDEV)
695 {
696 success();
697 yield break;
698 }
699 WWWForm form = new WWWForm();
700 form.AddField("fileId", fileId);
701
702 byte[] data = (byte[])null;
703 data = form.data;
704 if (data.Length == 0)
705 data = (byte[])null;
706
707 using (UnityWebRequest www = UnityWebRequest.Delete($"{url}files/delete-file-by-id/{fileId}"))
708 {
709 www.uploadHandler = (UploadHandler)new UploadHandlerRaw(data);
710
711 www.SetRequestHeader("Authorization", "Bearer " + currentToken);
712
713 foreach (KeyValuePair<string, string> header in form.headers)
714 www.SetRequestHeader(header.Key, header.Value);
715
716 yield return www.SendWebRequest();
717
718 if (www.isNetworkError || www.isHttpError)
719 {
720 Debug.LogError(www.error);
721 }
722 else
723 {
724 success();
725 }
726 }
727 }
728
729 public IEnumerator LoadAllFilesForThisCourse(Action success, Action<string> failed)
730 {
731 if (selectedLevel.id == 0)
732 {
733 success();
734 yield break;
735 }
736
737 using (UnityWebRequest www = UnityWebRequest.Get(url + "files/get-file-list-by-course-id/" + selectedLevel.id))
738 {
739 www.SetRequestHeader("Authorization", "Bearer " + currentToken);
740 yield return www.SendWebRequest();
741
742 if (www.isNetworkError || www.isHttpError)
743 {
744 Debug.LogError(www.error);
745 failed(www.error);
746 }
747 else
748 {
749 var fileLoader = FindObjectOfType<FileDragAndDrop>();
750 var list = JsonUtility.FromJson<WSFiles>(www.downloadHandler.text);
751 BuildFileTree(new[] { Application.streamingAssetsPath });
752 foreach (var wsFile in list.files)
753 {
754 if (wsFile.global)
755 continue;
756
757 if (HasFile(wsFile.GetFileName(), out var path) && (!Path.GetExtension(wsFile.GetFileName()).EndsWith("hlp") && !Path.GetExtension(wsFile.GetFileName()).EndsWith("qiz")))
758 {
759 Debug.Log($"Has File '{wsFile.GetFileName()}' on disk, loading it from there.");
760 fileLoader.OnFileData(File.ReadAllBytes(path), wsFile.fileName, wsFile.modified, new WSFile() { fileSavedURL = path });
761 }
762 else
763 {
764 Debug.Log($"Downloading File '{wsFile.GetFileName()}' now...");
765 yield return GetFile(wsFile.fileSavedName, bytes =>
766 {
767 Debug.Log($"File {wsFile.GetFileName()} downloaded!");
768 fileLoader.OnFileData(bytes, wsFile.GetFileName(), wsFile.modified, wsFile);
769 });
770 }
771 }
772 //yield return fileLoader.LateRebuild();
773 success();
774 }
775 }
776 }
777
778 public IEnumerator LoadAllGlobalFiles(Action success, Action<string> failed)
779 {
780#if UNITY_EDITOR && false
781 failed("Disabled in editor!");
782 yield break;
783#endif
784 var fileLoader = FindObjectOfType<FileDragAndDrop>();
785 WSFile[] list = default;
786 yield return GetGlobalFiles((retlist) => { list = retlist.files; });
787 foreach (var wsFile in list)
788 {
789 if (HasFile(wsFile.GetFileName(), out var path))
790 {
791 Debug.Log($"Has File '{wsFile.GetFileName()}' on disk, loading it from there.");
792 fileLoader.OnFileData(File.ReadAllBytes(path), wsFile.GetFileName(), wsFile.modified,
793 new WSFile() { fileSavedURL = path }, true);
794 }
795 else
796 {
797 yield return GetFile(wsFile.fileSavedName,
798 bytes => { fileLoader.OnFileData(bytes, wsFile.GetFileName(), wsFile.modified, wsFile, true); });
799 }
800 }
801 fileLoader.SetLoading(false);
802 LoadingManager.instance.MainLoading = false;
803 yield return fileLoader.LateRebuild();
804 success();
805 }
806
807 public string WSFileToUrl(WSFile file)
808 {
809 if (file.fileSavedURL == null)
810 {
811 return "";
812 }
813 if (file.fileName == null)
814 {
815 return file.fileSavedURL;
816 }
817 return url + file.fileSavedURL.Remove(0, 1);
818 }
819
820 private readonly List<string> fileTree = new List<string>();
821 private void BuildFileTree(string[] aFiles)
822 {
823#if UNITY_WEBGL
824 return;
825#endif
826 foreach (var aFile in aFiles)
827 {
828 if (Directory.Exists(aFile))
829 {
830 var files = Directory.GetFiles(aFile);
831 var dirs = Directory.GetDirectories(aFile);
832 BuildFileTree(files);
833 BuildFileTree(dirs);
834 }
835 else
836 {
837 fileTree.Add(aFile.Replace('/', '\\'));
838 }
839 }
840 }
841
842 private bool HasFile(string fileName, out string path)
843 {
844 path = "";
845#if UNITY_WEBGL
846 return false;
847#endif
848 foreach (var aFile in fileTree)
849 {
850 if (fileName.ToLower() == aFile.Substring(aFile.LastIndexOf('\\') + 1).ToLower())
851 {
852 path = aFile;
853 return true;
854 }
855 }
856
857 return false;
858 }
859
860
861 public IEnumerator GetAllFilesForThisCourse(Action<WSFiles> success, Action<string> failed)
862 {
863 if (selectedLevel.id == 0)
864 {
865 failed("level ID is 0");
866 yield break;
867 }
868 using (UnityWebRequest www = UnityWebRequest.Get(url + "files/get-file-list-by-course-id/" + selectedLevel.id))
869 {
870 www.SetRequestHeader("Authorization", "Bearer " + currentToken);
871 yield return www.SendWebRequest();
872
873 if (www.isNetworkError || www.isHttpError)
874 {
875 Debug.LogError(www.error);
876 failed(www.error);
877 }
878 else
879 {
880 success(JsonUtility.FromJson<WSFiles>(www.downloadHandler.text));
881 }
882 }
883 }
884
885 public IEnumerator GetUserById(int id, Action<UserManager.WSUser> success, Action<string> failed)
886 {
887 try
888 {
889 var token = HttpCookie.GetCookie("token");
890 if (!token.Contains(currentToken) && !string.IsNullOrEmpty(token))
891 {
892 Debug.Log($"MiARák: tokens does not match\nSaved: Bearer%20{currentToken}\nOnPage: {token}");
893 SaveToken(token);
894 }
895 }
896 catch (Exception)
897 {
898 // ignored
899 }
900 using (UnityWebRequest www = UnityWebRequest.Get(url + "users/user-by-id?userId=" + id))
901 {
902 www.SetRequestHeader("Authorization", "Bearer " + currentToken);
903 yield return www.SendWebRequest();
904
905 if (www.isNetworkError || www.isHttpError)
906 {
907 Debug.LogError(www.error);
908 failed(www.error);
909 }
910 else
911 {
912 success(JsonUtility.FromJson<UserManager.WSUser>(www.downloadHandler.text));
913 }
914 }
915 }
916
917 public IEnumerator GetFile(string name, Action<byte[]> success)
918 {
919 using (UnityWebRequest www = UnityWebRequest.Get(url + "files/get-by-filename?filename=" + @name))
920 {
921 if (currentToken != "")
922 {
923 www.SetRequestHeader("Authorization", "Bearer " + currentToken);
924 }
925 yield return www.SendWebRequest();
926
927 if (www.isNetworkError || www.isHttpError)
928 {
929 Debug.LogError(www.error);
930 }
931 else
932 {
933 success(www.downloadHandler.data);
934 }
935 }
936 }
937 public IEnumerator UploadJson(UserManager.WSActions wsActions)
938 {
939 yield return null;
940 WWWForm form = new WWWForm();
941 form.headers.Clear();
942 form.headers["Content-Type"] = "application/json";
943 form.AddField("courseId", selectedLevel.id);
944 form.AddField("userId", wsActions.userId);
945 form.AddField("savedActions", wsActions.ActionsToArray());
946 var body = JsonUtility.ToJson(wsActions);
947
948 using (UnityWebRequest www = UnityWebRequest.Post(url + "statistics/create-tact-statistics", body))
949 {
950 www.uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(body));
951 www.SetRequestHeader("Authorization", "Bearer " + currentToken);
952 www.SetRequestHeader("Content-Type", "application/json");
953 yield return www.SendWebRequest();
954
955 if (www.isNetworkError || www.isHttpError)
956 {
957 Debug.LogError(www.error);
958 Debug.LogError(www.downloadHandler.text);
959 }
960 else
961 {
962 Debug.Log("all ok");
963 }
964 }
965 }
966
967 public IEnumerator AddUser(string email, string name, int groupId, Action<UserManager.WSUser> success)
968 {
969 WWWForm form = new WWWForm();
970 form.AddField("email", email);
971 form.AddField("name", @name);
972 form.AddField("groupId", groupId);
973 using (UnityWebRequest www = UnityWebRequest.Post(url + "users/registration-from-cms", form))
974 {
975 www.SetRequestHeader("Authorization", "Bearer " + currentToken);
976 yield return www.SendWebRequest();
977
978 if (www.isNetworkError || www.isHttpError)
979 {
980 Debug.LogError(www.error);
981 }
982 else
983 {
984 success(JsonUtility.FromJson<UserManager.WSUser>(www.downloadHandler.text));
985 }
986 }
987 }
988
989 public IEnumerator SetFilesToCourse(int[] fileIdArray, Action success = null)
990 {
991 yield return SetFilesToCourse(selectedLevel.id, fileIdArray, success);
992 }
993
994 public IEnumerator SetFilesToCourse(int courseId, int[] fileIdArray, Action success = null)
995 {
996 var fd = "[";
997 for (var i = 0; i < fileIdArray.Length; i++)
998 {
999 var id = fileIdArray[i];
1000 if (i + 1 >= fileIdArray.Length)
1001 {
1002 fd += $"{id}]";
1003 }
1004 else
1005 {
1006 fd += $"{id},";
1007 }
1008 }
1009
1010 Debug.Log($"setfiles: {fd}");
1011
1012 var sendData = $"{{\"courseId\":{courseId},\"fileIds\" :{fd}}}";
1013
1014 using (UnityWebRequest www = UnityWebRequest.Put(url + "course/set-file-to-course", sendData))
1015 {
1016 www.SetRequestHeader("Authorization", "Bearer " + currentToken);
1017 www.SetRequestHeader("Content-Type", "application/json");
1018 yield return www.SendWebRequest();
1019
1020 if (www.isNetworkError || www.isHttpError)
1021 {
1022 Debug.LogError(www.error);
1023 }
1024 else
1025 {
1026 success?.Invoke();
1027 }
1028 }
1029 }
1030
1031 public IEnumerator GetAllUserWOAdmin(Action<UserManager.WSUsers> success)
1032 {
1033 using (UnityWebRequest www = UnityWebRequest.Get(url + "users/get-all-without-admin"))
1034 {
1035 www.SetRequestHeader("Authorization", "Bearer " + currentToken);
1036 yield return www.SendWebRequest();
1037
1038 if (www.isNetworkError || www.isHttpError)
1039 {
1040 Debug.LogError(www.error);
1041 }
1042 else
1043 {
1044 Debug.Log("Success! :D");
1045 Debug.Log(www.downloadHandler.text);
1046 success(JsonUtility.FromJson<UserManager.WSUsers>("{\"users\":" + www.downloadHandler.text + "}"));
1047 }
1048 }
1049 }
1050
1051 public IEnumerator UploadFileToCurrent(byte[] file, string filename, bool global, Action onSuccess, Action onFailed)
1052 {
1053 yield return UploadFileToCourse(selectedLevel.id, file, filename, global, (x) => { onSuccess(); }, onFailed);
1054 }
1055
1056 public IEnumerator UploadFileToCurrent(byte[] file, string filename, bool global, Action<WSFile> onSuccess, Action onFailed)
1057 {
1058 yield return UploadFileToCourse(selectedLevel.id, file, filename, global, onSuccess, onFailed);
1059 }
1060
1061 public IEnumerator UploadFileToCourse(int courseId, byte[] file, string filename, bool global, Action<WSFile> onSuccess, Action onFailed)
1062 {
1063 if (dontUploadDEV)
1064 {
1065 File.WriteAllBytes(@"E:\aaaaaa\" + filename.Substring(filename.LastIndexOf('\\') + 1), file);
1066 onSuccess(default);
1067 yield break;
1068 }
1069 WWWForm form = new WWWForm();
1070 form.AddField("courseId", courseId);
1071 form.AddBinaryData("file", file, filename); //Decode Quoted Printable a BACKENDEN
1072 form.AddField("isGlobal", global ? "true" : "false");
1073
1074 byte[] data = (byte[])null;
1075 data = form.data;
1076 if (data.Length == 0)
1077 data = (byte[])null;
1078 Debug.Log($"Uploading file: {filename} size: {GetSizeInMemory(data.LongLength)}");
1079
1080 using (UnityWebRequest www = UnityWebRequest.Post(url + "files/upload-file/" + courseId, form))
1081 {
1082 www.SetRequestHeader("Authorization", "Bearer " + currentToken);
1083
1084 www.uploadHandler = (UploadHandler)new UploadHandlerRaw(data);
1085 yield return www.SendWebRequest();
1086
1087 if (www.isNetworkError || www.isHttpError)
1088 {
1089 Debug.LogError(www.error);
1090 onFailed();
1091 }
1092 else
1093 {
1094 onSuccess(JsonUtility.FromJson<WSFile>(www.downloadHandler.text));
1095 }
1096 }
1097 }
1098
1099 string GetSizeInMemory(long bytesize)
1100 {
1101
1102
1103 string[] sizes = { "B", "KB", "MB", "GB", "TB" };
1104 double len = Convert.ToDouble(bytesize);
1105 int order = 0;
1106 while (len >= 1024D && order < sizes.Length - 1)
1107 {
1108 order++;
1109 len /= 1024;
1110 }
1111
1112 return string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:0.##} {1}", len, sizes[order]);
1113 }
1114
1115 public IEnumerator SetUserCourseStatus(int courseId, int userId, int courseTypeId, bool isSuccess, bool isFinished, float timeSpent, Action onSuccess, Action onFailed)
1116 {
1117 WWWForm form = new WWWForm();
1118 form.AddField("courseId", courseId);
1119 form.AddField("userId", userId);
1120 form.AddField("courseTypeId", courseTypeId);
1121 form.AddField("isSuccess", isSuccess.ToString());
1122 form.AddField("isFinished", isFinished.ToString());
1123 form.AddField("timeSpent", timeSpent.ToString());
1124
1125 byte[] data = (byte[])null;
1126 data = form.data;
1127 if (data.Length == 0)
1128 data = (byte[])null;
1129
1130 using (UnityWebRequest www = UnityWebRequest.Post(url + "course/set-user-course-status", form))
1131 {
1132 www.SetRequestHeader("Authorization", "Bearer " + currentToken);
1133
1134 www.uploadHandler = (UploadHandler)new UploadHandlerRaw(data);
1135 yield return www.SendWebRequest();
1136
1137 if (www.isNetworkError || www.isHttpError)
1138 {
1139 Debug.LogError(www.error);
1140 onFailed?.Invoke();
1141 }
1142 else
1143 {
1144 onSuccess?.Invoke();
1145 }
1146 }
1147 }
1148
1149 public IEnumerator SetUserCourseStatus(int courseTypeId, bool isSuccess, bool isFinished, float timeSpent, Action onSuccess, Action onFailed)
1150 {
1151 if (courseTypeId == -1)
1152 {
1153 Debug.Log("TODO: courseTypeId with -1");
1154 yield break;
1155 }
1156 Debug.Assert(SavedUser.instance.wsUser != null, "SavedUser.instance.wsUser != null");
1157 yield return SetUserCourseStatus(selectedLevel.id, SavedUser.instance.wsUser.Value.id, courseTypeId, isSuccess, isFinished, timeSpent, onSuccess, onFailed);
1158 }
1159
1160 public IEnumerator UploadScreenshotCourse(byte[] file, Action onSuccess, Action onFailed)
1161 {
1162 if (dontUploadDEV)
1163 {
1164 File.WriteAllBytes(@"E:\aaaaaa\screenshot.png", file);
1165 onSuccess();
1166 yield break;
1167 }
1168 WWWForm form = new WWWForm();
1169 form.AddBinaryData("file", file);
1170
1171 byte[] data = (byte[])null;
1172 data = form.data;
1173 if (data.Length == 0)
1174 data = (byte[])null;
1175
1176 using (UnityWebRequest www = UnityWebRequest.Post(url + "files/upload-image-to-ducument/" + selectedLevel.id, form))
1177 {
1178 www.SetRequestHeader("Authorization", "Bearer " + currentToken);
1179
1180 www.uploadHandler = (UploadHandler)new UploadHandlerRaw(data);
1181 yield return www.SendWebRequest();
1182
1183 if (www.isNetworkError || www.isHttpError)
1184 {
1185 Debug.LogError(www.error);
1186 onFailed();
1187 }
1188 else
1189 {
1190 onSuccess();
1191 }
1192 }
1193 }
1194
1195 public List<string> CourseArrayToNameList(WSCourses courses, out List<int> ids)
1196 {
1197 var retlist = new List<string>();
1198 ids = new List<int>();
1199 foreach (var wsCourse in courses.courses)
1200 {
1201 retlist.Add(wsCourse.name);
1202 ids.Add(wsCourse.id);
1203 }
1204
1205 return retlist;
1206 }
1207
1208 [Serializable]
1209 public struct WSCourses
1210 {
1212 }
1213 [Serializable]
1214 public struct WSCourse
1215 {
1216 public int id;
1217 public string name;
1218 public string description;
1219 public string data;
1220 public float dataSize;
1223 public bool isQuality;
1224 public string created;
1225 public string modified;
1226 public WSFile[] files;
1227 public int type; // 1 = tanuló, 2 = vizsga
1228 }
1229 [Serializable]
1230 public struct WSReturnCourse
1231 {
1233 }
1234
1235 [Serializable]
1236 public struct WSFiles
1237 {
1238 public WSFile[] files;
1239 }
1240
1241 [Serializable]
1242 public struct WSFile
1243 {
1244 public int id;
1245 public string GetFileName()
1246 {
1247 return Attachment.CreateAttachmentFromString("", fileName).Name;
1248 }
1249 public string fileName;
1250 public string fileSavedName;
1251 public string fileSavedURL;
1252 public bool global;
1253 public bool connected;
1254 public string created;
1255 public string modified;
1256
1257 public override bool Equals(object obj)
1258 {
1259 if (!(obj is WSFile))
1260 {
1261 return false;
1262 }
1263
1264 var file = (WSFile)obj;
1265 return fileName == file.fileName;
1266 }
1267
1268 public static bool operator ==(WSFile a, WSFile b)
1269 {
1270 return a.Equals(b);
1271 }
1272
1273 public static bool operator !=(WSFile a, WSFile b)
1274 {
1275 return !(a == b);
1276 }
1277 public static bool operator >(WSFile a, WSFile b)
1278 {
1279 return DateTime.Parse(a.modified) > DateTime.Parse(b.modified);
1280 }
1281 public static bool operator <(WSFile a, WSFile b)
1282 {
1283 return DateTime.Parse(a.modified) < DateTime.Parse(b.modified);
1284 }
1285
1286 public override string ToString()
1287 {
1288 return $"ID: {id} fileName: {GetFileName()} fileSavedName: {fileSavedName} fileSavedURL:{fileSavedURL} Global: {global}";
1289 }
1290 }
1291
1292 [Button]
1293 public void LoginTeszt()
1294 {
1295 StartCoroutine(Login("admin@teszt.hu", "teszt", s =>
1296 {
1297 Debug.Log(s.user.@group.name);
1298 }, Debug.LogError));
1299 }
1300
1301 [Button]
1302 public void GetMyCursesTeszt()
1303 {
1304 StartCoroutine(GetMyCurses(courses =>
1305 {
1306 Debug.Log(courses);
1307 }));
1308 }
1309 [Button]
1310 public void UploadTeszt()
1311 {
1312 StartCoroutine(UploadFileToCourse(23, File.ReadAllBytes(@"C:\Users\UnityTeam\Desktop\dev.png"), "teszt.png", false, (x) => Debug.Log("success!"), () => Debug.Log("fail :(")));
1313 }
1314 [Button]
1315 private void DownloadDemos()
1316 {
1317 StartCoroutine(BackupDemos());
1318 }
1319
1320 private IEnumerator BackupDemos()
1321 {
1322 WSCourses courses = default;
1323 yield return GetMyCurses(c => { courses = c; });
1324 foreach (var wsCourse in courses.courses)
1325 {
1326 if (wsCourse.name.ToLower().Contains("tolltarto"))
1327 {
1328 File.WriteAllText(Path.Combine("E:\\backup", wsCourse.name) + ".json", wsCourse.data);
1329 if (wsCourse.files != null)
1330 {
1331 Directory.CreateDirectory(Path.Combine("E:\\backup", wsCourse.name));
1332 foreach (var file in wsCourse.files)
1333 {
1334 yield return GetFile(file.fileSavedName,
1335 bytes => { File.WriteAllBytes(Path.Combine("E:\\backup", wsCourse.name, file.GetFileName()), bytes); });
1336 }
1337 }
1338 }
1339 }
1340 }
1341
1342 public struct ReturnError
1343 {
1344 public int code;
1345 public string message;
1346 }
1347
1348 [Button]
1349 public void UploadTeszt2()
1350 {
1351 StartCoroutine(UploadFileToCourse(7, File.ReadAllBytes(@"E:\quiz1.qiz"), "quiz1.qiz", false, (x) => Debug.Log("success!"), () => Debug.Log("fail :(")));
1352 }
1353 public int deleteFileID;
1354 [Button]
1355 private void DeleteID()
1356 {
1357 StartCoroutine(DeleteFileById(deleteFileID, () => Debug.Log("success!")));
1358 }
1359 [Button]
1360 public void DeleteTeszt2()
1361 {
1362 StartCoroutine(DeleteFileById(61, () => Debug.Log("success!")));
1363 }
1364 [Button]
1366 {
1367 StartCoroutine(GetMyCurses(courses =>
1368 {
1369 Debug.Log(CourseArrayToNameList(JsonUtility.FromJson<WSCourses>("{\"courses\":[{\"id\":1,\"name\":\"postmanTeszt\",\"data\":\"wololo\"}]}"), out var ids)[0]);
1370 }));
1371 }
1372 [Button]
1373 public void UploadTolltarto()
1374 {
1375 url = demoUrl;
1376 StartCoroutine(SaveCourse2(20, File.ReadAllText(@"E:\backup\tolltarto.json"), courses =>
1377 {
1378 Debug.Log("OK!");
1379 }));
1380 }
1381 private string StripPath(string fullname)
1382 {
1383 var retval = fullname;
1384 if (retval.IndexOf('\\') != -1)
1385 {
1386 retval = retval.Remove(0, retval.LastIndexOf('\\') + 1);
1387 }
1388 if (retval.IndexOf('/') != -1)
1389 {
1390 retval = retval.Remove(0, retval.LastIndexOf('/') + 1);
1391 }
1392 return retval;
1393 }
1394 [Button]
1395 public void Teszt()
1396 {
1397 int courseID = 115;
1398 selectedLevel.id = courseID;
1399 currentToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEsImlhdCI6MTY3MTE5NzAwMiwiZXhwIjoxNzAyNzMzMDAyfQ.SphSSutfVh1eWLBOXMX04KOH-0gx-PpyLMf9THd20y4";
1400 var value = new UploadedFile() { fileName = "1lépés.qiz" };
1401
1402 StartCoroutine(GetAllFilesForThisCourse((wsfiles) =>
1403 {
1404
1405 foreach (var wsFile in wsfiles.files)
1406 {
1407 if (wsFile.fileName == StripPath(value.fileName) || wsFile.GetFileName() == StripPath(value.fileName))
1408 {
1409
1410 }
1411 }
1412 selectedLevel.id = 0;
1413 currentToken = null;
1414 }, (_) => { }));
1415 }
1416
1417 [Button]
1418 private void FilesParse()
1419 {
1420 var files = JsonUtility.FromJson<WSFile[]>("{\"files\": " + File.ReadAllText(@"E:\files.json") + "}");
1421 Debug.Log(files);
1422 }
1423#if UNITY_EDITOR
1424 [Button]
1425 private void DuplicateDeleter() => StartCoroutine(dd());
1426
1427 private IEnumerator dd()
1428 {
1429 int courseID = 115;
1430 selectedLevel.id = courseID;
1431 //currentToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEsImlhdCI6MTY3MTE5NzAwMiwiZXhwIjoxNzAyNzMzMDAyfQ.SphSSutfVh1eWLBOXMX04KOH-0gx-PpyLMf9THd20y4";
1432
1433 using (UnityWebRequest www = UnityWebRequest.Get((forceDemo ? demoUrl : url) + "files/get-file-list-by-course-id/" + courseID))
1434 {
1435 www.SetRequestHeader("Authorization", "Bearer " + currentToken);
1436 yield return www.SendWebRequest();
1437
1438 if (www.isNetworkError || www.isHttpError)
1439 {
1440 Debug.LogError(www.error);
1441 }
1442 else
1443 {
1444 var wsFiles = JsonUtility.FromJson<WSFiles>(www.downloadHandler.text).files;
1445 var stayingFiles = new Dictionary<string, WSFile>();
1446 foreach (var file in wsFiles)
1447 {
1448 if (!stayingFiles.ContainsKey(file.fileName))
1449 {
1450 stayingFiles.Add(file.fileName, file);
1451 }
1452 else
1453 {
1454 if (stayingFiles[file.fileName] < file)
1455 {
1456 stayingFiles[file.fileName] = file;
1457 }
1458
1459 }
1460 }
1461 yield return null;
1462
1463 foreach (var file in wsFiles)
1464 {
1465 if (stayingFiles[file.fileName] > file)
1466 {
1467 yield return DeleteFileById(file.id, () => { Debug.Log("File deleted: " + file.GetFileName() + " ID: " + file.id); });
1468 }
1469 }
1470 }
1471 }
1472 selectedLevel.id = 0;
1473 currentToken = null;
1474 }
1475#endif
1476
1477#if UNITY_EDITOR
1478
1479 [DllImport("user32.dll")]
1480 internal static extern bool OpenClipboard(IntPtr hWndNewOwner);
1481
1482 [DllImport("user32.dll")]
1483 internal static extern bool CloseClipboard();
1484
1485 [DllImport("user32.dll")]
1486 internal static extern bool SetClipboardData(uint uFormat, IntPtr data);
1487 [SerializeField] private string decopressThis;
1488
1489 [Button]
1490 [STAThread]
1491 private void Decompress()
1492 {
1493 var decomp = Decompress(decopressThis);
1494 Debug.Log(decomp);
1495 OpenClipboard(IntPtr.Zero);
1496
1497 var ptr = Marshal.StringToHGlobalUni(decomp);
1498 SetClipboardData(13, ptr);
1499 CloseClipboard();
1500 Marshal.FreeHGlobal(ptr);
1501 }
1502#endif
1503}
UnityEngine.UI.Button Button
Definition: Pointer.cs:7
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
IEnumerator AddUser(string email, string name, int groupId, Action< UserManager.WSUser > success)
IEnumerator GetMyCurses(Action< WSCourses > success)
string GetDataFromCourseNameInCache(string name)
IEnumerator GetCurseByID(int id, Action< WSCourse > success)
IEnumerator DeleteFileByName(string fileName, Action success)
IEnumerator DeleteCurseByID(int id, Action success)
void AuthWebRequest(ref UnityWebRequest req)
IEnumerator UploadFileToCurrent(byte[] file, string filename, bool global, Action onSuccess, Action onFailed)
IEnumerator GetFile(string name, Action< byte[]> success)
IEnumerator UploadJson(UserManager.WSActions wsActions)
IEnumerator GetGlobalFiles(Action< WSFiles > success)
IEnumerator DeleteFileById(int fileId, Action success)
IEnumerator GetDobotMyCurses(Action< WSCourses > success)
IEnumerator GetQualityMyCurses(Action< WSCourses > success)
IEnumerator SetUserCourseStatus(int courseTypeId, bool isSuccess, bool isFinished, float timeSpent, Action onSuccess, Action onFailed)
IEnumerator LoadAllGlobalFiles(Action success, Action< string > failed)
WSCourse GetCourseFromIdInCache(string id)
IEnumerator CreateDobotCurse(string name, string description, Action< WSCourse > success)
IEnumerator GetAllUserWOAdmin(Action< UserManager.WSUsers > success)
List< string > CourseArrayToNameList(WSCourses courses, out List< int > ids)
string GetDataFromIdInCache(string id)
string Decompress(string compressedString)
IEnumerator SetFilesToCourse(int[] fileIdArray, Action success=null)
IEnumerator DeleteGlobalFileById(int fileId, Action success)
IEnumerator SetFilesToCourse(int courseId, int[] fileIdArray, Action success=null)
IEnumerator AddUsersToCourse(int[] userIds, int courseId, Action success)
IEnumerator CreateCurse(string name, string description, Action< WSCourse > success)
void GetMyCursesTesztLocal()
override void Awake()
WSCourse selectedLevel
string Compress(string uncompressedString)
IEnumerator SaveCourse(int id, string data, Action< WSCourse > success)
IEnumerator GetUserById(int id, Action< UserManager.WSUser > success, Action< string > failed)
IEnumerator Login(string user, string pw, Action< UserManager.WSLogin > success, Action< string > fail)
IEnumerator UploadScreenshotCourse(byte[] file, Action onSuccess, Action onFailed)
IEnumerator GetAllFilesForThisCourse(Action< WSFiles > success, Action< string > failed)
void SetAdminToken()
IEnumerator LoadAllFilesForThisCourse(Action success, Action< string > failed)
void SaveToken(string token)
IEnumerator CreateQualityCurse(string name, string description, Action< WSCourse > success)
IEnumerator LoginWithQR(string qr, Action< UserManager.WSLogin > success, Action< string > fail)
IEnumerator SetUserCourseStatus(int courseId, int userId, int courseTypeId, bool isSuccess, bool isFinished, float timeSpent, Action onSuccess, Action onFailed)
IEnumerator UploadFileToCourse(int courseId, byte[] file, string filename, bool global, Action< WSFile > onSuccess, Action onFailed)
IEnumerator UploadFileToCurrent(byte[] file, string filename, bool global, Action< WSFile > onSuccess, Action onFailed)
string WSFileToUrl(WSFile file)
override string ToString()
static bool operator>(WSFile a, WSFile b)
static bool operator<(WSFile a, WSFile b)
static bool operator==(WSFile a, WSFile b)
override bool Equals(object obj)
static bool operator!=(WSFile a, WSFile b)