Esempio n. 1
0
        /// <summary>
        /// 初始化作业最优先执行
        /// </summary>
        /// <param name="p"></param>
        /// <param name="d"></param>
        protected virtual void Init(FlowParameter p, FlowData d)
        {
            _p = p;
            _d = d;

            lock (lockobj)
            {
                if (_dic == null)
                {
                    if (HttpRuntime.Cache["flow.flowcontrols"] != null)
                    {
                        _dic = (ConcurrentDictionary <string, Type>)HttpRuntime.Cache["flow.flowcontrols"];
                    }
                    else
                    {
                        _dic = new ConcurrentDictionary <string, Type>();
                        Assembly asm = Assembly.Load(GlobalCommon.FlowCommon.FlowDefineAssemblyPath);
                        Type[]   ts  = asm.GetTypes();
                        foreach (Type t in ts)
                        {
                            if (t.IsSubclassOf(typeof(FlowBaseDefine)) && !t.IsAbstract && !t.IsInterface)
                            {
                                FlowBaseDefine l   = (FlowBaseDefine)Activator.CreateInstance(t, true);
                                string         key = l.FlowName.ToUpper() + "." + l.Version.ToString();
                                if (_dic.ContainsKey(key))
                                {
                                    throw new DuplicateFlowInstanceException(string.Format("Duplicate flow-instance's Name-Version,pleas ensure flow-instance:[{0}-{1}] unique!", l.FlowName.ToUpper(), l.Version.ToString()));
                                }
                                else
                                {
                                    _dic.TryAdd(key, t);
                                }
                            }
                        }
                        //写入缓存
                        HttpRuntime.Cache.Insert("flow.flowcontrols", _dic, null, Cache.NoAbsoluteExpiration, TimeSpan.FromHours(12));
                    }
                }
                if (_dicinstance == null)
                {
                    if (HttpRuntime.Cache["flow.flowinstances"] != null)
                    {
                        _dicinstance = (ConcurrentDictionary <string, FlowBaseDefine>)HttpRuntime.Cache["flow.flowinstances"];
                    }
                    else
                    {
                        _dicinstance = new ConcurrentDictionary <string, FlowBaseDefine>();
                        HttpRuntime.Cache.Insert("flow.flowinstances", _dicinstance, null, Cache.NoAbsoluteExpiration, TimeSpan.FromHours(12));
                    }
                }
            }
        }
Esempio n. 2
0
        private FlowBaseDefine LoadFlowDefine(FlowParameter p, FlowData d)
        {
            FlowBaseDefine rtn = null;
            var            key = "";

            if (d.CurrentInfo != null && d.CurrentInfo.FlowState != FlowStateType.None)
            {
                key = p.FlowName.ToUpper() + "." + d.CurrentInfo.FlowVersion.ToString();
            }
            else
            {
                var latestver = GetLatestVersionBy(p.FlowName);
                key = p.FlowName.ToUpper() + "." + latestver;
                if (d.CurrentInfo == null)
                {
                    d.CurrentInfo = new FlowInstanceInfo();
                }
                d.CurrentInfo.FlowName    = p.FlowName;
                d.CurrentInfo.FlowVersion = latestver;
                d.CurrentInfo.InstanceID  = p.FlowInstanceID;
                d.CurrentInfo.FlowState   = FlowStateType.Ready;
            }
            //获取的实例不为空或无效状态,则继续流程运行,否则创建最新的流程
            if (_dic.ContainsKey(key))
            {
                var typekey     = p.FlowName.ToUpper() + "." + d.CurrentInfo.FlowVersion.ToString();
                var instancekey = p.FlowName.ToUpper() + "." + d.CurrentInfo.FlowVersion.ToString() + "." + p.FlowInstanceID;
                if (_dicinstance.ContainsKey(instancekey))
                {
                    rtn = _dicinstance[instancekey];
                }
                else
                {
                    rtn = (FlowBaseDefine)Activator.CreateInstance(_dic[typekey], true);
                    if (!_dicinstance.TryAdd(instancekey, rtn))
                    {
                        return(LoadFlowDefine(p, d));
                    }
                }
            }
            else
            {
                throw new InvalidFlowException(string.Format("Not found  the flow-instance named [{0}-{1}]!", p.FlowName.ToUpper(), d.CurrentInfo.FlowVersion.ToString()));
            }
            return(rtn);
        }