Пример #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);
            }
        }
Пример #2
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);
            }
        }
Пример #3
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
            }));
        }
Пример #4
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);
        }