Beispiel #1
0
        public static string AnswerQuestionStudent(string studentName, string answer, string accessToken)
        {
            string method = "answerQuestionStudent";

            JObject obj  = JObject.Parse(answer);
            JObject jObj = JObject.Parse(JsonConvert.SerializeObject(obj));

            jObj.Add(new JProperty("Time_Table_ID", timeTableId));
            jObj.Add(new JProperty("Resource_ID", resourceId));
            jObj.Add(new JProperty("Course_ID", courseId));
            jObj.Add(new JProperty("Account_Name", studentName));
            jObj.Add(new JProperty("accessToken", accessToken));
            string[] param = new string[] { jObj.ToString() };

            try
            {
                string strRtn = WebServiceHelper.CallMethod(preclass_server_url, method, param);
                LogHelper.Trace("【{0}】 return:{1}", method, strRtn);
                if (string.IsNullOrEmpty(strRtn))
                {
                    LogHelper.Trace("WSanswerQuestionStudent:请求结果为空!");
                    return("");
                }
                JObject jo     = (JObject)JsonConvert.DeserializeObject(strRtn);
                string  status = jo["err_code"].ToString();
                if (status == "200")
                {
                    return(strRtn);
                }
                else
                {
                    LogHelper.Trace("{0}:请求成功,返回了错误码【{1}】", method, status);
                    return("");
                }
            }
            catch (Exception ex)
            {
                LogHelper.Trace($"{method}, {ex.GetType()}, {ex.Message}, {ex.Source}, {ex.StackTrace}");
                return("");
            }
            finally
            {
                ;
            }
        }
        static void Main(string[] args)
        {
            var     cfg = File.ReadAllText(Path.Combine(Environment.CurrentDirectory, "config.json"));
            JObject jo  = (JObject)JsonConvert.DeserializeObject(cfg);

            LogHelper.StartService();

            var classId      = "64c01042e1e64d23812768196ff012f6";
            var timeTableId  = "30b35e08dab04a5a88198b3ccb4cac73";
            var accountId    = "li_003";
            var accessToken  = "ACC-ESS-TOKEN-2020";
            var T_T_T_BH     = "DEMO-TTT-BH";
            var url          = jo["URL"].ToString();
            var numberOfRuns = Convert.ToInt32(jo["NUMBEROFRUNS"].ToString());   // 最大运行次数
            var mqIp         = jo["MQIP"].ToString();
            var mqPort       = jo["MQPORT"].ToString();
            var mqUserName   = jo["MQUSERNAME"].ToString();
            var mqPassword   = jo["MQPASSWORD"].ToString();

            Task[] mqKaoQinTask = new Task[numberOfRuns];
            MQHelper.CreateMqConnection(mqIp, mqPort, mqUserName, mqPassword);

            var wsObj = WebServiceHelper.GetObject(url);

            bool isExitTask = false;

            for (var i = 0; i < numberOfRuns; i++)
            {
                var k = i;
                mqKaoQinTask[i] = new Task(() => {
                    // 获取上课信息
                    string[] param = new string[] { accountId, "21", accessToken };

                    LogHelper.Trace($"param::accountId:{param[0]},applicationType:{param[1]},accessToken:{param[2]}");
                    //var s = WebServiceHelper.CallMethod(url, "getCourseInfoWhenStudentLoginInfo", param);
                    var s = WebServiceHelper.CallMethod(wsObj, "getCourseInfoWhenStudentLoginInfo", param);
                    LogHelper.Trace(s);
                    // 考勤
                    var jObj = new JObject();
                    jObj.Add(new JProperty("studentAccountId", accountId));
                    jObj.Add(new JProperty("timeTableId", timeTableId));
                    jObj.Add(new JProperty("wifiName", "Wifi-liuzhenhua"));
                    jObj.Add(new JProperty("checkWorkStatus", "2"));
                    jObj.Add(new JProperty("checkWorkTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                    jObj.Add(new JProperty("classId", classId));
                    jObj.Add(new JProperty("tocken", accessToken));
                    var jsonPostData = jObj.ToString();
                    LogHelper.OutputDebugString($"MQ::{jsonPostData}");
                    MQHelper.sentMsgToMQqueue("checkwork", jsonPostData);
                });
            }
            ;
            Console.WriteLine($"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff")}]开始并发测试MQ(考勤)...");
            mqKaoQinTask.ToList().ForEach(a => a.Start());
            #region 考勤统计
            Task.Run(() =>
            {
                while (!isExitTask)
                {
                    string method2  = "getCheckWorkStatistics";
                    string[] param2 = new string[] { timeTableId, T_T_T_BH, accessToken };
                    LogHelper.Trace("param::timeTableId:{0},T_T_T_BH:{1},token:{2}", param2[0], param2[1], param2[2]);
                    var s2 = WebServiceHelper.CallMethod(url, method2, param2);
                    LogHelper.Trace(s2);
                    LogHelper.Trace("Sleep 5000 ms.");
                    Thread.Sleep(5000);
                }
            });
            #endregion
            Task.WaitAll(mqKaoQinTask, 1000 * 60 * 5); // 最长等待5分钟
            isExitTask = true;
            Console.WriteLine($"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff")}]完成...");
            LogHelper.Stop();
        }