/// <summary> /// 保存副本 /// </summary> /// <param name="deltaMaterials">已经复制完成的副本的delta对象</param> /// <param name="sourceRootPathName">源文件的主路径的配置节点名称</param> /// <param name="destRootPathName">目标文件的主路径的配置节点名称</param> public void SaveCopyVersion(DeltaMaterialList deltaMaterials, string destRootPathName) { ExceptionHelper.TrueThrow <ArgumentNullException>(deltaMaterials == null, "deltaMaterials"); if (string.IsNullOrEmpty(deltaMaterials.RootPathName)) { deltaMaterials.RootPathName = MaterialAdapter.DefaultUploadPathName; } ExceptionHelper.CheckStringIsNullOrEmpty(destRootPathName, "destRootPathName"); string sql = this.GetCopyFilesSql(deltaMaterials); if (string.IsNullOrEmpty(sql) == false) { using (TransactionScope scope = TransactionScopeFactory.Create(TransactionScopeOption.Required)) { DbHelper.RunSql(sql, GetConnectionName()); DoFilesCopy(deltaMaterials.Inserted, deltaMaterials.RootPathName, destRootPathName, true); DoFilesCopy(deltaMaterials.Updated, deltaMaterials.RootPathName, destRootPathName, true); DoFilesCopy(deltaMaterials.Deleted, deltaMaterials.RootPathName, destRootPathName, false); scope.Complete(); } } }
private void InsertPostUsers(WfPostUserCollection postUsers) { using (TransactionScope scope = TransactionScopeFactory.Create()) { foreach (WfPostUser postUser in postUsers) { string ignoreFields = "UserID"; string sql = ORMapping.GetInsertSql(postUser, TSqlBuilder.Instance, ignoreFields); try { DbHelper.RunSql(sql, GetConnectionName()); } catch (System.Data.SqlClient.SqlException ex) { if (ex.ErrorCode != 2627) { throw; } } } scope.Complete(); } }
/// <summary> /// 根据已经完成系统任务创建新任务 /// </summary> /// <param name="taskID">被移动的任务的ID</param> /// <param name="status">重置任务的状态</param> public void MoveToNoRunningTask(string taskID) { var completedTask = this.Load(taskID); (completedTask != null).FalseThrow <ArgumentException>("ID为 {0} 的任务不存在", taskID); PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration(string.Format("MoveNoRunning({0})", this.GetType().FullName), () => { Dictionary <string, object> context = new Dictionary <string, object>(); ORMappingItemCollection mappingsTask = ORMapping.GetMappingInfo <SysTask>(); var task = completedTask.CreateNewSystask(UuidHelper.NewUuidString());; StringBuilder sql = new StringBuilder(); sql.Append(ORMapping.GetInsertSql(task, mappingsTask, TSqlBuilder.Instance)); sql.Append(TSqlBuilder.Instance.DBStatementSeperator); using (TransactionScope scope = TransactionScopeFactory.Create()) { DbHelper.RunSql(sql.ToString(), this.GetConnectionName()); scope.Complete(); } }); }
public virtual void Delete(Action <WhereSqlClauseBuilder> whereAction) { whereAction.NullCheck("whereAction"); PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration(string.Format("Delete(whereAction-{0})", this.GetType().FullName), () => { WhereSqlClauseBuilder builder = new WhereSqlClauseBuilder(); whereAction(builder); if (builder.Count > 0) { Dictionary <string, object> context = new Dictionary <string, object>(); ORMappingItemCollection mappings = GetMappingInfo(context); string sql = string.Format("DELETE {0} WHERE {1}", mappings.TableName, builder.ToSqlString(TSqlBuilder.Instance)); BeforeInnerDelete(builder, context); using (TransactionScope scope = TransactionScopeFactory.Create()) { DbHelper.RunSql(db => db.ExecuteNonQuery(CommandType.Text, sql), this.GetConnectionName()); AfterInnerDelete(builder, context); scope.Complete(); } } }); }
/// <summary> /// 在删除Group后触发删除关联用户操作。 /// </summary> /// <param name="data"></param> /// <param name="context"></param> protected override void AfterInnerDelete(WfGroup data, Dictionary <string, object> context) { string sql = string.Format("DELETE WF.GROUP_USERS WHERE GROUP_ID = {0}", TSqlBuilder.Instance.CheckQuotationMark(data.GroupID, true)); DbHelper.RunSql(sql, GetConnectionName()); }
public void Update() { XElementFormatter formatter = new XElementFormatter(); formatter.OutputShortType = false; string settings = formatter.Serialize(this).ToString(); string updateSQL = string.Format("UPDATE USER_SETTINGS SET SETTINGS = {0} WHERE USER_ID = {1}", TSqlBuilder.Instance.CheckQuotationMark(settings, true), TSqlBuilder.Instance.CheckQuotationMark(this.UserID, true)); using (DbContext context = DbContext.GetContext(ConnectionDefine.UserRelativeInfoConnectionName)) { using (TransactionScope scope = TransactionScopeFactory.Create()) { if (DbHelper.RunSql(updateSQL, ConnectionDefine.UserRelativeInfoConnectionName) == 0) { string insertSQL = string.Format("INSERT INTO USER_SETTINGS(USER_ID, SETTINGS) VALUES({0}, {1})", TSqlBuilder.Instance.CheckQuotationMark(this.UserID, true), TSqlBuilder.Instance.CheckQuotationMark(settings, true)); DbHelper.RunSql(insertSQL, ConnectionDefine.UserRelativeInfoConnectionName); } scope.Complete(); } } CacheNotifyData notifyData = new CacheNotifyData(typeof(UserSettingsCache), this.UserID, CacheNotifyType.Invalid); UdpCacheNotifier.Instance.SendNotifyAsync(notifyData); MmfCacheNotifier.Instance.SendNotify(notifyData); }
/// <summary> /// 调用本方法,删除外网用户与内网用户的映射关系 /// </summary> /// <param name="group"></param> /// <param name="userIDs"></param> public void DeleteMappingUser(string extUserId) { string sql = string.Format("DELETE EXT_INT_USERMAPPING WHERE Ext_UserID = {0}", TSqlBuilder.Instance.CheckQuotationMark(extUserId, true)); DbHelper.RunSql(sql, GetConnectionName()); }
/// <summary> /// /// </summary> /// <param name="deltaMaterials"></param> /// <param name="doFileOperations"></param> public void SaveDeltaMaterials(DeltaMaterialList deltaMaterials, bool doFileOperations) { ExceptionHelper.TrueThrow <ArgumentNullException>(deltaMaterials == null, "deltaMaterials"); string rootPathName = deltaMaterials.RootPathName; if (string.IsNullOrEmpty(rootPathName)) { rootPathName = MaterialAdapter.DefaultUploadPathName; } StringBuilder strB = new StringBuilder(1024); List <MaterialFileOeprationInfo> fileOPList = new List <MaterialFileOeprationInfo>(); string sql = FillMaterialSqlAndFileOpList(deltaMaterials, fileOPList); if (string.IsNullOrEmpty(sql) == false) { using (TransactionScope scope = TransactionScopeFactory.Create(TransactionScopeOption.Required)) { DbHelper.RunSql(sql, GetConnectionName()); if (doFileOperations) { DoFileOperations(rootPathName, fileOPList); } scope.Complete(); } } }
protected virtual void InnerInsert(T data, Dictionary <string, object> context) { ORMappingItemCollection mappings = GetMappingInfo(context); string sql = this.GetInsertSql(data, mappings, context); DbHelper.RunSql(db => db.ExecuteNonQuery(CommandType.Text, sql), this.GetConnectionName()); }
/// <summary> /// 设置待办箱阅读时间 /// </summary> /// <param name="taskID">待办箱ID</param> public void SetTaskReadFlag(string taskID) { taskID.NullCheck("taskID"); string sql = "UPDATE WF.USER_TASK SET READ_TIME = GETDATE() WHERE TASK_GUID = " + TSqlBuilder.Instance.CheckQuotationMark(taskID, true); DbHelper.RunSql(sql, GetConnectionName()); }
private void InsertSentMessage(EmailMessage message) { StringBuilder strB = new StringBuilder(2048); using (StringWriter writer = new StringWriter(strB)) { WriteEmailMessageBodySql(writer, message, "MSG.SENT_EMAIL_MESSAGES", true); } DbHelper.RunSql(strB.ToString(), GetConnectionName()); }
private void DeleteEmailMessagesMainData(IEnumerable <EmailMessage> messages) { InSqlClauseBuilder builder = new InSqlClauseBuilder("MESSAGE_ID"); messages.ForEach(m => builder.AppendItem(m.ID)); if (builder.Count > 0) { string sql = string.Format("DELETE MSG.EMAIL_MESSAGES WHERE {0}", builder.AppendTenantCodeSqlClause().ToSqlString(TSqlBuilder.Instance)); DbHelper.RunSql(sql, GetConnectionName()); } }
protected virtual int InnerUpdate(T data, Dictionary <string, object> context) { ORMappingItemCollection mappings = GetMappingInfo(context); string sql = this.GetUpdateSql(data, mappings, context); int result = 0; DbHelper.RunSql(db => result = db.ExecuteNonQuery(CommandType.Text, sql), this.GetConnectionName()); return(result); }
public int AddOperationTasksLogs(UserOperationTasksLogCollection userTaskslogs) { StringBuilder sqlStrB = new StringBuilder(); ORMappingItemCollection mappings = ORMapping.GetMappingInfo <UserOperationTasksLog>(); foreach (UserOperationTasksLog data in userTaskslogs) { sqlStrB.AppendFormat("{0} ; \n", ORMapping.GetInsertSql(data, mappings, TSqlBuilder.Instance)); } return(DbHelper.RunSql(sqlStrB.ToString(), this.GetConnectionName())); }
public void DeleteExpiredTasks(TimeSpan expiredTime) { WhereSqlClauseBuilder builder = new WhereSqlClauseBuilder(); builder.AppendItem("START_TIME", string.Format("DATEADD(second, -{0}, GETUTCDATE())", (int)expiredTime.TotalSeconds), "<", true); builder.AppendTenantCode(); string sql = string.Format("DELETE {0} WHERE {1}", this.GetTableName(), builder.ToSqlString(TSqlBuilder.Instance)); DbHelper.RunSql(sql, this.GetConnectionName()); }
private static int eventContainer_UpdateUserTask(UserTask task, UserTaskIDType idType, UserTaskFieldDefine fields, Dictionary <object, object> context) { ExceptionHelper.FalseThrow <ArgumentNullException>(task != null, "task"); WhereSqlClauseBuilder wBuilder = GetWhereSqlClauseBuilderByUserTask(task, idType); UpdateSqlClauseBuilder uBuilder = GetUpdateSqlClauseBuilderByUserTask(task, fields); string sql = string.Format("UPDATE WF.USER_TASK SET {0} WHERE {1}", uBuilder.ToSqlString(TSqlBuilder.Instance), wBuilder.ToSqlString(TSqlBuilder.Instance)); return(DbHelper.RunSql(sql, GetConnectionName())); }
private void InnerInsertWithStream(MaterialContent data, Stream stream, Dictionary <string, object> context) { ORMappingItemCollection mappings = GetMappingInfo(context); InsertSqlClauseBuilder builder = ORMapping.GetInsertSqlClauseBuilder(data, "ContentData"); builder.AppendItem("CONTENT_DATA", stream); string sql = string.Format("INSERT INTO {0}{1} ", mappings.TableName, builder.ToSqlString(TSqlBuilder.Instance)); DbHelper.RunSql(sql, GetConnectionName()); }
/// <summary> /// 取消待办箱置顶 /// </summary> /// <param name="taskID"></param> public void CancelTaskAtTop(params string[] taskID) { ExceptionHelper.TrueThrow <ArgumentNullException>(null == taskID, "taskID"); if (taskID.Length > 0) { InSqlClauseBuilder inSQL = new InSqlClauseBuilder(); inSQL.AppendItem(taskID); string strSQL = string.Format("UPDATE WF.USER_TASK SET TOP_FLAG = 0 WHERE TASK_GUID IN ({0})", inSQL.ToSqlString(TSqlBuilder.Instance)); DbHelper.RunSql(strSQL, GetConnectionName()); } }
protected override void InnerInsert(InvokeWebServiceJob data, Dictionary <string, object> context, string[] ignoreProperties) { InsertSqlClauseBuilder builder = new InsertSqlClauseBuilder(); FillSqlBuilder(builder, data); string sql = string.Format("INSERT INTO {0} {1}", GetMappingInfo(context).TableName, builder.ToSqlString(TSqlBuilder.Instance)); DbHelper.RunSql(sql, GetConnectionName()); JobBaseAdapter.Instance.Update(data); }
protected virtual int InnerDelete(T data, Dictionary <string, object> context) { ORMappingItemCollection mappings = GetMappingInfo(context); WhereSqlClauseBuilder builder = ORMapping.GetWhereSqlClauseBuilderByPrimaryKey(data, mappings); ExceptionHelper.FalseThrow(builder.Count > 0, "必须为对象{0}指定关键字", typeof(T)); string sql = string.Format("DELETE FROM {0} WHERE {1}", mappings.TableName, builder.ToSqlString(TSqlBuilder.Instance)); int result = 0; DbHelper.RunSql(db => result = db.ExecuteNonQuery(CommandType.Text, sql), this.GetConnectionName()); return(result); }
private static void eventContainer_DeleteUserTasks(UserTaskCollection tasks, Dictionary <object, object> context) { ExceptionHelper.FalseThrow <ArgumentNullException>(tasks != null, "tasks"); InSqlClauseBuilder builder = new InSqlClauseBuilder(); tasks.ForEach(u => builder.AppendItem(u.TaskID)); if (builder.Count > 0) { string sql = string.Format("DELETE WF.USER_TASK WHERE TASK_GUID {0}", builder.ToSqlStringWithInOperator(TSqlBuilder.Instance)); DbHelper.RunSql(sql, GetConnectionName()); } }
/// <summary> /// 移动到已经完成系统任务中 /// </summary> /// <param name="taskID">被移动的任务的ID</param> /// <param name="status">重置任务的状态</param> public SysAccomplishedTask MoveToCompletedSysTask(SysTask task, SysTaskStatus status, string statusText) { SysAccomplishedTask result = null; PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration(string.Format("MoveToAccomplished({0})", this.GetType().FullName), () => { Dictionary <string, object> context = new Dictionary <string, object>(); ORMappingItemCollection mappings = GetMappingInfo(context); WhereSqlClauseBuilder builder = ORMapping.GetWhereSqlClauseBuilderByPrimaryKey(task, mappings); ORMappingItemCollection mappingsCompleted = ORMapping.GetMappingInfo <SysAccomplishedTask>(); SysAccomplishedTask taskCompleted = new SysAccomplishedTask(task); taskCompleted.Status = status; taskCompleted.StatusText = statusText; StringBuilder sql = new StringBuilder(); sql.AppendFormat("DELETE FROM {0} WHERE {1}", mappingsCompleted.TableName, builder.ToSqlString(TSqlBuilder.Instance)); sql.Append(TSqlBuilder.Instance.DBStatementSeperator); sql.Append(GetMoveSysTaskSql(taskCompleted, context)); sql.Append(TSqlBuilder.Instance.DBStatementSeperator); sql.Append("IF @@ROWCOUNT = 0"); sql.Append(TSqlBuilder.Instance.DBStatementSeperator); sql.Append("\t" + ORMapping.GetInsertSql(taskCompleted, mappingsCompleted, TSqlBuilder.Instance)); sql.Append(TSqlBuilder.Instance.DBStatementSeperator); sql.AppendFormat("DELETE FROM {0} WHERE {1}", mappings.TableName, builder.ToSqlString(TSqlBuilder.Instance)); using (TransactionScope scope = TransactionScopeFactory.Create()) { DbHelper.RunSql(sql.ToString(), this.GetConnectionName()); scope.Complete(); } result = taskCompleted; }); return(result); }
private int InnerUpdate(AppCommonInfo aci, string[] ignoredUpdateProperties) { List<string> ignoredProperties = new List<string>(); for (int i = 0; i < ignoredUpdateProperties.Length; i++) { if (ignoredUpdateProperties[i] != "ResourceID") ignoredProperties.Add(ignoredUpdateProperties[i]); } ignoredProperties.Add("ResourceID"); string sql = ORMapping.GetUpdateSql(aci, TSqlBuilder.Instance, ignoredProperties.ToArray()); return DbHelper.RunSql(sql, this.GetConnectionName()); }
public void DeletePostUsers(WfPost post, params string[] userIDs) { post.NullCheck("post"); userIDs.NullCheck("userIDs"); InSqlClauseBuilder builder = new InSqlClauseBuilder(); builder.AppendItem(userIDs); if (builder.Count > 0) { string sql = string.Format("DELETE WF.POST_USERS WHERE POST_ID = {0} AND USER_ID {1}", TSqlBuilder.Instance.CheckQuotationMark(post.PostID, true), builder.ToSqlStringWithInOperator(TSqlBuilder.Instance)); DbHelper.RunSql(sql, GetConnectionName()); } }
/// <summary> /// 调用本方法,批量删除组内用户 /// </summary> /// <param name="group"></param> /// <param name="userIDs"></param> public void DeleteGroupUsers(WfGroup group, params string[] userIDs) { group.NullCheck("group"); userIDs.NullCheck("userIDs"); InSqlClauseBuilder builder = new InSqlClauseBuilder(); builder.AppendItem(userIDs); if (builder.Count > 0) { string sql = string.Format("DELETE WF.GROUP_USERS WHERE GROUP_ID = {0} AND USER_ID {1}", TSqlBuilder.Instance.CheckQuotationMark(group.GroupID, true), builder.ToSqlStringWithInOperator(TSqlBuilder.Instance)); DbHelper.RunSql(sql, GetConnectionName()); } }
/// <summary> /// 调用本方法,更改或添加外网用户与内网用户的映射关系; /// </summary> /// <param name="extUser"></param> /// <param name="mappingUserId"></param> public void SetMappingUser(string extUserId, string mappingUserId) { using (TransactionScope scope = TransactionScopeFactory.Create()) { string sql = string.Format("DELETE EXT_INT_USERMAPPING WHERE Ext_UserID = {0}", TSqlBuilder.Instance.CheckQuotationMark(extUserId, true)); DbHelper.RunSql(sql, GetConnectionName()); string insertSql = string.Format("INSERT EXT_INT_USERMAPPING(EXT_USERID, USERID) values({0}, {1})", TSqlBuilder.Instance.CheckQuotationMark(extUserId, true), TSqlBuilder.Instance.CheckQuotationMark(mappingUserId, true)); DbHelper.RunSql(insertSql, GetConnectionName()); scope.Complete(); } }
private int InnerUpdateWithStream(MaterialContent data, Stream stream, Dictionary <string, object> context) { ORMappingItemCollection mappings = GetMappingInfo(context); UpdateSqlClauseBuilder uBuilder = ORMapping.GetUpdateSqlClauseBuilder(data, "ContentData"); uBuilder.AppendItem("CONTENT_DATA", stream); WhereSqlClauseBuilder wBuilder = ORMapping.GetWhereSqlClauseBuilderByPrimaryKey(data); string sql = string.Format("UPDATE {0} SET {1} WHERE {2}", mappings.TableName, uBuilder.ToSqlString(TSqlBuilder.Instance), wBuilder.ToSqlString(TSqlBuilder.Instance)); DbHelper.RunSql(sql, GetConnectionName()); return(1); }
protected override int InnerUpdate(StartWorkflowJob data, Dictionary <string, object> context, string[] ignoreProperties) { UpdateSqlClauseBuilder builder = new UpdateSqlClauseBuilder(); FillSqlBuilder(builder, data); string sql = string.Format("UPDATE {0} SET {1} WHERE [JOB_ID] = {2}", GetMappingInfo(context).TableName, builder.ToSqlString(TSqlBuilder.Instance), TSqlBuilder.Instance.CheckUnicodeQuotationMark(data.JobID)); int result = DbHelper.RunSql(sql, GetConnectionName()); if (result > 0) { JobBaseAdapter.Instance.Update(data); } return(result); }
protected override void AfterInnerUpdate(JobBase data, Dictionary <string, object> context) { //更新任务-计划映射表JOB_SCHEDULES StringBuilder insertClause = new StringBuilder(); insertClause.Append(GetJobSchedulesDeleteClause(data.JobID)); insertClause.Append(TSqlBuilder.Instance.DBStatementSeperator); foreach (var schedule in data.Schedules) { InsertSqlClauseBuilder insertBuilder = new InsertSqlClauseBuilder(); insertBuilder.AppendItem("JOB_ID", data.JobID); insertBuilder.AppendItem("SCHEDULE_ID", schedule.ID); insertClause.Append(INSERT_JOB_SCHEDULES_SQL_CLAUSE + insertBuilder.ToSqlString(TSqlBuilder.Instance)); insertClause.Append(TSqlBuilder.Instance.DBStatementSeperator); } DbHelper.RunSql(insertClause.ToString(), GetConnectionName()); }
public void InsertWithContent(MaterialList materials) { materials.NullCheck("materials"); StringBuilder strB = new StringBuilder(); ORMappingItemCollection mappings = ORMapping.GetMappingInfo(typeof(Material)); foreach (Material m in materials) { if (strB.Length > 0) { strB.Append(TSqlBuilder.Instance.DBStatementSeperator); } InsertSqlClauseBuilder builder = ORMapping.GetInsertSqlClauseBuilder(m, mappings, "CreateDateTime"); builder.AppendItem("CREATE_DATETIME", m.CreateDateTime); strB.AppendFormat("INSERT INTO {0}{1}", mappings.TableName, builder.ToSqlString(TSqlBuilder.Instance)); } if (strB.Length > 0) { using (TransactionScope scope = TransactionScopeFactory.Create()) { DbHelper.RunSql(strB.ToString(), GetConnectionName()); foreach (Material m in materials) { m.Content.RelativeID = m.ResourceID; MaterialFileOeprationInfo fileOp = new MaterialFileOeprationInfo(m, FileOperation.Update); DoFileOperation(MaterialAdapter.DefaultUploadPathName, fileOp, m.Content); } scope.Complete(); } } }