Exemplo n.º 1
0
 public string Create(string compositionGuid, int userId, string triggerInvokeTime)
 {
     using (OOCEntities db = new OOCEntities())
     {
         IQueryable<Composition> result = from o in db.Composition
                                          where o.guid == compositionGuid
                                          select o;
         if (!result.Any())
         {
             throw new FaultException("COMPOSITION_NOT_EXISTS");
         }
         Composition composition = result.First();
         CompositionData compositionData = new CompositionData(composition);
         Task task = new Task()
         {
             guid = GuidUtil.newGuid(),
             compositionGuid = compositionGuid,
             compositionData = compositionData.Serialized,
             state = (sbyte)TaskState.Created,
             userId = userId,
             triggerInvokeTime = triggerInvokeTime,
             modelProgress = new ModelProgress().Serialized
         };
         db.Task.AddObject(task);
         db.SaveChanges();
         SyncCompositionInputFiles(task.guid);
         return task.guid;
     }
 }
Exemplo n.º 2
0
        public ResultLogs GetModelOne(string ID)
        {
            /*sb.Append("Select ID,ModelID,UserID,CalTime,FileFolder FROM ResultLogs WHERE ID=@ID;");
            SqlParameter[] parameters ={
                                        new SqlParameter("@ID", SqlDbType.NVarChar,50)
                                    };
            parameters[0].Value = ID;

            DataSet ds = new DataSet();
            ds = DbHelperSQL.Query(sb.ToString(), parameters);
            DataRow dr = ds.Tables[0].Rows[0];
            ModelYunModel.ResultLogs oneModel = new ModelYunModel.ResultLogs();
            oneModel.ID = dr[0].ToString();
            oneModel.ModelID = dr[1].ToString();
            oneModel.UserID = dr[2].ToString();
            oneModel.CalTime = Convert.ToDateTime(dr[3]);
            oneModel.FileFolder = dr[4].ToString();
            return oneModel;*/
            using (OOCEntities db = new OOCEntities()) {
                IQueryable<ResultLogs> result = from o in db.ResultLogs
                                                where o.id == ID
                                                select o;
                return result.First();
            }
        }
Exemplo n.º 3
0
 //根据guid查outputParameter表项
 public List<OutputParameter> GetByGuid(string guid)
 {
     using (OOCEntities db = new OOCEntities()) {
         IQueryable<OutputParameter> result = from o in db.OutputParameter
                                               where o.guid == guid
                                               select o;
         return result.ToList();
     }
 }
Exemplo n.º 4
0
 //根据compositionModelGuid查outputParameter表项
 public List<OutputParameter> GetByCmGuid(string cmGuid)
 {
     using (OOCEntities db = new OOCEntities()) {
         IQueryable<OutputParameter> result = from o in db.OutputParameter
                                              where o.compositionModelGuid == cmGuid
                                              select o;
         return result.ToList();
     }
 }
Exemplo n.º 5
0
 public bool Auth(string username, string password)
 {
     using (OOCEntities db = new OOCEntities())
     {
         string passhash = Hash(password);
         IQueryable<User> result = from o in db.User
                                   where o.username == username && o.passhash == passhash
                                   select o;
         return result.Any();
     }
 }
Exemplo n.º 6
0
 public User GetById(int id)
 {
     using (OOCEntities db = new OOCEntities())
     {
         IQueryable<User> result = from o in db.User
                                   where o.id == id
                                   select o;
         if (!result.Any())
         {
             throw new FaultException("USER_NOT_EXISTS");
         }
         return result.First();
     }
 }
Exemplo n.º 7
0
 public void Create(User user)
 {
     using (OOCEntities db = new OOCEntities())
     {
         try
         {
             db.User.AddObject(user);
             db.SaveChanges();
         }
         catch
         {
             throw new FaultException("TRANSACTION_FAILED");
         }
     }
 }
Exemplo n.º 8
0
        //string guid, string elementSet?,string quantity?,string parameterValue,string creation
        //根据task的计算结果创建outputParameter表项
        public void Create(string taskGuid, string compositionGuid, string compositionModelGuid, string elementSet, string quantity, string parameterValue, DateTime creation)
        {
            using (OOCEntities db = new OOCEntities()) {
                    OutputParameter outputParameter = new OutputParameter(){
                     guid = GuidUtil.newGuid(),
            taskGuid = taskGuid,
            compositionGuid = compositionGuid,
            compositionModelGuid = compositionModelGuid,
            elementSet = elementSet,
            quantity = quantity,
            parameterValue = parameterValue,
            creation = creation
                };
                    db.OutputParameter.AddObject(outputParameter);
                db.SaveChanges();

            }
        }
Exemplo n.º 9
0
 public void AddTaskFileMapping(string guid, string fileName, string relativePath, TaskFileType type, bool isDownloadable)
 {
     using (OOCEntities db = new OOCEntities())
     {
         TaskFileMapping taskFileMapping = new TaskFileMapping()
         {
             taskGuid = guid,
             fileName = fileName,
             relativePath = relativePath,
             type = (sbyte)type,
             isDownloadable = isDownloadable
         };
         try
         {
             db.TaskFileMapping.AddObject(taskFileMapping);
             db.SaveChanges();
         }
         catch { }
     }
 }
Exemplo n.º 10
0
 public TaskAssignResponse AssignPendingTask(string instanceName)
 {
     lock (assigningLock)
     {
         using (OOCEntities db = new OOCEntities())
         {
             IQueryable<Task> result = from o in db.Task
                                       where o.state == (sbyte)TaskState.Ready
                                       select o;
             if (!result.Any())
             {
                 throw new FaultException("NO_TASK_AVAILABLE");
             }
             Task task = result.First();
             task.state = (sbyte)TaskState.Assigned;
             task.instanceName = instanceName;
             db.SaveChanges();
             return new TaskAssignResponse(task, QueryTaskFileMapping(task.guid, TaskFileType.Input), task.triggerInvokeTime);
         }
     }
 }
Exemplo n.º 11
0
        public List<ResultLogs> GetLogsList()
        {
            /*sb.Append("Select top 8 ID,ModelID,UserID,CalTime FROM ResultLogs order by CalTime desc;");
            DataSet ds = new DataSet();
            ds = DbHelperSQL.Query(sb.ToString());
            foreach (DataRow dr in ds.Tables[0].Rows) {
                ModelYunModel.ResultLogs modelType = new ModelYunModel.ResultLogs();

                modelType.ID = dr[0].ToString();
                modelType.ModelID = dr[1].ToString();
                modelType.UserID = dr[2].ToString();
                modelType.CalTime = Convert.ToDateTime(dr[3]);
                list.Add(modelType);
            }
            return list;*/
            using (OOCEntities db = new OOCEntities()) {
                IQueryable<ResultLogs> result = from o in db.ResultLogs
                                                orderby o.calTime descending
                                                select o;
                return result.ToList();
            }
        }
Exemplo n.º 12
0
 public void AddOne(ResultLogs ModelResultLog)
 {
     /*strSql.Append("insert into ResultLogs (ID,ModelID,UserID,CalTime,FileFolder)");
     strSql.Append(" values(@ID,@ModelID,@UserID,@CalTime,@FileFolder);");
     SqlParameter[] parameters ={
                                 new SqlParameter("@ID", SqlDbType.NVarChar,50),
                                 new SqlParameter("@ModelID",SqlDbType.NVarChar,50),
                                 new SqlParameter("@UserID",SqlDbType.NVarChar,50),
                                 new SqlParameter("@CalTime",SqlDbType.DateTime),
                                 new SqlParameter("@FileFolder",SqlDbType.NVarChar,200),
                             };
     parameters[0].Value = ModelResultLog.ID;
     parameters[1].Value = ModelResultLog.ModelID;
     parameters[2].Value = ModelResultLog.UserID;
     parameters[3].Value = ModelResultLog.CalTime;
     parameters[4].Value = ModelResultLog.FileFolder;
     object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);*/
     using (OOCEntities db = new OOCEntities()) {
         db.ResultLogs.AddObject(ModelResultLog);
         db.SaveChanges();
     }
 }
Exemplo n.º 13
0
 public void AddAclEntry(int id, string entry)
 {
     using (OOCEntities db = new OOCEntities())
     {
         IQueryable<User> result = from o in db.User
                                   where o.id == id
                                   select o;
         if (!result.Any())
         {
             throw new FaultException("USER_NOT_EXISTS");
         }
         User user = result.First();
         List<string> entries = SerializationUtil.Deserialize<List<string>>(user.acl);
         if (entries == null) entries = new List<string>();
         if (entries.Contains(entry))
         {
             throw new FaultException("ENTRY_ALREADY_EXISTED");
         }
         entries.Add(entry);
         user.acl = SerializationUtil.Serialize(entries);
         db.SaveChanges();
     }
 }
Exemplo n.º 14
0
 public TaskDataResponse QueryTaskDataByGuid(string guid)
 {
     using (OOCEntities db = new OOCEntities())
     {
         IQueryable<Task> result = from o in db.Task
                                   where o.guid == guid
                                   select o;
         if (!result.Any())
         {
             throw new FaultException("TASK_NOT_EXISTS");
         }
         return new TaskDataResponse(result.First());
     }
 }
Exemplo n.º 15
0
 public void UpdatePassword(int id, string password)
 {
     using (OOCEntities db = new OOCEntities())
     {
         IQueryable<User> result = from o in db.User
                                   where o.id == id
                                   select o;
         if (!result.Any())
         {
             throw new FaultException("USER_NOT_EXISTS");
         }
         User user = result.First();
         user.passhash = Hash(password);
         db.SaveChanges();
     }
 }
Exemplo n.º 16
0
 public User GetByUsername(string Username)
 {
     using (OOCEntities db = new OOCEntities())
     {
         IQueryable<User> result = from o in db.User
                                   where o.username == Username
                                   select o;
         if (!result.Any())
         {
             throw new FaultException("USER_NOT_EXISTS");
         }
         return result.First();
     }
 }
Exemplo n.º 17
0
 public void UpdateModelProgress(string guid, ModelProgress modelProgress)
 {
     using (OOCEntities db = new OOCEntities())
     {
         IQueryable<Task> result = from o in db.Task
                                   where o.guid == guid
                                   select o;
         if (!result.Any())
         {
             throw new FaultException("TASK_NOT_EXISTS");
         }
         Task task = result.First();
         task.modelProgress = modelProgress.Serialized;
         db.SaveChanges();
     }
 }
Exemplo n.º 18
0
 public void UpdateState(string guid, TaskState state)
 {
     using (OOCEntities db = new OOCEntities())
     {
         IQueryable<Task> result = from o in db.Task
                                   where o.guid == guid
                                   select o;
         if (!result.Any())
         {
             throw new FaultException("TASK_NOT_EXISTS");
         }
         Task task = result.First();
         task.state = (sbyte)state;
         if (state == TaskState.Running)
         {
             task.timeStarted = System.DateTime.Now;
         }
         if (state == TaskState.Completed)
         {
             task.timeFinished = System.DateTime.Now;
         }
         db.SaveChanges();
     }
 }
Exemplo n.º 19
0
 public void SyncCompositionInputFiles(string guid)
 {
     using (OOCEntities db = new OOCEntities())
     {
         Task task = QueryTaskByGuid(guid);
         CompositionService compositionService = new CompositionService();
         List<string> fileNames = compositionService.GetInputFileNames(task.compositionGuid);
         foreach (string fileName in fileNames)
         {
             IQueryable<TaskFileMapping> result = from o in db.TaskFileMapping
                                                  where o.taskGuid == guid && o.fileName == fileName
                                                  select o;
             if (!result.Any())
             {
                 AddTaskFileMapping(guid, fileName, GuidUtil.newGuid() + ".in", TaskFileType.Input, false);
             }
         }
     }
 }
Exemplo n.º 20
0
 public void UpdateMobile(int id, string mobile)
 {
     using (OOCEntities db = new OOCEntities())
     {
         IQueryable<User> result = from o in db.User
                                   where o.id == id
                                   select o;
         if (!result.Any())
         {
             throw new FaultException("USER_NOT_EXISTS");
         }
         User user = result.First();
         user.mobile = mobile;
         db.SaveChanges();
     }
 }
Exemplo n.º 21
0
 public List<Task> GetTaskByCompositionAndUser(string compositionGuid, int userId)
 {
     using (OOCEntities db = new OOCEntities()) {
         IQueryable<Task> result = from o in db.Task
                                   where o.compositionGuid == compositionGuid && o.userId==userId
                                   select o;
         return result.ToList();
     }
 }
Exemplo n.º 22
0
 public ModelProgress QueryModelProgressByGuid(string guid)
 {
     using (OOCEntities db = new OOCEntities())
     {
         IQueryable<Task> result = from o in db.Task
                                   where o.guid == guid
                                   select o;
         if (!result.Any())
         {
             throw new FaultException("TASK_NOT_EXISTS");
         }
         return new ModelProgress() { Serialized = result.First().modelProgress };
     }
 }
Exemplo n.º 23
0
 public List<Task> QueryTaskByUserId(int userId)
 {
     using (OOCEntities db = new OOCEntities())
     {
         IQueryable<Task> result = from o in db.Task
                                   where o.userId == userId
                                   select o;
         return result.ToList();
     }
 }
Exemplo n.º 24
0
 //根据Time查outputParameter表项
 public List<OutputParameter> GetByTime(DateTime startTime, DateTime overTime)
 {
     using (OOCEntities db = new OOCEntities()) {
         IQueryable<OutputParameter> result = from o in db.OutputParameter
                                              where o.creation >= startTime && o.creation <= overTime
                                              select o;
         return result.ToList();
     }
 }
Exemplo n.º 25
0
 public List<TaskFileMapping> QueryTaskFileMapping(string guid, TaskFileType type)
 {
     using (OOCEntities db = new OOCEntities())
     {
         IQueryable<TaskFileMapping> result = from o in db.TaskFileMapping
                                              where o.taskGuid == guid && o.type == (sbyte)type
                                              select o;
         return result.ToList();
     }
 }
Exemplo n.º 26
0
 public void ReportInstanceFault(string instanceName)
 {
     using (OOCEntities db = new OOCEntities())
     {
         IQueryable<Task> result = from o in db.Task
                                   where o.instanceName == instanceName && o.state >= (sbyte)TaskState.Assigned && o.state <= (sbyte)TaskState.Finishing
                                   select o;
         foreach (Task task in result)
         {
             task.state = (sbyte)TaskState.Aborted;
         }
         db.SaveChanges();
     }
 }
Exemplo n.º 27
0
 public void SyncComposition(string guid)
 {
     using (OOCEntities db = new OOCEntities())
     {
         IQueryable<Task> result = from o in db.Task
                                   where o.guid == guid
                                   select o;
         if (!result.Any())
         {
             throw new FaultException("TASK_NOT_EXISTS");
         }
         Task task = result.First();
         CompositionData compositionData = new CompositionData(task.Composition);
         task.compositionData = compositionData.Serialized;
         db.SaveChanges();
         SyncCompositionInputFiles(guid);
     }
 }
Exemplo n.º 28
0
        //根据taskGuid,compositionGuid,compositionModelGuid,Time查outputParameter表项
        public List<OutputParameter> GetByGuidsAndTime(string taskGuid, string compGuid, string cmGuid,DateTime startTime, DateTime overTime)
        {
            int pageSize = 2;//每页显示的条数方案一:可以通过外部参数传递进行设置,由外围控制分页的范围,但是要记得及时的保存;方案二:可以定时的改变变量值进行查询,然后固定保存用以查询
            int pageIndex = 0;//页数,从0页开始
               using (OOCEntities db = new OOCEntities()) {//使用LINQ在后续中关于频繁的数据访问可能会涉及到效率的问题,所以在实现基本功能后要考虑进行优化
                /*IQueryable<OutputParameter> result = from o in db.OutputParameter
                                                     where o.taskGuid == taskGuid && o.compositionGuid == compGuid && o.compositionModelGuid == cmGuid && o.creation >= startTime && o.creation <= overTime
                                                     orderby o.creation ascending
                                                     select o*/
               /*IQueryable<OutputParameter> result = (from o in db.OutputParameter orderby o.creation ascending
                                                     where o.taskGuid == taskGuid && o.compositionGuid == compGuid && o.compositionModelGuid == cmGuid && o.creation >= startTime && o.creation <= overTime
                                                     //where ((from o1 in db.OutputParameter
                                                       //      orderby o1.creation ascending
                                                         // select o1.guid).Skip(m).Take(n)).Contains(o.guid)//从查询结果中跳过前每个记录,只要剩下的前n个记录

                                                    select o).Skip(pageIndex*pageSize).Take(pageSize);*/
                 var result = db.OutputParameter_show(taskGuid, compGuid, cmGuid, startTime, overTime, pageIndex, pageSize);//利用linq to entity 技术添加数据库中的存储过程,调用数据库中的存储过程进行查询并返回
            return result.ToList();
            }
        }
Exemplo n.º 29
0
 public List<string> QueryAcl(int id)
 {
     using (OOCEntities db = new OOCEntities())
     {
         IQueryable<User> result = from o in db.User
                                   where o.id == id
                                   select o;
         if (!result.Any())
         {
             throw new FaultException("USER_NOT_EXISTS");
         }
         User user = result.First();
         return SerializationUtil.Deserialize<List<string>>(user.acl);
     }
 }