[K2 Blackpearl] 流程相关的操作

创建Connection

        public void GetConn()
        {
            _connection = new Connection();
            ConnectionSetup setup = new ConnectionSetup();
            setup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.Authenticate, "true");
            setup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.IsPrimaryLogin, "true");
            setup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.SecurityLabelName, "K2");
            setup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.Host, "mydemo");
            setup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.Port, "5555");
            setup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.WindowsDomain, "mydemain");
            setup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.UserID, "k2manager");
            setup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.Password, "securitypassword");
            _connection.Open(setup);

       _connection.ImpersonateUser(HttpContext.Current.User.Identity.Name);
        }

发起流程

        public string StartProcess(string folio)
        {
            ProcessInstance pi = _connection.CreateProcessInstance(K2ProcessName);
            if (_dataFields == null) _dataFields = new Hashtable();

            foreach (object key in _dataFields.Keys)
            {
                pi.DataFields[key.ToString()].Value = _dataFields[key];
            }

            pi.Folio = folio;
            _connection.StartProcessInstance(pi);

            return pi.ID.ToString();
        }

读取流程DataField

        public string GetDataFieldValue(string field)
        {
            if (_wi== null) return string.Empty;

            ProcessInstance pi = _wi.ProcessInstance;
            DataField df = pi.DataFields[field];

            return df == null ? string.Empty : df.Value.ToString();
        }

执行Action操作

        public void ExcuteAction(string actionName)
        {
            if (_dataFields != null && _dataFields.Count > 0)
            {
                foreach (object key in _dataFields.Keys)
                {
                    wi.ProcessInstance.DataFields[key.ToString()].Value = _dataFields[key];
                }
                wi.ProcessInstance.Update();
            }

            try
            {
                SourceCode.Workflow.Client.Action action = wi.Actions[actionName];
                action.Execute();
            }
            catch
            {

            }
            //foreach (SourceCode.Workflow.Client.Action action in wi.Actions)
            //{
            //    if (action.Name.Trim()== actionName)
            //    {
            //        action.Execute();
            //        break;
            //    }
            //}
        }

获取当前Activity名称

        public string GetActivityName()
        {
            if (_wi != null)
            {
                return _wi.ActivityInstanceDestination.Name;
            }
            else
                return string.Empty;
        }
posted @ 2012-10-16 15:09  一只小小菜鸟  阅读(1065)  评论(0编辑  收藏  举报