Beispiel #1
0
    ///<summary>
    ///Create rows for the list of questions and answers created
    ///</summary>
    public async Task Read()
    {
        count = 0;
        for (int i = 0; i < itemParent.transform.childCount; i++)
        {
            Destroy(itemParent.transform.GetChild(i).gameObject);
        }
        DatabaseQAHandler.GetCourseLvlQn(key, courseLvlQn =>
        {
            courseLvlQnCreate = courseLvlQn;
            int number        = 1;
            for (int i = 0; i < (courseLvlQn.qns).Count; i++) // Loop through List
            {
                GameObject tmp_item = Instantiate(item, itemParent.transform);
                tmp_item.name       = i.ToString();
                Debug.Log("here item name: " + tmp_item.name);
                tmp_item.transform.GetChild(0).GetComponent <Text>().text = number.ToString();
                tmp_item.transform.GetChild(1).GetComponent <Text>().text = courseLvlQn.qns[i];
                tmp_item.transform.GetChild(2).GetComponent <Text>().text = (courseLvlQn.ans[i]).ToString();
                number++;
                count++;
            }
        });
        Stopwatch sw    = Stopwatch.StartNew();
        var       delay = Task.Delay(1000).ContinueWith(_ =>
        {
            sw.Stop();
            return(sw.ElapsedMilliseconds);
        });
        await delay;
        int   sec = (int)delay.Result;

        Debug.Log("Read elapsed milliseconds: {0}" + sec + "Count:" + count);
    }
    ///<summary>
    ///Check whether there is an existing level
    ///</summary>
    ///<param name = "lvlNo">Level number</param>
    public async Task InvokeLvlCheckExist(int lvlNo)
    {
        Task <bool> task     = CheckLvlExist(lvlNo);
        bool        lvlExist = await task;

        Debug.Log("Level Exist: " + lvlExist);
        if (lvlExist == true)
        {
            created = false;
            Debug.Log("LvlExist true, created: " + created);
            messageBox.SetActive(true);
            messageBox.transform.GetChild(1).GetComponent <Text>().text = "Level " + lvlNo + " already exist.";
        }
        else
        {
            var courseLvlQn = new CourseLvlQn(courseName, lvlNo, qns, ans);
            loader.SetActive(true);
            created = true;
            await PostingLvl(courseLvlQn);
            await Read();

            loader.SetActive(false);
            messageBox.SetActive(true);
            messageBox.transform.GetChild(1).GetComponent <Text>().text = "Level " + lvlNo + " created successfully.";
        }
    }
    ///<summary>
    ///Create a level in Database
    ///</summary>
    ///<param name = "courseLvlQn">CourseLvlQn Object</param>
    public async Task PostingLvl(CourseLvlQn courseLvlQn)
    {
        DatabaseQAHandler.PostCourseLvlQn(courseLvlQn, () => { });
        Stopwatch sw    = Stopwatch.StartNew();
        var       delay = Task.Delay(1000).ContinueWith(_ =>
        {
            sw.Stop();
            return(sw.ElapsedMilliseconds);
        });
        await delay;
        int   sec = (int)delay.Result;

        Debug.Log("Creating Level Elapsed milliseconds: {0}" + sec);
    }
Beispiel #4
0
 ///<summary>
 ///Create a Level
 ///</summary>
 ///<param name = "courseLvlQn">A CourseLvlQn object</param>
 ///<param name = "callback"></param>
 public static void PostCourseLvlQn(CourseLvlQn courseLvlQn, PostLvlCallback callback)
 {
     RestClient.Post <CourseLvlQn>($"{databaseURL}courseLevelQns/.json", courseLvlQn).Then(response => { callback(); });
 }
Beispiel #5
0
 ///<summary>
 ///Update a Course Level Atrributes
 ///</summary>
 ///<param name = "key">Unique key of data</param>
 ///<param name = "courseLvlQn">A CourseLvlQn object</param>
 ///<param name = "callback"></param>
 public static void PutCourseLvlQn(string key, CourseLvlQn courseLvlQn, PostLvlCallback callback)
 {
     RestClient.Put($"{databaseURL}courseLevelQns/" + key + ".json", courseLvlQn);//.Then(response => { callback(); });
 }