2016-09-02 18:05:17 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Configuration;
|
|
|
|
|
using System.Xml.Linq;
|
2016-09-04 01:15:43 +08:00
|
|
|
|
using OpenAuth.App;
|
2016-09-07 11:11:34 +08:00
|
|
|
|
using OpenAuth.Domain;
|
2016-09-02 18:05:17 +08:00
|
|
|
|
using OptimaJet.Workflow.Core.Builder;
|
|
|
|
|
using OptimaJet.Workflow.Core.Bus;
|
2016-09-04 01:15:43 +08:00
|
|
|
|
using OptimaJet.Workflow.Core.Persistence;
|
2016-09-02 18:05:17 +08:00
|
|
|
|
using OptimaJet.Workflow.Core.Runtime;
|
|
|
|
|
using OptimaJet.Workflow.DbPersistence;
|
|
|
|
|
|
2016-09-04 01:15:43 +08:00
|
|
|
|
namespace OpenAuth.Mvc.Models
|
2016-09-02 18:05:17 +08:00
|
|
|
|
{
|
2016-09-04 01:15:43 +08:00
|
|
|
|
public static class WorkflowInit
|
2016-09-02 18:05:17 +08:00
|
|
|
|
{
|
|
|
|
|
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>(
|
2016-09-07 11:11:34 +08:00
|
|
|
|
new MSSQLProvider(connectionString),
|
2016-09-02 18:05:17 +08:00
|
|
|
|
new OptimaJet.Workflow.Core.Parser.XmlWorkflowParser(),
|
|
|
|
|
new MSSQLProvider(connectionString)
|
|
|
|
|
).WithDefaultCache();
|
|
|
|
|
|
|
|
|
|
_runtime = new WorkflowRuntime(new Guid("{8D38DB8F-F3D5-4F26-A989-4FDD40F32D9D}"))
|
|
|
|
|
.WithBuilder(builder)
|
2016-09-05 20:07:10 +08:00
|
|
|
|
.WithRuleProvider(new WorkflowRuleProvider())
|
2016-09-07 11:11:34 +08:00
|
|
|
|
.WithActionProvider(new WorkflowActionProvider())
|
2016-09-02 18:05:17 +08:00
|
|
|
|
.WithPersistenceProvider(new MSSQLProvider(connectionString))
|
|
|
|
|
.WithTimerManager(new TimerManager())
|
|
|
|
|
.WithBus(new NullBus())
|
|
|
|
|
.SwitchAutoUpdateSchemeBeforeGetAvailableCommandsOn()
|
|
|
|
|
.Start();
|
2016-09-04 01:15:43 +08:00
|
|
|
|
_runtime.ProcessStatusChanged += _runtime_ProcessStatusChanged;
|
2016-09-02 18:05:17 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _runtime;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-04 01:15:43 +08:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2016-09-07 11:11:34 +08:00
|
|
|
|
//<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);
|
|
|
|
|
|
2016-09-04 01:15:43 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
2016-09-07 11:11:34 +08:00
|
|
|
|
UpdateApplyState(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
|
|
|
|
/// </summary>
|
|
|
|
|
private static void UpdateApplyState(ProcessStatusChangedEventArgs e)
|
|
|
|
|
{
|
2016-09-04 01:15:43 +08:00
|
|
|
|
var nextState = WorkflowInit.Runtime.GetLocalizedStateName(e.ProcessId, e.ProcessInstance.CurrentState);
|
|
|
|
|
|
|
|
|
|
var _app = AutofacExt.GetFromFac<GoodsApplyApp>();
|
2016-09-05 20:07:10 +08:00
|
|
|
|
_app.ChangeState(e.ProcessId, e.ProcessInstance.CurrentState, nextState);
|
2016-09-07 11:11:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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 WorkflowInbox()
|
|
|
|
|
{
|
|
|
|
|
Id = Guid.NewGuid(),
|
|
|
|
|
IdentityId = new Guid(newActor),
|
|
|
|
|
ProcessId = e.ProcessId
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
inboxApp.Add(newInboxItem);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-04 01:15:43 +08:00
|
|
|
|
}
|
2016-09-02 18:05:17 +08:00
|
|
|
|
}
|
|
|
|
|
}
|