Esempio n. 1
0
        private void DeleteProcesses(Action <WhereSqlClauseBuilder> action)
        {
            action.NullCheck("action");

            ORMappingItemCollection mapping = ORMapping.GetMappingInfo <WfProcessInstanceData>();

            WhereSqlClauseBuilder whereBuilder = new WhereSqlClauseBuilder();

            action(whereBuilder);

            string sql = string.Format("DELETE {0} WHERE {1}", mapping.TableName, whereBuilder.ToSqlString(TSqlBuilder.Instance));
            WfProcessCurrentInfoCollection processesInfo = WfProcessCurrentInfoAdapter.Instance.Load(false, action);

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

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                DbHelper.RunSql(sql, GetConnectionName());

                WfProcessCurrentActivityAdapter.Instance.DeleteProcessActivities(processesInfo);
                WfRelativeProcessAdapter.Instance.Delete(processesInfo);

                WfExtraPersistenceSettings.GetConfig().GetPersisters().DeleteData(processesInfo, context);

                scope.Complete();
            }
        }
		public static WfExtraPersistenceSettings GetConfig()
		{
			WfExtraPersistenceSettings result = (WfExtraPersistenceSettings)ConfigurationBroker.GetSection("wfExtraPersistenceSettings");

			if (result == null)
				result = new WfExtraPersistenceSettings(true);

			return result;
		}
Esempio n. 3
0
        public static WfExtraPersistenceSettings GetConfig()
        {
            WfExtraPersistenceSettings result = (WfExtraPersistenceSettings)ConfigurationBroker.GetSection("wfExtraPersistenceSettings");

            if (result == null)
            {
                result = new WfExtraPersistenceSettings(true);
            }

            return(result);
        }
Esempio n. 4
0
        public void SaveProcess(IWfProcess process)
        {
            WfProcessInstanceData instanceData = WfProcessInstanceData.FromProcess(process);

            if (instanceData.Data.IsNotEmpty())
            {
                if (WorkflowSettings.GetConfig().Compressed)
                {
                    XElement extData = GetExtData(instanceData.ExtData);

                    PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("CompressProcess", () =>
                    {
                        instanceData.BinaryData = GetCompressedStream(instanceData.Data, Encoding.GetEncoding(extData.Attribute("encoding", "utf-8")));
                        instanceData.Data       = string.Empty;
                    });
                }
            }

            string sql = string.Empty;

            ORMappingItemCollection mapping = ORMapping.GetMappingInfo <WfProcessInstanceData>();

            if (process.LoadingType == DataLoadingType.External)
            {
                UpdateSqlClauseBuilder uBuilder = ORMapping.GetUpdateSqlClauseBuilder(instanceData, mapping);

                uBuilder.AppendItem("UPDATE_TAG", "UPDATE_TAG + 1", "=", true);
                uBuilder.AppendTenantCode();

                WhereSqlClauseBuilder whereBuilder = ORMapping.GetWhereSqlClauseBuilderByPrimaryKey(instanceData, mapping);

                whereBuilder.AppendItem("UPDATE_TAG", process.UpdateTag);

                sql = string.Format("UPDATE {0} SET {1} WHERE {2}",
                                    mapping.TableName, uBuilder.ToSqlString(TSqlBuilder.Instance), whereBuilder.ToSqlString(TSqlBuilder.Instance));
            }
            else
            {
                InsertSqlClauseBuilder iBuilder = ORMapping.GetInsertSqlClauseBuilder(instanceData, mapping);
                iBuilder.AppendTenantCode();

                sql = string.Format("INSERT INTO {0} {1}", mapping.TableName, iBuilder.ToSqlString(TSqlBuilder.Instance));
            }

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

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("WriteProcessToDB", () =>
                                                                                    (DbHelper.RunSql(sql, GetConnectionName()) > 0).FalseThrow <WfRuntimeException>(
                                                                                        Translator.Translate(Define.DefaultCulture, "更新流程{0}失败,流程状态已经改变", process.ID))
                                                                                    );

                PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("WriteProcessActivitiesToDB",
                                                                                    () => WfProcessCurrentActivityAdapter.Instance.UpdateProcessActivities(process));

                PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("WriteRelativeProcessInfoToDB", () =>
                {
                    WfRelativeProcessAdapter.Instance.Delete(new WfRelativeProcess()
                    {
                        ProcessID = process.ID
                    });

                    if (process.RelativeID.IsNotEmpty())
                    {
                        WfRelativeProcessAdapter.Instance.Update(new WfRelativeProcess()
                        {
                            Description = string.IsNullOrEmpty(process.Descriptor.Description) ? process.Descriptor.Name : process.Descriptor.Description,
                            ProcessID   = process.ID,
                            RelativeID  = process.RelativeID,
                            RelativeURL = process.RelativeURL
                        });
                    }
                });

                if (WorkflowSettings.GetConfig().SaveRelativeData)
                {
                    PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("WriteRelativeDataToDB",
                                                                                        () => WfExtraPersistenceSettings.GetConfig().GetPersisters().SaveData(process, context));
                }

                scope.Complete();
            }
        }