Exemple #1
0
        public async Task <IExamItem> StartItemAsync(ExamItemExecutionContext context, CancellationToken token, string ItemVoice = "", string ItemEndVoice = "")
        {
            try
            {
                //todo:如果
                var examItem =
                    ExamItems.FirstOrDefault(x => x.ItemCode == context.ItemCode && x.State == ExamItemState.Progressing);
                if (examItem != null)
                {
                    if (!string.IsNullOrEmpty(ItemVoice))
                    {
                        examItem.VoiceFile = ItemVoice;
                    }
                    if (!string.IsNullOrEmpty(ItemEndVoice))
                    {
                        examItem.EndVoiceFile = ItemEndVoice;
                    }
                    return(examItem);
                }
                examItem = ProviderFactory.CreateExamItem(context.ItemCode, ItemVoice, ItemEndVoice);
                if (examItem != null)
                {
                    if (!string.IsNullOrEmpty(ItemVoice))
                    {
                        examItem.VoiceFile = ItemVoice;
                    }
                    if (!string.IsNullOrEmpty(ItemEndVoice))
                    {
                        examItem.EndVoiceFile = ItemEndVoice;
                    }
                }
                lock (ExamItems)
                {
                    ExamItems.Add(examItem);
                }
                await examItem.StartAsync(context, token).ContinueWith((task) =>
                {
                    if (task.Exception != null)
                    {
                        Logger.ErrorFormat("运行考试项目{0}发生异常,原因:{1}", context.ItemCode, task.Exception, task.Exception);
                    }
                }, token);

                return(examItem);
            }
            catch (Exception exp)
            {
                Logger.ErrorFormat("创建考试项目{0}发生异常,原因:{1}", context.ItemCode, exp, exp);
                return(null);
            }
        }