/// <summary>
        /// 更新任务
        /// </summary>
        /// <param name="newJob"></param>
        private void DoUpdate(JobBase newJob)
        {
            using (TransactionScope ts = TransactionScopeFactory.Create())
            {
                if (this.Page.Request["id"] != null)
                {
                    StartWorkflowJobAdapter.Instance.Delete(new string[] { newJob.JobID });
                    InvokeWebServiceJobAdapter.Instance.Delete(p => p.AppendItem("JOB_ID", newJob.JobID));
                }
                if (newJob is StartWorkflowJob)
                {
                    StartWorkflowJobAdapter.Instance.Update((StartWorkflowJob)newJob);
                }
                else if (newJob is InvokeWebServiceJob)
                {
                    InvokeWebServiceJobAdapter.Instance.Update((InvokeWebServiceJob)newJob);
                }
                else
                {
                    JobBaseAdapter.Instance.Update(newJob);
                }

                ts.Complete();
            }
        }
Пример #2
0
 /// <summary>
 /// 关闭工作流待办
 /// </summary>
 /// <param name="todo"></param>
 public void CloseWorkflowTodo(TodoWork todo)
 {
     try
     {
         OAMQMessages msg = OAService.OAServiceInstance.BuildMessage(todo);
         using (TransactionScope trans = TransactionScopeFactory.Create())
         {
             //删除通知待办
             TodoWorkAdapter.Instance.Delete(todo.ID);
             bool sendMessage     = true;
             bool needDoneMessage = true;
             if (OAMessageExceptionList.ContainsKey(todo.ProcessCode.ToLower().Trim()))
             {
                 needDoneMessage = false;
                 if (OAMessageExceptionList[todo.ProcessCode.ToLower().Trim()].ToString() == todo.NodeType.ToString())
                 {
                     sendMessage = false;;
                 }
             }
             if (sendMessage)
             {
                 OAService.OAServiceInstance.CloseOATodo(msg, needDoneMessage);
             }
             trans.Complete();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #3
0
        /// <summary>
        /// 保持SignInInfo信息
        /// </summary>
        /// <param name="signInInfo">SignInInfo信息</param>
        /// <remarks>
        /// <code source="..\Framework\TestProjects\DeluxeWorks.Library.Passport.Test\DataObjectsTest.cs" region="SignInInfoPersistTest" lang="cs" title="保存SignInInfo对象" />
        /// </remarks>
        public void SaveSignInInfo(ISignInInfo signInInfo)
        {
            ORMappingItemCollection mapping = LoadMappingFromResource("MCS.Library.Passport.DataObjects.SignInInfoMapping.xml", typeof(ISignInInfo));

            string sql = string.Format("UPDATE PASSPORT_SIGNIN_INFO SET {0} WHERE {1}",
                                       ORMapping.GetUpdateSqlClauseBuilder(signInInfo, mapping).ToSqlString(TSqlBuilder.Instance),
                                       ORMapping.GetWhereSqlClauseBuilderByPrimaryKey(signInInfo, mapping).ToSqlString(TSqlBuilder.Instance));

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                using (DbContext context = DbContext.GetContext(DataAdapter.DBConnectionName))
                {
                    Database db = DatabaseFactory.Create(DataAdapter.DBConnectionName);

                    if (db.ExecuteNonQuery(CommandType.Text, sql) == 0)
                    {
                        sql = string.Format("INSERT INTO PASSPORT_SIGNIN_INFO {0}",
                                            ORMapping.GetInsertSqlClauseBuilder(signInInfo, mapping).ToSqlString(TSqlBuilder.Instance));

                        db.ExecuteNonQuery(CommandType.Text, sql);
                    }
                }

                scope.Complete();
            }
        }
Пример #4
0
        /// <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();
                }
            }
        }
Пример #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ids"></param>
        /// <returns>无法删除的ID列表</returns>
        public string[] Delete(string[] ids)
        {
            StringBuilder strBuilder = new StringBuilder();
            List <string> result     = new List <string>();

            foreach (string id in ids)
            {
                if (CheckScheduleInJob(id))
                {
                    result.Add(id);
                    continue;
                }

                WhereSqlClauseBuilder whereBuilder = new WhereSqlClauseBuilder();

                whereBuilder.AppendItem("SCHEDULE_ID", id);
                whereBuilder.AppendTenantCode(typeof(JobSchedule));

                strBuilder.Append(DELETE_JOB_SCHEDULE_DEF_SQL_CLAUSE);
                strBuilder.Append(whereBuilder.ToSqlString(TSqlBuilder.Instance));
                strBuilder.Append(TSqlBuilder.Instance.DBStatementSeperator);
            }
            if (!string.IsNullOrEmpty(strBuilder.ToString()))
            {
                using (TransactionScope tran = TransactionScopeFactory.Create())
                {
                    DbHelper.RunSqlWithTransaction(strBuilder.ToString(), GetConnectionName());
                    tran.Complete();
                }
            }
            return(result.ToArray());
        }
Пример #6
0
        public int CancelTask(string id)
        {
            int result = 0;

            using (TransactionScope transaction = TransactionScopeFactory.Create(TransactionScopeOption.Required))
            {
                TemplateConfigInstance tem = TemplateConfigInstanceOperator.Instance.GetModel(id);
                //--终止任务 将该任务的流程状态设置为2
                tem.ProcessStatus = 2;
                TemplateConfigInstanceOperator.Instance.UpdateModel(tem);
                if (tem.TaskType == 3)
                {
                    var plan = TemplateConfigInstancePlanOperator.Instance.GetModelBySubTask(tem.ID);
                    if (plan != null)
                    {
                        plan.Status = 4;
                        TemplateConfigInstancePlanOperator.Instance.UpdateModel(plan);
                    }
                }
                if (tem.TaskType != 2)
                {
                    //找到该任务下所有的task 取消流程
                    var taskList = TemplateTaskOperator.Instance.GetList(tem.ID);
                    taskList.ForEach(x =>
                    {
                        TemplateConfigInstanceOperator.Instance.CancelCollectTask(x, false);
                    });
                }
                result = 100;
                transaction.Complete();
            }
            return(result);
        }
Пример #7
0
        /// <summary>
        /// 修改Acl成员项的状态
        /// </summary>
        /// <param name="members"></param>
        /// <param name="status"></param>
        public void UpdateStatus(SCAclContainerOrMemberCollectionBase members, SchemaObjectStatus status)
        {
            members.NullCheck("members");

            ORMappingItemCollection mappings = this.GetMappingInfo();

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                foreach (SCAclItem aclItem in members)
                {
                    aclItem.Status = status;

                    string sql = VersionCommonObjectUpdateStatusSqlBuilder <SCAclItem> .Instance.ToUpdateSql(aclItem, mappings);

                    DateTime dt = (DateTime)DbHelper.RunSqlReturnScalar(sql, this.GetConnectionName());

                    //SCSnapshotBasicAdapter.Instance.UpdateCurrentSnapshot(mappings.TableName,
                    //    mappings.TableName + "_Current",
                    //    ORMapping.GetWhereSqlClauseBuilderByPrimaryKey(aclItem, mappings));

                    SCActionContext.Current.TimePoint.IsMinValue(() => SCActionContext.Current.TimePoint = dt);
                }

                scope.Complete();
            }
        }
Пример #8
0
        /// <summary>
        /// 将模式对象的修改提交到数据库
        /// </summary>
        /// <param name="obj">对其进行更新的<typeparamref name="T"/>对象。</param>
        public void Update(T obj)
        {
            obj.NullCheck("obj");

            this.MergeExistsObjectInfo(obj);

            SchemaObjectUpdateActionCollection actions = GetActions("Update");

            actions.Prepare(obj);

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                obj.Properties.Write();

                string sql = VersionSchemaObjectUpdateSqlBuilder.Instance.ToUpdateSql(obj, this.GetMappingInfo());

                DateTime dt = (DateTime)DbHelper.RunSqlReturnScalar(sql, this.GetConnectionName());

                SCActionContext.Current.TimePoint.IsMinValue(() => SCActionContext.Current.TimePoint = dt);

                actions.Persist(obj);

                scope.Complete();
            }
        }
        /// <summary>
        /// 添加数据到列表
        /// </summary>
        /// <param name="List"></param>
        /// <returns></returns>
        internal int AddMonthlyreportdetailLisr(List <B_MonthlyReportDetail> List)
        {
            StringBuilder sb = new StringBuilder();
            int           i  = 0;

            if (List.Count > 0)
            {
                List.ForEach(p =>
                {
                    sb.Append(ORMapping.GetInsertSql <B_MonthlyReportDetail>(p, TSqlBuilder.Instance) + sqlSeperator);
                });

                if (sb.Length > 0)
                {
                    using (TransactionScope scope = TransactionScopeFactory.Create())
                    {
                        i = ExecuteSql(sb.ToString());
                        scope.Complete();
                    }
                }

                return(i);
            }
            else
            {
                return(i);
            }
        }
Пример #10
0
        /// <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();
                }
            });
        }
Пример #11
0
        /// <summary>
        /// 更新列表
        /// </summary>
        /// <param name="List"></param>
        /// <returns></returns>
        internal int UpdateCompanylLisr(List <C_Company> List)
        {
            StringBuilder sb = new StringBuilder();
            int           i  = 0;

            if (List.Count > 0)
            {
                List.ForEach(p =>
                {
                    sb.Append(ORMapping.GetUpdateSql <C_Company>(p, TSqlBuilder.Instance) + sqlSeperator);
                });

                if (sb.Length > 0)
                {
                    using (TransactionScope scope = TransactionScopeFactory.Create())
                    {
                        i = ExecuteSql(sb.ToString());
                        scope.Complete();
                    }
                }

                return(i);
            }
            else
            {
                return(i);
            }
        }
Пример #12
0
        /// <summary>
        /// 从队列中获取n条记录,并进行处理
        /// </summary>
        /// <param name="count"></param>
        /// <returns></returns>
        public WfPersistQueueCollection FetchQueueItemsAndDoOperation(int count)
        {
            ORMappingItemCollection mappingInfo = ORMapping.GetMappingInfo(typeof(WfPersistQueue));

            string top = count < 0 ? string.Empty : "TOP " + count;

            string sql = string.Format("SELECT {0} * FROM {1} WITH (UPDLOCK, READPAST) ORDER BY SORT_ID", top, mappingInfo.TableName);

            WfPersistQueueCollection result = new WfPersistQueueCollection();

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                DataView view = DbHelper.RunSqlReturnDS(sql, GetConnectionName()).Tables[0].DefaultView;

                ORMapping.DataViewToCollection(result, view);

                foreach (WfPersistQueue pq in result)
                {
                    DoQueueOperationAndMove(pq);
                }

                scope.Complete();
            }

            return(result);
        }
        private void SaveMaterialContentFromFile(MaterialContent content)
        {
            SourceFileInfo.NullCheck("SourceFileInfo");

            if (CheckSourceFileExists)
            {
                ExceptionHelper.FalseThrow(SourceFileInfo.Exists, string.Format(Resource.FileNotFound, SourceFileInfo.Name));
            }

            if (SourceFileInfo.Exists)
            {
                content.FileSize = SourceFileInfo.Length;

                using (TransactionScope scope = TransactionScopeFactory.Create())
                {
                    using (FileStream stream = SourceFileInfo.OpenRead())
                    {
                        MaterialContentAdapter.Instance.Update(content, stream);

                        TransactionScopeFactory.AttachCommittedAction(new Action <TransactionEventArgs>(Current_TransactionCompleted), false);
                    }

                    scope.Complete();
                }
            }
        }
Пример #14
0
        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);
        }
Пример #15
0
        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="mr">成员关系</param>
        public void Delete(SCMemberRelation mr)
        {
            ItemAndContainerSnapshot existedObj = this.GetExistedObject(mr);
            string sql = string.Empty;

            ItemAndContainerSnapshot obj = new ItemAndContainerSnapshot(mr);

            obj.Status = SchemaObjectStatus.Deleted;

            if (existedObj != null)
            {
                //如果已经存在,且状态是正常的
                obj.VersionStartTime = existedObj.VersionStartTime;

                if (existedObj.Status == SchemaObjectStatus.Normal)
                {
                    sql = this.PrepareUpdateSql(new ItemAndContainerSnapshot[] { obj });
                }
            }

            if (sql.IsNotEmpty())
            {
                using (TransactionScope scope = TransactionScopeFactory.Create())
                {
                    DateTime dt = (DateTime)DbHelper.RunSqlReturnScalar(sql, this.GetConnectionName());

                    SCActionContext.Current.TimePoint.IsMinValue(() => SCActionContext.Current.TimePoint = dt);

                    scope.Complete();
                }
            }
        }
Пример #17
0
        /// <summary>
        /// 启动流程,持久化,然后发送执行活动的任务
        /// </summary>
        /// <param name="process"></param>
        public static void StartProcess(SysTaskProcess process)
        {
            process.NullCheck("process");

            process.Status = SysTaskProcessStatus.Running;

            ProcessContext.AffectedProcesses.AddOrReplace(process);

            if (process.Activities.Count == 0)
            {
                process.Status = SysTaskProcessStatus.Completed;
            }

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                Persist();

                if (process.Activities.Count > 0)
                {
                    ExecuteSysTaskActivityTask.SendTask(process.Activities[0]);
                }

                scope.Complete();
            }
        }
        /// <summary>
        /// 合并用户信息,一个事物内更新所有的
        /// </summary>
        /// <param name="users"></param>
        public void BatchMerge(string containerID, string containerSchemaType, SchemaObjectCollection users)
        {
            containerID.CheckStringIsNullOrEmpty("containerID");
            containerSchemaType.CheckStringIsNullOrEmpty("containerSchemaType");
            users.NullCheck("users");

            SameContainerItemAndContainerSnapshotCollection existedData = this.LoadByContainerID(containerID);

            SameContainerItemAndContainerSnapshotCollection insertData = GetInsertData(containerID, containerSchemaType, existedData, users);
            SameContainerItemAndContainerSnapshotCollection updateData = GetUpdateData(containerID, containerSchemaType, existedData, users);

            string sqlInsert = this.PrepareUpdateSql(insertData);
            string sqlUpdate = this.PrepareUpdateSql(updateData);

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                DateTime dtInsert = (DateTime)DbHelper.RunSqlReturnScalar(sqlInsert, this.GetConnectionName());

                SCActionContext.Current.TimePoint.IsMinValue(() => SCActionContext.Current.TimePoint = dtInsert);

                DateTime dtUpdate = (DateTime)DbHelper.RunSqlReturnScalar(sqlUpdate, this.GetConnectionName());

                SCActionContext.Current.TimePoint.IsMinValue(() => SCActionContext.Current.TimePoint = dtUpdate);

                scope.Complete();
            }
        }
Пример #19
0
        /// <summary>
        /// 更新一个容器下的Acl信息
        /// </summary>
        /// <param name="containerID"></param>
        /// <param name="aclItems"></param>
        public void Update(SCAclContainer container)
        {
            container.NullCheck("container");

            container.FillMembersProperties();

            ORMappingItemCollection mappings = this.GetMappingInfo();

            WhereSqlClauseBuilder builder = new WhereSqlClauseBuilder();

            builder.AppendItem("ContainerID", container.ContainerID);

            string sql = this.GetUpdateSql(container.ContainerID, container.Members);

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                DateTime dt = (DateTime)DbHelper.RunSqlReturnScalar(
                    sql, this.GetConnectionName());

                SCActionContext.Current.TimePoint.IsMinValue(() => SCActionContext.Current.TimePoint = dt);

                //foreach (SCAclItem aclItem in container.Members)
                //{
                //    SCSnapshotBasicAdapter.Instance.UpdateCurrentSnapshot(mappings.TableName,
                //        mappings.TableName + "_Current",
                //        ORMapping.GetWhereSqlClauseBuilderByPrimaryKey(aclItem, mappings));
                //}

                scope.Complete();
            }
        }
Пример #20
0
        public void UpdateContent(ImageProperty image)
        {
            image.NullCheck("image");

            IMaterialContentPersistManager manager = MaterialContentSettings.GetConfig().PersistManager;

            image.EnsureMaterialContent();

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                if (image.Content.IsEmpty())
                {
                    manager.DeleteMaterialContent(image.Content);
                }
                else
                {
                    manager.DestFileInfo   = GetPhysicalDestinationImagePath(image.Content.FileName);
                    manager.SourceFileInfo = image.Content.PhysicalSourceFilePath;

                    manager.SaveMaterialContent(image.Content);
                    image.FilePath = string.Empty;
                    image.Changed  = false;
                }

                scope.Complete();
            }
        }
Пример #21
0
        /// <summary>
        /// 延长锁的时间
        /// </summary>
        /// <param name="lockData"></param>
        /// <returns></returns>
        public DECheckLockResult ExtendLockTime(DELock lockData)
        {
            DECheckLockResult result = null;

            lockData.LockTime = DateTime.MinValue;

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                bool updated = false;

                DELock lockInDB = lockInDB = Update(lockData, true, out updated);

                if (updated == false)
                {
                    result = BuildNotAvailableResult(lockData);
                }
                else
                {
                    result = BuildAvailableResult(lockInDB, true);
                }

                scope.Complete();
            }

            return(result);
        }
Пример #22
0
        public void BatchUpdate(TCollection data, Dictionary <string, object> context)
        {
            ExceptionHelper.FalseThrow <ArgumentNullException>(data != null, "data");
            if (context == null)
            {
                context = new Dictionary <string, object>();
            }

            data.ForEach(itemData => BeforeInnerUpdate(itemData, context));

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                foreach (T itemData in data)
                {
                    if (InnerUpdate(itemData, context) == 0)
                    {
                        InnerInsert(itemData, context);
                    }

                    AfterInnerUpdate(itemData, context);
                }
                scope.Complete();
            }
            RefreshCache();
        }
Пример #23
0
        /// <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();
                }
            }
        }
Пример #24
0
        private object InternalExecute()
        {
            AUObjectOperationContext context = new AUObjectOperationContext(this.OperationType, this);

            ExecutionWrapper("PrepareData", () => PrepareData(context));
            ExecutionWrapper("PrepareOperationLog", () => PrepareOperationLog(context));

            object result = null;

            if (this.AutoStartTransaction)
            {
                using (TransactionScope scope = TransactionScopeFactory.Create())
                {
                    ExecutionWrapper("DoOperation", () => { result = DoOperation(context); });
                    ExecutionWrapper("PersistOperationLog", () => PersistOperationLog(context));

                    scope.Complete();
                }
            }
            else
            {
                ExecutionWrapper("DoOperation", () => result = DoOperation(context));
                ExecutionWrapper("PersistOperationLog", () => PersistOperationLog(context));
            }


            return(result);
        }
Пример #25
0
        public int DisplaceUserInProcessMatrix(string processDespKey, string userID, string[] displacingUserIDArray)
        {
            WfMatrix matrix = WfMatrixAdapter.Instance.LoadByProcessKey(processDespKey, true);

            IUser originalUser = OguMechanismFactory.GetMechanism().GetObjects <IUser>(SearchOUIDType.Guid, userID).FirstOrDefault();
            OguObjectCollection <IUser> displacingUsers = OguMechanismFactory.GetMechanism().GetObjects <IUser>(SearchOUIDType.Guid, displacingUserIDArray);

            string originalUserCodeName = originalUser != null ? originalUser.LogOnName : string.Empty;

            List <string> desplacingUserCodeNames = new List <string>();

            foreach (IUser user in displacingUsers)
            {
                if (desplacingUserCodeNames.Contains(user.LogOnName) == false)
                {
                    desplacingUserCodeNames.Add(user.LogOnName);
                }
            }

            int result = matrix.Rows.ReplcaeOperators(WfMatrixOperatorType.Person, originalUserCodeName, desplacingUserCodeNames.ToArray());

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                WfMatrixAdapter.Instance.Update(matrix);

                scope.Complete();
            }

            return(result);
        }
Пример #26
0
        protected void Save_Click(object sender, EventArgs e)
        {
            try
            {
                Util.EnsureOperationSafe();
                SchemaObjectBase parent = null;

                if (this.ParentID.IsNotEmpty())
                {
                    parent = SchemaObjectAdapter.Instance.Load(this.ParentID);
                }

                using (var scope = TransactionScopeFactory.Create())
                {
                    this.Data.Properties.Write();

                    SCObjectOperations.InstanceWithPermissions.DoOperation(this.OperationMode, this.Data, parent);

                    scope.Complete();
                }

                // 等待全文目录更新
                WebUtility.ResponseShowClientMessageScriptBlock("可能需要几秒钟之后重新查询列表才会反映所做的更改。", string.Empty, "保存成功");

                WebUtility.ResponseCloseWindowScriptBlock();
            }
            catch (System.Exception ex)
            {
                WebUtility.ShowClientError(ex.GetRealException());
            }
        }
Пример #27
0
        /// <summary>
        /// 关闭通知类待办
        /// </summary>
        /// <param name="bizProcessID"></param>
        /// <param name="userID"></param>
        /// <param name="todoWorkID"></param>
        /// <param name="projectID"></param>
        public void CloseNotificationTodo(int bizProcessID, int userID, int todoWorkID, int projectID)
        {
            TodoWork todo = TodoWorkAdapter.Instance.Load(todoWorkID);

            if (todo == null)
            {
                throw new Exception("没有找到指定的待办。");
            }
            else if (todo.BizProcessID != bizProcessID || todo.ProjectID != projectID || todo.UserID != userID)
            {
                throw new Exception("用户无权限或该待办不存在。");
            }
            else if (todo.TodoType != (int)CommonConsts.TodoType.Notification)
            {
                throw new Exception("无法处理未知的待办类型。");
            }
            else
            {
                try
                {
                    OAMQMessages msg = OAService.OAServiceInstance.BuildMessage(todo);
                    using (TransactionScope trans = TransactionScopeFactory.Create())
                    {
                        //删除通知待办,暂不生成已办日志
                        TodoWorkAdapter.Instance.Delete(todo.ID);
                        OAService.OAServiceInstance.CloseOATodo(msg);
                        trans.Complete();
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Пример #28
0
        /// <summary>
        /// 按照条件删除
        /// </summary>
        /// <param name="whereAction"></param>
        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);

                Dictionary <string, object> context = new Dictionary <string, object>();

                this.BeforeInnerDelete(builder, context);

                string sql = this.GetDeleteSql(builder, context);

                if (sql.IsNotEmpty())
                {
                    using (TransactionScope scope = TransactionScopeFactory.Create())
                    {
                        DbHelper.RunSql(db => db.ExecuteNonQuery(CommandType.Text, sql), this.GetConnectionName());

                        this.AfterInnerDelete(builder, context);

                        scope.Complete();
                    }
                }
            });
        }
Пример #29
0
        ///// <summary>
        ///// 读取在时间范围内,没有执行过且没有正在运行任务的作业。仅通过最后执行时间进行判断
        ///// </summary>
        ///// <param name="batchCount"></param>
        ///// <param name="timeOffset"></param>
        ///// <param name="action"></param>
        ///// <returns></returns>
        //public JobCollection FetchNotDispatchedJobs(int batchCount, TimeSpan timeOffset, Action<JobBase> action)
        //{
        //    JobCollection result = new JobCollection();
        //    string sql = "SELECT {0} J.* FROM WF.JOBS J WITH(UPDLOCK READPAST) LEFT JOIN WF.SYS_NOT_RUNNING_TASK T WITH(UPDLOCK READPAST) ON J.JOB_ID = T.RESOURCE_ID WHERE (T.STATUS IS NULL) AND {1} ORDER BY CREATE_TIME";

        //    using (DbContext context = DbContext.GetContext(this.GetConnectionName()))
        //    {
        //        string top = batchCount >= 0 ? "TOP " + batchCount : string.Empty;

        //        WhereSqlClauseBuilder builder = new WhereSqlClauseBuilder();

        //        builder.AppendItem("ENABLED", "1");

        //        WhereSqlClauseBuilder builder2 = new WhereSqlClauseBuilder(LogicOperatorDefine.Or);
        //        builder2.AppendItem("LAST_START_EXE_TIME", string.Format("DATEADD(SECOND, -{0}, GETDATE())", (int)timeOffset.TotalSeconds), "<", true);
        //        builder2.AppendItem("LAST_START_EXE_TIME", "NULL", "IS", true);

        //        Database db = DatabaseFactory.Create(context);

        //        using (TransactionScope scope = TransactionScopeFactory.Create())
        //        {
        //            using (IDataReader dr = db.ExecuteReader(CommandType.Text,
        //                string.Format(sql, top, new ConnectiveSqlClauseCollection(builder, builder2).ToSqlString(TSqlBuilder.Instance), SysTaskStatus.NotRunning.ToString())))
        //            {
        //                while (dr.Read())
        //                {
        //                    JobBase job = new JobBase();

        //                    ORMapping.DataReaderToObject(dr, job);

        //                    result.Add(job);
        //                }
        //            }

        //            JobScheduleAdapter.Instance.FillJobsSchdules(result);

        //            foreach (JobBase job in result)
        //            {
        //                if (action != null)
        //                    action(job);
        //            }

        //            Console.WriteLine("Read {0}", result.Count);
        //            scope.Complete();
        //        }
        //    }

        //    return result;
        //}

        /// <summary>
        /// 读取在时间范围内,没有执行过且没有正在运行任务的作业。仅通过最后执行时间进行判断
        /// </summary>
        /// <param name="batchCount"></param>
        /// <param name="timeOffset"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public JobCollection FetchNotDispatchedJobs(int batchCount, TimeSpan timeOffset, Action <JobBase> action)
        {
            IList <string> jobIDs = LoadUnTaskedJobs(batchCount, timeOffset);

            JobCollection result = new JobCollection();

            foreach (string jobID in jobIDs)
            {
                using (TransactionScope scope = TransactionScopeFactory.Create())
                {
                    JobBase job = LoadOneUnTaskedJob(jobID);

                    if (job != null)
                    {
                        if (action != null)
                        {
                            action(job);
                        }

                        result.Add(job);
                    }

                    scope.Complete();
                }
            }

            return(result);
        }
Пример #30
0
        ///// <summary>
        ///// 添加实体映射(新)
        ///// </summary>
        //public void AddEntityMapping(EntityMapping entityMapping)
        //{
        //    DEObjectExecutor executor = null;

        //    if (this._NeedCheckPermissions)
        //        CheckPermissions(DEOperationType.AddEntityMapping, null, "AddEntityMapping", string.Empty);

        //    OuterEntity outerEntity = new OuterEntity();
        //    OuterEntityFieldCollection outerEntityFields = new OuterEntityFieldCollection();

        //    using (TransactionScope scope = TransactionScopeFactory.Create())
        //    {
        //        #region [实体与外部实体映射][外部实体]入库
        //        if (entityMapping.InnerEntity.OuterEntities.Any(p => p.ID.Equals(entityMapping.OuterEntityID)))
        //        {
        //            var outentity = entityMapping.InnerEntity.OuterEntities.FirstOrDefault(p => p.ID.Equals(entityMapping.OuterEntityID));
        //            outentity.Name = entityMapping.OuterEntityName;
        //            outentity.CustomType = entityMapping.OuterEntityInType;
        //            outerEntity = outentity;
        //        }
        //        else
        //        {
        //            outerEntity = new OuterEntity() { ID = entityMapping.OuterEntityID, Name = entityMapping.OuterEntityName, CustomType = entityMapping.OuterEntityInType };
        //            entityMapping.InnerEntity.OuterEntities.Add(outerEntity);
        //        }

        //        executor = new DEMemberCollectionRelativeExecutor
        //        (
        //            DEOperationType.AddEntityMapping,
        //            entityMapping.InnerEntity,
        //            entityMapping.InnerEntity.OuterEntities.ToSchemaObjects(),
        //            DEStandardObjectSchemaType.DynamicEntityMapping
        //        ) { SaveContainerData = false, NeedValidation = this.NeedValidationAndStatusCheck };

        //        ExecuteWithActions(DEOperationType.AddEntityMapping, () => SCActionContext.Current.DoActions(() => executor.Execute()));
        //        #endregion

        //        #region 实体字段与外部实体字段映射入库
        //        entityMapping.EntityFieldMappingCollection.Where(field => field.OuterFieldName.IsNotEmpty()).ForEach(field =>
        //        {
        //            DynamicEntityField container = DESchemaObjectAdapter.Instance.Load(field.FieldID) as DynamicEntityField;

        //            var outerFiled = container.OuterEntityFields.FirstOrDefault(of => of.OuterEntity.ID.Equals(entityMapping.OuterEntityID));//&& of.ID.Equals(field.OuterFieldID)
        //            if (outerFiled != null)
        //            {
        //                outerFiled.Name = field.OuterFieldName;
        //                outerEntityFields.Add(outerFiled);
        //            }
        //            else
        //            {
        //                OuterEntityField new_outerField = new OuterEntityField() { ID = string.IsNullOrEmpty(field.OuterFieldID) ? Guid.NewGuid().ToString() : field.OuterFieldID, Name = field.OuterFieldName };
        //                container.OuterEntityFields.Add(new_outerField);

        //                outerEntityFields.Add(new_outerField);
        //            }

        //            executor = new DEMemberCollectionRelativeExecutor(DEOperationType.AddEntityFieldMapping, container, container.OuterEntityFields.ToSchemaObjects(), DEStandardObjectSchemaType.DynamicEntityFieldMapping) { SaveContainerData = false, NeedValidation = this.NeedValidationAndStatusCheck };

        //            ExecuteWithActions(DEOperationType.AddEntityFieldMapping, () => SCActionContext.Current.DoActions(() => executor.Execute()));
        //        });
        //        #endregion

        //        #region 外部实体与外部实体属性关系入库
        //        executor = new DEMemberCollectionRelativeExecutor(DEOperationType.AddOuterEntityFieldMapping, outerEntity, outerEntityFields.ToSchemaObjects(), DEStandardObjectSchemaType.OuterEntityFieldMapping) { SaveContainerData = false, SaveMemberData = false, NeedValidation = this.NeedValidationAndStatusCheck };

        //        ExecuteWithActions(DEOperationType.AddOuterEntityFieldMapping, () => SCActionContext.Current.DoActions(() => executor.Execute()));
        //        #endregion
        //        scope.Complete();

        //    }
        //}

        #endregion

        /// <summary>
        /// 删除实体
        /// </summary>
        /// <param name="entity"></param>
        public void DeleteEntity(DynamicEntity entity)
        {
            entity.Status = SchemaObjectStatus.Deleted;
            entity.Fields.ForEach(p => p.Status = SchemaObjectStatus.DeletedByContainer);

            // 查询出引用实体地址的字段 然后删除该字段和mapping 关系
            //WhereSqlClauseBuilder builder = new WhereSqlClauseBuilder();

            //builder.AppendItem("SchemaType", "DynamicEntityField");
            //builder.AppendItem("CodeName",entity.CodeName);
            //DESchemaObjectAdapter.Instance.Load(builder);
            // DeleteEntityField(DynamicEntityField entityField)

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                //删除映射关系 注释掉。2015-8-13 王雷平
                //DeleteEntityMapping(entity, entity.OuterEntities);

                DEObjectExecutor executor = null;

                if (this._NeedCheckPermissions)
                {
                    CheckPermissions(DEOperationType.DeleteEntity, null, "DeleteEntity", string.Empty);
                }

                executor = new DEMemberCollectionRelativeExecutor(DEOperationType.DeleteEntity, entity, entity.Fields.ToSchemaObjects())
                {
                    SaveContainerData = true, NeedValidation = this.NeedValidationAndStatusCheck
                };

                ExecuteWithActions(DEOperationType.DeleteEntity, () => SCActionContext.Current.DoActions(() => executor.Execute()));

                scope.Complete();
            }
        }