예제 #1
0
        /// <summary>
        /// 创造带课程和教师名的exp返回
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public static expReturn GetExpRet(Experiment e)
        {
            expReturn exp        = new expReturn();
            var       properties = exp.GetType().GetProperties();
            var       type       = e.GetType();

            foreach (var pi in properties)
            {
                if (pi.Name == "teacher_name" || pi.Name == "course_name" || pi.Name == "term_name" || pi.Name == "term_id")
                {
                    continue;
                }
                var value = type.GetProperty(pi.Name).GetValue(e, null);
                if (value != null)
                {
                    pi.SetValue(exp, value);
                }
            }
            Course course = CourseDao.GetCourseInfoById((int)e.course_id);

            exp.course_name  = course.name;
            exp.teacher_name = UserDao.GetUserById(course.teacher_id).name;
            exp.term_id      = Convert.ToInt32(course.term_id);
            exp.term_name    = CourseDao.GetTermById(exp.term_id).name;
            return(exp);
        }
예제 #2
0
        /// <summary>
        /// 为实验创建虚拟机
        /// </summary>
        /// <param name="vmConfig">虚拟机配置</param>
        /// <param name="vmName">虚拟机名</param>
        /// <param name="expId">实验id</param>
        /// <returns></returns>
        public static string CreateVMsForExp(VMConfig vmConfig, int applyId, string stulist)
        {
            Experiment exp = ExperimentDao.GetExperimentByApplyId(applyId);

            Course course = CourseDao.GetCourseInfoById((int)exp.course_id);

            vmConfig.Name = exp.vm_name;
            string teacherId = course.teacher_id;

            string[]      ids    = stulist.Split(' ');
            List <string> stuIds = new List <string>();

            foreach (string id in ids)
            {
                if (id != null && id.Length != 0)
                {
                    stuIds.Add(id);
                }
            }
            string[] names = new string[stuIds.Count()];
            string   res   = "success";


            for (int i = 0; i < stuIds.Count(); ++i)
            {
                names[i] = vmConfig.Name + "_" + stuIds[i];
            }
            if (ManagerType.Equals("Sangfor"))
            {
                List <SangforInfo> infoList = new List <SangforInfo>();
                for (int i = 0; i < stuIds.Count(); ++i)
                {
                    SangforInfo info = new SangforInfo();
                    info.student_id   = stuIds[i];
                    info.teacher_id   = teacherId;
                    info.IsTemplate   = false;
                    info.is_exp       = true;
                    info.is_exps      = "True";
                    info.Name         = names[i];
                    info.TemplateName = vmConfig.TemplateName;
                    infoList.Add(info);
                }
                //vmConfig.Disk = vmConfig.Disk / 1024;

                foreach (SangforInfo info in infoList)
                {
                    string result = restful.Create(vmConfig, info.Name, null, null);
                    if (!result.StartsWith("error"))
                    {
                        info.id = result;
                        SangforDao.Add(info);
                    }
                }
                // 使用新逻辑创建,优化创建时间
                //restful.CreateNewLogic(vmConfig,infoList);
            }
            else
            {
                res = manager.Create(vmConfig, names.ToList(), stuIds.ToList(), teacherId);
            }

            return(res);
        }