コード例 #1
0
ファイル: EndPanel.cs プロジェクト: RelinkaKing/UnityPC
    /// <summary>
    /// 根据答案内容确定ABCDE
    /// </summary>
    public IEnumerator GetOption()
    {
        JsonToXmlTool.getOption();
        submitScore ss = new submitScore();

        ss.uuid                  = AppOpera.myClass.rykjMemberId;
        ss.testpaperId           = Question.LibId;
        ss.testpaperStudentScore = ScenceData.score;
        ss.studentId             = ClassPanelControll.sin.id;
        ss.no        = ClassPanelControll.sin.no;
        ss.classesId = ClassPanelControll.currentClassId;
        List <Option> datas = new List <Option>();

        Debug.Log(JsonConvert.SerializeObject(QuestingPanel.selecteds));
        foreach (Selected st in QuestingPanel.selecteds)
        {
            if (!st.isRight)
            {
                datas.Add(new Option(st.qid, st.option));
            }
        }
        ss.data = datas.ToArray();
        Debug.Log(JsonConvert.SerializeObject(ss));
        KeyValue        kv  = new KeyValue("testpaperjson", JsonConvert.SerializeObject(ss));
        WebServicesBase wsb = new WebServicesBase();
        UnityWebRequest uw  = wsb.PostWithParams(servelets.commitScore, kv);

        yield return(uw.Send());

        Debug.Log(uw.downloadHandler.text);
        //servelets
        //string filePath =
    }
コード例 #2
0
    /// <summary>
    /// 获得所有题库json信息
    /// </summary>
    /// <returns></returns>
    public IEnumerator getAllBankJson()
    {
        //当网络不可用时
        if (Application.internetReachability == NetworkReachability.NotReachable)
        {
            Debug.Log("网络不可用!");
        }
        else
        {
            foreach (int tmpId in addedClassId)
            {
                #region  载试题
                KeyValue        kv = new KeyValue("classesId", tmpId + "");
                UnityWebRequest uw = this.PostWithParams(servelets.studentTestpaperTitle, kv);
                yield return(uw.Send());

                Debug.Log(uw.downloadHandler.text);
                Debug.Log(uw.isNetworkError);
                string filePath = PublicClass.filePath + "classId_" + tmpId + "_QAJSON.json";
                Debug.Log("getAllBankJson:" + filePath);
                if (!uw.isNetworkError)
                {
                    if (uw.downloadHandler.text.Contains("查询失败"))
                    {
                        continue;
                    }
                    try
                    {
                        Debug.Log(filePath);
                        FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                        //Json字符串格式化
                        string jsondata = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(uw.downloadHandler.text), Formatting.Indented);
                        byte[] b        = System.Text.Encoding.UTF8.GetBytes(jsondata);
                        fs.Write(b, 0, b.Length);
                        fs.Flush();
                        fs.Close();
                        JsonToXmlTool.JsonToXml(tmpId, classnameDic[tmpId]);
                    }
                    catch (Exception e)
                    {
                        Debug.Log(e.Message);
                        Debug.Log(e.StackTrace);
                        Debug.Log(tmpId + "--------error");
                        if (File.Exists(filePath))
                        {
                            File.Delete(filePath);
                        }
                    }
                }
                else
                {
                    continue;
                }
                #endregion

                #region  载错题
                //if (!File.Exists(PublicClass.filePath + "classId_" + tmpId + "_QAJSON.xml"))
                //{
                //    continue;
                //}
                KeyValue[] kvs = new KeyValue[4];
                kvs[0] = new KeyValue("uuid", AppOpera.myClass.rykjMemberId);
                kvs[1] = new KeyValue("classesId", tmpId + "");
                kvs[2] = new KeyValue("studentId", ClassPanelControll.sin.id + "");
                kvs[3] = new KeyValue("no", ClassPanelControll.sin.no + "");
                uw     = this.PostWithParams(servelets.selectStudentWrongTitlteNo, kvs);
                yield return(uw.Send());

                Debug.Log(uw.downloadHandler.text);
                Debug.Log(uw.isNetworkError);
                filePath = PublicClass.filePath + "classId_" + tmpId + "_Error_QAJSON.json";
                if (!uw.isNetworkError)
                {
                    if (uw.downloadHandler.text.Contains("查询失败") || !uw.downloadHandler.text.Contains("option"))
                    {
                        if (File.Exists(filePath))
                        {
                            File.Delete(filePath);
                        }
                        if (File.Exists(PublicClass.filePath + "classId_" + tmpId + "_Error_QAXML.xml"))
                        {
                            File.Delete(PublicClass.filePath + "classId_" + tmpId + "_Error_QAXML.xml");
                        }
                        continue;
                    }
                    try
                    {
                        Debug.Log(filePath);
                        FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                        //Json字符串格式化
                        Debug.Log(uw.downloadHandler.text);
                        string jsondata = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(uw.downloadHandler.text), Formatting.Indented);
                        byte[] b        = System.Text.Encoding.UTF8.GetBytes(jsondata);
                        fs.Write(b, 0, b.Length);
                        fs.Flush();
                        fs.Close();
                        JsonToXmlTool.JsonToXml(tmpId, classnameDic[tmpId], "_Error");
                    }
                    catch (Exception e)
                    {
                        Debug.Log(e.Message);
                        Debug.Log(e.StackTrace);
                        Debug.Log(tmpId + "--------error");
                        if (File.Exists(filePath))
                        {
                            File.Delete(filePath);
                        }
                    }
                }
                else
                {
                    continue;
                }
                #endregion
            }
        }
        yield return(null);
    }