mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-09-19 18:22:11 +08:00
删除workflowengine.net
This commit is contained in:
@@ -1,45 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OptimaJet.Workflow.Core.Cache;
|
||||
using OptimaJet.Workflow.Core.Model;
|
||||
|
||||
namespace OpenAuth.Mvc.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 流程定义的缓存
|
||||
/// <para>李玉宝新增于2016-09-28 17:15:45</para>
|
||||
/// </summary>
|
||||
public sealed class DefaultParcedProcessCache : IParsedProcessCache
|
||||
{
|
||||
private Dictionary<Guid, ProcessDefinition> _cache;
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_cache.Clear();
|
||||
}
|
||||
|
||||
public ProcessDefinition GetProcessDefinitionBySchemeId(Guid schemeId)
|
||||
{
|
||||
if (_cache == null)
|
||||
return null;
|
||||
if (_cache.ContainsKey(schemeId))
|
||||
return _cache[schemeId];
|
||||
return null;
|
||||
}
|
||||
|
||||
public void AddProcessDefinition(Guid schemeId, ProcessDefinition processDefinition)
|
||||
{
|
||||
if (_cache == null)
|
||||
{
|
||||
_cache = new Dictionary<Guid, ProcessDefinition> {{schemeId, processDefinition}};
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_cache.ContainsKey(schemeId))
|
||||
_cache[schemeId] = processDefinition;
|
||||
else
|
||||
_cache.Add(schemeId, processDefinition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,146 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Entity.Validation;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using OpenAuth.App;
|
||||
using OpenAuth.Domain;
|
||||
using OptimaJet.Workflow.Core.Model;
|
||||
using OptimaJet.Workflow.Core.Runtime;
|
||||
|
||||
namespace OpenAuth.Mvc.Models
|
||||
{
|
||||
public class WorkflowActionProvider :IWorkflowActionProvider
|
||||
{
|
||||
private ModuleManagerApp _app;
|
||||
|
||||
public WorkflowActionProvider()
|
||||
{
|
||||
_app = AutofacExt.GetFromFac<ModuleManagerApp>();
|
||||
}
|
||||
public void ExecuteAction(string name, ProcessInstance processInstance, WorkflowRuntime runtime, string actionParameter)
|
||||
{
|
||||
if (_actions.ContainsKey(name))
|
||||
{
|
||||
_actions[name].Invoke(processInstance, actionParameter);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ExecuteCondition(string name, ProcessInstance processInstance, WorkflowRuntime runtime, string actionParameter)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<string> GetActions()
|
||||
{
|
||||
return _actions.Keys.ToList();
|
||||
}
|
||||
|
||||
private static Dictionary<string, Action<ProcessInstance, string>> _actions = new Dictionary
|
||||
<string, Action<ProcessInstance, string>>
|
||||
{
|
||||
{"创建流程记录", WriteTransitionHistory}, //仅用于PreExecution,创建流程初始转换列表
|
||||
{"更新流程记录", UpdateTransitionHistory}
|
||||
};
|
||||
|
||||
private static ApplyTransitionHistoryApp _applyTransitionHistoryApp = AutofacExt.GetFromFac<ApplyTransitionHistoryApp>();
|
||||
|
||||
public static void WriteTransitionHistory(ProcessInstance processInstance, string parameter)
|
||||
{
|
||||
if (processInstance.IdentityIds == null)
|
||||
return;
|
||||
|
||||
var currentstate = WorkflowInit.Runtime.GetLocalizedStateName(processInstance.ProcessId, processInstance.CurrentState);
|
||||
|
||||
var nextState = WorkflowInit.Runtime.GetLocalizedStateName(processInstance.ProcessId, processInstance.ExecutedActivityState);
|
||||
|
||||
var command = WorkflowInit.Runtime.GetLocalizedCommandName(processInstance.ProcessId, processInstance.CurrentCommand);
|
||||
|
||||
|
||||
var historyItem = new ApplyTransitionHistory
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
AllowedToUserNames = GetEmployeesString(processInstance.IdentityIds),
|
||||
DestinationState = nextState,
|
||||
ApplyId = processInstance.ProcessId,
|
||||
InitialState = currentstate,
|
||||
Command = command
|
||||
};
|
||||
_applyTransitionHistoryApp.Add(historyItem);
|
||||
|
||||
}
|
||||
|
||||
private static string GetEmployeesString(IEnumerable<string> identities)
|
||||
{
|
||||
var identitiesGuid = identities.Select(c => new Guid(c));
|
||||
var app = AutofacExt.GetFromFac<UserManagerApp>();
|
||||
|
||||
var employees = app.GetUsers(identitiesGuid);
|
||||
|
||||
var sb = new StringBuilder();
|
||||
bool isFirst = true;
|
||||
foreach (var employee in employees)
|
||||
{
|
||||
if (!isFirst)
|
||||
sb.Append(",");
|
||||
isFirst = false;
|
||||
|
||||
sb.Append(employee.Name);
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static void UpdateTransitionHistory(ProcessInstance processInstance, string parameter)
|
||||
{
|
||||
var currentstate = WorkflowInit.Runtime.GetLocalizedStateName(processInstance.ProcessId, processInstance.CurrentState);
|
||||
|
||||
var nextState = WorkflowInit.Runtime.GetLocalizedStateName(processInstance.ProcessId, processInstance.ExecutedActivityState);
|
||||
|
||||
var command = WorkflowInit.Runtime.GetLocalizedCommandName(processInstance.ProcessId, processInstance.CurrentCommand);
|
||||
|
||||
var isTimer = !string.IsNullOrEmpty(processInstance.ExecutedTimer);
|
||||
|
||||
var historyItem = _applyTransitionHistoryApp.Get(processInstance.ProcessId, currentstate, nextState);
|
||||
|
||||
if (historyItem == null)
|
||||
{
|
||||
historyItem = new ApplyTransitionHistory()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
AllowedToUserNames = string.Empty,
|
||||
DestinationState = nextState,
|
||||
ApplyId = processInstance.ProcessId,
|
||||
InitialState = currentstate
|
||||
};
|
||||
|
||||
_applyTransitionHistoryApp.Add(historyItem);
|
||||
|
||||
}
|
||||
|
||||
historyItem.Command = !isTimer ? command : string.Format("Timer: {0}", processInstance.ExecutedTimer);
|
||||
historyItem.TransitionTime = DateTime.Now;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(processInstance.IdentityId))
|
||||
historyItem.UserId = null;
|
||||
else
|
||||
historyItem.UserId = new Guid(processInstance.IdentityId);
|
||||
|
||||
try
|
||||
{
|
||||
_applyTransitionHistoryApp.Update(historyItem);
|
||||
}
|
||||
catch (DbEntityValidationException e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal static void DeleteEmptyPreHistory(Guid processId)
|
||||
{
|
||||
_applyTransitionHistoryApp.DeleteByProcess(processId);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,110 +0,0 @@
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Xml.Linq;
|
||||
using OpenAuth.App;
|
||||
using OpenAuth.Domain;
|
||||
using OptimaJet.Workflow.Core.Builder;
|
||||
using OptimaJet.Workflow.Core.Bus;
|
||||
using OptimaJet.Workflow.Core.Persistence;
|
||||
using OptimaJet.Workflow.Core.Runtime;
|
||||
using OptimaJet.Workflow.DbPersistence;
|
||||
|
||||
namespace OpenAuth.Mvc.Models
|
||||
{
|
||||
public static class WorkflowInit
|
||||
{
|
||||
private static volatile WorkflowRuntime _runtime;
|
||||
private static readonly object _sync = new object();
|
||||
|
||||
public static WorkflowRuntime Runtime
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_runtime == null)
|
||||
{
|
||||
lock (_sync)
|
||||
{
|
||||
if (_runtime == null)
|
||||
{
|
||||
var connectionString = ConfigurationManager.ConnectionStrings["WorkFlow"].ConnectionString;
|
||||
var builder = new WorkflowBuilder<XElement>(
|
||||
new MSSQLProvider(connectionString),
|
||||
new OptimaJet.Workflow.Core.Parser.XmlWorkflowParser(),
|
||||
new MSSQLProvider(connectionString)
|
||||
);
|
||||
builder.SetCache(new DefaultParcedProcessCache());
|
||||
|
||||
_runtime = new WorkflowRuntime(new Guid("{8D38DB8F-F3D5-4F26-A989-4FDD40F32D9D}"))
|
||||
.WithBuilder(builder)
|
||||
.WithRuleProvider(new WorkflowRuleProvider())
|
||||
.WithActionProvider(new WorkflowActionProvider())
|
||||
.WithPersistenceProvider(new MSSQLProvider(connectionString))
|
||||
.WithTimerManager(new TimerManager())
|
||||
.WithBus(new NullBus())
|
||||
.SwitchAutoUpdateSchemeBeforeGetAvailableCommandsOn()
|
||||
.Start();
|
||||
_runtime.ProcessStatusChanged += _runtime_ProcessStatusChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _runtime;
|
||||
}
|
||||
}
|
||||
|
||||
private static void _runtime_ProcessStatusChanged(object sender, ProcessStatusChangedEventArgs e)
|
||||
{
|
||||
if (e.NewStatus != ProcessStatus.Idled && e.NewStatus != ProcessStatus.Finalized)
|
||||
return;
|
||||
|
||||
if (string.IsNullOrEmpty(e.SchemeCode))
|
||||
return;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬ת<CCAC><D7AA><EFBFBD><EFBFBD>¼
|
||||
WorkflowActionProvider.DeleteEmptyPreHistory(e.ProcessId);
|
||||
_runtime.PreExecuteFromCurrentActivity(e.ProcessId);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>֪ͨ<CDA8>б<EFBFBD>
|
||||
UpdateInbox(e);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
||||
UpdateApplyState(e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
||||
/// </summary>
|
||||
private static void UpdateApplyState(ProcessStatusChangedEventArgs e)
|
||||
{
|
||||
var nextState = WorkflowInit.Runtime.GetLocalizedStateName(e.ProcessId, e.ProcessInstance.CurrentState);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD>֪ͨ<CDA8>б<EFBFBD>
|
||||
/// </summary>
|
||||
private static void UpdateInbox(ProcessStatusChangedEventArgs e)
|
||||
{
|
||||
var inboxApp = AutofacExt.GetFromFac<WorkflowInboxApp>();
|
||||
inboxApp.DeleteAllByProcess(e.ProcessId);
|
||||
|
||||
if (e.NewStatus != ProcessStatus.Finalized)
|
||||
{
|
||||
var newActors = Runtime.GetAllActorsForDirectCommandTransitions(e.ProcessId);
|
||||
foreach (var newActor in newActors)
|
||||
{
|
||||
var newInboxItem = new Relevance()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
SecondId = new Guid(newActor),
|
||||
FirstId = e.ProcessId,
|
||||
Key = "ProcessUser"
|
||||
};
|
||||
|
||||
inboxApp.Add(newInboxItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,65 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenAuth.App;
|
||||
using OptimaJet.Workflow.Core.Model;
|
||||
using OptimaJet.Workflow.Core.Runtime;
|
||||
|
||||
namespace OpenAuth.Mvc.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 流程角色处理
|
||||
/// </summary>
|
||||
public class WorkflowRuleProvider : IWorkflowRuleProvider
|
||||
{
|
||||
private RoleManagerApp _app;
|
||||
|
||||
public WorkflowRuleProvider()
|
||||
{
|
||||
_app = AutofacExt.GetFromFac<RoleManagerApp>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载角色列表,供流程设计的时候进行选择
|
||||
/// </summary>
|
||||
public List<string> GetRules()
|
||||
{
|
||||
var roles = _app.Load(Guid.Empty, 1, 100).rows;
|
||||
var rolestrs = new List<string>();
|
||||
foreach (var role in roles)
|
||||
{
|
||||
rolestrs.Add(role.Name);
|
||||
}
|
||||
return rolestrs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks the specified process instance.
|
||||
/// <para>李玉宝于2016-09-05 16:43:07</para>
|
||||
/// </summary>
|
||||
/// <param name="processInstance">The process instance.</param>
|
||||
/// <param name="runtime">The runtime.</param>
|
||||
/// <param name="identityId">用户ID</param>
|
||||
/// <param name="ruleName">Name of the rule.</param>
|
||||
/// <param name="parameter">The parameter.</param>
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
|
||||
public bool Check(ProcessInstance processInstance, WorkflowRuntime runtime, string identityId, string ruleName,
|
||||
string parameter)
|
||||
{
|
||||
var userRole = _app.LoadForUser(Guid.Parse(identityId));
|
||||
foreach (var role in userRole)
|
||||
{
|
||||
if (role.Name == ruleName)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetIdentities(ProcessInstance processInstance, WorkflowRuntime runtime, string ruleName, string parameter)
|
||||
{
|
||||
var userids = _app.GetUsersInRole(ruleName);
|
||||
if (userids == null) return null;
|
||||
return userids.Select(u => u.ToString());
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user