Insert() public method

新增流程记录
public Insert ( IDbConnection conn, ProcessEntity entity, IDbTransaction trans ) : void
conn IDbConnection
entity Slickflow.Engine.Business.Entity.ProcessEntity
trans IDbTransaction
return void
Exemplo n.º 1
0
 public void InsertProcess(ProcessEntity obj)
 {
     ProcessManager pm = new ProcessManager();
     pm.Insert(obj);
 }
        /// <summary>
        /// 创建流程定义记录
        /// </summary>
        /// <param name="entity"></param>
        public void CreateProcess(ProcessEntity entity)
        {
            var processManager = new ProcessManager();
            entity.ProcessGUID = Guid.NewGuid().ToString();
            entity.CreatedDateTime = DateTime.Now;
            entity.XmlFilePath = string.Format("{0}\\{1}", entity.AppType, entity.XmlFileName);

            var session = SessionFactory.CreateSession();
            try
            {
                session.BeginTrans();
                processManager.Insert(session.Connection, entity, session.Transaction);

                //创建xml文件到本地目录
                var serverPath = ConfigHelper.GetAppSettingString("WorkflowFileServer");
                var physicalFileName = string.Format("{0}\\{1}", serverPath, entity.XmlFilePath);

                //判断目录是否存在,否则创建
                var pathName = Path.GetDirectoryName(physicalFileName);
                if (!Directory.Exists(pathName))
                    Directory.CreateDirectory(pathName);

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml("<Package/>");
                XmlDeclaration xmldecl = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);

                //Add the new node to the document.
                XmlElement root = xmlDoc.DocumentElement;
                xmlDoc.InsertBefore(xmldecl, root);

                XmlElement workflowNode = xmlDoc.CreateElement("WorkflowProcess");
                XmlElement processNode = xmlDoc.CreateElement("Process");
                processNode.SetAttribute("name", entity.ProcessName);
                processNode.SetAttribute("id", entity.ProcessGUID);

                XmlElement descriptionNode = xmlDoc.CreateElement("Description");
                descriptionNode.InnerText = entity.Description;
                processNode.AppendChild(descriptionNode);

                workflowNode.AppendChild(processNode);
                root.AppendChild(workflowNode);

                xmlDoc.Save(physicalFileName);

                session.Commit();
            }
            catch (System.Exception ex)
            {
                session.Rollback();
            }
            finally
            {
                session.Dispose();
            }
        }