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; } }
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(); } }
//根据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(); } }
//根据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(); } }
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(); } }
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(); } }
public void Create(User user) { using (OOCEntities db = new OOCEntities()) { try { db.User.AddObject(user); db.SaveChanges(); } catch { throw new FaultException("TRANSACTION_FAILED"); } } }
//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(); } }
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 { } } }
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); } } }
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(); } }
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(); } }
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(); } }
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()); } }
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(); } }
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(); } }
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(); } }
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(); } }
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); } } } }
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(); } }
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(); } }
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 }; } }
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(); } }
//根据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(); } }
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(); } }
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(); } }
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); } }
//根据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(); } }
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); } }