Exemple #1
0
        public static void UpdatePlan(string id, Plan newPlan)
        {
            Plan plan = GetPlan(id);

            plan.Title        = newPlan.Title;
            plan.Description  = newPlan.Description;
            plan.Author       = newPlan.Author;
            plan.Variables    = newPlan.Variables;
            plan.Expressions  = newPlan.Expressions;
            plan.Styles       = newPlan.Styles;
            plan.PlanType     = newPlan.PlanType;
            plan.PlanCategory = newPlan.PlanCategory;
            plan.UserRole     = plan.UserRole;
            AppStore.PlanRepository.Save(id, new MemoryStream(System.Text.Encoding.UTF8.GetBytes(new JsonSerializer()
            {
                PrettifyJson = true
            }.SerializeToString(plan))));


            PlanLM planLM = PlanStorage.GetByID(id);

            if (planLM != null)
            {
                planLM.Title        = newPlan.Title;
                planLM.Description  = newPlan.Description;
                planLM.Author       = newPlan.Author;
                planLM.PlanType     = newPlan.PlanType;
                planLM.PlanCategory = newPlan.PlanCategory;
                planLM.UserRole     = planLM.UserRole;
                PlanStorage.Save(planLM);
            }
        }
        public static void Save(PlanLM lm)
        {
            PlanDB db = PlanDB.ToDB(lm);

            db.Save();

            lm.AutoID = db.AutoID;
        }
Exemple #3
0
        public static void DeletePlan(int autoID)
        {
            PlanLM plan = GetPlanLM(autoID);


            PlanStorage.Delete(autoID);
            JobStorage.DeleteByPlanAutoID(autoID);

            AppStore.PlanRepository.Delete(plan.ID);
        }
Exemple #4
0
        public static void DeleteJob(int autoID)
        {
            JobLM job = JobStorage.Get(autoID);

            JobStorage.Delete(autoID);
            if (job != null && job.PlanAutoID > 0)
            {
                PlanLM plan = PlanStorage.Get(job.PlanAutoID);
                plan.ReferenceCount--;
                PlanStorage.Save(plan);
            }
        }
Exemple #5
0
        /*
         * public static UserLM GetAuthUser(string userID, string password)
         * {
         *  AuthUser authUser = AppStore.UserAuthenticator.GetAuthUser(userID, password);
         *
         *  if (authUser == null)
         *  {
         *      return null;
         *  }
         *
         *
         *  UserLM user = UserStorage.Get(userID);
         *
         *  if (user == null)
         *  {
         *      user = new UserLM { ID = userID, Name = authUser.Name };
         *  }
         *
         *  UserStorage.Save(user);
         *
         *
         *  return user;
         * }
         */

        public static int CreateJob(int userAutoID, int planAutoID, string name, int decimalCount)
        {
            DateTime now = DateTime.Now;

            if (planAutoID > 0)
            {
                PlanLM planLM = GetPlanLM(planAutoID);
                Plan   plan   = GetPlan(planLM.AutoID);

                string id = Guid.NewGuid().ToString();
                AppStore.PlanRepository.Copy(planLM.ID, id);
                planLM.ReferenceCount++;
                PlanStorage.Save(planLM);
                return(JobStorage.Save(
                           new JobLM()
                {
                    Name = name,
                    CreateTime = now,
                    IsComplete = plan.Variables.Length == 0,
                    PlanAutoID = planAutoID,
                    PlanID = id,
                    PlanTitle = plan.Title,
                    UpdateTime = now,
                    UserAutoID = userAutoID,
                    Variables = new JsonSerializer().SerializeToString(new Dictionary <string, object>()),
                    DecimalCount = decimalCount,
                    DeleteFlag = 0
                }));
            }

            return(JobStorage.Save(
                       new JobLM()
            {
                Name = name,
                CreateTime = now,
                IsComplete = false,
                PlanAutoID = planAutoID,
                PlanID = "",
                PlanTitle = planAutoID == -1 ? "蒙特卡洛计算" : "蒙特卡洛计算(自适应)",
                UpdateTime = now,
                UserAutoID = userAutoID,
                Variables = new JsonSerializer().SerializeToString(new Dictionary <string, object>()),
                DecimalCount = decimalCount,
                DeleteFlag = 0
            }));
        }
Exemple #6
0
 public static PlanDB ToDB(PlanLM lm)
 {
     return(new PlanDB()
     {
         AutoID = lm.AutoID,
         ID = lm.ID,
         Title = lm.Title,
         Author = lm.Author,
         Description = lm.Description,
         CreateTime = lm.CreateTime,
         ReferenceCount = lm.ReferenceCount,
         PlanType = lm.PlanType,
         AuthFlag = lm.AuthFlag,
         PlanCategory = lm.PlanCategory,
         UserRole = lm.UserRole
     });
 }
        public ActionResult CreateJob(int planAutoID)
        {
            //ViewData["PageTitle"] = "创建实验";

            PlanLM plan = Script.GetPlanLM(planAutoID);

            //return View("EditJob", new EditJobVM(new JobLM()
            //{
            //    PlanAutoID = plan.AutoID,
            //    Name = plan.Title,
            //    PlanTitle = plan.Title
            //}));
            var job = new JobLM()
            {
                PlanAutoID   = plan.AutoID,
                PlanID       = plan.ID,
                Name         = plan.Title + "_" + DateTime.Now.ToString("yyyyMMddHHmmss"),
                PlanTitle    = plan.Title,
                DecimalCount = 3,
                IsComplete   = false,
                Variables    = "{}",
                UserAutoID   = Convert.ToInt32(HttpContext.Request.Cookies["userid"].Value)
            };
            var userid = Convert.ToInt32(HttpContext.Request.Cookies["userid"].Value);

            job.AutoID           = Script.CreateJob(userid, job.PlanAutoID, job.Name, 3);
            Session["JobAutoID"] = job.AutoID;
            Session["JobLM"]     = job;
            EvaluationContext context = Script.GetPlan(job.PlanAutoID, job.PlanID).CreateEvaluationContext();

            context.Settings = new Settings()
            {
                DecimalDigitCount = job.DecimalCount
            };
            Session["Context"] = context;
            Script.InitEvaluationContext(context, job);
            context.Update();
            new JobDAL().DeleteJob(job.AutoID);
            new PlanDAL().IncreaseQuote(planAutoID);
            return(View("ViewJob", new JobVM(context, job)));
        }
 public PlanListCellVM(PlanLM lm, int pageIndex, string author = "")
 {
     CreateJobUrl   = string.Format("/Home/CreateJob?planAutoID={0}", lm.AutoID);
     EditPlanUrl    = string.Format("/Home/EditPlan?planID={0}", lm.ID);
     DeletePlanUrl  = string.Format("javascript:deletePlan({0},{1});", lm.AutoID, pageIndex);
     ViewPlanUrl    = string.Format("/Home/ViewPlan?planID={0}", lm.AutoID);
     DownloadUrl    = string.Format("/Home/DownloadPlan?planID={0}", lm.ID);
     UpdatePlanUrl  = string.Format("/Home/UploadPlan?planID={0}", lm.ID);
     AuthPlanUrl    = string.Format("/Home/AuthPlan?planID={0}", lm.ID);
     Title          = lm.Title;
     Author         = lm.Author;
     Description    = lm.Description;
     CreateTime     = lm.CreateTime.ToShortDateString();
     ReferenceCount = lm.ReferenceCount;
     PlanType       = GetPlanType(lm.PlanType);
     IsCustom       = string.IsNullOrEmpty(author);
     AuthFlag       = lm.AuthFlag;
     PlanCategory   = lm.PlanCategory == "A" ? "检测数据处理" : "标准物质不确定度评定";
     PlanAutoID     = lm.AutoID;
     SeqNo          = lm.SeqNo;
     UserRole       = lm.UserRole;
 }
Exemple #9
0
        public static PlanLM AddPlan(Plan p)
        {
            Stream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(new JsonSerializer()
            {
                PrettifyJson = true
            }.SerializeToString(p)));

            string id   = Guid.NewGuid().ToString();
            Plan   plan = AppStore.PlanRepository.Save(id, stream);
            PlanLM lm   = new PlanLM()
            {
                ID           = id,
                Title        = plan.Title,
                Author       = p.Author,
                Description  = plan.Description,
                CreateTime   = DateTime.Now,
                PlanType     = p.PlanType,
                PlanCategory = p.PlanCategory,
                UserRole     = p.UserRole
            };

            PlanStorage.Save(lm);
            return(lm);
        }